diff --git a/Jenkinsfile2 b/Jenkinsfile2 index 441cf89626..a2043797c0 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -88,6 +88,12 @@ def pre_test(){ cmake .. > /dev/null make -j4> /dev/null ''' + sh''' + cd ${WKPY} + git reset --hard + git pull + pip3 install . + ''' return 1 } @@ -97,6 +103,7 @@ pipeline { environment{ WK = '/var/lib/jenkins/workspace/TDinternal' WKC= '/var/lib/jenkins/workspace/TDengine' + WKPY= '/var/lib/jenkins/workspace/taos-connector-python' } stages { stage('pre_build'){ @@ -117,6 +124,11 @@ pipeline { ./test-all.sh b1fq ''' sh''' + export LD_LIBRARY_PATH=${WKC}/debug/build/lib + cd ${WKC}/tests/system-test + ./fulltest.sh + ''' + sh''' cd ${WKC}/debug ctest ''' diff --git a/example/src/demoapi.c b/example/src/demoapi.c index 45da88fa1b..afa9e19d4d 100644 --- a/example/src/demoapi.c +++ b/example/src/demoapi.c @@ -176,7 +176,7 @@ static int print_result(char *tbname, TAOS_RES* res, int block) { } if (block) { - warnPrint("%s", "call taos_fetch_block()\n"); + warnPrint("%s", "call taos_fetch_block(), don't call taos_fetch_lengths()\n"); int rows = 0; while ((rows = taos_fetch_block(res, &row))) { int *lengths = taos_fetch_lengths(res); diff --git a/example/src/tmq.c b/example/src/tmq.c index fdd26bc95d..88fce7f4be 100644 --- a/example/src/tmq.c +++ b/example/src/tmq.c @@ -22,6 +22,7 @@ static int running = 1; static void msg_process(TAOS_RES* msg) { char buf[1024]; + memset(buf, 0, 1024); printf("topic: %s\n", tmq_get_topic_name(msg)); printf("vg:%d\n", tmq_get_vgroup_id(msg)); while (1) { @@ -140,7 +141,7 @@ int32_t create_topic() { return 0; } -void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets, void* param) { +void tmq_commit_cb_print(tmq_t* tmq, tmq_resp_err_t resp, tmq_topic_vgroup_list_t* offsets) { printf("commit %d\n", resp); } @@ -162,7 +163,7 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "td.connect.pass", "taosdata"); tmq_conf_set(conf, "td.connect.db", "abc1"); tmq_conf_set_offset_commit_cb(conf, tmq_commit_cb_print); - tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); + tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); return tmq; } @@ -188,7 +189,7 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { cnt++; /*printf("get data\n");*/ /*msg_process(tmqmessage);*/ - tmq_message_destroy(tmqmessage); + taos_free_result(tmqmessage); /*} else {*/ /*break;*/ } @@ -218,9 +219,9 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1000); if (tmqmessage) { msg_process(tmqmessage); - tmq_message_destroy(tmqmessage); + taos_free_result(tmqmessage); - if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); + /*if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0);*/ } } @@ -248,7 +249,7 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics) { batchCnt++; /*skipLogNum += tmqGetSkipLogNum(tmqmessage);*/ /*msg_process(tmqmessage);*/ - tmq_message_destroy(tmqmessage); + taos_free_result(tmqmessage); } else { break; } diff --git a/include/client/taos.h b/include/client/taos.h index 8f02d5610f..526edae8af 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -92,38 +92,14 @@ typedef struct taosField { typedef void (*__taos_async_fn_t)(void *param, TAOS_RES *, int code); -typedef struct TAOS_BIND { - int buffer_type; - void *buffer; - uintptr_t buffer_length; // unused - uintptr_t *length; - int *is_null; - - int is_unsigned; // unused - int *error; // unused - union { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - unsigned char *bin; - char *nchar; - } u; - unsigned int allocated; -} TAOS_BIND; - -typedef struct TAOS_MULTI_BIND { +typedef struct TAOS_BIND_v2 { int buffer_type; void *buffer; - uintptr_t buffer_length; + int32_t buffer_length; int32_t *length; char *is_null; int num; -} TAOS_MULTI_BIND; +} TAOS_BIND_v2; typedef enum { SET_CONF_RET_SUCC = 0, @@ -152,34 +128,34 @@ 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 *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 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 *bind); -DLL_EXPORT int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); -DLL_EXPORT int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int colIdx); -DLL_EXPORT int taos_stmt_add_batch(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_execute(TAOS_STMT *stmt); -DLL_EXPORT TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_close(TAOS_STMT *stmt); -DLL_EXPORT char *taos_stmt_errstr(TAOS_STMT *stmt); -DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); +DLL_EXPORT int taos_stmt_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 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_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_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); @@ -241,17 +217,17 @@ typedef struct tmq_conf_t tmq_conf_t; typedef struct tmq_list_t tmq_list_t; // typedef struct tmq_message_t tmq_message_t; -typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *, void *param)); +typedef void(tmq_commit_cb(tmq_t *, tmq_resp_err_t, tmq_topic_vgroup_list_t *)); DLL_EXPORT tmq_list_t *tmq_list_new(); DLL_EXPORT int32_t tmq_list_append(tmq_list_t *, const char *); DLL_EXPORT void tmq_list_destroy(tmq_list_t *); -#if 1 +#if 0 DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen); #endif -DLL_EXPORT tmq_t *tmq_consumer_new1(tmq_conf_t *conf, char *errstr, int32_t errstrLen); +DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen); DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t); @@ -295,14 +271,19 @@ int32_t tmqGetSkipLogNum(tmq_message_t *tmq_message); 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); +#endif + #if 0 DLL_EXPORT TAOS_ROW tmq_get_row(tmq_message_t *message); DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message); DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message); DLL_EXPORT TAOS_FIELD *tmq_get_fields(tmq_t *tmq, const char *topic); DLL_EXPORT int32_t tmq_field_count(tmq_t *tmq, const char *topic); -#endif DLL_EXPORT void tmq_message_destroy(TAOS_RES *res); +#endif /* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */ #if 0 DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen); diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 043f2d1d12..fa203e231a 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -54,12 +54,34 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet); BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \ } while (0) +#define colDataIsNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] == -1) +#define colDataSetNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] = -1) + +#define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT) + +#define colDataGetVarData(p1_, r_) ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) + +#define colDataGetNumData(p1_, r_) ((p1_)->pData + ((r_) * (p1_)->info.bytes)) +// SColumnInfoData, rowNumber +#define colDataGetData(p1_, r_) \ + ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) \ + : colDataGetNumData(p1_, r_)) + static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) { + if (pColumnInfoData->info.type == TSDB_DATA_TYPE_JSON){ + if(colDataIsNull_var(pColumnInfoData, row)){ + return true; + } + char *data = colDataGetVarData(pColumnInfoData, row); + return (*data == TSDB_DATA_TYPE_NULL); + } + if (!pColumnInfoData->hasNull) { return false; } - if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { - return pColumnInfoData->varmeta.offset[row] == -1; + + if (pColumnInfoData->info.type== TSDB_DATA_TYPE_VARCHAR || pColumnInfoData->info.type == TSDB_DATA_TYPE_NCHAR) { + return colDataIsNull_var(pColumnInfoData, row); } else { if (pColumnInfoData->nullbitmap == NULL) { return false; @@ -86,7 +108,7 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u } if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { - return pColumnInfoData->varmeta.offset[row] == -1; + return colDataIsNull_var(pColumnInfoData, row); } else { if (pColumnInfoData->nullbitmap == NULL) { return false; @@ -96,17 +118,10 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u } } -#define BitmapLen(_n) (((_n) + ((1 << NBIT) - 1)) >> NBIT) - -// SColumnInfoData, rowNumber -#define colDataGetData(p1_, r_) \ - ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \ - : ((p1_)->pData + ((r_) * (p1_)->info.bytes))) - static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uint32_t currentRow) { // There is a placehold for each NULL value of binary or nchar type. if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { - pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type. + colDataSetNull_var(pColumnInfoData, currentRow); // it is a null value of VAR type. } else { colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow); } @@ -117,7 +132,7 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, uint32_t start, size_t nRows) { if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { for (int32_t i = start; i < start + nRows; ++i) { - pColumnInfoData->varmeta.offset[i] = -1; // it is a null value of VAR type. + colDataSetNull_var(pColumnInfoData,i); // it is a null value of VAR type. } } else { for (int32_t i = start; i < start + nRows; ++i) { @@ -265,3 +280,4 @@ static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* da #endif #endif /*_TD_COMMON_EP_H_*/ + diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 8a87a1bd2e..a0f4351bbf 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -502,7 +502,7 @@ typedef struct { #define TD_KV_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t)) -#define kvRowLen(r) (*(TDRowLenT *)(r)) +#define kvRowLen(r) (*(uint16_t *)(r)) #define kvRowNCols(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(uint16_t))) #define kvRowSetLen(r, len) kvRowLen(r) = (len) #define kvRowSetNCols(r, n) kvRowNCols(r) = (n) @@ -608,7 +608,7 @@ void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder); void tdResetKVRowBuilder(SKVRowBuilder *pBuilder); SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder); -static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t colId, int8_t type, const void *value) { +static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t colId, const void *value, int32_t tlen) { if (pBuilder->nCols >= pBuilder->tCols) { pBuilder->tCols *= 2; SColIdx *pColIdx = (SColIdx *)taosMemoryRealloc((void *)(pBuilder->pColIdx), sizeof(SColIdx) * pBuilder->tCols); @@ -621,7 +621,6 @@ static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t co pBuilder->nCols++; - int32_t tlen = IS_VAR_DATA_TYPE(type) ? varDataTLen(value) : TYPE_BYTES[type]; if (tlen > pBuilder->alloc - pBuilder->size) { while (tlen > pBuilder->alloc - pBuilder->size) { pBuilder->alloc *= 2; diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 97f84f82d7..88ce0cd970 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -32,7 +32,6 @@ extern char tsLocalEp[]; extern uint16_t tsServerPort; extern int32_t tsVersion; extern int32_t tsStatusInterval; -extern bool tsEnableTelemetryReporting; // common extern int32_t tsRpcTimer; @@ -82,6 +81,12 @@ extern uint16_t tsMonitorPort; extern int32_t tsMonitorMaxLogs; extern bool tsMonitorComp; +// telem +extern bool tsEnableTelem; +extern int32_t tsTelemInterval; +extern char tsTelemServer[]; +extern uint16_t tsTelemPort; + // query buffer management extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing extern int64_t tsQueryBufferSizeBytes; // maximum allowed usage buffer size in byte for each data node diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 3ce6c1684b..9cac5fb0d1 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -269,6 +269,8 @@ typedef struct SSchema { #define SSCHMEA_BYTES(s) ((s)->bytes) #define SSCHMEA_NAME(s) ((s)->name) +STSchema* tdGetSTSChemaFromSSChema(SSchema** pSchema, int32_t nCols); + typedef struct { char name[TSDB_TABLE_FNAME_LEN]; int8_t igExists; @@ -322,13 +324,15 @@ typedef struct SEpSet { int32_t tEncodeSEpSet(SCoder* pEncoder, const SEpSet* pEp); int32_t tDecodeSEpSet(SCoder* pDecoder, SEpSet* pEp); int32_t taosEncodeSEpSet(void** buf, const SEpSet* pEp); -void* taosDecodeSEpSet(void* buf, SEpSet* pEp); +void* taosDecodeSEpSet(const void* buf, SEpSet* pEp); typedef struct { int8_t connType; int32_t pid; char app[TSDB_APP_NAME_LEN]; char db[TSDB_DB_NAME_LEN]; + char user[TSDB_USER_LEN]; + char passwd[TSDB_PASSWORD_LEN]; int64_t startTime; } SConnectReq; @@ -480,7 +484,7 @@ typedef struct { char intervalUnit; char slidingUnit; char - offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. + offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. int8_t precision; int64_t interval; int64_t sliding; @@ -658,6 +662,7 @@ typedef struct { int8_t outputType; int32_t outputLen; int32_t bufSize; + int32_t codeLen; int64_t signature; char* pComment; char* pCode; @@ -1270,11 +1275,16 @@ typedef struct { } SMVCreateStreamRsp, SMSCreateStreamRsp; typedef struct { - char name[TSDB_TOPIC_FNAME_LEN]; - int8_t igExists; - char* sql; - char* ast; - char subscribeDbName[TSDB_DB_NAME_LEN]; + char name[TSDB_TOPIC_FNAME_LEN]; + int8_t igExists; + int8_t withTbName; + int8_t withSchema; + int8_t withTag; + int8_t withTagSchema; + char* sql; + char* ast; + int64_t subDbUid; + char subscribeDbName[TSDB_DB_NAME_LEN]; } SCMCreateTopicReq; int32_t tSerializeSCMCreateTopicReq(void* buf, int32_t bufLen, const SCMCreateTopicReq* pReq); @@ -1288,10 +1298,14 @@ typedef struct { int32_t tSerializeSCMCreateTopicRsp(void* buf, int32_t bufLen, const SCMCreateTopicRsp* pRsp); int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicRsp* pRsp); +typedef struct { + int64_t consumerId; +} SMqConsumerLostMsg; + typedef struct { int32_t topicNum; int64_t consumerId; - char* consumerGroup; + char cgroup[TSDB_CGROUP_LEN]; SArray* topicNames; // SArray } SCMSubscribeReq; @@ -1299,7 +1313,7 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc int32_t tlen = 0; tlen += taosEncodeFixedI32(buf, pReq->topicNum); tlen += taosEncodeFixedI64(buf, pReq->consumerId); - tlen += taosEncodeString(buf, pReq->consumerGroup); + tlen += taosEncodeString(buf, pReq->cgroup); for (int32_t i = 0; i < pReq->topicNum; i++) { tlen += taosEncodeString(buf, (char*)taosArrayGetP(pReq->topicNames, i)); @@ -1310,7 +1324,7 @@ static FORCE_INLINE int32_t tSerializeSCMSubscribeReq(void** buf, const SCMSubsc static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq* pReq) { buf = taosDecodeFixedI32(buf, &pReq->topicNum); buf = taosDecodeFixedI64(buf, &pReq->consumerId); - buf = taosDecodeString(buf, &pReq->consumerGroup); + buf = taosDecodeStringTo(buf, pReq->cgroup); pReq->topicNames = taosArrayInit(pReq->topicNum, sizeof(void*)); for (int32_t i = 0; i < pReq->topicNum; i++) { char* name; @@ -1386,10 +1400,10 @@ static FORCE_INLINE void* tDeserializeSMVSubscribeReq(void* buf, SMVSubscribeReq } typedef struct { - const char* key; - SArray* lostConsumers; // SArray - SArray* removedConsumers; // SArray - SArray* newConsumers; // SArray + char key[TSDB_SUBSCRIBE_KEY_LEN]; + SArray* lostConsumers; // SArray + SArray* removedConsumers; // SArray + SArray* newConsumers; // SArray } SMqRebSubscribe; static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) { @@ -1397,7 +1411,7 @@ static FORCE_INLINE SMqRebSubscribe* tNewSMqRebSubscribe(const char* key) { if (pRebSub == NULL) { goto _err; } - pRebSub->key = strdup(key); + strcpy(pRebSub->key, key); pRebSub->lostConsumers = taosArrayInit(0, sizeof(int64_t)); if (pRebSub->lostConsumers == NULL) { goto _err; @@ -1422,6 +1436,7 @@ _err: // this message is sent from mnode to mnode(read thread to write thread), so there is no need for serialization or // deserialization typedef struct { + int8_t* mqInReb; SHashObj* rebSubHash; // SHashObj } SMqDoRebalanceMsg; @@ -1924,6 +1939,64 @@ static FORCE_INLINE void* taosDecodeSMqMsg(void* buf, SMqHbMsg* pMsg) { return buf; } +enum { + TOPIC_SUB_TYPE__DB = 1, + TOPIC_SUB_TYPE__TABLE, +}; + +typedef struct { + int64_t leftForVer; + int32_t vgId; + int64_t oldConsumerId; + int64_t newConsumerId; + char subKey[TSDB_SUBSCRIBE_KEY_LEN]; + int8_t subType; + int8_t withTbName; + int8_t withSchema; + int8_t withTag; + int8_t withTagSchema; + char* qmsg; +} SMqRebVgReq; + +static FORCE_INLINE int32_t tEncodeSMqRebVgReq(void** buf, const SMqRebVgReq* 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->subKey); + tlen += taosEncodeFixedI8(buf, pReq->subType); + tlen += taosEncodeFixedI8(buf, pReq->withTbName); + tlen += taosEncodeFixedI8(buf, pReq->withSchema); + tlen += taosEncodeFixedI8(buf, pReq->withTag); + tlen += taosEncodeFixedI8(buf, pReq->withTagSchema); + if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { + tlen += taosEncodeString(buf, pReq->qmsg); + } + return tlen; +} + +static FORCE_INLINE void* tDecodeSMqRebVgReq(const void* buf, SMqRebVgReq* pReq) { + buf = taosDecodeFixedI64(buf, &pReq->leftForVer); + buf = taosDecodeFixedI32(buf, &pReq->vgId); + buf = taosDecodeFixedI64(buf, &pReq->oldConsumerId); + buf = taosDecodeFixedI64(buf, &pReq->newConsumerId); + buf = taosDecodeStringTo(buf, pReq->subKey); + buf = taosDecodeFixedI8(buf, &pReq->subType); + buf = taosDecodeFixedI8(buf, &pReq->withTbName); + buf = taosDecodeFixedI8(buf, &pReq->withSchema); + buf = taosDecodeFixedI8(buf, &pReq->withTag); + buf = taosDecodeFixedI8(buf, &pReq->withTagSchema); + if (pReq->subType == TOPIC_SUB_TYPE__TABLE) { + buf = taosDecodeString(buf, &pReq->qmsg); + } + return (void*)buf; +} + +typedef struct { + int8_t reserved; +} SMqRebVgRsp; + typedef struct { int64_t leftForVer; int32_t vgId; @@ -2394,6 +2467,7 @@ typedef struct { int64_t consumerId; } SMqRspHead; +#if 0 typedef struct { SMsgHead head; @@ -2407,6 +2481,17 @@ typedef struct { uint64_t reqId; char topic[TSDB_TOPIC_FNAME_LEN]; } SMqPollReq; +#endif + +typedef struct { + SMsgHead head; + char subKey[TSDB_SUBSCRIBE_KEY_LEN]; + int32_t epoch; + uint64_t reqId; + int64_t consumerId; + int64_t blockingTime; + int64_t currentOffset; +} SMqPollReqV2; typedef struct { int32_t vgId; @@ -2480,13 +2565,81 @@ static FORCE_INLINE void* tDecodeSMqPollRspV2(const void* buf, SMqPollRspV2* pRs return (void*)buf; } +typedef struct { + SMqRspHead head; + int64_t reqOffset; + int64_t rspOffset; + int32_t skipLogNum; + int32_t blockNum; + int8_t withTbName; + int8_t withSchema; + int8_t withTag; + int8_t withTagSchema; + SArray* blockDataLen; // SArray + SArray* blockData; // SArray + SArray* blockTbName; // SArray + SArray* blockSchema; // SArray + SArray* blockTags; // SArray + SArray* blockTagSchema; // SArray +} SMqDataBlkRsp; + +static FORCE_INLINE int32_t tEncodeSMqDataBlkRsp(void** buf, const SMqDataBlkRsp* pRsp) { + int32_t tlen = 0; + tlen += taosEncodeFixedI64(buf, pRsp->reqOffset); + tlen += taosEncodeFixedI64(buf, pRsp->rspOffset); + tlen += taosEncodeFixedI32(buf, pRsp->skipLogNum); + tlen += taosEncodeFixedI32(buf, pRsp->blockNum); + if (pRsp->blockNum != 0) { + tlen += taosEncodeFixedI8(buf, pRsp->withTbName); + tlen += taosEncodeFixedI8(buf, pRsp->withSchema); + tlen += taosEncodeFixedI8(buf, pRsp->withTag); + tlen += taosEncodeFixedI8(buf, pRsp->withTagSchema); + + for (int32_t i = 0; i < pRsp->blockNum; i++) { + int32_t bLen = *(int32_t*)taosArrayGet(pRsp->blockDataLen, i); + void* data = taosArrayGetP(pRsp->blockData, i); + tlen += taosEncodeFixedI32(buf, bLen); + tlen += taosEncodeBinary(buf, data, bLen); + } + } + return tlen; +} + +static FORCE_INLINE void* tDecodeSMqDataBlkRsp(const void* buf, SMqDataBlkRsp* pRsp) { + buf = taosDecodeFixedI64(buf, &pRsp->reqOffset); + buf = taosDecodeFixedI64(buf, &pRsp->rspOffset); + buf = taosDecodeFixedI32(buf, &pRsp->skipLogNum); + buf = taosDecodeFixedI32(buf, &pRsp->blockNum); + pRsp->blockData = taosArrayInit(pRsp->blockNum, sizeof(void*)); + pRsp->blockDataLen = taosArrayInit(pRsp->blockNum, sizeof(void*)); + if (pRsp->blockNum != 0) { + buf = taosDecodeFixedI8(buf, &pRsp->withTbName); + buf = taosDecodeFixedI8(buf, &pRsp->withSchema); + buf = taosDecodeFixedI8(buf, &pRsp->withTag); + buf = taosDecodeFixedI8(buf, &pRsp->withTagSchema); + + for (int32_t i = 0; i < pRsp->blockNum; i++) { + int32_t bLen = 0; + void* data = NULL; + buf = taosDecodeFixedI32(buf, &bLen); + buf = taosDecodeBinary(buf, &data, bLen); + taosArrayPush(pRsp->blockDataLen, &bLen); + taosArrayPush(pRsp->blockData, &data); + } + } + return (void*)buf; +} + typedef struct { SMqRspHead head; char cgroup[TSDB_CGROUP_LEN]; SArray* topics; // SArray } SMqCMGetSubEpRsp; -static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { taosArrayDestroy(pSubTopicEp->vgs); } +static FORCE_INLINE void tDeleteSMqSubTopicEp(SMqSubTopicEp* pSubTopicEp) { + // taosMemoryFree(pSubTopicEp->schema.pSchema); + taosArrayDestroy(pSubTopicEp->vgs); +} static FORCE_INLINE int32_t tEncodeSMqSubVgEp(void** buf, const SMqSubVgEp* pVgEp) { int32_t tlen = 0; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index e519a84615..7387e51e81 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -146,6 +146,7 @@ enum { 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_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) TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-mq-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp) TD_DEF_MSG_TYPE(TDMT_MND_CREATE_STREAM, "mnode-create-stream", SCMCreateStreamReq, SCMCreateStreamRsp) @@ -177,6 +178,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CONN, "vnode-mq-set-conn", SMqSetCVgReq, SMqSetCVgRsp) TD_DEF_MSG_TYPE(TDMT_VND_MQ_REB, "vnode-mq-mv-rebalance", SMqMVRebReq, SMqMVRebRsp) TD_DEF_MSG_TYPE(TDMT_VND_MQ_CANCEL_CONN, "vnode-mq-mv-cancel-conn", SMqCancelConnReq, SMqCancelConnRsp) + TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp) TD_DEF_MSG_TYPE(TDMT_VND_MQ_SET_CUR, "vnode-mq-set-cur", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_RES_READY, "vnode-res-ready", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_TASKS_STATUS, "vnode-tasks-status", NULL, NULL) diff --git a/include/common/trow.h b/include/common/trow.h index 40462a7eef..7b0c009a11 100644 --- a/include/common/trow.h +++ b/include/common/trow.h @@ -219,7 +219,7 @@ static FORCE_INLINE void *tdKVRowColVal(STSRow *pRow, SKvRowIdx *pIdx) { return #define TD_ROW_OFFSET(p) ((p)->toffset); // During ParseInsert when without STSchema, how to get the offset for STpRow? -void tdMergeBitmap(uint8_t *srcBitmap, int32_t srcLen, uint8_t *dstBitmap); +void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap); static FORCE_INLINE void tdRowCopy(void *dst, STSRow *row) { memcpy(dst, row, TD_ROW_LEN(row)); } static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType); static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType); @@ -308,8 +308,8 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, // use literal value directly and not use formula to simplify the codes switch (nOffset) { case 0: + *pDestByte = ((*pDestByte) & 0x3F) | (valType << 6); // set the value and clear other partitions for offset 0 - *pDestByte = (valType << 6); // *pDestByte |= (valType << 6); break; case 1: @@ -417,8 +417,8 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T // use literal value directly and not use formula to simplify the codes switch (nOffset) { case 0: + *pDestByte = ((*pDestByte) & 0x7F) | (valType << 7); // set the value and clear other partitions for offset 0 - *pDestByte = (valType << 7); // *pDestByte |= (valType << 7); break; case 1: @@ -684,6 +684,43 @@ static int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) { return TSDB_CODE_SUCCESS; } +/** + * @brief The invoker is responsible for memory alloc/dealloc. + * + * @param pBuilder + * @param pBuf Output buffer of STSRow + */ +static int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) { + pBuilder->pBuf = (STSRow *)pBuf; + if (!pBuilder->pBuf) { + TASSERT(0); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + TASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0); + + uint32_t len = 0; + switch (pBuilder->rowType) { + case TD_ROW_TP: +#ifdef TD_SUPPORT_BITMAP + pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen); +#endif + break; + case TD_ROW_KV: +#ifdef TD_SUPPORT_BITMAP + pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols); +#endif + break; + default: + TASSERT(0); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + return TSDB_CODE_SUCCESS; +} + + /** * @brief 由调用方管理存储空间的分配及释放,一次输入多个参数 * @@ -1107,11 +1144,11 @@ static FORCE_INLINE bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col if (TD_IS_TP_ROW(pIter->pRow)) { STColumn *pCol = NULL; STSchema *pSchema = pIter->pSchema; - while (pIter->colIdx <= pSchema->numOfCols) { + while (pIter->colIdx < pSchema->numOfCols) { pCol = &pSchema->columns[pIter->colIdx]; // 1st column of schema is primary TS key if (colId == pCol->colId) { break; - } else if (colId < pCol->colId) { + } else if (pCol->colId < colId) { ++pIter->colIdx; continue; } else { @@ -1237,6 +1274,101 @@ static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, return result; } +static void tdSCellValPrint(SCellVal *pVal, int8_t colType) { + if (tdValTypeIsNull(pVal->valType)) { + printf("NULL "); + return; + } else if (tdValTypeIsNone(pVal->valType)) { + printf("NONE "); + return; + } + switch (colType) { + case TSDB_DATA_TYPE_BOOL: + printf("%s ", (*(int8_t *)pVal->val) == 0 ? "false" : "true"); + break; + case TSDB_DATA_TYPE_TINYINT: + printf("%" PRIi8 " ", *(int8_t *)pVal->val); + break; + case TSDB_DATA_TYPE_SMALLINT: + printf("%" PRIi16 " ", *(int16_t *)pVal->val); + break; + case TSDB_DATA_TYPE_INT: + printf("%" PRIi32 " ", *(int32_t *)pVal->val); + break; + case TSDB_DATA_TYPE_BIGINT: + printf("%" PRIi64 " ", *(int64_t *)pVal->val); + break; + case TSDB_DATA_TYPE_FLOAT: + printf("%f ", *(float *)pVal->val); + break; + case TSDB_DATA_TYPE_DOUBLE: + printf("%lf ", *(double *)pVal->val); + break; + case TSDB_DATA_TYPE_VARCHAR: + printf("VARCHAR "); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + printf("%" PRIi64 " ", *(int64_t *)pVal->val); + break; + case TSDB_DATA_TYPE_NCHAR: + printf("NCHAR "); + break; + case TSDB_DATA_TYPE_UTINYINT: + printf("%" PRIu8 " ", *(uint8_t *)pVal->val); + break; + case TSDB_DATA_TYPE_USMALLINT: + printf("%" PRIu16 " ", *(uint16_t *)pVal->val); + break; + case TSDB_DATA_TYPE_UINT: + printf("%" PRIu32 " ", *(uint32_t *)pVal->val); + break; + case TSDB_DATA_TYPE_UBIGINT: + printf("%" PRIu64 " ", *(uint64_t *)pVal->val); + break; + case TSDB_DATA_TYPE_JSON: + printf("JSON "); + break; + case TSDB_DATA_TYPE_VARBINARY: + printf("VARBIN "); + break; + case TSDB_DATA_TYPE_DECIMAL: + printf("DECIMAL "); + break; + case TSDB_DATA_TYPE_BLOB: + printf("BLOB "); + break; + case TSDB_DATA_TYPE_MEDIUMBLOB: + printf("MedBLOB "); + break; + // case TSDB_DATA_TYPE_BINARY: + // printf("BINARY "); + // break; + case TSDB_DATA_TYPE_MAX: + printf("UNDEF "); + break; + default: + printf("UNDEF "); + break; + } +} + +static void tdSRowPrint(STSRow *row, STSchema *pSchema) { + STSRowIter iter = {0}; + tdSTSRowIterInit(&iter, pSchema); + tdSTSRowIterReset(&iter, row); + printf(">>>"); + for (int i = 0; i < pSchema->numOfCols; ++i) { + STColumn *stCol = pSchema->columns + i; + SCellVal sVal = {.valType = 255, .val = NULL}; + if (!tdSTSRowIterNext(&iter, stCol->colId, stCol->type, &sVal)) { + break; + } + ASSERT(sVal.valType == 0 || sVal.valType == 1 || sVal.valType == 2); + tdSCellValPrint(&sVal, stCol->type); + } + printf("\n"); +} + #ifdef TROW_ORIGIN_HZ typedef struct { uint32_t nRows; diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 5d8227daa1..39858cbbde 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -148,94 +148,95 @@ #define TK_VARIABLES 130 #define TK_BNODES 131 #define TK_SNODES 132 -#define TK_LIKE 133 -#define TK_INDEX 134 -#define TK_FULLTEXT 135 -#define TK_FUNCTION 136 -#define TK_INTERVAL 137 -#define TK_TOPIC 138 -#define TK_AS 139 -#define TK_DESC 140 -#define TK_DESCRIBE 141 -#define TK_RESET 142 -#define TK_QUERY 143 -#define TK_EXPLAIN 144 -#define TK_ANALYZE 145 -#define TK_VERBOSE 146 -#define TK_NK_BOOL 147 -#define TK_RATIO 148 -#define TK_COMPACT 149 -#define TK_VNODES 150 -#define TK_IN 151 -#define TK_OUTPUTTYPE 152 -#define TK_AGGREGATE 153 -#define TK_BUFSIZE 154 -#define TK_STREAM 155 -#define TK_INTO 156 -#define TK_TRIGGER 157 -#define TK_AT_ONCE 158 -#define TK_WINDOW_CLOSE 159 -#define TK_WATERMARK 160 -#define TK_KILL 161 -#define TK_CONNECTION 162 -#define TK_MERGE 163 -#define TK_VGROUP 164 -#define TK_REDISTRIBUTE 165 -#define TK_SPLIT 166 -#define TK_SYNCDB 167 -#define TK_NULL 168 -#define TK_NK_QUESTION 169 -#define TK_NK_ARROW 170 -#define TK_ROWTS 171 -#define TK_TBNAME 172 -#define TK_QSTARTTS 173 -#define TK_QENDTS 174 -#define TK_WSTARTTS 175 -#define TK_WENDTS 176 -#define TK_WDURATION 177 -#define TK_CAST 178 -#define TK_NOW 179 -#define TK_TODAY 180 -#define TK_TIMEZONE 181 -#define TK_COUNT 182 -#define TK_FIRST 183 -#define TK_LAST 184 -#define TK_LAST_ROW 185 -#define TK_BETWEEN 186 -#define TK_IS 187 -#define TK_NK_LT 188 -#define TK_NK_GT 189 -#define TK_NK_LE 190 -#define TK_NK_GE 191 -#define TK_NK_NE 192 -#define TK_MATCH 193 -#define TK_NMATCH 194 -#define TK_CONTAINS 195 -#define TK_JOIN 196 -#define TK_INNER 197 -#define TK_SELECT 198 -#define TK_DISTINCT 199 -#define TK_WHERE 200 -#define TK_PARTITION 201 -#define TK_BY 202 -#define TK_SESSION 203 -#define TK_STATE_WINDOW 204 -#define TK_SLIDING 205 -#define TK_FILL 206 -#define TK_VALUE 207 -#define TK_NONE 208 -#define TK_PREV 209 -#define TK_LINEAR 210 -#define TK_NEXT 211 -#define TK_GROUP 212 -#define TK_HAVING 213 -#define TK_ORDER 214 -#define TK_SLIMIT 215 -#define TK_SOFFSET 216 -#define TK_LIMIT 217 -#define TK_OFFSET 218 -#define TK_ASC 219 -#define TK_NULLS 220 +#define TK_CLUSTER 133 +#define TK_LIKE 134 +#define TK_INDEX 135 +#define TK_FULLTEXT 136 +#define TK_FUNCTION 137 +#define TK_INTERVAL 138 +#define TK_TOPIC 139 +#define TK_AS 140 +#define TK_DESC 141 +#define TK_DESCRIBE 142 +#define TK_RESET 143 +#define TK_QUERY 144 +#define TK_EXPLAIN 145 +#define TK_ANALYZE 146 +#define TK_VERBOSE 147 +#define TK_NK_BOOL 148 +#define TK_RATIO 149 +#define TK_COMPACT 150 +#define TK_VNODES 151 +#define TK_IN 152 +#define TK_OUTPUTTYPE 153 +#define TK_AGGREGATE 154 +#define TK_BUFSIZE 155 +#define TK_STREAM 156 +#define TK_INTO 157 +#define TK_TRIGGER 158 +#define TK_AT_ONCE 159 +#define TK_WINDOW_CLOSE 160 +#define TK_WATERMARK 161 +#define TK_KILL 162 +#define TK_CONNECTION 163 +#define TK_MERGE 164 +#define TK_VGROUP 165 +#define TK_REDISTRIBUTE 166 +#define TK_SPLIT 167 +#define TK_SYNCDB 168 +#define TK_NULL 169 +#define TK_NK_QUESTION 170 +#define TK_NK_ARROW 171 +#define TK_ROWTS 172 +#define TK_TBNAME 173 +#define TK_QSTARTTS 174 +#define TK_QENDTS 175 +#define TK_WSTARTTS 176 +#define TK_WENDTS 177 +#define TK_WDURATION 178 +#define TK_CAST 179 +#define TK_NOW 180 +#define TK_TODAY 181 +#define TK_TIMEZONE 182 +#define TK_COUNT 183 +#define TK_FIRST 184 +#define TK_LAST 185 +#define TK_LAST_ROW 186 +#define TK_BETWEEN 187 +#define TK_IS 188 +#define TK_NK_LT 189 +#define TK_NK_GT 190 +#define TK_NK_LE 191 +#define TK_NK_GE 192 +#define TK_NK_NE 193 +#define TK_MATCH 194 +#define TK_NMATCH 195 +#define TK_CONTAINS 196 +#define TK_JOIN 197 +#define TK_INNER 198 +#define TK_SELECT 199 +#define TK_DISTINCT 200 +#define TK_WHERE 201 +#define TK_PARTITION 202 +#define TK_BY 203 +#define TK_SESSION 204 +#define TK_STATE_WINDOW 205 +#define TK_SLIDING 206 +#define TK_FILL 207 +#define TK_VALUE 208 +#define TK_NONE 209 +#define TK_PREV 210 +#define TK_LINEAR 211 +#define TK_NEXT 212 +#define TK_GROUP 213 +#define TK_HAVING 214 +#define TK_ORDER 215 +#define TK_SLIMIT 216 +#define TK_SOFFSET 217 +#define TK_LIMIT 218 +#define TK_OFFSET 219 +#define TK_ASC 220 +#define TK_NULLS 221 #define TK_NK_SPACE 300 #define TK_NK_COMMENT 301 diff --git a/include/common/ttypes.h b/include/common/ttypes.h index 7f2e59ea85..405b20c521 100644 --- a/include/common/ttypes.h +++ b/include/common/ttypes.h @@ -49,7 +49,7 @@ typedef struct { #define varDataCopy(dst, v) memcpy((dst), (void *)(v), varDataTLen(v)) #define varDataLenByData(v) (*(VarDataLenT *)(((char *)(v)) - VARSTR_HEADER_SIZE)) #define varDataSetLen(v, _len) (((VarDataLenT *)(v))[0] = (VarDataLenT)(_len)) -#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR)) +#define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_VARCHAR) || ((t) == TSDB_DATA_TYPE_NCHAR) || ((t) == TSDB_DATA_TYPE_JSON)) #define varDataNetLen(v) (htons(((VarDataLenT *)(v))[0])) #define varDataNetTLen(v) (sizeof(VarDataLenT) + varDataNetLen(v)) @@ -252,7 +252,7 @@ typedef struct tDataTypeDescriptor { int64_t *max, int64_t *sum, int16_t *minindex, int16_t *maxindex, int16_t *numofnull); } tDataTypeDescriptor; -extern tDataTypeDescriptor tDataTypes[15]; +extern tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX]; bool isValidDataType(int32_t type); diff --git a/include/dnode/mnode/sdb/sdb.h b/include/dnode/mnode/sdb/sdb.h index a28c093e85..d7d53ad1d0 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/include/dnode/mnode/sdb/sdb.h @@ -92,7 +92,13 @@ extern "C" { typedef struct SMnode SMnode; typedef struct SSdbRaw SSdbRaw; typedef struct SSdbRow SSdbRow; -typedef enum { SDB_KEY_BINARY = 1, SDB_KEY_INT32 = 2, SDB_KEY_INT64 = 3 } EKeyType; + +typedef enum { + SDB_KEY_BINARY = 1, + SDB_KEY_INT32 = 2, + SDB_KEY_INT64 = 3, +} EKeyType; + typedef enum { SDB_STATUS_INIT = 0, SDB_STATUS_CREATING = 1, diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 22bbc36ee1..cd49e88b2f 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -110,7 +110,10 @@ typedef enum EFunctionType { FUNCTION_TYPE_QENDTS, FUNCTION_TYPE_WSTARTTS, FUNCTION_TYPE_WENDTS, - FUNCTION_TYPE_WDURATION + FUNCTION_TYPE_WDURATION, + + // user defined funcion + FUNCTION_TYPE_UDF = 10000 } EFunctionType; struct SqlFunctionCtx; @@ -138,6 +141,7 @@ bool fmIsWindowClauseFunc(int32_t funcId); bool fmIsSpecialDataRequiredFunc(int32_t funcId); bool fmIsDynamicScanOptimizedFunc(int32_t funcId); bool fmIsMultiResFunc(int32_t funcId); +bool fmIsUserDefinedFunc(int32_t funcId); typedef enum EFuncDataRequired { FUNC_DATA_REQUIRED_DATA_LOAD = 1, diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 84f2d9ed6b..0394dfd9bd 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -295,6 +295,16 @@ typedef struct SDropStreamStmt { bool ignoreNotExists; } SDropStreamStmt; +typedef struct SCreateFunctionStmt { + ENodeType type; + bool ignoreExists; + char funcName[TSDB_FUNC_NAME_LEN]; + bool isAgg; + char libraryPath[PATH_MAX]; + SDataType outputDt; + int32_t bufSize; +} SCreateFunctionStmt; + #ifdef __cplusplus } #endif diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 8db93ee5f9..a47bf4caee 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -48,6 +48,9 @@ extern "C" { (NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \ cell1 = cell1->pNext, cell2 = cell2->pNext) +#define REPLACE_LIST1_NODE(newNode) cell1->pNode = (SNode*)(newNode) +#define REPLACE_LIST2_NODE(newNode) cell2->pNode = (SNode*)(newNode) + #define FOREACH_FOR_REWRITE(node, list) \ for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext) @@ -134,6 +137,7 @@ typedef enum ENodeType { QUERY_NODE_SHOW_QNODES_STMT, QUERY_NODE_SHOW_SNODES_STMT, QUERY_NODE_SHOW_BNODES_STMT, + QUERY_NODE_SHOW_CLUSTER_STMT, QUERY_NODE_SHOW_DATABASES_STMT, QUERY_NODE_SHOW_FUNCTIONS_STMT, QUERY_NODE_SHOW_INDEXES_STMT, diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index 01e03a983d..b4a290cbfc 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -155,7 +155,6 @@ typedef struct SLogicSubplan { typedef struct SQueryLogicPlan { ENodeType type; - int32_t totalLevel; SNodeList* pTopSubplans; } SQueryLogicPlan; diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index d2f73e4071..143224d8f5 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -229,10 +229,10 @@ typedef struct SFillNode { typedef struct SSelectStmt { ENodeType type; // QUERY_NODE_SELECT_STMT bool isDistinct; - SNodeList* pProjectionList; // SNode + SNodeList* pProjectionList; SNode* pFromTable; SNode* pWhere; - SNodeList* pPartitionByList; // SNode + SNodeList* pPartitionByList; SNode* pWindow; SNodeList* pGroupByList; // SGroupingSetNode SNode* pHaving; @@ -245,12 +245,14 @@ typedef struct SSelectStmt { } SSelectStmt; typedef enum ESetOperatorType { - SET_OP_TYPE_UNION_ALL = 1 + SET_OP_TYPE_UNION_ALL = 1, + SET_OP_TYPE_UNION } ESetOperatorType; typedef struct SSetOperator { ENodeType type; // QUERY_NODE_SET_OPERATOR ESetOperatorType opType; + SNodeList* pProjectionList; SNode* pLeft; SNode* pRight; SNodeList* pOrderByList; // SOrderByExprNode @@ -283,12 +285,12 @@ typedef struct SVgDataBlocks { } 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 { diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 02cd073226..58482735ba 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -21,6 +21,15 @@ extern "C" { #endif #include "querynodes.h" +#include "query.h" + +typedef struct SStmtCallback { + TAOS_STMT* pStmt; + int32_t (*getTbNameFn)(TAOS_STMT*, char**); + int32_t (*setBindInfoFn)(TAOS_STMT*, STableMeta*, void*); + int32_t (*setExecInfoFn)(TAOS_STMT*, SHashObj*, SHashObj*); + int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**); +} SStmtCallback; typedef struct SParseContext { uint64_t requestId; @@ -34,6 +43,7 @@ typedef struct SParseContext { char *pMsg; // extended error message if exists to help identifying the problem in sql statement. int32_t msgLen; // max length of the msg struct SCatalog *pCatalog; + SStmtCallback *pStmtCb; } SParseContext; typedef struct SCmdMsgInfo { @@ -66,11 +76,27 @@ typedef struct SQuery { } SQuery; int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery); +bool isInsertSql(const char* pStr, size_t length); void qDestroyQuery(SQuery* pQueryNode); int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema); +int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash); +int32_t qResetStmtDataBlock(void* block, bool keepBuf); +int32_t qCloneStmtDataBlock(void** pDst, void* pSrc); +void qFreeStmtDataBlock(void* pDataBlock); +int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc); +void qDestroyStmtDataBlock(void* pBlock); +int32_t qBindStmtColsValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen); +int32_t qBindStmtSingleColValue(void *pBlock, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum); +int32_t qBuildStmtColFields(void *pDataBlock, int32_t *fieldNum, TAOS_FIELD** fields); +int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields); +int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_BIND_v2 *bind, char *msgBuf, int32_t msgBufLen); +void destroyBoundColumnInfo(void* pBoundInfo); +int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen); + + #ifdef __cplusplus } #endif diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index f343295c56..851d4d63c5 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -30,6 +30,7 @@ typedef struct SPlanContext { SNode* pAstRoot; bool topicQuery; bool streamQuery; + bool rSmaQuery; bool showRewrite; int8_t triggerType; int64_t watermark; @@ -45,7 +46,6 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo // @pSource one execution location of this group of datasource subplans int32_t qSetSubplanExecutionNode(SSubplan* pSubplan, int32_t groupId, SDownstreamSourceNode* pSource); -typedef TAOS_MULTI_BIND TAOS_BIND_v2; // todo remove int32_t qStmtBindParam(SQueryPlan* pPlan, TAOS_BIND_v2* pParams); // Convert to subplan to string for the scheduler to send to the executor diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index 7d765bf139..0c7db45c4b 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -76,6 +76,7 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp /* Time related functions */ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); +int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t nowFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); diff --git a/include/util/talgo.h b/include/util/talgo.h index 0fd44a6e91..ebddce62a8 100644 --- a/include/util/talgo.h +++ b/include/util/talgo.h @@ -27,6 +27,11 @@ extern "C" { typedef int32_t (*__compar_fn_t)(const void *, const void *); #endif +typedef void *(*FCopy)(void *); +typedef void (*FDelete)(void *); +typedef int32_t (*FEncode)(void **buf, const void *dst); +typedef void *(*FDecode)(const void *buf, void *dst); + #define TD_EQ 0x1 #define TD_GT 0x2 #define TD_LT 0x4 diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 6c5e006671..215e83c7d4 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -132,6 +132,9 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_INVALID_JSON_TYPE TAOS_DEF_ERROR_CODE(0, 0x0222) #define TSDB_CODE_TSC_VALUE_OUT_OF_RANGE TAOS_DEF_ERROR_CODE(0, 0x0223) #define TSDB_CODE_TSC_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0X0224) +#define TSDB_CODE_TSC_STMT_API_ERROR TAOS_DEF_ERROR_CODE(0, 0X0225) +#define TSDB_CODE_TSC_STMT_TBNAME_ERROR TAOS_DEF_ERROR_CODE(0, 0X0226) +#define TSDB_CODE_TSC_STMT_CLAUSE_ERROR TAOS_DEF_ERROR_CODE(0, 0X0227) // mnode-common #define TSDB_CODE_MND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0300) @@ -279,6 +282,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_UNSUPPORTED_TOPIC TAOS_DEF_ERROR_CODE(0, 0x03E8) #define TSDB_CODE_MND_SUBSCRIBE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03E9) #define TSDB_CODE_MND_OFFSET_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03EA) +#define TSDB_CODE_MND_CONSUMER_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x03EB) // mnode-stream #define TSDB_CODE_MND_STREAM_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03F0) @@ -609,6 +613,8 @@ int32_t* taosGetErrno(); #define TSDB_CODE_PAR_INTER_SLIDING_UNIT TAOS_DEF_ERROR_CODE(0, 0x2630) #define TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x2631) #define TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2632) +#define TSDB_CODE_PAR_ONLY_ONE_JSON_TAG TAOS_DEF_ERROR_CODE(0, 0x2633) +#define TSDB_CODE_PAR_INCORRECT_NUM_OF_COL TAOS_DEF_ERROR_CODE(0, 0x2634) //planner #define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700) diff --git a/include/util/tarray.h b/include/util/tarray.h index 383af8309d..a41bcd9349 100644 --- a/include/util/tarray.h +++ b/include/util/tarray.h @@ -41,10 +41,10 @@ extern "C" { #define TARRAY_GET_START(array) ((array)->pData) typedef struct SArray { - size_t size; + size_t size; uint32_t capacity; uint32_t elemSize; - void* pData; + void* pData; } SArray; /** @@ -199,6 +199,13 @@ SArray* taosArrayFromList(const void* src, size_t size, size_t elemSize); */ SArray* taosArrayDup(const SArray* pSrc); +/** + * deep copy a new array + * @param pSrc + */ +SArray* taosArrayDeepCopy(const SArray* pSrc, FCopy deepCopy); + + /** * clear the array (remove all element) * @param pArray @@ -212,19 +219,9 @@ void taosArrayClear(SArray* pArray); */ void taosArrayClearEx(SArray* pArray, void (*fp)(void*)); - -/** - * destroy array list - * @param pArray - */ void* taosArrayDestroy(SArray* pArray); - -/** - * - * @param pArray - * @param fp - */ -void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)); +void taosArrayDestroyP(SArray* pArray, FDelete fp); +void taosArrayDestroyEx(SArray* pArray, FDelete fp); /** * sort the array @@ -272,6 +269,9 @@ char* taosArraySearchString(const SArray* pArray, const char* key, __compar_fn_t void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param); +int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode); +void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz); + #ifdef __cplusplus } #endif diff --git a/include/util/tcompare.h b/include/util/tcompare.h index cc9e8ae464..ed07ae1c9c 100644 --- a/include/util/tcompare.h +++ b/include/util/tcompare.h @@ -105,6 +105,8 @@ int32_t compareStrPatternNotMatch(const void *pLeft, const void *pRight); int32_t compareWStrPatternMatch(const void *pLeft, const void *pRight); int32_t compareWStrPatternNotMatch(const void *pLeft, const void *pRight); +int32_t compareJsonContainsKey(const void *pLeft, const void *pRight); + __compar_fn_t getComparFunc(int32_t type, int32_t optr); __compar_fn_t getKeyComparFunc(int32_t keyType, int32_t order); int32_t doCompare(const char *a, const char *b, int32_t type, size_t size); diff --git a/include/util/tdef.h b/include/util/tdef.h index c379eb1cf6..2548df7186 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -239,6 +239,8 @@ typedef enum ELogicConditionType { #define TSDB_FUNC_BUF_SIZE 512 #define TSDB_FUNC_TYPE_SCALAR 1 #define TSDB_FUNC_TYPE_AGGREGATE 2 +#define TSDB_FUNC_SCRIPT_BIN_LIB 0 +#define TSDB_FUNC_SCRIPT_LUA 1 #define TSDB_FUNC_MAX_RETRIEVE 1024 #define TSDB_INDEX_NAME_LEN 65 // 64 + 1 '\0' @@ -271,6 +273,8 @@ typedef enum ELogicConditionType { #define TSDB_MAX_TAGS 128 #define TSDB_MAX_TAG_CONDITIONS 1024 +#define TSDB_MAX_JSON_TAG_LEN 16384 + #define TSDB_AUTH_LEN 16 #define TSDB_PASSWORD_LEN 32 #define TSDB_USET_PASSWORD_LEN 129 diff --git a/include/util/tjson.h b/include/util/tjson.h index 6b2221f704..28bcb3cfc6 100644 --- a/include/util/tjson.h +++ b/include/util/tjson.h @@ -76,6 +76,7 @@ char* tjsonToString(const SJson* pJson); char* tjsonToUnformattedString(const SJson* pJson); SJson* tjsonParse(const char* pStr); +bool tjsonValidateJson(const char* pJson); #ifdef __cplusplus } diff --git a/include/util/tlog.h b/include/util/tlog.h index d3ab9b0bfb..32421a59cc 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -59,6 +59,7 @@ extern int32_t sDebugFlag; extern int32_t tsdbDebugFlag; extern int32_t tqDebugFlag; extern int32_t fsDebugFlag; +extern int32_t fnDebugFlag; int32_t taosInitLog(const char *logName, int32_t maxFiles); void taosCloseLog(); diff --git a/include/util/tutil.h b/include/util/tutil.h index e0f92be76a..444a893a88 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -26,8 +26,6 @@ extern "C" { #endif int32_t strdequote(char *src); -int32_t strndequote(char *dst, const char *z, int32_t len); -int32_t strRmquote(char *z, int32_t len); size_t strtrim(char *src); char *strnchr(const char *haystack, char needle, int32_t len, bool skipquote); char **strsplit(char *src, const char *delim, int32_t *num); diff --git a/packaging/install.sh b/packaging/install.sh index 9ce7fc326a..740d356f80 100755 --- a/packaging/install.sh +++ b/packaging/install.sh @@ -30,6 +30,15 @@ bin_dir="/usr/local/taos/bin" service_config_dir="/etc/systemd/system" +#taos-tools para +demoName="taosdemo" +benchmarkName="taosBenchmark" +dumpName="taosdump" +emailName="taosdata.com" +taosName="taos" +toolsName="taostools" + + # Color setting RED='\033[0;31m' GREEN='\033[1;32m' @@ -230,8 +239,20 @@ function install_header() { # temp install taosBenchmark function install_taosTools() { - cd ${script_dir}/taos-tools/ - tar xvf taosTools-1.4.1-Linux-x64.tar.gz && cd taosTools-1.4.1/ && ./install-taostools.sh + ${csudo} rm -f ${bin_link_dir}/${benchmarkName} || : + ${csudo} rm -f ${bin_link_dir}/${dumpName} || : + ${csudo} rm -f ${bin_link_dir}/rm${toolsName} || : + + ${csudo} /usr/bin/install -c -m 755 ${script_dir}/bin/${dumpName} ${install_main_dir}/bin/${dumpName} + ${csudo} /usr/bin/install -c -m 755 ${script_dir}/bin/${benchmarkName} ${install_main_dir}/bin/${benchmarkName} + ${csudo} ln -sf ${install_main_dir}/bin/${benchmarkName} ${install_main_dir}/bin/${demoName} + #Make link + [[ -x ${install_main_dir}/bin/${benchmarkName} ]] && \ + ${csudo} ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName} || : + [[ -x ${install_main_dir}/bin/${demoName} ]] && \ + ${csudo} ln -s ${install_main_dir}/bin/${demoName} ${bin_link_dir}/${demoName} || : + [[ -x ${install_main_dir}/bin/${dumpName} ]] && \ + ${csudo} ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || : } function add_newHostname_to_hosts() { diff --git a/packaging/release.sh b/packaging/release.sh index adf1195e56..a56d991bf8 100755 --- a/packaging/release.sh +++ b/packaging/release.sh @@ -39,7 +39,7 @@ cd ${compile_dir} echo "compile_dir: ${compile_dir}" -cmake .. +cmake .. -DBUILD_TOOLS=true make -j32 release_dir="${top_dir}/release" @@ -55,7 +55,6 @@ mkdir -p ${install_dir} mkdir -p ${install_dir}/bin mkdir -p ${install_dir}/lib mkdir -p ${install_dir}/inc -mkdir -p ${install_dir}/taos-tools install_files="${script_dir}/install.sh" chmod a+x ${script_dir}/install.sh || : @@ -64,13 +63,14 @@ cp ${install_files} ${install_dir} header_files="${top_dir}/include/client/taos.h ${top_dir}/include/util/taoserror.h" cp ${header_files} ${install_dir}/inc -bin_files="${compile_dir}/build/bin/taosd ${compile_dir}/build/bin/taos ${compile_dir}/build/bin/create_table ${compile_dir}/build/bin/tmq_sim ${script_dir}/remove.sh" -cp ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || : +bin_files="${compile_dir}/source/dnode/mgmt/taosd ${compile_dir}/tools/shell/taos ${compile_dir}/tests/test/c/create_table ${compile_dir}/tests/test/c/tmq_sim ${script_dir}/remove.sh ${compile_dir}/build/bin/taosBenchmark ${compile_dir}/build/bin/taosdump" +cp -rf ${bin_files} ${install_dir}/bin && chmod a+x ${install_dir}/bin/* || : + +cp -rf ${compile_dir}/source/client/libtaos.so ${install_dir}/lib/ +cp -rf ${compile_dir}/source/libs/tdb/libtdb.so ${install_dir}/lib/ +cp -rf ${compile_dir}/build/lib/libavro* ${install_dir}/lib/ > /dev/null || echo -e "failed to copy avro libraries" +cp -rf ${compile_dir}/build/lib/pkgconfig ${install_dir}/lib/ > /dev/null || echo -e "failed to copy pkgconfig directory" -cp ${compile_dir}/build/lib/libtaos.so ${install_dir}/lib/ -cp ${compile_dir}/build/lib/libtdb.so ${install_dir}/lib/ -taostoolfile="${top_dir}/tools/taosTools-1.4.1-Linux-x64.tar.gz" -cp ${taostoolfile} ${install_dir}/taos-tools #cp ${compile_dir}/source/dnode/mnode/impl/libmnode.so ${install_dir}/lib/ #cp ${compile_dir}/source/dnode/qnode/libqnode.so ${install_dir}/lib/ diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 772ff5e69a..00a58e16a7 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -44,7 +44,7 @@ extern "C" { } while (0) #define ERROR_MSG_BUF_DEFAULT_SIZE 512 -#define HEARTBEAT_INTERVAL 1500 // ms +#define HEARTBEAT_INTERVAL 1500 // ms enum { RES_TYPE__QUERY = 1, @@ -187,11 +187,13 @@ typedef struct SRequestSendRecvBody { } SRequestSendRecvBody; typedef struct { - int8_t resType; - char* topic; - SArray* res; // SArray - int32_t resIter; - int32_t vgId; + int8_t resType; + char topic[TSDB_TOPIC_FNAME_LEN]; + int32_t vgId; + SSchemaWrapper schema; + int32_t resIter; + SMqDataBlkRsp rsp; + SReqResultInfo resInfo; } SMqRspObj; typedef struct SRequestObj { @@ -203,7 +205,8 @@ typedef struct SRequestObj { char* sqlstr; // sql string int32_t sqlLen; int64_t self; - char* msgBuf; // error msg buffer + char* msgBuf; + int32_t msgBufLen; int32_t code; SArray* dbList; SArray* tableList; @@ -211,16 +214,24 @@ typedef struct SRequestObj { SRequestSendRecvBody body; } SRequestObj; +void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); +void doSetOneRowPtr(SReqResultInfo* pResultInfo); +void setResPrecision(SReqResultInfo* pResInfo, int32_t precision); +int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); +void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); + static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) { SMqRspObj* msg = (SMqRspObj*)res; - int32_t resIter = msg->resIter == -1 ? 0 : msg->resIter; - return (SReqResultInfo*)taosArrayGet(msg->res, resIter); + return (SReqResultInfo*)&msg->resInfo; } -static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res) { +static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res, bool convertUcs4) { SMqRspObj* msg = (SMqRspObj*)res; - if (++msg->resIter < taosArrayGetSize(msg->res)) { - return (SReqResultInfo*)taosArrayGet(msg->res, msg->resIter); + msg->resIter++; + if (msg->resIter < msg->rsp.blockNum) { + SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)taosArrayGetP(msg->rsp.blockData, msg->resIter); + setQueryResultFromRsp(&msg->resInfo, pRetrieve, convertUcs4); + return &msg->resInfo; } return NULL; } @@ -238,25 +249,25 @@ extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code); SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pReqObj); -int taos_init(); +int taos_init(); -void* createTscObj(const char* user, const char* auth, const char* db, SAppInstInfo* pAppInfo); -void destroyTscObj(void* pObj); -STscObj *acquireTscObj(int64_t rid); -int32_t releaseTscObj(int64_t rid); +void* createTscObj(const char* user, const char* auth, const char* db, SAppInstInfo* pAppInfo); +void destroyTscObj(void* pObj); +STscObj* acquireTscObj(int64_t rid); +int32_t releaseTscObj(int64_t rid); uint64_t generateRequestId(); -void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); -void destroyRequest(SRequestObj* pRequest); -SRequestObj *acquireRequest(int64_t rid); -int32_t releaseRequest(int64_t rid); +void* createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type); +void destroyRequest(SRequestObj* pRequest); +SRequestObj* acquireRequest(int64_t rid); +int32_t releaseRequest(int64_t rid); char* getDbOfConnection(STscObj* pObj); void setConnectionDB(STscObj* pTscObj, const char* db); void resetConnectDB(STscObj* pTscObj); -int taos_options_imp(TSDB_OPTION option, const char* str); +int taos_options_imp(TSDB_OPTION option, const char* str); void* openTransporter(const char* user, const char* auth, int32_t numOfThreads); @@ -268,17 +279,12 @@ void initMsgHandleFp(); TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, uint16_t port, int connType); -int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery); +int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb); + int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest); -void* doFetchRows(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4); -void doSetOneRowPtr(SReqResultInfo* pResultInfo); -void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols); -void setResPrecision(SReqResultInfo* pResInfo, int32_t precision); -int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4); - // --- heartbeat // global, called by mgmt int hbMgrInit(); @@ -290,7 +296,7 @@ SAppHbMgr* appHbMgrInit(SAppInstInfo* pAppInstInfo, char* key); void appHbMgrCleanup(void); // conn level -int hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); +int hbRegisterConn(SAppHbMgr* pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType); void hbDeregisterConn(SAppHbMgr* pAppHbMgr, SClientHbKey connKey); int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* value, int32_t keyLen, int32_t valueLen); @@ -298,6 +304,8 @@ int hbAddConnInfo(SAppHbMgr* pAppHbMgr, SClientHbKey connKey, void* key, void* v // --- mq void hbMgrInitMqHbRspHandle(); +SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery); + #ifdef __cplusplus } #endif diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index c29361758d..219257ba74 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -19,6 +19,9 @@ #ifdef __cplusplus extern "C" { #endif +#include "catalog.h" + +typedef void STableDataBlocks; typedef enum { STMT_TYPE_INSERT = 1, @@ -26,17 +29,64 @@ typedef enum { STMT_TYPE_QUERY, } STMT_TYPE; -typedef struct STscStmt { - STMT_TYPE type; - //int16_t last; - //STscObj* taos; - //SSqlObj* pSql; - //SMultiTbStmt mtb; - //SNormalStmt normal; +typedef enum { + STMT_INIT = 1, + STMT_PREPARE, + STMT_SETTBNAME, + STMT_SETTAGS, + STMT_FETCH_TAG_FIELDS, + STMT_FETCH_COL_FIELDS, + STMT_BIND, + STMT_BIND_COL, + STMT_ADD_BATCH, + STMT_EXECUTE, +} STMT_STATUS; - //int numOfRows; +typedef struct SStmtTableCache { + STableDataBlocks* pDataBlock; + void* boundTags; +} SStmtTableCache; + +typedef struct SStmtBindInfo { + bool needParse; + uint64_t tbUid; + uint64_t tbSuid; + int32_t sBindRowNum; + int32_t sBindLastIdx; + int8_t tbType; + void* boundTags; + char* tbName; + SName sname; +} SStmtBindInfo; + +typedef struct SStmtExecInfo { + SRequestObj* pRequest; + SHashObj* pVgHash; + SHashObj* pBlockHash; +} SStmtExecInfo; + +typedef struct SStmtSQLInfo { + STMT_TYPE type; + STMT_STATUS status; + bool autoCreate; + uint64_t runTimes; + SHashObj* pTableCache; //SHash + SQuery* pQuery; + char* sqlStr; + int32_t sqlLen; +} SStmtSQLInfo; + +typedef struct STscStmt { + STscObj* taos; + SCatalog* pCatalog; + int32_t affectedRows; + + SStmtSQLInfo sql; + SStmtExecInfo exec; + SStmtBindInfo bInfo; } STscStmt; + #define STMT_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0) #define STMT_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define STMT_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) @@ -44,16 +94,16 @@ typedef struct STscStmt { TAOS_STMT *stmtInit(TAOS *taos); int stmtClose(TAOS_STMT *stmt); int stmtExec(TAOS_STMT *stmt); -char *stmtErrstr(TAOS_STMT *stmt); +const char *stmtErrstr(TAOS_STMT *stmt); int stmtAffectedRows(TAOS_STMT *stmt); -int stmtBind(TAOS_STMT *stmt, TAOS_BIND *bind); int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length); -int stmtSetTbNameTags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags); +int stmtSetTbName(TAOS_STMT *stmt, const char *tbName); +int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags); int stmtIsInsert(TAOS_STMT *stmt, int *insert); int stmtGetParamNum(TAOS_STMT *stmt, int *nums); int stmtAddBatch(TAOS_STMT *stmt); TAOS_RES *stmtUseResult(TAOS_STMT *stmt); -int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind); +int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx); #ifdef __cplusplus diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index ad736fb195..0b75e3a30b 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -186,6 +186,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty pRequest->pTscObj = pObj; pRequest->body.fp = fp; // not used it yet pRequest->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE); + pRequest->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE; tsem_init(&pRequest->body.rspSem, 0, 0); registerRequest(pRequest); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 6a29c7a8fd..10edb38bf1 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -146,7 +146,8 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj* (*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlLen = sqlLen; - if (taosHashPut(pTscObj->pRequests, &(*pRequest)->self, sizeof((*pRequest)->self), &(*pRequest)->self, sizeof((*pRequest)->self))) { + if (taosHashPut(pTscObj->pRequests, &(*pRequest)->self, sizeof((*pRequest)->self), &(*pRequest)->self, + sizeof((*pRequest)->self))) { destroyRequest(*pRequest); *pRequest = NULL; tscError("put request to request hash failed"); @@ -157,7 +158,7 @@ int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj* return TSDB_CODE_SUCCESS; } -int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { +int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb) { STscObj* pTscObj = pRequest->pTscObj; SParseContext cxt = { @@ -170,6 +171,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery) { .pMsg = pRequest->msgBuf, .msgLen = ERROR_MSG_BUF_DEFAULT_SIZE, .pTransporter = pTscObj->pAppInfo->pTransporter, + .pStmtCb = pStmtCb, }; cxt.mgmtEpSet = getEpSet_s(&pTscObj->pAppInfo->mgmtEp); @@ -262,7 +264,8 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t } void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) { - if (precision != TSDB_TIME_PRECISION_MILLI && precision != TSDB_TIME_PRECISION_MICRO && precision != TSDB_TIME_PRECISION_NANO) { + if (precision != TSDB_TIME_PRECISION_MILLI && precision != TSDB_TIME_PRECISION_MICRO && + precision != TSDB_TIME_PRECISION_NANO) { return; } @@ -274,7 +277,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); @@ -298,15 +301,8 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList return pRequest->code; } -SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { - SRequestObj* pRequest = NULL; - SQuery* pQuery = NULL; - SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); - - int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); - if (TSDB_CODE_SUCCESS == code) { - code = parseSql(pRequest, false, &pQuery); - } +SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery) { + SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); if (TSDB_CODE_SUCCESS == code) { switch (pQuery->execMode) { @@ -331,7 +327,10 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { } taosArrayDestroy(pNodeList); - qDestroyQuery(pQuery); + if (!keepQuery) { + qDestroyQuery(pQuery); + } + if (NULL != pRequest && TSDB_CODE_SUCCESS != code) { pRequest->code = terrno; } @@ -339,6 +338,18 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) { return pRequest; } +SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen) { + SRequestObj* pRequest = NULL; + SQuery* pQuery = NULL; + + int32_t code = buildRequest(pTscObj, sql, sqlLen, &pRequest); + if (TSDB_CODE_SUCCESS == code) { + code = parseSql(pRequest, false, &pQuery, NULL); + } + + return launchQueryImpl(pRequest, pQuery, code, false); +} + int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) { SCatalog* pCatalog = NULL; int32_t code = 0; @@ -383,7 +394,7 @@ SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) { int32_t code = 0; while (retryNum++ < REQUEST_MAX_TRY_TIMES) { - pRequest = execQueryImpl(pTscObj, sql, sqlLen); + pRequest = launchQuery(pTscObj, sql, sqlLen); if (TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) { break; } @@ -512,6 +523,8 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest, int8_t connType) { connectReq.pid = htonl(appInfo.pid); connectReq.startTime = htobe64(appInfo.startTime); tstrncpy(connectReq.app, appInfo.appName, sizeof(connectReq.app)); + tstrncpy(connectReq.user, pObj->user, sizeof(connectReq.user)); + tstrncpy(connectReq.passwd, pObj->pass, sizeof(connectReq.passwd)); int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); void* pReq = taosMemoryMalloc(contLen); @@ -715,6 +728,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p)); ASSERT(len <= bytes); + ASSERT((p + len) < (pResultInfo->convertBuf[i] + colLength[i])); varDataSetLen(p, len); pCol->offset[j] = (p - pResultInfo->convertBuf[i]); @@ -725,6 +739,80 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; pResultInfo->row[i] = pResultInfo->pCol[i].pData; } + + if (type == TSDB_DATA_TYPE_JSON) { + char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pResultInfo->convertBuf[i] = p; + int32_t len = 0; + SResultColumn* pCol = &pResultInfo->pCol[i]; + for (int32_t j = 0; j < numOfRows; ++j) { + if (pCol->offset[j] != -1) { + char* pStart = pCol->offset[j] + pCol->pData; + + int32_t jsonInnerType = *pStart; + char* jsonInnerData = pStart + CHAR_BYTES; + char dst[TSDB_MAX_JSON_TAG_LEN] = {0}; + if (jsonInnerType == TSDB_DATA_TYPE_NULL) { + sprintf(varDataVal(dst), "%s", TSDB_DATA_NULL_STR_L); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else if (jsonInnerType == TSDB_DATA_TYPE_JSON) { + int32_t length = + taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), varDataVal(dst)); + + if (length <= 0) { + tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, + varDataVal(jsonInnerData)); + length = 0; + } + varDataSetLen(dst, length); + } else if (jsonInnerType == TSDB_DATA_TYPE_NCHAR) { // value -> "value" + *(char*)varDataVal(dst) = '\"'; + int32_t length = taosUcs4ToMbs((TdUcs4*)varDataVal(jsonInnerData), varDataLen(jsonInnerData), + varDataVal(dst) + CHAR_BYTES); + if (length <= 0) { + tscError("charset:%s to %s. val:%s convert failed.", DEFAULT_UNICODE_ENCODEC, tsCharset, + varDataVal(jsonInnerData)); + length = 0; + } + varDataSetLen(dst, length + CHAR_BYTES * 2); + *(char*)(varDataVal(dst), length + CHAR_BYTES) = '\"'; + } else if (jsonInnerType == TSDB_DATA_TYPE_DOUBLE) { + double jsonVd = *(double*)(jsonInnerData); + sprintf(varDataVal(dst), "%.9lf", jsonVd); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else if (jsonInnerType == TSDB_DATA_TYPE_BIGINT) { + int64_t jsonVd = *(int64_t*)(jsonInnerData); + sprintf(varDataVal(dst), "%" PRId64, jsonVd); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else if (jsonInnerType == TSDB_DATA_TYPE_BOOL) { + sprintf(varDataVal(dst), "%s", (*((char*)jsonInnerData) == 1) ? "true" : "false"); + varDataSetLen(dst, strlen(varDataVal(dst))); + } else { + ASSERT(0); + } + + if (len + varDataTLen(dst) > colLength[i]) { + p = taosMemoryRealloc(pResultInfo->convertBuf[i], len + varDataTLen(dst)); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pResultInfo->convertBuf[i] = p; + } + p = pResultInfo->convertBuf[i] + len; + memcpy(p, dst, varDataTLen(dst)); + pCol->offset[j] = len; + len += varDataTLen(dst); + } + } + + pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i]; + pResultInfo->row[i] = pResultInfo->pCol[i].pData; + } } return TSDB_CODE_SUCCESS; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 903018d5c3..e730f0a34a 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -14,12 +14,12 @@ */ #include "catalog.h" -#include "scheduler.h" #include "clientInt.h" -#include "clientStmt.h" #include "clientLog.h" +#include "clientStmt.h" #include "os.h" #include "query.h" +#include "scheduler.h" #include "tglobal.h" #include "tmsg.h" #include "tref.h" @@ -128,6 +128,10 @@ const char *taos_errstr(TAOS_RES *res) { } void taos_free_result(TAOS_RES *res) { + if (NULL == res) { + return; + } + if (TD_RES_QUERY(res)) { SRequestObj *pRequest = (SRequestObj *)res; destroyRequest(pRequest); @@ -177,25 +181,24 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return doFetchRows(pRequest, true, true); } else if (TD_RES_TMQ(res)) { - SMqRspObj *msg = ((SMqRspObj *)res); - if (msg->resIter == -1) msg->resIter++; - SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter); + SMqRspObj *msg = ((SMqRspObj *)res); + SReqResultInfo *pResultInfo; + if (msg->resIter == -1) { + pResultInfo = tmqGetNextResInfo(res, true); + } else { + pResultInfo = tmqGetCurResInfo(res); + } if (pResultInfo->current < pResultInfo->numOfRows) { doSetOneRowPtr(pResultInfo); pResultInfo->current += 1; return pResultInfo->row; } else { - msg->resIter++; - if (msg->resIter < taosArrayGetSize(msg->res)) { - pResultInfo = taosArrayGet(msg->res, msg->resIter); - doSetOneRowPtr(pResultInfo); - pResultInfo->current += 1; - return pResultInfo->row; - } else { - return NULL; - } + pResultInfo = tmqGetNextResInfo(res, true); + if (pResultInfo == NULL) return NULL; + doSetOneRowPtr(pResultInfo); + pResultInfo->current += 1; + return pResultInfo->row; } - } else { // assert to avoid un-initialization error ASSERT(0); @@ -455,7 +458,7 @@ int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) { (*numOfRows) = pResultInfo->numOfRows; return pRequest->code; } else if (TD_RES_TMQ(res)) { - SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, true); if (pResultInfo == NULL) return -1; pResultInfo->current = pResultInfo->numOfRows; @@ -474,7 +477,7 @@ int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) { } if (TD_RES_TMQ(res)) { - SReqResultInfo *pResultInfo = tmqGetNextResInfo(res); + SReqResultInfo *pResultInfo = tmqGetNextResInfo(res, false); if (pResultInfo == NULL) { (*numOfRows) = 0; return 0; @@ -580,56 +583,6 @@ TAOS_STMT *taos_stmt_init(TAOS *taos) { return stmtInit(taos); } -int taos_stmt_close(TAOS_STMT *stmt) { - if (stmt == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - - return stmtClose(stmt); -} - -int taos_stmt_execute(TAOS_STMT *stmt) { - if (stmt == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - - return stmtExec(stmt); -} - -char *taos_stmt_errstr(TAOS_STMT *stmt) { - if (stmt == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return NULL; - } - - return stmtErrstr(stmt); -} - -int taos_stmt_affected_rows(TAOS_STMT *stmt) { - if (stmt == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return 0; - } - - return stmtAffectedRows(stmt); -} - -int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND *bind) { - if (stmt == NULL || bind == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - - return stmtBind(stmt, bind); -} - int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { if (stmt == NULL || sql == NULL) { tscError("NULL parameter for %s", __FUNCTION__); @@ -640,14 +593,23 @@ int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { return stmtPrepare(stmt, sql, length); } -int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags) { - if (stmt == NULL || name == NULL || tags == NULL) { +int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_BIND_v2 *tags) { + if (stmt == NULL || name == NULL) { tscError("NULL parameter for %s", __FUNCTION__); terrno = TSDB_CODE_INVALID_PARA; return terrno; } - return stmtSetTbNameTags(stmt, name, tags); + int32_t code = stmtSetTbName(stmt, name); + if (code) { + return code; + } + + if (tags) { + return stmtSetTbTags(stmt, tags); + } + + return TSDB_CODE_SUCCESS; } int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { @@ -657,7 +619,75 @@ int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name) { return terrno; } - return stmtSetTbNameTags(stmt, name, NULL); + return stmtSetTbName(stmt, name); +} + +int taos_stmt_bind_param(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) { + if (stmt == NULL || bind == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + if (bind->num > 1) { + tscError("invalid bind number %d for %s", bind->num, __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtBindBatch(stmt, bind, -1); +} + +int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) { + if (stmt == NULL || bind == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + if (bind->num <= 0 || bind->num > INT16_MAX) { + tscError("invalid bind num %d", bind->num); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtBindBatch(stmt, bind, -1); +} + +int taos_stmt_bind_single_param_batch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int colIdx) { + if (stmt == NULL || bind == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + if (colIdx < 0) { + tscError("invalid bind column idx %d", colIdx); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtBindBatch(stmt, bind, colIdx); +} + +int taos_stmt_add_batch(TAOS_STMT *stmt) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtAddBatch(stmt); +} + +int taos_stmt_execute(TAOS_STMT *stmt) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } + + return stmtExec(stmt); } int taos_stmt_is_insert(TAOS_STMT *stmt, int *insert) { @@ -680,16 +710,6 @@ int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) { return stmtGetParamNum(stmt, nums); } -int taos_stmt_add_batch(TAOS_STMT *stmt) { - if (stmt == NULL) { - tscError("NULL parameter for %s", __FUNCTION__); - terrno = TSDB_CODE_INVALID_PARA; - return terrno; - } - - return stmtAddBatch(stmt); -} - TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { if (stmt == NULL) { tscError("NULL parameter for %s", __FUNCTION__); @@ -700,20 +720,32 @@ TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) { return stmtUseResult(stmt); } -int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { - if (stmt == NULL || bind == NULL) { +char *taos_stmt_errstr(TAOS_STMT *stmt) { + return (char *)stmtErrstr(stmt); +} + +int taos_stmt_affected_rows(TAOS_STMT *stmt) { + if (stmt == NULL) { + tscError("NULL parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_INVALID_PARA; + return 0; + } + + return stmtAffectedRows(stmt); +} + +int taos_stmt_close(TAOS_STMT *stmt) { + if (stmt == NULL) { tscError("NULL parameter for %s", __FUNCTION__); terrno = TSDB_CODE_INVALID_PARA; return terrno; } - return stmtBindBatch(stmt, bind); + return stmtClose(stmt); } - TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) { // TODO return NULL; } - diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 8c4cff9251..8a5134e02a 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -4,86 +4,539 @@ #include "clientStmt.h" #include "tdef.h" +int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) { + switch (newStatus) { + case STMT_SETTBNAME: + break; + default: + break; + } + + //STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + + pStmt->sql.status = newStatus; + + return TSDB_CODE_SUCCESS; +} + + +int32_t stmtGetTbName(TAOS_STMT *stmt, char **tbName) { + STscStmt* pStmt = (STscStmt*)stmt; + + pStmt->sql.type = STMT_TYPE_MULTI_INSERT; + + if (NULL == pStmt->bInfo.tbName) { + tscError("no table name set"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_TBNAME_ERROR); + } + + *tbName = pStmt->bInfo.tbName; + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) { + STscStmt* pStmt = (STscStmt*)stmt; + + pStmt->bInfo.tbUid = pTableMeta->uid; + pStmt->bInfo.tbSuid = pTableMeta->suid; + pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.boundTags = tags; + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtSetExecInfo(TAOS_STMT* stmt, SHashObj* pVgHash, SHashObj* pBlockHash) { + STscStmt* pStmt = (STscStmt*)stmt; + + pStmt->exec.pVgHash = pVgHash; + pStmt->exec.pBlockHash = pBlockHash; + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtGetExecInfo(TAOS_STMT* stmt, SHashObj** pVgHash, SHashObj** pBlockHash) { + STscStmt* pStmt = (STscStmt*)stmt; + + *pVgHash = pStmt->exec.pVgHash; + *pBlockHash = pStmt->exec.pBlockHash; + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtCacheBlock(STscStmt *pStmt) { + if (pStmt->sql.type != STMT_TYPE_MULTI_INSERT) { + return TSDB_CODE_SUCCESS; + } + + uint64_t uid; + if (TSDB_CHILD_TABLE == pStmt->bInfo.tbType) { + uid = pStmt->bInfo.tbSuid; + } else { + ASSERT(TSDB_NORMAL_TABLE == pStmt->bInfo.tbType); + uid = pStmt->bInfo.tbUid; + } + + if (taosHashGet(pStmt->sql.pTableCache, &uid, sizeof(uid))) { + return TSDB_CODE_SUCCESS; + } + + STableDataBlocks** pSrc = taosHashGet(pStmt->exec.pBlockHash, &uid, sizeof(uid)); + STableDataBlocks* pDst = NULL; + + STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc)); + + SStmtTableCache cache = { + .pDataBlock = pDst, + .boundTags = pStmt->bInfo.boundTags, + }; + + if (taosHashPut(pStmt->sql.pTableCache, &uid, sizeof(uid), &cache, sizeof(cache))) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pStmt->bInfo.boundTags = NULL; + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtParseSql(STscStmt* pStmt) { + SStmtCallback stmtCb = { + .pStmt = pStmt, + .getTbNameFn = stmtGetTbName, + .setBindInfoFn = stmtSetBindInfo, + .setExecInfoFn = stmtSetExecInfo, + .getExecInfoFn = stmtGetExecInfo, + }; + + if (NULL == pStmt->exec.pRequest) { + STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); + } + + STMT_ERR_RET(parseSql(pStmt->exec.pRequest, false, &pStmt->sql.pQuery, &stmtCb)); + + pStmt->bInfo.needParse = false; + + switch (nodeType(pStmt->sql.pQuery->pRoot)) { + case QUERY_NODE_VNODE_MODIF_STMT: + if (0 == pStmt->sql.type) { + pStmt->sql.type = STMT_TYPE_INSERT; + } + break; + case QUERY_NODE_SELECT_STMT: + pStmt->sql.type = STMT_TYPE_QUERY; + break; + default: + tscError("not supported stmt type %d", nodeType(pStmt->sql.pQuery->pRoot)); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_CLAUSE_ERROR); + } + + STMT_ERR_RET(stmtCacheBlock(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtCleanBindInfo(STscStmt* pStmt) { + pStmt->bInfo.tbUid = 0; + pStmt->bInfo.tbSuid = 0; + pStmt->bInfo.tbType = 0; + pStmt->bInfo.needParse = true; + + taosMemoryFreeClear(pStmt->bInfo.tbName); + destroyBoundColumnInfo(pStmt->bInfo.boundTags); + taosMemoryFreeClear(pStmt->bInfo.boundTags); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtCleanExecInfo(STscStmt* pStmt, bool keepTable) { + taos_free_result(pStmt->exec.pRequest); + pStmt->exec.pRequest = NULL; + + void *pIter = taosHashIterate(pStmt->exec.pBlockHash, NULL); + while (pIter) { + STableDataBlocks* pBlocks = *(STableDataBlocks**)pIter; + uint64_t *key = taosHashGetKey(pIter, NULL); + + if (keepTable && (*key == pStmt->bInfo.tbUid)) { + STMT_ERR_RET(qResetStmtDataBlock(pBlocks, true)); + + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + continue; + } + + qFreeStmtDataBlock(pBlocks); + taosHashRemove(pStmt->exec.pBlockHash, key, sizeof(*key)); + + pIter = taosHashIterate(pStmt->exec.pBlockHash, pIter); + } + + if (keepTable) { + return TSDB_CODE_SUCCESS; + } + + taosHashCleanup(pStmt->exec.pBlockHash); + pStmt->exec.pBlockHash = NULL; + + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtCleanSQLInfo(STscStmt* pStmt) { + taosMemoryFree(pStmt->sql.sqlStr); + qDestroyQuery(pStmt->sql.pQuery); + + void *pIter = taosHashIterate(pStmt->sql.pTableCache, NULL); + while (pIter) { + SStmtTableCache* pCache = (SStmtTableCache*)pIter; + + qDestroyStmtDataBlock(pCache->pDataBlock); + destroyBoundColumnInfo(pCache->boundTags); + + pIter = taosHashIterate(pStmt->sql.pTableCache, pIter); + } + taosHashCleanup(pStmt->sql.pTableCache); + pStmt->sql.pTableCache = NULL; + + memset(&pStmt->sql, 0, sizeof(pStmt->sql)); + + STMT_ERR_RET(stmtCleanExecInfo(pStmt, false)); + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtGetFromCache(STscStmt* pStmt) { + pStmt->bInfo.needParse = true; + + if (NULL == pStmt->sql.pTableCache || taosHashGetSize(pStmt->sql.pTableCache) <= 0) { + return TSDB_CODE_SUCCESS; + } + + if (NULL == pStmt->pCatalog) { + STMT_ERR_RET(catalogGetHandle(pStmt->taos->pAppInfo->clusterId, &pStmt->pCatalog)); + } + + STableMeta *pTableMeta = NULL; + SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp); + STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta)); + + if (pTableMeta->uid == pStmt->bInfo.tbUid) { + pStmt->bInfo.needParse = false; + + return TSDB_CODE_SUCCESS; + } + + if (taosHashGet(pStmt->exec.pBlockHash, &pTableMeta->uid, sizeof(pTableMeta->uid))) { + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid)); + if (NULL == pCache) { + tscError("table uid %" PRIx64 "found in exec blockHash, but not in sql blockHash", pTableMeta->uid); + STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); + } + + pStmt->bInfo.needParse = false; + + pStmt->bInfo.tbUid = pTableMeta->uid; + pStmt->bInfo.tbSuid = pTableMeta->suid; + pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.boundTags = pCache->boundTags; + + return TSDB_CODE_SUCCESS; + } + + SStmtTableCache* pCache = taosHashGet(pStmt->sql.pTableCache, &pTableMeta->uid, sizeof(pTableMeta->uid)); + if (pCache) { + pStmt->bInfo.needParse = false; + + pStmt->bInfo.tbUid = pTableMeta->uid; + pStmt->bInfo.tbSuid = pTableMeta->suid; + pStmt->bInfo.tbType = pTableMeta->tableType; + pStmt->bInfo.boundTags = pCache->boundTags; + + STableDataBlocks* pNewBlock = NULL; + STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock)); + + if (taosHashPut(pStmt->exec.pBlockHash, &pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid), &pNewBlock, POINTER_BYTES)) { + STMT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + } + + return TSDB_CODE_SUCCESS; + } + + STMT_ERR_RET(stmtCleanBindInfo(pStmt)); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtResetStmt(STscStmt* pStmt) { + STMT_ERR_RET(stmtCleanSQLInfo(pStmt)); + + pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (NULL == pStmt->sql.pTableCache) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + STMT_ERR_RET(terrno); + } + + pStmt->sql.status = STMT_INIT; + + return TSDB_CODE_SUCCESS; +} + + TAOS_STMT *stmtInit(TAOS *taos) { STscObj* pObj = (STscObj*)taos; STscStmt* pStmt = NULL; -#if 0 pStmt = taosMemoryCalloc(1, sizeof(STscStmt)); - if (pStmt == NULL) { + if (NULL == pStmt) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tscError("failed to allocate memory for statement"); return NULL; } + + pStmt->sql.pTableCache = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + if (NULL == pStmt->sql.pTableCache) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + taosMemoryFree(pStmt); + return NULL; + } + pStmt->taos = pObj; - - SSqlObj* pSql = calloc(1, sizeof(SSqlObj)); - - if (pSql == NULL) { - free(pStmt); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tscError("failed to allocate memory for statement"); - return NULL; - } - - if (TSDB_CODE_SUCCESS != tscAllocPayload(&pSql->cmd, TSDB_DEFAULT_PAYLOAD_SIZE)) { - free(pSql); - free(pStmt); - terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; - tscError("failed to malloc payload buffer"); - return NULL; - } - - tsem_init(&pSql->rspSem, 0, 0); - pSql->signature = pSql; - pSql->pTscObj = pObj; - pSql->maxRetry = TSDB_MAX_REPLICA; - pStmt->pSql = pSql; - pStmt->last = STMT_INIT; - pStmt->numOfRows = 0; - registerSqlObj(pSql); -#endif - + pStmt->bInfo.needParse = true; + pStmt->sql.status = STMT_INIT; + return pStmt; } -int stmtClose(TAOS_STMT *stmt) { +int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (pStmt->sql.status >= STMT_PREPARE) { + STMT_ERR_RET(stmtResetStmt(pStmt)); + } + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_PREPARE)); + + if (length <= 0) { + length = strlen(sql); + } + + pStmt->sql.sqlStr = strndup(sql, length); + pStmt->sql.sqlLen = length; + + return TSDB_CODE_SUCCESS; +} + + +int stmtSetTbName(TAOS_STMT *stmt, const char *tbName) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); + + if (NULL == pStmt->exec.pRequest) { + STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); + } + + STMT_ERR_RET(qCreateSName(&pStmt->bInfo.sname, tbName, pStmt->taos->acctId, pStmt->exec.pRequest->pDb, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); + + STMT_ERR_RET(stmtGetFromCache(pStmt)); + + if (pStmt->bInfo.needParse) { + taosMemoryFree(pStmt->bInfo.tbName); + pStmt->bInfo.tbName = strdup(tbName); + } + + return TSDB_CODE_SUCCESS; +} + +int stmtSetTbTags(TAOS_STMT *stmt, TAOS_BIND_v2 *tags) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); + if (NULL == pDataBlock) { + tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid); + STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + STMT_ERR_RET(qBindStmtTagsValue(*pDataBlock, pStmt->bInfo.boundTags, pStmt->bInfo.tbSuid, &pStmt->bInfo.sname, tags, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen)); + + return TSDB_CODE_SUCCESS; +} + + +int32_t stmtFetchTagFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fields) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_TAG_FIELDS)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + tscError("invalid operation to get query tag fileds"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); + if (NULL == pDataBlock) { + tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid); + STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + STMT_ERR_RET(qBuildStmtTagFields(*pDataBlock, pStmt->bInfo.boundTags, fieldNum, fields)); + + return TSDB_CODE_SUCCESS; +} + +int32_t stmtFetchColFields(TAOS_STMT *stmt, int32_t *fieldNum, TAOS_FIELD** fields) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_COL_FIELDS)); + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + if (STMT_TYPE_QUERY == pStmt->sql.type) { + tscError("invalid operation to get query column fileds"); + STMT_ERR_RET(TSDB_CODE_TSC_STMT_API_ERROR); + } + + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); + if (NULL == pDataBlock) { + tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid); + STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + STMT_ERR_RET(qBuildStmtColFields(*pDataBlock, fieldNum, fields)); + + return TSDB_CODE_SUCCESS; +} + +int stmtBindBatch(TAOS_STMT *stmt, TAOS_BIND_v2 *bind, int32_t colIdx) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); + + if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) { + pStmt->bInfo.needParse = false; + } + + if (NULL == pStmt->exec.pRequest) { + STMT_ERR_RET(buildRequest(pStmt->taos, pStmt->sql.sqlStr, pStmt->sql.sqlLen, &pStmt->exec.pRequest)); + } + + if (pStmt->bInfo.needParse) { + STMT_ERR_RET(stmtParseSql(pStmt)); + } + + STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid)); + if (NULL == pDataBlock) { + tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid); + STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + if (colIdx < 0) { + qBindStmtColsValue(*pDataBlock, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen); + } else { + if (colIdx != (pStmt->bInfo.sBindLastIdx + 1) && colIdx != 0) { + tscError("bind column index not in sequence"); + STMT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + + pStmt->bInfo.sBindLastIdx = colIdx; + + if (0 == colIdx) { + pStmt->bInfo.sBindRowNum = bind->num; + } + + qBindStmtSingleColValue(*pDataBlock, bind, pStmt->exec.pRequest->msgBuf, pStmt->exec.pRequest->msgBufLen, colIdx, pStmt->bInfo.sBindRowNum); + } + + return TSDB_CODE_SUCCESS; +} + + +int stmtAddBatch(TAOS_STMT *stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH)); + + STMT_ERR_RET(stmtCacheBlock(pStmt)); + return TSDB_CODE_SUCCESS; } int stmtExec(TAOS_STMT *stmt) { - return TSDB_CODE_SUCCESS; + STscStmt* pStmt = (STscStmt*)stmt; + int32_t code = 0; + + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); + + STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash)); + + launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true); + + STMT_ERR_JRET(pStmt->exec.pRequest->code); + + pStmt->affectedRows += taos_affected_rows(pStmt->exec.pRequest); + +_return: + + stmtCleanExecInfo(pStmt, (code ? false : true)); + + ++pStmt->sql.runTimes; + + STMT_RET(code); } -char *stmtErrstr(TAOS_STMT *stmt) { - return NULL; + +int stmtClose(TAOS_STMT *stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + STMT_RET(stmtCleanSQLInfo(pStmt)); +} + +const char *stmtErrstr(TAOS_STMT *stmt) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (stmt == NULL) { + return (char*) tstrerror(terrno); + } + + if (pStmt->exec.pRequest) { + pStmt->exec.pRequest->code = terrno; + } + + return taos_errstr(pStmt->exec.pRequest); } int stmtAffectedRows(TAOS_STMT *stmt) { - return TSDB_CODE_SUCCESS; -} - -int stmtBind(TAOS_STMT *stmt, TAOS_BIND *bind) { - return TSDB_CODE_SUCCESS; -} - -int stmtPrepare(TAOS_STMT *stmt, const char *sql, unsigned long length) { - return TSDB_CODE_SUCCESS; -} - -int stmtSetTbNameTags(TAOS_STMT *stmt, const char *name, TAOS_BIND *tags) { - return TSDB_CODE_SUCCESS; + return ((STscStmt*)stmt)->affectedRows; } int stmtIsInsert(TAOS_STMT *stmt, int *insert) { + STscStmt* pStmt = (STscStmt*)stmt; + + if (pStmt->sql.type) { + *insert = (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type); + } else { + *insert = isInsertSql(pStmt->sql.sqlStr, 0); + } + return TSDB_CODE_SUCCESS; } int stmtGetParamNum(TAOS_STMT *stmt, int *nums) { - return TSDB_CODE_SUCCESS; -} - -int stmtAddBatch(TAOS_STMT *stmt) { + STMT_ERR_RET(stmtFetchColFields(stmt, nums, NULL)); + return TSDB_CODE_SUCCESS; } @@ -91,9 +544,5 @@ TAOS_RES *stmtUseResult(TAOS_STMT *stmt) { return NULL; } -int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) { - return TSDB_CODE_SUCCESS; -} - diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 478e328a16..14c7e9533d 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -24,6 +24,7 @@ #include "tqueue.h" #include "tref.h" +#if 0 struct tmq_message_t { SMqPollRsp msg; char* topic; @@ -31,6 +32,7 @@ struct tmq_message_t { int32_t vgId; int32_t resIter; }; +#endif typedef struct { int8_t tmqRspType; @@ -52,9 +54,7 @@ struct tmq_topic_vgroup_t { }; struct tmq_topic_vgroup_list_t { - int32_t cnt; - int32_t size; - tmq_topic_vgroup_t* elems; + SArray container; // SArray }; struct tmq_conf_t { @@ -63,6 +63,7 @@ struct tmq_conf_t { int8_t autoCommit; int8_t resetOffset; uint16_t port; + uint16_t autoCommitInterval; char* ip; char* user; char* pass; @@ -72,25 +73,25 @@ struct tmq_conf_t { struct tmq_t { // conf - char groupId[TSDB_CGROUP_LEN]; - char clientId[256]; - int8_t autoCommit; - int8_t inWaiting; + char groupId[TSDB_CGROUP_LEN]; + char clientId[256]; + int8_t autoCommit; + /*int8_t inWaiting;*/ int64_t consumerId; int32_t epoch; int32_t resetOffsetCfg; int64_t status; STscObj* pTscObj; tmq_commit_cb* commit_cb; - int32_t nextTopicIdx; - int8_t epStatus; - int32_t epSkipCnt; - int32_t waitingRequest; - int32_t readyRequest; - SArray* clientTopics; // SArray - STaosQueue* mqueue; // queue of tmq_message_t - STaosQall* qall; - tsem_t rspSem; + /*int32_t nextTopicIdx;*/ + int8_t epStatus; + int32_t epSkipCnt; + /*int32_t waitingRequest;*/ + /*int32_t readyRequest;*/ + SArray* clientTopics; // SArray + STaosQueue* mqueue; // queue of tmq_message_t + STaosQall* qall; + tsem_t rspSem; // stat int64_t pollCnt; }; @@ -134,7 +135,7 @@ typedef struct { int32_t epoch; SMqClientVg* vgHandle; SMqClientTopic* topicHandle; - SMqPollRspV2 msg; + SMqDataBlkRsp msg; } SMqPollRspWrapper; typedef struct { @@ -145,6 +146,7 @@ typedef struct { typedef struct { tmq_t* tmq; + int32_t code; int32_t sync; tsem_t rspSem; } SMqAskEpCbParam; @@ -201,6 +203,11 @@ tmq_conf_res_t tmq_conf_set(tmq_conf_t* conf, const char* key, const char* value } } + if (strcmp(key, "auto.commit.interval.ms") == 0) { + conf->autoCommitInterval = atoi(value); + return TMQ_CONF_OK; + } + if (strcmp(key, "auto.offset.reset") == 0) { if (strcmp(value, "none") == 0) { conf->resetOffset = TMQ_CONF__RESET_OFFSET__NONE; @@ -255,7 +262,12 @@ 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);*/ - taosArrayDestroyEx(container, (void (*)(void*))taosMemoryFree); + int32_t sz = taosArrayGetSize(container); + for (int32_t i = 0; i < sz; i++) { + char* str = taosArrayGetP(container, i); + taosMemoryFree(str); + } + taosArrayDestroy(container); } static int32_t tmqMakeTopicVgKey(char* dst, const char* topicName, int32_t vg) { @@ -294,7 +306,7 @@ int32_t tmqCommitCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqCommitCbParam* pParam = (SMqCommitCbParam*)param; pParam->rspErr = code == 0 ? TMQ_RESP_ERR__SUCCESS : TMQ_RESP_ERR__FAIL; if (pParam->tmq->commit_cb) { - pParam->tmq->commit_cb(pParam->tmq, pParam->rspErr, NULL, NULL); + pParam->tmq->commit_cb(pParam->tmq, pParam->rspErr, NULL); } if (!pParam->async) tsem_post(&pParam->rspSem); return 0; @@ -316,18 +328,19 @@ tmq_resp_err_t tmq_unsubscribe(tmq_t* tmq) { return tmq_subscribe(tmq, lst); } +#if 0 tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errstrLen) { tmq_t* pTmq = taosMemoryCalloc(sizeof(tmq_t), 1); if (pTmq == NULL) { return NULL; } pTmq->pTscObj = (STscObj*)conn; - pTmq->inWaiting = 0; + /*pTmq->inWaiting = 0;*/ pTmq->status = 0; pTmq->pollCnt = 0; pTmq->epoch = 0; - pTmq->waitingRequest = 0; - pTmq->readyRequest = 0; + /*pTmq->waitingRequest = 0;*/ + /*pTmq->readyRequest = 0;*/ pTmq->epStatus = 0; pTmq->epSkipCnt = 0; // set conf @@ -351,8 +364,9 @@ tmq_t* tmq_consumer_new(void* conn, tmq_conf_t* conf, char* errstr, int32_t errs return pTmq; } +#endif -tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { +tmq_t* tmq_consumer_new(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { tmq_t* pTmq = taosMemoryCalloc(1, sizeof(tmq_t)); if (pTmq == NULL) { return NULL; @@ -363,16 +377,17 @@ tmq_t* tmq_consumer_new1(tmq_conf_t* conf, char* errstr, int32_t errstrLen) { 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->inWaiting = 0; + /*pTmq->inWaiting = 0;*/ pTmq->status = 0; pTmq->pollCnt = 0; pTmq->epoch = 0; - pTmq->waitingRequest = 0; - pTmq->readyRequest = 0; + /*pTmq->waitingRequest = 0;*/ + /*pTmq->readyRequest = 0;*/ pTmq->epStatus = 0; pTmq->epSkipCnt = 0; // set conf @@ -423,8 +438,8 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* offsets, in req.num = pArray->size; req.offsets = pArray->pData; } else { - req.num = offsets->cnt; - req.offsets = (SMqOffset*)offsets->elems; + req.num = taosArrayGetSize(&offsets->container); + req.offsets = (SMqOffset*)offsets->container.pData; } SCoder encoder; @@ -496,7 +511,7 @@ tmq_resp_err_t tmq_subscribe(tmq_t* tmq, tmq_list_t* topic_list) { SCMSubscribeReq req; req.topicNum = sz; req.consumerId = tmq->consumerId; - req.consumerGroup = strdup(tmq->groupId); + strcpy(req.cgroup, tmq->groupId); req.topicNames = taosArrayInit(sz, sizeof(void*)); for (int i = 0; i < sz; i++) { @@ -609,7 +624,7 @@ 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), _return); + CHECK_CODE_GOTO(parseSql(pRequest, false, &pQueryNode, NULL), _return); // todo check for invalid sql statement and return with error code @@ -857,7 +872,6 @@ void tmqShowMsg(tmq_message_t* tmq_message) { #endif int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { - /*printf("recv poll\n");*/ SMqPollCbParam* pParam = (SMqPollCbParam*)param; SMqClientVg* pVg = pParam->pVg; SMqClientTopic* pTopic = pParam->pTopic; @@ -870,17 +884,15 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { int32_t msgEpoch = ((SMqRspHead*)pMsg->pData)->epoch; int32_t tmqEpoch = atomic_load_32(&tmq->epoch); if (msgEpoch < tmqEpoch) { - /*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/ - /*tsem_post(&tmq->rspSem);*/ + // do not write into queue since updating epoch reset tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch); + /*tsem_post(&tmq->rspSem);*/ return 0; } if (msgEpoch != tmqEpoch) { tscWarn("mismatch rsp from vg %d, epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch); - } else { - atomic_sub_fetch_32(&tmq->waitingRequest, 1); } #if 0 @@ -902,45 +914,33 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) { } #endif - /*SMqConsumeRsp* pRsp = taosMemoryCalloc(1, sizeof(SMqConsumeRsp));*/ - /*tmq_message_t* pRsp = taosAllocateQitem(sizeof(tmq_message_t));*/ SMqPollRspWrapper* pRspWrapper = taosAllocateQitem(sizeof(SMqPollRspWrapper)); if (pRspWrapper == NULL) { tscWarn("msg discard from vg %d, epoch %d since out of memory", pParam->vgId, pParam->epoch); goto CREATE_MSG_FAIL; } + pRspWrapper->tmqRspType = TMQ_MSG_TYPE__POLL_RSP; pRspWrapper->vgHandle = pVg; pRspWrapper->topicHandle = pTopic; - /*memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));*/ - memcpy(&pRspWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); - tDecodeSMqPollRspV2(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->msg); - // TODO: alloc mem - /*pRsp->*/ - /*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/ -#if 0 - if (pRsp->msg.numOfTopics == 0) { - /*printf("no data\n");*/ - taosFreeQitem(pRsp); - goto CREATE_MSG_FAIL; - } -#endif + memcpy(&pRspWrapper->msg, pMsg->pData, sizeof(SMqRspHead)); + + tDecodeSMqDataBlkRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRspWrapper->msg); tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pVg->vgId, pRspWrapper->msg.reqOffset, pRspWrapper->msg.rspOffset); taosWriteQitem(tmq->mqueue, pRspWrapper); - atomic_add_fetch_32(&tmq->readyRequest, 1); /*tsem_post(&tmq->rspSem);*/ - return 0; + return 0; CREATE_MSG_FAIL: if (pParam->epoch == tmq->epoch) { atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); } /*tsem_post(&tmq->rspSem);*/ - return code; + return -1; } bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { @@ -1023,6 +1023,7 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { SMqAskEpCbParam* pParam = (SMqAskEpCbParam*)param; tmq_t* tmq = pParam->tmq; + pParam->code = code; if (code != 0) { tscError("consumer %ld get topic endpoint error, not ready, wait:%d", tmq->consumerId, pParam->sync); goto END; @@ -1062,6 +1063,7 @@ int32_t tmqAskEpCb(void* param, const SDataBuf* pMsg, int32_t code) { taosWriteQitem(tmq->mqueue, pWrapper); /*tsem_post(&tmq->rspSem);*/ + taosMemoryFree(pParam); } END: @@ -1073,7 +1075,8 @@ END: } int32_t tmqAskEp(tmq_t* tmq, bool sync) { - int8_t epStatus = atomic_val_compare_exchange_8(&tmq->epStatus, 0, 1); + int32_t code = 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); tscTrace("consumer %ld skip ask ep cnt %d", tmq->consumerId, epSkipCnt); @@ -1130,8 +1133,12 @@ int32_t tmqAskEp(tmq_t* tmq, bool sync) { int64_t transporterId = 0; asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo); - if (sync) tsem_wait(&pParam->rspSem); - return 0; + if (sync) { + tsem_wait(&pParam->rspSem); + code = pParam->code; + taosMemoryFree(pParam); + } + return code; } tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) { @@ -1157,7 +1164,7 @@ tmq_resp_err_t tmq_seek(tmq_t* tmq, const tmq_topic_vgroup_t* offset) { return TMQ_RESP_ERR__FAIL; } -SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTopic* pTopic, SMqClientVg* pVg) { +SMqPollReqV2* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTopic* pTopic, SMqClientVg* pVg) { int64_t reqOffset; if (pVg->currentOffset >= 0) { reqOffset = pVg->currentOffset; @@ -1169,13 +1176,18 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo reqOffset = tmq->resetOffsetCfg; } - SMqPollReq* pReq = taosMemoryMalloc(sizeof(SMqPollReq)); + SMqPollReqV2* pReq = taosMemoryMalloc(sizeof(SMqPollReqV2)); if (pReq == NULL) { return NULL; } - strcpy(pReq->topic, pTopic->topicName); - strcpy(pReq->cgroup, tmq->groupId); + /*strcpy(pReq->topic, pTopic->topicName);*/ + /*strcpy(pReq->cgroup, tmq->groupId);*/ + + int32_t tlen = strlen(tmq->groupId); + memcpy(pReq->subKey, tmq->groupId, tlen); + pReq->subKey[tlen] = TMQ_SEPARATOR; + strcpy(pReq->subKey + tlen + 1, pTopic->topicName); pReq->blockingTime = blockingTime; pReq->consumerId = tmq->consumerId; @@ -1184,102 +1196,27 @@ SMqPollReq* tmqBuildConsumeReqImpl(tmq_t* tmq, int64_t blockingTime, SMqClientTo pReq->reqId = generateRequestId(); pReq->head.vgId = htonl(pVg->vgId); - pReq->head.contLen = htonl(sizeof(SMqPollReq)); + pReq->head.contLen = htonl(sizeof(SMqPollReqV2)); return pReq; } SMqRspObj* tmqBuildRspFromWrapper(SMqPollRspWrapper* pWrapper) { SMqRspObj* pRspObj = taosMemoryCalloc(1, sizeof(SMqRspObj)); pRspObj->resType = RES_TYPE__TMQ; - pRspObj->topic = strdup(pWrapper->topicHandle->topicName); - pRspObj->resIter = -1; + strncpy(pRspObj->topic, pWrapper->topicHandle->topicName, TSDB_TOPIC_FNAME_LEN); pRspObj->vgId = pWrapper->vgHandle->vgId; - SMqPollRspV2* pRsp = &pWrapper->msg; - int32_t blockNum = taosArrayGetSize(pRsp->blockPos); - pRspObj->res = taosArrayInit(blockNum, sizeof(SReqResultInfo)); - for (int32_t i = 0; i < blockNum; i++) { - int32_t pos = *(int32_t*)taosArrayGet(pRsp->blockPos, i); - SRetrieveTableRsp* pRetrieve = POINTER_SHIFT(pRsp->blockData, pos); - SReqResultInfo resInfo = {0}; - resInfo.totalRows = 0; - resInfo.precision = TSDB_TIME_PRECISION_MILLI; - setResSchemaInfo(&resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); - setQueryResultFromRsp(&resInfo, pRetrieve, true); - taosArrayPush(pRspObj->res, &resInfo); - } + pRspObj->resIter = -1; + memcpy(&pRspObj->rsp, &pWrapper->msg, sizeof(SMqDataBlkRsp)); + + /*SRetrieveTableRsp* pRetrieve = taosArrayGetP(pWrapper->msg.blockData, 0);*/ + pRspObj->resInfo.totalRows = 0; + pRspObj->resInfo.precision = TSDB_TIME_PRECISION_MILLI; + setResSchemaInfo(&pRspObj->resInfo, pWrapper->topicHandle->schema.pSchema, pWrapper->topicHandle->schema.nCols); + + taosFreeQitem(pWrapper); return pRspObj; } -#if 0 -tmq_message_t* tmqSyncPollImpl(tmq_t* tmq, int64_t blockingTime) { - tmq_message_t* msg = NULL; - for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { - SMqClientTopic* pTopic = taosArrayGet(tmq->clientTopics, i); - for (int j = 0; j < taosArrayGetSize(pTopic->vgs); j++) { - SMqClientVg* pVg = taosArrayGet(pTopic->vgs, j); - int32_t vgStatus = atomic_val_compare_exchange_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE, TMQ_VG_STATUS__WAIT); - /*if (vgStatus != TMQ_VG_STATUS__IDLE) {*/ - /*continue;*/ - /*}*/ - SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); - if (pReq == NULL) { - atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); - // TODO: out of mem - return NULL; - } - - SMqPollCbParam* pParam = taosMemoryMalloc(sizeof(SMqPollCbParam)); - if (pParam == NULL) { - atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); - // TODO: out of mem - return NULL; - } - pParam->tmq = tmq; - pParam->pVg = pVg; - pParam->epoch = tmq->epoch; - pParam->sync = 1; - pParam->msg = &msg; - tsem_init(&pParam->rspSem, 0, 0); - - SMsgSendInfo* sendInfo = taosMemoryMalloc(sizeof(SMsgSendInfo)); - if (sendInfo == NULL) { - return NULL; - } - - sendInfo->msgInfo = (SDataBuf){ - .pData = pReq, - .len = sizeof(SMqPollReq), - .handle = NULL, - }; - sendInfo->requestId = generateRequestId(); - sendInfo->requestObjRefId = 0; - sendInfo->param = pParam; - sendInfo->fp = tmqPollCb; - sendInfo->msgType = TDMT_VND_CONSUME; - - int64_t transporterId = 0; - /*printf("send poll\n");*/ - atomic_add_fetch_32(&tmq->waitingRequest, 1); - asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo); - pVg->pollCnt++; - tmq->pollCnt++; - - tsem_wait(&pParam->rspSem); - tmq_message_t* nmsg = NULL; - while (1) { - taosReadQitem(tmq->mqueue, (void**)&nmsg); - if (nmsg == NULL) continue; - while (nmsg->head.mqMsgType != TMQ_MSG_TYPE__POLL_RSP) { - taosReadQitem(tmq->mqueue, (void**)&nmsg); - } - return nmsg; - } - } - } - return NULL; -} -#endif - int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { /*printf("call poll\n");*/ for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) { @@ -1301,7 +1238,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { #endif } atomic_store_32(&pVg->vgSkipCnt, 0); - SMqPollReq* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); + SMqPollReqV2* pReq = tmqBuildConsumeReqImpl(tmq, blockingTime, pTopic, pVg); if (pReq == NULL) { atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); /*tsem_post(&tmq->rspSem);*/ @@ -1332,7 +1269,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { sendInfo->msgInfo = (SDataBuf){ .pData = pReq, - .len = sizeof(SMqPollReq), + .len = sizeof(SMqPollReqV2), .handle = NULL, }; sendInfo->requestId = pReq->reqId; @@ -1343,7 +1280,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) { int64_t transporterId = 0; /*printf("send poll\n");*/ - atomic_add_fetch_32(&tmq->waitingRequest, 1); + /*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);*/ @@ -1385,7 +1322,7 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) { if (rspWrapper->tmqRspType == TMQ_MSG_TYPE__POLL_RSP) { SMqPollRspWrapper* pollRspWrapper = (SMqPollRspWrapper*)rspWrapper; - atomic_sub_fetch_32(&tmq->readyRequest, 1); + /*atomic_sub_fetch_32(&tmq->readyRequest, 1);*/ /*printf("handle poll rsp %d\n", rspMsg->head.mqMsgType);*/ if (pollRspWrapper->msg.head.epoch == atomic_load_32(&tmq->epoch)) { /*printf("epoch match\n");*/ @@ -1393,7 +1330,7 @@ SMqRspObj* tmqHandleAllRsp(tmq_t* tmq, int64_t blockingTime, bool pollIfReset) { /*printf("vg %d offset %ld up to %ld\n", pVg->vgId, pVg->currentOffset, rspMsg->msg.rspOffset);*/ pVg->currentOffset = pollRspWrapper->msg.rspOffset; atomic_store_32(&pVg->vgStatus, TMQ_VG_STATUS__IDLE); - if (pollRspWrapper->msg.dataLen == 0) { + if (pollRspWrapper->msg.blockNum == 0) { taosFreeQitem(pollRspWrapper); rspWrapper = NULL; continue; @@ -1449,7 +1386,10 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t blocking_time) { // TODO: put into another thread or delayed queue int64_t status = atomic_load_64(&tmq->status); - tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT); + while (0 != tmqAskEp(tmq, status == TMQ_CONSUMER_STATUS__INIT)) { + tscDebug("not ready, retry\n"); + taosSsleep(1); + } rspObj = tmqHandleAllRsp(tmq, blocking_time, false); if (rspObj) { @@ -1607,16 +1547,6 @@ tmq_resp_err_t tmq_commit(tmq_t* tmq, const tmq_topic_vgroup_list_t* tmq_topic_v } #endif -#if 0 -void tmq_message_destroy(tmq_message_t* tmq_message) { - if (tmq_message == NULL) return; - SMqPollRsp* pRsp = &tmq_message->msg; - tDeleteSMqConsumeRsp(pRsp); - /*taosMemoryFree(tmq_message);*/ - taosFreeQitem(tmq_message); -} -#endif - tmq_resp_err_t tmq_consumer_close(tmq_t* tmq) { return TMQ_RESP_ERR__SUCCESS; } const char* tmq_err2str(tmq_resp_err_t err) { diff --git a/source/client/test/tmqTest.cpp b/source/client/test/tmqTest.cpp index d45050d7ff..00ed16944c 100644 --- a/source/client/test/tmqTest.cpp +++ b/source/client/test/tmqTest.cpp @@ -108,7 +108,7 @@ TEST(testCase, tmq_subscribe_ctb_Test) { while (1) { tmq_message_t* msg = tmq_consumer_poll(tmq, 1000); - tmq_message_destroy(msg); + taos_free_result(msg); //printf("get msg\n"); //if (msg == NULL) break; } @@ -141,7 +141,7 @@ TEST(testCase, tmq_subscribe_stb_Test) { tmq_commit(tmq, NULL, 0); } //tmq_commit(tmq, NULL, 0); - tmq_message_destroy(msg); + taos_free_result(msg); //printf("get msg\n"); } } diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 975d097205..d796df16d3 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -113,14 +113,27 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con int32_t type = pColumnInfoData->info.type; if (IS_VAR_DATA_TYPE(type)) { + int32_t dataLen = varDataTLen(pData); + if(type == TSDB_DATA_TYPE_JSON) { + if(*pData == TSDB_DATA_TYPE_NULL) { + dataLen = 0; + }else if(*pData == TSDB_DATA_TYPE_NCHAR) { + dataLen = varDataTLen(pData+CHAR_BYTES); + }else if(*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) { + dataLen = LONG_BYTES; + }else if(*pData == TSDB_DATA_TYPE_BOOL) { + dataLen = CHAR_BYTES; + } + dataLen += CHAR_BYTES; + } SVarColAttr* pAttr = &pColumnInfoData->varmeta; - if (pAttr->allocLen < pAttr->length + varDataTLen(pData)) { + if (pAttr->allocLen < pAttr->length + dataLen) { uint32_t newSize = pAttr->allocLen; if (newSize == 0) { newSize = 8; } - while (newSize < pAttr->length + varDataTLen(pData)) { + while (newSize < pAttr->length + dataLen) { newSize = newSize * 1.5; } @@ -136,8 +149,8 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con uint32_t len = pColumnInfoData->varmeta.length; pColumnInfoData->varmeta.offset[currentRow] = len; - memcpy(pColumnInfoData->pData + len, pData, varDataTLen(pData)); - pColumnInfoData->varmeta.length += varDataTLen(pData); + memcpy(pColumnInfoData->pData + len, pData, dataLen); + pColumnInfoData->varmeta.length += dataLen; } else { memcpy(pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow, pData, pColumnInfoData->info.bytes); } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 49f4afc12b..73031c410d 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -30,7 +30,6 @@ char tsLocalEp[TSDB_EP_LEN] = {0}; // Local End Point, hostname:port uint16_t tsServerPort = 6030; int32_t tsVersion = 30000000; int32_t tsStatusInterval = 1; // second -bool tsEnableTelemetryReporting = false; // common int32_t tsRpcTimer = 300; @@ -75,6 +74,12 @@ uint16_t tsMonitorPort = 6043; int32_t tsMonitorMaxLogs = 100; bool tsMonitorComp = false; +// telem +bool tsEnableTelem = false; +int32_t tsTelemInterval = 86400; +char tsTelemServer[TSDB_FQDN_LEN] = "telemetry.taosdata.com"; +uint16_t tsTelemPort = 80; + /* * denote if the server needs to compress response message at the application layer to client, including query rsp, * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server. @@ -284,6 +289,7 @@ static int32_t taosAddServerLogCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "tsdbDebugFlag", tsdbDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "tqDebugFlag", tqDebugFlag, 0, 255, 0) != 0) return -1; if (cfgAddInt32(pCfg, "fsDebugFlag", fsDebugFlag, 0, 255, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "fnDebugFlag", fnDebugFlag, 0, 255, 0) != 0) return -1; return 0; } @@ -354,7 +360,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddDir(pCfg, "dataDir", tsDataDir, 0) != 0) return -1; if (cfgAddFloat(pCfg, "minimalDataDirGB", 2.0f, 0.001f, 10000000, 0) != 0) return -1; if (cfgAddInt32(pCfg, "maxNumOfDistinctRes", tsMaxNumOfDistinctResults, 10 * 10000, 10000 * 10000, 0) != 0) return -1; - if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelemetryReporting, 0) != 0) return -1; if (cfgAddInt32(pCfg, "maxConnections", tsMaxConnections, 1, 100000, 0) != 0) return -1; if (cfgAddInt32(pCfg, "maxShellConns", tsMaxShellConns, 10, 50000000, 0) != 0) return -1; if (cfgAddInt32(pCfg, "statusInterval", tsStatusInterval, 1, 30, 0) != 0) return -1; @@ -430,12 +435,17 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeUniqueThreads, 1, 1024, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 200000, 0) != 0) return -1; if (cfgAddString(pCfg, "monitorFqdn", tsMonitorFqdn, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorPort", tsMonitorPort, 1, 65056, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorMaxLogs", tsMonitorMaxLogs, 1, 1000000, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitorComp", tsMonitorComp, 0) != 0) return -1; + if (cfgAddBool(pCfg, "telemetryReporting", tsEnableTelem, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "telemetryInterval", tsTelemInterval, 1, 200000, 0) != 0) return -1; + if (cfgAddString(pCfg, "telemetryServer", tsTelemServer, 0) != 0) return -1; + if (cfgAddInt32(pCfg, "telemetryPort", tsTelemPort, 1, 65056, 0) != 0) return -1; + return 0; } @@ -464,6 +474,7 @@ static void taosSetServerLogCfg(SConfig *pCfg) { tsdbDebugFlag = cfgGetItem(pCfg, "tsdbDebugFlag")->i32; tqDebugFlag = cfgGetItem(pCfg, "tqDebugFlag")->i32; fsDebugFlag = cfgGetItem(pCfg, "fsDebugFlag")->i32; + fnDebugFlag = cfgGetItem(pCfg, "fnDebugFlag")->i32; } static int32_t taosSetClientCfg(SConfig *pCfg) { @@ -528,7 +539,6 @@ static void taosSetSystemCfg(SConfig *pCfg) { static int32_t taosSetServerCfg(SConfig *pCfg) { tsDataSpace.reserved = cfgGetItem(pCfg, "minimalDataDirGB")->fval; tsMaxNumOfDistinctResults = cfgGetItem(pCfg, "maxNumOfDistinctRes")->i32; - tsEnableTelemetryReporting = cfgGetItem(pCfg, "telemetryReporting")->bval; tsMaxConnections = cfgGetItem(pCfg, "maxConnections")->i32; tsMaxShellConns = cfgGetItem(pCfg, "maxShellConns")->i32; tsStatusInterval = cfgGetItem(pCfg, "statusInterval")->i32; @@ -572,6 +582,11 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsMonitorMaxLogs = cfgGetItem(pCfg, "monitorMaxLogs")->i32; tsMonitorComp = cfgGetItem(pCfg, "monitorComp")->bval; + tsEnableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; + tsTelemInterval = cfgGetItem(pCfg, "telemetryInterval")->i32; + tstrncpy(tsTelemServer, cfgGetItem(pCfg, "telemetryServer")->str, TSDB_FQDN_LEN); + tsTelemPort = (uint16_t)cfgGetItem(pCfg, "telemetryPort")->i32; + if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 4fb7531dc7..c5de24e595 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -125,14 +125,14 @@ int32_t taosEncodeSEpSet(void **buf, const SEpSet *pEp) { return tlen; } -void *taosDecodeSEpSet(void *buf, SEpSet *pEp) { +void *taosDecodeSEpSet(const void *buf, SEpSet *pEp) { buf = taosDecodeFixedI8(buf, &pEp->inUse); buf = taosDecodeFixedI8(buf, &pEp->numOfEps); for (int32_t i = 0; i < TSDB_MAX_REPLICA; i++) { buf = taosDecodeFixedU16(buf, &pEp->eps[i].port); buf = taosDecodeStringTo(buf, pEp->eps[i].fqdn); } - return buf; + return (void *)buf; } static int32_t tSerializeSClientHbReq(SCoder *pEncoder, const SClientHbReq *pReq) { @@ -1515,6 +1515,7 @@ int32_t tSerializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pReq if (tEncodeI8(&encoder, pReq->outputType) < 0) return -1; if (tEncodeI32(&encoder, pReq->outputLen) < 0) return -1; if (tEncodeI32(&encoder, pReq->bufSize) < 0) return -1; + if (tEncodeI32(&encoder, pReq->codeLen) < 0) return -1; if (tEncodeI64(&encoder, pReq->signature) < 0) return -1; int32_t codeSize = 0; @@ -1554,6 +1555,7 @@ int32_t tDeserializeSCreateFuncReq(void *buf, int32_t bufLen, SCreateFuncReq *pR if (tDecodeI8(&decoder, &pReq->outputType) < 0) return -1; if (tDecodeI32(&decoder, &pReq->outputLen) < 0) return -1; if (tDecodeI32(&decoder, &pReq->bufSize) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->codeLen) < 0) return -1; if (tDecodeI64(&decoder, &pReq->signature) < 0) return -1; int32_t codeSize = 0; @@ -2672,6 +2674,10 @@ int32_t tSerializeSCMCreateTopicReq(void *buf, int32_t bufLen, const SCMCreateTo if (tStartEncode(&encoder) < 0) return -1; if (tEncodeCStr(&encoder, pReq->name) < 0) return -1; if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; + if (tEncodeI8(&encoder, pReq->withTbName) < 0) return -1; + if (tEncodeI8(&encoder, pReq->withSchema) < 0) return -1; + if (tEncodeI8(&encoder, pReq->withTag) < 0) return -1; + if (tEncodeI8(&encoder, pReq->withTagSchema) < 0) return -1; if (tEncodeI32(&encoder, sqlLen) < 0) return -1; if (tEncodeI32(&encoder, astLen) < 0) return -1; if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; @@ -2694,6 +2700,10 @@ int32_t tDeserializeSCMCreateTopicReq(void *buf, int32_t bufLen, SCMCreateTopicR if (tStartDecode(&decoder) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->name) < 0) return -1; if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->withTbName) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->withSchema) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->withTag) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->withTagSchema) < 0) return -1; if (tDecodeI32(&decoder, &sqlLen) < 0) return -1; if (tDecodeI32(&decoder, &astLen) < 0) return -1; @@ -2754,6 +2764,8 @@ int32_t tSerializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) { if (tEncodeI32(&encoder, pReq->pid) < 0) return -1; if (tEncodeCStr(&encoder, pReq->app) < 0) return -1; if (tEncodeCStr(&encoder, pReq->db) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->user) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->passwd) < 0) return -1; if (tEncodeI64(&encoder, pReq->startTime) < 0) return -1; tEndEncode(&encoder); @@ -2771,6 +2783,8 @@ int32_t tDeserializeSConnectReq(void *buf, int32_t bufLen, SConnectReq *pReq) { if (tDecodeI32(&decoder, &pReq->pid) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->app) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->db) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->user) < 0) return -1; + if (tDecodeCStrTo(&decoder, pReq->passwd) < 0) return -1; if (tDecodeI64(&decoder, &pReq->startTime) < 0) return -1; tEndDecode(&decoder); @@ -3030,7 +3044,6 @@ int32_t tDeserializeSCompactVnodeReq(void *buf, int32_t bufLen, SCompactVnodeReq return 0; } - int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -3050,7 +3063,7 @@ int32_t tSerializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pReq SReplica *pReplica = &pReq->replicas[i]; if (tEncodeSReplica(&encoder, pReplica) < 0) return -1; } - + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -3083,7 +3096,6 @@ int32_t tDeserializeSAlterVnodeReq(void *buf, int32_t bufLen, SAlterVnodeReq *pR return 0; } - int32_t tSerializeSKillQueryReq(void *buf, int32_t bufLen, SKillQueryReq *pReq) { SCoder encoder = {0}; tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER); @@ -3597,8 +3609,6 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1; if (tEncodeI32(&encoder, sqlLen) < 0) return -1; if (tEncodeI32(&encoder, astLen) < 0) return -1; - if (tEncodeI8(&encoder, pReq->triggerType) < 0) return -1; - if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1; if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1; if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1; @@ -3646,3 +3656,27 @@ void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { taosMemoryFreeClear(pReq->sql); taosMemoryFreeClear(pReq->ast); } + +STSchema *tdGetSTSChemaFromSSChema(SSchema **pSchema, int32_t nCols) { + STSchemaBuilder schemaBuilder = {0}; + if (tdInitTSchemaBuilder(&schemaBuilder, 0) < 0) { + return NULL; + } + + for (int i = 0; i < nCols; i++) { + SSchema *schema = *pSchema + i; + if (tdAddColToSchema(&schemaBuilder, schema->type, schema->flags, schema->colId, schema->bytes) < 0) { + tdDestroyTSchemaBuilder(&schemaBuilder); + return NULL; + } + } + + STSchema *pNSchema = tdGetSchemaFromBuilder(&schemaBuilder); + if (pNSchema == NULL) { + tdDestroyTSchemaBuilder(&schemaBuilder); + return NULL; + } + + tdDestroyTSchemaBuilder(&schemaBuilder); + return pNSchema; +} diff --git a/source/common/src/trow.c b/source/common/src/trow.c index a1a2d236f9..c73f26e6da 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -24,9 +24,8 @@ const uint8_t tdVTypeByte[2][3] = {{ }, { // 1 bit - TD_VTYPE_NORM_BYTE_I, - TD_VTYPE_NULL_BYTE_I, - TD_VTYPE_NULL_BYTE_I, // padding + TD_VTYPE_NORM_BYTE_I, TD_VTYPE_NULL_BYTE_I, + TD_VTYPE_NULL_BYTE_I, // padding } }; @@ -224,17 +223,40 @@ static uint8_t tdGetMergedBitmapByte(uint8_t byte) { * @brief Merge bitmap from 2 bits to 1 bits, and the memory buffer should be guaranteed by the invoker. * * @param srcBitmap - * @param srcLen + * @param nBits * @param dstBitmap */ -void tdMergeBitmap(uint8_t *srcBitmap, int32_t srcLen, uint8_t *dstBitmap) { +void tdMergeBitmap(uint8_t *srcBitmap, int32_t nBits, uint8_t *dstBitmap) { int32_t i = 0, j = 0; + int32_t nBytes = TD_BITMAP_BYTES(nBits); + int32_t nStrictBytes = nBits / 4; + int32_t nPartialBits = nBits - nStrictBytes * 4; - if (srcLen > 0) { + switch (nPartialBits) { + case 0: + // NOTHING TODO + break; + case 1: { + void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes); + *(uint8_t *)lastByte &= 0xC0; + } break; + case 2: { + void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes); + *(uint8_t *)lastByte &= 0xF0; + } break; + case 3: { + void *lastByte = POINTER_SHIFT(srcBitmap, nStrictBytes); + *(uint8_t *)lastByte &= 0xFC; + } break; + default: + ASSERT(0); + } + + if (nBytes > 0) { dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4); } - while ((++i) < srcLen) { + while ((++i) < nBytes) { if ((i & 1) == 0) { dstBitmap[j] = (tdGetMergedBitmapByte(srcBitmap[i]) << 4); } else { @@ -381,17 +403,18 @@ STSRow *tdRowDup(STSRow *row) { } /** - * @brief - * - * @param pCol - * @param valType - * @param val - * @param numOfRows - * @param maxPoints + * @brief + * + * @param pCol + * @param valType + * @param val + * @param numOfRows + * @param maxPoints * @param bitmapMode default is 0(2 bits), otherwise 1(1 bit) - * @return int + * @return int */ -int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints, int8_t bitmapMode) { +int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int numOfRows, int maxPoints, + int8_t bitmapMode) { TASSERT(pCol != NULL); // Assume that the columns not specified during insert/upsert mean None. @@ -426,7 +449,7 @@ int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int pCol->len += pCol->bytes; } #ifdef TD_SUPPORT_BITMAP - tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode); + tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode); #endif return 0; } @@ -496,8 +519,9 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols SKvRowIdx *pIdx = tdKvRowColIdxAt(pRow, rcol); int16_t colIdx = -1; if (pIdx) { - colIdx = POINTER_DISTANCE(pRow->data, pIdx) / sizeof(SKvRowIdx); + colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx); } + TASSERT(colIdx >= 0); SCellVal sVal = {0}; if (pIdx->colId == pDataCol->colId) { if (tdGetKvRowValOfCol(&sVal, pRow, pBitmap, pIdx->offset, colIdx) < 0) { @@ -537,7 +561,8 @@ int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCol return TSDB_CODE_SUCCESS; } -int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull, TDRowVerT maxVer) { +int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull, + TDRowVerT maxVer) { ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows); ASSERT(target->numOfCols == source->numOfCols); int offset = 0; @@ -558,7 +583,8 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int * if (tdGetColDataOfRow(&sVal, source->cols + j, i + (*pOffset), source->bitmapMode) < 0) { TASSERT(0); } - tdAppendValToDataCol(target->cols + j, sVal.valType, sVal.val, target->numOfRows, target->maxPoints, target->bitmapMode); + tdAppendValToDataCol(target->cols + j, sVal.valType, sVal.val, target->numOfRows, target->maxPoints, + target->bitmapMode); } } ++target->numOfRows; @@ -605,7 +631,8 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1, src1->bitmapMode) < 0) { TASSERT(0); } - tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, target->bitmapMode); + tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, + target->bitmapMode); } } @@ -621,12 +648,14 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i TASSERT(0); } if (src2->cols[i].len > 0 && !tdValTypeIsNull(sVal.valType)) { - tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, target->bitmapMode); + tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, + target->bitmapMode); } else if (!forceSetNull && key1 == key2 && src1->cols[i].len > 0) { if (tdGetColDataOfRow(&sVal, src1->cols + i, *iter1, src1->bitmapMode) < 0) { TASSERT(0); } - tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, target->bitmapMode); + tdAppendValToDataCol(&(target->cols[i]), sVal.valType, sVal.val, target->numOfRows, target->maxPoints, + target->bitmapMode); } else if (target->cols[i].len > 0) { dataColSetNullAt(&target->cols[i], target->numOfRows, true, target->bitmapMode); } diff --git a/source/common/src/ttypes.c b/source/common/src/ttypes.c index cb01a17273..1c7a7986e9 100644 --- a/source/common/src/ttypes.c +++ b/source/common/src/ttypes.c @@ -379,7 +379,7 @@ static void getStatics_nchr(int8_t bitmapMode, const void *pBitmap, const void * *maxIndex = 0; } -tDataTypeDescriptor tDataTypes[15] = { +tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX] = { {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL}, {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool}, {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint, @@ -402,6 +402,7 @@ tDataTypeDescriptor tDataTypes[15] = { {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32}, {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64}, + {TSDB_DATA_TYPE_JSON, 4, TSDB_MAX_JSON_TAG_LEN, "JSON", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr}, }; char tTokenTypeSwitcher[13] = { diff --git a/source/common/src/tvariant.c b/source/common/src/tvariant.c index a0503e43a1..a546d9bb6b 100644 --- a/source/common/src/tvariant.c +++ b/source/common/src/tvariant.c @@ -118,7 +118,7 @@ void taosVariantCreate(SVariant *pVar, const char *z, int32_t n, int32_t type) { } case TSDB_DATA_TYPE_BINARY: { pVar->pz = strndup(z, n); - pVar->nLen = strRmquote(pVar->pz, n); + //pVar->nLen = strRmquote(pVar->pz, n); break; } case TSDB_DATA_TYPE_TIMESTAMP: { diff --git a/source/dnode/mgmt/implement/src/dmTransport.c b/source/dnode/mgmt/implement/src/dmTransport.c index 7cfec917b1..a574d802f9 100644 --- a/source/dnode/mgmt/implement/src/dmTransport.c +++ b/source/dnode/mgmt/implement/src/dmTransport.c @@ -119,10 +119,10 @@ _OVER: } static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SDnodeTrans *pTrans = &pDnode->trans; + SDnodeTrans * pTrans = &pDnode->trans; tmsg_t msgType = pMsg->msgType; bool isReq = msgType & 1u; - SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)]; + SMsgHandle * pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)]; SMgmtWrapper *pWrapper = pHandle->pNdWrapper; if (msgType == TDMT_DND_SERVER_STATUS) { @@ -443,7 +443,7 @@ static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *s SAuthReq authReq = {0}; tstrncpy(authReq.user, user, TSDB_USER_LEN); int32_t contLen = tSerializeSAuthReq(NULL, 0, &authReq); - void *pReq = rpcMallocCont(contLen); + void * pReq = rpcMallocCont(contLen); tSerializeSAuthReq(pReq, contLen, &authReq); SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528}; @@ -523,4 +523,4 @@ SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) { .pWrapper = pWrapper, }; return msgCb; -} \ No newline at end of file +} diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index aa0cebe13c..411eff5374 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -211,6 +211,7 @@ void mmInitMsgHandle(SMgmtWrapper *pWrapper) { dmSetMsgHandle(pWrapper, TDMT_MND_SUBSCRIBE, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_MQ_COMMIT_OFFSET, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_GET_SUB_EP, mmProcessReadMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_VG_CHANGE_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_CREATE_STREAM, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY_RSP, mmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_MND_GET_DB_CFG, mmProcessReadMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 5aade6bdfc..cad0a04912 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -252,7 +252,7 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) { dmSetMsgHandle(pWrapper, TDMT_VND_MQ_QUERY, vmProcessQueryMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CONNECT, vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_MQ_DISCONNECT, vmProcessWriteMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, DEFAULT_HANDLE); + //dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_RES_READY, vmProcessFetchMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_TASKS_STATUS, vmProcessFetchMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_TASK, vmProcessFetchMsg, DEFAULT_HANDLE); @@ -265,10 +265,11 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) { dmSetMsgHandle(pWrapper, TDMT_VND_CREATE_SMA, vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_CANCEL_SMA, vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_DROP_SMA, vmProcessWriteMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, vmProcessWriteMsg, DEFAULT_HANDLE); - dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, DEFAULT_HANDLE); + //dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CONN, vmProcessWriteMsg, DEFAULT_HANDLE); + //dmSetMsgHandle(pWrapper, TDMT_VND_MQ_REB, vmProcessWriteMsg, DEFAULT_HANDLE); + //dmSetMsgHandle(pWrapper, TDMT_VND_MQ_CANCEL_CONN, vmProcessWriteMsg, DEFAULT_HANDLE); + //dmSetMsgHandle(pWrapper, TDMT_VND_MQ_SET_CUR, vmProcessFetchMsg, DEFAULT_HANDLE); + dmSetMsgHandle(pWrapper, TDMT_VND_MQ_VG_CHANGE, (NodeMsgFp)vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, DEFAULT_HANDLE); dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, DEFAULT_HANDLE); diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h index cc345379cf..a818f5d7c3 100644 --- a/source/dnode/mnode/impl/inc/mndConsumer.h +++ b/source/dnode/mnode/impl/inc/mndConsumer.h @@ -22,27 +22,30 @@ extern "C" { #endif - enum { - MQ_CONSUMER_STATUS__INIT = 1, - MQ_CONSUMER_STATUS__IDLE, - MQ_CONSUMER_STATUS__ACTIVE, + // MQ_CONSUMER_STATUS__INIT = 1, + MQ_CONSUMER_STATUS__MODIFY = 1, + MQ_CONSUMER_STATUS__MODIFY_IN_REB, + // MQ_CONSUMER_STATUS__IDLE, + MQ_CONSUMER_STATUS__READY, MQ_CONSUMER_STATUS__LOST, - MQ_CONSUMER_STATUS__MODIFY + MQ_CONSUMER_STATUS__LOST_IN_REB, + MQ_CONSUMER_STATUS__LOST_REBD, }; - int32_t mndInitConsumer(SMnode *pMnode); void mndCleanupConsumer(SMnode *pMnode); SMqConsumerObj *mndAcquireConsumer(SMnode *pMnode, int64_t consumerId); void mndReleaseConsumer(SMnode *pMnode, SMqConsumerObj *pConsumer); -SMqConsumerObj* mndCreateConsumer(int64_t consumerId, const char* cgroup); +SMqConsumerObj *mndCreateConsumer(int64_t consumerId, const char *cgroup); SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer); SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw); +int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 6940f55f8a..984e9f917f 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -88,6 +88,7 @@ typedef enum { TRN_TYPE_CREATE_STREAM = 1019, TRN_TYPE_DROP_STREAM = 1020, TRN_TYPE_ALTER_STREAM = 1021, + TRN_TYPE_CONSUMER_LOST = 1022, TRN_TYPE_BASIC_SCOPE_END, TRN_TYPE_GLOBAL_SCOPE = 2000, TRN_TYPE_CREATE_DNODE = 2001, @@ -417,82 +418,6 @@ typedef struct { char payload[]; } SSysTableRetrieveObj; -typedef struct { - int32_t vgId; // -1 for unassigned - int32_t status; - int32_t epoch; - SEpSet epSet; - int64_t oldConsumerId; - int64_t consumerId; // -1 for unassigned - char* qmsg; -} SMqConsumerEp; - -static FORCE_INLINE int32_t tEncodeSMqConsumerEp(void** buf, const SMqConsumerEp* pConsumerEp) { - int32_t tlen = 0; - tlen += taosEncodeFixedI32(buf, pConsumerEp->vgId); - tlen += taosEncodeFixedI32(buf, pConsumerEp->status); - tlen += taosEncodeFixedI32(buf, pConsumerEp->epoch); - tlen += taosEncodeSEpSet(buf, &pConsumerEp->epSet); - tlen += taosEncodeFixedI64(buf, pConsumerEp->oldConsumerId); - tlen += taosEncodeFixedI64(buf, pConsumerEp->consumerId); - tlen += taosEncodeString(buf, pConsumerEp->qmsg); - return tlen; -} - -static FORCE_INLINE void* tDecodeSMqConsumerEp(void** buf, SMqConsumerEp* pConsumerEp) { - buf = taosDecodeFixedI32(buf, &pConsumerEp->vgId); - buf = taosDecodeFixedI32(buf, &pConsumerEp->status); - buf = taosDecodeFixedI32(buf, &pConsumerEp->epoch); - buf = taosDecodeSEpSet(buf, &pConsumerEp->epSet); - buf = taosDecodeFixedI64(buf, &pConsumerEp->oldConsumerId); - buf = taosDecodeFixedI64(buf, &pConsumerEp->consumerId); - buf = taosDecodeString(buf, &pConsumerEp->qmsg); - return buf; -} - -static FORCE_INLINE void tDeleteSMqConsumerEp(SMqConsumerEp* pConsumerEp) { - if (pConsumerEp) { - taosMemoryFreeClear(pConsumerEp->qmsg); - } -} - -typedef struct { - int64_t consumerId; - SArray* vgInfo; // SArray -} SMqSubConsumer; - -static FORCE_INLINE int32_t tEncodeSMqSubConsumer(void** buf, const SMqSubConsumer* pConsumer) { - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pConsumer->consumerId); - int32_t sz = taosArrayGetSize(pConsumer->vgInfo); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - SMqConsumerEp* pCEp = taosArrayGet(pConsumer->vgInfo, i); - tlen += tEncodeSMqConsumerEp(buf, pCEp); - } - return tlen; -} - -static FORCE_INLINE void* tDecodeSMqSubConsumer(void** buf, SMqSubConsumer* pConsumer) { - int32_t sz; - buf = taosDecodeFixedI64(buf, &pConsumer->consumerId); - buf = taosDecodeFixedI32(buf, &sz); - pConsumer->vgInfo = taosArrayInit(sz, sizeof(SMqConsumerEp)); - for (int32_t i = 0; i < sz; i++) { - SMqConsumerEp consumerEp; - buf = tDecodeSMqConsumerEp(buf, &consumerEp); - taosArrayPush(pConsumer->vgInfo, &consumerEp); - } - return buf; -} - -static FORCE_INLINE void tDeleteSMqSubConsumer(SMqSubConsumer* pSubConsumer) { - if (pSubConsumer->vgInfo) { - taosArrayDestroyEx(pSubConsumer->vgInfo, (void (*)(void*))tDeleteSMqConsumerEp); - pSubConsumer->vgInfo = NULL; - } -} - typedef struct { char key[TSDB_PARTITION_KEY_LEN]; int64_t offset; @@ -512,144 +437,20 @@ static FORCE_INLINE void* tDecodeSMqOffsetObj(void* buf, SMqOffsetObj* pOffset) } typedef struct { - char key[TSDB_SUBSCRIBE_KEY_LEN]; - int32_t status; - int32_t vgNum; - SArray* consumers; // SArray - SArray* lostConsumers; // SArray - SArray* unassignedVg; // SArray -} SMqSubscribeObj; - -static FORCE_INLINE SMqSubscribeObj* tNewSubscribeObj() { - SMqSubscribeObj* pSub = taosMemoryCalloc(1, sizeof(SMqSubscribeObj)); - if (pSub == NULL) { - return NULL; - } - - pSub->consumers = taosArrayInit(0, sizeof(SMqSubConsumer)); - if (pSub->consumers == NULL) { - goto _err; - } - - pSub->lostConsumers = taosArrayInit(0, sizeof(SMqSubConsumer)); - if (pSub->lostConsumers == NULL) { - goto _err; - } - - pSub->unassignedVg = taosArrayInit(0, sizeof(SMqConsumerEp)); - if (pSub->unassignedVg == NULL) { - goto _err; - } - - pSub->key[0] = 0; - pSub->vgNum = 0; - pSub->status = 0; - - return pSub; - -_err: - taosMemoryFreeClear(pSub->consumers); - taosMemoryFreeClear(pSub->lostConsumers); - taosMemoryFreeClear(pSub->unassignedVg); - taosMemoryFreeClear(pSub); - return NULL; -} - -static FORCE_INLINE int32_t tEncodeSubscribeObj(void** buf, const SMqSubscribeObj* pSub) { - int32_t tlen = 0; - tlen += taosEncodeString(buf, pSub->key); - tlen += taosEncodeFixedI32(buf, pSub->vgNum); - tlen += taosEncodeFixedI32(buf, pSub->status); - int32_t sz; - - sz = taosArrayGetSize(pSub->consumers); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - SMqSubConsumer* pSubConsumer = taosArrayGet(pSub->consumers, i); - tlen += tEncodeSMqSubConsumer(buf, pSubConsumer); - } - - sz = taosArrayGetSize(pSub->lostConsumers); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - SMqSubConsumer* pSubConsumer = taosArrayGet(pSub->lostConsumers, i); - tlen += tEncodeSMqSubConsumer(buf, pSubConsumer); - } - - sz = taosArrayGetSize(pSub->unassignedVg); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - SMqConsumerEp* pCEp = taosArrayGet(pSub->unassignedVg, i); - tlen += tEncodeSMqConsumerEp(buf, pCEp); - } - - return tlen; -} - -static FORCE_INLINE void* tDecodeSubscribeObj(void* buf, SMqSubscribeObj* pSub) { - buf = taosDecodeStringTo(buf, pSub->key); - buf = taosDecodeFixedI32(buf, &pSub->vgNum); - buf = taosDecodeFixedI32(buf, &pSub->status); - - int32_t sz; - - buf = taosDecodeFixedI32(buf, &sz); - pSub->consumers = taosArrayInit(sz, sizeof(SMqSubConsumer)); - if (pSub->consumers == NULL) { - return NULL; - } - for (int32_t i = 0; i < sz; i++) { - SMqSubConsumer subConsumer = {0}; - buf = tDecodeSMqSubConsumer(buf, &subConsumer); - taosArrayPush(pSub->consumers, &subConsumer); - } - - buf = taosDecodeFixedI32(buf, &sz); - pSub->lostConsumers = taosArrayInit(sz, sizeof(SMqSubConsumer)); - if (pSub->lostConsumers == NULL) { - return NULL; - } - for (int32_t i = 0; i < sz; i++) { - SMqSubConsumer subConsumer = {0}; - buf = tDecodeSMqSubConsumer(buf, &subConsumer); - taosArrayPush(pSub->lostConsumers, &subConsumer); - } - - buf = taosDecodeFixedI32(buf, &sz); - pSub->unassignedVg = taosArrayInit(sz, sizeof(SMqConsumerEp)); - if (pSub->unassignedVg == NULL) { - return NULL; - } - for (int32_t i = 0; i < sz; i++) { - SMqConsumerEp consumerEp = {0}; - buf = tDecodeSMqConsumerEp(buf, &consumerEp); - taosArrayPush(pSub->unassignedVg, &consumerEp); - } - return buf; -} - -static FORCE_INLINE void tDeleteSMqSubscribeObj(SMqSubscribeObj* pSub) { - if (pSub->consumers) { - // taosArrayDestroyEx(pSub->consumers, (void (*)(void*))tDeleteSMqSubConsumer); - // taosArrayDestroy(pSub->consumers); - pSub->consumers = NULL; - } - - if (pSub->unassignedVg) { - // taosArrayDestroyEx(pSub->unassignedVg, (void (*)(void*))tDeleteSMqConsumerEp); - // taosArrayDestroy(pSub->unassignedVg); - pSub->unassignedVg = NULL; - } -} - -typedef struct { - char name[TSDB_TOPIC_FNAME_LEN]; - char db[TSDB_DB_FNAME_LEN]; - int64_t createTime; - int64_t updateTime; - int64_t uid; + char name[TSDB_TOPIC_FNAME_LEN]; + char db[TSDB_DB_FNAME_LEN]; + int64_t createTime; + int64_t updateTime; + int64_t uid; + // TODO: use subDbUid int64_t dbUid; + int64_t subDbUid; int32_t version; + int8_t subType; // db or table + int8_t withTbName; + int8_t withSchema; + int8_t withTag; + int8_t withTagSchema; SRWLatch lock; int32_t sqlLen; int32_t astLen; @@ -659,76 +460,115 @@ typedef struct { SSchemaWrapper schema; } SMqTopicObj; +enum { + CONSUMER_UPDATE__TOUCH = 1, + CONSUMER_UPDATE__ADD, + CONSUMER_UPDATE__REMOVE, + CONSUMER_UPDATE__LOST, + CONSUMER_UPDATE__MODIFY, +}; + typedef struct { - int64_t consumerId; - int64_t connId; - SRWLatch lock; - char cgroup[TSDB_CGROUP_LEN]; - SArray* currentTopics; // SArray - SArray* recentRemovedTopics; // SArray - int32_t epoch; - // stat - int64_t pollCnt; - // status + int64_t consumerId; + char cgroup[TSDB_CGROUP_LEN]; + int8_t updateType; // used only for update + int32_t epoch; int32_t status; - // heartbeat from the consumer reset hbStatus to 0 - // each checkConsumerAlive msg add hbStatus by 1 - // if checkConsumerAlive > CONSUMER_REBALANCE_CNT, mask to lost + // hbStatus is not applicable to serialization int32_t hbStatus; + // lock is used for topics update + SRWLatch lock; + SArray* currentTopics; // SArray + SArray* rebNewTopics; // SArray + SArray* rebRemovedTopics; // SArray } SMqConsumerObj; -static FORCE_INLINE int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer) { - int32_t sz; - int32_t tlen = 0; - tlen += taosEncodeFixedI64(buf, pConsumer->consumerId); - tlen += taosEncodeFixedI64(buf, pConsumer->connId); - tlen += taosEncodeFixedI32(buf, pConsumer->epoch); - tlen += taosEncodeFixedI64(buf, pConsumer->pollCnt); - tlen += taosEncodeFixedI32(buf, pConsumer->status); - tlen += taosEncodeString(buf, pConsumer->cgroup); +SMqConsumerObj* tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]); +void tDeleteSMqConsumerObj(SMqConsumerObj* pConsumer); +int32_t tEncodeSMqConsumerObj(void** buf, const SMqConsumerObj* pConsumer); +void* tDecodeSMqConsumerObj(const void* buf, SMqConsumerObj* pConsumer); - sz = taosArrayGetSize(pConsumer->currentTopics); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - char* topic = taosArrayGetP(pConsumer->currentTopics, i); - tlen += taosEncodeString(buf, topic); - } +typedef struct { + int32_t vgId; + char* qmsg; + SEpSet epSet; +} SMqVgEp; - sz = taosArrayGetSize(pConsumer->recentRemovedTopics); - tlen += taosEncodeFixedI32(buf, sz); - for (int32_t i = 0; i < sz; i++) { - char* topic = taosArrayGetP(pConsumer->recentRemovedTopics, i); - tlen += taosEncodeString(buf, topic); - } - return tlen; -} +SMqVgEp* tCloneSMqVgEp(const SMqVgEp* pVgEp); +void tDeleteSMqVgEp(SMqVgEp* pVgEp); +int32_t tEncodeSMqVgEp(void** buf, const SMqVgEp* pVgEp); +void* tDecodeSMqVgEp(const void* buf, SMqVgEp* pVgEp); -static FORCE_INLINE void* tDecodeSMqConsumerObj(void* buf, SMqConsumerObj* pConsumer) { - int32_t sz; - buf = taosDecodeFixedI64(buf, &pConsumer->consumerId); - buf = taosDecodeFixedI64(buf, &pConsumer->connId); - buf = taosDecodeFixedI32(buf, &pConsumer->epoch); - buf = taosDecodeFixedI64(buf, &pConsumer->pollCnt); - buf = taosDecodeFixedI32(buf, &pConsumer->status); - buf = taosDecodeStringTo(buf, pConsumer->cgroup); +typedef struct { + int64_t consumerId; // -1 for unassigned + SArray* vgs; // SArray +} SMqConsumerEpInSub; - buf = taosDecodeFixedI32(buf, &sz); - pConsumer->currentTopics = taosArrayInit(sz, sizeof(SMqConsumerObj)); - for (int32_t i = 0; i < sz; i++) { - char* topic; - buf = taosDecodeString(buf, &topic); - taosArrayPush(pConsumer->currentTopics, &topic); - } +SMqConsumerEpInSub* tCloneSMqConsumerEpInSub(const SMqConsumerEpInSub* pEpInSub); +void tDeleteSMqConsumerEpInSub(SMqConsumerEpInSub* pEpInSub); +int32_t tEncodeSMqConsumerEpInSub(void** buf, const SMqConsumerEpInSub* pEpInSub); +void* tDecodeSMqConsumerEpInSub(const void* buf, SMqConsumerEpInSub* pEpInSub); - buf = taosDecodeFixedI32(buf, &sz); - pConsumer->recentRemovedTopics = taosArrayInit(sz, sizeof(SMqConsumerObj)); - for (int32_t i = 0; i < sz; i++) { - char* topic; - buf = taosDecodeString(buf, &topic); - taosArrayPush(pConsumer->recentRemovedTopics, &topic); - } - return buf; -} +typedef struct { + char key[TSDB_SUBSCRIBE_KEY_LEN]; + SRWLatch lock; + int32_t vgNum; + int8_t subType; + int8_t withTbName; + int8_t withSchema; + int8_t withTag; + int8_t withTagSchema; + SHashObj* consumerHash; // consumerId -> SMqConsumerEpInSub + // TODO put -1 into unassignVgs + // SArray* unassignedVgs; +} SMqSubscribeObj; + +SMqSubscribeObj* tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]); +SMqSubscribeObj* tCloneSubscribeObj(const SMqSubscribeObj* pSub); +void tDeleteSubscribeObj(SMqSubscribeObj* pSub); +int32_t tEncodeSubscribeObj(void** buf, const SMqSubscribeObj* pSub); +void* tDecodeSubscribeObj(const void* buf, SMqSubscribeObj* pSub); + +typedef struct { + int32_t epoch; + SArray* consumers; // SArray +} SMqSubActionLogEntry; + +SMqSubActionLogEntry* tCloneSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry); +void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry* pEntry); +int32_t tEncodeSMqSubActionLogEntry(void** buf, const SMqSubActionLogEntry* pEntry); +void* tDecodeSMqSubActionLogEntry(const void* buf, SMqSubActionLogEntry* pEntry); + +typedef struct { + char key[TSDB_SUBSCRIBE_KEY_LEN]; + SArray* logs; // SArray +} SMqSubActionLogObj; + +SMqSubActionLogObj* tCloneSMqSubActionLogObj(SMqSubActionLogObj* pLog); +void tDeleteSMqSubActionLogObj(SMqSubActionLogObj* pLog); +int32_t tEncodeSMqSubActionLogObj(void** buf, const SMqSubActionLogObj* pLog); +void* tDecodeSMqSubActionLogObj(const void* buf, SMqSubActionLogObj* pLog); + +typedef struct { + const SMqSubscribeObj* pOldSub; + const SMqTopicObj* pTopic; + const SMqRebSubscribe* pRebInfo; +} SMqRebInputObj; + +typedef struct { + int64_t oldConsumerId; + int64_t newConsumerId; + SMqVgEp* pVgEp; +} SMqRebOutputVg; + +typedef struct { + SArray* rebVgs; // SArray + SArray* newConsumers; // SArray + SArray* removedConsumers; // SArray + SArray* touchedConsumers; // SArray + SMqSubscribeObj* pSub; + SMqSubActionLogEntry* pLogEntry; +} SMqRebOutputObj; typedef struct { char name[TSDB_TOPIC_FNAME_LEN]; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 07e36c7622..b9ec1905e6 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -67,7 +67,6 @@ typedef struct { } SProfileMgmt; typedef struct { - bool enable; SRWLatch lock; char email[TSDB_FQDN_LEN]; } STelemMgmt; diff --git a/source/dnode/mnode/impl/inc/mndOffset.h b/source/dnode/mnode/impl/inc/mndOffset.h index e18eec973f..556bfe6a53 100644 --- a/source/dnode/mnode/impl/inc/mndOffset.h +++ b/source/dnode/mnode/impl/inc/mndOffset.h @@ -31,7 +31,7 @@ void mndReleaseOffset(SMnode *pMnode, SMqOffsetObj *pOffset); SSdbRaw *mndOffsetActionEncode(SMqOffsetObj *pOffset); SSdbRow *mndOffsetActionDecode(SSdbRaw *pRaw); -int32_t mndCreateOffset(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs); +int32_t mndCreateOffsets(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs); static FORCE_INLINE int32_t mndMakePartitionKey(char *key, const char *cgroup, const char *topicName, int32_t vgId) { return snprintf(key, TSDB_PARTITION_KEY_LEN, "%d:%s:%s", vgId, cgroup, topicName); diff --git a/source/dnode/mnode/impl/inc/mndScheduler.h b/source/dnode/mnode/impl/inc/mndScheduler.h index 42951beca2..33af040915 100644 --- a/source/dnode/mnode/impl/inc/mndScheduler.h +++ b/source/dnode/mnode/impl/inc/mndScheduler.h @@ -29,6 +29,8 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); +int32_t mndConvertRSmaTask(const char* ast, int8_t triggerType, int64_t watermark, char** pStr, int32_t* pLen); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndSubscribe.h b/source/dnode/mnode/impl/inc/mndSubscribe.h index 3f897067a2..7915006f27 100644 --- a/source/dnode/mnode/impl/inc/mndSubscribe.h +++ b/source/dnode/mnode/impl/inc/mndSubscribe.h @@ -26,9 +26,11 @@ int32_t mndInitSubscribe(SMnode *pMnode); void mndCleanupSubscribe(SMnode *pMnode); SMqSubscribeObj *mndAcquireSubscribe(SMnode *pMnode, const char *CGroup, const char *topicName); -SMqSubscribeObj *mndAcquireSubscribeByKey(SMnode *pMnode, const char* key); +SMqSubscribeObj *mndAcquireSubscribeByKey(SMnode *pMnode, const char *key); void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub); +int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index d2a3c38135..7f5df5d356 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -19,8 +19,10 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" +#include "mndOffset.h" #include "mndShow.h" #include "mndStb.h" +#include "mndSubscribe.h" #include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" @@ -28,9 +30,13 @@ #include "tcompare.h" #include "tname.h" -#define MND_CONSUMER_VER_NUMBER 1 +#define MND_CONSUMER_VER_NUMBER 1 #define MND_CONSUMER_RESERVE_SIZE 64 +#define MND_CONSUMER_LOST_HB_CNT 3 + +static int8_t mqInRebFlag = 0; + static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer); static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pConsumer, SMqConsumerObj *pNewConsumer); @@ -38,6 +44,11 @@ static int32_t mndProcessConsumerMetaMsg(SNodeMsg *pMsg); static int32_t mndRetrieveConsumer(SNodeMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows); static void mndCancelGetNextConsumer(SMnode *pMnode, void *pIter); +static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg); +static int32_t mndProcessAskEpReq(SNodeMsg *pMsg); +static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg); +static int32_t mndProcessConsumerLostMsg(SNodeMsg *pMsg); + int32_t mndInitConsumer(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_CONSUMER, .keyType = SDB_KEY_INT64, @@ -47,25 +58,397 @@ int32_t mndInitConsumer(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndConsumerActionUpdate, .deleteFp = (SdbDeleteFp)mndConsumerActionDelete}; + mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq); + mndSetMsgHandle(pMnode, TDMT_MND_GET_SUB_EP, mndProcessAskEpReq); + mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg); + mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_LOST, mndProcessConsumerLostMsg); return sdbSetTable(pMnode->pSdb, table); } void mndCleanupConsumer(SMnode *pMnode) {} -SMqConsumerObj *mndCreateConsumer(int64_t consumerId, const char *cgroup) { - SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj)); - if (pConsumer == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return NULL; +static int32_t mndProcessConsumerLostMsg(SNodeMsg *pMsg) { + SMnode *pMnode = pMsg->pNode; + SMqConsumerLostMsg *pLostMsg = pMsg->rpcMsg.pCont; + SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pLostMsg->consumerId); + ASSERT(pConsumer); + + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__LOST; + + mndReleaseConsumer(pMnode, pConsumer); + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CONSUMER_LOST, &pMsg->rpcMsg); + if (pTrans == NULL) goto FAIL; + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL; + if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL; + + mndTransDrop(pTrans); + return 0; +FAIL: + // TODO delete consumer + mndTransDrop(pTrans); + return -1; +} + +static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { + SMqRebSubscribe *pRebSub = taosHashGet(pHash, key, strlen(key) + 1); + if (pRebSub == NULL) { + pRebSub = tNewSMqRebSubscribe(key); + if (pRebSub == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + taosHashPut(pHash, key, strlen(key) + 1, pRebSub, sizeof(SMqRebSubscribe)); + } + return pRebSub; +} + +static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { + SMnode *pMnode = pMsg->pNode; + SSdb *pSdb = pMnode->pSdb; + SMqConsumerObj *pConsumer; + void *pIter = NULL; + + // rebalance cannot be parallel + int8_t old = atomic_val_compare_exchange_8(&mqInRebFlag, 0, 1); + if (old != 0) { + mInfo("mq rebalance already in progress, do nothing"); + return 0; } - pConsumer->recentRemovedTopics = taosArrayInit(1, sizeof(char *)); - pConsumer->epoch = 1; - pConsumer->consumerId = consumerId; - atomic_store_32(&pConsumer->status, MQ_CONSUMER_STATUS__INIT); - strcpy(pConsumer->cgroup, cgroup); - taosInitRWLatch(&pConsumer->lock); - return pConsumer; + SMqDoRebalanceMsg *pRebMsg = rpcMallocCont(sizeof(SMqDoRebalanceMsg)); + pRebMsg->rebSubHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); + // TODO set cleanfp + pRebMsg->mqInReb = &mqInRebFlag; + + // iterate all consumers, find all modification + while (1) { + pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); + if (pIter == NULL) break; + + int32_t hbStatus = atomic_add_fetch_32(&pConsumer->hbStatus, 1); + int32_t status = atomic_load_32(&pConsumer->status); + if (status == MQ_CONSUMER_STATUS__READY && hbStatus > MND_CONSUMER_LOST_HB_CNT) { + SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg)); + + pLostMsg->consumerId = pConsumer->consumerId; + SRpcMsg *pRpcMsg = taosMemoryCalloc(1, sizeof(SRpcMsg)); + pRpcMsg->msgType = TDMT_MND_MQ_CONSUMER_LOST; + pRpcMsg->pCont = pLostMsg; + pRpcMsg->contLen = sizeof(SMqConsumerLostMsg); + tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, pRpcMsg); + } + if (status == MQ_CONSUMER_STATUS__LOST_REBD || status == MQ_CONSUMER_STATUS__READY) { + // do nothing + } else if (status == MQ_CONSUMER_STATUS__LOST) { + taosRLockLatch(&pConsumer->lock); + int32_t topicNum = taosArrayGetSize(pConsumer->currentTopics); + for (int32_t i = 0; i < topicNum; i++) { + char key[TSDB_SUBSCRIBE_KEY_LEN]; + char *removedTopic = taosArrayGetP(pConsumer->currentTopics, i); + mndMakeSubscribeKey(key, pConsumer->cgroup, removedTopic); + SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId); + } + taosRUnLockLatch(&pConsumer->lock); + } else if (status == MQ_CONSUMER_STATUS__MODIFY) { + taosRLockLatch(&pConsumer->lock); + int32_t newTopicNum = taosArrayGetSize(pConsumer->rebNewTopics); + for (int32_t i = 0; i < newTopicNum; i++) { + char key[TSDB_SUBSCRIBE_KEY_LEN]; + char *newTopic = taosArrayGetP(pConsumer->rebNewTopics, i); + mndMakeSubscribeKey(key, pConsumer->cgroup, newTopic); + SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + taosArrayPush(pRebSub->newConsumers, &pConsumer->consumerId); + } + + int32_t removedTopicNum = taosArrayGetSize(pConsumer->rebRemovedTopics); + for (int32_t i = 0; i < removedTopicNum; i++) { + char key[TSDB_SUBSCRIBE_KEY_LEN]; + char *removedTopic = taosArrayGetP(pConsumer->rebRemovedTopics, i); + mndMakeSubscribeKey(key, pConsumer->cgroup, removedTopic); + SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); + taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId); + } + taosRUnLockLatch(&pConsumer->lock); + } else { + // do nothing + } + + mndReleaseConsumer(pMnode, pConsumer); + } + + if (taosHashGetSize(pRebMsg->rebSubHash) != 0) { + mInfo("mq rebalance will be triggered"); + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_MQ_DO_REBALANCE, + .pCont = pRebMsg, + .contLen = sizeof(SMqDoRebalanceMsg), + }; + tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + } else { + taosHashCleanup(pRebMsg->rebSubHash); + rpcFreeCont(pRebMsg); + mTrace("mq rebalance finished, no modification"); + atomic_store_8(&mqInRebFlag, 0); + } + return 0; +} + +static int32_t mndProcessAskEpReq(SNodeMsg *pMsg) { + SMnode *pMnode = pMsg->pNode; + SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont; + SMqCMGetSubEpRsp rsp = {0}; + int64_t consumerId = be64toh(pReq->consumerId); + int32_t epoch = ntohl(pReq->epoch); + + SMqConsumerObj *pConsumer = mndAcquireConsumer(pMsg->pNode, consumerId); + if (pConsumer == NULL) { + terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST; + return -1; + } + + ASSERT(strcmp(pReq->cgroup, pConsumer->cgroup) == 0); + /*int32_t hbStatus = atomic_load_32(&pConsumer->hbStatus);*/ + atomic_store_32(&pConsumer->hbStatus, 0); + + // 1. check consumer status + int32_t status = atomic_load_32(&pConsumer->status); + + if (status == MQ_CONSUMER_STATUS__LOST) { + // TODO: recover consumer + } + + if (status != MQ_CONSUMER_STATUS__READY) { + terrno = TSDB_CODE_MND_CONSUMER_NOT_READY; + return -1; + } + + int32_t serverEpoch = atomic_load_32(&pConsumer->epoch); + + // 2. check epoch, only send ep info when epoches do not match + if (epoch != serverEpoch) { + taosRLockLatch(&pConsumer->lock); + mInfo("process ask ep, consumer %ld(epoch %d), server epoch %d", consumerId, epoch, serverEpoch); + int32_t numOfTopics = taosArrayGetSize(pConsumer->currentTopics); + + rsp.topics = taosArrayInit(numOfTopics, sizeof(SMqSubTopicEp)); + if (rsp.topics == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosRUnLockLatch(&pConsumer->lock); + goto FAIL; + } + + // handle all topic subscribed by the consumer + for (int32_t i = 0; i < numOfTopics; i++) { + char *topic = taosArrayGetP(pConsumer->currentTopics, i); + SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, topic); + + // txn guarantees pSub is created + ASSERT(pSub); + taosRLockLatch(&pSub->lock); + + SMqSubTopicEp topicEp = {0}; + strcpy(topicEp.topic, topic); + + // 2.1 fetch topic schema + SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); + ASSERT(pTopic); + taosRLockLatch(&pTopic->lock); + topicEp.schema.nCols = pTopic->schema.nCols; + topicEp.schema.pSchema = taosMemoryCalloc(topicEp.schema.nCols, sizeof(SSchema)); + memcpy(topicEp.schema.pSchema, pTopic->schema.pSchema, topicEp.schema.nCols * sizeof(SSchema)); + taosRUnLockLatch(&pTopic->lock); + mndReleaseTopic(pMnode, pTopic); + + // 2.2 iterate all vg assigned to the consumer of that topic + SMqConsumerEpInSub *pEpInSub = taosHashGet(pSub->consumerHash, &consumerId, sizeof(int64_t)); + int32_t vgNum = taosArrayGetSize(pEpInSub->vgs); + + topicEp.vgs = taosArrayInit(vgNum, sizeof(SMqSubVgEp)); + if (topicEp.vgs == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosRUnLockLatch(&pConsumer->lock); + goto FAIL; + } + + for (int32_t j = 0; j < vgNum; j++) { + SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, j); + char offsetKey[TSDB_PARTITION_KEY_LEN]; + mndMakePartitionKey(offsetKey, pConsumer->cgroup, topic, pVgEp->vgId); + // 2.2.1 build vg ep + SMqSubVgEp vgEp = { + .epSet = pVgEp->epSet, + .vgId = pVgEp->vgId, + .offset = -1, + }; + + // 2.2.2 fetch vg offset + SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, offsetKey); + if (pOffsetObj != NULL) { + vgEp.offset = atomic_load_64(&pOffsetObj->offset); + mndReleaseOffset(pMnode, pOffsetObj); + } + taosArrayPush(topicEp.vgs, &vgEp); + } + taosArrayPush(rsp.topics, &topicEp); + + taosRUnLockLatch(&pSub->lock); + mndReleaseSubscribe(pMnode, pSub); + } + taosRUnLockLatch(&pConsumer->lock); + } + // encode rsp + int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqCMGetSubEpRsp(NULL, &rsp); + void *buf = rpcMallocCont(tlen); + if (buf == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + ((SMqRspHead *)buf)->mqMsgType = TMQ_MSG_TYPE__EP_RSP; + ((SMqRspHead *)buf)->epoch = serverEpoch; + ((SMqRspHead *)buf)->consumerId = pConsumer->consumerId; + + void *abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); + tEncodeSMqCMGetSubEpRsp(&abuf, &rsp); + + // release consumer and free memory + tDeleteSMqCMGetSubEpRsp(&rsp); + mndReleaseConsumer(pMnode, pConsumer); + + // send rsp + pMsg->pRsp = buf; + pMsg->rspLen = tlen; + return 0; +FAIL: + tDeleteSMqCMGetSubEpRsp(&rsp); + mndReleaseConsumer(pMnode, pConsumer); + return -1; +} + +int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) { + SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} + +static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { + SMnode *pMnode = pMsg->pNode; + char *msgStr = pMsg->rpcMsg.pCont; + SCMSubscribeReq subscribe = {0}; + tDeserializeSCMSubscribeReq(msgStr, &subscribe); + int64_t consumerId = subscribe.consumerId; + char *cgroup = subscribe.cgroup; + SMqConsumerObj *pConsumerOld = NULL; + SMqConsumerObj *pConsumerNew = NULL; + + int32_t code = -1; + SArray *newSub = subscribe.topicNames; + taosArraySortString(newSub, taosArrayCompareString); + + int32_t newTopicNum = taosArrayGetSize(newSub); + // check topic existance + for (int32_t i = 0; i < newTopicNum; i++) { + char *topic = taosArrayGetP(newSub, i); + SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); + if (pTopic == NULL) { + terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; + goto SUBSCRIBE_OVER; + } + // TODO lock topic to prevent drop + mndReleaseTopic(pMnode, pTopic); + } + + pConsumerOld = mndAcquireConsumer(pMnode, consumerId); + if (pConsumerOld == NULL) { + pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY; + /*pConsumerNew->waitingRebTopics = newSub;*/ + pConsumerNew->rebNewTopics = newSub; + subscribe.topicNames = NULL; + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_SUBSCRIBE, &pMsg->rpcMsg); + if (pTrans == NULL) goto SUBSCRIBE_OVER; + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto SUBSCRIBE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto SUBSCRIBE_OVER; + + } else { + /*taosRLockLatch(&pConsumerOld->lock);*/ + int32_t status = atomic_load_32(&pConsumerOld->status); + if (status != MQ_CONSUMER_STATUS__READY) { + terrno = TSDB_CODE_MND_CONSUMER_NOT_READY; + goto SUBSCRIBE_OVER; + } + + pConsumerNew = tNewSMqConsumerObj(consumerId, cgroup); + if (pConsumerNew == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto SUBSCRIBE_OVER; + } + pConsumerNew->updateType = CONSUMER_UPDATE__MODIFY; + /*pConsumerOld->waitingRebTopics = newSub;*/ + + int32_t oldTopicNum = 0; + if (pConsumerOld->currentTopics) { + oldTopicNum = taosArrayGetSize(pConsumerOld->currentTopics); + } + + int32_t i = 0, j = 0; + while (i < oldTopicNum || j < newTopicNum) { + if (i >= oldTopicNum) { + char *newTopicCopy = strdup(taosArrayGetP(newSub, j)); + taosArrayPush(pConsumerNew->rebNewTopics, &newTopicCopy); + j++; + continue; + } else if (j >= newTopicNum) { + char *oldTopicCopy = strdup(taosArrayGetP(pConsumerOld->currentTopics, i)); + taosArrayPush(pConsumerNew->rebRemovedTopics, &oldTopicCopy); + i++; + continue; + } else { + char *oldTopic = taosArrayGetP(pConsumerOld->currentTopics, i); + char *newTopic = taosArrayGetP(newSub, j); + int comp = compareLenPrefixedStr(oldTopic, newTopic); + if (comp == 0) { + i++; + j++; + continue; + } else if (comp < 0) { + char *oldTopicCopy = strdup(oldTopic); + taosArrayPush(pConsumerNew->rebRemovedTopics, &oldTopicCopy); + i++; + continue; + } else { + char *newTopicCopy = strdup(newTopic); + taosArrayPush(pConsumerNew->rebNewTopics, &newTopicCopy); + j++; + continue; + } + } + } + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_SUBSCRIBE, &pMsg->rpcMsg); + if (pTrans == NULL) goto SUBSCRIBE_OVER; + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) goto SUBSCRIBE_OVER; + if (mndTransPrepare(pMnode, pTrans) != 0) goto SUBSCRIBE_OVER; + } + + code = TSDB_CODE_MND_ACTION_IN_PROGRESS; + +SUBSCRIBE_OVER: + if (pConsumerOld) { + /*taosRUnLockLatch(&pConsumerOld->lock);*/ + mndReleaseConsumer(pMnode, pConsumerOld); + } + if (pConsumerNew) { + tDeleteSMqConsumerObj(pConsumerNew); + } + // TODO: replace with destroy subscribe msg + if (subscribe.topicNames) taosArrayDestroyP(subscribe.topicNames, (FDelete)taosMemoryFree); + return code; } SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) { @@ -154,15 +537,141 @@ static int32_t mndConsumerActionInsert(SSdb *pSdb, SMqConsumerObj *pConsumer) { static int32_t mndConsumerActionDelete(SSdb *pSdb, SMqConsumerObj *pConsumer) { mTrace("consumer:%" PRId64 ", perform delete action", pConsumer->consumerId); + tDeleteSMqConsumerObj(pConsumer); return 0; } static int32_t mndConsumerActionUpdate(SSdb *pSdb, SMqConsumerObj *pOldConsumer, SMqConsumerObj *pNewConsumer) { mTrace("consumer:%" PRId64 ", perform update action", pOldConsumer->consumerId); - /*taosWLockLatch(&pOldConsumer->lock);*/ - atomic_add_fetch_32(&pOldConsumer->epoch, 1); - /*taosWUnLockLatch(&pOldConsumer->lock);*/ + taosWLockLatch(&pOldConsumer->lock); + + if (pNewConsumer->updateType == CONSUMER_UPDATE__MODIFY) { + ASSERT(taosArrayGetSize(pOldConsumer->rebNewTopics) == 0); + ASSERT(taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0); + SArray *tmp = pOldConsumer->rebNewTopics; + pOldConsumer->rebNewTopics = pNewConsumer->rebNewTopics; + pNewConsumer->rebNewTopics = tmp; + + tmp = pOldConsumer->rebRemovedTopics; + pOldConsumer->rebRemovedTopics = pNewConsumer->rebRemovedTopics; + pNewConsumer->rebRemovedTopics = tmp; + + pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY; + } else if (pNewConsumer->updateType == CONSUMER_UPDATE__LOST) { + int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics); + pOldConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *)); + for (int32_t i = 0; i < sz; i++) { + char *topic = strdup(taosArrayGetP(pOldConsumer->currentTopics, i)); + taosArrayPush(pNewConsumer->rebRemovedTopics, &topic); + } + pOldConsumer->status = MQ_CONSUMER_STATUS__LOST; + } else if (pNewConsumer->updateType == CONSUMER_UPDATE__TOUCH) { + atomic_add_fetch_32(&pOldConsumer->epoch, 1); + } else if (pNewConsumer->updateType == CONSUMER_UPDATE__ADD) { + ASSERT(taosArrayGetSize(pNewConsumer->rebNewTopics) == 1); + ASSERT(taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 0); + + char *addedTopic = strdup(taosArrayGetP(pNewConsumer->rebNewTopics, 0)); + // not exist in current topic +#if 1 + for (int32_t i = 0; i < taosArrayGetSize(pOldConsumer->currentTopics); i++) { + char *topic = taosArrayGetP(pOldConsumer->currentTopics, i); + ASSERT(strcmp(topic, addedTopic) != 0); + } +#endif + + // remove from new topic + for (int32_t i = 0; i < taosArrayGetSize(pOldConsumer->rebNewTopics); i++) { + char *topic = taosArrayGetP(pOldConsumer->rebNewTopics, i); + if (strcmp(addedTopic, topic) == 0) { + taosArrayRemove(pOldConsumer->rebNewTopics, i); + taosMemoryFree(topic); + break; + } + } + + // add to current topic + taosArrayPush(pOldConsumer->currentTopics, &addedTopic); + taosArraySortString(pOldConsumer->currentTopics, taosArrayCompareString); + // set status + if (taosArrayGetSize(pOldConsumer->rebNewTopics) == 0 && taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0) { + if (pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY || + pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__READY; + } else if (pOldConsumer->status == MQ_CONSUMER_STATUS__LOST_IN_REB || + pOldConsumer->status == MQ_CONSUMER_STATUS__LOST) { + pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_REBD; + } + } else { + if (pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY || + pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY_IN_REB; + } else if (pOldConsumer->status == MQ_CONSUMER_STATUS__LOST || + pOldConsumer->status == MQ_CONSUMER_STATUS__LOST_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_IN_REB; + } + } + atomic_add_fetch_32(&pOldConsumer->epoch, 1); + } else if (pNewConsumer->updateType == CONSUMER_UPDATE__REMOVE) { + ASSERT(taosArrayGetSize(pNewConsumer->rebNewTopics) == 0); + ASSERT(taosArrayGetSize(pNewConsumer->rebRemovedTopics) == 1); + char *removedTopic = taosArrayGetP(pNewConsumer->rebRemovedTopics, 0); + + // not exist in new topic +#if 1 + for (int32_t i = 0; i < taosArrayGetSize(pOldConsumer->rebNewTopics); i++) { + char *topic = taosArrayGetP(pOldConsumer->rebNewTopics, i); + ASSERT(strcmp(topic, removedTopic) != 0); + } +#endif + + // remove from removed topic + for (int32_t i = 0; i < taosArrayGetSize(pOldConsumer->rebRemovedTopics); i++) { + char *topic = taosArrayGetP(pOldConsumer->rebRemovedTopics, i); + if (strcmp(removedTopic, topic) == 0) { + taosArrayRemove(pOldConsumer->rebRemovedTopics, i); + taosMemoryFree(topic); + break; + } + } + + // remove from current topic + int32_t i = 0; + int32_t sz = taosArrayGetSize(pOldConsumer->currentTopics); + for (i = 0; i < sz; i++) { + char *topic = taosArrayGetP(pOldConsumer->currentTopics, i); + if (strcmp(removedTopic, topic) == 0) { + taosArrayRemove(pOldConsumer->currentTopics, i); + taosMemoryFree(topic); + break; + } + } + // must find the topic + ASSERT(i < sz); + + // set status + if (taosArrayGetSize(pOldConsumer->rebNewTopics) == 0 && taosArrayGetSize(pOldConsumer->rebRemovedTopics) == 0) { + if (pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY || + pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__READY; + } else if (pOldConsumer->status == MQ_CONSUMER_STATUS__LOST_IN_REB || + pOldConsumer->status == MQ_CONSUMER_STATUS__LOST) { + pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_REBD; + } + } else { + if (pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY || + pOldConsumer->status == MQ_CONSUMER_STATUS__MODIFY_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__MODIFY_IN_REB; + } else if (pOldConsumer->status == MQ_CONSUMER_STATUS__LOST || + pOldConsumer->status == MQ_CONSUMER_STATUS__LOST_IN_REB) { + pOldConsumer->status = MQ_CONSUMER_STATUS__LOST_IN_REB; + } + } + atomic_add_fetch_32(&pOldConsumer->epoch, 1); + } + + taosWUnLockLatch(&pOldConsumer->lock); return 0; } diff --git a/source/dnode/mnode/impl/src/mndDef.c b/source/dnode/mnode/impl/src/mndDef.c index 6374b4cad2..78d54d273d 100644 --- a/source/dnode/mnode/impl/src/mndDef.c +++ b/source/dnode/mnode/impl/src/mndDef.c @@ -14,6 +14,354 @@ */ #include "mndDef.h" +#include "mndConsumer.h" + +SMqConsumerObj *tNewSMqConsumerObj(int64_t consumerId, char cgroup[TSDB_CGROUP_LEN]) { + SMqConsumerObj *pConsumer = taosMemoryCalloc(1, sizeof(SMqConsumerObj)); + if (pConsumer == NULL) { + return NULL; + } + + pConsumer->consumerId = consumerId; + memcpy(pConsumer->cgroup, cgroup, TSDB_CGROUP_LEN); + + pConsumer->epoch = 0; + pConsumer->status = MQ_CONSUMER_STATUS__MODIFY; + pConsumer->hbStatus = 0; + + taosInitRWLatch(&pConsumer->lock); + + pConsumer->currentTopics = taosArrayInit(0, sizeof(void *)); + pConsumer->rebNewTopics = taosArrayInit(0, sizeof(void *)); + pConsumer->rebRemovedTopics = taosArrayInit(0, sizeof(void *)); + + if (pConsumer->currentTopics == NULL || pConsumer->rebNewTopics == NULL || pConsumer->rebRemovedTopics == NULL) { + taosArrayDestroy(pConsumer->currentTopics); + taosArrayDestroy(pConsumer->rebNewTopics); + taosArrayDestroy(pConsumer->rebRemovedTopics); + taosMemoryFree(pConsumer); + return NULL; + } + + return pConsumer; +} + +void tDeleteSMqConsumerObj(SMqConsumerObj *pConsumer) { + if (pConsumer->currentTopics) { + taosArrayDestroyP(pConsumer->currentTopics, (FDelete)taosMemoryFree); + } + if (pConsumer->rebNewTopics) { + taosArrayDestroyP(pConsumer->rebNewTopics, (FDelete)taosMemoryFree); + } + if (pConsumer->rebRemovedTopics) { + taosArrayDestroyP(pConsumer->rebRemovedTopics, (FDelete)taosMemoryFree); + } +} + +int32_t tEncodeSMqConsumerObj(void **buf, const SMqConsumerObj *pConsumer) { + int32_t tlen = 0; + int32_t sz; + tlen += taosEncodeFixedI64(buf, pConsumer->consumerId); + tlen += taosEncodeString(buf, pConsumer->cgroup); + tlen += taosEncodeFixedI8(buf, pConsumer->updateType); + tlen += taosEncodeFixedI32(buf, pConsumer->epoch); + tlen += taosEncodeFixedI32(buf, pConsumer->status); + + // current topics + if (pConsumer->currentTopics) { + sz = taosArrayGetSize(pConsumer->currentTopics); + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + char *topic = taosArrayGetP(pConsumer->currentTopics, i); + tlen += taosEncodeString(buf, topic); + } + } else { + tlen += taosEncodeFixedI32(buf, 0); + } + + // reb new topics + if (pConsumer->rebNewTopics) { + sz = taosArrayGetSize(pConsumer->rebNewTopics); + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + char *topic = taosArrayGetP(pConsumer->rebNewTopics, i); + tlen += taosEncodeString(buf, topic); + } + } else { + tlen += taosEncodeFixedI32(buf, 0); + } + + // reb removed topics + if (pConsumer->rebRemovedTopics) { + sz = taosArrayGetSize(pConsumer->rebRemovedTopics); + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + char *topic = taosArrayGetP(pConsumer->rebRemovedTopics, i); + tlen += taosEncodeString(buf, topic); + } + } else { + tlen += taosEncodeFixedI32(buf, 0); + } + + return tlen; +} + +void *tDecodeSMqConsumerObj(const void *buf, SMqConsumerObj *pConsumer) { + int32_t sz; + buf = taosDecodeFixedI64(buf, &pConsumer->consumerId); + buf = taosDecodeStringTo(buf, pConsumer->cgroup); + buf = taosDecodeFixedI8(buf, &pConsumer->updateType); + buf = taosDecodeFixedI32(buf, &pConsumer->epoch); + buf = taosDecodeFixedI32(buf, &pConsumer->status); + + // current topics + buf = taosDecodeFixedI32(buf, &sz); + pConsumer->currentTopics = taosArrayInit(sz, sizeof(void *)); + for (int32_t i = 0; i < sz; i++) { + char *topic; + buf = taosDecodeString(buf, &topic); + taosArrayPush(pConsumer->currentTopics, &topic); + } + + // reb new topics + buf = taosDecodeFixedI32(buf, &sz); + pConsumer->rebNewTopics = taosArrayInit(sz, sizeof(void *)); + for (int32_t i = 0; i < sz; i++) { + char *topic; + buf = taosDecodeString(buf, &topic); + taosArrayPush(pConsumer->rebNewTopics, &topic); + } + + // reb removed topics + buf = taosDecodeFixedI32(buf, &sz); + pConsumer->rebRemovedTopics = taosArrayInit(sz, sizeof(void *)); + for (int32_t i = 0; i < sz; i++) { + char *topic; + buf = taosDecodeString(buf, &topic); + taosArrayPush(pConsumer->rebRemovedTopics, &topic); + } + + return (void *)buf; +} + +SMqVgEp *tCloneSMqVgEp(const SMqVgEp *pVgEp) { + SMqVgEp *pVgEpNew = taosMemoryMalloc(sizeof(SMqVgEp)); + if (pVgEpNew == NULL) return NULL; + pVgEpNew->vgId = pVgEp->vgId; + pVgEpNew->qmsg = strdup(pVgEp->qmsg); + pVgEpNew->epSet = pVgEp->epSet; + return pVgEpNew; +} + +void tDeleteSMqVgEp(SMqVgEp *pVgEp) { taosMemoryFree(pVgEp->qmsg); } + +int32_t tEncodeSMqVgEp(void **buf, const SMqVgEp *pVgEp) { + int32_t tlen = 0; + tlen += taosEncodeFixedI32(buf, pVgEp->vgId); + tlen += taosEncodeString(buf, pVgEp->qmsg); + tlen += taosEncodeSEpSet(buf, &pVgEp->epSet); + return tlen; +} + +void *tDecodeSMqVgEp(const void *buf, SMqVgEp *pVgEp) { + buf = taosDecodeFixedI32(buf, &pVgEp->vgId); + buf = taosDecodeString(buf, &pVgEp->qmsg); + buf = taosDecodeSEpSet(buf, &pVgEp->epSet); + return (void *)buf; +} + +SMqConsumerEpInSub *tCloneSMqConsumerEpInSub(const SMqConsumerEpInSub *pEpInSub) { + SMqConsumerEpInSub *pEpInSubNew = taosMemoryMalloc(sizeof(SMqConsumerEpInSub)); + if (pEpInSubNew == NULL) return NULL; + pEpInSubNew->consumerId = pEpInSub->consumerId; + pEpInSubNew->vgs = taosArrayDeepCopy(pEpInSub->vgs, (FCopy)tCloneSMqVgEp); + return pEpInSubNew; +} + +void tDeleteSMqConsumerEpInSub(SMqConsumerEpInSub *pEpInSub) { + taosArrayDestroyEx(pEpInSub->vgs, (FDelete)tDeleteSMqVgEp); +} + +int32_t tEncodeSMqConsumerEpInSub(void **buf, const SMqConsumerEpInSub *pEpInSub) { + int32_t tlen = 0; + tlen += taosEncodeFixedI64(buf, pEpInSub->consumerId); + int32_t sz = taosArrayGetSize(pEpInSub->vgs); + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, i); + tlen += tEncodeSMqVgEp(buf, pVgEp); + } + /*tlen += taosEncodeArray(buf, pEpInSub->vgs, (FEncode)tEncodeSMqVgEp);*/ + return tlen; +} + +void *tDecodeSMqConsumerEpInSub(const void *buf, SMqConsumerEpInSub *pEpInSub) { + buf = taosDecodeFixedI64(buf, &pEpInSub->consumerId); + /*buf = taosDecodeArray(buf, &pEpInSub->vgs, (FDecode)tDecodeSMqVgEp, sizeof(SMqSubVgEp));*/ + int32_t sz; + buf = taosDecodeFixedI32(buf, &sz); + pEpInSub->vgs = taosArrayInit(sz, sizeof(void *)); + for (int32_t i = 0; i < sz; i++) { + SMqVgEp *pVgEp = taosMemoryMalloc(sizeof(SMqVgEp)); + buf = tDecodeSMqVgEp(buf, pVgEp); + taosArrayPush(pEpInSub->vgs, &pVgEp); + } + + return (void *)buf; +} + +SMqSubscribeObj *tNewSubscribeObj(const char key[TSDB_SUBSCRIBE_KEY_LEN]) { + SMqSubscribeObj *pSubNew = taosMemoryCalloc(1, sizeof(SMqSubscribeObj)); + if (pSubNew == NULL) return NULL; + memcpy(pSubNew->key, key, TSDB_SUBSCRIBE_KEY_LEN); + taosInitRWLatch(&pSubNew->lock); + pSubNew->vgNum = -1; + pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + // TODO set free fp + SMqConsumerEpInSub epInSub = { + .consumerId = -1, + .vgs = taosArrayInit(0, sizeof(void *)), + }; + int64_t unexistKey = -1; + taosHashPut(pSubNew->consumerHash, &unexistKey, sizeof(int64_t), &epInSub, sizeof(SMqConsumerEpInSub)); + return pSubNew; +} + +SMqSubscribeObj *tCloneSubscribeObj(const SMqSubscribeObj *pSub) { + SMqSubscribeObj *pSubNew = taosMemoryMalloc(sizeof(SMqSubscribeObj)); + if (pSubNew == NULL) return NULL; + memcpy(pSubNew->key, pSub->key, TSDB_SUBSCRIBE_KEY_LEN); + taosInitRWLatch(&pSubNew->lock); + + pSubNew->subType = pSub->subType; + pSubNew->withTbName = pSub->withTbName; + pSubNew->withSchema = pSub->withSchema; + pSubNew->withTag = pSub->withTag; + pSubNew->withTagSchema = pSub->withTagSchema; + + pSubNew->vgNum = pSub->vgNum; + pSubNew->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + /*taosHashSetFreeFp(pSubNew->consumerHash, taosArrayDestroy);*/ + void *pIter = NULL; + SMqConsumerEpInSub *pEpInSub = NULL; + while (1) { + pIter = taosHashIterate(pSub->consumerHash, pIter); + if (pIter == NULL) break; + pEpInSub = (SMqConsumerEpInSub *)pIter; + SMqConsumerEpInSub newEp = { + .consumerId = pEpInSub->consumerId, + .vgs = taosArrayDeepCopy(pEpInSub->vgs, (FCopy)tCloneSMqVgEp), + }; + taosHashPut(pSubNew->consumerHash, &newEp.consumerId, sizeof(int64_t), &newEp, sizeof(SMqConsumerEpInSub)); + } + return pSubNew; +} + +void tDeleteSubscribeObj(SMqSubscribeObj *pSub) { + /*taosArrayDestroyEx(pSub->consumerEps, (FDelete)tDeleteSMqConsumerEpInSub);*/ + taosHashCleanup(pSub->consumerHash); +} + +int32_t tEncodeSubscribeObj(void **buf, const SMqSubscribeObj *pSub) { + int32_t tlen = 0; + tlen += taosEncodeString(buf, pSub->key); + tlen += taosEncodeFixedI32(buf, pSub->vgNum); + tlen += taosEncodeFixedI8(buf, pSub->subType); + tlen += taosEncodeFixedI8(buf, pSub->withTbName); + tlen += taosEncodeFixedI8(buf, pSub->withSchema); + tlen += taosEncodeFixedI8(buf, pSub->withTag); + tlen += taosEncodeFixedI8(buf, pSub->withTagSchema); + + void *pIter = NULL; + int32_t sz = taosHashGetSize(pSub->consumerHash); + tlen += taosEncodeFixedI32(buf, sz); + + int32_t cnt = 0; + while (1) { + pIter = taosHashIterate(pSub->consumerHash, pIter); + if (pIter == NULL) break; + SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; + tlen += tEncodeSMqConsumerEpInSub(buf, pEpInSub); + cnt++; + } + ASSERT(cnt == sz); + /*tlen += taosEncodeArray(buf, pSub->consumerEps, (FEncode)tEncodeSMqConsumerEpInSub);*/ + return tlen; +} + +void *tDecodeSubscribeObj(const void *buf, SMqSubscribeObj *pSub) { + // + buf = taosDecodeStringTo(buf, pSub->key); + buf = taosDecodeFixedI32(buf, &pSub->vgNum); + buf = taosDecodeFixedI8(buf, &pSub->subType); + buf = taosDecodeFixedI8(buf, &pSub->withTbName); + buf = taosDecodeFixedI8(buf, &pSub->withSchema); + buf = taosDecodeFixedI8(buf, &pSub->withTag); + buf = taosDecodeFixedI8(buf, &pSub->withTagSchema); + + int32_t sz; + buf = taosDecodeFixedI32(buf, &sz); + + pSub->consumerHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); + for (int32_t i = 0; i < sz; i++) { + /*SMqConsumerEpInSub* pEpInSub = taosMemoryMalloc(sizeof(SMqConsumerEpInSub));*/ + SMqConsumerEpInSub epInSub = {0}; + buf = tDecodeSMqConsumerEpInSub(buf, &epInSub); + taosHashPut(pSub->consumerHash, &epInSub.consumerId, sizeof(int64_t), &epInSub, sizeof(SMqConsumerEpInSub)); + } + + /*buf = taosDecodeArray(buf, &pSub->consumerEps, (FDecode)tDecodeSMqConsumerEpInSub, sizeof(SMqConsumerEpInSub));*/ + return (void *)buf; +} + +SMqSubActionLogEntry *tCloneSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) { + SMqSubActionLogEntry *pEntryNew = taosMemoryMalloc(sizeof(SMqSubActionLogEntry)); + if (pEntryNew == NULL) return NULL; + pEntryNew->epoch = pEntry->epoch; + pEntryNew->consumers = taosArrayDeepCopy(pEntry->consumers, (FCopy)tCloneSMqConsumerEpInSub); + return pEntryNew; +} + +void tDeleteSMqSubActionLogEntry(SMqSubActionLogEntry *pEntry) { + taosArrayDestroyEx(pEntry->consumers, (FDelete)tDeleteSMqConsumerEpInSub); +} + +int32_t tEncodeSMqSubActionLogEntry(void **buf, const SMqSubActionLogEntry *pEntry) { + int32_t tlen = 0; + tlen += taosEncodeFixedI32(buf, pEntry->epoch); + tlen += taosEncodeArray(buf, pEntry->consumers, (FEncode)tEncodeSMqSubActionLogEntry); + return tlen; +} +void *tDecodeSMqSubActionLogEntry(const void *buf, SMqSubActionLogEntry *pEntry) { + buf = taosDecodeFixedI32(buf, &pEntry->epoch); + buf = taosDecodeArray(buf, &pEntry->consumers, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry)); + return (void *)buf; +} + +SMqSubActionLogObj *tCloneSMqSubActionLogObj(SMqSubActionLogObj *pLog) { + SMqSubActionLogObj *pLogNew = taosMemoryMalloc(sizeof(SMqSubActionLogObj)); + if (pLogNew == NULL) return pLogNew; + memcpy(pLogNew->key, pLog->key, TSDB_SUBSCRIBE_KEY_LEN); + pLogNew->logs = taosArrayDeepCopy(pLog->logs, (FCopy)tCloneSMqConsumerEpInSub); + return pLogNew; +} + +void tDeleteSMqSubActionLogObj(SMqSubActionLogObj *pLog) { + taosArrayDestroyEx(pLog->logs, (FDelete)tDeleteSMqConsumerEpInSub); +} + +int32_t tEncodeSMqSubActionLogObj(void **buf, const SMqSubActionLogObj *pLog) { + int32_t tlen = 0; + tlen += taosEncodeString(buf, pLog->key); + tlen += taosEncodeArray(buf, pLog->logs, (FEncode)tEncodeSMqSubActionLogEntry); + return tlen; +} + +void *tDecodeSMqSubActionLogObj(const void *buf, SMqSubActionLogObj *pLog) { + buf = taosDecodeStringTo(buf, pLog->key); + buf = taosDecodeArray(buf, &pLog->logs, (FDecode)tDecodeSMqSubActionLogEntry, sizeof(SMqSubActionLogEntry)); + return (void *)buf; +} int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { int32_t sz = 0; diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 26c7b4d200..c25561814b 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -77,7 +77,9 @@ static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) { SDB_SET_INT64(pRaw, dataPos, pFunc->signature, _OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->commentSize, _OVER) SDB_SET_INT32(pRaw, dataPos, pFunc->codeSize, _OVER) - SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER) + if (pFunc->commentSize > 0) { + SDB_SET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER) + } SDB_SET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER) SDB_SET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER) SDB_SET_DATALEN(pRaw, dataPos, _OVER); @@ -125,13 +127,18 @@ static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) { SDB_GET_INT32(pRaw, dataPos, &pFunc->commentSize, _OVER) SDB_GET_INT32(pRaw, dataPos, &pFunc->codeSize, _OVER) - pFunc->pComment = taosMemoryCalloc(1, pFunc->commentSize); - pFunc->pCode = taosMemoryCalloc(1, pFunc->codeSize); - if (pFunc->pComment == NULL || pFunc->pCode == NULL) { - goto _OVER; + if (pFunc->commentSize > 0) { + pFunc->pComment = taosMemoryCalloc(1, pFunc->commentSize); + if (pFunc->pComment == NULL) { + goto _OVER; + } + SDB_GET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER) } - SDB_GET_BINARY(pRaw, dataPos, pFunc->pComment, pFunc->commentSize, _OVER) + pFunc->pCode = taosMemoryCalloc(1, pFunc->codeSize); + if (pFunc->pCode == NULL) { + goto _OVER; + } SDB_GET_BINARY(pRaw, dataPos, pFunc->pCode, pFunc->codeSize, _OVER) SDB_GET_RESERVE(pRaw, dataPos, SDB_FUNC_RESERVE_SIZE, _OVER) @@ -192,16 +199,20 @@ static int32_t mndCreateFunc(SMnode *pMnode, SNodeMsg *pReq, SCreateFuncReq *pCr func.outputLen = pCreate->outputLen; func.bufSize = pCreate->bufSize; func.signature = pCreate->signature; - func.commentSize = strlen(pCreate->pComment) + 1; - func.codeSize = strlen(pCreate->pCode) + 1; - func.pComment = taosMemoryMalloc(func.commentSize); + if (NULL != pCreate->pComment) { + func.commentSize = strlen(pCreate->pComment) + 1; + func.pComment = taosMemoryMalloc(func.commentSize); + } + func.codeSize = pCreate->codeLen; func.pCode = taosMemoryMalloc(func.codeSize); if (func.pCode == NULL || func.pCode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _OVER; } - memcpy(func.pComment, pCreate->pComment, func.commentSize); + if (func.commentSize > 0) { + memcpy(func.pComment, pCreate->pComment, func.commentSize); + } memcpy(func.pCode, pCreate->pCode, func.codeSize); pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_FUNC, &pReq->rpcMsg); @@ -293,16 +304,6 @@ static int32_t mndProcessCreateFuncReq(SNodeMsg *pReq) { goto _OVER; } - if (createReq.pComment == NULL) { - terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT; - goto _OVER; - } - - if (createReq.pComment[0] == 0) { - terrno = TSDB_CODE_MND_INVALID_FUNC_COMMENT; - goto _OVER; - } - if (createReq.pCode == NULL) { terrno = TSDB_CODE_MND_INVALID_FUNC_CODE; goto _OVER; @@ -440,14 +441,20 @@ static int32_t mndProcessRetrieveFuncReq(SNodeMsg *pReq) { funcInfo.signature = pFunc->signature; funcInfo.commentSize = pFunc->commentSize; funcInfo.codeSize = pFunc->codeSize; - funcInfo.pCode = taosMemoryCalloc(1, sizeof(funcInfo.codeSize)); - funcInfo.pComment = taosMemoryCalloc(1, sizeof(funcInfo.commentSize)); - if (funcInfo.pCode == NULL || funcInfo.pComment == NULL) { + funcInfo.pCode = taosMemoryCalloc(1, funcInfo.codeSize); + if (funcInfo.pCode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto RETRIEVE_FUNC_OVER; } - memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize); memcpy(funcInfo.pCode, pFunc->pCode, pFunc->codeSize); + if (funcInfo.commentSize > 0) { + funcInfo.pComment = taosMemoryCalloc(1, funcInfo.commentSize); + if (funcInfo.pComment == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto RETRIEVE_FUNC_OVER; + } + memcpy(funcInfo.pComment, pFunc->pComment, pFunc->commentSize); + } taosArrayPush(retrieveRsp.pFuncInfos, &funcInfo); mndReleaseFunc(pMnode, pFunc); } diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c index 31c16e1e1d..f5433e8f9e 100644 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ b/source/dnode/mnode/impl/src/mndOffset.c @@ -130,13 +130,12 @@ OFFSET_DECODE_OVER: return pRow; } -int32_t mndCreateOffset(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs) { - int32_t code = 0; +int32_t mndCreateOffsets(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs) { int32_t sz = taosArrayGetSize(vgs); for (int32_t i = 0; i < sz; i++) { - SMqConsumerEp *pConsumerEp = taosArrayGet(vgs, i); - SMqOffsetObj offsetObj; - if (mndMakePartitionKey(offsetObj.key, cgroup, topicName, pConsumerEp->vgId) < 0) { + int32_t vgId = *(int32_t *)taosArrayGet(vgs, i); + SMqOffsetObj offsetObj; + if (mndMakePartitionKey(offsetObj.key, cgroup, topicName, vgId) < 0) { return -1; } offsetObj.offset = -1; @@ -170,13 +169,22 @@ static int32_t mndProcessCommitOffsetReq(SNodeMsg *pMsg) { if (mndMakePartitionKey(key, pOffset->cgroup, pOffset->topicName, pOffset->vgId) < 0) { return -1; } + bool create = false; SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, key); - ASSERT(pOffsetObj); + if (pOffsetObj == NULL) { + pOffsetObj = taosMemoryMalloc(sizeof(SMqOffset)); + memcpy(pOffsetObj->key, key, TSDB_PARTITION_KEY_LEN); + create = true; + } pOffsetObj->offset = pOffset->offset; SSdbRaw *pOffsetRaw = mndOffsetActionEncode(pOffsetObj); sdbSetRawStatus(pOffsetRaw, SDB_STATUS_READY); mndTransAppendRedolog(pTrans, pOffsetRaw); - mndReleaseOffset(pMnode, pOffsetObj); + if (create) { + taosMemoryFree(pOffsetObj); + } else { + mndReleaseOffset(pMnode, pOffsetObj); + } } if (mndTransPrepare(pMnode, pTrans) != 0) { @@ -201,7 +209,7 @@ static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) { static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOldOffset, SMqOffsetObj *pNewOffset) { mTrace("offset:%s, perform update action", pOldOffset->key); - pOldOffset->offset = pNewOffset->offset; + atomic_store_64(&pOldOffset->offset, pNewOffset->offset); return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 826a73afc6..ec4be8cba3 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -24,20 +24,20 @@ #include "version.h" typedef struct { - uint32_t id; - int8_t connType; - char user[TSDB_USER_LEN]; - char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc - int64_t appStartTimeMs; // app start time - int32_t pid; // pid of app that invokes taosc - uint32_t ip; - uint16_t port; - int8_t killed; - int64_t loginTimeMs; - int64_t lastAccessTimeMs; - uint64_t killId; - int32_t numOfQueries; - SArray *pQueries; //SArray + uint32_t id; + int8_t connType; + char user[TSDB_USER_LEN]; + char app[TSDB_APP_NAME_LEN]; // app name that invokes taosc + int64_t appStartTimeMs; // app start time + int32_t pid; // pid of app that invokes taosc + uint32_t ip; + uint16_t port; + int8_t killed; + int64_t loginTimeMs; + int64_t lastAccessTimeMs; + uint64_t killId; + int32_t numOfQueries; + SArray * pQueries; // SArray } SConnObj; static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port, @@ -45,7 +45,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType static void mndFreeConn(SConnObj *pConn); static SConnObj *mndAcquireConn(SMnode *pMnode, uint32_t connId); static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn); -static void *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter); +static void * mndGetNextConn(SMnode *pMnode, SCacheIter *pIter); static void mndCancelGetNextConn(SMnode *pMnode, void *pIter); static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq); static int32_t mndProcessConnectReq(SNodeMsg *pReq); @@ -71,9 +71,9 @@ int32_t mndInitProfile(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryReq); mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnReq); -// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndCancelGetNextConn); -// mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries); + // mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndCancelGetNextQuery); return 0; @@ -91,7 +91,7 @@ static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType int32_t pid, const char *app, int64_t startTime) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; - char connStr[255] = {0}; + char connStr[255] = {0}; int32_t len = snprintf(connStr, sizeof(connStr), "%s%d%d%d%s", user, ip, port, pid, app); int32_t connId = mndGenerateUid(connStr, len); if (startTime == 0) startTime = taosGetTimestampMs(); @@ -174,10 +174,10 @@ static void mndCancelGetNextConn(SMnode *pMnode, void *pIter) { } static int32_t mndProcessConnectReq(SNodeMsg *pReq) { - SMnode *pMnode = pReq->pNode; - SUserObj *pUser = NULL; - SDbObj *pDb = NULL; - SConnObj *pConn = NULL; + SMnode * pMnode = pReq->pNode; + SUserObj * pUser = NULL; + SDbObj * pDb = NULL; + SConnObj * pConn = NULL; int32_t code = -1; SConnectReq connReq = {0}; char ip[30] = {0}; @@ -194,6 +194,11 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) { mError("user:%s, failed to login while acquire user since %s", pReq->user, terrstr()); goto CONN_OVER; } + if (0 != strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1)) { + mError("user:%s, failed to auth while acquire user\n %s \r\n %s", pReq->user, connReq.passwd, pUser->pass); + code = TSDB_CODE_RPC_AUTH_FAILURE; + goto CONN_OVER; + } if (connReq.db[0]) { char db[TSDB_DB_FNAME_LEN]; @@ -253,8 +258,8 @@ static int32_t mndSaveQueryList(SConnObj *pConn, SQueryHbReqBasic *pBasic) { pConn->pQueries = pBasic->queryDesc; pBasic->queryDesc = NULL; - - pConn->numOfQueries = pBasic->queryDesc ? taosArrayGetSize(pBasic->queryDesc) : 0; + + pConn->numOfQueries = pBasic->queryDesc ? taosArrayGetSize(pBasic->queryDesc) : 0; return TSDB_CODE_SUCCESS; } @@ -324,9 +329,10 @@ static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) { return NULL; } -static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq, SClientHbBatchRsp *pBatchRsp) { +static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq, + SClientHbBatchRsp *pBatchRsp) { SProfileMgmt *pMgmt = &pMnode->profileMgmt; - SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL}; + SClientHbRsp hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL}; if (pHbReq->query) { SQueryHbReqBasic *pBasic = pHbReq->query; @@ -335,8 +341,9 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb rpcGetConnInfo(pMsg->handle, &connInfo); SConnObj *pConn = mndAcquireConn(pMnode, pBasic->connId); - if (pConn == NULL) { - pConn = mndCreateConn(pMnode, connInfo.user, CONN_TYPE__QUERY, connInfo.clientIp, connInfo.clientPort, pBasic->pid, pBasic->app, 0); + if (pConn == NULL) { + pConn = mndCreateConn(pMnode, connInfo.user, CONN_TYPE__QUERY, connInfo.clientIp, connInfo.clientPort, + pBasic->pid, pBasic->app, 0); if (pConn == NULL) { mError("user:%s, conn:%u is freed and failed to create new since %s", connInfo.user, pBasic->connId, terrstr()); return -1; @@ -345,7 +352,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb } } else if (pConn->killed) { mError("user:%s, conn:%u is already killed", connInfo.user, pConn->id); - mndReleaseConn(pMnode, pConn); + mndReleaseConn(pMnode, pConn); terrno = TSDB_CODE_MND_INVALID_CONNECTION; return -1; } @@ -369,8 +376,8 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb } rspBasic->connId = pConn->id; - rspBasic->totalDnodes = 1; //TODO - rspBasic->onlineDnodes = 1; //TODO + rspBasic->totalDnodes = 1; // TODO + rspBasic->onlineDnodes = 1; // TODO mndGetMnodeEpSet(pMnode, &rspBasic->epSet); mndReleaseConn(pMnode, pConn); @@ -379,7 +386,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb int32_t kvNum = taosHashGetSize(pHbReq->info); if (NULL == pHbReq->info || kvNum <= 0) { - taosArrayPush(pBatchRsp->rsps, &hbRsp); + taosArrayPush(pBatchRsp->rsps, &hbRsp); return TSDB_CODE_SUCCESS; } @@ -396,7 +403,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb switch (kv->key) { case HEARTBEAT_KEY_DBINFO: { - void *rspMsg = NULL; + void * rspMsg = NULL; int32_t rspLen = 0; mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbVgVersion), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { @@ -406,7 +413,7 @@ static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHb break; } case HEARTBEAT_KEY_STBINFO: { - void *rspMsg = NULL; + void * rspMsg = NULL; int32_t rspLen = 0; mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableMetaVersion), &rspMsg, &rspLen); if (rspMsg && rspLen > 0) { @@ -457,7 +464,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq); int32_t tlen = tSerializeSClientHbBatchRsp(NULL, 0, &batchRsp); - void *buf = rpcMallocCont(tlen); + void * buf = rpcMallocCont(tlen); tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp); int32_t rspNum = (int32_t)taosArrayGetSize(batchRsp.rsps); @@ -479,7 +486,7 @@ static int32_t mndProcessHeartBeatReq(SNodeMsg *pReq) { } static int32_t mndProcessKillQueryReq(SNodeMsg *pReq) { - SMnode *pMnode = pReq->pNode; + SMnode * pMnode = pReq->pNode; SProfileMgmt *pMgmt = &pMnode->profileMgmt; SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); @@ -513,7 +520,7 @@ static int32_t mndProcessKillQueryReq(SNodeMsg *pReq) { } static int32_t mndProcessKillConnReq(SNodeMsg *pReq) { - SMnode *pMnode = pReq->pNode; + SMnode * pMnode = pReq->pNode; SProfileMgmt *pMgmt = &pMnode->profileMgmt; SUserObj *pUser = mndAcquireUser(pMnode, pReq->user); @@ -545,11 +552,11 @@ static int32_t mndProcessKillConnReq(SNodeMsg *pReq) { } static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pReq->pNode; + SMnode * pMnode = pReq->pNode; int32_t numOfRows = 0; SConnObj *pConn = NULL; int32_t cols = 0; - char *pWrite; + char * pWrite; char ipStr[TSDB_IPv4ADDR_LEN + 6]; if (pShow->pIter == NULL) { @@ -604,8 +611,8 @@ static int32_t mndRetrieveConns(SNodeMsg *pReq, SShowObj *pShow, char *data, int } static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, int32_t rows) { - SMnode *pMnode = pReq->pNode; - int32_t numOfRows = 0; + SMnode *pMnode = pReq->pNode; + int32_t numOfRows = 0; #if 0 SConnObj *pConn = NULL; int32_t cols = 0; @@ -703,7 +710,7 @@ static int32_t mndRetrieveQueries(SNodeMsg *pReq, SShowObj *pShow, char *data, i } pShow->numOfRows += numOfRows; -#endif +#endif return numOfRows; } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index df7946a0c1..73583058f1 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -34,6 +34,54 @@ extern bool tsStreamSchedV; +int32_t mndConvertRSmaTask(const char* ast, int8_t triggerType, int64_t watermark, char** pStr, int32_t* pLen) { + SNode* pAst = NULL; + SQueryPlan* pPlan = NULL; + terrno = TSDB_CODE_SUCCESS; + + if (nodesStringToNode(ast, &pAst) < 0) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + goto END; + } + + SPlanContext cxt = { + .pAstRoot = pAst, + .topicQuery = false, + .streamQuery = true, + .rSmaQuery = true, + .triggerType = triggerType, + .watermark = watermark, + }; + if (qCreateQueryPlan(&cxt, &pPlan, NULL) < 0) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + goto END; + } + + int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); + if (levelNum != 1) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + goto END; + } + SNodeListNode* inner = nodesListGetNode(pPlan->pSubplans, 0); + + int32_t opNum = LIST_LENGTH(inner->pNodeList); + if (opNum != 1) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + goto END; + } + + SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); + if (qSubPlanToString(plan, pStr, pLen) < 0) { + terrno = TSDB_CODE_QRY_INVALID_INPUT; + goto END; + } + +END: + if (pAst) nodesDestroyNode(pAst); + if (pPlan) nodesDestroyNode(pPlan); + return terrno; +} + int32_t mndPersistTaskDeployReq(STrans* pTrans, SStreamTask* pTask, const SEpSet* pEpSet, tmsg_t type, int32_t nodeId) { SCoder encoder; tCoderInit(&encoder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); @@ -434,7 +482,9 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib return -1; } - ASSERT(pSub->vgNum == 0); + ASSERT(pSub->vgNum == -1); + + pSub->vgNum = 0; int32_t levelNum = LIST_LENGTH(pPlan->pSubplans); if (levelNum != 1) { @@ -453,6 +503,12 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib } SSubplan* plan = nodesListGetNode(inner->pNodeList, 0); + int64_t unexistKey = -1; + SMqConsumerEpInSub* pEpInSub = taosHashGet(pSub->consumerHash, &unexistKey, sizeof(int64_t)); + ASSERT(pEpInSub); + + ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + void* pIter = NULL; while (1) { pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void**)&pVgroup); @@ -466,24 +522,41 @@ int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscrib 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; - - mDebug("init subscribption %s, assign vg: %d", pSub->key, consumerEp.vgId); +#endif + + mDebug("init subscribption %s, assign vg: %d", pSub->key, pVgEp->vgId); int32_t msgLen; - if (qSubPlanToString(plan, &consumerEp.qmsg, &msgLen) < 0) { + if (qSubPlanToString(plan, &pVgEp->qmsg, &msgLen) < 0) { sdbRelease(pSdb, pVgroup); qDestroyQueryPlan(pPlan); terrno = TSDB_CODE_QRY_INVALID_INPUT; return -1; } - taosArrayPush(pSub->unassignedVg, &consumerEp); + 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); + + ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + qDestroyQueryPlan(pPlan); return 0; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index d8b94f5ffe..6bdf4575a8 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -348,7 +348,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { memcpy(pOld->pColumns, pNew->pColumns, pOld->numOfColumns * sizeof(SSchema)); memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema)); if (pNew->commentLen != 0) { - memcpy(pOld->comment, pNew->comment, TSDB_STB_COMMENT_LEN); + memcpy(pOld->comment, pNew->comment, pNew->commentLen); } if (pNew->ast1Len != 0) { memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len); diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 3a31b0abb9..e37bd60e12 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -40,30 +40,30 @@ enum { MQ_SUBSCRIBE_STATUS__DELETED, }; -static int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName); - static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *); static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw); static int32_t mndSubActionInsert(SSdb *pSdb, SMqSubscribeObj *); static int32_t mndSubActionDelete(SSdb *pSdb, SMqSubscribeObj *); static int32_t mndSubActionUpdate(SSdb *pSdb, SMqSubscribeObj *pOldSub, SMqSubscribeObj *pNewSub); -static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg); -static int32_t mndProcessSubscribeRsp(SNodeMsg *pMsg); -static int32_t mndProcessSubscribeInternalReq(SNodeMsg *pMsg); +static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg); static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pMsg); -static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg); -static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg); -static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg); -static int32_t mndProcessResetOffsetReq(SNodeMsg *pMsg); -static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup, - const SMqConsumerEp *pConsumerEp); +static int32_t mndSetSubRedoLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub) { + SSdbRaw *pRedoRaw = mndSubActionEncode(pSub); + if (pRedoRaw == NULL) return -1; + if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; + if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, - const char *topicName); -static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, - const char *oldTopicName); +static int32_t mndSetSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub) { + SSdbRaw *pCommitRaw = mndSubActionEncode(pSub); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY) != 0) return -1; + return 0; +} int32_t mndInitSubscribe(SMnode *pMnode) { SSdbTable table = {.sdbType = SDB_SUBSCRIBE, @@ -74,242 +74,93 @@ int32_t mndInitSubscribe(SMnode *pMnode) { .updateFp = (SdbUpdateFp)mndSubActionUpdate, .deleteFp = (SdbDeleteFp)mndSubActionDelete}; - mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq); - mndSetMsgHandle(pMnode, TDMT_VND_MQ_SET_CONN_RSP, mndProcessSubscribeInternalRsp); - mndSetMsgHandle(pMnode, TDMT_VND_MQ_REB_RSP, mndProcessSubscribeInternalRsp); - mndSetMsgHandle(pMnode, TDMT_VND_MQ_CANCEL_CONN_RSP, mndProcessSubscribeInternalRsp); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg); - mndSetMsgHandle(pMnode, TDMT_MND_GET_SUB_EP, mndProcessGetSubEpReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_DO_REBALANCE, mndProcessDoRebalanceMsg); + mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_CHANGE_RSP, mndProcessSubscribeInternalRsp); + mndSetMsgHandle(pMnode, TDMT_MND_MQ_DO_REBALANCE, mndProcessRebalanceReq); return sdbSetTable(pMnode->pSdb, table); } -static SMqSubscribeObj *mndCreateSubscription(SMnode *pMnode, const SMqTopicObj *pTopic, const char *cgroup) { - SMqSubscribeObj *pSub = tNewSubscribeObj(); +static SMqSubscribeObj *mndCreateSub(SMnode *pMnode, const SMqTopicObj *pTopic, const char *subKey) { + SMqSubscribeObj *pSub = tNewSubscribeObj(subKey); if (pSub == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - char key[TSDB_SUBSCRIBE_KEY_LEN]; - mndMakeSubscribeKey(key, cgroup, pTopic->name); - strcpy(pSub->key, key); + pSub->subType = pTopic->subType; + pSub->withTbName = pTopic->withTbName; + pSub->withSchema = pTopic->withSchema; + pSub->withTag = pTopic->withTag; + pSub->withTagSchema = pTopic->withTagSchema; + + ASSERT(taosHashGetSize(pSub->consumerHash) == 1); if (mndSchedInitSubEp(pMnode, pTopic, pSub) < 0) { - tDeleteSMqSubscribeObj(pSub); + tDeleteSubscribeObj(pSub); taosMemoryFree(pSub); return NULL; } - // TODO: disable alter subscribed table + ASSERT(taosHashGetSize(pSub->consumerHash) == 1); + return pSub; } -static int32_t mndBuildRebalanceMsg(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, - const char *topicName) { - SMqMVRebReq req = { - .vgId = pConsumerEp->vgId, - .oldConsumerId = pConsumerEp->oldConsumerId, - .newConsumerId = pConsumerEp->consumerId, - }; - req.topic = strdup(topicName); +static int32_t mndBuildSubChangeReq(void **pBuf, int32_t *pLen, const SMqSubscribeObj *pSub, + const SMqRebOutputVg *pRebVg) { + SMqRebVgReq req = {0}; + req.oldConsumerId = pRebVg->oldConsumerId; + req.newConsumerId = pRebVg->newConsumerId; + req.vgId = pRebVg->pVgEp->vgId; + req.qmsg = pRebVg->pVgEp->qmsg; + req.subType = pSub->subType; + req.withTbName = pSub->withTbName; + req.withSchema = pSub->withSchema; + req.withTag = pSub->withTag; + req.withTagSchema = pSub->withTagSchema; + strncpy(req.subKey, pSub->key, TSDB_SUBSCRIBE_KEY_LEN); - int32_t tlen = tEncodeSMqMVRebReq(NULL, &req); - void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); + int32_t tlen = sizeof(SMsgHead) + tEncodeSMqRebVgReq(NULL, &req); + void *buf = taosMemoryMalloc(tlen); if (buf == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } SMsgHead *pMsgHead = (SMsgHead *)buf; - pMsgHead->contLen = htonl(sizeof(SMsgHead) + tlen); - pMsgHead->vgId = htonl(pConsumerEp->vgId); + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(pRebVg->pVgEp->vgId); void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSMqMVRebReq(&abuf, &req); - taosMemoryFree(req.topic); - + tEncodeSMqRebVgReq(&abuf, &req); *pBuf = buf; *pLen = tlen; return 0; } -static int32_t mndPersistRebalanceMsg(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, - const char *topicName) { - ASSERT(pConsumerEp->oldConsumerId != -1); +static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SMqSubscribeObj *pSub, + const SMqRebOutputVg *pRebVg) { + ASSERT(pRebVg->oldConsumerId != pRebVg->newConsumerId); void *buf; int32_t tlen; - if (mndBuildRebalanceMsg(&buf, &tlen, pConsumerEp, topicName) < 0) { + if (mndBuildSubChangeReq(&buf, &tlen, pSub, pRebVg) < 0) { return -1; } - int32_t vgId = pConsumerEp->vgId; + int32_t vgId = pRebVg->pVgEp->vgId; SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId); STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgObj); action.pCont = buf; - action.contLen = sizeof(SMsgHead) + tlen; - action.msgType = TDMT_VND_MQ_REB; + action.contLen = tlen; + action.msgType = TDMT_VND_MQ_VG_CHANGE; mndReleaseVgroup(pMnode, pVgObj); if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(buf); return -1; } - - return 0; -} - -static int32_t mndBuildCancelConnReq(void **pBuf, int32_t *pLen, const SMqConsumerEp *pConsumerEp, - const char *oldTopicName) { - SMqCancelConnReq req = {0}; - req.consumerId = pConsumerEp->consumerId; - req.vgId = pConsumerEp->vgId; - req.epoch = pConsumerEp->epoch; - strcpy(req.topicName, oldTopicName); - - int32_t tlen = tEncodeSMqCancelConnReq(NULL, &req); - void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); - if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - SMsgHead *pMsgHead = (SMsgHead *)buf; - - pMsgHead->contLen = htonl(sizeof(SMsgHead) + tlen); - pMsgHead->vgId = htonl(pConsumerEp->vgId); - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSMqCancelConnReq(&abuf, &req); - *pBuf = buf; - *pLen = tlen; - return 0; -} - -static int32_t mndPersistCancelConnReq(SMnode *pMnode, STrans *pTrans, const SMqConsumerEp *pConsumerEp, - const char *oldTopicName) { - void *buf; - int32_t tlen; - if (mndBuildCancelConnReq(&buf, &tlen, pConsumerEp, oldTopicName) < 0) { - return -1; - } - - int32_t vgId = pConsumerEp->vgId; - SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId); - - STransAction action = {0}; - action.epSet = mndGetVgroupEpset(pMnode, pVgObj); - action.pCont = buf; - action.contLen = sizeof(SMsgHead) + tlen; - action.msgType = TDMT_VND_MQ_CANCEL_CONN; - - mndReleaseVgroup(pMnode, pVgObj); - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(buf); - return -1; - } - - return 0; -} - -static int32_t mndProcessGetSubEpReq(SNodeMsg *pMsg) { - SMnode *pMnode = pMsg->pNode; - SMqCMGetSubEpReq *pReq = (SMqCMGetSubEpReq *)pMsg->rpcMsg.pCont; - SMqCMGetSubEpRsp rsp = {0}; - int64_t consumerId = be64toh(pReq->consumerId); - int32_t epoch = ntohl(pReq->epoch); - - SMqConsumerObj *pConsumer = mndAcquireConsumer(pMsg->pNode, consumerId); - if (pConsumer == NULL) { - terrno = TSDB_CODE_MND_CONSUMER_NOT_EXIST; - return -1; - } - // TODO add lock - ASSERT(strcmp(pReq->cgroup, pConsumer->cgroup) == 0); - int32_t serverEpoch = pConsumer->epoch; - - // TODO - int32_t hbStatus = atomic_load_32(&pConsumer->hbStatus); - mDebug("consumer %ld epoch(%d) try to get sub ep, server epoch %d, old val: %d", consumerId, epoch, serverEpoch, - hbStatus); - atomic_store_32(&pConsumer->hbStatus, 0); - /*SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pConsumer);*/ - /*sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY);*/ - /*sdbWrite(pMnode->pSdb, pConsumerRaw);*/ - - strcpy(rsp.cgroup, pReq->cgroup); - if (epoch != serverEpoch) { - mInfo("send new assignment to consumer %ld, consumer epoch %d, server epoch %d", pConsumer->consumerId, epoch, - serverEpoch); - mDebug("consumer %ld try r lock", consumerId); - taosRLockLatch(&pConsumer->lock); - mDebug("consumer %ld r locked", consumerId); - SArray *pTopics = pConsumer->currentTopics; - int32_t sz = taosArrayGetSize(pTopics); - rsp.topics = taosArrayInit(sz, sizeof(SMqSubTopicEp)); - for (int32_t i = 0; i < sz; i++) { - char *topicName = taosArrayGetP(pTopics, i); - SMqSubscribeObj *pSub = mndAcquireSubscribe(pMnode, pConsumer->cgroup, topicName); - ASSERT(pSub); - int32_t csz = taosArrayGetSize(pSub->consumers); - // TODO: change to bsearch - for (int32_t j = 0; j < csz; j++) { - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j); - if (consumerId == pSubConsumer->consumerId) { - int32_t vgsz = taosArrayGetSize(pSubConsumer->vgInfo); - mInfo("topic %s has %d vg", topicName, serverEpoch); - - SMqSubTopicEp topicEp; - strcpy(topicEp.topic, topicName); - - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topicName); - ASSERT(pTopic != NULL); - topicEp.schema = pTopic->schema; - mndReleaseTopic(pMnode, pTopic); - - topicEp.vgs = taosArrayInit(vgsz, sizeof(SMqSubVgEp)); - for (int32_t k = 0; k < vgsz; k++) { - char offsetKey[TSDB_PARTITION_KEY_LEN]; - SMqConsumerEp *pConsumerEp = taosArrayGet(pSubConsumer->vgInfo, k); - SMqSubVgEp vgEp = { - .epSet = pConsumerEp->epSet, - .vgId = pConsumerEp->vgId, - .offset = -1, - }; - mndMakePartitionKey(offsetKey, pConsumer->cgroup, topicName, pConsumerEp->vgId); - SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, offsetKey); - if (pOffsetObj != NULL) { - vgEp.offset = pOffsetObj->offset; - mndReleaseOffset(pMnode, pOffsetObj); - } - taosArrayPush(topicEp.vgs, &vgEp); - } - taosArrayPush(rsp.topics, &topicEp); - break; - } - } - mndReleaseSubscribe(pMnode, pSub); - } - taosRUnLockLatch(&pConsumer->lock); - mDebug("consumer %ld r unlock", consumerId); - } - int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqCMGetSubEpRsp(NULL, &rsp); - void *buf = rpcMallocCont(tlen); - if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - ((SMqRspHead *)buf)->mqMsgType = TMQ_MSG_TYPE__EP_RSP; - ((SMqRspHead *)buf)->epoch = serverEpoch; - ((SMqRspHead *)buf)->consumerId = pConsumer->consumerId; - - void *abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); - tEncodeSMqCMGetSubEpRsp(&abuf, &rsp); - tDeleteSMqCMGetSubEpRsp(&rsp); - mndReleaseConsumer(pMnode, pConsumer); - pMsg->pRsp = buf; - pMsg->rspLen = tlen; return 0; } @@ -337,82 +188,298 @@ static SMqRebSubscribe *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { return pRebSub; } -static int32_t mndProcessMqTimerMsg(SNodeMsg *pMsg) { - SMnode *pMnode = pMsg->pNode; - SSdb *pSdb = pMnode->pSdb; - SMqConsumerObj *pConsumer; - void *pIter = NULL; - SMqDoRebalanceMsg *pRebMsg = rpcMallocCont(sizeof(SMqDoRebalanceMsg)); - pRebMsg->rebSubHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); - - while (1) { - pIter = sdbFetch(pSdb, SDB_CONSUMER, pIter, (void **)&pConsumer); - if (pIter == NULL) break; - int32_t hbStatus = atomic_add_fetch_32(&pConsumer->hbStatus, 1); - if (hbStatus > MND_SUBSCRIBE_REBALANCE_CNT) { - int32_t old = - atomic_val_compare_exchange_32(&pConsumer->status, MQ_CONSUMER_STATUS__ACTIVE, MQ_CONSUMER_STATUS__LOST); - if (old == MQ_CONSUMER_STATUS__ACTIVE) { - // get all topics of that topic - int32_t sz = taosArrayGetSize(pConsumer->currentTopics); - for (int32_t i = 0; i < sz; i++) { - char *topic = taosArrayGetP(pConsumer->currentTopics, i); - char key[TSDB_SUBSCRIBE_KEY_LEN]; - mndMakeSubscribeKey(key, pConsumer->cgroup, topic); - SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); - taosArrayPush(pRebSub->lostConsumers, &pConsumer->consumerId); - } - } - } - int32_t status = atomic_load_32(&pConsumer->status); - if (status == MQ_CONSUMER_STATUS__INIT || status == MQ_CONSUMER_STATUS__MODIFY) { - SArray *rebSubs; - if (status == MQ_CONSUMER_STATUS__INIT) { - rebSubs = pConsumer->currentTopics; - } else { - rebSubs = pConsumer->recentRemovedTopics; - } - int32_t sz = taosArrayGetSize(rebSubs); - for (int32_t i = 0; i < sz; i++) { - char *topic = taosArrayGetP(rebSubs, i); - char key[TSDB_SUBSCRIBE_KEY_LEN]; - mndMakeSubscribeKey(key, pConsumer->cgroup, topic); - SMqRebSubscribe *pRebSub = mndGetOrCreateRebSub(pRebMsg->rebSubHash, key); - if (status == MQ_CONSUMER_STATUS__INIT) { - taosArrayPush(pRebSub->newConsumers, &pConsumer->consumerId); - } else if (status == MQ_CONSUMER_STATUS__MODIFY) { - taosArrayPush(pRebSub->removedConsumers, &pConsumer->consumerId); - } - } - if (status == MQ_CONSUMER_STATUS__MODIFY) { - int32_t removeSz = taosArrayGetSize(pConsumer->recentRemovedTopics); - for (int32_t i = 0; i < removeSz; i++) { - char *topicName = taosArrayGetP(pConsumer->recentRemovedTopics, i); - taosMemoryFree(topicName); - } - taosArrayClear(pConsumer->recentRemovedTopics); - } - } - } - if (taosHashGetSize(pRebMsg->rebSubHash) != 0) { - mInfo("mq rebalance will be triggered"); - SRpcMsg rpcMsg = { - .msgType = TDMT_MND_MQ_DO_REBALANCE, - .pCont = pRebMsg, - .contLen = sizeof(SMqDoRebalanceMsg), - }; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); +static int32_t mndDoRebalance(SMnode *pMnode, const SMqRebInputObj *pInput, SMqRebOutputObj *pOutput) { + if (pInput->pTopic != NULL) { + // create subscribe + pOutput->pSub = mndCreateSub(pMnode, pInput->pTopic, pInput->pRebInfo->key); + ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) == 1); } else { - taosHashCleanup(pRebMsg->rebSubHash); - rpcFreeCont(pRebMsg); + pOutput->pSub = tCloneSubscribeObj(pInput->pOldSub); } + int32_t totalVgNum = pOutput->pSub->vgNum; + + mInfo("mq rebalance subscription: %s, vgNum: %d", pOutput->pSub->key, pOutput->pSub->vgNum); + + // 1. build temporary hash(vgId -> SMqRebOutputVg) to store modified vg + SHashObj *pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); + + ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) > 0); + // 2. check and get actual removed consumers, put their vg into hash + int32_t removedNum = taosArrayGetSize(pInput->pRebInfo->removedConsumers); + int32_t actualRemoved = 0; + for (int32_t i = 0; i < removedNum; i++) { + int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->removedConsumers, i); + ASSERT(consumerId > 0); + SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t)); + ASSERT(pEpInSub); + if (pEpInSub) { + ASSERT(consumerId == pEpInSub->consumerId); + actualRemoved++; + int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + for (int32_t j = 0; j < consumerVgNum; j++) { + SMqVgEp *pVgEp = taosArrayGetP(pEpInSub->vgs, j); + SMqRebOutputVg outputVg = { + .oldConsumerId = consumerId, + .newConsumerId = -1, + .pVgEp = pVgEp, + }; + taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); + } + taosHashRemove(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t)); + // put into removed + taosArrayPush(pOutput->removedConsumers, &consumerId); + } + } + ASSERT(removedNum == actualRemoved); + ASSERT(taosHashGetSize(pOutput->pSub->consumerHash) > 0); + + // if previously no consumer, there are vgs not assigned + { + int64_t unexistKey = -1; + SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &unexistKey, sizeof(int64_t)); + ASSERT(pEpInSub); + int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + for (int32_t i = 0; i < consumerVgNum; i++) { + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + SMqRebOutputVg rebOutput = { + .oldConsumerId = -1, + .newConsumerId = -1, + .pVgEp = pVgEp, + }; + taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &rebOutput, sizeof(SMqRebOutputVg)); + } + } + + // 3. calc vg number of each consumer + int32_t oldSz = 0; + if (pInput->pOldSub) { + oldSz = taosHashGetSize(pInput->pOldSub->consumerHash) - 1; + } + int32_t afterRebConsumerNum = + oldSz + taosArrayGetSize(pInput->pRebInfo->newConsumers) - taosArrayGetSize(pInput->pRebInfo->removedConsumers); + int32_t minVgCnt = 0; + int32_t imbConsumerNum = 0; + // calc num + if (afterRebConsumerNum) { + minVgCnt = totalVgNum / afterRebConsumerNum; + imbConsumerNum = totalVgNum % afterRebConsumerNum; + } + + // 4. first scan: remove consumer more than wanted, put to remove hash + int32_t imbCnt = 0; + void *pIter = NULL; + while (1) { + pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); + if (pIter == NULL) break; + SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; + if (pEpInSub->consumerId == -1) continue; + ASSERT(pEpInSub->consumerId > 0); + int32_t consumerVgNum = taosArrayGetSize(pEpInSub->vgs); + // all old consumers still existing are touched + // TODO optimize: touch only consumer whose vgs changed + taosArrayPush(pOutput->touchedConsumers, &pEpInSub->consumerId); + if (consumerVgNum > minVgCnt) { + if (imbCnt < imbConsumerNum) { + if (consumerVgNum == minVgCnt + 1) { + continue; + } else { + // pop until equal minVg + 1 + while (taosArrayGetSize(pEpInSub->vgs) > minVgCnt + 1) { + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + SMqRebOutputVg outputVg = { + .oldConsumerId = pEpInSub->consumerId, + .newConsumerId = -1, + .pVgEp = pVgEp, + }; + taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); + } + imbCnt++; + } + } else { + // pop until equal minVg + while (taosArrayGetSize(pEpInSub->vgs) > minVgCnt) { + SMqVgEp *pVgEp = *(SMqVgEp **)taosArrayPop(pEpInSub->vgs); + SMqRebOutputVg outputVg = { + .oldConsumerId = pEpInSub->consumerId, + .newConsumerId = -1, + .pVgEp = pVgEp, + }; + taosHashPut(pHash, &pVgEp->vgId, sizeof(int32_t), &outputVg, sizeof(SMqRebOutputVg)); + } + } + } + } + + // 5. add new consumer into sub + { + int32_t consumerNum = taosArrayGetSize(pInput->pRebInfo->newConsumers); + for (int32_t i = 0; i < consumerNum; i++) { + int64_t consumerId = *(int64_t *)taosArrayGet(pInput->pRebInfo->newConsumers, i); + ASSERT(consumerId > 0); + SMqConsumerEpInSub newConsumerEp; + newConsumerEp.consumerId = consumerId; + newConsumerEp.vgs = taosArrayInit(0, sizeof(void *)); + taosHashPut(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t), &newConsumerEp, + sizeof(SMqConsumerEpInSub)); + /*SMqConsumerEpInSub *pTestNew = taosHashGet(pOutput->pSub->consumerHash, &consumerId, sizeof(int64_t));*/ + /*ASSERT(pTestNew->consumerId == consumerId);*/ + /*ASSERT(pTestNew->vgs == newConsumerEp.vgs);*/ + taosArrayPush(pOutput->newConsumers, &consumerId); + } + } + + // 6. second scan: find consumer do not have enough vg, extract from temporary hash and assign to new consumer. + // All related vg should be put into rebVgs + SMqRebOutputVg *pRebVg = NULL; + void *pRemovedIter = NULL; + pIter = NULL; + while (1) { + pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); + if (pIter == NULL) break; + SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; + if (pEpInSub->consumerId == -1) continue; + ASSERT(pEpInSub->consumerId > 0); + + // push until equal minVg + while (taosArrayGetSize(pEpInSub->vgs) < minVgCnt) { + // iter hash and find one vg + pRemovedIter = taosHashIterate(pHash, pRemovedIter); + ASSERT(pRemovedIter); + pRebVg = (SMqRebOutputVg *)pRemovedIter; + // push + taosArrayPush(pEpInSub->vgs, &pRebVg->pVgEp); + pRebVg->newConsumerId = pEpInSub->consumerId; + taosArrayPush(pOutput->rebVgs, pRebVg); + } + } + + // 7. handle unassigned vg + if (taosHashGetSize(pOutput->pSub->consumerHash) != 1) { + // if has consumer, assign all left vg + while (1) { + pRemovedIter = taosHashIterate(pHash, pRemovedIter); + if (pRemovedIter == NULL) break; + pIter = taosHashIterate(pOutput->pSub->consumerHash, pIter); + ASSERT(pIter); + pRebVg = (SMqRebOutputVg *)pRemovedIter; + SMqConsumerEpInSub *pEpInSub = (SMqConsumerEpInSub *)pIter; + if (pEpInSub->consumerId == -1) continue; + ASSERT(pEpInSub->consumerId > 0); + taosArrayPush(pEpInSub->vgs, &pRebVg->pVgEp); + pRebVg->newConsumerId = pEpInSub->consumerId; + taosArrayPush(pOutput->rebVgs, pRebVg); + } + } else { + // if all consumer is removed, put all vg into unassigned + int64_t unexistKey = -1; + SMqConsumerEpInSub *pEpInSub = taosHashGet(pOutput->pSub->consumerHash, &unexistKey, sizeof(int64_t)); + ASSERT(pEpInSub); + ASSERT(pEpInSub->consumerId == -1); + + pIter = NULL; + SMqRebOutputVg *pRebOutput = NULL; + while (1) { + pIter = taosHashIterate(pHash, pIter); + if (pIter == NULL) break; + pRebOutput = (SMqRebOutputVg *)pIter; + ASSERT(pRebOutput->newConsumerId == -1); + taosArrayPush(pEpInSub->vgs, &pRebOutput->pVgEp); + taosArrayPush(pOutput->rebVgs, pRebOutput); + } + } + + // 8. generate logs + + // 9. clear + taosHashCleanup(pHash); + return 0; } -static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { +static int32_t mndPersistRebResult(SMnode *pMnode, SNodeMsg *pMsg, const SMqRebOutputObj *pOutput) { + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_REBALANCE, &pMsg->rpcMsg); + if (pTrans == NULL) { + return -1; + } + // make txn: + // 1. redo action: action to all vg + const SArray *rebVgs = pOutput->rebVgs; + int32_t vgNum = taosArrayGetSize(rebVgs); + for (int32_t i = 0; i < vgNum; i++) { + SMqRebOutputVg *pRebVg = taosArrayGet(rebVgs, i); + if (mndPersistSubChangeVgReq(pMnode, pTrans, pOutput->pSub, pRebVg) < 0) { + goto REB_FAIL; + } + } + + // 2. redo log: subscribe and vg assignment + // subscribe + if (mndSetSubRedoLogs(pMnode, pTrans, pOutput->pSub) != 0) { + goto REB_FAIL; + } + + // 3. commit log: consumer to update status and epoch + // 3.1 set touched consumer + int32_t consumerNum = taosArrayGetSize(pOutput->touchedConsumers); + for (int32_t i = 0; i < consumerNum; i++) { + int64_t consumerId = *(int64_t *)taosArrayGet(pOutput->touchedConsumers, i); + SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId); + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__TOUCH; + mndReleaseConsumer(pMnode, pConsumerOld); + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) { + goto REB_FAIL; + } + } + // 3.2 set new consumer + consumerNum = taosArrayGetSize(pOutput->newConsumers); + for (int32_t i = 0; i < consumerNum; i++) { + int64_t consumerId = *(int64_t *)taosArrayGet(pOutput->newConsumers, i); + ASSERT(consumerId > 0); + SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId); + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__ADD; + char *topic = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); + char cgroup[TSDB_CGROUP_LEN]; + mndSplitSubscribeKey(pOutput->pSub->key, topic, cgroup); + taosArrayPush(pConsumerNew->rebNewTopics, &topic); + mndReleaseConsumer(pMnode, pConsumerOld); + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) { + goto REB_FAIL; + } + } + + // 3.3 set removed consumer + consumerNum = taosArrayGetSize(pOutput->removedConsumers); + for (int32_t i = 0; i < consumerNum; i++) { + int64_t consumerId = *(int64_t *)taosArrayGet(pOutput->removedConsumers, i); + ASSERT(consumerId > 0); + SMqConsumerObj *pConsumerOld = mndAcquireConsumer(pMnode, consumerId); + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumerOld->consumerId, pConsumerOld->cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__REMOVE; + char *topic = taosMemoryCalloc(1, TSDB_TOPIC_FNAME_LEN); + char cgroup[TSDB_CGROUP_LEN]; + mndSplitSubscribeKey(pOutput->pSub->key, topic, cgroup); + taosArrayPush(pConsumerNew->rebRemovedTopics, &topic); + mndReleaseConsumer(pMnode, pConsumerOld); + if (mndSetConsumerCommitLogs(pMnode, pTrans, pConsumerNew) != 0) { + goto REB_FAIL; + } + } + // 4. commit log: modification log + if (mndTransPrepare(pMnode, pTrans) != 0) goto REB_FAIL; + + mndTransDrop(pTrans); + return 0; + +REB_FAIL: + mndTransDrop(pTrans); + return -1; +} + +static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; SMqDoRebalanceMsg *pReq = pMsg->rpcMsg.pCont; - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_REBALANCE, &pMsg->rpcMsg); void *pIter = NULL; mInfo("mq rebalance start"); @@ -420,192 +487,52 @@ static int32_t mndProcessDoRebalanceMsg(SNodeMsg *pMsg) { while (1) { pIter = taosHashIterate(pReq->rebSubHash, pIter); if (pIter == NULL) break; + SMqRebInputObj rebInput = {0}; + + SMqRebOutputObj rebOutput = {0}; + rebOutput.newConsumers = taosArrayInit(0, sizeof(void *)); + rebOutput.removedConsumers = taosArrayInit(0, sizeof(void *)); + rebOutput.touchedConsumers = taosArrayInit(0, sizeof(void *)); + rebOutput.rebVgs = taosArrayInit(0, sizeof(SMqRebOutputVg)); + SMqRebSubscribe *pRebSub = (SMqRebSubscribe *)pIter; SMqSubscribeObj *pSub = mndAcquireSubscribeByKey(pMnode, pRebSub->key); - taosMemoryFreeClear(pRebSub->key); - mInfo("mq rebalance subscription: %s, vgNum: %d, unassignedVg: %d", pSub->key, pSub->vgNum, - (int32_t)taosArrayGetSize(pSub->unassignedVg)); - - // remove lost consumer - for (int32_t i = 0; i < taosArrayGetSize(pRebSub->lostConsumers); i++) { - int64_t lostConsumerId = *(int64_t *)taosArrayGet(pRebSub->lostConsumers, i); - - mInfo("mq remove lost consumer %" PRId64 "", lostConsumerId); - - for (int32_t j = 0; j < taosArrayGetSize(pSub->consumers); j++) { - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, j); - if (pSubConsumer->consumerId == lostConsumerId) { - taosArrayAddAll(pSub->unassignedVg, pSubConsumer->vgInfo); - taosArrayPush(pSub->lostConsumers, pSubConsumer); - taosArrayRemove(pSub->consumers, j); - break; - } - } + if (pSub == NULL) { + // split sub key and extract topic + char topic[TSDB_TOPIC_FNAME_LEN]; + char cgroup[TSDB_CGROUP_LEN]; + mndSplitSubscribeKey(pRebSub->key, topic, cgroup); + SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); + ASSERT(pTopic); + taosRLockLatch(&pTopic->lock); + rebInput.pTopic = pTopic; } - // calculate rebalance - int32_t consumerNum = taosArrayGetSize(pSub->consumers); - if (consumerNum != 0) { - int32_t vgNum = pSub->vgNum; - int32_t vgEachConsumer = vgNum / consumerNum; - int32_t imbalanceVg = vgNum % consumerNum; + rebInput.pRebInfo = pRebSub; + rebInput.pOldSub = pSub; - // iterate all consumers, set unassignedVgStash - for (int32_t i = 0; i < consumerNum; i++) { - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, i); - int32_t vgThisConsumerBeforeRb = taosArrayGetSize(pSubConsumer->vgInfo); - int32_t vgThisConsumerAfterRb; - if (i < imbalanceVg) - vgThisConsumerAfterRb = vgEachConsumer + 1; - else - vgThisConsumerAfterRb = vgEachConsumer; + // TODO replace assert with error check + ASSERT(mndDoRebalance(pMnode, &rebInput, &rebOutput) == 0); + // if add more consumer to balanced subscribe, + // possibly no vg is changed + /*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/ + ASSERT(mndPersistRebResult(pMnode, pMsg, &rebOutput) == 0); - mInfo("mq consumer:%" PRId64 ", connectted vgroup number change from %d to %d", pSubConsumer->consumerId, - vgThisConsumerBeforeRb, vgThisConsumerAfterRb); - - while (taosArrayGetSize(pSubConsumer->vgInfo) > vgThisConsumerAfterRb) { - SMqConsumerEp *pConsumerEp = taosArrayPop(pSubConsumer->vgInfo); - ASSERT(pConsumerEp != NULL); - ASSERT(pConsumerEp->consumerId == pSubConsumer->consumerId); - taosArrayPush(pSub->unassignedVg, pConsumerEp); - mDebug("mq rebalance: vg %d push to unassignedVg", pConsumerEp->vgId); - } - - SMqConsumerObj *pRebConsumer = mndAcquireConsumer(pMnode, pSubConsumer->consumerId); - mDebug("consumer %ld try w lock", pRebConsumer->consumerId); - taosWLockLatch(&pRebConsumer->lock); - mDebug("consumer %ld w locked", pRebConsumer->consumerId); - int32_t status = atomic_load_32(&pRebConsumer->status); - if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb || - (vgThisConsumerAfterRb != 0 && status != MQ_CONSUMER_STATUS__ACTIVE) || - (vgThisConsumerAfterRb == 0 && status != MQ_CONSUMER_STATUS__LOST)) { - /*if (vgThisConsumerAfterRb != vgThisConsumerBeforeRb) {*/ - /*pRebConsumer->epoch++;*/ - /*}*/ - if (vgThisConsumerAfterRb != 0) { - atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__ACTIVE); - } else { - atomic_store_32(&pRebConsumer->status, MQ_CONSUMER_STATUS__IDLE); - } - - mInfo("mq consumer:%" PRId64 ", status change from %d to %d", pRebConsumer->consumerId, status, - pRebConsumer->status); - - SSdbRaw *pConsumerRaw = mndConsumerActionEncode(pRebConsumer); - sdbSetRawStatus(pConsumerRaw, SDB_STATUS_READY); - mndTransAppendCommitlog(pTrans, pConsumerRaw); - } - taosWUnLockLatch(&pRebConsumer->lock); - mDebug("consumer %ld w unlock", pRebConsumer->consumerId); - mndReleaseConsumer(pMnode, pRebConsumer); - } - - // assign to vgroup - if (taosArrayGetSize(pSub->unassignedVg) != 0) { - for (int32_t i = 0; i < consumerNum; i++) { - SMqSubConsumer *pSubConsumer = taosArrayGet(pSub->consumers, i); - int32_t vgThisConsumerAfterRb; - if (i < imbalanceVg) - vgThisConsumerAfterRb = vgEachConsumer + 1; - else - vgThisConsumerAfterRb = vgEachConsumer; - - while (taosArrayGetSize(pSubConsumer->vgInfo) < vgThisConsumerAfterRb) { - SMqConsumerEp *pConsumerEp = taosArrayPop(pSub->unassignedVg); - mDebug("mq rebalance: vg %d pop from unassignedVg", pConsumerEp->vgId); - ASSERT(pConsumerEp != NULL); - - pConsumerEp->oldConsumerId = pConsumerEp->consumerId; - pConsumerEp->consumerId = pSubConsumer->consumerId; - // TODO - pConsumerEp->epoch = 0; - taosArrayPush(pSubConsumer->vgInfo, pConsumerEp); - - char topic[TSDB_TOPIC_FNAME_LEN]; - char cgroup[TSDB_CGROUP_LEN]; - mndSplitSubscribeKey(pSub->key, topic, cgroup); - if (pConsumerEp->oldConsumerId == -1) { - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, topic); - - mInfo("mq set conn: assign vgroup %d of topic %s to consumer %" PRId64 " cgroup: %s", pConsumerEp->vgId, - topic, pConsumerEp->consumerId, cgroup); - - mndPersistMqSetConnReq(pMnode, pTrans, pTopic, cgroup, pConsumerEp); - mndReleaseTopic(pMnode, pTopic); - } else { - mInfo("mq rebalance: assign vgroup %d, from consumer %" PRId64 " to consumer %" PRId64 "", - pConsumerEp->vgId, pConsumerEp->oldConsumerId, pConsumerEp->consumerId); - - mndPersistRebalanceMsg(pMnode, pTrans, pConsumerEp, topic); - } - } - } - } - ASSERT(taosArrayGetSize(pSub->unassignedVg) == 0); - - // TODO: log rebalance statistics - SSdbRaw *pSubRaw = mndSubActionEncode(pSub); - sdbSetRawStatus(pSubRaw, SDB_STATUS_READY); - mndTransAppendRedolog(pTrans, pSubRaw); + if (rebInput.pTopic) { + SMqTopicObj *pTopic = (SMqTopicObj *)rebInput.pTopic; + taosRUnLockLatch(&pTopic->lock); + mndReleaseTopic(pMnode, pTopic); + } else { + mndReleaseSubscribe(pMnode, pSub); } - mndReleaseSubscribe(pMnode, pSub); - } - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("mq-rebalance-trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - taosHashCleanup(pReq->rebSubHash); - mndTransDrop(pTrans); - return -1; } + // reset flag + atomic_store_8(pReq->mqInReb, 0); + mInfo("mq rebalance completed successfully"); taosHashCleanup(pReq->rebSubHash); - mndTransDrop(pTrans); - return 0; -} -static int32_t mndPersistMqSetConnReq(SMnode *pMnode, STrans *pTrans, const SMqTopicObj *pTopic, const char *cgroup, - const SMqConsumerEp *pConsumerEp) { - ASSERT(pConsumerEp->oldConsumerId == -1); - int32_t vgId = pConsumerEp->vgId; - - SMqSetCVgReq req = { - .vgId = vgId, - .consumerId = pConsumerEp->consumerId, - .sql = pTopic->sql, - .physicalPlan = pTopic->physicalPlan, - .qmsg = pConsumerEp->qmsg, - }; - - strcpy(req.cgroup, cgroup); - strcpy(req.topicName, pTopic->name); - int32_t tlen = tEncodeSMqSetCVgReq(NULL, &req); - void *buf = taosMemoryMalloc(sizeof(SMsgHead) + tlen); - if (buf == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - SMsgHead *pMsgHead = (SMsgHead *)buf; - - pMsgHead->contLen = htonl(sizeof(SMsgHead) + tlen); - pMsgHead->vgId = htonl(vgId); - - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - tEncodeSMqSetCVgReq(&abuf, &req); - - SVgObj *pVgObj = mndAcquireVgroup(pMnode, vgId); - - STransAction action = {0}; - action.epSet = mndGetVgroupEpset(pMnode, pVgObj); - action.pCont = buf; - action.contLen = sizeof(SMsgHead) + tlen; - action.msgType = TDMT_VND_MQ_SET_CONN; - - mndReleaseVgroup(pMnode, pVgObj); - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(buf); - return -1; - } return 0; } @@ -697,16 +624,23 @@ static int32_t mndSubActionInsert(SSdb *pSdb, SMqSubscribeObj *pSub) { static int32_t mndSubActionDelete(SSdb *pSdb, SMqSubscribeObj *pSub) { mTrace("subscribe:%s, perform delete action", pSub->key); - tDeleteSMqSubscribeObj(pSub); + tDeleteSubscribeObj(pSub); return 0; } static int32_t mndSubActionUpdate(SSdb *pSdb, SMqSubscribeObj *pOldSub, SMqSubscribeObj *pNewSub) { mTrace("subscribe:%s, perform update action", pOldSub->key); + taosWLockLatch(&pOldSub->lock); + + SHashObj *tmp = pOldSub->consumerHash; + pOldSub->consumerHash = pNewSub->consumerHash; + pNewSub->consumerHash = tmp; + + taosWUnLockLatch(&pOldSub->lock); return 0; } -static int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName) { +int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName) { int32_t tlen = strlen(cgroup); memcpy(key, cgroup, tlen); key[tlen] = TMQ_SEPARATOR; @@ -739,6 +673,7 @@ void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub) { sdbRelease(pSdb, pSub); } +#if 0 static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { SMnode *pMnode = pMsg->pNode; char *msgStr = pMsg->rpcMsg.pCont; @@ -901,6 +836,7 @@ static int32_t mndProcessSubscribeReq(SNodeMsg *pMsg) { if (!createConsumer) mndReleaseConsumer(pMnode, pConsumer); return TSDB_CODE_MND_ACTION_IN_PROGRESS; } +#endif static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pRsp) { mndTransProcessRsp(pRsp); diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 83a5cf938f..e445022548 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -21,9 +21,6 @@ #include "thttp.h" #include "tjson.h" -#define TELEMETRY_SERVER "telemetry.taosdata.com" -#define TELEMETRY_PORT 80 - typedef struct { int64_t numOfDnode; int64_t numOfMnode; @@ -62,6 +59,12 @@ static void mndGetStat(SMnode* pMnode, SMnodeStat* pStat) { sdbRelease(pSdb, pVgroup); } + + pStat->numOfChildTable = 100; + pStat->numOfColumn = 200; + pStat->totalPoints = 300; + pStat->totalStorage = 400; + pStat->compStorage = 500; } static void mndBuildRuntimeInfo(SMnode* pMnode, SJson* pJson) { @@ -122,12 +125,14 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { static int32_t mndProcessTelemTimer(SNodeMsg* pReq) { SMnode* pMnode = pReq->pNode; STelemMgmt* pMgmt = &pMnode->telemMgmt; - if (!pMgmt->enable) return 0; + if (!tsEnableTelem) return 0; taosWLockLatch(&pMgmt->lock); char* pCont = mndBuildTelemetryReport(pMnode); if (pCont != NULL) { - taosSendHttpReport(TELEMETRY_SERVER, TELEMETRY_PORT, pCont, strlen(pCont), HTTP_FLAT); + if (taosSendHttpReport(tsTelemServer, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT) != 0) { + mError("failed to send telemetry msg"); + } taosMemoryFree(pCont); } taosWUnLockLatch(&pMgmt->lock); @@ -138,7 +143,6 @@ int32_t mndInitTelem(SMnode* pMnode) { STelemMgmt* pMgmt = &pMnode->telemMgmt; taosInitRWLatch(&pMgmt->lock); - pMgmt->enable = tsEnableTelemetryReporting; taosGetEmail(pMgmt->email, sizeof(pMgmt->email)); mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer); diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index b9c42fe899..22b1b404bb 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -76,7 +76,13 @@ SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) { SDB_SET_INT64(pRaw, dataPos, pTopic->updateTime, TOPIC_ENCODE_OVER); SDB_SET_INT64(pRaw, dataPos, pTopic->uid, TOPIC_ENCODE_OVER); SDB_SET_INT64(pRaw, dataPos, pTopic->dbUid, TOPIC_ENCODE_OVER); + SDB_SET_INT64(pRaw, dataPos, pTopic->subDbUid, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->version, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->subType, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->withTbName, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->withSchema, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->withTag, TOPIC_ENCODE_OVER); + SDB_SET_INT8(pRaw, dataPos, pTopic->withTagSchema, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->sqlLen, TOPIC_ENCODE_OVER); SDB_SET_BINARY(pRaw, dataPos, pTopic->sql, pTopic->sqlLen, TOPIC_ENCODE_OVER); SDB_SET_INT32(pRaw, dataPos, pTopic->astLen, TOPIC_ENCODE_OVER); @@ -134,7 +140,13 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) { SDB_GET_INT64(pRaw, dataPos, &pTopic->updateTime, TOPIC_DECODE_OVER); SDB_GET_INT64(pRaw, dataPos, &pTopic->uid, TOPIC_DECODE_OVER); SDB_GET_INT64(pRaw, dataPos, &pTopic->dbUid, TOPIC_DECODE_OVER); + SDB_GET_INT64(pRaw, dataPos, &pTopic->subDbUid, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->version, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->subType, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->withTbName, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->withSchema, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->withTag, TOPIC_DECODE_OVER); + SDB_GET_INT8(pRaw, dataPos, &pTopic->withTagSchema, TOPIC_DECODE_OVER); SDB_GET_INT32(pRaw, dataPos, &pTopic->sqlLen, TOPIC_DECODE_OVER); pTopic->sql = taosMemoryCalloc(pTopic->sqlLen, sizeof(char)); @@ -254,34 +266,14 @@ static int32_t mndCheckCreateTopicReq(SCMCreateTopicReq *pCreate) { terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; return -1; } + + if ((pCreate->ast == NULL || pCreate->ast[0] == 0) && pCreate->subscribeDbName[0] == 0) { + terrno = TSDB_CODE_MND_INVALID_TOPIC_OPTION; + return -1; + } return 0; } -#if 0 -static int32_t mndGetPlanString(const SCMCreateTopicReq *pCreate, char **pStr) { - if (NULL == pCreate->ast) { - return TSDB_CODE_SUCCESS; - } - - SNode *pAst = NULL; - int32_t code = nodesStringToNode(pCreate->ast, &pAst); - - SQueryPlan *pPlan = NULL; - if (TSDB_CODE_SUCCESS == code) { - SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; - code = qCreateQueryPlan(&cxt, &pPlan, NULL); - } - - if (TSDB_CODE_SUCCESS == code) { - code = nodesNodeToString(pPlan, false, pStr, NULL); - } - nodesDestroyNode(pAst); - nodesDestroyNode(pPlan); - terrno = code; - return code; -} -#endif - static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq *pCreate, SDbObj *pDb) { mDebug("topic:%s to create", pCreate->name); SMqTopicObj topicObj = {0}; @@ -297,28 +289,38 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq topicObj.ast = strdup(pCreate->ast); topicObj.astLen = strlen(pCreate->ast) + 1; - SNode *pAst = NULL; - if (nodesStringToNode(pCreate->ast, &pAst) != 0) { - mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - return -1; - } + if (pCreate->ast && pCreate->ast[0]) { + topicObj.subType = TOPIC_SUB_TYPE__TABLE; + topicObj.withTbName = 0; + topicObj.withSchema = 0; - SQueryPlan *pPlan = NULL; + SNode *pAst = NULL; + if (nodesStringToNode(pCreate->ast, &pAst) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } - SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; - if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) { - mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - return -1; - } + SQueryPlan *pPlan = NULL; - if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) { - mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - return -1; - } + SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true}; + if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } - if (nodesNodeToString(pPlan, false, &topicObj.physicalPlan, NULL) != 0) { - mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); - return -1; + if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + + if (nodesNodeToString(pPlan, false, &topicObj.physicalPlan, NULL) != 0) { + mError("topic:%s, failed to create since %s", pCreate->name, terrstr()); + return -1; + } + } else { + topicObj.subType = TOPIC_SUB_TYPE__DB; + topicObj.withTbName = 1; + topicObj.withSchema = 1; } STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 13fe01e16e..daf8dd431f 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -22,12 +22,14 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndFunc.h" +#include "mndGrant.h" #include "mndInfoSchema.h" -#include "mndPerfSchema.h" #include "mndMnode.h" #include "mndOffset.h" +#include "mndPerfSchema.h" #include "mndProfile.h" #include "mndQnode.h" +#include "mndQuery.h" #include "mndShow.h" #include "mndSma.h" #include "mndSnode.h" @@ -40,12 +42,9 @@ #include "mndTrans.h" #include "mndUser.h" #include "mndVgroup.h" -#include "mndQuery.h" -#include "mndGrant.h" #define MQ_TIMER_MS 3000 #define TRNAS_TIMER_MS 6000 -#define TELEM_TIMER_MS 86400000 static void *mndBuildTimerMsg(int32_t *pContLen) { SMTimerReq timerReq = {0}; @@ -97,7 +96,7 @@ static void mndPullupTelem(void *param, void *tmrId) { tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } - taosTmrReset(mndPullupTelem, TELEM_TIMER_MS, pMnode, pMnode->timer, &pMnode->telemTimer); + taosTmrReset(mndPullupTelem, tsTelemInterval * 1000, pMnode, pMnode->timer, &pMnode->telemTimer); } static int32_t mndInitTimer(SMnode *pMnode) { @@ -117,7 +116,8 @@ static int32_t mndInitTimer(SMnode *pMnode) { return -1; } - if (taosTmrReset(mndPullupTelem, 60000, pMnode, pMnode->timer, &pMnode->telemTimer)) { + int32_t interval = tsTelemInterval < 10 ? tsTelemInterval : 10; + if (taosTmrReset(mndPullupTelem, interval * 1000, pMnode, pMnode->timer, &pMnode->telemTimer)) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } diff --git a/source/dnode/mnode/impl/test/func/func.cpp b/source/dnode/mnode/impl/test/func/func.cpp index 22b0387d8b..1569976105 100644 --- a/source/dnode/mnode/impl/test/func/func.cpp +++ b/source/dnode/mnode/impl/test/func/func.cpp @@ -32,6 +32,7 @@ void MndTestFunc::SetCode(SCreateFuncReq* pReq, const char* pCode) { int32_t len = strlen(pCode); pReq->pCode = (char*)taosMemoryCalloc(1, len + 1); strcpy(pReq->pCode, pCode); + pReq->codeLen = len; } void MndTestFunc::SetComment(SCreateFuncReq* pReq, const char* pComment) { @@ -60,21 +61,6 @@ TEST_F(MndTestFunc, 02_Create_Func) { ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_NAME); } - { - SCreateFuncReq createReq = {0}; - strcpy(createReq.name, "f1"); - SetCode(&createReq, "code1"); - - int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSCreateFuncReq(pReq, contLen, &createReq); - tFreeSCreateFuncReq(&createReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT); - } - { SCreateFuncReq createReq = {0}; strcpy(createReq.name, "f1"); @@ -90,22 +76,6 @@ TEST_F(MndTestFunc, 02_Create_Func) { ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_CODE); } - { - SCreateFuncReq createReq = {0}; - strcpy(createReq.name, "f1"); - SetCode(&createReq, "code1"); - SetComment(&createReq, ""); - - int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq); - void* pReq = rpcMallocCont(contLen); - tSerializeSCreateFuncReq(pReq, contLen, &createReq); - tFreeSCreateFuncReq(&createReq); - - SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen); - ASSERT_NE(pRsp, nullptr); - ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT); - } - { SCreateFuncReq createReq = {0}; strcpy(createReq.name, "f1"); @@ -329,7 +299,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1); - EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1); EXPECT_STREQ("comment2", pFuncInfo->pComment); EXPECT_STREQ("code2", pFuncInfo->pCode); @@ -368,7 +337,6 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { EXPECT_EQ(pFuncInfo->bufSize, 6); EXPECT_EQ(pFuncInfo->signature, 18); EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1); - EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1); EXPECT_STREQ("comment2", pFuncInfo->pComment); EXPECT_STREQ("code2", pFuncInfo->pCode); } diff --git a/source/dnode/mnode/impl/test/profile/profile.cpp b/source/dnode/mnode/impl/test/profile/profile.cpp index 2c3be2135b..9c8e0298aa 100644 --- a/source/dnode/mnode/impl/test/profile/profile.cpp +++ b/source/dnode/mnode/impl/test/profile/profile.cpp @@ -30,8 +30,15 @@ int32_t MndTestProfile::connId; TEST_F(MndTestProfile, 01_ConnectMsg) { SConnectReq connectReq = {0}; connectReq.pid = 1234; + + char passwd[] = "taosdata"; + char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; + taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt); + strcpy(connectReq.app, "mnode_test_profile"); strcpy(connectReq.db, ""); + strcpy(connectReq.user, "root"); + strcpy(connectReq.passwd, secretEncrypt); int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); void* pReq = rpcMallocCont(contLen); @@ -58,10 +65,16 @@ TEST_F(MndTestProfile, 01_ConnectMsg) { } TEST_F(MndTestProfile, 02_ConnectMsg_InvalidDB) { + char passwd[] = "taosdata"; + char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; + taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt); + SConnectReq connectReq = {0}; connectReq.pid = 1234; strcpy(connectReq.app, "mnode_test_profile"); strcpy(connectReq.db, "invalid_db"); + strcpy(connectReq.user, "root"); + strcpy(connectReq.passwd, secretEncrypt); int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); void* pReq = rpcMallocCont(contLen); diff --git a/source/dnode/mnode/impl/test/show/show.cpp b/source/dnode/mnode/impl/test/show/show.cpp index 201a42e3ef..2b0eaa0bec 100644 --- a/source/dnode/mnode/impl/test/show/show.cpp +++ b/source/dnode/mnode/impl/test/show/show.cpp @@ -54,10 +54,16 @@ TEST_F(MndTestShow, 02_ShowMsg_InvalidMsgStart) { } TEST_F(MndTestShow, 03_ShowMsg_Conn) { + char passwd[] = "taosdata"; + char secretEncrypt[TSDB_PASSWORD_LEN] = {0}; + taosEncryptPass_c((uint8_t*)passwd, strlen(passwd), secretEncrypt); + SConnectReq connectReq = {0}; connectReq.pid = 1234; strcpy(connectReq.app, "mnode_test_show"); strcpy(connectReq.db, ""); + strcpy(connectReq.user, "root"); + strcpy(connectReq.passwd, secretEncrypt); int32_t contLen = tSerializeSConnectReq(NULL, 0, &connectReq); void* pReq = rpcMallocCont(contLen); @@ -74,4 +80,4 @@ TEST_F(MndTestShow, 03_ShowMsg_Conn) { TEST_F(MndTestShow, 04_ShowMsg_Cluster) { test.SendShowReq(TSDB_MGMT_TABLE_CLUSTER, "cluster", ""); EXPECT_EQ(test.GetShowRows(), 1); -} \ No newline at end of file +} diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 834d11fc20..2b52d333da 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -109,8 +109,7 @@ int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList); int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver); bool tqNextDataBlock(STqReadHandle *pHandle); -int tqRetrieveDataBlockInfo(STqReadHandle *pHandle, SDataBlockInfo *pBlockInfo); -SArray *tqRetrieveDataBlock(STqReadHandle *pHandle); +int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, int32_t *pNumOfRows); // need to reposition diff --git a/source/dnode/vnode/src/inc/tq.h b/source/dnode/vnode/src/inc/tq.h index ed33473b16..5e074eeb12 100644 --- a/source/dnode/vnode/src/inc/tq.h +++ b/source/dnode/vnode/src/inc/tq.h @@ -16,6 +16,13 @@ #ifndef _TD_VNODE_TQ_H_ #define _TD_VNODE_TQ_H_ +#include "executor.h" +#include "os.h" +#include "thash.h" +#include "tmsg.h" +#include "ttimer.h" +#include "wal.h" + #ifdef __cplusplus extern "C" { #endif @@ -30,12 +37,6 @@ extern "C" { #define tqTrace(...) do { if (tqDebugFlag & DEBUG_TRACE) { taosPrintLog("TQ ", DEBUG_TRACE, tqDebugFlag, __VA_ARGS__); }} while(0) // clang-format on -enum { - TQ_STREAM_TOKEN__DATA = 1, - TQ_STREAM_TOKEN__WATERMARK, - TQ_STREAM_TOKEN__CHECKPOINT, -}; - #define TQ_BUFFER_SIZE 4 #define TQ_BUCKET_MASK 0xFF @@ -151,22 +152,27 @@ typedef struct { } STqMetaStore; typedef struct { - SMemAllocatorFactory* pAllocatorFactory; - SMemAllocator* pAllocator; -} STqMemRef; + char subKey[TSDB_SUBSCRIBE_KEY_LEN]; + int64_t consumerId; + int32_t epoch; + char* qmsg; + // SRWLatch lock; + SWalReadHandle* pReadHandle; + // number should be identical to fetch thread num + qTaskInfo_t task[4]; +} STqExec; struct STQ { // the collection of groups // the handle of meta kvstore bool writeTrigger; char* path; - STqMemRef tqMemRef; STqMetaStore* tqMeta; - // STqPushMgr* tqPushMgr; - SHashObj* pStreamTasks; - SVnode* pVnode; - SWal* pWal; - SMeta* pVnodeMeta; + SHashObj* tqMetaNew; // subKey -> tqExec + SHashObj* pStreamTasks; + SVnode* pVnode; + SWal* pWal; + SMeta* pVnodeMeta; }; typedef struct { @@ -230,10 +236,6 @@ typedef struct { // TODO sync function } STqStreamPusher; -typedef struct { - int8_t type; // mq or stream -} STqPusher; - typedef struct { SHashObj* pHash; // } STqPushMgr; @@ -257,9 +259,10 @@ int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version); int tqCommit(STQ*); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId); -int32_t tqProcessSetConnReq(STQ* pTq, char* msg); -int32_t tqProcessRebReq(STQ* pTq, char* msg); -int32_t tqProcessCancelConnReq(STQ* pTq, char* msg); +int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen); +// int32_t tqProcessSetConnReq(STQ* pTq, char* msg); +// int32_t tqProcessRebReq(STQ* pTq, char* msg); +// int32_t tqProcessCancelConnReq(STQ* pTq, char* msg); int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen, int32_t workerId); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen, int32_t workerId); @@ -314,4 +317,4 @@ STqStreamPusher* tqAddStreamPusher(STqPushMgr* pushMgr, int64_t streamId, SEpSet } #endif -#endif /*_TD_VNODE_TQ_H_*/ \ No newline at end of file +#endif /*_TD_VNODE_TQ_H_*/ diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 0aa6023eaf..510dd32459 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -29,31 +29,14 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, SMe pTq->pVnode = pVnode; pTq->pWal = pWal; pTq->pVnodeMeta = pVnodeMeta; -#if 0 - pTq->tqMemRef.pAllocatorFactory = allocFac; - pTq->tqMemRef.pAllocator = allocFac->create(allocFac); - if (pTq->tqMemRef.pAllocator == NULL) { - // TODO: error code of buffer pool - } -#endif pTq->tqMeta = tqStoreOpen(pTq, path, (FTqSerialize)tqSerializeConsumer, (FTqDeserialize)tqDeserializeConsumer, (FTqDelete)taosMemoryFree, 0); if (pTq->tqMeta == NULL) { taosMemoryFree(pTq); -#if 0 - allocFac->destroy(allocFac, pTq->tqMemRef.pAllocator); -#endif return NULL; } -#if 0 - pTq->tqPushMgr = tqPushMgrOpen(); - if (pTq->tqPushMgr == NULL) { - // free store - taosMemoryFree(pTq); - return NULL; - } -#endif + pTq->tqMetaNew = taosHashInit(64, MurmurHash3_32, true, HASH_ENTRY_LOCK); pTq->pStreamTasks = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); @@ -248,16 +231,15 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu return 0; } -#if 0 + int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { - SMqPollReq* pReq = pMsg->pCont; - int64_t consumerId = pReq->consumerId; - int64_t fetchOffset; - int64_t blockingTime = pReq->blockingTime; - int32_t reqEpoch = pReq->epoch; + SMqPollReqV2* pReq = pMsg->pCont; + int64_t consumerId = pReq->consumerId; + int32_t reqEpoch = pReq->epoch; + int64_t fetchOffset; if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) { - fetchOffset = 0; + fetchOffset = walGetFirstVer(pTq->pWal); } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) { fetchOffset = walGetLastVer(pTq->pWal); } else { @@ -267,65 +249,29 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch, TD_VID(pTq->pVnode), pReq->currentOffset, fetchOffset); - SMqPollRsp rsp = { - /*.consumerId = consumerId,*/ - .numOfTopics = 0, - .pBlockData = NULL, - }; + STqExec* pExec = taosHashGet(pTq->tqMetaNew, pReq->subKey, strlen(pReq->subKey)); + ASSERT(pExec); - STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId); - if (pConsumer == NULL) { - vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode)); - pMsg->pCont = NULL; - pMsg->contLen = 0; - pMsg->code = -1; - tmsgSendRsp(pMsg); - return 0; - } - - int32_t consumerEpoch = atomic_load_32(&pConsumer->epoch); + int32_t consumerEpoch = atomic_load_32(&pExec->epoch); while (consumerEpoch < reqEpoch) { - consumerEpoch = atomic_val_compare_exchange_32(&pConsumer->epoch, consumerEpoch, reqEpoch); + consumerEpoch = atomic_val_compare_exchange_32(&pExec->epoch, consumerEpoch, reqEpoch); } - STqTopic* pTopic = NULL; - int32_t sz = taosArrayGetSize(pConsumer->topics); - for (int32_t i = 0; i < sz; i++) { - STqTopic* topic = taosArrayGet(pConsumer->topics, i); - // TODO race condition - ASSERT(pConsumer->consumerId == consumerId); - if (strcmp(topic->topicName, pReq->topic) == 0) { - pTopic = topic; - break; - } - } - if (pTopic == NULL) { - vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic, - TD_VID(pTq->pVnode)); - pMsg->pCont = NULL; - pMsg->contLen = 0; - pMsg->code = -1; - tmsgSendRsp(pMsg); - return 0; - } - - vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch, - TD_VID(pTq->pVnode)); - + SMqDataBlkRsp rsp = {0}; rsp.reqOffset = pReq->currentOffset; - rsp.skipLogNum = 0; + rsp.blockDataLen = taosArrayInit(0, sizeof(int32_t)); + rsp.blockData = taosArrayInit(0, sizeof(void*)); while (1) { - /*if (fetchOffset > walGetLastVer(pTq->pWal) || walReadWithHandle(pTopic->pReadhandle, fetchOffset) < 0) {*/ - // TODO - consumerEpoch = atomic_load_32(&pConsumer->epoch); + consumerEpoch = atomic_load_32(&pExec->epoch); if (consumerEpoch > reqEpoch) { vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode), fetchOffset, consumerEpoch, reqEpoch); break; } + SWalReadHead* pHead; - if (walReadWithHandle_s(pTopic->pReadhandle, fetchOffset, &pHead) < 0) { + if (walReadWithHandle_s(pExec->pReadHandle, fetchOffset, &pHead) < 0) { // TODO: no more log, set timer to wait blocking time // if data inserted during waiting, launch query and // response to user @@ -333,101 +279,88 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { TD_VID(pTq->pVnode), fetchOffset); break; } + vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode), fetchOffset, pHead->msgType); - /*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/ - /*pHead = pTopic->pReadhandle->pHead;*/ + if (pHead->msgType == TDMT_VND_SUBMIT) { SSubmitReq* pCont = (SSubmitReq*)&pHead->body; - qTaskInfo_t task = pTopic->buffer.output[workerId].task; + qTaskInfo_t task = pExec->task[workerId]; ASSERT(task); qSetStreamInput(task, pCont, STREAM_DATA_TYPE_SUBMIT_BLOCK); - SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); while (1) { SSDataBlock* pDataBlock = NULL; - uint64_t ts; + uint64_t ts = 0; if (qExecTask(task, &pDataBlock, &ts) < 0) { - ASSERT(false); - } - if (pDataBlock == NULL) { - /*pos = fetchOffset % TQ_BUFFER_SIZE;*/ - break; + ASSERT(0); } + if (pDataBlock == NULL) break; - taosArrayPush(pRes, pDataBlock); + ASSERT(pDataBlock->info.rows != 0); + ASSERT(pDataBlock->info.numOfCols != 0); + + int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(pDataBlock); + void* buf = taosMemoryCalloc(1, dataStrLen); + SRetrieveTableRsp* pRetrieve = (SRetrieveTableRsp*)buf; + pRetrieve->useconds = ts; + pRetrieve->precision = TSDB_DEFAULT_PRECISION; + pRetrieve->compressed = 0; + pRetrieve->completed = 1; + pRetrieve->numOfRows = htonl(pDataBlock->info.rows); + + // TODO enable compress + int32_t actualLen = 0; + blockCompressEncode(pDataBlock, pRetrieve->data, &actualLen, pDataBlock->info.numOfCols, false); + actualLen += sizeof(SRetrieveTableRsp); + ASSERT(actualLen <= dataStrLen); + taosArrayPush(rsp.blockDataLen, &actualLen); + taosArrayPush(rsp.blockData, &buf); + rsp.blockNum++; } - - if (taosArrayGetSize(pRes) == 0) { - vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId, - pReq->epoch, TD_VID(pTq->pVnode), fetchOffset); - fetchOffset++; - rsp.skipLogNum++; - taosArrayDestroy(pRes); - continue; - } - rsp.schema = pTopic->buffer.output[workerId].pReadHandle->pSchemaWrapper; - rsp.rspOffset = fetchOffset; - - rsp.numOfTopics = 1; - rsp.pBlockData = pRes; - - int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp); - void* buf = rpcMallocCont(tlen); - if (buf == NULL) { - pMsg->code = -1; - taosMemoryFree(pHead); - return -1; - } - ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; - ((SMqRspHead*)buf)->epoch = pReq->epoch; - ((SMqRspHead*)buf)->consumerId = consumerId; - - void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); - tEncodeSMqPollRsp(&abuf, &rsp); - /*taosArrayDestroyEx(rsp.pBlockData, (void (*)(void*))tDeleteSSDataBlock);*/ - pMsg->pCont = buf; - pMsg->contLen = tlen; - pMsg->code = 0; - vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", TD_VID(pTq->pVnode), fetchOffset, - pHead->msgType, consumerId, pReq->epoch); - tmsgSendRsp(pMsg); - taosMemoryFree(pHead); - return 0; - } else { - taosMemoryFree(pHead); - fetchOffset++; - rsp.skipLogNum++; } + + // TODO batch optimization + if (rsp.blockNum != 0) break; + rsp.skipLogNum++; + fetchOffset++; } - /*if (blockingTime != 0) {*/ - /*tqAddClientPusher(pTq->tqPushMgr, pMsg, consumerId, blockingTime);*/ - /*} else {*/ - int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqPollRsp(NULL, &rsp); + ASSERT(taosArrayGetSize(rsp.blockData) == rsp.blockNum); + ASSERT(taosArrayGetSize(rsp.blockDataLen) == rsp.blockNum); + + if (rsp.blockNum != 0) + rsp.rspOffset = fetchOffset; + else + rsp.rspOffset = fetchOffset - 1; + + int32_t tlen = sizeof(SMqRspHead) + tEncodeSMqDataBlkRsp(NULL, &rsp); void* buf = rpcMallocCont(tlen); if (buf == NULL) { pMsg->code = -1; return -1; } + ((SMqRspHead*)buf)->mqMsgType = TMQ_MSG_TYPE__POLL_RSP; ((SMqRspHead*)buf)->epoch = pReq->epoch; - rsp.rspOffset = fetchOffset - 1; + ((SMqRspHead*)buf)->consumerId = consumerId; void* abuf = POINTER_SHIFT(buf, sizeof(SMqRspHead)); - tEncodeSMqPollRsp(&abuf, &rsp); - rsp.pBlockData = NULL; + tEncodeSMqDataBlkRsp(&abuf, &rsp); pMsg->pCont = buf; pMsg->contLen = tlen; pMsg->code = 0; tmsgSendRsp(pMsg); - vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", TD_VID(pTq->pVnode), fetchOffset, consumerId, - pReq->epoch); - /*}*/ + vDebug("vg %d offset %ld from consumer %ld (epoch %d) send rsp, block num: %d, reqOffset: %ld, rspOffset: %ld", + TD_VID(pTq->pVnode), fetchOffset, consumerId, pReq->epoch, rsp.blockNum, rsp.reqOffset, rsp.rspOffset); + + // TODO destroy + taosArrayDestroy(rsp.blockData); + taosArrayDestroy(rsp.blockDataLen); return 0; } -#endif +#if 0 int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { SMqPollReq* pReq = pMsg->pCont; int64_t consumerId = pReq->consumerId; @@ -436,7 +369,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { int32_t reqEpoch = pReq->epoch; if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__EARLIEAST) { - fetchOffset = 0; + fetchOffset = walGetFirstVer(pTq->pWal); } else if (pReq->currentOffset == TMQ_CONF__RESET_OFFSET__LATEST) { fetchOffset = walGetLastVer(pTq->pWal); } else { @@ -635,124 +568,54 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) { return 0; } +#endif -int32_t tqProcessRebReq(STQ* pTq, char* msg) { - SMqMVRebReq req = {0}; - terrno = TSDB_CODE_SUCCESS; - tDecodeSMqMVRebReq(msg, &req); +// TODO: persist meta into tdb +int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { + SMqRebVgReq req; + tDecodeSMqRebVgReq(msg, &req); + // todo lock + STqExec* pExec = taosHashGet(pTq->tqMetaNew, req.subKey, strlen(req.subKey)); + if (pExec == NULL) { + ASSERT(req.oldConsumerId == -1); + ASSERT(req.newConsumerId != -1); + STqExec exec = {0}; + pExec = &exec; + /*taosInitRWLatch(&pExec->lock);*/ - vDebug("vg %d set from consumer %ld to consumer %ld", req.vgId, req.oldConsumerId, req.newConsumerId); - STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.oldConsumerId); - ASSERT(pConsumer); - ASSERT(pConsumer->consumerId == req.oldConsumerId); - int32_t numOfTopics = taosArrayGetSize(pConsumer->topics); - if (numOfTopics == 1) { - STqTopic* pTopic = taosArrayGet(pConsumer->topics, 0); - ASSERT(strcmp(pTopic->topicName, req.topic) == 0); - STqConsumer* pNewConsumer = tqHandleGet(pTq->tqMeta, req.newConsumerId); - if (pNewConsumer == NULL) { - pConsumer->consumerId = req.newConsumerId; - tqHandleMovePut(pTq->tqMeta, req.newConsumerId, pConsumer); - tqHandleCommit(pTq->tqMeta, req.newConsumerId); - tqHandlePurge(pTq->tqMeta, req.oldConsumerId); - return 0; - } else { - taosArrayPush(pNewConsumer->topics, pTopic); + memcpy(pExec->subKey, req.subKey, TSDB_SUBSCRIBE_KEY_LEN); + pExec->consumerId = req.newConsumerId; + pExec->epoch = -1; + pExec->qmsg = req.qmsg; + req.qmsg = NULL; + pExec->pReadHandle = walOpenReadHandle(pTq->pVnode->pWal); + for (int32_t i = 0; i < 4; i++) { + STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta); + SReadHandle handle = { + .reader = pReadHandle, + .meta = pTq->pVnodeMeta, + }; + pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle); + ASSERT(pExec->task[i]); } + taosHashPut(pTq->tqMetaNew, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec)); + return 0; } else { - for (int32_t i = 0; i < numOfTopics; i++) { - STqTopic* pTopic = taosArrayGet(pConsumer->topics, i); - if (strcmp(pTopic->topicName, req.topic) == 0) { - STqConsumer* pNewConsumer = tqHandleGet(pTq->tqMeta, req.newConsumerId); - if (pNewConsumer == NULL) { - pNewConsumer = taosMemoryCalloc(1, sizeof(STqConsumer)); - if (pNewConsumer == NULL) { - terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; - return -1; - } - strcpy(pNewConsumer->cgroup, pConsumer->cgroup); - pNewConsumer->topics = taosArrayInit(0, sizeof(STqTopic)); - pNewConsumer->consumerId = req.newConsumerId; - pNewConsumer->epoch = 0; - - taosArrayPush(pNewConsumer->topics, pTopic); - tqHandleMovePut(pTq->tqMeta, req.newConsumerId, pConsumer); - tqHandleCommit(pTq->tqMeta, req.newConsumerId); - return 0; - } - ASSERT(pNewConsumer->consumerId == req.newConsumerId); - taosArrayPush(pNewConsumer->topics, pTopic); - break; - } - } - // + /*if (req.newConsumerId != -1) {*/ + /*taosWLockLatch(&pExec->lock);*/ + ASSERT(pExec->consumerId == req.oldConsumerId); + // TODO handle qmsg and exec modification + atomic_store_32(&pExec->epoch, -1); + atomic_store_64(&pExec->consumerId, req.newConsumerId); + atomic_add_fetch_32(&pExec->epoch, 1); + /*taosWUnLockLatch(&pExec->lock);*/ + return 0; + /*} else {*/ + // TODO + /*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/ + /*return 0;*/ + /*}*/ } - return 0; -} - -int32_t tqProcessSetConnReq(STQ* pTq, char* msg) { - SMqSetCVgReq req = {0}; - tDecodeSMqSetCVgReq(msg, &req); - bool create = false; - - vDebug("vg %d set to consumer %ld", req.vgId, req.consumerId); - STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, req.consumerId); - if (pConsumer == NULL) { - pConsumer = taosMemoryCalloc(1, sizeof(STqConsumer)); - if (pConsumer == NULL) { - terrno = TSDB_CODE_TQ_OUT_OF_MEMORY; - return -1; - } - strcpy(pConsumer->cgroup, req.cgroup); - pConsumer->topics = taosArrayInit(0, sizeof(STqTopic)); - pConsumer->consumerId = req.consumerId; - pConsumer->epoch = 0; - create = true; - } - - STqTopic* pTopic = taosMemoryCalloc(1, sizeof(STqTopic)); - if (pTopic == NULL) { - taosArrayDestroy(pConsumer->topics); - taosMemoryFree(pConsumer); - return -1; - } - strcpy(pTopic->topicName, req.topicName); - pTopic->sql = req.sql; - pTopic->physicalPlan = req.physicalPlan; - pTopic->qmsg = req.qmsg; - /*pTopic->committedOffset = -1;*/ - /*pTopic->currentOffset = -1;*/ - - pTopic->buffer.firstOffset = -1; - pTopic->buffer.lastOffset = -1; - pTopic->pReadhandle = walOpenReadHandle(pTq->pWal); - if (pTopic->pReadhandle == NULL) { - ASSERT(false); - } - for (int i = 0; i < TQ_BUFFER_SIZE; i++) { - pTopic->buffer.output[i].status = 0; - STqReadHandle* pReadHandle = tqInitSubmitMsgScanner(pTq->pVnodeMeta); - SReadHandle handle = { - .reader = pReadHandle, - .meta = pTq->pVnodeMeta, - }; - pTopic->buffer.output[i].pReadHandle = pReadHandle; - pTopic->buffer.output[i].task = qCreateStreamExecTaskInfo(req.qmsg, &handle); - ASSERT(pTopic->buffer.output[i].task); - } - vDebug("set topic %s to consumer %ld on vg %d", pTopic->topicName, req.consumerId, TD_VID(pTq->pVnode)); - taosArrayPush(pConsumer->topics, pTopic); - if (create) { - tqHandleMovePut(pTq->tqMeta, req.consumerId, pConsumer); - tqHandleCommit(pTq->tqMeta, req.consumerId); - } - terrno = TSDB_CODE_SUCCESS; - return 0; -} - -int32_t tqProcessCancelConnReq(STQ* pTq, char* msg) { - terrno = TSDB_CODE_SUCCESS; - return 0; } int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) { diff --git a/source/dnode/vnode/src/tq/tqMetaStore.c b/source/dnode/vnode/src/tq/tqMetaStore.c index 357917e0ba..809fd7cb06 100644 --- a/source/dnode/vnode/src/tq/tqMetaStore.c +++ b/source/dnode/vnode/src/tq/tqMetaStore.c @@ -13,7 +13,6 @@ * along with this program. If not, see . */ #include "vnodeInt.h" -// TODO:replace by an abstract file layer // #include // #include // #include diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index cf62ea8714..02ce6c4aad 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -82,16 +82,7 @@ bool tqNextDataBlock(STqReadHandle* pHandle) { return false; } -int tqRetrieveDataBlockInfo(STqReadHandle* pHandle, SDataBlockInfo* pBlockInfo) { - // currently only rows are used - - pBlockInfo->numOfCols = taosArrayGetSize(pHandle->pColIdList); - pBlockInfo->rows = pHandle->pBlock->numOfRows; - // pBlockInfo->uid = pHandle->pBlock->uid; // the uid can not be assigned to pBlockData. - return 0; -} - -SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { +int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* pGroupId, int32_t* pNumOfRows) { /*int32_t sversion = pHandle->pBlock->sversion;*/ // TODO set to real sversion int32_t sversion = 0; @@ -112,7 +103,7 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { STSchema* pTschema = pHandle->pSchema; SSchemaWrapper* pSchemaWrapper = pHandle->pSchemaWrapper; - int32_t numOfRows = pHandle->pBlock->numOfRows; + *pNumOfRows = pHandle->pBlock->numOfRows; /*int32_t numOfCols = pHandle->pSchema->numOfCols;*/ int32_t colNumNeed = taosArrayGetSize(pHandle->pColIdList); @@ -120,10 +111,11 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colNumNeed = pSchemaWrapper->nCols; } - SArray* pArray = taosArrayInit(colNumNeed, sizeof(SColumnInfoData)); - if (pArray == NULL) { - return NULL; + *ppCols = taosArrayInit(colNumNeed, sizeof(SColumnInfoData)); + if (*ppCols == NULL) { + return -1; } + int32_t colMeta = 0; int32_t colNeed = 0; while (colMeta < pSchemaWrapper->nCols && colNeed < colNumNeed) { @@ -136,21 +128,24 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { colNeed++; } else { SColumnInfoData colInfo = {0}; - /*int sz = numOfRows * pColSchema->bytes;*/ colInfo.info.bytes = pColSchema->bytes; colInfo.info.colId = pColSchema->colId; colInfo.info.type = pColSchema->type; - if (colInfoDataEnsureCapacity(&colInfo, 0, numOfRows) < 0) { - taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); - return NULL; + if (colInfoDataEnsureCapacity(&colInfo, 0, *pNumOfRows) < 0) { + goto FAIL; } - taosArrayPush(pArray, &colInfo); + taosArrayPush(*ppCols, &colInfo); colMeta++; colNeed++; } } + int32_t colActual = taosArrayGetSize(*ppCols); + + // TODO in stream shuffle case, fetch groupId + *pGroupId = 0; + STSRowIter iter = {0}; tdSTSRowIterInit(&iter, pTschema); STSRow* row; @@ -159,22 +154,22 @@ SArray* tqRetrieveDataBlock(STqReadHandle* pHandle) { while ((row = tGetSubmitBlkNext(&pHandle->blkIter)) != NULL) { tdSTSRowIterReset(&iter, row); // get all wanted col of that block - int32_t colTot = taosArrayGetSize(pArray); - for (int32_t i = 0; i < colTot; i++) { - SColumnInfoData* pColData = taosArrayGet(pArray, i); + for (int32_t i = 0; i < colActual; i++) { + SColumnInfoData* pColData = taosArrayGet(*ppCols, i); SCellVal sVal = {0}; if (!tdSTSRowIterNext(&iter, pColData->info.colId, pColData->info.type, &sVal)) { break; } - /*if (colDataAppend(pColData, curRow, sVal.val, false) < 0) {*/ if (colDataAppend(pColData, curRow, sVal.val, sVal.valType == TD_VTYPE_NULL) < 0) { - taosArrayDestroyEx(pArray, (void (*)(void*))tDeleteSSDataBlock); - return NULL; + goto FAIL; } } curRow++; } - return pArray; + return 0; +FAIL: + taosArrayDestroy(*ppCols); + return -1; } void tqReadHandleSetColIdList(STqReadHandle* pReadHandle, SArray* pColIdList) { pReadHandle->pColIdList = pColIdList; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 09616a8969..28ba50c3df 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -1350,7 +1350,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF if (tBitmaps > 0) { bptr = POINTER_SHIFT(pBlockData, lsize + flen); if (isSuper && !tdDataColsIsBitmapI(pDataCols)) { - tdMergeBitmap((uint8_t *)pDataCol->pBitmap, nBitmaps, (uint8_t *)pDataCol->pBitmap); + tdMergeBitmap((uint8_t *)pDataCol->pBitmap, rowsToWrite, (uint8_t *)pDataCol->pBitmap); } tBitmapsLen = tsCompressTinyint((char *)pDataCol->pBitmap, tBitmaps, tBitmaps, bptr, tBitmaps + COMP_OVERFLOW_BYTES, diff --git a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c index b15271a51a..0cf8a0d359 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadImpl.c +++ b/source/dnode/vnode/src/tsdb/tsdbReadImpl.c @@ -305,7 +305,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, SDataCol *pDataCol = pReadh->pDCols[0]->cols + i; if (pDataCol->bitmap) { ASSERT(pDataCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID); - tdMergeBitmap(pDataCol->pBitmap, TD_BITMAP_BYTES(pReadh->pDCols[0]->numOfRows), pDataCol->pBitmap); + tdMergeBitmap(pDataCol->pBitmap, pReadh->pDCols[0]->numOfRows, pDataCol->pBitmap); tdDataColsSetBitmapI(pReadh->pDCols[0]); } } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 2a8d78b827..fb75ffe6b6 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -80,6 +80,13 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg pRsp->msgType = TDMT_VND_SUBMIT_RSP; vnodeProcessSubmitReq(pVnode, ptr, pRsp); break; + case TDMT_VND_MQ_VG_CHANGE: + if (tqProcessVgChangeReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), + pMsg->contLen - sizeof(SMsgHead)) < 0) { + // TODO: handle error + } + break; +#if 0 case TDMT_VND_MQ_SET_CONN: { if (tqProcessSetConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { // TODO: handle error @@ -93,6 +100,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg if (tqProcessCancelConnReq(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) { } } break; +#endif case TDMT_VND_TASK_DEPLOY: { if (tqProcessTaskDeploy(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), pMsg->contLen - sizeof(SMsgHead)) < 0) { @@ -309,4 +317,4 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pSubmitReq, SRpcMsg pRsp->contLen = sizeof(SSubmitRsp); return 0; -} \ No newline at end of file +} diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f0d3d95b6a..b054bbfcb6 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -30,12 +30,11 @@ #include "query.h" #include "tcompare.h" #include "thash.h" -#include "vnode.h" #include "ttypes.h" +#include "vnode.h" #define SET_REVERSE_SCAN_FLAG(_info) ((_info)->scanFlag = REVERSE_SCAN) -#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) - +#define SWITCH_ORDER(n) (((n) = ((n) == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC)) void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { for (int32_t i = 0; i < numOfOutput; ++i) { @@ -90,7 +89,7 @@ static void getNextTimeWindow(SInterval* pInterval, STimeWindow* tw, int32_t ord } int64_t key = tw->skey, interval = pInterval->interval; - //convert key to second + // convert key to second key = convertTimePrecision(key, pInterval->precision, TSDB_TIME_PRECISION_MILLI) / 1000; if (pInterval->intervalUnit == 'y') { @@ -98,7 +97,7 @@ static void getNextTimeWindow(SInterval* pInterval, STimeWindow* tw, int32_t ord } struct tm tm; - time_t t = (time_t)key; + time_t t = (time_t)key; taosLocalTime(&t, &tm); int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor); @@ -125,8 +124,8 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn // todo handle the time range case TSKEY sk = INT64_MIN; TSKEY ek = INT64_MAX; -// TSKEY sk = MIN(pQueryAttr->window.skey, pQueryAttr->window.ekey); -// TSKEY ek = MAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); + // TSKEY sk = MIN(pQueryAttr->window.skey, pQueryAttr->window.ekey); + // TSKEY ek = MAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); if (true) { getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey, &w); @@ -136,7 +135,7 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn return true; } - while(1) { // todo handle the desc order scan case + while (1) { // todo handle the desc order scan case getNextTimeWindow(pInterval, &w, TSDB_ORDER_ASC); if (w.skey > pBlockInfo->window.ekey) { break; @@ -148,31 +147,31 @@ static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockIn } } } else { -// getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w); -// assert(w.skey <= pBlockInfo->window.ekey); -// -// if (w.skey > pBlockInfo->window.skey) { -// return true; -// } -// -// while(1) { -// getNextTimeWindow(pQueryAttr, &w); -// if (w.ekey < pBlockInfo->window.skey) { -// break; -// } -// -// assert(w.skey < pBlockInfo->window.skey); -// if (w.ekey < pBlockInfo->window.ekey && w.ekey >= pBlockInfo->window.skey) { -// return true; -// } -// } + // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w); + // assert(w.skey <= pBlockInfo->window.ekey); + // + // if (w.skey > pBlockInfo->window.skey) { + // return true; + // } + // + // while(1) { + // getNextTimeWindow(pQueryAttr, &w); + // if (w.ekey < pBlockInfo->window.skey) { + // break; + // } + // + // assert(w.skey < pBlockInfo->window.skey); + // if (w.ekey < pBlockInfo->window.ekey && w.ekey >= pBlockInfo->window.skey) { + // return true; + // } + // } } return false; } int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableScanInfo* pInfo = pOperator->info; STaskCostInfo* pCost = &pTaskInfo->cost; @@ -189,13 +188,13 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, taosMemoryFreeClear(pBlock->pBlockAgg); if (*status == FUNC_DATA_REQUIRED_FILTEROUT) { - qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, - pBlockInfo->window.ekey, pBlockInfo->rows); + qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), + pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); pCost->filterOutBlocks += 1; return TSDB_CODE_SUCCESS; } else if (*status == FUNC_DATA_REQUIRED_NOT_LOAD) { - qDebug("%s data block skipped, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, - pBlockInfo->window.ekey, pBlockInfo->rows); + qDebug("%s data block skipped, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), + pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); pCost->skipBlocks += 1; return TSDB_CODE_SUCCESS; } else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) { @@ -218,12 +217,12 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, } return TSDB_CODE_SUCCESS; - } else { // failed to load the block sma data, data block statistics does not exist, load data block instead + } else { // failed to load the block sma data, data block statistics does not exist, load data block instead *status = FUNC_DATA_REQUIRED_DATA_LOAD; } } - ASSERT (*status == FUNC_DATA_REQUIRED_DATA_LOAD); + ASSERT(*status == FUNC_DATA_REQUIRED_DATA_LOAD); // todo filter data block according to the block sma data firstly #if 0 @@ -249,8 +248,8 @@ int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, doFilter(pTableScanInfo->pFilterNode, pBlock); if (pBlock->info.rows == 0) { pCost->filterOutBlocks += 1; - qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, - pBlockInfo->window.ekey, pBlockInfo->rows); + qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), + pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); } return TSDB_CODE_SUCCESS; @@ -348,9 +347,9 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; -// if (pResultRowInfo->size > 0) { -// pResultRowInfo->curPos = 0; -// } + // if (pResultRowInfo->size > 0) { + // pResultRowInfo->curPos = 0; + // } 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); @@ -367,7 +366,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey); if (pResultRowInfo->size > 0) { -// pResultRowInfo->curPos = pResultRowInfo->size - 1; + // pResultRowInfo->curPos = pResultRowInfo->size - 1; } p = doTableScanImpl(pOperator, newgroup); @@ -376,9 +375,10 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) { return p; } -SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, 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) { +SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, 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); STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); @@ -391,26 +391,26 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, return NULL; } - pInfo->interval = *pInterval; - pInfo->sampleRatio = sampleRatio; - pInfo->dataBlockLoadFlag= dataLoadFlag; - pInfo->pResBlock = pResBlock; - pInfo->pFilterNode = pCondition; - pInfo->dataReader = pTsdbReadHandle; - pInfo->times = repeatTime; - pInfo->reverseTimes = reverseTime; - pInfo->order = order; - pInfo->current = 0; - pInfo->scanFlag = MAIN_SCAN; - pInfo->pColMatchInfo = pColMatchInfo; - pOperator->name = "TableScanOperator"; + pInfo->interval = *pInterval; + pInfo->sampleRatio = sampleRatio; + pInfo->dataBlockLoadFlag = dataLoadFlag; + pInfo->pResBlock = pResBlock; + pInfo->pFilterNode = pCondition; + pInfo->dataReader = pTsdbReadHandle; + 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; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = numOfOutput; - pOperator->getNextFn = doTableScan; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = numOfOutput; + pOperator->getNextFn = doTableScan; + pOperator->pTaskInfo = pTaskInfo; static int32_t cost = 0; pOperator->cost.openCost = ++cost; @@ -456,67 +456,67 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) { ++numRowSteps; } - tableBlockDist.dataBlockInfos = taosArrayInit(numRowSteps, sizeof(SFileBlockInfo)); + tableBlockDist.dataBlockInfos = taosArrayInit(numRowSteps, sizeof(SFileBlockInfo)); taosArraySetSize(tableBlockDist.dataBlockInfos, numRowSteps); tableBlockDist.maxRows = INT_MIN; tableBlockDist.minRows = INT_MAX; tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist); - tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); + tableBlockDist.numOfRowsInMemTable = (int32_t)tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader); SSDataBlock* pBlock = pTableScanInfo->pResBlock; - pBlock->info.rows = 1; + pBlock->info.rows = 1; pBlock->info.numOfCols = 1; -// SBufferWriter bw = tbufInitWriter(NULL, false); -// blockDistInfoToBinary(&tableBlockDist, &bw); + // SBufferWriter bw = tbufInitWriter(NULL, false); + // blockDistInfoToBinary(&tableBlockDist, &bw); SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0); -// int32_t len = (int32_t) tbufTell(&bw); -// pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t)); -// *(int32_t*) pColInfo->pData = len; -// memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len); -// -// tbufCloseWriter(&bw); + // int32_t len = (int32_t) tbufTell(&bw); + // pColInfo->pData = taosMemoryMalloc(len + sizeof(int32_t)); + // *(int32_t*) pColInfo->pData = len; + // memcpy(pColInfo->pData + sizeof(int32_t), tbufGetData(&bw, false), len); + // + // tbufCloseWriter(&bw); -// SArray* g = GET_TABLEGROUP(pOperator->, 0); -// pOperator->pRuntimeEnv->current = taosArrayGetP(g, 0); + // SArray* g = GET_TABLEGROUP(pOperator->, 0); + // pOperator->pRuntimeEnv->current = taosArrayGetP(g, 0); pOperator->status = OP_EXEC_DONE; return pBlock; } SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo) { - STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; goto _error; } - pInfo->dataReader = dataReader; -// pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); + pInfo->dataReader = dataReader; + // pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData)); SColumnInfoData infoData = {0}; - infoData.info.type = TSDB_DATA_TYPE_BINARY; + infoData.info.type = TSDB_DATA_TYPE_BINARY; infoData.info.bytes = 1024; infoData.info.colId = 0; -// taosArrayPush(pInfo->block.pDataBlock, &infoData); + // taosArrayPush(pInfo->block.pDataBlock, &infoData); - pOperator->name = "DataBlockInfoScanOperator"; + pOperator->name = "DataBlockInfoScanOperator"; // pOperator->operatorType = OP_TableBlockInfoScan; - pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doBlockInfoScan; + pOperator->blockingOptr = false; + pOperator->status = OP_NOT_OPENED; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doBlockInfoScan; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; return pOperator; - _error: +_error: taosMemoryFreeClear(pInfo); taosMemoryFreeClear(pOperator); return NULL; @@ -558,29 +558,42 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) blockDataCleanup(pInfo->pRes); while (tqNextDataBlock(pInfo->readerHandle)) { - pTaskInfo->code = tqRetrieveDataBlockInfo(pInfo->readerHandle, pBlockInfo); - if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - terrno = pTaskInfo->code; - pOperator->status = OP_EXEC_DONE; + SArray* pCols = NULL; + uint64_t groupId; + int32_t numOfRows; + int32_t code = tqRetrieveDataBlock(&pCols, pInfo->readerHandle, &groupId, &numOfRows); + + if (code != TSDB_CODE_SUCCESS || numOfRows == 0) { + pTaskInfo->code = code; return NULL; } - if (pBlockInfo->rows == 0) { - break; - } - - SArray* pCols = tqRetrieveDataBlock(pInfo->readerHandle); + pInfo->pRes->info.groupId = groupId; + pInfo->pRes->info.rows = numOfRows; int32_t numOfCols = pInfo->pRes->info.numOfCols; for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData* p = taosArrayGet(pCols, i); - SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); + SColMatchInfo* pColMatchInfo = taosArrayGet(pInfo->pColMatchInfo, i); if (!pColMatchInfo->output) { continue; } - ASSERT(pColMatchInfo->colId == p->info.colId); - taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, p); + bool colExists = false; + for (int32_t j = 0; j < taosArrayGetSize(pCols); ++j) { + SColumnInfoData* pResCol = taosArrayGet(pCols, j); + if (pResCol->info.colId == pColMatchInfo->colId) { + taosArraySet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId, pResCol); + colExists = true; + break; + } + } + + // the required column does not exists in submit block, let's set it to be all null value + if (!colExists) { + SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, pColMatchInfo->targetSlotId); + colInfoDataEnsureCapacity(pDst, 0, pBlockInfo->rows); + colDataAppendNNULL(pDst, 0, pBlockInfo->rows); + } } if (pInfo->pRes->pDataBlock == NULL) { @@ -605,7 +618,8 @@ static SSDataBlock* doStreamBlockScan(SOperatorInfo* pOperator, bool* newgroup) } } -SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, + SArray* pTableIdList, SExecTaskInfo* pTaskInfo) { SStreamBlockScanInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamBlockScanInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -618,7 +632,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* int32_t numOfOutput = taosArrayGetSize(pColList); SArray* pColIds = taosArrayInit(4, sizeof(int16_t)); - for(int32_t i = 0; i < numOfOutput; ++i) { + for (int32_t i = 0; i < numOfOutput; ++i) { int16_t* id = taosArrayGet(pColList, i); taosArrayPush(pColIds, id); } @@ -644,16 +658,16 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pInfo->readerHandle = streamReadHandle; pInfo->pRes = pResBlock; - pOperator->name = "StreamBlockScanOperator"; + pOperator->name = "StreamBlockScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->_openFn = operatorDummyOpenFn; - pOperator->getNextFn = doStreamBlockScan; - pOperator->closeFn = operatorDummyCloseFn; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->_openFn = operatorDummyOpenFn; + pOperator->getNextFn = doStreamBlockScan; + pOperator->closeFn = operatorDummyCloseFn; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } @@ -733,9 +747,9 @@ static int32_t loadSysTableContentCb(void* param, const SDataBuf* pMsg, int32_t SRetrieveMetaTableRsp* pRsp = pScanResInfo->pRsp; pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->handle = htobe64(pRsp->handle); - pRsp->compLen = htonl(pRsp->compLen); + pRsp->useconds = htobe64(pRsp->useconds); + pRsp->handle = htobe64(pRsp->handle); + pRsp->compLen = htonl(pRsp->compLen); } else { operator->pTaskInfo->code = code; } @@ -777,7 +791,7 @@ static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { if (rowRes[j] == 0) { continue; } - + colDataAppend(pDest, numOfRow, colDataGetData(pSrc, j), false); numOfRow += 1; } @@ -828,7 +842,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator, bool* newgroup) { SColumnInfoData* pColInfoData = taosArrayGet(pInfo->pRes->pDataBlock, i); int64_t tmp = 0; char t[10] = {0}; - STR_TO_VARSTR(t, "_"); //TODO + STR_TO_VARSTR(t, "_"); // TODO if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { colDataAppend(pColInfoData, numOfRows, t, false); } else { @@ -926,12 +940,12 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB return NULL; } - pInfo->accountId = accountId; + pInfo->accountId = accountId; pInfo->showRewrite = showRewrite; - pInfo->pRes = pResBlock; - pInfo->capacity = 4096; - pInfo->pCondition = pCondition; - pInfo->scanCols = colList; + pInfo->pRes = pResBlock; + pInfo->capacity = 4096; + pInfo->pCondition = pCondition; + pInfo->scanCols = colList; // TODO remove it int32_t tableType = 0; @@ -986,9 +1000,9 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB tableType = TSDB_MGMT_TABLE_CONNS; } else if (strncasecmp(name, TSDB_INS_TABLE_QUERIES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_QUERIES; - } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, tListLen(pName->tname)) == 0) { + } else if (strncasecmp(name, TSDB_INS_TABLE_VNODES, tListLen(pName->tname)) == 0) { tableType = TSDB_MGMT_TABLE_VNODES; - }else { + } else { ASSERT(0); } @@ -1025,15 +1039,15 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB #endif } - pOperator->name = "SysTableScanOperator"; + pOperator->name = "SysTableScanOperator"; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; pOperator->blockingOptr = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->numOfOutput = pResBlock->info.numOfCols; - pOperator->getNextFn = doSysTableScan; - pOperator->closeFn = destroySysScanOperator; - pOperator->pTaskInfo = pTaskInfo; + pOperator->status = OP_NOT_OPENED; + pOperator->info = pInfo; + pOperator->numOfOutput = pResBlock->info.numOfCols; + pOperator->getNextFn = doSysTableScan; + pOperator->closeFn = destroySysScanOperator; + pOperator->pTaskInfo = pTaskInfo; return pOperator; } diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 19a0897e20..eddc094285 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -14,7 +14,7 @@ target_include_directories( target_link_libraries( function - PRIVATE os util common nodes scalar + PRIVATE os util common nodes scalar catalog qcom transport PUBLIC uv_a ) diff --git a/source/libs/function/inc/builtins.h b/source/libs/function/inc/builtins.h index fb36c9d978..54a68715a8 100644 --- a/source/libs/function/inc/builtins.h +++ b/source/libs/function/inc/builtins.h @@ -20,26 +20,7 @@ extern "C" { #endif -#include "functionMgt.h" - -#define FUNCTION_NAME_MAX_LENGTH 32 - -#define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n) - -#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) -#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) -#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) -#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) -#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) -#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) -#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) -#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) -#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) -#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9) -#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10) -#define FUNC_MGT_MULTI_RES_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(11) - -#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) +#include "functionMgtInt.h" typedef int32_t (*FTranslateFunc)(SFunctionNode* pFunc, char* pErrBuf, int32_t len); typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow); diff --git a/source/libs/function/inc/fnLog.h b/source/libs/function/inc/fnLog.h new file mode 100644 index 0000000000..f572948907 --- /dev/null +++ b/source/libs/function/inc/fnLog.h @@ -0,0 +1,24 @@ +// +// Created by slzhou on 22-4-20. +// + +#ifndef TDENGINE_FNLOG_H +#define TDENGINE_FNLOG_H +#include "tlog.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define fnFatal(...) { if (fnDebugFlag & DEBUG_FATAL) { taosPrintLog("FN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define fnError(...) { if (fnDebugFlag & DEBUG_ERROR) { taosPrintLog("FN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define fnWarn(...) { if (fnDebugFlag & DEBUG_WARN) { taosPrintLog("FN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define fnInfo(...) { if (fnDebugFlag & DEBUG_INFO) { taosPrintLog("FN ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define fnDebug(...) { if (fnDebugFlag & DEBUG_DEBUG) { taosPrintLog("FN ", DEBUG_DEBUG, dDebugFlag, __VA_ARGS__); }} +#define fnTrace(...) { if (fnDebugFlag & DEBUG_TRACE) { taosPrintLog("FN ", DEBUG_TRACE, dDebugFlag, __VA_ARGS__); }} + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_FNLOG_H diff --git a/source/libs/function/inc/functionMgtInt.h b/source/libs/function/inc/functionMgtInt.h index 4baf338e9b..39287f08ee 100644 --- a/source/libs/function/inc/functionMgtInt.h +++ b/source/libs/function/inc/functionMgtInt.h @@ -21,9 +21,29 @@ extern "C" { #endif #include "functionMgt.h" -// #include "builtins.h" +#define FUNCTION_NAME_MAX_LENGTH 32 +#define FUNC_MGT_FUNC_CLASSIFICATION_MASK(n) (1 << n) + +#define FUNC_MGT_AGG_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(0) +#define FUNC_MGT_SCALAR_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(1) +#define FUNC_MGT_NONSTANDARD_SQL_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(2) +#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3) +#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4) +#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5) +#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6) +#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7) +#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8) +#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9) +#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10) +#define FUNC_MGT_MULTI_RES_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(11) + +#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0) + +#define FUNC_UDF_ID_START_OFFSET_VAL 5000 + +extern const int funcMgtUdfNum; #ifdef __cplusplus } diff --git a/source/libs/function/inc/tudf.h b/source/libs/function/inc/tudf.h index 8ec02c777f..c51b6e1264 100644 --- a/source/libs/function/inc/tudf.h +++ b/source/libs/function/inc/tudf.h @@ -26,6 +26,9 @@ extern "C" { #endif +#define UDF_LISTEN_PIPE_NAME_LEN 32 +#define UDF_LISTEN_PIPE_NAME_PREFIX "udf.sock." + //====================================================================================== //begin API to taosd and qworker @@ -35,17 +38,28 @@ enum { UDFC_CODE_PIPE_READ_ERR = -3, }; +/*TODO: no api for dnode startudfd/stopudfd*/ /** - * start udf dameon service - * @return error code + * start udfd dameon service */ -int32_t startUdfService(); +int32_t startUdfd(int32_t dnodeId); /** - * stop udf dameon service + * stop udfd dameon service + */ +int32_t stopUdfd(int32_t dnodeId); + +/** + * create udfd proxy, called once in process that call setupUdf/callUdfxxx/teardownUdf * @return error code */ -int32_t stopUdfService(); +int32_t createUdfdProxy(int32_t dnodeId); + +/** + * destroy udfd proxy + * @return error code + */ +int32_t destroyUdfdProxy(int32_t dnodeId); typedef void *UdfHandle; @@ -101,7 +115,6 @@ typedef struct SUdfInterBuf { char* buf; } SUdfInterBuf; -//TODO: translate these calls to callUdf // output: interBuf int32_t callUdfAggInit(UdfHandle handle, SUdfInterBuf *interBuf); // input: block, state diff --git a/source/libs/function/inc/udfc.h b/source/libs/function/inc/udfc.h index 4d2aeb7049..fed2818ced 100644 --- a/source/libs/function/inc/udfc.h +++ b/source/libs/function/inc/udfc.h @@ -32,9 +32,9 @@ typedef struct SUdfInfo { typedef void *UdfHandle; -int32_t startUdfService(); +int32_t createUdfdProxy(); -int32_t stopUdfService(); +int32_t destroyUdfdProxy(); //int32_t setupUdf(SUdfInfo *udf, int32_t numOfUdfs, UdfHandle *handles); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index c2629b9bf4..ce7384cbbe 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -32,7 +32,7 @@ static int32_t invaildFuncParaNumErrMsg(char* pErrBuf, int32_t len, const char* } static int32_t invaildFuncParaTypeErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { - return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_TYPE, "Invalid datatypes : %s", pFuncName); + return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_TYPE, "Invalid parameter data type : %s", pFuncName); } static int32_t invaildFuncParaValueErrMsg(char* pErrBuf, int32_t len, const char* pFuncName) { @@ -327,6 +327,10 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { para2Type != TSDB_DATA_TYPE_TIMESTAMP) { return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); } + if ((para2Type == TSDB_DATA_TYPE_TIMESTAMP && IS_VAR_DATA_TYPE(para1Type)) || + (para2Type == TSDB_DATA_TYPE_BINARY && para1Type == TSDB_DATA_TYPE_NCHAR)) { + return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName); + } int32_t para2Bytes = pFunc->node.resType.bytes; if (para2Bytes <= 0) { //non-positive value or overflow return invaildFuncParaValueErrMsg(pErrBuf, len, pFunc->functionName); @@ -935,7 +939,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .translateFunc = translateToJson, .getEnvFunc = NULL, .initFunc = NULL, - .sprocessFunc = NULL, + .sprocessFunc = toJsonFunction, .finalizeFunc = NULL } }; diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index 9500064949..130b81a609 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -20,16 +20,22 @@ #include "taoserror.h" #include "thash.h" #include "builtins.h" +#include "catalog.h" typedef struct SFuncMgtService { SHashObj* pFuncNameHashTable; + SArray* pUdfTable; // SUdfInfo } SFuncMgtService; +typedef struct SUdfInfo { + SDataType outputDt; +} SUdfInfo; + static SFuncMgtService gFunMgtService; static TdThreadOnce functionHashTableInit = PTHREAD_ONCE_INIT; static int32_t initFunctionCode = 0; -static void doInitFunctionHashTable() { +static void doInitFunctionTable() { gFunMgtService.pFuncNameHashTable = taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == gFunMgtService.pFuncNameHashTable) { initFunctionCode = TSDB_CODE_FAILED; @@ -42,6 +48,8 @@ static void doInitFunctionHashTable() { return; } } + + gFunMgtService.pUdfTable = NULL; } static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { @@ -51,25 +59,56 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) { return FUNC_MGT_TEST_MASK(funcMgtBuiltins[funcId].classification, classification); } +static int32_t getUdfId(const char* pFuncName) { + // todo: udf by call catalog + if (1) { + return -1; + } + if (NULL == gFunMgtService.pUdfTable) { + gFunMgtService.pUdfTable = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SUdfInfo)); + } + SUdfInfo info = {0}; //todo + taosArrayPush(gFunMgtService.pUdfTable, &info); + return taosArrayGetSize(gFunMgtService.pUdfTable) + FUNC_UDF_ID_START_OFFSET_VAL; +} + +static int32_t getFuncId(const char* pFuncName) { + void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName)); + if (NULL == pVal) { + return getUdfId(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; +} + int32_t fmFuncMgtInit() { - taosThreadOnce(&functionHashTableInit, doInitFunctionHashTable); + taosThreadOnce(&functionHashTableInit, doInitFunctionTable); return initFunctionCode; } int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) { - void* pVal = taosHashGet(gFunMgtService.pFuncNameHashTable, pFuncName, strlen(pFuncName)); - if (NULL == pVal) { + *pFuncId = getFuncId(pFuncName); + if (*pFuncId < 0) { return TSDB_CODE_FAILED; } - *pFuncId = *(int32_t*)pVal; - if (*pFuncId < 0 || *pFuncId >= funcMgtBuiltinsNum) { - return TSDB_CODE_FAILED; + if (fmIsUserDefinedFunc(*pFuncId)) { + *pFuncType = FUNCTION_TYPE_UDF; + } else { + *pFuncType = funcMgtBuiltins[*pFuncId].type; } - *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; } @@ -77,7 +116,7 @@ int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { } EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { - if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { + if (fmIsUserDefinedFunc(pFunc->funcId) || pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) { return FUNC_DATA_REQUIRED_DATA_LOAD; } if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) { @@ -87,7 +126,7 @@ EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin } int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { - if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; } pFpSet->getEnv = funcMgtBuiltins[funcId].getEnvFunc; @@ -98,7 +137,7 @@ int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) { } int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet) { - if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) { return TSDB_CODE_FAILED; } pFpSet->process = funcMgtBuiltins[funcId].sprocessFunc; @@ -142,6 +181,10 @@ bool fmIsMultiResFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC); } +bool fmIsUserDefinedFunc(int32_t funcId) { + return funcId > FUNC_UDF_ID_START_OFFSET_VAL; +} + void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index c41447b584..ad74daddc6 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -200,10 +200,10 @@ int64_t gUdfTaskSeqNum = 0; enum { UDFC_STATE_INITAL = 0, // initial state - UDFC_STATE_STARTNG, // starting after startUdfService + UDFC_STATE_STARTNG, // starting after createUdfdProxy UDFC_STATE_READY, // started and begin to receive quests UDFC_STATE_RESTARTING, // udfd abnormal exit. cleaning up and restart. - UDFC_STATE_STOPPING, // stopping after stopUdfService + UDFC_STATE_STOPPING, // stopping after destroyUdfdProxy UDFC_STATUS_FINAL, // stopped }; int8_t gUdfcState = UDFC_STATE_INITAL; @@ -929,7 +929,7 @@ void udfStopAsyncCb(uv_async_t *async) { } } -int32_t startUdfd(); +int32_t udfcSpawnUdfd(); void onUdfdExit(uv_process_t *req, int64_t exit_status, int term_signal) { //TODO: pipe close will be first received @@ -944,12 +944,12 @@ void onUdfdExit(uv_process_t *req, int64_t exit_status, int term_signal) { if (gUdfcState == UDFC_STATE_READY) { gUdfcState = UDFC_STATE_RESTARTING; //TODO: asynchronous without blocking. how to do it - cleanUpUvTasks(); - startUdfd(); + //cleanUpUvTasks(); + udfcSpawnUdfd(); } } -int32_t startUdfd() { +int32_t udfcSpawnUdfd() { //TODO: path uv_process_options_t options = {0}; static char path[256] = {0}; @@ -979,9 +979,6 @@ int32_t startUdfd() { void constructUdfService(void *argsThread) { uv_loop_init(&gUdfdLoop); - //TODO spawn error - startUdfd(); - uv_async_init(&gUdfdLoop, &gUdfLoopTaskAync, udfClientAsyncCb); uv_async_init(&gUdfdLoop, &gUdfLoopStopAsync, udfStopAsyncCb); uv_mutex_init(&gUdfTaskQueueMutex); @@ -994,7 +991,7 @@ void constructUdfService(void *argsThread) { } -int32_t startUdfService() { +int32_t createUdfdProxy(int32_t dnodeId) { gUdfcState = UDFC_STATE_STARTNG; uv_barrier_init(&gUdfInitBarrier, 2); uv_thread_create(&gUdfLoopThread, constructUdfService, 0); @@ -1002,12 +999,12 @@ int32_t startUdfService() { return 0; } -int32_t stopUdfService() { +int32_t destroyUdfdProxy(int32_t dnodeId) { gUdfcState = UDFC_STATE_STOPPING; uv_barrier_destroy(&gUdfInitBarrier); - if (gUdfcState == UDFC_STATE_STOPPING) { - uv_process_kill(&gUdfdProcess, SIGINT); - } +// if (gUdfcState == UDFC_STATE_STOPPING) { +// uv_process_kill(&gUdfdProcess, SIGINT); +// } uv_async_send(&gUdfLoopStopAsync); uv_thread_join(&gUdfLoopThread); uv_mutex_destroy(&gUdfTaskQueueMutex); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index a02c94c109..71434c695f 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -12,10 +12,10 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ - #include "uv.h" #include "os.h" -#include "tlog.h" +#include "fnLog.h" +#include "thash.h" #include "tudf.h" #include "tudfInt.h" @@ -25,336 +25,377 @@ #include "tmsg.h" #include "trpc.h" -static uv_loop_t *loop; +typedef struct SUdfdContext { + uv_loop_t *loop; + char listenPipeName[UDF_LISTEN_PIPE_NAME_LEN]; + void *clientRpc; + + uv_mutex_t udfsMutex; + SHashObj* udfsHash; + + bool printVersion; +} SUdfdContext; + +SUdfdContext global; typedef struct SUdfdUvConn { - uv_stream_t *client; - char *inputBuf; - int32_t inputLen; - int32_t inputCap; - int32_t inputTotal; + uv_stream_t *client; + char *inputBuf; + int32_t inputLen; + int32_t inputCap; + int32_t inputTotal; } SUdfdUvConn; typedef struct SUvUdfWork { - uv_stream_t *client; - uv_buf_t input; - uv_buf_t output; + uv_stream_t *client; + uv_buf_t input; + uv_buf_t output; } SUvUdfWork; +typedef enum { + UDF_STATE_INIT = 0, + UDF_STATE_LOADING, + UDF_STATE_READY, + UDF_STATE_UNLOADING +} EUdfState; + typedef struct SUdf { - int32_t refCount; + int32_t refCount; + EUdfState state; + uv_mutex_t lock; + uv_cond_t condReady; - char name[16]; - int8_t type; + char name[16]; + int8_t type; + char path[PATH_MAX]; - uv_lib_t lib; - TUdfScalarProcFunc scalarProcFunc; - TUdfFreeUdfColumnFunc freeUdfColumn; + uv_lib_t lib; + TUdfScalarProcFunc scalarProcFunc; + TUdfFreeUdfColumnFunc freeUdfColumn; } SUdf; -//TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix -//TODO: add private udf structure. +// TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix +// TODO: add private udf structure. typedef struct SUdfHandle { - SUdf *udf; + SUdf *udf; } SUdfHandle; +int32_t udfdLoadUdf(char* udfName, SUdf* udf) { + strcpy(udf->name, udfName); + + int err = uv_dlopen(udf->path, &udf->lib); + if (err != 0) { + fnError("can not load library %s. error: %s", udf->path, uv_strerror(err)); + // TODO set error + } + //TODO: find all the functions + char normalFuncName[TSDB_FUNC_NAME_LEN] = {0}; + strcpy(normalFuncName, udfName); + uv_dlsym(&udf->lib, normalFuncName, (void **)(&udf->scalarProcFunc)); + char freeFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; + char *freeSuffix = "_free"; + strncpy(freeFuncName, normalFuncName, strlen(normalFuncName)); + strncat(freeFuncName, freeSuffix, strlen(freeSuffix)); + uv_dlsym(&udf->lib, freeFuncName, (void **)(&udf->freeUdfColumn)); + return 0; +} void udfdProcessRequest(uv_work_t *req) { - SUvUdfWork *uvUdf = (SUvUdfWork *) (req->data); - SUdfRequest request = {0}; - decodeUdfRequest(uvUdf->input.base, &request); + SUvUdfWork *uvUdf = (SUvUdfWork *)(req->data); + SUdfRequest request = {0}; + decodeUdfRequest(uvUdf->input.base, &request); - switch (request.type) { - case UDF_TASK_SETUP: { - debugPrint("%s", "process setup request"); - SUdf *udf = taosMemoryMalloc(sizeof(SUdf)); - udf->refCount = 0; - SUdfSetupRequest *setup = &request.setup; - strcpy(udf->name, setup->udfName); - //TODO: retrive udf info from mnode - char* path = "libudf1.so"; - int err = uv_dlopen(path, &udf->lib); - if (err != 0) { - debugPrint("can not load library %s. error: %s", path, uv_strerror(err)); - //TODO set error - } + switch (request.type) { + case UDF_TASK_SETUP: { + //TODO: tracable id from client. connect, setup, call, teardown + fnInfo("%"PRId64" setup request. udf name: %s", request.seqNum, request.setup.udfName); + SUdfSetupRequest *setup = &request.setup; - char normalFuncName[TSDB_FUNC_NAME_LEN] = {0}; - strcpy(normalFuncName, setup->udfName); - //TODO error, multi-thread, same udf, lock it - //TODO find all functions normal, init, destroy, normal, merge, finalize - uv_dlsym(&udf->lib, normalFuncName, (void **) (&udf->scalarProcFunc)); - char freeFuncName[TSDB_FUNC_NAME_LEN + 6] = {0}; - char *freeSuffix = "_free"; - strncpy(freeFuncName, normalFuncName, strlen(normalFuncName)); - strncat(freeFuncName, freeSuffix, strlen(freeSuffix)); - uv_dlsym(&udf->lib, freeFuncName, (void **)(&udf->freeUdfColumn)); + SUdf* udf = NULL; + uv_mutex_lock(&global.udfsMutex); + SUdf** udfInHash = taosHashGet(global.udfsHash, request.setup.udfName, TSDB_FUNC_NAME_LEN); + if (*udfInHash) { + ++(*udfInHash)->refCount; + udf = *udfInHash; + uv_mutex_unlock(&global.udfsMutex); + } else { + SUdf *udfNew = taosMemoryCalloc(1, sizeof(SUdf)); + udfNew->refCount = 1; + udfNew->state = UDF_STATE_INIT; - SUdfHandle *handle = taosMemoryMalloc(sizeof(SUdfHandle)); - handle->udf = udf; - udf->refCount++; - //TODO: allocate private structure and call init function and set it to handle - SUdfResponse rsp; - rsp.seqNum = request.seqNum; - rsp.type = request.type; - rsp.code = 0; - rsp.setupRsp.udfHandle = (int64_t) (handle); - int32_t len = encodeUdfResponse(NULL, &rsp); - rsp.msgLen = len; - void *bufBegin = taosMemoryMalloc(len); - void *buf = bufBegin; - encodeUdfResponse(&buf, &rsp); + uv_mutex_init(&udfNew->lock); + uv_cond_init(&udfNew->condReady); + udf = udfNew; + taosHashPut(global.udfsHash, request.setup.udfName, TSDB_FUNC_NAME_LEN, &udfNew, sizeof(&udfNew)); + uv_mutex_unlock(&global.udfsMutex); + } - uvUdf->output = uv_buf_init(bufBegin, len); - - taosMemoryFree(uvUdf->input.base); - break; + uv_mutex_lock(&udf->lock); + if (udf->state == UDF_STATE_INIT) { + udf->state = UDF_STATE_LOADING; + udfdLoadUdf(setup->udfName, udf); + udf->state = UDF_STATE_READY; + uv_cond_broadcast(&udf->condReady); + uv_mutex_unlock(&udf->lock); + } else { + while (udf->state != UDF_STATE_READY) { + uv_cond_wait(&udf->condReady, &udf->lock); } + uv_mutex_unlock(&udf->lock); + } + SUdfHandle *handle = taosMemoryMalloc(sizeof(SUdfHandle)); + handle->udf = udf; + // TODO: allocate private structure and call init function and set it to handle + SUdfResponse rsp; + rsp.seqNum = request.seqNum; + rsp.type = request.type; + rsp.code = 0; + rsp.setupRsp.udfHandle = (int64_t)(handle); + int32_t len = encodeUdfResponse(NULL, &rsp); + rsp.msgLen = len; + void *bufBegin = taosMemoryMalloc(len); + void *buf = bufBegin; + encodeUdfResponse(&buf, &rsp); - case UDF_TASK_CALL: { - debugPrint("%s", "process call request"); - SUdfCallRequest *call = &request.call; - SUdfHandle *handle = (SUdfHandle *) (call->udfHandle); - SUdf *udf = handle->udf; - - SUdfDataBlock input = {0}; - convertDataBlockToUdfDataBlock(&call->block, &input); - SUdfColumn output = {0}; - //TODO: call different functions according to call type, for now just calar - if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { - udf->scalarProcFunc(input, &output); - } - - SUdfResponse response = {0}; - SUdfResponse *rsp = &response; - if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { - rsp->seqNum = request.seqNum; - rsp->type = request.type; - rsp->code = 0; - SUdfCallResponse *subRsp = &rsp->callRsp; - subRsp->callType = call->callType; - convertUdfColumnToDataBlock(&output, &subRsp->resultData); - } - - int32_t len = encodeUdfResponse(NULL, rsp); - rsp->msgLen = len; - void *bufBegin = taosMemoryMalloc(len); - void *buf = bufBegin; - encodeUdfResponse(&buf, rsp); - uvUdf->output = uv_buf_init(bufBegin, len); - - //TODO: free - udf->freeUdfColumn(&output); - - taosMemoryFree(uvUdf->input.base); - break; - } - case UDF_TASK_TEARDOWN: { - debugPrint("%s", "process teardown request"); - - SUdfTeardownRequest *teardown = &request.teardown; - SUdfHandle *handle = (SUdfHandle *) (teardown->udfHandle); - SUdf *udf = handle->udf; - udf->refCount--; - if (udf->refCount == 0) { - uv_dlclose(&udf->lib); - taosMemoryFree(udf); - } - //TODO: call destroy and free udf private - taosMemoryFree(handle); - - SUdfResponse response; - SUdfResponse *rsp = &response; - rsp->seqNum = request.seqNum; - rsp->type = request.type; - rsp->code = 0; - int32_t len = encodeUdfResponse(NULL, rsp); - rsp->msgLen = len; - void *bufBegin = taosMemoryMalloc(len); - void *buf = bufBegin; - encodeUdfResponse(&buf, rsp); - uvUdf->output = uv_buf_init(bufBegin, len); - - taosMemoryFree(uvUdf->input.base); - break; - } - default: { - break; - } + uvUdf->output = uv_buf_init(bufBegin, len); + taosMemoryFree(uvUdf->input.base); + break; } + case UDF_TASK_CALL: { + SUdfCallRequest *call = &request.call; + fnDebug("%"PRId64 "call request. call type %d, handle: %"PRIx64, request.seqNum, call->callType, call->udfHandle); + SUdfHandle *handle = (SUdfHandle *)(call->udfHandle); + SUdf *udf = handle->udf; + + SUdfDataBlock input = {0}; + convertDataBlockToUdfDataBlock(&call->block, &input); + SUdfColumn output = {0}; + // TODO: call different functions according to call type, for now just calar + if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { + udf->scalarProcFunc(input, &output); + } + + SUdfResponse response = {0}; + SUdfResponse *rsp = &response; + if (call->callType == TSDB_UDF_CALL_SCALA_PROC) { + rsp->seqNum = request.seqNum; + rsp->type = request.type; + rsp->code = 0; + SUdfCallResponse *subRsp = &rsp->callRsp; + subRsp->callType = call->callType; + convertUdfColumnToDataBlock(&output, &subRsp->resultData); + } + + int32_t len = encodeUdfResponse(NULL, rsp); + rsp->msgLen = len; + void *bufBegin = taosMemoryMalloc(len); + void *buf = bufBegin; + encodeUdfResponse(&buf, rsp); + uvUdf->output = uv_buf_init(bufBegin, len); + + // TODO: free udf column + udf->freeUdfColumn(&output); + + taosMemoryFree(uvUdf->input.base); + break; + } + case UDF_TASK_TEARDOWN: { + SUdfTeardownRequest *teardown = &request.teardown; + fnInfo("teardown. %"PRId64"handle:%"PRIx64, request.seqNum, teardown->udfHandle) + SUdfHandle *handle = (SUdfHandle *)(teardown->udfHandle); + SUdf *udf = handle->udf; + bool unloadUdf = false; + uv_mutex_lock(&global.udfsMutex); + udf->refCount--; + if (udf->refCount == 0) { + unloadUdf = true; + taosHashRemove(global.udfsHash, udf->name, TSDB_FUNC_NAME_LEN); + } + uv_mutex_unlock(&global.udfsMutex); + if (unloadUdf) { + uv_cond_destroy(&udf->condReady); + uv_mutex_destroy(&udf->lock); + uv_dlclose(&udf->lib); + taosMemoryFree(udf); + } + // TODO: call destroy and free udf private + taosMemoryFree(handle); + + SUdfResponse response; + SUdfResponse *rsp = &response; + rsp->seqNum = request.seqNum; + rsp->type = request.type; + rsp->code = 0; + int32_t len = encodeUdfResponse(NULL, rsp); + rsp->msgLen = len; + void *bufBegin = taosMemoryMalloc(len); + void *buf = bufBegin; + encodeUdfResponse(&buf, rsp); + uvUdf->output = uv_buf_init(bufBegin, len); + + taosMemoryFree(uvUdf->input.base); + break; + } + default: { + break; + } + } } void udfdOnWrite(uv_write_t *req, int status) { - debugPrint("%s", "server after writing to pipe"); - if (status < 0) { - debugPrint("Write error %s", uv_err_name(status)); - } - SUvUdfWork *work = (SUvUdfWork *) req->data; - debugPrint("\tlength: %zu", work->output.len); - taosMemoryFree(work->output.base); - taosMemoryFree(work); - taosMemoryFree(req); + SUvUdfWork *work = (SUvUdfWork *)req->data; + if (status < 0) { + //TODO:log error and process it. + } + fnDebug("send response. length:%zu, status: %s", work->output.len, uv_err_name(status)); + taosMemoryFree(work->output.base); + taosMemoryFree(work); + taosMemoryFree(req); } - void udfdSendResponse(uv_work_t *work, int status) { - debugPrint("%s", "send response"); - SUvUdfWork *udfWork = (SUvUdfWork *) (work->data); + SUvUdfWork *udfWork = (SUvUdfWork *)(work->data); - uv_write_t *write_req = taosMemoryMalloc(sizeof(uv_write_t)); - write_req->data = udfWork; - uv_write(write_req, udfWork->client, &udfWork->output, 1, udfdOnWrite); + uv_write_t *write_req = taosMemoryMalloc(sizeof(uv_write_t)); + write_req->data = udfWork; + uv_write(write_req, udfWork->client, &udfWork->output, 1, udfdOnWrite); - taosMemoryFree(work); + taosMemoryFree(work); } void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) { - debugPrint("%s", "server allocate buffer for read"); - SUdfdUvConn *ctx = handle->data; - int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t); - if (ctx->inputCap == 0) { - ctx->inputBuf = taosMemoryMalloc(msgHeadSize); - if (ctx->inputBuf) { - ctx->inputLen = 0; - ctx->inputCap = msgHeadSize; - ctx->inputTotal = -1; + SUdfdUvConn *ctx = handle->data; + int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t); + if (ctx->inputCap == 0) { + ctx->inputBuf = taosMemoryMalloc(msgHeadSize); + if (ctx->inputBuf) { + ctx->inputLen = 0; + ctx->inputCap = msgHeadSize; + ctx->inputTotal = -1; - buf->base = ctx->inputBuf; - buf->len = ctx->inputCap; - } else { - //TODO: log error - buf->base = NULL; - buf->len = 0; - } + buf->base = ctx->inputBuf; + buf->len = ctx->inputCap; } else { - ctx->inputCap = ctx->inputTotal > ctx->inputCap ? ctx->inputTotal : ctx->inputCap; - void *inputBuf = taosMemoryRealloc(ctx->inputBuf, ctx->inputCap); - if (inputBuf) { - ctx->inputBuf = inputBuf; - buf->base = ctx->inputBuf + ctx->inputLen; - buf->len = ctx->inputCap - ctx->inputLen; - } else { - //TODO: log error - buf->base = NULL; - buf->len = 0; - } + // TODO: log error + buf->base = NULL; + buf->len = 0; } - debugPrint("\tinput buf cap - len - total : %d - %d - %d", ctx->inputCap, ctx->inputLen, ctx->inputTotal); - + } else { + ctx->inputCap = ctx->inputTotal > ctx->inputCap ? ctx->inputTotal : ctx->inputCap; + void *inputBuf = taosMemoryRealloc(ctx->inputBuf, ctx->inputCap); + if (inputBuf) { + ctx->inputBuf = inputBuf; + buf->base = ctx->inputBuf + ctx->inputLen; + buf->len = ctx->inputCap - ctx->inputLen; + } else { + // TODO: log error + buf->base = NULL; + buf->len = 0; + } + } + fnDebug("allocate buf. input buf cap - len - total : %d - %d - %d", ctx->inputCap, ctx->inputLen, ctx->inputTotal); } bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) { - if (pipe->inputTotal == -1 && pipe->inputLen >= sizeof(int32_t)) { - pipe->inputTotal = *(int32_t *) (pipe->inputBuf); - } - if (pipe->inputLen == pipe->inputCap && pipe->inputTotal == pipe->inputCap) { - return true; - } - return false; + if (pipe->inputTotal == -1 && pipe->inputLen >= sizeof(int32_t)) { + pipe->inputTotal = *(int32_t *)(pipe->inputBuf); + } + if (pipe->inputLen == pipe->inputCap && pipe->inputTotal == pipe->inputCap) { + fnDebug("receive request complete. length %d", pipe->inputLen); + return true; + } + return false; } void udfdHandleRequest(SUdfdUvConn *conn) { - uv_work_t *work = taosMemoryMalloc(sizeof(uv_work_t)); - SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork)); - udfWork->client = conn->client; - udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen); - conn->inputBuf = NULL; - conn->inputLen = 0; - conn->inputCap = 0; - conn->inputTotal = -1; - work->data = udfWork; - uv_queue_work(loop, work, udfdProcessRequest, udfdSendResponse); + uv_work_t *work = taosMemoryMalloc(sizeof(uv_work_t)); + SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork)); + udfWork->client = conn->client; + udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen); + conn->inputBuf = NULL; + conn->inputLen = 0; + conn->inputCap = 0; + conn->inputTotal = -1; + work->data = udfWork; + uv_queue_work(global.loop, work, udfdProcessRequest, udfdSendResponse); } void udfdPipeCloseCb(uv_handle_t *pipe) { - SUdfdUvConn *conn = pipe->data; - taosMemoryFree(conn->client); - taosMemoryFree(conn->inputBuf); - taosMemoryFree(conn); + SUdfdUvConn *conn = pipe->data; + taosMemoryFree(conn->client); + taosMemoryFree(conn->inputBuf); + taosMemoryFree(conn); } -void udfdUvHandleError(SUdfdUvConn *conn) { - uv_close((uv_handle_t *) conn->client, udfdPipeCloseCb); -} +void udfdUvHandleError(SUdfdUvConn *conn) { uv_close((uv_handle_t *)conn->client, udfdPipeCloseCb); } void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) { - debugPrint("%s, nread: %zd", "read from pipe", nread); + fnDebug("udf read %zu bytes from client", nread); + if (nread == 0) return; - if (nread == 0) return; + SUdfdUvConn *conn = client->data; - SUdfdUvConn *conn = client->data; - - if (nread > 0) { - conn->inputLen += nread; - if (isUdfdUvMsgComplete(conn)) { - udfdHandleRequest(conn); - } else { - //log error or continue; - } - return; + if (nread > 0) { + conn->inputLen += nread; + if (isUdfdUvMsgComplete(conn)) { + udfdHandleRequest(conn); + } else { + // log error or continue; } + return; + } - if (nread < 0) { - debugPrint("Read error %s", uv_err_name(nread)); - if (nread == UV_EOF) { - //TODO check more when close - } else { - } - udfdUvHandleError(conn); + if (nread < 0) { + fnDebug("Receive error %s", uv_err_name(nread)); + if (nread == UV_EOF) { + // TODO check more when close + } else { } + udfdUvHandleError(conn); + } } void udfdOnNewConnection(uv_stream_t *server, int status) { - debugPrint("%s", "on new connection"); - if (status < 0) { - // TODO - return; - } + fnDebug("new connection"); + if (status < 0) { + // TODO + return; + } - uv_pipe_t *client = (uv_pipe_t *) taosMemoryMalloc(sizeof(uv_pipe_t)); - uv_pipe_init(loop, client, 0); - if (uv_accept(server, (uv_stream_t *) client) == 0) { - SUdfdUvConn *ctx = taosMemoryMalloc(sizeof(SUdfdUvConn)); - ctx->client = (uv_stream_t *) client; - ctx->inputBuf = 0; - ctx->inputLen = 0; - ctx->inputCap = 0; - client->data = ctx; - ctx->client = (uv_stream_t *) client; - uv_read_start((uv_stream_t *) client, udfdAllocBuffer, udfdPipeRead); - } else { - uv_close((uv_handle_t *) client, NULL); - } + uv_pipe_t *client = (uv_pipe_t *)taosMemoryMalloc(sizeof(uv_pipe_t)); + uv_pipe_init(global.loop, client, 0); + if (uv_accept(server, (uv_stream_t *)client) == 0) { + SUdfdUvConn *ctx = taosMemoryMalloc(sizeof(SUdfdUvConn)); + ctx->client = (uv_stream_t *)client; + ctx->inputBuf = 0; + ctx->inputLen = 0; + ctx->inputCap = 0; + client->data = ctx; + ctx->client = (uv_stream_t *)client; + uv_read_start((uv_stream_t *)client, udfdAllocBuffer, udfdPipeRead); + } else { + uv_close((uv_handle_t *)client, NULL); + } } void removeListeningPipe(int sig) { - uv_fs_t req; - uv_fs_unlink(loop, &req, "udf.sock", NULL); - exit(0); + uv_fs_t req; + uv_fs_unlink(global.loop, &req, "udf.sock", NULL); + exit(0); } -typedef struct SServerContext { - void *clientRpc; -} SUdfdContext; +void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { return; } - -void udfdProcessRpcRsp(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - - return; -} - -int32_t fetchUdfFuncInfo(void *clientRpc, SEpSet* pEpSet, char* udfNames[], int32_t numOfUdfs) { +int32_t udfdFillUdfInfoFromMNode(void *clientRpc, SEpSet *pEpSet, char* udfName, SUdf* udf) { SRetrieveFuncReq retrieveReq = {0}; retrieveReq.numOfFuncs = 1; retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN); - for (int32_t i = 0; i < numOfUdfs; ++i) { - taosArrayPush(retrieveReq.pFuncNames, udfNames[i]); - } + taosArrayPush(retrieveReq.pFuncNames, udfName); int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq); - void* pReq = rpcMallocCont(contLen); + void *pReq = rpcMallocCont(contLen); tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq); taosArrayDestroy(retrieveReq.pFuncNames); @@ -368,66 +409,176 @@ int32_t fetchUdfFuncInfo(void *clientRpc, SEpSet* pEpSet, char* udfNames[], int3 SRetrieveFuncRsp retrieveRsp = {0}; tDeserializeSRetrieveFuncRsp(rpcRsp.pCont, rpcRsp.contLen, &retrieveRsp); - SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0); + SFuncInfo *pFuncInfo = (SFuncInfo *)taosArrayGet(retrieveRsp.pFuncInfos, 0); + char path[PATH_MAX] = {0}; + taosGetTmpfilePath("/tmp", "libudf", path); + TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); + // TODO check for failure of flush to disk + taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize); + taosCloseFile(&file); + strncpy(udf->path, path, strlen(path)); taosArrayDestroy(retrieveRsp.pFuncInfos); rpcFreeCont(rpcRsp.pCont); return 0; } -int32_t openUdfdClientRpc(SUdfdContext *ctx) { +int32_t udfdOpenClientRpc() { char *pass = "taosdata"; char *user = "root"; - char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; - taosEncryptPass_c((uint8_t*)pass, strlen(pass), secretEncrypt); + char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; + taosEncryptPass_c((uint8_t *)pass, strlen(pass), secretEncrypt); SRpcInit rpcInit = {0}; - rpcInit.label = (char*)"UDFD"; + rpcInit.label = (char *)"UDFD"; rpcInit.numOfThreads = 1; rpcInit.cfp = udfdProcessRpcRsp; rpcInit.sessions = 1024; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.idleTime = 30 * 1000; - rpcInit.parent = ctx; + rpcInit.parent = &global; - rpcInit.user = (char*)user; - rpcInit.ckey = (char*)"key"; - rpcInit.secret = (char*)secretEncrypt; + rpcInit.user = (char *)user; + rpcInit.ckey = (char *)"key"; + rpcInit.secret = (char *)secretEncrypt; rpcInit.spi = 1; - ctx->clientRpc = rpcOpen(&rpcInit); + global.clientRpc = rpcOpen(&rpcInit); return 0; } -int32_t closeUdfdClientRpc(SUdfdContext *ctx) { - rpcClose(ctx->clientRpc); +int32_t udfdCloseClientRpc() { + rpcClose(global.clientRpc); + return 0; +} + +static void udfdPrintVersion() { +#ifdef TD_ENTERPRISE + char *releaseName = "enterprise"; +#else + char *releaseName = "community"; +#endif + printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("gitinfo: %s\n", gitinfo); + printf("buildInfo: %s\n", buildinfo); +} + +static int32_t udfdParseArgs(int32_t argc, char *argv[]) { + for (int32_t i = 1; i < argc; ++i) { + if (strcmp(argv[i], "-c") == 0) { + if (i < argc - 1) { + if (strlen(argv[++i]) >= PATH_MAX) { + printf("config file path overflow"); + return -1; + } + tstrncpy(configDir, argv[i], PATH_MAX); + } else { + printf("'-c' requires a parameter, default is %s\n", configDir); + return -1; + } + } else if (strcmp(argv[i], "-V") == 0) { + global.printVersion = true; + } else { + } + } return 0; } -int main() { - debugPrint("libuv version: %x", UV_VERSION_HEX); - - loop = uv_default_loop(); - uv_fs_t req; - uv_fs_unlink(loop, &req, "udf.sock", NULL); - - uv_pipe_t server; - uv_pipe_init(loop, &server, 0); - - signal(SIGINT, removeListeningPipe); - - int r; - if ((r = uv_pipe_bind(&server, "udf.sock"))) { - debugPrint("Bind error %s\n", uv_err_name(r)); - removeListeningPipe(0); - return 1; - } - if ((r = uv_listen((uv_stream_t *) &server, 128, udfdOnNewConnection))) { - debugPrint("Listen error %s", uv_err_name(r)); - return 2; - } - uv_run(loop, UV_RUN_DEFAULT); - uv_loop_close(loop); +static int32_t udfdInitLog() { + char logName[12] = {0}; + snprintf(logName, sizeof(logName), "%slog", "udfd"); + return taosCreateLog(logName, 1, configDir, NULL, NULL, NULL, 0); +} + +static int32_t udfdUvInit() { + uv_loop_t* loop = taosMemoryMalloc(sizeof(uv_loop_t)); + if (loop) { + uv_loop_init(loop); + } + global.loop = loop; + char dnodeId[8] = {0}; + size_t dnodeIdSize; + uv_os_getenv("DNODE_ID", dnodeId, &dnodeIdSize); + char listenPipeName[32] = {0}; + snprintf(listenPipeName, sizeof(listenPipeName), "%s%s", UDF_LISTEN_PIPE_NAME_PREFIX, dnodeId); + strcpy(global.listenPipeName, listenPipeName); + + uv_fs_t req; + uv_fs_unlink(global.loop, &req, global.listenPipeName, NULL); + + uv_pipe_t server; + uv_pipe_init(global.loop, &server, 0); + + signal(SIGINT, removeListeningPipe); + + int r; + fnInfo("bind to pipe %s", global.listenPipeName); + if ((r = uv_pipe_bind(&server, listenPipeName))) { + fnError("Bind error %s", uv_err_name(r)); + removeListeningPipe(0); + return -1; + } + if ((r = uv_listen((uv_stream_t *)&server, 128, udfdOnNewConnection))) { + fnError("Listen error %s", uv_err_name(r)); + removeListeningPipe(0); + return -2; + } + return 0; +} + +static int32_t udfdRun() { + global.udfsHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + uv_mutex_init(&global.udfsMutex); + + //TOOD: client rpc to fetch udf function info from mnode + if (udfdOpenClientRpc() != 0) { + fnError("open rpc connection to mnode failure"); + return -1; + } + + if (udfdUvInit() != 0) { + fnError("uv init failure"); + return -2; + } + + fnInfo("start the udfd"); + int code = uv_run(global.loop, UV_RUN_DEFAULT); + fnInfo("udfd stopped. result: %s", uv_err_name(code)); + int codeClose = uv_loop_close(global.loop); + fnDebug("uv loop close. result: %s", uv_err_name(codeClose)); + udfdCloseClientRpc(); + uv_mutex_destroy(&global.udfsMutex); + taosHashCleanup(global.udfsHash); + return code; +} + +int main(int argc, char* argv[]) { + if (!taosCheckSystemIsSmallEnd()) { + printf("failed to start since on non-small-end machines\n"); + return -1; + } + + if (udfdParseArgs(argc, argv) != 0) { + printf("failed to start since parse args error\n"); + return -1; + } + + if (global.printVersion) { + udfdPrintVersion(); + return 0; + } + + if (udfdInitLog() != 0) { + printf("failed to start since init log error\n"); + return -1; + } + + if (taosInitCfg(configDir, NULL, NULL, NULL, 0) != 0) { + fnError("failed to start since read config error"); + return -1; + } + + return udfdRun(); } diff --git a/source/libs/function/test/runUdf.c b/source/libs/function/test/runUdf.c index 28dc6bb99a..41c7f65e0b 100644 --- a/source/libs/function/test/runUdf.c +++ b/source/libs/function/test/runUdf.c @@ -8,7 +8,7 @@ #include "tdatablock.h" int main(int argc, char *argv[]) { - startUdfService(); + createUdfdProxy(1); uv_sleep(1000); char path[256] = {0}; size_t cwdSize = 256; @@ -53,5 +53,5 @@ int main(int argc, char *argv[]) { } teardownUdf(handle); - stopUdfService(); + destroyUdfdProxy(1); } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index d4457a056e..bc9614b169 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -149,7 +149,9 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_RESET_QUERY_CACHE_STMT: return makeNode(type, sizeof(SNode)); case QUERY_NODE_COMPACT_STMT: + break; case QUERY_NODE_CREATE_FUNCTION_STMT: + return makeNode(type, sizeof(SCreateFunctionStmt)); case QUERY_NODE_DROP_FUNCTION_STMT: break; case QUERY_NODE_CREATE_STREAM_STMT: @@ -167,6 +169,7 @@ SNodeptr nodesMakeNode(ENodeType type) { case QUERY_NODE_SHOW_QNODES_STMT: case QUERY_NODE_SHOW_SNODES_STMT: case QUERY_NODE_SHOW_BNODES_STMT: + case QUERY_NODE_SHOW_CLUSTER_STMT: case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_FUNCTIONS_STMT: case QUERY_NODE_SHOW_INDEXES_STMT: @@ -1006,6 +1009,7 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp) { case OP_TYPE_NOT_LIKE: case OP_TYPE_MATCH: case OP_TYPE_NMATCH: + case OP_TYPE_JSON_CONTAINS: case OP_TYPE_IS_NULL: case OP_TYPE_IS_NOT_NULL: case OP_TYPE_IS_TRUE: @@ -1024,7 +1028,6 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp) { bool nodesIsJsonOp(const SOperatorNode* pOp) { switch (pOp->opType) { case OP_TYPE_JSON_GET_VALUE: - case OP_TYPE_JSON_CONTAINS: return true; default: break; diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index d53181b76f..7cb64b78e3 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -167,7 +167,7 @@ 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 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); diff --git a/source/libs/parser/inc/parInsertData.h b/source/libs/parser/inc/parInsertData.h index cf87f57d4f..ed7267655c 100644 --- a/source/libs/parser/inc/parInsertData.h +++ b/source/libs/parser/inc/parInsertData.h @@ -89,7 +89,7 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) { (int32_t)TD_BITMAP_BYTES(pTableInfo->numOfColumns - 1); } -static FORCE_INLINE void getSTSRowAppendInfo(SSchema *pSchema, uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, +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)) { @@ -131,7 +131,6 @@ 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 destroyBoundColumnInfo(SParsedDataColInfo* pColList); void destroyBlockArrayList(SArray* pDataBlockList); void destroyBlockHashmap(SHashObj* pDataBlockHash); int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo *pColInfo); @@ -139,5 +138,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t 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 ea01caf9d7..87348e292e 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -21,6 +21,8 @@ extern "C" { #endif #include "parser.h" +#include "parToken.h" +#include "parUtil.h" int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 742ab303d3..460a089802 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -47,6 +47,7 @@ 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); 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 94913eb7c2..9ff36c702f 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -346,6 +346,7 @@ cmd ::= SHOW TOPICS. cmd ::= SHOW VARIABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLE_STMT, NULL, NULL); } cmd ::= SHOW BNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT, NULL, NULL); } cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } +cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT, NULL, NULL); } db_name_cond_opt(A) ::= . { A = createDefaultDatabaseCondValue(pCxt); } db_name_cond_opt(A) ::= db_name(B) NK_DOT. { A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); } @@ -413,8 +414,8 @@ explain_options(A) ::= explain_options(B) RATIO NK_FLOAT(C). cmd ::= COMPACT VNODES IN NK_LP integer_list(A) NK_RP. { pCxt->pRootNode = createCompactStmt(pCxt, A); } /************************************************ create/drop function ************************************************/ -cmd ::= CREATE agg_func_opt(A) FUNCTION function_name(B) - AS NK_STRING(C) OUTPUTTYPE type_name(D) bufsize_opt(E). { pCxt->pRootNode = createCreateFunctionStmt(pCxt, A, &B, &C, D, E); } +cmd ::= CREATE agg_func_opt(A) FUNCTION not_exists_opt(F) function_name(B) + AS NK_STRING(C) OUTPUTTYPE type_name(D) bufsize_opt(E). { pCxt->pRootNode = createCreateFunctionStmt(pCxt, F, A, &B, &C, D, E); } cmd ::= DROP FUNCTION function_name(A). { pCxt->pRootNode = createDropFunctionStmt(pCxt, &A); } %type agg_func_opt { bool } @@ -836,6 +837,8 @@ query_expression(A) ::= query_expression_body(A) ::= query_primary(B). { A = B; } query_expression_body(A) ::= query_expression_body(B) UNION ALL query_expression_body(D). { A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, D); } +query_expression_body(A) ::= + query_expression_body(B) UNION query_expression_body(D). { A = createSetOperator(pCxt, SET_OP_TYPE_UNION, B, D); } query_primary(A) ::= query_specification(B). { A = B; } //query_primary(A) ::= diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 0296495d05..ea4e8cae50 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -48,6 +48,7 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) { } static void trimEscape(SToken* pName) { + // todo need to deal with `ioo``ii` -> ioo`ii if (NULL != pName && pName->n > 1 && '`' == pName->z[0]) { pName->z += 1; pName->n -= 2; @@ -1181,10 +1182,21 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) { return pStmt; } -SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize) { - SNode* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT); +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; + } + SCreateFunctionStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT); CHECK_OUT_OF_MEM(pStmt); - return pStmt; + pStmt->ignoreExists = ignoreExists; + strncpy(pStmt->funcName, pFuncName->z, pFuncName->n); + pStmt->isAgg = aggFunc; + strncpy(pStmt->libraryPath, pLibPath->z + 1, pLibPath->n - 2); + pStmt->outputDt = dataType; + pStmt->bufSize = bufSize; + return (SNode*)pStmt; } SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName) { diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index da759bc15a..f21a738032 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -40,29 +40,21 @@ sToken = tStrGetToken(pSql, &index, false); \ } while (0) -#define CHECK_CODE(expr) \ - do { \ - int32_t code = expr; \ - if (TSDB_CODE_SUCCESS != code) { \ - return code; \ - } \ - } 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* pTableDataBlocks; // 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; } SInsertParseContext; typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param); @@ -70,6 +62,29 @@ typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t 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; + char buf[TSDB_MAX_TAGS_LEN]; +} SKvParam; + +typedef struct SMemParam { + SRowBuilder* rb; + SSchema* schema; + int32_t toffset; + col_id_t colIdx; +} SMemParam; + + +#define CHECK_CODE(expr) \ + do { \ + int32_t code = expr; \ + if (TSDB_CODE_SUCCESS != code) { \ + return code; \ + } \ + } while (0) + + static int32_t skipInsertInto(SInsertParseContext* pCxt) { SToken sToken; NEXT_TOKEN(pCxt->pSql, sToken); @@ -163,7 +178,8 @@ static int32_t buildName(SInsertParseContext* pCxt, SToken* pStname, char* fullD return TSDB_CODE_SUCCESS; } -static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pParseCtx, SMsgBuf* pMsgBuf) { + +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"; const char* msg3 = "db is not specified"; @@ -179,7 +195,7 @@ static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pPar strncpy(name, pTableName->z, dbLen); dbLen = strdequote(name); - code = tNameSetDbName(pName, pParseCtx->acctId, name, dbLen); + code = tNameSetDbName(pName, acctId, name, dbLen); if (code != TSDB_CODE_SUCCESS) { return buildInvalidOperationMsg(pMsgBuf, msg1); } @@ -204,11 +220,11 @@ static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pPar strncpy(name, pTableName->z, pTableName->n); strdequote(name); - if (pParseCtx->db == NULL) { + if (dbName == NULL) { return buildInvalidOperationMsg(pMsgBuf, msg3); } - code = tNameSetDbName(pName, pParseCtx->acctId, pParseCtx->db, strlen(pParseCtx->db)); + code = tNameSetDbName(pName, acctId, dbName, strlen(dbName)); if (code != TSDB_CODE_SUCCESS) { code = buildInvalidOperationMsg(pMsgBuf, msg2); return code; @@ -225,8 +241,8 @@ static int32_t createSName(SName* pName, SToken* pTableName, SParseContext* pPar static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool isStb) { SParseContext* pBasicCtx = pCxt->pComCxt; - SName name = {0}; - createSName(&name, pTname, pBasicCtx, &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)); @@ -299,7 +315,7 @@ static int32_t buildOutput(SInsertParseContext* pCxt) { return TSDB_CODE_SUCCESS; } -static 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; @@ -397,35 +413,15 @@ static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, uint32_t type, cha return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z); } - if (IS_NUMERIC_TYPE(type) && pToken->n == 0) { - return buildSyntaxErrMsg(pMsgBuf, "invalid numeric data", pToken->z); - } - // Remove quotation marks if (TK_NK_STRING == pToken->type) { if (pToken->n >= TSDB_MAX_BYTES_PER_ROW) { return buildSyntaxErrMsg(pMsgBuf, "too long string", pToken->z); } - // delete escape character: \\, \', \" - char delim = pToken->z[0]; - int32_t cnt = 0; - int32_t j = 0; - for (uint32_t k = 1; k < pToken->n - 1; ++k) { - if (pToken->z[k] == '\\' || (pToken->z[k] == delim && pToken->z[k + 1] == delim)) { - tmpTokenBuf[j] = pToken->z[k + 1]; - cnt++; - j++; - k++; - continue; - } - tmpTokenBuf[j] = pToken->z[k]; - j++; - } - - tmpTokenBuf[j] = 0; + int32_t len = trimString(pToken->z, pToken->n, tmpTokenBuf, TSDB_MAX_BYTES_PER_ROW); pToken->z = tmpTokenBuf; - pToken->n -= 2 + cnt; + pToken->n = len; } return TSDB_CODE_SUCCESS; @@ -461,7 +457,7 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int if (isNullStr(pToken)) { if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { - return buildSyntaxErrMsg(pMsgBuf, "primary timestamp can not be null", pToken->z); + return buildSyntaxErrMsg(pMsgBuf, "primary timestamp should not be null", pToken->z); } return func(pMsgBuf, NULL, 0, param); @@ -603,6 +599,13 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return func(pMsgBuf, pToken->z, pToken->n, param); } + case TSDB_DATA_TYPE_JSON: { + 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); + } + case TSDB_DATA_TYPE_TIMESTAMP: { int64_t tmpVal; if (parseTime(end, pToken, timePrec, &tmpVal, pMsgBuf) != TSDB_CODE_SUCCESS) { @@ -616,13 +619,6 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return TSDB_CODE_FAILED; } -typedef struct SMemParam { - SRowBuilder* rb; - SSchema* schema; - int32_t toffset; - col_id_t colIdx; -} SMemParam; - static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) { SMemParam* pa = (SMemParam*)param; SRowBuilder* rb = pa->rb; @@ -723,27 +719,32 @@ static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* qsort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), boundIdxCompar); } - memset(&pColList->boundColumns[pColList->numOfBound], 0, - sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); + if(pColList->numOfCols > pColList->numOfBound){ + memset(&pColList->boundColumns[pColList->numOfBound], 0, + sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); + } return TSDB_CODE_SUCCESS; } -typedef struct SKvParam { - SKVRowBuilder* builder; - SSchema* schema; - char buf[TSDB_MAX_TAGS_LEN]; -} SKvParam; - -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){ + 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); + return TSDB_CODE_SUCCESS; + } + if (TSDB_DATA_TYPE_BINARY == type) { STR_WITH_SIZE_TO_VARSTR(pa->buf, value, len); - tdAddColToKVRow(pa->builder, colId, type, pa->buf); + tdAddColToKVRow(pa->builder, colId, pa->buf, varDataTLen(pa->buf)); } else if (TSDB_DATA_TYPE_NCHAR == type) { // if the converted output len is over than pColumnModel->bytes, return error: 'Argument list too long' int32_t output = 0; @@ -751,25 +752,24 @@ static int32_t KvRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, voi char buf[512] = {0}; snprintf(buf, tListLen(buf), "%s", strerror(errno)); return buildSyntaxErrMsg(pMsgBuf, buf, value); - ; } varDataSetLen(pa->buf, output); - tdAddColToKVRow(pa->builder, colId, type, pa->buf); + tdAddColToKVRow(pa->builder, colId, pa->buf, varDataTLen(pa->buf)); } else { - tdAddColToKVRow(pa->builder, colId, type, value); + tdAddColToKVRow(pa->builder, colId, value, TYPE_BYTES[type]); } return TSDB_CODE_SUCCESS; } -static int32_t buildCreateTbReq(SInsertParseContext* pCxt, const SName* pName, SKVRow row) { +static int32_t buildCreateTbReq(SVCreateTbReq *pTbReq, const SName* pName, SKVRow row, int64_t suid) { char dbFName[TSDB_DB_FNAME_LEN] = {0}; tNameGetFullDbName(pName, dbFName); - pCxt->createTblReq.type = TD_CHILD_TABLE; - pCxt->createTblReq.name = strdup(pName->tname); - pCxt->createTblReq.ctbCfg.suid = pCxt->pTableMeta->suid; - pCxt->createTblReq.ctbCfg.pTag = row; + pTbReq->type = TD_CHILD_TABLE; + pTbReq->name = strdup(pName->tname); + pTbReq->ctbCfg.suid = suid; + pTbReq->ctbCfg.pTag = row; return TSDB_CODE_SUCCESS; } @@ -781,23 +781,42 @@ static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint } SKvParam param = {.builder = &pCxt->tagsBuilder}; - SToken sToken; - 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); - SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i] - 1]; // colId starts with 1 + + if (sToken.type == TK_NK_QUESTION) { + isParseBindParam = true; + if (NULL == pCxt->pStmtCb) { + return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); + } + + continue; + } + + 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 param.schema = pTagSchema; CHECK_CODE( parseValueToken(&pCxt->pSql, &sToken, pTagSchema, precision, tmpTokenBuf, KvRowAppend, ¶m, &pCxt->msg)); } + if (isParseBindParam) { + return TSDB_CODE_SUCCESS; + } + SKVRow row = tdGetKVRowFromBuilder(&pCxt->tagsBuilder); if (NULL == row) { return buildInvalidOperationMsg(&pCxt->msg, "tag value expected"); } tdSortKVRowByColIdx(row); - return buildCreateTbReq(pCxt, pName, row); + return buildCreateTbReq(&pCxt->createTblReq, pName, row, pCxt->pTableMeta->suid); } static int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { @@ -821,7 +840,7 @@ static int32_t storeTableMeta(SHashObj* pHash, const char* pName, int32_t len, S // pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) { SName name; - createSName(&name, pTbnameToken, pCxt->pComCxt, &pCxt->msg); + createSName(&name, pTbnameToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg); char tbFName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(&name, tbFName); int32_t len = strlen(tbFName); @@ -866,8 +885,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken) return TSDB_CODE_SUCCESS; } -static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, int32_t* len, - 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 @@ -882,8 +900,22 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); SSchema* pSchema = &schema[spd->boundColumns[i] - 1]; + + if (sToken.type == TK_NK_QUESTION) { + isParseBindParam = true; + if (NULL == pCxt->pStmtCb) { + return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); + } + + continue; + } + + if (isParseBindParam) { + return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); + } + param.schema = pSchema; - getSTSRowAppendInfo(schema, pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx); + getSTSRowAppendInfo(pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx); CHECK_CODE(parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, MemRowAppend, ¶m, &pCxt->msg)); if (PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { @@ -902,6 +934,8 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, } } } + + *gotRow = true; } // *len = pBuilder->extendedRowSize; @@ -932,20 +966,24 @@ static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlo maxRows = tSize; } - int32_t len = 0; - CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &len, tmpTokenBuf)); - pDataBlock->size += extendedRowSize; // len; + bool gotRow = false; + CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf)); + if (gotRow) { + pDataBlock->size += extendedRowSize; //len; + } NEXT_TOKEN(pCxt->pSql, sToken); if (TK_NK_RP != sToken.type) { return buildSyntaxErrMsg(&pCxt->msg, ") expected", sToken.z); } - (*numOfRows)++; + if (gotRow) { + (*numOfRows)++; + } } - if (0 == (*numOfRows)) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + 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 TSDB_CODE_SUCCESS; } @@ -967,7 +1005,7 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da return TSDB_CODE_SUCCESS; } -static void destroyCreateSubTbReq(SVCreateTbReq* pReq) { +void destroyCreateSubTbReq(SVCreateTbReq* pReq) { taosMemoryFreeClear(pReq->name); taosMemoryFreeClear(pReq->ctbCfg.pTag); } @@ -1001,7 +1039,6 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) { taosHashCleanup(pCxt->pVgroupsHashObj); destroyBlockHashmap(pCxt->pTableBlockHashObj); - destroyBlockArrayList(pCxt->pTableDataBlocks); destroyBlockArrayList(pCxt->pVgDataBlocks); } @@ -1011,23 +1048,41 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) { // VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path // [...]; static int32_t parseInsertBody(SInsertParseContext* pCxt) { + int32_t tbNum = 0; + // for each table while (1) { - destroyInsertParseContextForTable(pCxt); - SToken sToken; + char *tbName = NULL; + // pSql -> tb_name ... NEXT_TOKEN(pCxt->pSql, sToken); // no data in the sql string anymore. if (sToken.n == 0) { - if (0 == pCxt->totalNum) { + if (0 == pCxt->totalNum && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { return buildInvalidOperationMsg(&pCxt->msg, "no data in sql"); - ; } break; } + 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");; + } + + destroyInsertParseContextForTable(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); @@ -1053,7 +1108,9 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { if (TK_VALUES == sToken.type) { // pSql -> (field1_value, ...) [(field1_value2, ...) ...] CHECK_CODE(parseValuesClause(pCxt, dataBuf)); - pCxt->pOutput->insertType = TSDB_QUERY_TYPE_INSERT; + TSDB_QUERY_SET_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_INSERT); + + tbNum++; continue; } @@ -1066,14 +1123,32 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { } // todo pCxt->pOutput->insertType = TSDB_QUERY_TYPE_FILE_INSERT; + + tbNum++; continue; } 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)); + if (NULL == tags) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + memcpy(tags, &pCxt->tags, sizeof(pCxt->tags)); + (*pCxt->pStmtCb->setBindInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pTableMeta, tags); + memset(&pCxt->tags, 0, sizeof(pCxt->tags)); + + (*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 (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && - taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { + if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { CHECK_CODE(mergeTableDataBlocks(pCxt->pTableBlockHashObj, pCxt->pOutput->payloadType, &pCxt->pVgDataBlocks)); } return buildOutput(pCxt); @@ -1087,29 +1162,43 @@ 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, - .pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, false), - .pTableBlockHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, false), - .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, false), - .totalNum = 0, - .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT)}; + .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 (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj || - NULL == context.pOutput) { + if (pContext->pStmtCb && *pQuery) { + (*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) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - *pQuery = taosMemoryCalloc(1, sizeof(SQuery)); - if (NULL == *pQuery) { - return TSDB_CODE_OUT_OF_MEMORY; + if (pContext->pStmtCb) { + TSDB_QUERY_SET_TYPE(context.pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT); } - (*pQuery)->execMode = QUERY_EXEC_MODE_SCHEDULE; - (*pQuery)->haveResultSet = false; - (*pQuery)->msgType = TDMT_VND_SUBMIT; - (*pQuery)->pRoot = (SNode*)context.pOutput; + + if (NULL == *pQuery) { + *pQuery = taosMemoryCalloc(1, sizeof(SQuery)); + if (NULL == *pQuery) { + return TSDB_CODE_OUT_OF_MEMORY; + } + (*pQuery)->execMode = QUERY_EXEC_MODE_SCHEDULE; + (*pQuery)->haveResultSet = false; + (*pQuery)->msgType = TDMT_VND_SUBMIT; + (*pQuery)->pRoot = (SNode*)context.pOutput; + } + context.pOutput->payloadType = PAYLOAD_TYPE_KV; int32_t code = skipInsertInto(&context); @@ -1119,3 +1208,318 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { destroyInsertParseContext(&context); 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 code = 0; + char *tbName = NULL; + + NEXT_TOKEN(pTableName, sToken); + + if (sToken.n == 0) { + return buildInvalidOperationMsg(&msg, "empty table name"); + } + + code = createSName(pName, &sToken, acctId, dbName, &msg); + if (code) { + return code; + } + + NEXT_TOKEN(pTableName, sToken); + + if (sToken.n > 0) { + return buildInvalidOperationMsg(&msg, "table name format is wrong"); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) { + SVnodeModifOpStmt *modifyNode = (SVnodeModifOpStmt *)pQuery->pRoot; + int32_t code = 0; + SInsertParseContext insertCtx = { + .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)); + } + + CHECK_CODE(buildOutput(&insertCtx)); + + 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}; + SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags; + if (NULL == tags) { + return TSDB_CODE_QRY_APP_ERROR; + } + + SKVRowBuilder tagBuilder; + if (tdInitKVRowBuilder(&tagBuilder) < 0) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + + SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta); + SKvParam param = {.builder = &tagBuilder}; + + for (int c = 0; c < tags->numOfBound; ++c) { + if (bind[c].is_null && bind[c].is_null[0]) { + KvRowAppend(&pBuf, NULL, 0, ¶m); + continue; + } + + 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)); + } + + SKVRow row = tdGetKVRowFromBuilder(&tagBuilder); + if (NULL == row) { + tdDestroyKVRowBuilder(&tagBuilder); + return buildInvalidOperationMsg(&pBuf, "tag value expected"); + } + tdSortKVRowByColIdx(row); + + SVCreateTbReq tbReq = {0}; + CHECK_CODE(buildCreateTbReq(&tbReq, pName, row, suid)); + CHECK_CODE(buildCreateTbMsg(pDataBlock, &tbReq)); + + destroyCreateSubTbReq(&tbReq); + tdDestroyKVRowBuilder(&tagBuilder); + + 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); + SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo; + SRowBuilder* pBuilder = &pDataBlock->rowBuilder; + 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); + + // 1. set the parsed value from sql string + for (int c = 0; c < spd->numOfBound; ++c) { + SSchema* pColSchema = &pSchema[spd->boundColumns[c] - 1]; + + if (bind[c].buffer_type != pColSchema->type) { + return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + } + + if (bind[c].num != rowNum) { + return buildInvalidOperationMsg(&pBuf, "row number in each bind param should be the same"); + } + + param.schema = pColSchema; + getSTSRowAppendInfo(pBuilder->rowType, spd, c, ¶m.toffset, ¶m.colIdx); + + if (bind[c].is_null && bind[c].is_null[r]) { + 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)); + } + + if (PRIMARYKEY_TIMESTAMP_COL_ID == pColSchema->colId) { + TSKEY tsKey = TD_ROW_KEY(row); + 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) { + if (spd->cols[i].valStat == VAL_STAT_NONE) { // the primary TS key is not VAL_STAT_NONE + tdAppendColValToTpRow(pBuilder, TD_VTYPE_NONE, getNullValue(pSchema[i].type), true, pSchema[i].type, i, + spd->cols[i].toffset); + } + } + } + + pDataBlock->size += extendedRowSize; + } + + 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"); + } + + 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); + 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); + + 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) { + tdSRowResetBuf(pBuilder, row); + } else { + tdSRowGetBuf(pBuilder, row); + } + + SSchema* pColSchema = &pSchema[spd->boundColumns[colIdx] - 1]; + + if (bind->buffer_type != pColSchema->type) { + return buildInvalidOperationMsg(&pBuf, "column type mis-match with buffer type"); + } + + 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); + + if (bind->is_null && bind->is_null[r]) { + 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->length[r]; + } + + 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); + } + + // 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) { + if (spd->cols[i].valStat == VAL_STAT_NONE) { // the primary TS key is not VAL_STAT_NONE + tdAppendColValToTpRow(pBuilder, TD_VTYPE_NONE, getNullValue(pSchema[i].type), true, pSchema[i].type, i, + spd->cols[i].toffset); + } + } + } + } + + if (rowEnd) { + pDataBlock->size += extendedRowSize * bind->num; + + 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"); + } + } + + return TSDB_CODE_SUCCESS; +} + + +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) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < boundInfo->numOfBound; ++i) { + SSchema* pTagSchema = &pSchema[boundInfo->boundColumns[i] - 1]; + strcpy((*fields)[i].name, pTagSchema->name); + (*fields)[i].type = pTagSchema->type; + (*fields)[i].bytes = pTagSchema->bytes; + } + } + + *fieldNum = boundInfo->numOfBound; + + return TSDB_CODE_SUCCESS; +} + + +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); + if (tags->numOfBound <= 0) { + *fieldNum = 0; + *fields = NULL; + + return TSDB_CODE_SUCCESS; + } + + 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); + if (pDataBlock->boundColumnInfo.numOfBound <= 0) { + *fieldNum = 0; + if (fields) { + *fields = NULL; + } + + return TSDB_CODE_SUCCESS; + } + + 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 088b25d544..bf30915fcb 100644 --- a/source/libs/parser/src/parInsertData.c +++ b/source/libs/parser/src/parInsertData.c @@ -18,6 +18,7 @@ #include "catalog.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 @@ -102,7 +103,13 @@ int32_t boundIdxCompar(const void *lhs, const void *rhs) { } } -void destroyBoundColumnInfo(SParsedDataColInfo* pColList) { +void destroyBoundColumnInfo(void* pBoundInfo) { + if (NULL == pBoundInfo) { + return; + } + + SParsedDataColInfo* pColList = (SParsedDataColInfo*)pBoundInfo; + taosMemoryFreeClear(pColList->boundColumns); taosMemoryFreeClear(pColList->cols); taosMemoryFreeClear(pColList->colIdxInfo); @@ -149,7 +156,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star return TSDB_CODE_SUCCESS; } -static int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) { +int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq) { int32_t len = tSerializeSVCreateTbReq(NULL, pCreateTbReq); if (pBlocks->nAllocSize - pBlocks->size < len) { pBlocks->nAllocSize += len + pBlocks->rowSize; @@ -506,6 +513,28 @@ 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; + 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); + if (tmp != NULL) { + pDataBlock->pData = tmp; + memset(pDataBlock->pData + pDataBlock->size, 0, pDataBlock->nAllocSize - pDataBlock->size); + } else { + // do nothing, if allocate more memory failed + pDataBlock->nAllocSize = nAllocSizeOld; + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + } + + return TSDB_CODE_SUCCESS; +} + int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t * numOfRows) { size_t remain = pDataBlock->nAllocSize - pDataBlock->size; const int factor = 5; @@ -541,3 +570,84 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo pColInfo->boundNullLen); return TSDB_CODE_SUCCESS; } + + +int32_t qResetStmtDataBlock(void* block, bool keepBuf) { + STableDataBlocks* pBlock = (STableDataBlocks*)block; + + if (keepBuf) { + taosMemoryFreeClear(pBlock->pData); + pBlock->pData = taosMemoryMalloc(TSDB_PAYLOAD_SIZE); + if (NULL == pBlock->pData) { + return TSDB_CODE_OUT_OF_MEMORY; + } + memset(pBlock->pData, 0, sizeof(SSubmitBlk)); + } else { + pBlock->pData = NULL; + } + + 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); +} + +int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) { + int32_t code = qCloneStmtDataBlock(pDst, pSrc); + if (code) { + return code; + } + + STableDataBlocks *pBlock = (STableDataBlocks*)*pDst; + pBlock->pData = taosMemoryMalloc(pBlock->nAllocSize); + if (NULL == pBlock->pData) { + qFreeStmtDataBlock(pBlock); + return TSDB_CODE_OUT_OF_MEMORY; + } + + memset(pBlock->pData, 0, sizeof(SSubmitBlk)); + + return TSDB_CODE_SUCCESS; +} + + +void qFreeStmtDataBlock(void* pDataBlock) { + if (pDataBlock == NULL) { + return; + } + + taosMemoryFreeClear(((STableDataBlocks*)pDataBlock)->pData); + taosMemoryFreeClear(pDataBlock); +} + +void qDestroyStmtDataBlock(void* pBlock) { + if (pBlock == NULL) { + return; + } + + STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock; + + pDataBlock->cloned = false; + destroyDataBlock(pDataBlock); +} + diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index d8ab3f8ced..666cdbb6db 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -52,6 +52,7 @@ static SKeyword keywordTable[] = { {"CACHE", TK_CACHE}, {"CACHELAST", TK_CACHELAST}, {"CAST", TK_CAST}, + {"CLUSTER", TK_CLUSTER}, {"COLUMN", TK_COLUMN}, {"COMMENT", TK_COMMENT}, {"COMP", TK_COMP}, @@ -248,7 +249,6 @@ static SKeyword keywordTable[] = { // {"BEFORE", TK_BEFORE}, // {"BEGIN", TK_BEGIN}, // {"CASCADE", TK_CASCADE}, - // {"CLUSTER", TK_CLUSTER}, // {"CONFLICT", TK_CONFLICT}, // {"COPY", TK_COPY}, // {"DEFERRED", TK_DEFERRED}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 4e1749ac02..a2b86274b3 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -230,6 +230,21 @@ static int32_t initTranslateContext(SParseContext* pParseCxt, STranslateContext* return TSDB_CODE_SUCCESS; } +static int32_t resetTranslateNamespace(STranslateContext* pCxt) { + if (NULL != pCxt->pNsLevel) { + size_t size = taosArrayGetSize(pCxt->pNsLevel); + for (size_t i = 0; i < size; ++i) { + taosArrayDestroy(taosArrayGetP(pCxt->pNsLevel, i)); + } + taosArrayDestroy(pCxt->pNsLevel); + } + pCxt->pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); + if (NULL == pCxt->pNsLevel) { + return TSDB_CODE_OUT_OF_MEMORY; + } + return TSDB_CODE_SUCCESS; +} + static void destroyTranslateContext(STranslateContext* pCxt) { if (NULL != pCxt->pNsLevel) { size_t size = taosArrayGetSize(pCxt->pNsLevel); @@ -261,9 +276,11 @@ static bool belongTable(const char* currentDb, const SColumnNode* pCol, const ST return (0 == cmp); } -static SNodeList* getProjectList(SNode* pNode) { +static SNodeList* getProjectList(const SNode* pNode) { if (QUERY_NODE_SELECT_STMT == nodeType(pNode)) { return ((SSelectStmt*)pNode)->pProjectionList; + } else if (QUERY_NODE_SET_OPERATOR == nodeType(pNode)) { + return ((SSetOperator*)pNode)->pProjectionList; } return NULL; } @@ -543,14 +560,18 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; } } else if (nodesIsComparisonOp(pOp)) { - if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_JSON == rdt.type || + if (TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_JSON == rdt.type || TSDB_DATA_TYPE_BLOB == rdt.type) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); } pOp->node.resType.type = TSDB_DATA_TYPE_BOOL; pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes; - } else { - // todo json operator + } else if (nodesIsJsonOp(pOp)){ + if (TSDB_DATA_TYPE_JSON != ldt.type || TSDB_DATA_TYPE_BINARY != rdt.type) { + return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName); + } + pOp->node.resType.type = TSDB_DATA_TYPE_JSON; + pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes; } return DEAL_RES_CONTINUE; } @@ -1349,6 +1370,86 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) { return code; } +static SNode* createSetOperProject(SNode* pNode) { + SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN); + if (NULL == pCol) { + return NULL; + } + pCol->node.resType = ((SExprNode*)pNode)->resType; + strcpy(pCol->colName, ((SExprNode*)pNode)->aliasName); + strcpy(pCol->node.aliasName, pCol->colName); + return (SNode*)pCol; +} + +static bool dataTypeEqual(const SDataType* l, const SDataType* r) { + return (l->type == r->type && l->bytes == l->bytes && l->precision == r->precision && l->scale == l->scale); +} + +static int32_t createCastFunc(STranslateContext* pCxt, SNode* pExpr, SDataType dt, SNode** pCast) { + SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION); + if (NULL == pFunc) { + return TSDB_CODE_OUT_OF_MEMORY; + } + strcpy(pFunc->functionName, "cast"); + pFunc->node.resType = dt; + if (TSDB_CODE_SUCCESS != nodesListMakeAppend(&pFunc->pParameterList, pExpr)) { + nodesDestroyNode(pFunc); + return TSDB_CODE_OUT_OF_MEMORY; + } + if (DEAL_RES_ERROR == translateFunction(pCxt, pFunc)) { + nodesClearList(pFunc->pParameterList); + pFunc->pParameterList = NULL; + nodesDestroyNode(pFunc); + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)pExpr)->aliasName); + } + *pCast = (SNode*)pFunc; + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSetOperatorImpl(STranslateContext* pCxt, SSetOperator* pSetOperator) { + SNodeList* pLeftProjections = getProjectList(pSetOperator->pLeft); + SNodeList* pRightProjections = getProjectList(pSetOperator->pRight); + if (LIST_LENGTH(pLeftProjections) != LIST_LENGTH(pRightProjections)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCORRECT_NUM_OF_COL); + } + + SNode* pLeft = NULL; + SNode* pRight = NULL; + FORBOTH(pLeft, pLeftProjections, pRight, pRightProjections) { + SExprNode* pLeftExpr = (SExprNode*)pLeft; + SExprNode* pRightExpr = (SExprNode*)pRight; + if (!dataTypeEqual(&pLeftExpr->resType, &pRightExpr->resType)) { + SNode* pRightFunc = NULL; + int32_t code = createCastFunc(pCxt, pRight, pLeftExpr->resType, &pRightFunc); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + REPLACE_LIST2_NODE(pRightFunc); + pRightExpr = (SExprNode*)pRightFunc; + } + strcpy(pRightExpr->aliasName, pLeftExpr->aliasName); + pRightExpr->aliasName[strlen(pLeftExpr->aliasName)] = '\0'; + if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, createSetOperProject(pLeft))) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + return TSDB_CODE_SUCCESS; +} + +static int32_t translateSetOperator(STranslateContext* pCxt, SSetOperator* pSetOperator) { + int32_t code = translateQuery(pCxt, pSetOperator->pLeft); + if (TSDB_CODE_SUCCESS == code) { + code = resetTranslateNamespace(pCxt); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateQuery(pCxt, pSetOperator->pRight); + } + if (TSDB_CODE_SUCCESS == code) { + code = translateSetOperatorImpl(pCxt, pSetOperator); + } + return code; +} + static int64_t getUnitPerMinute(uint8_t precision) { switch (precision) { case TSDB_TIME_PRECISION_MILLI: @@ -1797,6 +1898,17 @@ static int32_t checkTableSmaOption(STranslateContext* pCxt, SCreateTableStmt* pS return TSDB_CODE_SUCCESS; } +static int32_t checkTableTags(STranslateContext* pCxt, SCreateTableStmt* pStmt) { + SNode* pNode; + FOREACH(pNode, pStmt->pTags) { + SColumnDefNode* pCol = (SColumnDefNode*)pNode; + if(pCol->dataType.type == TSDB_DATA_TYPE_JSON && LIST_LENGTH(pStmt->pTags) > 1){ + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG); + } + } + return TSDB_CODE_SUCCESS; +} + static int32_t checkTableRollupOption(STranslateContext* pCxt, SNodeList* pFuncs) { if (NULL == pFuncs) { return TSDB_CODE_SUCCESS; @@ -1832,6 +1944,9 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt if (TSDB_CODE_SUCCESS == code) { code = checkRangeOption(pCxt, "delay", pStmt->pOptions->pDelay, TSDB_MIN_DB_DELAY, TSDB_MAX_DB_DELAY); } + if (TSDB_CODE_SUCCESS == code) { + code = checkTableTags(pCxt, pStmt); + } return code; } @@ -2590,12 +2705,64 @@ static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pSt return TSDB_CODE_SUCCESS; } +static int32_t readFromFile(char* pName, int32_t *len, char **buf) { + int64_t filesize = 0; + if (taosStatFile(pName, &filesize, NULL) < 0) { + return TAOS_SYSTEM_ERROR(errno); + } + + *len = filesize; + + if (*len <= 0) { + return TSDB_CODE_TSC_FILE_EMPTY; + } + + *buf = taosMemoryCalloc(1, *len); + if (*buf == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY); + if (NULL == tfile) { + taosMemoryFreeClear(*buf); + return TAOS_SYSTEM_ERROR(errno); + } + + int64_t s = taosReadFile(tfile, *buf, *len); + if (s != *len) { + taosCloseFile(&tfile); + taosMemoryFreeClear(*buf); + return TSDB_CODE_TSC_APP_ERROR; + } + taosCloseFile(&tfile); + return TSDB_CODE_SUCCESS; +} + +static int32_t translateCreateFunction(STranslateContext* pCxt, SCreateFunctionStmt* pStmt) { + SCreateFuncReq req = {0}; + strcpy(req.name, pStmt->funcName); + req.igExists = pStmt->ignoreExists; + req.funcType = pStmt->isAgg ? TSDB_FUNC_TYPE_AGGREGATE : TSDB_FUNC_TYPE_SCALAR; + req.scriptType = TSDB_FUNC_SCRIPT_BIN_LIB; + req.outputType = pStmt->outputDt.type; + req.outputLen = pStmt->outputDt.bytes; + req.bufSize = pStmt->bufSize; + int32_t code = readFromFile(pStmt->libraryPath, &req.codeLen, &req.pCode); + if (TSDB_CODE_SUCCESS == code) { + code = buildCmdMsg(pCxt, TDMT_MND_CREATE_FUNC, (FSerializeFunc)tSerializeSCreateFuncReq, &req); + } + return code; +} + static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { int32_t code = TSDB_CODE_SUCCESS; switch (nodeType(pNode)) { case QUERY_NODE_SELECT_STMT: code = translateSelect(pCxt, (SSelectStmt*)pNode); break; + case QUERY_NODE_SET_OPERATOR: + code = translateSetOperator(pCxt, (SSetOperator*)pNode); + break; case QUERY_NODE_CREATE_DATABASE_STMT: code = translateCreateDatabase(pCxt, (SCreateDatabaseStmt*)pNode); break; @@ -2688,6 +2855,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { case QUERY_NODE_DROP_STREAM_STMT: code = translateDropStream(pCxt, (SDropStreamStmt*)pNode); break; + case QUERY_NODE_CREATE_FUNCTION_STMT: + code = translateCreateFunction(pCxt, (SCreateFunctionStmt*)pNode); + break; default: break; } @@ -2705,8 +2875,8 @@ static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode) { return code; } -static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* numOfCols, SSchema** pSchema) { - *numOfCols = LIST_LENGTH(pSelect->pProjectionList); +static int32_t extractQueryResultSchema(const SNodeList* pProjections, int32_t* numOfCols, SSchema** pSchema) { + *numOfCols = LIST_LENGTH(pProjections); *pSchema = taosMemoryCalloc((*numOfCols), sizeof(SSchema)); if (NULL == (*pSchema)) { return TSDB_CODE_OUT_OF_MEMORY; @@ -2714,7 +2884,7 @@ static int32_t extractSelectResultSchema(const SSelectStmt* pSelect, int32_t* nu SNode* pNode; int32_t index = 0; - FOREACH(pNode, pSelect->pProjectionList) { + FOREACH(pNode, pProjections) { SExprNode* pExpr = (SExprNode*)pNode; (*pSchema)[index].type = pExpr->resType.type; (*pSchema)[index].bytes = pExpr->resType.bytes; @@ -2773,7 +2943,8 @@ int32_t extractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pS switch (nodeType(pRoot)) { case QUERY_NODE_SELECT_STMT: - return extractSelectResultSchema((SSelectStmt*)pRoot, numOfCols, pSchema); + case QUERY_NODE_SET_OPERATOR: + return extractQueryResultSchema(getProjectList(pRoot), numOfCols, pSchema); case QUERY_NODE_EXPLAIN_STMT: return extractExplainResultSchema(numOfCols, pSchema); case QUERY_NODE_DESCRIBE_STMT: @@ -2802,6 +2973,7 @@ static const char* getSysDbName(ENodeType type) { case QUERY_NODE_SHOW_BNODES_STMT: case QUERY_NODE_SHOW_SNODES_STMT: case QUERY_NODE_SHOW_LICENCE_STMT: + case QUERY_NODE_SHOW_CLUSTER_STMT: return TSDB_INFORMATION_SCHEMA_DB; case QUERY_NODE_SHOW_CONNECTIONS_STMT: case QUERY_NODE_SHOW_QUERIES_STMT: @@ -2844,6 +3016,8 @@ static const char* getSysTableName(ENodeType type) { return TSDB_INS_TABLE_SNODES; case QUERY_NODE_SHOW_LICENCE_STMT: return TSDB_INS_TABLE_LICENCES; + case QUERY_NODE_SHOW_CLUSTER_STMT: + return TSDB_INS_TABLE_CLUSTER; case QUERY_NODE_SHOW_CONNECTIONS_STMT: return TSDB_PERFS_TABLE_CONNECTIONS; case QUERY_NODE_SHOW_QUERIES_STMT: @@ -3173,17 +3347,25 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, c static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SSchema* pSchema, SKVRowBuilder* pBuilder) { + if(pSchema->type == TSDB_DATA_TYPE_JSON){ + if(pVal->literal && strlen(pVal->literal) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ + return buildSyntaxErrMsg(&pCxt->msgBuf, "json string too long than 4095", pVal->literal); + } + + return parseJsontoTagData(pVal->literal, pBuilder, &pCxt->msgBuf, pSchema->colId); + } + if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) { return pCxt->errCode; } - SVariant var; - valueNodeToVariant(pVal, &var); - char tagVal[TSDB_MAX_TAGS_LEN] = {0}; - int32_t code = taosVariantDump(&var, tagVal, pSchema->type, true); - if (TSDB_CODE_SUCCESS == code) { - tdAddColToKVRow(pBuilder, pSchema->colId, pSchema->type, tagVal); + + if(pVal->node.resType.type == TSDB_DATA_TYPE_NULL){ + // todo + }else{ + tdAddColToKVRow(pBuilder, pSchema->colId, &(pVal->datum.p), IS_VAR_DATA_TYPE(pSchema->type) ? varDataTLen(pVal->datum.p) : TYPE_BYTES[pSchema->type]); } - return code; + + return TSDB_CODE_SUCCESS; } static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableClause* pStmt, STableMeta* pSuperTableMeta, @@ -3360,6 +3542,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_SHOW_SNODES_STMT: case QUERY_NODE_SHOW_CONNECTIONS_STMT: case QUERY_NODE_SHOW_QUERIES_STMT: + case QUERY_NODE_SHOW_CLUSTER_STMT: code = rewriteShow(pCxt, pQuery); break; case QUERY_NODE_CREATE_TABLE_STMT: @@ -3384,6 +3567,7 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { switch (nodeType(pQuery->pRoot)) { case QUERY_NODE_SELECT_STMT: + case QUERY_NODE_SET_OPERATOR: case QUERY_NODE_EXPLAIN_STMT: pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; pQuery->haveResultSet = true; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 51e0b2a328..075caa868c 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -14,6 +14,7 @@ */ #include "parUtil.h" +#include "cJSON.h" static char* getSyntaxErrFormat(int32_t errCode) { switch (errCode) { @@ -115,6 +116,10 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "sliding value no larger than the interval value"; case TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL: return "sliding value can not less than 1% of interval value"; + case TSDB_CODE_PAR_ONLY_ONE_JSON_TAG: + return "Only one tag if there is a json tag"; + case TSDB_CODE_PAR_INCORRECT_NUM_OF_COL: + return "Query block has incorrect number of result columns"; case TSDB_CODE_OUT_OF_MEMORY: return "Out of memory"; default: @@ -215,24 +220,178 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) { } int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) { - // delete escape character: \\, \', \" + if (len <=0 || dlen <= 0) return 0; + char delim = src[0]; - int32_t cnt = 0; int32_t j = 0; for (uint32_t k = 1; k < len - 1; ++k) { if (j >= dlen) { - break; + dst[j - 1] = '\0'; + return j; } - if (src[k] == '\\' || (src[k] == delim && src[k + 1] == delim)) { + if (src[k] == delim && src[k + 1] == delim) { // deal with "", '' dst[j] = src[k + 1]; - cnt++; j++; k++; continue; } + + if (src[k] == '\\') { // deal with escape character + if(src[k+1] == 'n'){ + dst[j] = '\n'; + }else if(src[k+1] == 'r'){ + dst[j] = '\r'; + }else if(src[k+1] == 't'){ + dst[j] = '\t'; + }else if(src[k+1] == '\\'){ + dst[j] = '\\'; + }else if(src[k+1] == '\''){ + dst[j] = '\''; + }else if(src[k+1] == '"'){ + dst[j] = '"'; + }else if(src[k+1] == '%' || src[k+1] == '_'){ + dst[j++] = src[k]; + dst[j] = src[k+1]; + }else{ + dst[j] = src[k+1]; + } + j++; + k++; + continue; + } + dst[j] = src[k]; j++; } dst[j] = '\0'; return j; } + +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; + } + return true; +} + +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){ + tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); + return TSDB_CODE_SUCCESS; + } + + // set json real data + cJSON *root = cJSON_Parse(json); + if (root == NULL){ + return buildSyntaxErrMsg(pMsgBuf, "json parse error", json); + } + + int size = cJSON_GetArraySize(root); + if(!cJSON_IsObject(root)){ + return buildSyntaxErrMsg(pMsgBuf, "json error invalide value", json); + } + + int retCode = 0; + char *tagKV = NULL; + SHashObj* keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); + for(int i = 0; i < size; i++) { + cJSON* item = cJSON_GetArrayItem(root, i); + if (!item) { + qError("json inner error:%d", i); + retCode = buildSyntaxErrMsg(pMsgBuf, "json inner error", json); + goto end; + } + + 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; +// } + size_t keyLen = strlen(jsonKey); + 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) { + retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto end; + } + strncpy(varDataVal(tagKV), jsonKey, keyLen); + varDataSetLen(tagKV, keyLen); + if(taosHashGetSize(keyHash) == 0){ + uint8_t jsonNotNULL = TSDB_DATA_TYPE_JSON; + 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 + + 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) { + retCode = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto end; + } + tagKV = tmp; + char* valueType = POINTER_SHIFT(tagKV, keyLen + VARSTR_HEADER_SIZE); + 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)); + 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)){ + qError("json value is invalidate"); + 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){ + 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){ + 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{ + retCode = buildSyntaxErrMsg(pMsgBuf, "invalidate json value", json); + goto end; + } + } + + if(taosHashGetSize(keyHash) == 0){ // set json NULL true + tdAddColToKVRow(kvRowBuilder, jsonIndex, &jsonNULL, CHAR_BYTES); + } + +end: + taosMemoryFree(tagKV); + taosHashCleanup(keyHash); + cJSON_Delete(root); + return retCode; +} \ No newline at end of file diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index ebe76cc129..e2e2207c70 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -18,7 +18,11 @@ #include "parInt.h" #include "parToken.h" -static bool isInsertSql(const char* pStr, size_t length) { +bool isInsertSql(const char* pStr, size_t length) { + if (NULL == pStr) { + return false; + } + int32_t index = 0; do { @@ -68,4 +72,4 @@ void qDestroyQuery(SQuery* pQueryNode) { int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema) { return extractResultSchema(pRoot, numOfCols, pSchema); -} \ No newline at end of file +} diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index f8396dc50c..b38e4092e3 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -100,24 +100,24 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 335 +#define YYNOCODE 336 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - SNode* yy42; - EJoinType yy102; - ENullOrder yy197; - bool yy237; - int32_t yy240; - SNodeList* yy244; - EOperatorType yy270; - SDataType yy314; - SAlterOption yy325; - SToken yy359; - EOrder yy508; - EFillMode yy544; + int32_t yy4; + bool yy89; + EFillMode yy102; + SDataType yy112; + SAlterOption yy221; + ENullOrder yy361; + EJoinType yy372; + SNodeList* yy376; + EOperatorType yy380; + EOrder yy386; + SNode* yy392; + SToken yy449; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -132,17 +132,17 @@ typedef union { #define ParseCTX_PARAM #define ParseCTX_FETCH #define ParseCTX_STORE -#define YYNSTATE 570 -#define YYNRULE 435 -#define YYNTOKEN 221 -#define YY_MAX_SHIFT 569 -#define YY_MIN_SHIFTREDUCE 847 -#define YY_MAX_SHIFTREDUCE 1281 -#define YY_ERROR_ACTION 1282 -#define YY_ACCEPT_ACTION 1283 -#define YY_NO_ACTION 1284 -#define YY_MIN_REDUCE 1285 -#define YY_MAX_REDUCE 1719 +#define YYNSTATE 572 +#define YYNRULE 437 +#define YYNTOKEN 222 +#define YY_MAX_SHIFT 571 +#define YY_MIN_SHIFTREDUCE 850 +#define YY_MAX_SHIFTREDUCE 1286 +#define YY_ERROR_ACTION 1287 +#define YY_ACCEPT_ACTION 1288 +#define YY_NO_ACTION 1289 +#define YY_MIN_REDUCE 1290 +#define YY_MAX_REDUCE 1726 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -209,536 +209,553 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (1813) +#define YY_ACTTAB_COUNT (1960) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 268, 1587, 285, 53, 1571, 483, 26, 203, 467, 1385, - /* 10 */ 1283, 1557, 33, 31, 77, 1571, 99, 1557, 483, 1557, - /* 20 */ 277, 380, 1102, 442, 1402, 1553, 1560, 321, 1587, 288, - /* 30 */ 1407, 1553, 1559, 1553, 1559, 467, 1490, 1492, 1100, 1587, - /* 40 */ 124, 69, 435, 1407, 1364, 466, 467, 1384, 104, 1543, - /* 50 */ 12, 33, 31, 1224, 482, 105, 466, 1108, 359, 277, - /* 60 */ 1543, 1102, 1399, 293, 1123, 446, 1571, 241, 1572, 469, - /* 70 */ 1574, 1575, 465, 482, 460, 1, 323, 1100, 72, 1572, - /* 80 */ 469, 1574, 1575, 465, 102, 460, 562, 561, 1637, 12, - /* 90 */ 1587, 100, 249, 1633, 482, 383, 1108, 445, 566, 133, - /* 100 */ 1644, 1645, 1698, 1649, 1698, 438, 248, 466, 106, 36, - /* 110 */ 1101, 1543, 514, 483, 1, 136, 1651, 136, 386, 1696, - /* 120 */ 359, 1696, 322, 34, 32, 30, 29, 28, 36, 73, - /* 130 */ 1572, 469, 1574, 1575, 465, 517, 460, 566, 1407, 1637, - /* 140 */ 1648, 483, 483, 270, 1633, 131, 123, 1103, 1297, 1101, - /* 150 */ 330, 331, 1398, 1487, 513, 512, 511, 199, 510, 470, - /* 160 */ 145, 250, 280, 425, 1664, 1499, 1407, 1407, 1106, 1107, - /* 170 */ 1651, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 462, 1162, - /* 180 */ 1163, 1164, 1165, 1166, 1167, 1168, 1103, 1138, 1127, 34, - /* 190 */ 32, 30, 29, 28, 1647, 1186, 418, 1543, 137, 34, - /* 200 */ 32, 30, 29, 28, 523, 442, 1379, 1106, 1107, 432, - /* 210 */ 1151, 1152, 1153, 1154, 1155, 1156, 1157, 462, 1162, 1163, - /* 220 */ 1164, 1165, 1166, 1167, 1168, 33, 31, 250, 483, 483, - /* 230 */ 104, 937, 137, 277, 247, 1102, 1123, 358, 77, 317, - /* 240 */ 419, 260, 137, 338, 1187, 387, 350, 1111, 55, 266, - /* 250 */ 939, 1100, 174, 1407, 1407, 351, 34, 32, 30, 29, - /* 260 */ 28, 1186, 1192, 12, 33, 31, 102, 100, 483, 410, - /* 270 */ 1108, 383, 277, 1383, 1102, 437, 433, 291, 1698, 1698, - /* 280 */ 444, 132, 1644, 1645, 261, 1649, 259, 258, 1, 382, - /* 290 */ 1100, 136, 136, 1407, 386, 1696, 1696, 25, 275, 1181, - /* 300 */ 1182, 1183, 1184, 1185, 1189, 1190, 1191, 198, 1698, 1108, - /* 310 */ 1187, 566, 1248, 127, 34, 32, 30, 29, 28, 1114, - /* 320 */ 1238, 136, 519, 1101, 1448, 1696, 120, 7, 1192, 349, - /* 330 */ 385, 384, 344, 343, 342, 341, 340, 449, 337, 336, - /* 340 */ 335, 334, 333, 329, 328, 327, 326, 325, 324, 137, - /* 350 */ 566, 429, 1246, 1247, 1249, 1250, 30, 29, 28, 884, - /* 360 */ 1103, 883, 1101, 25, 275, 1181, 1182, 1183, 1184, 1185, - /* 370 */ 1189, 1190, 1191, 34, 32, 30, 29, 28, 1125, 885, - /* 380 */ 225, 1106, 1107, 1437, 1151, 1152, 1153, 1154, 1155, 1156, - /* 390 */ 1157, 462, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1103, - /* 400 */ 975, 506, 505, 504, 979, 503, 981, 982, 502, 984, - /* 410 */ 499, 121, 990, 496, 992, 993, 493, 490, 442, 1410, - /* 420 */ 1106, 1107, 1324, 1151, 1152, 1153, 1154, 1155, 1156, 1157, - /* 430 */ 462, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 33, 31, - /* 440 */ 1169, 1571, 1278, 104, 397, 316, 277, 315, 1102, 442, - /* 450 */ 137, 88, 394, 393, 87, 86, 85, 84, 83, 82, - /* 460 */ 81, 80, 79, 1698, 1100, 1587, 483, 34, 32, 30, - /* 470 */ 29, 28, 445, 281, 104, 1404, 1697, 33, 31, 102, - /* 480 */ 1696, 121, 466, 1108, 883, 277, 1543, 1102, 1651, 1409, - /* 490 */ 483, 1407, 436, 446, 134, 1644, 1645, 137, 1649, 1524, - /* 500 */ 378, 7, 519, 1100, 73, 1572, 469, 1574, 1575, 465, - /* 510 */ 102, 460, 1646, 1571, 1637, 1407, 522, 345, 270, 1633, - /* 520 */ 131, 1277, 1108, 401, 566, 196, 1644, 441, 1126, 440, - /* 530 */ 6, 1138, 1698, 1188, 483, 1456, 1101, 1587, 409, 1665, - /* 540 */ 7, 267, 1308, 480, 464, 136, 1454, 483, 448, 1696, - /* 550 */ 1564, 1193, 173, 53, 466, 404, 481, 22, 1543, 1407, - /* 560 */ 398, 143, 1562, 566, 147, 146, 172, 34, 32, 30, - /* 570 */ 29, 28, 1407, 1103, 1403, 1101, 245, 1572, 469, 1574, - /* 580 */ 1575, 465, 463, 460, 458, 1609, 23, 1543, 51, 165, - /* 590 */ 1571, 50, 163, 45, 1106, 1107, 44, 1151, 1152, 1153, - /* 600 */ 1154, 1155, 1156, 1157, 462, 1162, 1163, 1164, 1165, 1166, - /* 610 */ 1167, 1168, 1103, 24, 1587, 450, 9, 8, 534, 516, - /* 620 */ 515, 467, 311, 34, 32, 30, 29, 28, 1307, 535, - /* 630 */ 533, 466, 1223, 1106, 1107, 1543, 1151, 1152, 1153, 1154, - /* 640 */ 1155, 1156, 1157, 462, 1162, 1163, 1164, 1165, 1166, 1167, - /* 650 */ 1168, 33, 31, 73, 1572, 469, 1574, 1575, 465, 277, - /* 660 */ 460, 1102, 1571, 1637, 1456, 483, 308, 270, 1633, 1710, - /* 670 */ 282, 287, 290, 1543, 217, 1454, 1306, 1100, 1671, 121, - /* 680 */ 121, 1491, 1492, 62, 1219, 310, 1587, 1409, 1409, 1456, - /* 690 */ 1407, 1200, 470, 467, 1124, 289, 1108, 1305, 1500, 396, - /* 700 */ 1454, 390, 1304, 466, 1400, 395, 1303, 1543, 101, 1319, - /* 710 */ 391, 389, 1571, 392, 1, 453, 1302, 509, 388, 1301, - /* 720 */ 1300, 1543, 1299, 1296, 417, 73, 1572, 469, 1574, 1575, - /* 730 */ 465, 399, 460, 1396, 1456, 1637, 1587, 566, 1231, 270, - /* 740 */ 1633, 1710, 1543, 467, 1125, 1455, 569, 1543, 1295, 1101, - /* 750 */ 1694, 1543, 1294, 466, 1293, 1128, 1174, 1543, 1292, 451, - /* 760 */ 221, 1543, 1125, 98, 1543, 1543, 1532, 1543, 1543, 558, - /* 770 */ 1317, 554, 550, 546, 220, 73, 1572, 469, 1574, 1575, - /* 780 */ 465, 1291, 460, 1290, 1289, 1637, 1103, 1334, 1288, 270, - /* 790 */ 1633, 1710, 402, 1543, 1656, 1219, 408, 1543, 1110, 1543, - /* 800 */ 1655, 70, 300, 1543, 215, 9, 8, 1106, 1107, 406, - /* 810 */ 1151, 1152, 1153, 1154, 1155, 1156, 1157, 462, 1162, 1163, - /* 820 */ 1164, 1165, 1166, 1167, 1168, 1392, 1543, 1222, 1543, 1543, - /* 830 */ 1088, 1089, 167, 1543, 479, 166, 1571, 1280, 1281, 542, - /* 840 */ 541, 540, 539, 292, 1394, 538, 537, 536, 107, 531, - /* 850 */ 530, 529, 528, 527, 526, 525, 524, 114, 520, 122, - /* 860 */ 1587, 454, 424, 1382, 231, 180, 1571, 467, 169, 171, - /* 870 */ 1113, 168, 170, 457, 184, 112, 229, 466, 1390, 421, - /* 880 */ 1080, 1543, 176, 47, 187, 68, 446, 1245, 189, 148, - /* 890 */ 1587, 1286, 35, 177, 35, 64, 1194, 467, 1158, 238, - /* 900 */ 1572, 469, 1574, 1575, 465, 35, 460, 466, 909, 1063, - /* 910 */ 206, 1543, 88, 461, 208, 87, 86, 85, 84, 83, - /* 920 */ 82, 81, 80, 79, 106, 1698, 508, 910, 514, 74, - /* 930 */ 1572, 469, 1574, 1575, 465, 1285, 460, 109, 136, 1637, - /* 940 */ 1298, 475, 1696, 1636, 1633, 110, 112, 1365, 47, 214, - /* 950 */ 968, 517, 963, 71, 488, 1571, 200, 430, 996, 97, - /* 960 */ 96, 95, 94, 93, 92, 91, 90, 89, 411, 110, - /* 970 */ 513, 512, 511, 1000, 510, 1449, 111, 193, 377, 1587, - /* 980 */ 1007, 49, 48, 320, 112, 142, 467, 1667, 1006, 110, - /* 990 */ 314, 1178, 443, 113, 1588, 202, 466, 2, 1123, 295, - /* 1000 */ 1543, 299, 256, 1571, 306, 255, 302, 298, 139, 937, - /* 1010 */ 257, 1072, 1571, 222, 332, 1489, 144, 339, 74, 1572, - /* 1020 */ 469, 1574, 1575, 465, 346, 460, 347, 1587, 1637, 348, - /* 1030 */ 1102, 352, 456, 1633, 467, 1132, 1587, 353, 149, 137, - /* 1040 */ 1131, 152, 354, 467, 466, 355, 1100, 356, 1543, 357, - /* 1050 */ 1130, 155, 1129, 466, 379, 360, 52, 1543, 158, 78, - /* 1060 */ 265, 381, 1397, 162, 1571, 1108, 125, 1572, 469, 1574, - /* 1070 */ 1575, 465, 1571, 460, 1108, 74, 1572, 469, 1574, 1575, - /* 1080 */ 465, 223, 460, 1393, 164, 1637, 1528, 115, 1587, 175, - /* 1090 */ 1634, 116, 1395, 1391, 117, 467, 1587, 118, 412, 413, - /* 1100 */ 420, 179, 1571, 467, 182, 466, 566, 416, 422, 1543, - /* 1110 */ 447, 1711, 426, 466, 1128, 431, 423, 1543, 1101, 1678, - /* 1120 */ 473, 185, 1677, 1668, 428, 269, 1587, 246, 1572, 469, - /* 1130 */ 1574, 1575, 465, 467, 460, 125, 1572, 469, 1574, 1575, - /* 1140 */ 465, 188, 460, 466, 5, 439, 434, 1543, 427, 192, - /* 1150 */ 274, 1658, 4, 1219, 1571, 1103, 103, 1127, 37, 271, - /* 1160 */ 455, 1695, 195, 452, 129, 246, 1572, 469, 1574, 1575, - /* 1170 */ 465, 1652, 460, 194, 16, 1498, 1106, 1107, 1587, 1618, - /* 1180 */ 1712, 1497, 201, 471, 476, 464, 1713, 472, 279, 477, - /* 1190 */ 478, 210, 212, 224, 63, 466, 61, 1408, 1380, 1543, - /* 1200 */ 160, 486, 226, 130, 1571, 219, 128, 565, 43, 376, - /* 1210 */ 232, 372, 368, 364, 159, 1571, 233, 245, 1572, 469, - /* 1220 */ 1574, 1575, 465, 228, 460, 230, 1610, 294, 1587, 1537, - /* 1230 */ 1536, 1533, 296, 297, 1096, 467, 1097, 140, 301, 1587, - /* 1240 */ 303, 54, 1531, 304, 157, 466, 467, 305, 1530, 1543, - /* 1250 */ 307, 1529, 276, 1571, 309, 1514, 466, 141, 312, 313, - /* 1260 */ 1543, 1074, 1075, 278, 1508, 1507, 318, 246, 1572, 469, - /* 1270 */ 1574, 1575, 465, 319, 460, 1506, 1505, 1587, 246, 1572, - /* 1280 */ 469, 1574, 1575, 465, 467, 460, 1482, 1046, 1481, 1480, - /* 1290 */ 1479, 1478, 1477, 1476, 466, 1475, 1474, 1473, 1543, 1472, - /* 1300 */ 1571, 156, 1471, 151, 1470, 153, 1469, 1468, 1467, 108, - /* 1310 */ 1466, 1465, 1464, 1571, 1463, 1462, 234, 1572, 469, 1574, - /* 1320 */ 1575, 465, 150, 460, 1587, 1048, 1460, 1459, 1571, 1461, - /* 1330 */ 1458, 467, 1457, 1336, 1522, 1516, 1504, 1587, 902, 1335, - /* 1340 */ 1333, 466, 1495, 154, 467, 1543, 1386, 361, 363, 362, - /* 1350 */ 1331, 1329, 1587, 76, 466, 365, 366, 369, 1543, 467, - /* 1360 */ 370, 367, 1327, 240, 1572, 469, 1574, 1575, 465, 466, - /* 1370 */ 460, 371, 1316, 1543, 375, 1571, 242, 1572, 469, 1574, - /* 1380 */ 1575, 465, 373, 460, 374, 1315, 1312, 1388, 532, 1012, - /* 1390 */ 1571, 235, 1572, 469, 1574, 1575, 465, 1015, 460, 1587, - /* 1400 */ 262, 936, 935, 1571, 161, 1387, 467, 934, 933, 534, - /* 1410 */ 1325, 932, 929, 928, 1587, 263, 466, 1320, 400, 1318, - /* 1420 */ 1543, 467, 403, 264, 1311, 405, 1310, 1587, 407, 75, - /* 1430 */ 1521, 466, 1082, 46, 467, 1543, 1515, 119, 243, 1572, - /* 1440 */ 469, 1574, 1575, 465, 466, 460, 1503, 414, 1543, 1502, - /* 1450 */ 1494, 1571, 56, 236, 1572, 469, 1574, 1575, 465, 181, - /* 1460 */ 460, 3, 415, 35, 1571, 13, 244, 1572, 469, 1574, - /* 1470 */ 1575, 465, 186, 460, 41, 1587, 14, 178, 38, 191, - /* 1480 */ 1244, 183, 467, 126, 40, 1562, 190, 20, 1587, 1237, - /* 1490 */ 1216, 58, 466, 57, 21, 467, 1543, 1215, 1266, 39, - /* 1500 */ 11, 15, 1571, 1265, 272, 466, 1270, 197, 1271, 1543, - /* 1510 */ 135, 1269, 273, 8, 237, 1572, 469, 1574, 1575, 465, - /* 1520 */ 1179, 460, 459, 17, 1161, 138, 1587, 1583, 1572, 469, - /* 1530 */ 1574, 1575, 465, 467, 460, 1160, 27, 1146, 1159, 10, - /* 1540 */ 204, 468, 18, 466, 19, 1493, 205, 1543, 1242, 1571, - /* 1550 */ 207, 209, 59, 211, 60, 1118, 64, 42, 487, 997, - /* 1560 */ 286, 489, 1571, 491, 485, 1582, 1572, 469, 1574, 1575, - /* 1570 */ 465, 474, 460, 1587, 213, 1561, 216, 1571, 994, 492, - /* 1580 */ 467, 991, 494, 495, 497, 985, 1587, 498, 500, 983, - /* 1590 */ 466, 501, 989, 467, 1543, 988, 987, 986, 974, 65, - /* 1600 */ 1009, 1587, 507, 466, 1008, 66, 67, 1543, 467, 1005, - /* 1610 */ 1002, 900, 1581, 1572, 469, 1574, 1575, 465, 466, 460, - /* 1620 */ 518, 925, 1543, 943, 1571, 253, 1572, 469, 1574, 1575, - /* 1630 */ 465, 521, 460, 218, 923, 922, 921, 920, 919, 1571, - /* 1640 */ 252, 1572, 469, 1574, 1575, 465, 918, 460, 1587, 917, - /* 1650 */ 916, 940, 1571, 938, 913, 467, 284, 283, 912, 911, - /* 1660 */ 908, 907, 906, 1587, 905, 466, 1116, 1332, 543, 1543, - /* 1670 */ 467, 544, 545, 1330, 547, 548, 1587, 1337, 1328, 551, - /* 1680 */ 466, 549, 1109, 467, 1543, 552, 553, 254, 1572, 469, - /* 1690 */ 1574, 1575, 465, 466, 460, 1326, 555, 1543, 556, 557, - /* 1700 */ 1314, 1108, 251, 1572, 469, 1574, 1575, 465, 559, 460, - /* 1710 */ 1313, 560, 1309, 563, 564, 239, 1572, 469, 1574, 1575, - /* 1720 */ 465, 1104, 460, 227, 567, 568, 1284, 1284, 1284, 396, - /* 1730 */ 1284, 390, 1284, 1284, 1284, 395, 1284, 1284, 101, 1284, - /* 1740 */ 391, 389, 484, 392, 1284, 1284, 1284, 1284, 388, 1284, - /* 1750 */ 1284, 1284, 1284, 1284, 1112, 1284, 1284, 1284, 1284, 1284, - /* 1760 */ 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, - /* 1770 */ 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, - /* 1780 */ 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, - /* 1790 */ 1284, 1117, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, - /* 1800 */ 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, 1284, - /* 1810 */ 1284, 1284, 1120, + /* 0 */ 270, 1593, 287, 472, 1577, 485, 282, 325, 469, 1505, + /* 10 */ 1288, 1401, 33, 31, 78, 1577, 124, 1563, 1302, 1563, + /* 20 */ 279, 383, 1106, 34, 32, 30, 29, 28, 1593, 1563, + /* 30 */ 1412, 1559, 1565, 1559, 1565, 469, 125, 250, 1104, 1593, + /* 40 */ 1369, 1705, 438, 1559, 1566, 468, 469, 1389, 445, 1549, + /* 50 */ 12, 33, 31, 1228, 1704, 54, 468, 1112, 1702, 279, + /* 60 */ 1549, 1106, 484, 295, 319, 449, 1577, 243, 1578, 471, + /* 70 */ 1580, 1581, 467, 105, 462, 1, 1408, 1104, 73, 1578, + /* 80 */ 471, 1580, 1581, 467, 525, 462, 1384, 290, 1643, 12, + /* 90 */ 1593, 484, 251, 1639, 1496, 1498, 1112, 448, 568, 26, + /* 100 */ 205, 362, 1705, 1705, 1705, 441, 421, 468, 107, 103, + /* 110 */ 1105, 1549, 516, 485, 1, 137, 137, 137, 1129, 1702, + /* 120 */ 1702, 1702, 323, 447, 133, 1650, 1651, 445, 1655, 74, + /* 130 */ 1578, 471, 1580, 1581, 467, 519, 462, 568, 1412, 1643, + /* 140 */ 54, 144, 485, 272, 1639, 132, 36, 940, 1107, 1105, + /* 150 */ 422, 324, 105, 100, 515, 514, 513, 201, 512, 1127, + /* 160 */ 439, 1407, 1130, 428, 1670, 435, 942, 1412, 52, 1110, + /* 170 */ 1111, 51, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 464, + /* 180 */ 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1107, 103, 1705, + /* 190 */ 1461, 34, 32, 30, 29, 28, 269, 9, 8, 138, + /* 200 */ 69, 1459, 137, 134, 1650, 1651, 1702, 1655, 1110, 1111, + /* 210 */ 65, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 464, 1166, + /* 220 */ 1167, 1168, 1169, 1170, 1171, 1172, 33, 31, 138, 252, + /* 230 */ 227, 440, 436, 1442, 279, 249, 1106, 1127, 1577, 399, + /* 240 */ 63, 393, 521, 1461, 341, 398, 70, 353, 102, 284, + /* 250 */ 394, 392, 1104, 395, 1459, 1142, 354, 318, 391, 317, + /* 260 */ 106, 1405, 1593, 1190, 12, 33, 31, 1404, 1227, 469, + /* 270 */ 138, 1112, 1204, 279, 22, 1106, 1657, 56, 268, 468, + /* 280 */ 1252, 175, 24, 1549, 34, 32, 30, 29, 28, 1, + /* 290 */ 1657, 1104, 34, 32, 30, 29, 28, 30, 29, 28, + /* 300 */ 1654, 74, 1578, 471, 1580, 1581, 467, 128, 462, 138, + /* 310 */ 1112, 1643, 568, 1191, 1653, 272, 1639, 1717, 1453, 432, + /* 320 */ 1250, 1251, 1253, 1254, 1105, 413, 1677, 1390, 7, 1290, + /* 330 */ 352, 1196, 1128, 347, 346, 345, 344, 343, 138, 340, + /* 340 */ 339, 338, 337, 336, 332, 331, 330, 329, 328, 327, + /* 350 */ 326, 568, 59, 98, 97, 96, 95, 94, 93, 92, + /* 360 */ 91, 90, 1107, 1105, 1705, 1705, 25, 277, 1185, 1186, + /* 370 */ 1187, 1188, 1189, 1193, 1194, 1195, 362, 137, 1703, 1403, + /* 380 */ 1131, 1702, 1702, 1110, 1111, 6, 1155, 1156, 1157, 1158, + /* 390 */ 1159, 1160, 1161, 464, 1166, 1167, 1168, 1169, 1170, 1171, + /* 400 */ 1172, 1107, 524, 484, 452, 34, 32, 30, 29, 28, + /* 410 */ 89, 564, 563, 88, 87, 86, 85, 84, 83, 82, + /* 420 */ 81, 80, 1110, 1111, 1549, 1155, 1156, 1157, 1158, 1159, + /* 430 */ 1160, 1161, 464, 1166, 1167, 1168, 1169, 1170, 1171, 1172, + /* 440 */ 33, 31, 1173, 252, 1291, 536, 1313, 283, 279, 313, + /* 450 */ 1106, 289, 138, 485, 472, 122, 262, 101, 36, 122, + /* 460 */ 1506, 386, 333, 1414, 1226, 89, 1104, 1414, 88, 87, + /* 470 */ 86, 85, 84, 83, 82, 81, 80, 1190, 1412, 33, + /* 480 */ 31, 48, 101, 1387, 389, 1112, 386, 279, 1312, 1106, + /* 490 */ 1577, 1549, 34, 32, 30, 29, 28, 485, 485, 263, + /* 500 */ 200, 261, 260, 7, 385, 1104, 78, 334, 511, 389, + /* 510 */ 388, 387, 292, 390, 1593, 34, 32, 30, 29, 28, + /* 520 */ 122, 469, 1412, 1412, 1112, 485, 568, 1191, 1414, 1311, + /* 530 */ 1461, 468, 1493, 1549, 361, 1549, 291, 485, 1105, 146, + /* 540 */ 1223, 1459, 7, 1192, 107, 1196, 1409, 138, 516, 453, + /* 550 */ 1412, 397, 396, 74, 1578, 471, 1580, 1581, 467, 1461, + /* 560 */ 462, 1197, 1412, 1643, 1342, 568, 1132, 272, 1639, 1717, + /* 570 */ 1460, 519, 348, 1397, 1549, 1657, 1107, 1105, 1700, 1242, + /* 580 */ 25, 277, 1185, 1186, 1187, 1188, 1189, 1193, 1194, 1195, + /* 590 */ 515, 514, 513, 1577, 512, 1538, 23, 1110, 1111, 1652, + /* 600 */ 1155, 1156, 1157, 1158, 1159, 1160, 1161, 464, 1166, 1167, + /* 610 */ 1168, 1169, 1170, 1171, 1172, 1107, 399, 1593, 393, 148, + /* 620 */ 147, 1283, 398, 1310, 448, 102, 166, 394, 392, 164, + /* 630 */ 395, 302, 518, 517, 468, 391, 1110, 1111, 1549, 1155, + /* 640 */ 1156, 1157, 1158, 1159, 1160, 1161, 464, 1166, 1167, 1168, + /* 650 */ 1169, 1170, 1171, 1172, 33, 31, 74, 1578, 471, 1580, + /* 660 */ 1581, 467, 279, 462, 1106, 1577, 1643, 1388, 1549, 485, + /* 670 */ 272, 1639, 132, 34, 32, 30, 29, 28, 1530, 485, + /* 680 */ 1104, 1309, 122, 485, 445, 887, 186, 886, 482, 1593, + /* 690 */ 1415, 1671, 293, 451, 1412, 1399, 469, 537, 535, 1112, + /* 700 */ 1282, 1235, 485, 886, 1412, 888, 468, 1129, 1412, 105, + /* 710 */ 1549, 483, 485, 1308, 1307, 310, 521, 1, 1339, 381, + /* 720 */ 1306, 219, 1305, 1304, 1301, 1395, 1549, 1412, 74, 1578, + /* 730 */ 471, 1580, 1581, 467, 312, 462, 168, 1412, 1643, 167, + /* 740 */ 568, 455, 272, 1639, 1717, 103, 34, 32, 30, 29, + /* 750 */ 28, 1300, 1105, 1661, 1299, 1298, 178, 1297, 1549, 1549, + /* 760 */ 135, 1650, 1651, 1296, 1655, 1549, 459, 1549, 1549, 1549, + /* 770 */ 544, 543, 542, 541, 294, 463, 540, 539, 538, 108, + /* 780 */ 533, 532, 531, 530, 529, 528, 527, 526, 115, 522, + /* 790 */ 1107, 1178, 1497, 1498, 1662, 1223, 1549, 1129, 510, 1549, + /* 800 */ 1549, 121, 1549, 1295, 1092, 1093, 1294, 1293, 1549, 113, + /* 810 */ 1142, 1110, 1111, 424, 1155, 1156, 1157, 1158, 1159, 1160, + /* 820 */ 1161, 464, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1570, + /* 830 */ 978, 508, 507, 506, 982, 505, 984, 985, 504, 987, + /* 840 */ 501, 1568, 993, 498, 995, 996, 495, 492, 1549, 123, + /* 850 */ 1577, 1549, 1549, 170, 233, 1329, 169, 172, 1324, 411, + /* 860 */ 171, 1322, 1115, 1577, 47, 189, 231, 420, 1249, 191, + /* 870 */ 9, 8, 409, 1114, 1593, 1285, 1286, 400, 35, 149, + /* 880 */ 402, 469, 1198, 405, 1303, 1182, 35, 1593, 456, 35, + /* 890 */ 1162, 468, 208, 1067, 469, 1549, 210, 110, 1370, 111, + /* 900 */ 449, 477, 113, 216, 468, 47, 971, 202, 1549, 966, + /* 910 */ 433, 1454, 414, 240, 1578, 471, 1580, 1581, 467, 490, + /* 920 */ 462, 111, 195, 999, 380, 1003, 75, 1578, 471, 1580, + /* 930 */ 1581, 467, 446, 462, 1118, 1673, 1643, 1594, 112, 1705, + /* 940 */ 1642, 1639, 1010, 72, 1577, 1117, 204, 912, 2, 301, + /* 950 */ 161, 113, 137, 131, 111, 1009, 1702, 1127, 114, 379, + /* 960 */ 297, 375, 371, 367, 160, 257, 913, 259, 1593, 940, + /* 970 */ 224, 335, 50, 49, 322, 469, 143, 1495, 1076, 342, + /* 980 */ 145, 316, 350, 349, 351, 468, 355, 1136, 356, 1549, + /* 990 */ 150, 55, 357, 258, 158, 308, 1577, 304, 300, 140, + /* 1000 */ 1135, 358, 153, 359, 1134, 360, 156, 75, 1578, 471, + /* 1010 */ 1580, 1581, 467, 53, 462, 363, 159, 1643, 1133, 571, + /* 1020 */ 1593, 458, 1639, 382, 384, 1402, 79, 466, 163, 267, + /* 1030 */ 138, 1398, 1112, 223, 165, 116, 99, 468, 117, 1400, + /* 1040 */ 1396, 1549, 560, 118, 556, 552, 548, 222, 119, 176, + /* 1050 */ 225, 1577, 157, 415, 152, 423, 154, 1534, 179, 247, + /* 1060 */ 1578, 471, 1580, 1581, 467, 465, 462, 460, 1615, 419, + /* 1070 */ 181, 425, 426, 151, 71, 1593, 416, 217, 1132, 434, + /* 1080 */ 184, 187, 469, 1684, 475, 1674, 431, 1683, 5, 190, + /* 1090 */ 442, 271, 468, 437, 430, 4, 1549, 1223, 104, 1131, + /* 1100 */ 1577, 273, 37, 1720, 457, 454, 197, 481, 1658, 1664, + /* 1110 */ 16, 473, 1624, 474, 126, 1578, 471, 1580, 1581, 467, + /* 1120 */ 194, 462, 130, 1504, 1593, 196, 478, 1503, 226, 212, + /* 1130 */ 281, 469, 479, 214, 480, 62, 427, 1701, 203, 182, + /* 1140 */ 1413, 468, 64, 488, 221, 1549, 1385, 228, 567, 129, + /* 1150 */ 230, 234, 1577, 43, 1084, 235, 177, 232, 450, 1718, + /* 1160 */ 445, 1543, 1542, 75, 1578, 471, 1580, 1581, 467, 296, + /* 1170 */ 462, 1539, 298, 1643, 299, 1100, 1593, 1101, 1640, 141, + /* 1180 */ 303, 1537, 1577, 469, 305, 105, 306, 307, 1536, 309, + /* 1190 */ 1535, 1520, 311, 468, 142, 314, 315, 1549, 1079, 1078, + /* 1200 */ 429, 1514, 1513, 320, 449, 321, 1593, 1512, 1511, 1050, + /* 1210 */ 1488, 1487, 1486, 469, 109, 248, 1578, 471, 1580, 1581, + /* 1220 */ 467, 103, 462, 468, 1485, 1484, 1483, 1549, 1482, 1481, + /* 1230 */ 1480, 1479, 1478, 1577, 1477, 1476, 198, 1650, 444, 1475, + /* 1240 */ 443, 1474, 1473, 1705, 1472, 126, 1578, 471, 1580, 1581, + /* 1250 */ 467, 1471, 462, 1470, 1469, 1468, 137, 1593, 1467, 1466, + /* 1260 */ 1702, 1465, 1052, 1577, 469, 1464, 1463, 1462, 1341, 1528, + /* 1270 */ 1522, 1510, 1501, 1391, 468, 162, 155, 1340, 1549, 1338, + /* 1280 */ 1336, 276, 365, 364, 369, 368, 366, 1593, 905, 1334, + /* 1290 */ 1719, 1577, 370, 374, 466, 372, 248, 1578, 471, 1580, + /* 1300 */ 1581, 467, 1332, 462, 468, 378, 1321, 1320, 1549, 1317, + /* 1310 */ 373, 1393, 1015, 1392, 1018, 1593, 376, 377, 1330, 264, + /* 1320 */ 77, 939, 469, 938, 534, 937, 247, 1578, 471, 1580, + /* 1330 */ 1581, 467, 468, 462, 936, 1616, 1549, 935, 932, 278, + /* 1340 */ 1577, 931, 286, 285, 1325, 1323, 265, 403, 266, 1106, + /* 1350 */ 406, 1316, 1120, 408, 248, 1578, 471, 1580, 1581, 467, + /* 1360 */ 536, 462, 1315, 410, 1593, 1104, 76, 1527, 1113, 1521, + /* 1370 */ 1086, 469, 120, 1509, 417, 180, 1508, 1500, 1577, 57, + /* 1380 */ 183, 468, 3, 13, 1112, 1549, 35, 1112, 280, 1577, + /* 1390 */ 14, 188, 41, 1248, 127, 38, 46, 192, 185, 11, + /* 1400 */ 418, 1241, 1593, 248, 1578, 471, 1580, 1581, 467, 469, + /* 1410 */ 462, 1220, 193, 1593, 20, 1568, 199, 58, 1271, 468, + /* 1420 */ 469, 21, 40, 1549, 1219, 568, 39, 15, 486, 1276, + /* 1430 */ 468, 1270, 274, 1275, 1549, 1274, 275, 1105, 8, 1577, + /* 1440 */ 1116, 236, 1578, 471, 1580, 1581, 467, 136, 462, 461, + /* 1450 */ 17, 1165, 242, 1578, 471, 1580, 1581, 467, 1164, 462, + /* 1460 */ 1183, 27, 10, 1593, 1163, 18, 139, 1150, 206, 470, + /* 1470 */ 469, 19, 476, 1499, 209, 1107, 207, 1246, 1121, 211, + /* 1480 */ 468, 60, 213, 61, 1549, 215, 42, 65, 1122, 1577, + /* 1490 */ 1567, 1000, 489, 288, 218, 487, 1110, 1111, 491, 1124, + /* 1500 */ 1577, 997, 244, 1578, 471, 1580, 1581, 467, 493, 462, + /* 1510 */ 494, 977, 496, 1593, 994, 497, 499, 988, 500, 502, + /* 1520 */ 469, 992, 986, 503, 1593, 509, 991, 990, 989, 1012, + /* 1530 */ 468, 469, 66, 67, 1549, 68, 1008, 1005, 903, 1011, + /* 1540 */ 520, 468, 928, 946, 523, 1549, 926, 220, 1577, 925, + /* 1550 */ 924, 923, 237, 1578, 471, 1580, 1581, 467, 922, 462, + /* 1560 */ 921, 1577, 404, 245, 1578, 471, 1580, 1581, 467, 920, + /* 1570 */ 462, 919, 1593, 943, 941, 916, 915, 412, 914, 469, + /* 1580 */ 911, 910, 909, 908, 1337, 1593, 545, 546, 1335, 468, + /* 1590 */ 547, 174, 469, 1549, 407, 549, 550, 551, 1333, 401, + /* 1600 */ 553, 554, 468, 1331, 555, 173, 1549, 557, 558, 559, + /* 1610 */ 1319, 238, 1578, 471, 1580, 1581, 467, 561, 462, 562, + /* 1620 */ 1318, 1314, 565, 566, 246, 1578, 471, 1580, 1581, 467, + /* 1630 */ 1577, 462, 45, 1108, 229, 44, 569, 570, 1289, 1577, + /* 1640 */ 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1650 */ 1289, 1289, 1289, 1289, 1593, 1289, 1289, 1289, 1289, 1289, + /* 1660 */ 1289, 469, 1289, 1593, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1670 */ 469, 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, 1289, + /* 1680 */ 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, 1289, 1577, + /* 1690 */ 1289, 1289, 1289, 239, 1578, 471, 1580, 1581, 467, 1289, + /* 1700 */ 462, 1289, 1589, 1578, 471, 1580, 1581, 467, 1289, 462, + /* 1710 */ 1289, 1289, 1289, 1593, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1720 */ 469, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1730 */ 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, 1289, 1577, + /* 1740 */ 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1750 */ 1577, 1289, 1588, 1578, 471, 1580, 1581, 467, 1289, 462, + /* 1760 */ 1289, 1289, 1289, 1593, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1770 */ 469, 1289, 1289, 1289, 1593, 1289, 1289, 1289, 1289, 1289, + /* 1780 */ 468, 469, 1289, 1289, 1549, 1289, 1289, 1289, 1289, 1289, + /* 1790 */ 1289, 468, 1289, 1289, 1289, 1549, 1289, 1289, 1577, 1289, + /* 1800 */ 1289, 1289, 1587, 1578, 471, 1580, 1581, 467, 1289, 462, + /* 1810 */ 1289, 1577, 1289, 255, 1578, 471, 1580, 1581, 467, 1289, + /* 1820 */ 462, 1289, 1593, 1289, 1289, 1289, 1289, 1289, 1289, 469, + /* 1830 */ 1289, 1289, 1289, 1289, 1289, 1593, 1289, 1289, 1289, 468, + /* 1840 */ 1289, 1289, 469, 1549, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1850 */ 1289, 1289, 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, + /* 1860 */ 1289, 254, 1578, 471, 1580, 1581, 467, 1289, 462, 1289, + /* 1870 */ 1289, 1289, 1289, 1289, 256, 1578, 471, 1580, 1581, 467, + /* 1880 */ 1577, 462, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1577, + /* 1890 */ 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1900 */ 1289, 1289, 1289, 1289, 1593, 1289, 1289, 1289, 1289, 1289, + /* 1910 */ 1289, 469, 1289, 1593, 1289, 1289, 1289, 1289, 1289, 1289, + /* 1920 */ 469, 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, 1289, + /* 1930 */ 468, 1289, 1289, 1289, 1549, 1289, 1289, 1289, 1289, 1289, + /* 1940 */ 1289, 1289, 1289, 253, 1578, 471, 1580, 1581, 467, 1289, + /* 1950 */ 462, 1289, 241, 1578, 471, 1580, 1581, 467, 1289, 462, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 252, 248, 252, 232, 224, 230, 298, 299, 255, 0, - /* 10 */ 221, 269, 12, 13, 239, 224, 245, 269, 230, 269, - /* 20 */ 20, 246, 22, 230, 253, 283, 284, 239, 248, 257, - /* 30 */ 255, 283, 284, 283, 284, 255, 264, 265, 38, 248, - /* 40 */ 233, 229, 289, 255, 237, 265, 255, 0, 255, 269, - /* 50 */ 50, 12, 13, 14, 20, 243, 265, 57, 49, 20, - /* 60 */ 269, 22, 250, 274, 20, 274, 224, 287, 288, 289, - /* 70 */ 290, 291, 292, 20, 294, 75, 230, 38, 287, 288, - /* 80 */ 289, 290, 291, 292, 291, 294, 227, 228, 297, 50, - /* 90 */ 248, 61, 301, 302, 20, 65, 57, 255, 98, 306, - /* 100 */ 307, 308, 313, 310, 313, 325, 260, 265, 61, 75, - /* 110 */ 110, 269, 65, 230, 75, 326, 285, 326, 88, 330, - /* 120 */ 49, 330, 239, 12, 13, 14, 15, 16, 75, 287, - /* 130 */ 288, 289, 290, 291, 292, 88, 294, 98, 255, 297, - /* 140 */ 309, 230, 230, 301, 302, 303, 223, 147, 225, 110, - /* 150 */ 239, 239, 224, 255, 107, 108, 109, 315, 111, 265, - /* 160 */ 262, 50, 268, 321, 322, 271, 255, 255, 168, 169, - /* 170 */ 285, 171, 172, 173, 174, 175, 176, 177, 178, 179, - /* 180 */ 180, 181, 182, 183, 184, 185, 147, 76, 20, 12, - /* 190 */ 13, 14, 15, 16, 309, 84, 230, 269, 198, 12, - /* 200 */ 13, 14, 15, 16, 236, 230, 238, 168, 169, 137, - /* 210 */ 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, - /* 220 */ 181, 182, 183, 184, 185, 12, 13, 50, 230, 230, - /* 230 */ 255, 38, 198, 20, 18, 22, 20, 239, 239, 274, - /* 240 */ 274, 35, 198, 27, 133, 246, 30, 38, 156, 157, - /* 250 */ 57, 38, 160, 255, 255, 39, 12, 13, 14, 15, - /* 260 */ 16, 84, 151, 50, 12, 13, 291, 61, 230, 274, - /* 270 */ 57, 65, 20, 0, 22, 203, 204, 239, 313, 313, - /* 280 */ 305, 306, 307, 308, 78, 310, 80, 81, 75, 83, - /* 290 */ 38, 326, 326, 255, 88, 330, 330, 186, 187, 188, - /* 300 */ 189, 190, 191, 192, 193, 194, 195, 139, 313, 57, - /* 310 */ 133, 98, 168, 247, 12, 13, 14, 15, 16, 110, - /* 320 */ 76, 326, 49, 110, 258, 330, 139, 75, 151, 113, - /* 330 */ 234, 235, 116, 117, 118, 119, 120, 3, 122, 123, - /* 340 */ 124, 125, 126, 127, 128, 129, 130, 131, 132, 198, - /* 350 */ 98, 207, 208, 209, 210, 211, 14, 15, 16, 20, - /* 360 */ 147, 22, 110, 186, 187, 188, 189, 190, 191, 192, - /* 370 */ 193, 194, 195, 12, 13, 14, 15, 16, 20, 40, - /* 380 */ 241, 168, 169, 244, 171, 172, 173, 174, 175, 176, - /* 390 */ 177, 178, 179, 180, 181, 182, 183, 184, 185, 147, - /* 400 */ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, - /* 410 */ 99, 248, 101, 102, 103, 104, 105, 106, 230, 256, - /* 420 */ 168, 169, 0, 171, 172, 173, 174, 175, 176, 177, - /* 430 */ 178, 179, 180, 181, 182, 183, 184, 185, 12, 13, - /* 440 */ 14, 224, 140, 255, 22, 146, 20, 148, 22, 230, - /* 450 */ 198, 21, 234, 235, 24, 25, 26, 27, 28, 29, - /* 460 */ 30, 31, 32, 313, 38, 248, 230, 12, 13, 14, - /* 470 */ 15, 16, 255, 240, 255, 239, 326, 12, 13, 291, - /* 480 */ 330, 248, 265, 57, 22, 20, 269, 22, 285, 256, - /* 490 */ 230, 255, 20, 274, 306, 307, 308, 198, 310, 239, - /* 500 */ 38, 75, 49, 38, 287, 288, 289, 290, 291, 292, - /* 510 */ 291, 294, 309, 224, 297, 255, 57, 67, 301, 302, - /* 520 */ 303, 219, 57, 4, 98, 306, 307, 308, 20, 310, - /* 530 */ 43, 76, 313, 133, 230, 248, 110, 248, 19, 322, - /* 540 */ 75, 254, 224, 239, 255, 326, 259, 230, 214, 330, - /* 550 */ 75, 151, 33, 232, 265, 36, 239, 2, 269, 255, - /* 560 */ 41, 47, 87, 98, 114, 115, 47, 12, 13, 14, - /* 570 */ 15, 16, 255, 147, 253, 110, 287, 288, 289, 290, - /* 580 */ 291, 292, 293, 294, 295, 296, 186, 269, 74, 79, - /* 590 */ 224, 77, 82, 74, 168, 169, 77, 171, 172, 173, - /* 600 */ 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, - /* 610 */ 184, 185, 147, 2, 248, 72, 1, 2, 72, 234, - /* 620 */ 235, 255, 76, 12, 13, 14, 15, 16, 224, 234, - /* 630 */ 235, 265, 4, 168, 169, 269, 171, 172, 173, 174, - /* 640 */ 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, - /* 650 */ 185, 12, 13, 287, 288, 289, 290, 291, 292, 20, - /* 660 */ 294, 22, 224, 297, 248, 230, 143, 301, 302, 303, - /* 670 */ 254, 240, 240, 269, 239, 259, 224, 38, 312, 248, - /* 680 */ 248, 264, 265, 229, 197, 162, 248, 256, 256, 248, - /* 690 */ 255, 76, 265, 255, 20, 254, 57, 224, 271, 52, - /* 700 */ 259, 54, 224, 265, 250, 58, 224, 269, 61, 0, - /* 710 */ 63, 64, 224, 66, 75, 72, 224, 86, 71, 224, - /* 720 */ 224, 269, 224, 224, 277, 287, 288, 289, 290, 291, - /* 730 */ 292, 22, 294, 249, 248, 297, 248, 98, 14, 301, - /* 740 */ 302, 303, 269, 255, 20, 259, 19, 269, 224, 110, - /* 750 */ 312, 269, 224, 265, 224, 20, 14, 269, 224, 216, - /* 760 */ 33, 269, 20, 36, 269, 269, 0, 269, 269, 42, - /* 770 */ 0, 44, 45, 46, 47, 287, 288, 289, 290, 291, - /* 780 */ 292, 224, 294, 224, 224, 297, 147, 0, 224, 301, - /* 790 */ 302, 303, 22, 269, 196, 197, 21, 269, 38, 269, - /* 800 */ 312, 74, 36, 269, 77, 1, 2, 168, 169, 34, - /* 810 */ 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, - /* 820 */ 181, 182, 183, 184, 185, 249, 269, 199, 269, 269, - /* 830 */ 158, 159, 79, 269, 107, 82, 224, 183, 184, 52, - /* 840 */ 53, 54, 55, 56, 249, 58, 59, 60, 61, 62, - /* 850 */ 63, 64, 65, 66, 67, 68, 69, 70, 71, 18, - /* 860 */ 248, 218, 135, 0, 23, 138, 224, 255, 79, 79, - /* 870 */ 110, 82, 82, 50, 139, 72, 35, 265, 249, 76, - /* 880 */ 153, 269, 155, 72, 72, 75, 274, 76, 76, 48, - /* 890 */ 248, 0, 72, 249, 72, 85, 76, 255, 76, 287, - /* 900 */ 288, 289, 290, 291, 292, 72, 294, 265, 38, 76, - /* 910 */ 72, 269, 21, 249, 76, 24, 25, 26, 27, 28, - /* 920 */ 29, 30, 31, 32, 61, 313, 249, 57, 65, 287, - /* 930 */ 288, 289, 290, 291, 292, 0, 294, 72, 326, 297, - /* 940 */ 225, 76, 330, 301, 302, 72, 72, 237, 72, 76, - /* 950 */ 76, 88, 76, 112, 72, 224, 333, 324, 76, 24, - /* 960 */ 25, 26, 27, 28, 29, 30, 31, 32, 281, 72, - /* 970 */ 107, 108, 109, 76, 111, 258, 72, 318, 227, 248, - /* 980 */ 76, 140, 141, 142, 72, 144, 255, 286, 76, 72, - /* 990 */ 149, 168, 311, 76, 248, 327, 265, 314, 20, 230, - /* 1000 */ 269, 36, 161, 224, 163, 282, 165, 166, 167, 38, - /* 1010 */ 234, 145, 224, 275, 230, 230, 121, 263, 287, 288, - /* 1020 */ 289, 290, 291, 292, 261, 294, 133, 248, 297, 261, - /* 1030 */ 22, 230, 301, 302, 255, 20, 248, 279, 232, 198, - /* 1040 */ 20, 232, 265, 255, 265, 273, 38, 255, 269, 266, - /* 1050 */ 20, 232, 20, 265, 226, 230, 232, 269, 232, 230, - /* 1060 */ 226, 248, 248, 248, 224, 57, 287, 288, 289, 290, - /* 1070 */ 291, 292, 224, 294, 57, 287, 288, 289, 290, 291, - /* 1080 */ 292, 279, 294, 248, 248, 297, 269, 248, 248, 229, - /* 1090 */ 302, 248, 248, 248, 248, 255, 248, 248, 154, 278, - /* 1100 */ 273, 229, 224, 255, 229, 265, 98, 265, 255, 269, - /* 1110 */ 331, 332, 272, 265, 20, 206, 266, 269, 110, 323, - /* 1120 */ 205, 270, 323, 286, 269, 269, 248, 287, 288, 289, - /* 1130 */ 290, 291, 292, 255, 294, 287, 288, 289, 290, 291, - /* 1140 */ 292, 270, 294, 265, 213, 212, 269, 269, 201, 319, - /* 1150 */ 272, 320, 200, 197, 224, 147, 255, 20, 121, 220, - /* 1160 */ 217, 329, 304, 215, 317, 287, 288, 289, 290, 291, - /* 1170 */ 292, 285, 294, 316, 75, 270, 168, 169, 248, 300, - /* 1180 */ 332, 270, 328, 269, 136, 255, 334, 269, 269, 267, - /* 1190 */ 266, 255, 229, 244, 75, 265, 229, 255, 238, 269, - /* 1200 */ 33, 251, 230, 36, 224, 229, 280, 226, 276, 42, - /* 1210 */ 242, 44, 45, 46, 47, 224, 242, 287, 288, 289, - /* 1220 */ 290, 291, 292, 231, 294, 222, 296, 64, 248, 0, - /* 1230 */ 0, 0, 38, 164, 38, 255, 38, 38, 164, 248, - /* 1240 */ 38, 74, 0, 38, 77, 265, 255, 164, 0, 269, - /* 1250 */ 38, 0, 272, 224, 38, 0, 265, 75, 151, 150, - /* 1260 */ 269, 147, 110, 272, 0, 0, 53, 287, 288, 289, - /* 1270 */ 290, 291, 292, 143, 294, 0, 0, 248, 287, 288, - /* 1280 */ 289, 290, 291, 292, 255, 294, 0, 87, 0, 0, - /* 1290 */ 0, 0, 0, 0, 265, 0, 0, 0, 269, 0, - /* 1300 */ 224, 134, 0, 136, 0, 138, 0, 0, 0, 121, - /* 1310 */ 0, 0, 0, 224, 0, 0, 287, 288, 289, 290, - /* 1320 */ 291, 292, 155, 294, 248, 22, 0, 0, 224, 0, - /* 1330 */ 0, 255, 0, 0, 0, 0, 0, 248, 51, 0, - /* 1340 */ 0, 265, 0, 43, 255, 269, 0, 38, 43, 36, - /* 1350 */ 0, 0, 248, 84, 265, 38, 36, 38, 269, 255, - /* 1360 */ 36, 43, 0, 287, 288, 289, 290, 291, 292, 265, - /* 1370 */ 294, 43, 0, 269, 43, 224, 287, 288, 289, 290, - /* 1380 */ 291, 292, 38, 294, 36, 0, 0, 0, 72, 22, - /* 1390 */ 224, 287, 288, 289, 290, 291, 292, 38, 294, 248, - /* 1400 */ 22, 38, 38, 224, 82, 0, 255, 38, 38, 72, - /* 1410 */ 0, 38, 38, 38, 248, 22, 265, 0, 39, 0, - /* 1420 */ 269, 255, 38, 22, 0, 22, 0, 248, 22, 20, - /* 1430 */ 0, 265, 38, 139, 255, 269, 0, 152, 287, 288, - /* 1440 */ 289, 290, 291, 292, 265, 294, 0, 22, 269, 0, - /* 1450 */ 0, 224, 75, 287, 288, 289, 290, 291, 292, 43, - /* 1460 */ 294, 72, 139, 72, 224, 202, 287, 288, 289, 290, - /* 1470 */ 291, 292, 76, 294, 72, 248, 202, 136, 196, 72, - /* 1480 */ 76, 134, 255, 75, 139, 87, 75, 75, 248, 76, - /* 1490 */ 76, 4, 265, 75, 72, 255, 269, 76, 38, 72, - /* 1500 */ 202, 72, 224, 38, 38, 265, 38, 87, 76, 269, - /* 1510 */ 87, 38, 38, 2, 287, 288, 289, 290, 291, 292, - /* 1520 */ 168, 294, 75, 72, 76, 87, 248, 287, 288, 289, - /* 1530 */ 290, 291, 292, 255, 294, 76, 75, 22, 76, 75, - /* 1540 */ 87, 170, 75, 265, 75, 0, 76, 269, 76, 224, - /* 1550 */ 75, 75, 75, 43, 75, 22, 85, 75, 38, 76, - /* 1560 */ 38, 75, 224, 38, 86, 287, 288, 289, 290, 291, - /* 1570 */ 292, 137, 294, 248, 134, 87, 87, 224, 76, 75, - /* 1580 */ 255, 76, 38, 75, 38, 76, 248, 75, 38, 76, - /* 1590 */ 265, 75, 100, 255, 269, 100, 100, 100, 22, 75, - /* 1600 */ 38, 248, 88, 265, 110, 75, 75, 269, 255, 38, - /* 1610 */ 22, 51, 287, 288, 289, 290, 291, 292, 265, 294, - /* 1620 */ 50, 38, 269, 57, 224, 287, 288, 289, 290, 291, - /* 1630 */ 292, 73, 294, 72, 38, 38, 38, 38, 38, 224, - /* 1640 */ 287, 288, 289, 290, 291, 292, 38, 294, 248, 38, - /* 1650 */ 22, 57, 224, 38, 38, 255, 12, 13, 38, 38, - /* 1660 */ 38, 38, 38, 248, 38, 265, 22, 0, 38, 269, - /* 1670 */ 255, 36, 43, 0, 38, 36, 248, 0, 0, 38, - /* 1680 */ 265, 43, 38, 255, 269, 36, 43, 287, 288, 289, - /* 1690 */ 290, 291, 292, 265, 294, 0, 38, 269, 36, 43, - /* 1700 */ 0, 57, 287, 288, 289, 290, 291, 292, 38, 294, - /* 1710 */ 0, 37, 0, 22, 21, 287, 288, 289, 290, 291, - /* 1720 */ 292, 22, 294, 22, 21, 20, 335, 335, 335, 52, - /* 1730 */ 335, 54, 335, 335, 335, 58, 335, 335, 61, 335, - /* 1740 */ 63, 64, 98, 66, 335, 335, 335, 335, 71, 335, - /* 1750 */ 335, 335, 335, 335, 110, 335, 335, 335, 335, 335, - /* 1760 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1770 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1780 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1790 */ 335, 147, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1800 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1810 */ 335, 335, 168, 335, 335, 335, 335, 335, 335, 335, - /* 1820 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1830 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1840 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1850 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1860 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1870 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1880 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1890 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1900 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1910 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1920 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1930 */ 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, - /* 1940 */ 335, 335, 335, 335, 335, 335, 335, + /* 0 */ 253, 249, 253, 266, 225, 231, 269, 231, 256, 272, + /* 10 */ 222, 250, 12, 13, 240, 225, 224, 270, 226, 270, + /* 20 */ 20, 247, 22, 12, 13, 14, 15, 16, 249, 270, + /* 30 */ 256, 284, 285, 284, 285, 256, 234, 261, 38, 249, + /* 40 */ 238, 314, 290, 284, 285, 266, 256, 0, 231, 270, + /* 50 */ 50, 12, 13, 14, 327, 233, 266, 57, 331, 20, + /* 60 */ 270, 22, 20, 275, 275, 275, 225, 288, 289, 290, + /* 70 */ 291, 292, 293, 256, 295, 75, 254, 38, 288, 289, + /* 80 */ 290, 291, 292, 293, 237, 295, 239, 258, 298, 50, + /* 90 */ 249, 20, 302, 303, 265, 266, 57, 256, 98, 299, + /* 100 */ 300, 49, 314, 314, 314, 326, 231, 266, 61, 292, + /* 110 */ 110, 270, 65, 231, 75, 327, 327, 327, 20, 331, + /* 120 */ 331, 331, 240, 306, 307, 308, 309, 231, 311, 288, + /* 130 */ 289, 290, 291, 292, 293, 88, 295, 98, 256, 298, + /* 140 */ 233, 47, 231, 302, 303, 304, 75, 38, 148, 110, + /* 150 */ 275, 240, 256, 246, 107, 108, 109, 316, 111, 20, + /* 160 */ 20, 254, 20, 322, 323, 138, 57, 256, 74, 169, + /* 170 */ 170, 77, 172, 173, 174, 175, 176, 177, 178, 179, + /* 180 */ 180, 181, 182, 183, 184, 185, 186, 148, 292, 314, + /* 190 */ 249, 12, 13, 14, 15, 16, 255, 1, 2, 199, + /* 200 */ 75, 260, 327, 307, 308, 309, 331, 311, 169, 170, + /* 210 */ 85, 172, 173, 174, 175, 176, 177, 178, 179, 180, + /* 220 */ 181, 182, 183, 184, 185, 186, 12, 13, 199, 50, + /* 230 */ 242, 204, 205, 245, 20, 18, 22, 20, 225, 52, + /* 240 */ 230, 54, 49, 249, 27, 58, 230, 30, 61, 255, + /* 250 */ 63, 64, 38, 66, 260, 76, 39, 147, 71, 149, + /* 260 */ 244, 251, 249, 84, 50, 12, 13, 251, 4, 256, + /* 270 */ 199, 57, 76, 20, 2, 22, 286, 157, 158, 266, + /* 280 */ 169, 161, 2, 270, 12, 13, 14, 15, 16, 75, + /* 290 */ 286, 38, 12, 13, 14, 15, 16, 14, 15, 16, + /* 300 */ 310, 288, 289, 290, 291, 292, 293, 248, 295, 199, + /* 310 */ 57, 298, 98, 134, 310, 302, 303, 304, 259, 208, + /* 320 */ 209, 210, 211, 212, 110, 275, 313, 0, 75, 0, + /* 330 */ 113, 152, 20, 116, 117, 118, 119, 120, 199, 122, + /* 340 */ 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, + /* 350 */ 133, 98, 4, 24, 25, 26, 27, 28, 29, 30, + /* 360 */ 31, 32, 148, 110, 314, 314, 187, 188, 189, 190, + /* 370 */ 191, 192, 193, 194, 195, 196, 49, 327, 327, 225, + /* 380 */ 20, 331, 331, 169, 170, 43, 172, 173, 174, 175, + /* 390 */ 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, + /* 400 */ 186, 148, 57, 20, 72, 12, 13, 14, 15, 16, + /* 410 */ 21, 228, 229, 24, 25, 26, 27, 28, 29, 30, + /* 420 */ 31, 32, 169, 170, 270, 172, 173, 174, 175, 176, + /* 430 */ 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, + /* 440 */ 12, 13, 14, 50, 0, 72, 225, 241, 20, 76, + /* 450 */ 22, 241, 199, 231, 266, 249, 35, 61, 75, 249, + /* 460 */ 272, 65, 240, 257, 200, 21, 38, 257, 24, 25, + /* 470 */ 26, 27, 28, 29, 30, 31, 32, 84, 256, 12, + /* 480 */ 13, 3, 61, 0, 88, 57, 65, 20, 225, 22, + /* 490 */ 225, 270, 12, 13, 14, 15, 16, 231, 231, 78, + /* 500 */ 140, 80, 81, 75, 83, 38, 240, 240, 86, 88, + /* 510 */ 235, 236, 241, 247, 249, 12, 13, 14, 15, 16, + /* 520 */ 249, 256, 256, 256, 57, 231, 98, 134, 257, 225, + /* 530 */ 249, 266, 256, 270, 240, 270, 255, 231, 110, 263, + /* 540 */ 198, 260, 75, 134, 61, 152, 240, 199, 65, 217, + /* 550 */ 256, 235, 236, 288, 289, 290, 291, 292, 293, 249, + /* 560 */ 295, 152, 256, 298, 0, 98, 20, 302, 303, 304, + /* 570 */ 260, 88, 67, 250, 270, 286, 148, 110, 313, 76, + /* 580 */ 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, + /* 590 */ 107, 108, 109, 225, 111, 0, 187, 169, 170, 310, + /* 600 */ 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, + /* 610 */ 182, 183, 184, 185, 186, 148, 52, 249, 54, 114, + /* 620 */ 115, 141, 58, 225, 256, 61, 79, 63, 64, 82, + /* 630 */ 66, 36, 235, 236, 266, 71, 169, 170, 270, 172, + /* 640 */ 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, + /* 650 */ 183, 184, 185, 186, 12, 13, 288, 289, 290, 291, + /* 660 */ 292, 293, 20, 295, 22, 225, 298, 0, 270, 231, + /* 670 */ 302, 303, 304, 12, 13, 14, 15, 16, 240, 231, + /* 680 */ 38, 225, 249, 231, 231, 20, 140, 22, 240, 249, + /* 690 */ 257, 323, 240, 215, 256, 250, 256, 235, 236, 57, + /* 700 */ 220, 14, 231, 22, 256, 40, 266, 20, 256, 256, + /* 710 */ 270, 240, 231, 225, 225, 144, 49, 75, 0, 38, + /* 720 */ 225, 240, 225, 225, 225, 250, 270, 256, 288, 289, + /* 730 */ 290, 291, 292, 293, 163, 295, 79, 256, 298, 82, + /* 740 */ 98, 72, 302, 303, 304, 292, 12, 13, 14, 15, + /* 750 */ 16, 225, 110, 313, 225, 225, 250, 225, 270, 270, + /* 760 */ 307, 308, 309, 225, 311, 270, 50, 270, 270, 270, + /* 770 */ 52, 53, 54, 55, 56, 250, 58, 59, 60, 61, + /* 780 */ 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, + /* 790 */ 148, 14, 265, 266, 197, 198, 270, 20, 250, 270, + /* 800 */ 270, 140, 270, 225, 159, 160, 225, 225, 270, 72, + /* 810 */ 76, 169, 170, 76, 172, 173, 174, 175, 176, 177, + /* 820 */ 178, 179, 180, 181, 182, 183, 184, 185, 186, 75, + /* 830 */ 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, + /* 840 */ 99, 87, 101, 102, 103, 104, 105, 106, 270, 18, + /* 850 */ 225, 270, 270, 79, 23, 0, 82, 79, 0, 21, + /* 860 */ 82, 0, 38, 225, 72, 72, 35, 278, 76, 76, + /* 870 */ 1, 2, 34, 38, 249, 184, 185, 22, 72, 48, + /* 880 */ 22, 256, 76, 22, 226, 169, 72, 249, 219, 72, + /* 890 */ 76, 266, 72, 76, 256, 270, 76, 72, 238, 72, + /* 900 */ 275, 76, 72, 76, 266, 72, 76, 334, 270, 76, + /* 910 */ 325, 259, 282, 288, 289, 290, 291, 292, 293, 72, + /* 920 */ 295, 72, 319, 76, 228, 76, 288, 289, 290, 291, + /* 930 */ 292, 293, 312, 295, 110, 287, 298, 249, 72, 314, + /* 940 */ 302, 303, 76, 112, 225, 110, 328, 38, 315, 36, + /* 950 */ 33, 72, 327, 36, 72, 76, 331, 20, 76, 42, + /* 960 */ 231, 44, 45, 46, 47, 283, 57, 235, 249, 38, + /* 970 */ 276, 231, 141, 142, 143, 256, 145, 231, 146, 264, + /* 980 */ 121, 150, 134, 262, 262, 266, 231, 20, 280, 270, + /* 990 */ 233, 74, 266, 162, 77, 164, 225, 166, 167, 168, + /* 1000 */ 20, 274, 233, 256, 20, 267, 233, 288, 289, 290, + /* 1010 */ 291, 292, 293, 233, 295, 231, 233, 298, 20, 19, + /* 1020 */ 249, 302, 303, 227, 249, 249, 231, 256, 249, 227, + /* 1030 */ 199, 249, 57, 33, 249, 249, 36, 266, 249, 249, + /* 1040 */ 249, 270, 42, 249, 44, 45, 46, 47, 249, 230, + /* 1050 */ 280, 225, 135, 155, 137, 274, 139, 270, 230, 288, + /* 1060 */ 289, 290, 291, 292, 293, 294, 295, 296, 297, 266, + /* 1070 */ 230, 256, 267, 156, 74, 249, 279, 77, 20, 207, + /* 1080 */ 230, 271, 256, 324, 206, 287, 270, 324, 214, 271, + /* 1090 */ 213, 270, 266, 270, 202, 201, 270, 198, 256, 20, + /* 1100 */ 225, 221, 121, 335, 218, 216, 305, 107, 286, 321, + /* 1110 */ 75, 270, 301, 270, 288, 289, 290, 291, 292, 293, + /* 1120 */ 320, 295, 318, 271, 249, 317, 137, 271, 245, 256, + /* 1130 */ 270, 256, 268, 230, 267, 230, 136, 330, 329, 139, + /* 1140 */ 256, 266, 75, 252, 230, 270, 239, 231, 227, 281, + /* 1150 */ 232, 243, 225, 277, 154, 243, 156, 223, 332, 333, + /* 1160 */ 231, 0, 0, 288, 289, 290, 291, 292, 293, 64, + /* 1170 */ 295, 0, 38, 298, 165, 38, 249, 38, 303, 38, + /* 1180 */ 165, 0, 225, 256, 38, 256, 38, 165, 0, 38, + /* 1190 */ 0, 0, 38, 266, 75, 152, 151, 270, 110, 148, + /* 1200 */ 273, 0, 0, 53, 275, 144, 249, 0, 0, 87, + /* 1210 */ 0, 0, 0, 256, 121, 288, 289, 290, 291, 292, + /* 1220 */ 293, 292, 295, 266, 0, 0, 0, 270, 0, 0, + /* 1230 */ 0, 0, 0, 225, 0, 0, 307, 308, 309, 0, + /* 1240 */ 311, 0, 0, 314, 0, 288, 289, 290, 291, 292, + /* 1250 */ 293, 0, 295, 0, 0, 0, 327, 249, 0, 0, + /* 1260 */ 331, 0, 22, 225, 256, 0, 0, 0, 0, 0, + /* 1270 */ 0, 0, 0, 0, 266, 82, 43, 0, 270, 0, + /* 1280 */ 0, 273, 36, 38, 36, 38, 43, 249, 51, 0, + /* 1290 */ 333, 225, 43, 43, 256, 38, 288, 289, 290, 291, + /* 1300 */ 292, 293, 0, 295, 266, 43, 0, 0, 270, 0, + /* 1310 */ 36, 0, 22, 0, 38, 249, 38, 36, 0, 22, + /* 1320 */ 84, 38, 256, 38, 72, 38, 288, 289, 290, 291, + /* 1330 */ 292, 293, 266, 295, 38, 297, 270, 38, 38, 273, + /* 1340 */ 225, 38, 12, 13, 0, 0, 22, 39, 22, 22, + /* 1350 */ 38, 0, 22, 22, 288, 289, 290, 291, 292, 293, + /* 1360 */ 72, 295, 0, 22, 249, 38, 20, 0, 38, 0, + /* 1370 */ 38, 256, 153, 0, 22, 137, 0, 0, 225, 75, + /* 1380 */ 43, 266, 72, 203, 57, 270, 72, 57, 273, 225, + /* 1390 */ 203, 76, 72, 76, 75, 197, 140, 75, 135, 203, + /* 1400 */ 140, 76, 249, 288, 289, 290, 291, 292, 293, 256, + /* 1410 */ 295, 76, 72, 249, 75, 87, 87, 75, 38, 266, + /* 1420 */ 256, 72, 140, 270, 76, 98, 72, 72, 98, 76, + /* 1430 */ 266, 38, 38, 38, 270, 38, 38, 110, 2, 225, + /* 1440 */ 110, 288, 289, 290, 291, 292, 293, 87, 295, 75, + /* 1450 */ 72, 76, 288, 289, 290, 291, 292, 293, 76, 295, + /* 1460 */ 169, 75, 75, 249, 76, 75, 87, 22, 87, 171, + /* 1470 */ 256, 75, 138, 0, 75, 148, 76, 76, 148, 75, + /* 1480 */ 266, 75, 43, 75, 270, 135, 75, 85, 22, 225, + /* 1490 */ 87, 76, 38, 38, 87, 86, 169, 170, 75, 169, + /* 1500 */ 225, 76, 288, 289, 290, 291, 292, 293, 38, 295, + /* 1510 */ 75, 22, 38, 249, 76, 75, 38, 76, 75, 38, + /* 1520 */ 256, 100, 76, 75, 249, 88, 100, 100, 100, 38, + /* 1530 */ 266, 256, 75, 75, 270, 75, 38, 22, 51, 110, + /* 1540 */ 50, 266, 38, 57, 73, 270, 38, 72, 225, 38, + /* 1550 */ 38, 38, 288, 289, 290, 291, 292, 293, 38, 295, + /* 1560 */ 38, 225, 4, 288, 289, 290, 291, 292, 293, 38, + /* 1570 */ 295, 22, 249, 57, 38, 38, 38, 19, 38, 256, + /* 1580 */ 38, 38, 38, 38, 0, 249, 38, 36, 0, 266, + /* 1590 */ 43, 33, 256, 270, 36, 38, 36, 43, 0, 41, + /* 1600 */ 38, 36, 266, 0, 43, 47, 270, 38, 36, 43, + /* 1610 */ 0, 288, 289, 290, 291, 292, 293, 38, 295, 37, + /* 1620 */ 0, 0, 22, 21, 288, 289, 290, 291, 292, 293, + /* 1630 */ 225, 295, 74, 22, 22, 77, 21, 20, 336, 225, + /* 1640 */ 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, + /* 1650 */ 336, 336, 336, 336, 249, 336, 336, 336, 336, 336, + /* 1660 */ 336, 256, 336, 249, 336, 336, 336, 336, 336, 336, + /* 1670 */ 256, 266, 336, 336, 336, 270, 336, 336, 336, 336, + /* 1680 */ 266, 336, 336, 336, 270, 336, 336, 336, 336, 225, + /* 1690 */ 336, 336, 336, 288, 289, 290, 291, 292, 293, 336, + /* 1700 */ 295, 336, 288, 289, 290, 291, 292, 293, 336, 295, + /* 1710 */ 336, 336, 336, 249, 336, 336, 336, 336, 336, 336, + /* 1720 */ 256, 336, 336, 336, 336, 336, 336, 336, 336, 336, + /* 1730 */ 266, 336, 336, 336, 270, 336, 336, 336, 336, 225, + /* 1740 */ 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, + /* 1750 */ 225, 336, 288, 289, 290, 291, 292, 293, 336, 295, + /* 1760 */ 336, 336, 336, 249, 336, 336, 336, 336, 336, 336, + /* 1770 */ 256, 336, 336, 336, 249, 336, 336, 336, 336, 336, + /* 1780 */ 266, 256, 336, 336, 270, 336, 336, 336, 336, 336, + /* 1790 */ 336, 266, 336, 336, 336, 270, 336, 336, 225, 336, + /* 1800 */ 336, 336, 288, 289, 290, 291, 292, 293, 336, 295, + /* 1810 */ 336, 225, 336, 288, 289, 290, 291, 292, 293, 336, + /* 1820 */ 295, 336, 249, 336, 336, 336, 336, 336, 336, 256, + /* 1830 */ 336, 336, 336, 336, 336, 249, 336, 336, 336, 266, + /* 1840 */ 336, 336, 256, 270, 336, 336, 336, 336, 336, 336, + /* 1850 */ 336, 336, 266, 336, 336, 336, 270, 336, 336, 336, + /* 1860 */ 336, 288, 289, 290, 291, 292, 293, 336, 295, 336, + /* 1870 */ 336, 336, 336, 336, 288, 289, 290, 291, 292, 293, + /* 1880 */ 225, 295, 336, 336, 336, 336, 336, 336, 336, 225, + /* 1890 */ 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, + /* 1900 */ 336, 336, 336, 336, 249, 336, 336, 336, 336, 336, + /* 1910 */ 336, 256, 336, 249, 336, 336, 336, 336, 336, 336, + /* 1920 */ 256, 266, 336, 336, 336, 270, 336, 336, 336, 336, + /* 1930 */ 266, 336, 336, 336, 270, 336, 336, 336, 336, 336, + /* 1940 */ 336, 336, 336, 288, 289, 290, 291, 292, 293, 336, + /* 1950 */ 295, 336, 288, 289, 290, 291, 292, 293, 336, 295, }; -#define YY_SHIFT_COUNT (569) +#define YY_SHIFT_COUNT (571) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (1712) +#define YY_SHIFT_MAX (1621) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 841, 0, 39, 213, 213, 213, 213, 252, 213, 213, - /* 10 */ 426, 465, 639, 465, 465, 465, 465, 465, 465, 465, - /* 20 */ 465, 465, 465, 465, 465, 465, 465, 465, 465, 465, - /* 30 */ 465, 465, 465, 465, 465, 465, 34, 53, 53, 53, - /* 40 */ 44, 1644, 1644, 299, 74, 74, 151, 1644, 74, 74, - /* 50 */ 74, 74, 74, 74, 71, 74, 358, 472, 151, 508, - /* 60 */ 358, 74, 74, 358, 74, 358, 508, 358, 358, 74, - /* 70 */ 453, 216, 111, 177, 177, 430, 1008, 206, 647, 1008, - /* 80 */ 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, - /* 90 */ 1008, 1008, 1008, 1008, 1008, 1008, 1008, 1008, 339, 9, - /* 100 */ 193, 193, 168, 168, 168, 273, 193, 193, 674, 508, - /* 110 */ 358, 508, 358, 631, 459, 311, 311, 311, 311, 311, - /* 120 */ 311, 311, 727, 891, 1677, 302, 144, 30, 92, 72, - /* 130 */ 462, 735, 598, 487, 598, 724, 334, 628, 742, 978, - /* 140 */ 965, 971, 866, 978, 978, 895, 893, 893, 978, 1015, - /* 150 */ 71, 508, 1020, 71, 674, 1030, 71, 71, 978, 71, - /* 160 */ 1032, 358, 358, 358, 358, 358, 358, 358, 358, 358, - /* 170 */ 358, 358, 978, 1032, 1017, 1015, 453, 944, 508, 1020, - /* 180 */ 453, 674, 1030, 453, 1094, 909, 915, 1017, 909, 915, - /* 190 */ 1017, 1017, 931, 933, 947, 952, 956, 674, 1137, 1037, - /* 200 */ 939, 943, 948, 1099, 358, 915, 1017, 1017, 915, 1017, - /* 210 */ 1048, 674, 1030, 453, 631, 453, 674, 1119, 459, 978, - /* 220 */ 453, 1032, 1813, 1813, 1813, 1813, 1813, 1813, 787, 1167, - /* 230 */ 935, 519, 47, 863, 244, 555, 611, 187, 455, 361, - /* 240 */ 361, 361, 361, 361, 361, 361, 361, 514, 450, 615, - /* 250 */ 400, 342, 342, 342, 342, 766, 523, 546, 510, 753, - /* 260 */ 789, 790, 422, 709, 770, 775, 672, 803, 811, 812, - /* 270 */ 804, 654, 543, 643, 820, 823, 822, 475, 833, 838, - /* 280 */ 865, 873, 874, 209, 760, 876, 882, 897, 904, 912, - /* 290 */ 917, 810, 870, 1229, 1230, 1163, 1231, 1194, 1069, 1196, - /* 300 */ 1198, 1199, 1074, 1242, 1202, 1205, 1083, 1248, 1212, 1251, - /* 310 */ 1216, 1255, 1182, 1107, 1109, 1152, 1114, 1264, 1265, 1213, - /* 320 */ 1130, 1275, 1276, 1200, 1286, 1288, 1289, 1290, 1291, 1292, - /* 330 */ 1293, 1295, 1296, 1297, 1299, 1302, 1304, 1306, 1307, 1308, - /* 340 */ 1188, 1310, 1311, 1312, 1314, 1315, 1329, 1303, 1326, 1327, - /* 350 */ 1330, 1332, 1333, 1334, 1335, 1336, 1342, 1300, 1346, 1287, - /* 360 */ 1339, 1340, 1309, 1313, 1305, 1350, 1317, 1320, 1318, 1351, - /* 370 */ 1319, 1324, 1328, 1362, 1344, 1348, 1331, 1372, 1385, 1386, - /* 380 */ 1387, 1269, 1322, 1359, 1316, 1337, 1367, 1405, 1363, 1364, - /* 390 */ 1369, 1370, 1373, 1316, 1337, 1374, 1375, 1410, 1378, 1417, - /* 400 */ 1393, 1379, 1419, 1401, 1384, 1424, 1403, 1426, 1406, 1409, - /* 410 */ 1430, 1294, 1394, 1436, 1285, 1425, 1323, 1341, 1446, 1449, - /* 420 */ 1345, 1450, 1377, 1416, 1347, 1389, 1391, 1263, 1396, 1402, - /* 430 */ 1404, 1408, 1411, 1412, 1413, 1407, 1398, 1418, 1422, 1274, - /* 440 */ 1414, 1421, 1420, 1282, 1427, 1423, 1432, 1429, 1298, 1487, - /* 450 */ 1460, 1465, 1466, 1468, 1473, 1474, 1511, 1352, 1451, 1448, - /* 460 */ 1447, 1459, 1461, 1462, 1438, 1464, 1467, 1453, 1515, 1371, - /* 470 */ 1469, 1470, 1472, 1475, 1476, 1434, 1477, 1545, 1510, 1440, - /* 480 */ 1479, 1471, 1488, 1489, 1533, 1482, 1478, 1483, 1520, 1522, - /* 490 */ 1486, 1502, 1525, 1504, 1505, 1544, 1508, 1509, 1546, 1512, - /* 500 */ 1513, 1550, 1516, 1492, 1495, 1496, 1497, 1576, 1514, 1524, - /* 510 */ 1562, 1494, 1530, 1531, 1571, 1316, 1337, 1588, 1560, 1570, - /* 520 */ 1583, 1566, 1558, 1561, 1596, 1597, 1598, 1599, 1600, 1608, - /* 530 */ 1611, 1628, 1594, 1316, 1615, 1337, 1616, 1620, 1621, 1622, - /* 540 */ 1623, 1624, 1626, 1667, 1630, 1635, 1629, 1673, 1636, 1639, - /* 550 */ 1638, 1678, 1641, 1649, 1643, 1695, 1658, 1662, 1656, 1700, - /* 560 */ 1670, 1674, 1710, 1712, 1691, 1693, 1699, 1701, 1703, 1705, + /* 0 */ 831, 0, 39, 214, 214, 214, 214, 253, 214, 214, + /* 10 */ 428, 467, 642, 467, 467, 467, 467, 467, 467, 467, + /* 20 */ 467, 467, 467, 467, 467, 467, 467, 467, 467, 467, + /* 30 */ 467, 467, 467, 467, 467, 467, 71, 383, 383, 383, + /* 40 */ 139, 1330, 1330, 110, 42, 42, 29, 1330, 348, 42, + /* 50 */ 42, 42, 42, 42, 42, 52, 42, 98, 140, 29, + /* 60 */ 142, 98, 42, 42, 98, 42, 98, 142, 98, 98, + /* 70 */ 42, 193, 217, 179, 393, 393, 389, 1327, 421, 187, + /* 80 */ 1327, 1327, 1327, 1327, 1327, 1327, 1327, 1327, 1327, 1327, + /* 90 */ 1327, 1327, 1327, 1327, 1327, 1327, 1327, 1327, 1327, 665, + /* 100 */ 327, 109, 109, 360, 360, 360, 667, 109, 109, 312, + /* 110 */ 142, 98, 142, 98, 422, 345, 741, 741, 741, 741, + /* 120 */ 741, 741, 741, 1000, 444, 564, 480, 111, 396, 120, + /* 130 */ 27, 681, 546, 597, 342, 597, 687, 478, 264, 777, + /* 140 */ 937, 913, 931, 832, 937, 937, 859, 848, 848, 937, + /* 150 */ 967, 52, 142, 980, 52, 312, 984, 52, 52, 937, + /* 160 */ 52, 998, 98, 98, 98, 98, 98, 98, 98, 98, + /* 170 */ 98, 98, 98, 937, 998, 975, 967, 193, 898, 142, + /* 180 */ 193, 980, 193, 312, 984, 193, 1058, 872, 878, 975, + /* 190 */ 872, 878, 975, 975, 874, 877, 892, 894, 899, 312, + /* 200 */ 1079, 981, 880, 886, 889, 1035, 98, 878, 975, 975, + /* 210 */ 878, 975, 989, 312, 984, 193, 422, 193, 312, 1067, + /* 220 */ 345, 937, 193, 998, 1960, 1960, 1960, 1960, 1960, 1960, + /* 230 */ 718, 917, 329, 1558, 47, 483, 503, 272, 280, 661, + /* 240 */ 734, 11, 11, 11, 11, 11, 11, 11, 11, 94, + /* 250 */ 505, 196, 409, 283, 283, 283, 283, 595, 571, 373, + /* 260 */ 547, 657, 774, 778, 855, 858, 861, 838, 645, 737, + /* 270 */ 792, 793, 869, 691, 332, 669, 806, 716, 814, 754, + /* 280 */ 817, 820, 825, 827, 830, 824, 835, 833, 847, 849, + /* 290 */ 866, 879, 882, 125, 909, 1161, 1162, 1105, 1171, 1134, + /* 300 */ 1009, 1137, 1139, 1141, 1015, 1181, 1146, 1148, 1022, 1188, + /* 310 */ 1151, 1190, 1154, 1191, 1119, 1043, 1045, 1088, 1051, 1201, + /* 320 */ 1202, 1150, 1061, 1207, 1208, 1122, 1210, 1211, 1212, 1224, + /* 330 */ 1225, 1226, 1228, 1229, 1230, 1231, 1232, 1234, 1235, 1239, + /* 340 */ 1241, 1242, 1244, 1093, 1251, 1253, 1254, 1255, 1258, 1259, + /* 350 */ 1240, 1261, 1265, 1266, 1267, 1268, 1269, 1270, 1271, 1272, + /* 360 */ 1233, 1273, 1237, 1277, 1279, 1245, 1246, 1243, 1280, 1247, + /* 370 */ 1248, 1249, 1289, 1257, 1274, 1250, 1302, 1278, 1281, 1262, + /* 380 */ 1306, 1307, 1309, 1311, 1236, 1193, 1276, 1252, 1288, 1290, + /* 390 */ 1313, 1283, 1285, 1287, 1296, 1299, 1252, 1288, 1300, 1303, + /* 400 */ 1318, 1297, 1344, 1324, 1308, 1345, 1326, 1312, 1351, 1331, + /* 410 */ 1362, 1341, 1346, 1367, 1256, 1332, 1369, 1219, 1352, 1260, + /* 420 */ 1238, 1373, 1376, 1282, 1377, 1304, 1337, 1263, 1310, 1314, + /* 430 */ 1180, 1315, 1320, 1317, 1319, 1322, 1339, 1325, 1340, 1328, + /* 440 */ 1342, 1349, 1187, 1335, 1348, 1329, 1198, 1354, 1360, 1353, + /* 450 */ 1355, 1196, 1380, 1393, 1394, 1395, 1397, 1398, 1436, 1291, + /* 460 */ 1378, 1375, 1374, 1382, 1386, 1388, 1379, 1387, 1390, 1381, + /* 470 */ 1445, 1298, 1396, 1400, 1401, 1399, 1404, 1334, 1406, 1473, + /* 480 */ 1439, 1350, 1408, 1402, 1403, 1407, 1466, 1411, 1409, 1415, + /* 490 */ 1454, 1455, 1423, 1425, 1470, 1435, 1438, 1474, 1440, 1441, + /* 500 */ 1478, 1443, 1446, 1481, 1448, 1421, 1426, 1427, 1428, 1489, + /* 510 */ 1437, 1457, 1491, 1429, 1458, 1460, 1498, 1252, 1288, 1515, + /* 520 */ 1487, 1490, 1504, 1486, 1471, 1475, 1508, 1511, 1512, 1513, + /* 530 */ 1520, 1522, 1531, 1549, 1516, 1252, 1536, 1288, 1537, 1538, + /* 540 */ 1540, 1542, 1543, 1544, 1545, 1584, 1548, 1551, 1547, 1588, + /* 550 */ 1557, 1560, 1554, 1598, 1562, 1565, 1561, 1603, 1569, 1572, + /* 560 */ 1566, 1610, 1579, 1582, 1620, 1621, 1600, 1602, 1611, 1612, + /* 570 */ 1615, 1617, }; -#define YY_REDUCE_COUNT (227) -#define YY_REDUCE_MIN (-292) -#define YY_REDUCE_MAX (1428) +#define YY_REDUCE_COUNT (229) +#define YY_REDUCE_MIN (-273) +#define YY_REDUCE_MAX (1664) static const short yy_reduce_ofst[] = { - /* 0 */ -211, -209, -158, 217, 366, 438, 488, 612, 642, 731, - /* 10 */ 289, 779, 788, 840, -220, 848, 878, 930, 980, 991, - /* 20 */ 1029, 1076, 1089, 1104, 1151, 1166, 1179, 1227, 1240, 1278, - /* 30 */ 1325, 1338, 1353, 1400, 1415, 1428, 219, -25, -207, 188, - /* 40 */ -34, -252, -250, -35, -225, -1, -5, -258, -212, -117, - /* 50 */ -89, -88, -2, 236, -229, 260, 287, -247, 150, -106, - /* 60 */ 233, 304, 317, 416, 435, 431, -228, 441, 432, 38, - /* 70 */ -188, -154, -292, -292, -292, -77, -72, 66, -193, 318, - /* 80 */ 404, 452, 473, 478, 482, 492, 495, 496, 498, 499, - /* 90 */ 524, 528, 530, 534, 557, 559, 560, 564, -141, 321, - /* 100 */ 96, 218, -169, -115, 203, 454, 385, 395, -102, 427, - /* 110 */ 163, 417, 486, 139, -32, 484, 576, 595, 629, 644, - /* 120 */ 664, 677, 447, 715, 710, 623, 633, 717, 687, 659, - /* 130 */ 751, 701, 681, 681, 681, 746, 668, 683, 746, 769, - /* 140 */ 723, 776, 738, 784, 785, 754, 763, 768, 801, 758, - /* 150 */ 806, 777, 772, 809, 792, 783, 819, 824, 825, 826, - /* 160 */ 828, 813, 814, 815, 835, 836, 839, 843, 844, 845, - /* 170 */ 846, 849, 829, 834, 817, 802, 860, 821, 842, 827, - /* 180 */ 872, 853, 850, 875, 837, 796, 851, 855, 799, 871, - /* 190 */ 856, 877, 831, 830, 847, 857, 681, 901, 886, 858, - /* 200 */ 852, 832, 854, 879, 746, 905, 914, 918, 911, 919, - /* 210 */ 922, 936, 924, 963, 949, 967, 942, 950, 960, 972, - /* 220 */ 976, 981, 932, 926, 968, 974, 992, 1003, + /* 0 */ -212, -210, -159, 368, 13, 265, 440, 625, 638, 719, + /* 10 */ 771, 826, 875, 927, -221, 957, 1008, 1038, 1066, 1115, + /* 20 */ 1153, 1164, 1214, 1264, 1275, 1323, 1336, 1405, 1414, 1464, + /* 30 */ 1514, 1525, 1573, 1586, 1655, 1664, 929, -183, -104, 453, + /* 40 */ -125, -253, -251, -211, -226, 266, 50, -241, -273, -118, + /* 50 */ -89, 222, 267, 294, 306, -93, 438, -59, -248, 51, + /* 60 */ -263, 206, 448, 471, -6, 481, 210, -171, 281, 271, + /* 70 */ 452, 16, -224, -200, -200, -200, -208, 154, 59, -198, + /* 80 */ 221, 263, 304, 398, 456, 488, 489, 495, 497, 498, + /* 90 */ 499, 526, 529, 530, 532, 538, 578, 581, 582, 183, + /* 100 */ -178, 275, 316, -10, 4, 289, 10, 397, 462, 276, + /* 110 */ 188, 433, 527, 310, -12, -153, -239, 323, 445, 475, + /* 120 */ 506, 525, 548, 589, 658, 660, 573, 585, 652, 630, + /* 130 */ 603, 696, 648, 620, 620, 620, 688, 618, 633, 688, + /* 140 */ 729, 682, 732, 694, 740, 746, 715, 721, 722, 755, + /* 150 */ 708, 757, 726, 727, 769, 747, 738, 773, 780, 784, + /* 160 */ 783, 796, 775, 776, 779, 782, 785, 786, 789, 790, + /* 170 */ 791, 794, 799, 795, 802, 787, 770, 819, 797, 803, + /* 180 */ 828, 781, 840, 815, 805, 850, 798, 759, 810, 816, + /* 190 */ 763, 818, 821, 823, 788, 800, 804, 808, 620, 842, + /* 200 */ 822, 801, 768, 807, 809, 811, 688, 852, 841, 843, + /* 210 */ 856, 860, 864, 873, 867, 903, 883, 905, 884, 891, + /* 220 */ 907, 916, 914, 921, 876, 868, 908, 912, 918, 934, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 10 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 20 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 30 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 40 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 50 */ 1282, 1282, 1282, 1282, 1341, 1282, 1282, 1282, 1282, 1282, - /* 60 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 70 */ 1339, 1483, 1282, 1639, 1282, 1282, 1282, 1282, 1282, 1282, - /* 80 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 90 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1341, - /* 100 */ 1282, 1282, 1650, 1650, 1650, 1339, 1282, 1282, 1282, 1282, - /* 110 */ 1282, 1282, 1282, 1436, 1282, 1282, 1282, 1282, 1282, 1282, - /* 120 */ 1282, 1282, 1517, 1282, 1282, 1714, 1282, 1389, 1523, 1674, - /* 130 */ 1282, 1666, 1642, 1656, 1643, 1282, 1699, 1659, 1282, 1282, - /* 140 */ 1282, 1282, 1509, 1282, 1282, 1488, 1485, 1485, 1282, 1282, - /* 150 */ 1341, 1282, 1282, 1341, 1282, 1282, 1341, 1341, 1282, 1341, - /* 160 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 170 */ 1282, 1282, 1282, 1282, 1282, 1282, 1339, 1519, 1282, 1282, - /* 180 */ 1339, 1282, 1282, 1339, 1282, 1681, 1679, 1282, 1681, 1679, - /* 190 */ 1282, 1282, 1693, 1689, 1672, 1670, 1656, 1282, 1282, 1282, - /* 200 */ 1717, 1705, 1701, 1282, 1282, 1679, 1282, 1282, 1679, 1282, - /* 210 */ 1496, 1282, 1282, 1339, 1282, 1339, 1282, 1405, 1282, 1282, - /* 220 */ 1339, 1282, 1511, 1525, 1439, 1439, 1342, 1287, 1282, 1282, - /* 230 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1586, - /* 240 */ 1692, 1691, 1615, 1614, 1613, 1611, 1585, 1282, 1282, 1282, - /* 250 */ 1282, 1579, 1580, 1578, 1577, 1282, 1282, 1282, 1282, 1282, - /* 260 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 270 */ 1640, 1282, 1702, 1706, 1282, 1282, 1282, 1563, 1282, 1282, - /* 280 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 290 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 300 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 310 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 320 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 330 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 340 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 350 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 360 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 370 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 380 */ 1282, 1282, 1282, 1282, 1452, 1451, 1282, 1282, 1282, 1282, - /* 390 */ 1282, 1282, 1282, 1369, 1368, 1282, 1282, 1282, 1282, 1282, - /* 400 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 410 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 420 */ 1282, 1282, 1282, 1282, 1282, 1663, 1673, 1282, 1282, 1282, - /* 430 */ 1282, 1282, 1282, 1282, 1282, 1282, 1563, 1282, 1690, 1282, - /* 440 */ 1649, 1645, 1282, 1282, 1641, 1282, 1282, 1700, 1282, 1282, - /* 450 */ 1282, 1282, 1282, 1282, 1282, 1282, 1635, 1282, 1608, 1282, - /* 460 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1573, - /* 470 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 480 */ 1282, 1282, 1562, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 490 */ 1433, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 500 */ 1282, 1282, 1282, 1418, 1416, 1415, 1414, 1282, 1411, 1282, - /* 510 */ 1282, 1282, 1282, 1282, 1282, 1442, 1441, 1282, 1282, 1282, - /* 520 */ 1282, 1282, 1282, 1362, 1282, 1282, 1282, 1282, 1282, 1282, - /* 530 */ 1282, 1282, 1282, 1353, 1282, 1352, 1282, 1282, 1282, 1282, - /* 540 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 550 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, - /* 560 */ 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, 1282, + /* 0 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 10 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 20 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 30 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 40 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 50 */ 1287, 1287, 1287, 1287, 1287, 1346, 1287, 1287, 1287, 1287, + /* 60 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 70 */ 1287, 1344, 1489, 1287, 1645, 1287, 1287, 1287, 1287, 1287, + /* 80 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 90 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 100 */ 1346, 1287, 1287, 1656, 1656, 1656, 1344, 1287, 1287, 1287, + /* 110 */ 1287, 1287, 1287, 1287, 1441, 1287, 1287, 1287, 1287, 1287, + /* 120 */ 1287, 1287, 1287, 1523, 1287, 1287, 1721, 1287, 1394, 1529, + /* 130 */ 1680, 1287, 1672, 1648, 1662, 1649, 1287, 1706, 1665, 1287, + /* 140 */ 1287, 1287, 1287, 1515, 1287, 1287, 1494, 1491, 1491, 1287, + /* 150 */ 1287, 1346, 1287, 1287, 1346, 1287, 1287, 1346, 1346, 1287, + /* 160 */ 1346, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 170 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1344, 1525, 1287, + /* 180 */ 1344, 1287, 1344, 1287, 1287, 1344, 1287, 1687, 1685, 1287, + /* 190 */ 1687, 1685, 1287, 1287, 1699, 1695, 1678, 1676, 1662, 1287, + /* 200 */ 1287, 1287, 1724, 1712, 1708, 1287, 1287, 1685, 1287, 1287, + /* 210 */ 1685, 1287, 1502, 1287, 1287, 1344, 1287, 1344, 1287, 1410, + /* 220 */ 1287, 1287, 1344, 1287, 1517, 1531, 1444, 1444, 1347, 1292, + /* 230 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 240 */ 1287, 1592, 1698, 1697, 1621, 1620, 1619, 1617, 1591, 1287, + /* 250 */ 1287, 1287, 1287, 1585, 1586, 1584, 1583, 1287, 1287, 1287, + /* 260 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 270 */ 1287, 1287, 1646, 1287, 1709, 1713, 1287, 1287, 1287, 1569, + /* 280 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 290 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 300 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 310 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 320 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 330 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 340 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 350 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 360 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 370 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 380 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1457, 1456, 1287, + /* 390 */ 1287, 1287, 1287, 1287, 1287, 1287, 1374, 1373, 1287, 1287, + /* 400 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 410 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 420 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1669, 1679, + /* 430 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1569, + /* 440 */ 1287, 1696, 1287, 1655, 1651, 1287, 1287, 1647, 1287, 1287, + /* 450 */ 1707, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1641, 1287, + /* 460 */ 1614, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 470 */ 1287, 1579, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 480 */ 1287, 1287, 1287, 1287, 1568, 1287, 1287, 1287, 1287, 1287, + /* 490 */ 1287, 1287, 1438, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 500 */ 1287, 1287, 1287, 1287, 1287, 1423, 1421, 1420, 1419, 1287, + /* 510 */ 1416, 1287, 1287, 1287, 1287, 1287, 1287, 1447, 1446, 1287, + /* 520 */ 1287, 1287, 1287, 1287, 1287, 1367, 1287, 1287, 1287, 1287, + /* 530 */ 1287, 1287, 1287, 1287, 1287, 1358, 1287, 1357, 1287, 1287, + /* 540 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 550 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 560 */ 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, 1287, + /* 570 */ 1287, 1287, }; /********** End of lemon-generated parsing tables *****************************/ @@ -978,208 +995,209 @@ static const char *const yyTokenName[] = { /* 130 */ "VARIABLES", /* 131 */ "BNODES", /* 132 */ "SNODES", - /* 133 */ "LIKE", - /* 134 */ "INDEX", - /* 135 */ "FULLTEXT", - /* 136 */ "FUNCTION", - /* 137 */ "INTERVAL", - /* 138 */ "TOPIC", - /* 139 */ "AS", - /* 140 */ "DESC", - /* 141 */ "DESCRIBE", - /* 142 */ "RESET", - /* 143 */ "QUERY", - /* 144 */ "EXPLAIN", - /* 145 */ "ANALYZE", - /* 146 */ "VERBOSE", - /* 147 */ "NK_BOOL", - /* 148 */ "RATIO", - /* 149 */ "COMPACT", - /* 150 */ "VNODES", - /* 151 */ "IN", - /* 152 */ "OUTPUTTYPE", - /* 153 */ "AGGREGATE", - /* 154 */ "BUFSIZE", - /* 155 */ "STREAM", - /* 156 */ "INTO", - /* 157 */ "TRIGGER", - /* 158 */ "AT_ONCE", - /* 159 */ "WINDOW_CLOSE", - /* 160 */ "WATERMARK", - /* 161 */ "KILL", - /* 162 */ "CONNECTION", - /* 163 */ "MERGE", - /* 164 */ "VGROUP", - /* 165 */ "REDISTRIBUTE", - /* 166 */ "SPLIT", - /* 167 */ "SYNCDB", - /* 168 */ "NULL", - /* 169 */ "NK_QUESTION", - /* 170 */ "NK_ARROW", - /* 171 */ "ROWTS", - /* 172 */ "TBNAME", - /* 173 */ "QSTARTTS", - /* 174 */ "QENDTS", - /* 175 */ "WSTARTTS", - /* 176 */ "WENDTS", - /* 177 */ "WDURATION", - /* 178 */ "CAST", - /* 179 */ "NOW", - /* 180 */ "TODAY", - /* 181 */ "TIMEZONE", - /* 182 */ "COUNT", - /* 183 */ "FIRST", - /* 184 */ "LAST", - /* 185 */ "LAST_ROW", - /* 186 */ "BETWEEN", - /* 187 */ "IS", - /* 188 */ "NK_LT", - /* 189 */ "NK_GT", - /* 190 */ "NK_LE", - /* 191 */ "NK_GE", - /* 192 */ "NK_NE", - /* 193 */ "MATCH", - /* 194 */ "NMATCH", - /* 195 */ "CONTAINS", - /* 196 */ "JOIN", - /* 197 */ "INNER", - /* 198 */ "SELECT", - /* 199 */ "DISTINCT", - /* 200 */ "WHERE", - /* 201 */ "PARTITION", - /* 202 */ "BY", - /* 203 */ "SESSION", - /* 204 */ "STATE_WINDOW", - /* 205 */ "SLIDING", - /* 206 */ "FILL", - /* 207 */ "VALUE", - /* 208 */ "NONE", - /* 209 */ "PREV", - /* 210 */ "LINEAR", - /* 211 */ "NEXT", - /* 212 */ "GROUP", - /* 213 */ "HAVING", - /* 214 */ "ORDER", - /* 215 */ "SLIMIT", - /* 216 */ "SOFFSET", - /* 217 */ "LIMIT", - /* 218 */ "OFFSET", - /* 219 */ "ASC", - /* 220 */ "NULLS", - /* 221 */ "cmd", - /* 222 */ "account_options", - /* 223 */ "alter_account_options", - /* 224 */ "literal", - /* 225 */ "alter_account_option", - /* 226 */ "user_name", - /* 227 */ "dnode_endpoint", - /* 228 */ "dnode_host_name", - /* 229 */ "not_exists_opt", - /* 230 */ "db_name", - /* 231 */ "db_options", - /* 232 */ "exists_opt", - /* 233 */ "alter_db_options", - /* 234 */ "integer_list", - /* 235 */ "variable_list", - /* 236 */ "retention_list", - /* 237 */ "alter_db_option", - /* 238 */ "retention", - /* 239 */ "full_table_name", - /* 240 */ "column_def_list", - /* 241 */ "tags_def_opt", - /* 242 */ "table_options", - /* 243 */ "multi_create_clause", - /* 244 */ "tags_def", - /* 245 */ "multi_drop_clause", - /* 246 */ "alter_table_clause", - /* 247 */ "alter_table_options", - /* 248 */ "column_name", - /* 249 */ "type_name", - /* 250 */ "create_subtable_clause", - /* 251 */ "specific_tags_opt", - /* 252 */ "literal_list", - /* 253 */ "drop_table_clause", - /* 254 */ "col_name_list", - /* 255 */ "table_name", - /* 256 */ "column_def", - /* 257 */ "func_name_list", - /* 258 */ "alter_table_option", - /* 259 */ "col_name", - /* 260 */ "db_name_cond_opt", - /* 261 */ "like_pattern_opt", - /* 262 */ "table_name_cond", - /* 263 */ "from_db_opt", - /* 264 */ "func_name", - /* 265 */ "function_name", - /* 266 */ "index_name", - /* 267 */ "index_options", - /* 268 */ "func_list", - /* 269 */ "duration_literal", - /* 270 */ "sliding_opt", - /* 271 */ "func", - /* 272 */ "expression_list", - /* 273 */ "topic_name", - /* 274 */ "query_expression", - /* 275 */ "analyze_opt", - /* 276 */ "explain_options", - /* 277 */ "agg_func_opt", - /* 278 */ "bufsize_opt", - /* 279 */ "stream_name", - /* 280 */ "stream_options", - /* 281 */ "into_opt", - /* 282 */ "dnode_list", - /* 283 */ "signed", - /* 284 */ "signed_literal", - /* 285 */ "table_alias", - /* 286 */ "column_alias", - /* 287 */ "expression", - /* 288 */ "pseudo_column", - /* 289 */ "column_reference", - /* 290 */ "function_expression", - /* 291 */ "subquery", - /* 292 */ "star_func", - /* 293 */ "star_func_para_list", - /* 294 */ "noarg_func", - /* 295 */ "other_para_list", - /* 296 */ "star_func_para", - /* 297 */ "predicate", - /* 298 */ "compare_op", - /* 299 */ "in_op", - /* 300 */ "in_predicate_value", - /* 301 */ "boolean_value_expression", - /* 302 */ "boolean_primary", - /* 303 */ "common_expression", - /* 304 */ "from_clause", - /* 305 */ "table_reference_list", - /* 306 */ "table_reference", - /* 307 */ "table_primary", - /* 308 */ "joined_table", - /* 309 */ "alias_opt", - /* 310 */ "parenthesized_joined_table", - /* 311 */ "join_type", - /* 312 */ "search_condition", - /* 313 */ "query_specification", - /* 314 */ "set_quantifier_opt", - /* 315 */ "select_list", - /* 316 */ "where_clause_opt", - /* 317 */ "partition_by_clause_opt", - /* 318 */ "twindow_clause_opt", - /* 319 */ "group_by_clause_opt", - /* 320 */ "having_clause_opt", - /* 321 */ "select_sublist", - /* 322 */ "select_item", - /* 323 */ "fill_opt", - /* 324 */ "fill_mode", - /* 325 */ "group_by_list", - /* 326 */ "query_expression_body", - /* 327 */ "order_by_clause_opt", - /* 328 */ "slimit_clause_opt", - /* 329 */ "limit_clause_opt", - /* 330 */ "query_primary", - /* 331 */ "sort_specification_list", - /* 332 */ "sort_specification", - /* 333 */ "ordering_specification_opt", - /* 334 */ "null_ordering_opt", + /* 133 */ "CLUSTER", + /* 134 */ "LIKE", + /* 135 */ "INDEX", + /* 136 */ "FULLTEXT", + /* 137 */ "FUNCTION", + /* 138 */ "INTERVAL", + /* 139 */ "TOPIC", + /* 140 */ "AS", + /* 141 */ "DESC", + /* 142 */ "DESCRIBE", + /* 143 */ "RESET", + /* 144 */ "QUERY", + /* 145 */ "EXPLAIN", + /* 146 */ "ANALYZE", + /* 147 */ "VERBOSE", + /* 148 */ "NK_BOOL", + /* 149 */ "RATIO", + /* 150 */ "COMPACT", + /* 151 */ "VNODES", + /* 152 */ "IN", + /* 153 */ "OUTPUTTYPE", + /* 154 */ "AGGREGATE", + /* 155 */ "BUFSIZE", + /* 156 */ "STREAM", + /* 157 */ "INTO", + /* 158 */ "TRIGGER", + /* 159 */ "AT_ONCE", + /* 160 */ "WINDOW_CLOSE", + /* 161 */ "WATERMARK", + /* 162 */ "KILL", + /* 163 */ "CONNECTION", + /* 164 */ "MERGE", + /* 165 */ "VGROUP", + /* 166 */ "REDISTRIBUTE", + /* 167 */ "SPLIT", + /* 168 */ "SYNCDB", + /* 169 */ "NULL", + /* 170 */ "NK_QUESTION", + /* 171 */ "NK_ARROW", + /* 172 */ "ROWTS", + /* 173 */ "TBNAME", + /* 174 */ "QSTARTTS", + /* 175 */ "QENDTS", + /* 176 */ "WSTARTTS", + /* 177 */ "WENDTS", + /* 178 */ "WDURATION", + /* 179 */ "CAST", + /* 180 */ "NOW", + /* 181 */ "TODAY", + /* 182 */ "TIMEZONE", + /* 183 */ "COUNT", + /* 184 */ "FIRST", + /* 185 */ "LAST", + /* 186 */ "LAST_ROW", + /* 187 */ "BETWEEN", + /* 188 */ "IS", + /* 189 */ "NK_LT", + /* 190 */ "NK_GT", + /* 191 */ "NK_LE", + /* 192 */ "NK_GE", + /* 193 */ "NK_NE", + /* 194 */ "MATCH", + /* 195 */ "NMATCH", + /* 196 */ "CONTAINS", + /* 197 */ "JOIN", + /* 198 */ "INNER", + /* 199 */ "SELECT", + /* 200 */ "DISTINCT", + /* 201 */ "WHERE", + /* 202 */ "PARTITION", + /* 203 */ "BY", + /* 204 */ "SESSION", + /* 205 */ "STATE_WINDOW", + /* 206 */ "SLIDING", + /* 207 */ "FILL", + /* 208 */ "VALUE", + /* 209 */ "NONE", + /* 210 */ "PREV", + /* 211 */ "LINEAR", + /* 212 */ "NEXT", + /* 213 */ "GROUP", + /* 214 */ "HAVING", + /* 215 */ "ORDER", + /* 216 */ "SLIMIT", + /* 217 */ "SOFFSET", + /* 218 */ "LIMIT", + /* 219 */ "OFFSET", + /* 220 */ "ASC", + /* 221 */ "NULLS", + /* 222 */ "cmd", + /* 223 */ "account_options", + /* 224 */ "alter_account_options", + /* 225 */ "literal", + /* 226 */ "alter_account_option", + /* 227 */ "user_name", + /* 228 */ "dnode_endpoint", + /* 229 */ "dnode_host_name", + /* 230 */ "not_exists_opt", + /* 231 */ "db_name", + /* 232 */ "db_options", + /* 233 */ "exists_opt", + /* 234 */ "alter_db_options", + /* 235 */ "integer_list", + /* 236 */ "variable_list", + /* 237 */ "retention_list", + /* 238 */ "alter_db_option", + /* 239 */ "retention", + /* 240 */ "full_table_name", + /* 241 */ "column_def_list", + /* 242 */ "tags_def_opt", + /* 243 */ "table_options", + /* 244 */ "multi_create_clause", + /* 245 */ "tags_def", + /* 246 */ "multi_drop_clause", + /* 247 */ "alter_table_clause", + /* 248 */ "alter_table_options", + /* 249 */ "column_name", + /* 250 */ "type_name", + /* 251 */ "create_subtable_clause", + /* 252 */ "specific_tags_opt", + /* 253 */ "literal_list", + /* 254 */ "drop_table_clause", + /* 255 */ "col_name_list", + /* 256 */ "table_name", + /* 257 */ "column_def", + /* 258 */ "func_name_list", + /* 259 */ "alter_table_option", + /* 260 */ "col_name", + /* 261 */ "db_name_cond_opt", + /* 262 */ "like_pattern_opt", + /* 263 */ "table_name_cond", + /* 264 */ "from_db_opt", + /* 265 */ "func_name", + /* 266 */ "function_name", + /* 267 */ "index_name", + /* 268 */ "index_options", + /* 269 */ "func_list", + /* 270 */ "duration_literal", + /* 271 */ "sliding_opt", + /* 272 */ "func", + /* 273 */ "expression_list", + /* 274 */ "topic_name", + /* 275 */ "query_expression", + /* 276 */ "analyze_opt", + /* 277 */ "explain_options", + /* 278 */ "agg_func_opt", + /* 279 */ "bufsize_opt", + /* 280 */ "stream_name", + /* 281 */ "stream_options", + /* 282 */ "into_opt", + /* 283 */ "dnode_list", + /* 284 */ "signed", + /* 285 */ "signed_literal", + /* 286 */ "table_alias", + /* 287 */ "column_alias", + /* 288 */ "expression", + /* 289 */ "pseudo_column", + /* 290 */ "column_reference", + /* 291 */ "function_expression", + /* 292 */ "subquery", + /* 293 */ "star_func", + /* 294 */ "star_func_para_list", + /* 295 */ "noarg_func", + /* 296 */ "other_para_list", + /* 297 */ "star_func_para", + /* 298 */ "predicate", + /* 299 */ "compare_op", + /* 300 */ "in_op", + /* 301 */ "in_predicate_value", + /* 302 */ "boolean_value_expression", + /* 303 */ "boolean_primary", + /* 304 */ "common_expression", + /* 305 */ "from_clause", + /* 306 */ "table_reference_list", + /* 307 */ "table_reference", + /* 308 */ "table_primary", + /* 309 */ "joined_table", + /* 310 */ "alias_opt", + /* 311 */ "parenthesized_joined_table", + /* 312 */ "join_type", + /* 313 */ "search_condition", + /* 314 */ "query_specification", + /* 315 */ "set_quantifier_opt", + /* 316 */ "select_list", + /* 317 */ "where_clause_opt", + /* 318 */ "partition_by_clause_opt", + /* 319 */ "twindow_clause_opt", + /* 320 */ "group_by_clause_opt", + /* 321 */ "having_clause_opt", + /* 322 */ "select_sublist", + /* 323 */ "select_item", + /* 324 */ "fill_opt", + /* 325 */ "fill_mode", + /* 326 */ "group_by_list", + /* 327 */ "query_expression_body", + /* 328 */ "order_by_clause_opt", + /* 329 */ "slimit_clause_opt", + /* 330 */ "limit_clause_opt", + /* 331 */ "query_primary", + /* 332 */ "sort_specification_list", + /* 333 */ "sort_specification", + /* 334 */ "ordering_specification_opt", + /* 335 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1385,243 +1403,245 @@ static const char *const yyRuleName[] = { /* 195 */ "cmd ::= SHOW VARIABLES", /* 196 */ "cmd ::= SHOW BNODES", /* 197 */ "cmd ::= SHOW SNODES", - /* 198 */ "db_name_cond_opt ::=", - /* 199 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 200 */ "like_pattern_opt ::=", - /* 201 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 202 */ "table_name_cond ::= table_name", - /* 203 */ "from_db_opt ::=", - /* 204 */ "from_db_opt ::= FROM db_name", - /* 205 */ "func_name_list ::= func_name", - /* 206 */ "func_name_list ::= func_name_list NK_COMMA func_name", - /* 207 */ "func_name ::= function_name", - /* 208 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", - /* 209 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", - /* 210 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", - /* 211 */ "index_options ::=", - /* 212 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", - /* 213 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", - /* 214 */ "func_list ::= func", - /* 215 */ "func_list ::= func_list NK_COMMA func", - /* 216 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 217 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", - /* 218 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", - /* 219 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 220 */ "cmd ::= DESC full_table_name", - /* 221 */ "cmd ::= DESCRIBE full_table_name", - /* 222 */ "cmd ::= RESET QUERY CACHE", - /* 223 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", - /* 224 */ "analyze_opt ::=", - /* 225 */ "analyze_opt ::= ANALYZE", - /* 226 */ "explain_options ::=", - /* 227 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 228 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 229 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", - /* 230 */ "cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 231 */ "cmd ::= DROP FUNCTION function_name", - /* 232 */ "agg_func_opt ::=", - /* 233 */ "agg_func_opt ::= AGGREGATE", - /* 234 */ "bufsize_opt ::=", - /* 235 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 236 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", - /* 237 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 238 */ "into_opt ::=", - /* 239 */ "into_opt ::= INTO full_table_name", - /* 240 */ "stream_options ::=", - /* 241 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 242 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 243 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 244 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 245 */ "cmd ::= KILL QUERY NK_INTEGER", - /* 246 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 247 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 248 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 249 */ "dnode_list ::= DNODE NK_INTEGER", - /* 250 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 251 */ "cmd ::= SYNCDB db_name REPLICA", - /* 252 */ "cmd ::= query_expression", - /* 253 */ "literal ::= NK_INTEGER", - /* 254 */ "literal ::= NK_FLOAT", - /* 255 */ "literal ::= NK_STRING", - /* 256 */ "literal ::= NK_BOOL", - /* 257 */ "literal ::= TIMESTAMP NK_STRING", - /* 258 */ "literal ::= duration_literal", - /* 259 */ "literal ::= NULL", - /* 260 */ "literal ::= NK_QUESTION", - /* 261 */ "duration_literal ::= NK_VARIABLE", - /* 262 */ "signed ::= NK_INTEGER", - /* 263 */ "signed ::= NK_PLUS NK_INTEGER", - /* 264 */ "signed ::= NK_MINUS NK_INTEGER", - /* 265 */ "signed ::= NK_FLOAT", - /* 266 */ "signed ::= NK_PLUS NK_FLOAT", - /* 267 */ "signed ::= NK_MINUS NK_FLOAT", - /* 268 */ "signed_literal ::= signed", - /* 269 */ "signed_literal ::= NK_STRING", - /* 270 */ "signed_literal ::= NK_BOOL", - /* 271 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 272 */ "signed_literal ::= duration_literal", - /* 273 */ "signed_literal ::= NULL", - /* 274 */ "literal_list ::= signed_literal", - /* 275 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 276 */ "db_name ::= NK_ID", - /* 277 */ "table_name ::= NK_ID", - /* 278 */ "column_name ::= NK_ID", - /* 279 */ "function_name ::= NK_ID", - /* 280 */ "table_alias ::= NK_ID", - /* 281 */ "column_alias ::= NK_ID", - /* 282 */ "user_name ::= NK_ID", - /* 283 */ "index_name ::= NK_ID", - /* 284 */ "topic_name ::= NK_ID", - /* 285 */ "stream_name ::= NK_ID", - /* 286 */ "expression ::= literal", - /* 287 */ "expression ::= pseudo_column", - /* 288 */ "expression ::= column_reference", - /* 289 */ "expression ::= function_expression", - /* 290 */ "expression ::= subquery", - /* 291 */ "expression ::= NK_LP expression NK_RP", - /* 292 */ "expression ::= NK_PLUS expression", - /* 293 */ "expression ::= NK_MINUS expression", - /* 294 */ "expression ::= expression NK_PLUS expression", - /* 295 */ "expression ::= expression NK_MINUS expression", - /* 296 */ "expression ::= expression NK_STAR expression", - /* 297 */ "expression ::= expression NK_SLASH expression", - /* 298 */ "expression ::= expression NK_REM expression", - /* 299 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 300 */ "expression_list ::= expression", - /* 301 */ "expression_list ::= expression_list NK_COMMA expression", - /* 302 */ "column_reference ::= column_name", - /* 303 */ "column_reference ::= table_name NK_DOT column_name", - /* 304 */ "pseudo_column ::= ROWTS", - /* 305 */ "pseudo_column ::= TBNAME", - /* 306 */ "pseudo_column ::= QSTARTTS", - /* 307 */ "pseudo_column ::= QENDTS", - /* 308 */ "pseudo_column ::= WSTARTTS", - /* 309 */ "pseudo_column ::= WENDTS", - /* 310 */ "pseudo_column ::= WDURATION", - /* 311 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 312 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 313 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", - /* 314 */ "function_expression ::= noarg_func NK_LP NK_RP", - /* 315 */ "noarg_func ::= NOW", - /* 316 */ "noarg_func ::= TODAY", - /* 317 */ "noarg_func ::= TIMEZONE", - /* 318 */ "star_func ::= COUNT", - /* 319 */ "star_func ::= FIRST", - /* 320 */ "star_func ::= LAST", - /* 321 */ "star_func ::= LAST_ROW", - /* 322 */ "star_func_para_list ::= NK_STAR", - /* 323 */ "star_func_para_list ::= other_para_list", - /* 324 */ "other_para_list ::= star_func_para", - /* 325 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 326 */ "star_func_para ::= expression", - /* 327 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 328 */ "predicate ::= expression compare_op expression", - /* 329 */ "predicate ::= expression BETWEEN expression AND expression", - /* 330 */ "predicate ::= expression NOT BETWEEN expression AND expression", - /* 331 */ "predicate ::= expression IS NULL", - /* 332 */ "predicate ::= expression IS NOT NULL", - /* 333 */ "predicate ::= expression in_op in_predicate_value", - /* 334 */ "compare_op ::= NK_LT", - /* 335 */ "compare_op ::= NK_GT", - /* 336 */ "compare_op ::= NK_LE", - /* 337 */ "compare_op ::= NK_GE", - /* 338 */ "compare_op ::= NK_NE", - /* 339 */ "compare_op ::= NK_EQ", - /* 340 */ "compare_op ::= LIKE", - /* 341 */ "compare_op ::= NOT LIKE", - /* 342 */ "compare_op ::= MATCH", - /* 343 */ "compare_op ::= NMATCH", - /* 344 */ "compare_op ::= CONTAINS", - /* 345 */ "in_op ::= IN", - /* 346 */ "in_op ::= NOT IN", - /* 347 */ "in_predicate_value ::= NK_LP expression_list NK_RP", - /* 348 */ "boolean_value_expression ::= boolean_primary", - /* 349 */ "boolean_value_expression ::= NOT boolean_primary", - /* 350 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 351 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 352 */ "boolean_primary ::= predicate", - /* 353 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 354 */ "common_expression ::= expression", - /* 355 */ "common_expression ::= boolean_value_expression", - /* 356 */ "from_clause ::= FROM table_reference_list", - /* 357 */ "table_reference_list ::= table_reference", - /* 358 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 359 */ "table_reference ::= table_primary", - /* 360 */ "table_reference ::= joined_table", - /* 361 */ "table_primary ::= table_name alias_opt", - /* 362 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 363 */ "table_primary ::= subquery alias_opt", - /* 364 */ "table_primary ::= parenthesized_joined_table", - /* 365 */ "alias_opt ::=", - /* 366 */ "alias_opt ::= table_alias", - /* 367 */ "alias_opt ::= AS table_alias", - /* 368 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 369 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 370 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 371 */ "join_type ::=", - /* 372 */ "join_type ::= INNER", - /* 373 */ "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", - /* 374 */ "set_quantifier_opt ::=", - /* 375 */ "set_quantifier_opt ::= DISTINCT", - /* 376 */ "set_quantifier_opt ::= ALL", - /* 377 */ "select_list ::= NK_STAR", - /* 378 */ "select_list ::= select_sublist", - /* 379 */ "select_sublist ::= select_item", - /* 380 */ "select_sublist ::= select_sublist NK_COMMA select_item", - /* 381 */ "select_item ::= common_expression", - /* 382 */ "select_item ::= common_expression column_alias", - /* 383 */ "select_item ::= common_expression AS column_alias", - /* 384 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 385 */ "where_clause_opt ::=", - /* 386 */ "where_clause_opt ::= WHERE search_condition", - /* 387 */ "partition_by_clause_opt ::=", - /* 388 */ "partition_by_clause_opt ::= PARTITION BY expression_list", - /* 389 */ "twindow_clause_opt ::=", - /* 390 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 391 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", - /* 392 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 393 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 394 */ "sliding_opt ::=", - /* 395 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 396 */ "fill_opt ::=", - /* 397 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 398 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 399 */ "fill_mode ::= NONE", - /* 400 */ "fill_mode ::= PREV", - /* 401 */ "fill_mode ::= NULL", - /* 402 */ "fill_mode ::= LINEAR", - /* 403 */ "fill_mode ::= NEXT", - /* 404 */ "group_by_clause_opt ::=", - /* 405 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 406 */ "group_by_list ::= expression", - /* 407 */ "group_by_list ::= group_by_list NK_COMMA expression", - /* 408 */ "having_clause_opt ::=", - /* 409 */ "having_clause_opt ::= HAVING search_condition", - /* 410 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 411 */ "query_expression_body ::= query_primary", - /* 412 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", - /* 413 */ "query_primary ::= query_specification", - /* 414 */ "order_by_clause_opt ::=", - /* 415 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 416 */ "slimit_clause_opt ::=", - /* 417 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 418 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 419 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 420 */ "limit_clause_opt ::=", - /* 421 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 422 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 423 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 424 */ "subquery ::= NK_LP query_expression NK_RP", - /* 425 */ "search_condition ::= common_expression", - /* 426 */ "sort_specification_list ::= sort_specification", - /* 427 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 428 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", - /* 429 */ "ordering_specification_opt ::=", - /* 430 */ "ordering_specification_opt ::= ASC", - /* 431 */ "ordering_specification_opt ::= DESC", - /* 432 */ "null_ordering_opt ::=", - /* 433 */ "null_ordering_opt ::= NULLS FIRST", - /* 434 */ "null_ordering_opt ::= NULLS LAST", + /* 198 */ "cmd ::= SHOW CLUSTER", + /* 199 */ "db_name_cond_opt ::=", + /* 200 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 201 */ "like_pattern_opt ::=", + /* 202 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 203 */ "table_name_cond ::= table_name", + /* 204 */ "from_db_opt ::=", + /* 205 */ "from_db_opt ::= FROM db_name", + /* 206 */ "func_name_list ::= func_name", + /* 207 */ "func_name_list ::= func_name_list NK_COMMA func_name", + /* 208 */ "func_name ::= function_name", + /* 209 */ "cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options", + /* 210 */ "cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP", + /* 211 */ "cmd ::= DROP INDEX exists_opt index_name ON table_name", + /* 212 */ "index_options ::=", + /* 213 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt", + /* 214 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt", + /* 215 */ "func_list ::= func", + /* 216 */ "func_list ::= func_list NK_COMMA func", + /* 217 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 218 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression", + /* 219 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name", + /* 220 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 221 */ "cmd ::= DESC full_table_name", + /* 222 */ "cmd ::= DESCRIBE full_table_name", + /* 223 */ "cmd ::= RESET QUERY CACHE", + /* 224 */ "cmd ::= EXPLAIN analyze_opt explain_options query_expression", + /* 225 */ "analyze_opt ::=", + /* 226 */ "analyze_opt ::= ANALYZE", + /* 227 */ "explain_options ::=", + /* 228 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 229 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 230 */ "cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP", + /* 231 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 232 */ "cmd ::= DROP FUNCTION function_name", + /* 233 */ "agg_func_opt ::=", + /* 234 */ "agg_func_opt ::= AGGREGATE", + /* 235 */ "bufsize_opt ::=", + /* 236 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 237 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression", + /* 238 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 239 */ "into_opt ::=", + /* 240 */ "into_opt ::= INTO full_table_name", + /* 241 */ "stream_options ::=", + /* 242 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 243 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 244 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 245 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 246 */ "cmd ::= KILL QUERY NK_INTEGER", + /* 247 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 248 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 249 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 250 */ "dnode_list ::= DNODE NK_INTEGER", + /* 251 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 252 */ "cmd ::= SYNCDB db_name REPLICA", + /* 253 */ "cmd ::= query_expression", + /* 254 */ "literal ::= NK_INTEGER", + /* 255 */ "literal ::= NK_FLOAT", + /* 256 */ "literal ::= NK_STRING", + /* 257 */ "literal ::= NK_BOOL", + /* 258 */ "literal ::= TIMESTAMP NK_STRING", + /* 259 */ "literal ::= duration_literal", + /* 260 */ "literal ::= NULL", + /* 261 */ "literal ::= NK_QUESTION", + /* 262 */ "duration_literal ::= NK_VARIABLE", + /* 263 */ "signed ::= NK_INTEGER", + /* 264 */ "signed ::= NK_PLUS NK_INTEGER", + /* 265 */ "signed ::= NK_MINUS NK_INTEGER", + /* 266 */ "signed ::= NK_FLOAT", + /* 267 */ "signed ::= NK_PLUS NK_FLOAT", + /* 268 */ "signed ::= NK_MINUS NK_FLOAT", + /* 269 */ "signed_literal ::= signed", + /* 270 */ "signed_literal ::= NK_STRING", + /* 271 */ "signed_literal ::= NK_BOOL", + /* 272 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 273 */ "signed_literal ::= duration_literal", + /* 274 */ "signed_literal ::= NULL", + /* 275 */ "literal_list ::= signed_literal", + /* 276 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 277 */ "db_name ::= NK_ID", + /* 278 */ "table_name ::= NK_ID", + /* 279 */ "column_name ::= NK_ID", + /* 280 */ "function_name ::= NK_ID", + /* 281 */ "table_alias ::= NK_ID", + /* 282 */ "column_alias ::= NK_ID", + /* 283 */ "user_name ::= NK_ID", + /* 284 */ "index_name ::= NK_ID", + /* 285 */ "topic_name ::= NK_ID", + /* 286 */ "stream_name ::= NK_ID", + /* 287 */ "expression ::= literal", + /* 288 */ "expression ::= pseudo_column", + /* 289 */ "expression ::= column_reference", + /* 290 */ "expression ::= function_expression", + /* 291 */ "expression ::= subquery", + /* 292 */ "expression ::= NK_LP expression NK_RP", + /* 293 */ "expression ::= NK_PLUS expression", + /* 294 */ "expression ::= NK_MINUS expression", + /* 295 */ "expression ::= expression NK_PLUS expression", + /* 296 */ "expression ::= expression NK_MINUS expression", + /* 297 */ "expression ::= expression NK_STAR expression", + /* 298 */ "expression ::= expression NK_SLASH expression", + /* 299 */ "expression ::= expression NK_REM expression", + /* 300 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 301 */ "expression_list ::= expression", + /* 302 */ "expression_list ::= expression_list NK_COMMA expression", + /* 303 */ "column_reference ::= column_name", + /* 304 */ "column_reference ::= table_name NK_DOT column_name", + /* 305 */ "pseudo_column ::= ROWTS", + /* 306 */ "pseudo_column ::= TBNAME", + /* 307 */ "pseudo_column ::= QSTARTTS", + /* 308 */ "pseudo_column ::= QENDTS", + /* 309 */ "pseudo_column ::= WSTARTTS", + /* 310 */ "pseudo_column ::= WENDTS", + /* 311 */ "pseudo_column ::= WDURATION", + /* 312 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 313 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 314 */ "function_expression ::= CAST NK_LP expression AS type_name NK_RP", + /* 315 */ "function_expression ::= noarg_func NK_LP NK_RP", + /* 316 */ "noarg_func ::= NOW", + /* 317 */ "noarg_func ::= TODAY", + /* 318 */ "noarg_func ::= TIMEZONE", + /* 319 */ "star_func ::= COUNT", + /* 320 */ "star_func ::= FIRST", + /* 321 */ "star_func ::= LAST", + /* 322 */ "star_func ::= LAST_ROW", + /* 323 */ "star_func_para_list ::= NK_STAR", + /* 324 */ "star_func_para_list ::= other_para_list", + /* 325 */ "other_para_list ::= star_func_para", + /* 326 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 327 */ "star_func_para ::= expression", + /* 328 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 329 */ "predicate ::= expression compare_op expression", + /* 330 */ "predicate ::= expression BETWEEN expression AND expression", + /* 331 */ "predicate ::= expression NOT BETWEEN expression AND expression", + /* 332 */ "predicate ::= expression IS NULL", + /* 333 */ "predicate ::= expression IS NOT NULL", + /* 334 */ "predicate ::= expression in_op in_predicate_value", + /* 335 */ "compare_op ::= NK_LT", + /* 336 */ "compare_op ::= NK_GT", + /* 337 */ "compare_op ::= NK_LE", + /* 338 */ "compare_op ::= NK_GE", + /* 339 */ "compare_op ::= NK_NE", + /* 340 */ "compare_op ::= NK_EQ", + /* 341 */ "compare_op ::= LIKE", + /* 342 */ "compare_op ::= NOT LIKE", + /* 343 */ "compare_op ::= MATCH", + /* 344 */ "compare_op ::= NMATCH", + /* 345 */ "compare_op ::= CONTAINS", + /* 346 */ "in_op ::= IN", + /* 347 */ "in_op ::= NOT IN", + /* 348 */ "in_predicate_value ::= NK_LP expression_list NK_RP", + /* 349 */ "boolean_value_expression ::= boolean_primary", + /* 350 */ "boolean_value_expression ::= NOT boolean_primary", + /* 351 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 352 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 353 */ "boolean_primary ::= predicate", + /* 354 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 355 */ "common_expression ::= expression", + /* 356 */ "common_expression ::= boolean_value_expression", + /* 357 */ "from_clause ::= FROM table_reference_list", + /* 358 */ "table_reference_list ::= table_reference", + /* 359 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 360 */ "table_reference ::= table_primary", + /* 361 */ "table_reference ::= joined_table", + /* 362 */ "table_primary ::= table_name alias_opt", + /* 363 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 364 */ "table_primary ::= subquery alias_opt", + /* 365 */ "table_primary ::= parenthesized_joined_table", + /* 366 */ "alias_opt ::=", + /* 367 */ "alias_opt ::= table_alias", + /* 368 */ "alias_opt ::= AS table_alias", + /* 369 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 370 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 371 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 372 */ "join_type ::=", + /* 373 */ "join_type ::= INNER", + /* 374 */ "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", + /* 375 */ "set_quantifier_opt ::=", + /* 376 */ "set_quantifier_opt ::= DISTINCT", + /* 377 */ "set_quantifier_opt ::= ALL", + /* 378 */ "select_list ::= NK_STAR", + /* 379 */ "select_list ::= select_sublist", + /* 380 */ "select_sublist ::= select_item", + /* 381 */ "select_sublist ::= select_sublist NK_COMMA select_item", + /* 382 */ "select_item ::= common_expression", + /* 383 */ "select_item ::= common_expression column_alias", + /* 384 */ "select_item ::= common_expression AS column_alias", + /* 385 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 386 */ "where_clause_opt ::=", + /* 387 */ "where_clause_opt ::= WHERE search_condition", + /* 388 */ "partition_by_clause_opt ::=", + /* 389 */ "partition_by_clause_opt ::= PARTITION BY expression_list", + /* 390 */ "twindow_clause_opt ::=", + /* 391 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 392 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP", + /* 393 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 394 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 395 */ "sliding_opt ::=", + /* 396 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 397 */ "fill_opt ::=", + /* 398 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 399 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 400 */ "fill_mode ::= NONE", + /* 401 */ "fill_mode ::= PREV", + /* 402 */ "fill_mode ::= NULL", + /* 403 */ "fill_mode ::= LINEAR", + /* 404 */ "fill_mode ::= NEXT", + /* 405 */ "group_by_clause_opt ::=", + /* 406 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 407 */ "group_by_list ::= expression", + /* 408 */ "group_by_list ::= group_by_list NK_COMMA expression", + /* 409 */ "having_clause_opt ::=", + /* 410 */ "having_clause_opt ::= HAVING search_condition", + /* 411 */ "query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 412 */ "query_expression_body ::= query_primary", + /* 413 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", + /* 414 */ "query_expression_body ::= query_expression_body UNION query_expression_body", + /* 415 */ "query_primary ::= query_specification", + /* 416 */ "order_by_clause_opt ::=", + /* 417 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 418 */ "slimit_clause_opt ::=", + /* 419 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 420 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 421 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 422 */ "limit_clause_opt ::=", + /* 423 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 424 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 425 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 426 */ "subquery ::= NK_LP query_expression NK_RP", + /* 427 */ "search_condition ::= common_expression", + /* 428 */ "sort_specification_list ::= sort_specification", + /* 429 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 430 */ "sort_specification ::= expression ordering_specification_opt null_ordering_opt", + /* 431 */ "ordering_specification_opt ::=", + /* 432 */ "ordering_specification_opt ::= ASC", + /* 433 */ "ordering_specification_opt ::= DESC", + /* 434 */ "null_ordering_opt ::=", + /* 435 */ "null_ordering_opt ::= NULLS FIRST", + /* 436 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -1748,164 +1768,164 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 221: /* cmd */ - case 224: /* literal */ - case 231: /* db_options */ - case 233: /* alter_db_options */ - case 238: /* retention */ - case 239: /* full_table_name */ - case 242: /* table_options */ - case 246: /* alter_table_clause */ - case 247: /* alter_table_options */ - case 250: /* create_subtable_clause */ - case 253: /* drop_table_clause */ - case 256: /* column_def */ - case 259: /* col_name */ - case 260: /* db_name_cond_opt */ - case 261: /* like_pattern_opt */ - case 262: /* table_name_cond */ - case 263: /* from_db_opt */ - case 264: /* func_name */ - case 267: /* index_options */ - case 269: /* duration_literal */ - case 270: /* sliding_opt */ - case 271: /* func */ - case 274: /* query_expression */ - case 276: /* explain_options */ - case 280: /* stream_options */ - case 281: /* into_opt */ - case 283: /* signed */ - case 284: /* signed_literal */ - case 287: /* expression */ - case 288: /* pseudo_column */ - case 289: /* column_reference */ - case 290: /* function_expression */ - case 291: /* subquery */ - case 296: /* star_func_para */ - case 297: /* predicate */ - case 300: /* in_predicate_value */ - case 301: /* boolean_value_expression */ - case 302: /* boolean_primary */ - case 303: /* common_expression */ - case 304: /* from_clause */ - case 305: /* table_reference_list */ - case 306: /* table_reference */ - case 307: /* table_primary */ - case 308: /* joined_table */ - case 310: /* parenthesized_joined_table */ - case 312: /* search_condition */ - case 313: /* query_specification */ - case 316: /* where_clause_opt */ - case 318: /* twindow_clause_opt */ - case 320: /* having_clause_opt */ - case 322: /* select_item */ - case 323: /* fill_opt */ - case 326: /* query_expression_body */ - case 328: /* slimit_clause_opt */ - case 329: /* limit_clause_opt */ - case 330: /* query_primary */ - case 332: /* sort_specification */ + case 222: /* cmd */ + case 225: /* literal */ + case 232: /* db_options */ + case 234: /* alter_db_options */ + case 239: /* retention */ + case 240: /* full_table_name */ + case 243: /* table_options */ + case 247: /* alter_table_clause */ + case 248: /* alter_table_options */ + case 251: /* create_subtable_clause */ + case 254: /* drop_table_clause */ + case 257: /* column_def */ + case 260: /* col_name */ + case 261: /* db_name_cond_opt */ + case 262: /* like_pattern_opt */ + case 263: /* table_name_cond */ + case 264: /* from_db_opt */ + case 265: /* func_name */ + case 268: /* index_options */ + case 270: /* duration_literal */ + case 271: /* sliding_opt */ + case 272: /* func */ + case 275: /* query_expression */ + case 277: /* explain_options */ + case 281: /* stream_options */ + case 282: /* into_opt */ + case 284: /* signed */ + case 285: /* signed_literal */ + case 288: /* expression */ + case 289: /* pseudo_column */ + case 290: /* column_reference */ + case 291: /* function_expression */ + case 292: /* subquery */ + case 297: /* star_func_para */ + case 298: /* predicate */ + case 301: /* in_predicate_value */ + case 302: /* boolean_value_expression */ + case 303: /* boolean_primary */ + case 304: /* common_expression */ + case 305: /* from_clause */ + case 306: /* table_reference_list */ + case 307: /* table_reference */ + case 308: /* table_primary */ + case 309: /* joined_table */ + case 311: /* parenthesized_joined_table */ + case 313: /* search_condition */ + case 314: /* query_specification */ + case 317: /* where_clause_opt */ + case 319: /* twindow_clause_opt */ + case 321: /* having_clause_opt */ + case 323: /* select_item */ + case 324: /* fill_opt */ + case 327: /* query_expression_body */ + case 329: /* slimit_clause_opt */ + case 330: /* limit_clause_opt */ + case 331: /* query_primary */ + case 333: /* sort_specification */ { - nodesDestroyNode((yypminor->yy42)); + nodesDestroyNode((yypminor->yy392)); } break; - case 222: /* account_options */ - case 223: /* alter_account_options */ - case 225: /* alter_account_option */ - case 278: /* bufsize_opt */ + case 223: /* account_options */ + case 224: /* alter_account_options */ + case 226: /* alter_account_option */ + case 279: /* bufsize_opt */ { } break; - case 226: /* user_name */ - case 227: /* dnode_endpoint */ - case 228: /* dnode_host_name */ - case 230: /* db_name */ - case 248: /* column_name */ - case 255: /* table_name */ - case 265: /* function_name */ - case 266: /* index_name */ - case 273: /* topic_name */ - case 279: /* stream_name */ - case 285: /* table_alias */ - case 286: /* column_alias */ - case 292: /* star_func */ - case 294: /* noarg_func */ - case 309: /* alias_opt */ + case 227: /* user_name */ + case 228: /* dnode_endpoint */ + case 229: /* dnode_host_name */ + case 231: /* db_name */ + case 249: /* column_name */ + case 256: /* table_name */ + case 266: /* function_name */ + case 267: /* index_name */ + case 274: /* topic_name */ + case 280: /* stream_name */ + case 286: /* table_alias */ + case 287: /* column_alias */ + case 293: /* star_func */ + case 295: /* noarg_func */ + case 310: /* alias_opt */ { } break; - case 229: /* not_exists_opt */ - case 232: /* exists_opt */ - case 275: /* analyze_opt */ - case 277: /* agg_func_opt */ - case 314: /* set_quantifier_opt */ + case 230: /* not_exists_opt */ + case 233: /* exists_opt */ + case 276: /* analyze_opt */ + case 278: /* agg_func_opt */ + case 315: /* set_quantifier_opt */ { } break; - case 234: /* integer_list */ - case 235: /* variable_list */ - case 236: /* retention_list */ - case 240: /* column_def_list */ - case 241: /* tags_def_opt */ - case 243: /* multi_create_clause */ - case 244: /* tags_def */ - case 245: /* multi_drop_clause */ - case 251: /* specific_tags_opt */ - case 252: /* literal_list */ - case 254: /* col_name_list */ - case 257: /* func_name_list */ - case 268: /* func_list */ - case 272: /* expression_list */ - case 282: /* dnode_list */ - case 293: /* star_func_para_list */ - case 295: /* other_para_list */ - case 315: /* select_list */ - case 317: /* partition_by_clause_opt */ - case 319: /* group_by_clause_opt */ - case 321: /* select_sublist */ - case 325: /* group_by_list */ - case 327: /* order_by_clause_opt */ - case 331: /* sort_specification_list */ + case 235: /* integer_list */ + case 236: /* variable_list */ + case 237: /* retention_list */ + case 241: /* column_def_list */ + case 242: /* tags_def_opt */ + case 244: /* multi_create_clause */ + case 245: /* tags_def */ + case 246: /* multi_drop_clause */ + case 252: /* specific_tags_opt */ + case 253: /* literal_list */ + case 255: /* col_name_list */ + case 258: /* func_name_list */ + case 269: /* func_list */ + case 273: /* expression_list */ + case 283: /* dnode_list */ + case 294: /* star_func_para_list */ + case 296: /* other_para_list */ + case 316: /* select_list */ + case 318: /* partition_by_clause_opt */ + case 320: /* group_by_clause_opt */ + case 322: /* select_sublist */ + case 326: /* group_by_list */ + case 328: /* order_by_clause_opt */ + case 332: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy244)); + nodesDestroyList((yypminor->yy376)); } break; - case 237: /* alter_db_option */ - case 258: /* alter_table_option */ + case 238: /* alter_db_option */ + case 259: /* alter_table_option */ { } break; - case 249: /* type_name */ + case 250: /* type_name */ { } break; - case 298: /* compare_op */ - case 299: /* in_op */ + case 299: /* compare_op */ + case 300: /* in_op */ { } break; - case 311: /* join_type */ + case 312: /* join_type */ { } break; - case 324: /* fill_mode */ + case 325: /* fill_mode */ { } break; - case 333: /* ordering_specification_opt */ + case 334: /* ordering_specification_opt */ { } break; - case 334: /* null_ordering_opt */ + case 335: /* null_ordering_opt */ { } @@ -2204,441 +2224,443 @@ static const struct { YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */ } yyRuleInfo[] = { - { 221, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 221, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 222, 0 }, /* (2) account_options ::= */ - { 222, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 222, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 222, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 222, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 222, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 222, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 222, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 222, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 222, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 223, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 223, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 225, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 225, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 225, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 225, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 225, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 225, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 225, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 225, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 225, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 225, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 221, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ - { 221, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 221, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ - { 221, -3 }, /* (27) cmd ::= DROP USER user_name */ - { 221, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ - { 221, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ - { 221, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ - { 221, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ - { 221, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 221, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 221, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ - { 221, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 227, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ - { 228, -1 }, /* (37) dnode_host_name ::= NK_ID */ - { 228, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ - { 221, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ - { 221, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 221, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (43) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (44) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (45) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (46) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (47) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (48) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 221, -5 }, /* (49) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 221, -4 }, /* (50) cmd ::= DROP DATABASE exists_opt db_name */ - { 221, -2 }, /* (51) cmd ::= USE db_name */ - { 221, -4 }, /* (52) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 229, -3 }, /* (53) not_exists_opt ::= IF NOT EXISTS */ - { 229, 0 }, /* (54) not_exists_opt ::= */ - { 232, -2 }, /* (55) exists_opt ::= IF EXISTS */ - { 232, 0 }, /* (56) exists_opt ::= */ - { 231, 0 }, /* (57) db_options ::= */ - { 231, -3 }, /* (58) db_options ::= db_options BLOCKS NK_INTEGER */ - { 231, -3 }, /* (59) db_options ::= db_options CACHE NK_INTEGER */ - { 231, -3 }, /* (60) db_options ::= db_options CACHELAST NK_INTEGER */ - { 231, -3 }, /* (61) db_options ::= db_options COMP NK_INTEGER */ - { 231, -3 }, /* (62) db_options ::= db_options DAYS NK_INTEGER */ - { 231, -3 }, /* (63) db_options ::= db_options DAYS NK_VARIABLE */ - { 231, -3 }, /* (64) db_options ::= db_options FSYNC NK_INTEGER */ - { 231, -3 }, /* (65) db_options ::= db_options MAXROWS NK_INTEGER */ - { 231, -3 }, /* (66) db_options ::= db_options MINROWS NK_INTEGER */ - { 231, -3 }, /* (67) db_options ::= db_options KEEP integer_list */ - { 231, -3 }, /* (68) db_options ::= db_options KEEP variable_list */ - { 231, -3 }, /* (69) db_options ::= db_options PRECISION NK_STRING */ - { 231, -3 }, /* (70) db_options ::= db_options QUORUM NK_INTEGER */ - { 231, -3 }, /* (71) db_options ::= db_options REPLICA NK_INTEGER */ - { 231, -3 }, /* (72) db_options ::= db_options TTL NK_INTEGER */ - { 231, -3 }, /* (73) db_options ::= db_options WAL NK_INTEGER */ - { 231, -3 }, /* (74) db_options ::= db_options VGROUPS NK_INTEGER */ - { 231, -3 }, /* (75) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 231, -3 }, /* (76) db_options ::= db_options STREAM_MODE NK_INTEGER */ - { 231, -3 }, /* (77) db_options ::= db_options RETENTIONS retention_list */ - { 231, -3 }, /* (78) db_options ::= db_options STRICT NK_INTEGER */ - { 233, -1 }, /* (79) alter_db_options ::= alter_db_option */ - { 233, -2 }, /* (80) alter_db_options ::= alter_db_options alter_db_option */ - { 237, -2 }, /* (81) alter_db_option ::= BLOCKS NK_INTEGER */ - { 237, -2 }, /* (82) alter_db_option ::= FSYNC NK_INTEGER */ - { 237, -2 }, /* (83) alter_db_option ::= KEEP integer_list */ - { 237, -2 }, /* (84) alter_db_option ::= KEEP variable_list */ - { 237, -2 }, /* (85) alter_db_option ::= WAL NK_INTEGER */ - { 237, -2 }, /* (86) alter_db_option ::= QUORUM NK_INTEGER */ - { 237, -2 }, /* (87) alter_db_option ::= CACHELAST NK_INTEGER */ - { 237, -2 }, /* (88) alter_db_option ::= REPLICA NK_INTEGER */ - { 237, -2 }, /* (89) alter_db_option ::= STRICT NK_INTEGER */ - { 234, -1 }, /* (90) integer_list ::= NK_INTEGER */ - { 234, -3 }, /* (91) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 235, -1 }, /* (92) variable_list ::= NK_VARIABLE */ - { 235, -3 }, /* (93) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 236, -1 }, /* (94) retention_list ::= retention */ - { 236, -3 }, /* (95) retention_list ::= retention_list NK_COMMA retention */ - { 238, -3 }, /* (96) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 221, -9 }, /* (97) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 221, -3 }, /* (98) cmd ::= CREATE TABLE multi_create_clause */ - { 221, -9 }, /* (99) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 221, -3 }, /* (100) cmd ::= DROP TABLE multi_drop_clause */ - { 221, -4 }, /* (101) cmd ::= DROP STABLE exists_opt full_table_name */ - { 221, -3 }, /* (102) cmd ::= ALTER TABLE alter_table_clause */ - { 221, -3 }, /* (103) cmd ::= ALTER STABLE alter_table_clause */ - { 246, -2 }, /* (104) alter_table_clause ::= full_table_name alter_table_options */ - { 246, -5 }, /* (105) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 246, -4 }, /* (106) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 246, -5 }, /* (107) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 246, -5 }, /* (108) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 246, -5 }, /* (109) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 246, -4 }, /* (110) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 246, -5 }, /* (111) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 246, -5 }, /* (112) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 246, -6 }, /* (113) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ - { 243, -1 }, /* (114) multi_create_clause ::= create_subtable_clause */ - { 243, -2 }, /* (115) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 250, -9 }, /* (116) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ - { 245, -1 }, /* (117) multi_drop_clause ::= drop_table_clause */ - { 245, -2 }, /* (118) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 253, -2 }, /* (119) drop_table_clause ::= exists_opt full_table_name */ - { 251, 0 }, /* (120) specific_tags_opt ::= */ - { 251, -3 }, /* (121) specific_tags_opt ::= NK_LP col_name_list NK_RP */ - { 239, -1 }, /* (122) full_table_name ::= table_name */ - { 239, -3 }, /* (123) full_table_name ::= db_name NK_DOT table_name */ - { 240, -1 }, /* (124) column_def_list ::= column_def */ - { 240, -3 }, /* (125) column_def_list ::= column_def_list NK_COMMA column_def */ - { 256, -2 }, /* (126) column_def ::= column_name type_name */ - { 256, -4 }, /* (127) column_def ::= column_name type_name COMMENT NK_STRING */ - { 249, -1 }, /* (128) type_name ::= BOOL */ - { 249, -1 }, /* (129) type_name ::= TINYINT */ - { 249, -1 }, /* (130) type_name ::= SMALLINT */ - { 249, -1 }, /* (131) type_name ::= INT */ - { 249, -1 }, /* (132) type_name ::= INTEGER */ - { 249, -1 }, /* (133) type_name ::= BIGINT */ - { 249, -1 }, /* (134) type_name ::= FLOAT */ - { 249, -1 }, /* (135) type_name ::= DOUBLE */ - { 249, -4 }, /* (136) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 249, -1 }, /* (137) type_name ::= TIMESTAMP */ - { 249, -4 }, /* (138) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 249, -2 }, /* (139) type_name ::= TINYINT UNSIGNED */ - { 249, -2 }, /* (140) type_name ::= SMALLINT UNSIGNED */ - { 249, -2 }, /* (141) type_name ::= INT UNSIGNED */ - { 249, -2 }, /* (142) type_name ::= BIGINT UNSIGNED */ - { 249, -1 }, /* (143) type_name ::= JSON */ - { 249, -4 }, /* (144) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 249, -1 }, /* (145) type_name ::= MEDIUMBLOB */ - { 249, -1 }, /* (146) type_name ::= BLOB */ - { 249, -4 }, /* (147) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 249, -1 }, /* (148) type_name ::= DECIMAL */ - { 249, -4 }, /* (149) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 249, -6 }, /* (150) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 241, 0 }, /* (151) tags_def_opt ::= */ - { 241, -1 }, /* (152) tags_def_opt ::= tags_def */ - { 244, -4 }, /* (153) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 242, 0 }, /* (154) table_options ::= */ - { 242, -3 }, /* (155) table_options ::= table_options COMMENT NK_STRING */ - { 242, -3 }, /* (156) table_options ::= table_options KEEP integer_list */ - { 242, -3 }, /* (157) table_options ::= table_options KEEP variable_list */ - { 242, -3 }, /* (158) table_options ::= table_options TTL NK_INTEGER */ - { 242, -5 }, /* (159) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 242, -5 }, /* (160) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ - { 242, -3 }, /* (161) table_options ::= table_options FILE_FACTOR NK_FLOAT */ - { 242, -3 }, /* (162) table_options ::= table_options DELAY NK_INTEGER */ - { 247, -1 }, /* (163) alter_table_options ::= alter_table_option */ - { 247, -2 }, /* (164) alter_table_options ::= alter_table_options alter_table_option */ - { 258, -2 }, /* (165) alter_table_option ::= COMMENT NK_STRING */ - { 258, -2 }, /* (166) alter_table_option ::= KEEP integer_list */ - { 258, -2 }, /* (167) alter_table_option ::= KEEP variable_list */ - { 258, -2 }, /* (168) alter_table_option ::= TTL NK_INTEGER */ - { 254, -1 }, /* (169) col_name_list ::= col_name */ - { 254, -3 }, /* (170) col_name_list ::= col_name_list NK_COMMA col_name */ - { 259, -1 }, /* (171) col_name ::= column_name */ - { 221, -2 }, /* (172) cmd ::= SHOW DNODES */ - { 221, -2 }, /* (173) cmd ::= SHOW USERS */ - { 221, -2 }, /* (174) cmd ::= SHOW DATABASES */ - { 221, -4 }, /* (175) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 221, -4 }, /* (176) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 221, -3 }, /* (177) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 221, -2 }, /* (178) cmd ::= SHOW MNODES */ - { 221, -2 }, /* (179) cmd ::= SHOW MODULES */ - { 221, -2 }, /* (180) cmd ::= SHOW QNODES */ - { 221, -2 }, /* (181) cmd ::= SHOW FUNCTIONS */ - { 221, -5 }, /* (182) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 221, -2 }, /* (183) cmd ::= SHOW STREAMS */ - { 221, -2 }, /* (184) cmd ::= SHOW ACCOUNTS */ - { 221, -2 }, /* (185) cmd ::= SHOW APPS */ - { 221, -2 }, /* (186) cmd ::= SHOW CONNECTIONS */ - { 221, -2 }, /* (187) cmd ::= SHOW LICENCE */ - { 221, -2 }, /* (188) cmd ::= SHOW GRANTS */ - { 221, -4 }, /* (189) cmd ::= SHOW CREATE DATABASE db_name */ - { 221, -4 }, /* (190) cmd ::= SHOW CREATE TABLE full_table_name */ - { 221, -4 }, /* (191) cmd ::= SHOW CREATE STABLE full_table_name */ - { 221, -2 }, /* (192) cmd ::= SHOW QUERIES */ - { 221, -2 }, /* (193) cmd ::= SHOW SCORES */ - { 221, -2 }, /* (194) cmd ::= SHOW TOPICS */ - { 221, -2 }, /* (195) cmd ::= SHOW VARIABLES */ - { 221, -2 }, /* (196) cmd ::= SHOW BNODES */ - { 221, -2 }, /* (197) cmd ::= SHOW SNODES */ - { 260, 0 }, /* (198) db_name_cond_opt ::= */ - { 260, -2 }, /* (199) db_name_cond_opt ::= db_name NK_DOT */ - { 261, 0 }, /* (200) like_pattern_opt ::= */ - { 261, -2 }, /* (201) like_pattern_opt ::= LIKE NK_STRING */ - { 262, -1 }, /* (202) table_name_cond ::= table_name */ - { 263, 0 }, /* (203) from_db_opt ::= */ - { 263, -2 }, /* (204) from_db_opt ::= FROM db_name */ - { 257, -1 }, /* (205) func_name_list ::= func_name */ - { 257, -3 }, /* (206) func_name_list ::= func_name_list NK_COMMA func_name */ - { 264, -1 }, /* (207) func_name ::= function_name */ - { 221, -8 }, /* (208) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ - { 221, -10 }, /* (209) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ - { 221, -6 }, /* (210) cmd ::= DROP INDEX exists_opt index_name ON table_name */ - { 267, 0 }, /* (211) index_options ::= */ - { 267, -9 }, /* (212) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ - { 267, -11 }, /* (213) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ - { 268, -1 }, /* (214) func_list ::= func */ - { 268, -3 }, /* (215) func_list ::= func_list NK_COMMA func */ - { 271, -4 }, /* (216) func ::= function_name NK_LP expression_list NK_RP */ - { 221, -6 }, /* (217) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ - { 221, -6 }, /* (218) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ - { 221, -4 }, /* (219) cmd ::= DROP TOPIC exists_opt topic_name */ - { 221, -2 }, /* (220) cmd ::= DESC full_table_name */ - { 221, -2 }, /* (221) cmd ::= DESCRIBE full_table_name */ - { 221, -3 }, /* (222) cmd ::= RESET QUERY CACHE */ - { 221, -4 }, /* (223) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ - { 275, 0 }, /* (224) analyze_opt ::= */ - { 275, -1 }, /* (225) analyze_opt ::= ANALYZE */ - { 276, 0 }, /* (226) explain_options ::= */ - { 276, -3 }, /* (227) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 276, -3 }, /* (228) explain_options ::= explain_options RATIO NK_FLOAT */ - { 221, -6 }, /* (229) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ - { 221, -9 }, /* (230) cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 221, -3 }, /* (231) cmd ::= DROP FUNCTION function_name */ - { 277, 0 }, /* (232) agg_func_opt ::= */ - { 277, -1 }, /* (233) agg_func_opt ::= AGGREGATE */ - { 278, 0 }, /* (234) bufsize_opt ::= */ - { 278, -2 }, /* (235) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 221, -8 }, /* (236) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ - { 221, -4 }, /* (237) cmd ::= DROP STREAM exists_opt stream_name */ - { 281, 0 }, /* (238) into_opt ::= */ - { 281, -2 }, /* (239) into_opt ::= INTO full_table_name */ - { 280, 0 }, /* (240) stream_options ::= */ - { 280, -3 }, /* (241) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 280, -3 }, /* (242) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 280, -3 }, /* (243) stream_options ::= stream_options WATERMARK duration_literal */ - { 221, -3 }, /* (244) cmd ::= KILL CONNECTION NK_INTEGER */ - { 221, -3 }, /* (245) cmd ::= KILL QUERY NK_INTEGER */ - { 221, -4 }, /* (246) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 221, -4 }, /* (247) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 221, -3 }, /* (248) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 282, -2 }, /* (249) dnode_list ::= DNODE NK_INTEGER */ - { 282, -3 }, /* (250) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 221, -3 }, /* (251) cmd ::= SYNCDB db_name REPLICA */ - { 221, -1 }, /* (252) cmd ::= query_expression */ - { 224, -1 }, /* (253) literal ::= NK_INTEGER */ - { 224, -1 }, /* (254) literal ::= NK_FLOAT */ - { 224, -1 }, /* (255) literal ::= NK_STRING */ - { 224, -1 }, /* (256) literal ::= NK_BOOL */ - { 224, -2 }, /* (257) literal ::= TIMESTAMP NK_STRING */ - { 224, -1 }, /* (258) literal ::= duration_literal */ - { 224, -1 }, /* (259) literal ::= NULL */ - { 224, -1 }, /* (260) literal ::= NK_QUESTION */ - { 269, -1 }, /* (261) duration_literal ::= NK_VARIABLE */ - { 283, -1 }, /* (262) signed ::= NK_INTEGER */ - { 283, -2 }, /* (263) signed ::= NK_PLUS NK_INTEGER */ - { 283, -2 }, /* (264) signed ::= NK_MINUS NK_INTEGER */ - { 283, -1 }, /* (265) signed ::= NK_FLOAT */ - { 283, -2 }, /* (266) signed ::= NK_PLUS NK_FLOAT */ - { 283, -2 }, /* (267) signed ::= NK_MINUS NK_FLOAT */ - { 284, -1 }, /* (268) signed_literal ::= signed */ - { 284, -1 }, /* (269) signed_literal ::= NK_STRING */ - { 284, -1 }, /* (270) signed_literal ::= NK_BOOL */ - { 284, -2 }, /* (271) signed_literal ::= TIMESTAMP NK_STRING */ - { 284, -1 }, /* (272) signed_literal ::= duration_literal */ - { 284, -1 }, /* (273) signed_literal ::= NULL */ - { 252, -1 }, /* (274) literal_list ::= signed_literal */ - { 252, -3 }, /* (275) literal_list ::= literal_list NK_COMMA signed_literal */ - { 230, -1 }, /* (276) db_name ::= NK_ID */ - { 255, -1 }, /* (277) table_name ::= NK_ID */ - { 248, -1 }, /* (278) column_name ::= NK_ID */ - { 265, -1 }, /* (279) function_name ::= NK_ID */ - { 285, -1 }, /* (280) table_alias ::= NK_ID */ - { 286, -1 }, /* (281) column_alias ::= NK_ID */ - { 226, -1 }, /* (282) user_name ::= NK_ID */ - { 266, -1 }, /* (283) index_name ::= NK_ID */ - { 273, -1 }, /* (284) topic_name ::= NK_ID */ - { 279, -1 }, /* (285) stream_name ::= NK_ID */ - { 287, -1 }, /* (286) expression ::= literal */ - { 287, -1 }, /* (287) expression ::= pseudo_column */ - { 287, -1 }, /* (288) expression ::= column_reference */ - { 287, -1 }, /* (289) expression ::= function_expression */ - { 287, -1 }, /* (290) expression ::= subquery */ - { 287, -3 }, /* (291) expression ::= NK_LP expression NK_RP */ - { 287, -2 }, /* (292) expression ::= NK_PLUS expression */ - { 287, -2 }, /* (293) expression ::= NK_MINUS expression */ - { 287, -3 }, /* (294) expression ::= expression NK_PLUS expression */ - { 287, -3 }, /* (295) expression ::= expression NK_MINUS expression */ - { 287, -3 }, /* (296) expression ::= expression NK_STAR expression */ - { 287, -3 }, /* (297) expression ::= expression NK_SLASH expression */ - { 287, -3 }, /* (298) expression ::= expression NK_REM expression */ - { 287, -3 }, /* (299) expression ::= column_reference NK_ARROW NK_STRING */ - { 272, -1 }, /* (300) expression_list ::= expression */ - { 272, -3 }, /* (301) expression_list ::= expression_list NK_COMMA expression */ - { 289, -1 }, /* (302) column_reference ::= column_name */ - { 289, -3 }, /* (303) column_reference ::= table_name NK_DOT column_name */ - { 288, -1 }, /* (304) pseudo_column ::= ROWTS */ - { 288, -1 }, /* (305) pseudo_column ::= TBNAME */ - { 288, -1 }, /* (306) pseudo_column ::= QSTARTTS */ - { 288, -1 }, /* (307) pseudo_column ::= QENDTS */ - { 288, -1 }, /* (308) pseudo_column ::= WSTARTTS */ - { 288, -1 }, /* (309) pseudo_column ::= WENDTS */ - { 288, -1 }, /* (310) pseudo_column ::= WDURATION */ - { 290, -4 }, /* (311) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 290, -4 }, /* (312) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 290, -6 }, /* (313) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ - { 290, -3 }, /* (314) function_expression ::= noarg_func NK_LP NK_RP */ - { 294, -1 }, /* (315) noarg_func ::= NOW */ - { 294, -1 }, /* (316) noarg_func ::= TODAY */ - { 294, -1 }, /* (317) noarg_func ::= TIMEZONE */ - { 292, -1 }, /* (318) star_func ::= COUNT */ - { 292, -1 }, /* (319) star_func ::= FIRST */ - { 292, -1 }, /* (320) star_func ::= LAST */ - { 292, -1 }, /* (321) star_func ::= LAST_ROW */ - { 293, -1 }, /* (322) star_func_para_list ::= NK_STAR */ - { 293, -1 }, /* (323) star_func_para_list ::= other_para_list */ - { 295, -1 }, /* (324) other_para_list ::= star_func_para */ - { 295, -3 }, /* (325) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 296, -1 }, /* (326) star_func_para ::= expression */ - { 296, -3 }, /* (327) star_func_para ::= table_name NK_DOT NK_STAR */ - { 297, -3 }, /* (328) predicate ::= expression compare_op expression */ - { 297, -5 }, /* (329) predicate ::= expression BETWEEN expression AND expression */ - { 297, -6 }, /* (330) predicate ::= expression NOT BETWEEN expression AND expression */ - { 297, -3 }, /* (331) predicate ::= expression IS NULL */ - { 297, -4 }, /* (332) predicate ::= expression IS NOT NULL */ - { 297, -3 }, /* (333) predicate ::= expression in_op in_predicate_value */ - { 298, -1 }, /* (334) compare_op ::= NK_LT */ - { 298, -1 }, /* (335) compare_op ::= NK_GT */ - { 298, -1 }, /* (336) compare_op ::= NK_LE */ - { 298, -1 }, /* (337) compare_op ::= NK_GE */ - { 298, -1 }, /* (338) compare_op ::= NK_NE */ - { 298, -1 }, /* (339) compare_op ::= NK_EQ */ - { 298, -1 }, /* (340) compare_op ::= LIKE */ - { 298, -2 }, /* (341) compare_op ::= NOT LIKE */ - { 298, -1 }, /* (342) compare_op ::= MATCH */ - { 298, -1 }, /* (343) compare_op ::= NMATCH */ - { 298, -1 }, /* (344) compare_op ::= CONTAINS */ - { 299, -1 }, /* (345) in_op ::= IN */ - { 299, -2 }, /* (346) in_op ::= NOT IN */ - { 300, -3 }, /* (347) in_predicate_value ::= NK_LP expression_list NK_RP */ - { 301, -1 }, /* (348) boolean_value_expression ::= boolean_primary */ - { 301, -2 }, /* (349) boolean_value_expression ::= NOT boolean_primary */ - { 301, -3 }, /* (350) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 301, -3 }, /* (351) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 302, -1 }, /* (352) boolean_primary ::= predicate */ - { 302, -3 }, /* (353) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 303, -1 }, /* (354) common_expression ::= expression */ - { 303, -1 }, /* (355) common_expression ::= boolean_value_expression */ - { 304, -2 }, /* (356) from_clause ::= FROM table_reference_list */ - { 305, -1 }, /* (357) table_reference_list ::= table_reference */ - { 305, -3 }, /* (358) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 306, -1 }, /* (359) table_reference ::= table_primary */ - { 306, -1 }, /* (360) table_reference ::= joined_table */ - { 307, -2 }, /* (361) table_primary ::= table_name alias_opt */ - { 307, -4 }, /* (362) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 307, -2 }, /* (363) table_primary ::= subquery alias_opt */ - { 307, -1 }, /* (364) table_primary ::= parenthesized_joined_table */ - { 309, 0 }, /* (365) alias_opt ::= */ - { 309, -1 }, /* (366) alias_opt ::= table_alias */ - { 309, -2 }, /* (367) alias_opt ::= AS table_alias */ - { 310, -3 }, /* (368) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 310, -3 }, /* (369) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 308, -6 }, /* (370) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 311, 0 }, /* (371) join_type ::= */ - { 311, -1 }, /* (372) join_type ::= INNER */ - { 313, -9 }, /* (373) 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 */ - { 314, 0 }, /* (374) set_quantifier_opt ::= */ - { 314, -1 }, /* (375) set_quantifier_opt ::= DISTINCT */ - { 314, -1 }, /* (376) set_quantifier_opt ::= ALL */ - { 315, -1 }, /* (377) select_list ::= NK_STAR */ - { 315, -1 }, /* (378) select_list ::= select_sublist */ - { 321, -1 }, /* (379) select_sublist ::= select_item */ - { 321, -3 }, /* (380) select_sublist ::= select_sublist NK_COMMA select_item */ - { 322, -1 }, /* (381) select_item ::= common_expression */ - { 322, -2 }, /* (382) select_item ::= common_expression column_alias */ - { 322, -3 }, /* (383) select_item ::= common_expression AS column_alias */ - { 322, -3 }, /* (384) select_item ::= table_name NK_DOT NK_STAR */ - { 316, 0 }, /* (385) where_clause_opt ::= */ - { 316, -2 }, /* (386) where_clause_opt ::= WHERE search_condition */ - { 317, 0 }, /* (387) partition_by_clause_opt ::= */ - { 317, -3 }, /* (388) partition_by_clause_opt ::= PARTITION BY expression_list */ - { 318, 0 }, /* (389) twindow_clause_opt ::= */ - { 318, -6 }, /* (390) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 318, -4 }, /* (391) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ - { 318, -6 }, /* (392) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 318, -8 }, /* (393) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 270, 0 }, /* (394) sliding_opt ::= */ - { 270, -4 }, /* (395) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 323, 0 }, /* (396) fill_opt ::= */ - { 323, -4 }, /* (397) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 323, -6 }, /* (398) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 324, -1 }, /* (399) fill_mode ::= NONE */ - { 324, -1 }, /* (400) fill_mode ::= PREV */ - { 324, -1 }, /* (401) fill_mode ::= NULL */ - { 324, -1 }, /* (402) fill_mode ::= LINEAR */ - { 324, -1 }, /* (403) fill_mode ::= NEXT */ - { 319, 0 }, /* (404) group_by_clause_opt ::= */ - { 319, -3 }, /* (405) group_by_clause_opt ::= GROUP BY group_by_list */ - { 325, -1 }, /* (406) group_by_list ::= expression */ - { 325, -3 }, /* (407) group_by_list ::= group_by_list NK_COMMA expression */ - { 320, 0 }, /* (408) having_clause_opt ::= */ - { 320, -2 }, /* (409) having_clause_opt ::= HAVING search_condition */ - { 274, -4 }, /* (410) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 326, -1 }, /* (411) query_expression_body ::= query_primary */ - { 326, -4 }, /* (412) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ - { 330, -1 }, /* (413) query_primary ::= query_specification */ - { 327, 0 }, /* (414) order_by_clause_opt ::= */ - { 327, -3 }, /* (415) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 328, 0 }, /* (416) slimit_clause_opt ::= */ - { 328, -2 }, /* (417) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 328, -4 }, /* (418) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 328, -4 }, /* (419) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 329, 0 }, /* (420) limit_clause_opt ::= */ - { 329, -2 }, /* (421) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 329, -4 }, /* (422) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 329, -4 }, /* (423) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 291, -3 }, /* (424) subquery ::= NK_LP query_expression NK_RP */ - { 312, -1 }, /* (425) search_condition ::= common_expression */ - { 331, -1 }, /* (426) sort_specification_list ::= sort_specification */ - { 331, -3 }, /* (427) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 332, -3 }, /* (428) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ - { 333, 0 }, /* (429) ordering_specification_opt ::= */ - { 333, -1 }, /* (430) ordering_specification_opt ::= ASC */ - { 333, -1 }, /* (431) ordering_specification_opt ::= DESC */ - { 334, 0 }, /* (432) null_ordering_opt ::= */ - { 334, -2 }, /* (433) null_ordering_opt ::= NULLS FIRST */ - { 334, -2 }, /* (434) null_ordering_opt ::= NULLS LAST */ + { 222, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 222, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 223, 0 }, /* (2) account_options ::= */ + { 223, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 223, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 223, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 223, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 223, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 223, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 223, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 223, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 223, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 224, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 224, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 226, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 226, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 226, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 226, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 226, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 226, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 226, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 226, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 226, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 226, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 222, -5 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING */ + { 222, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 222, -5 }, /* (26) cmd ::= ALTER USER user_name PRIVILEGE NK_STRING */ + { 222, -3 }, /* (27) cmd ::= DROP USER user_name */ + { 222, -3 }, /* (28) cmd ::= CREATE DNODE dnode_endpoint */ + { 222, -5 }, /* (29) cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ + { 222, -3 }, /* (30) cmd ::= DROP DNODE NK_INTEGER */ + { 222, -3 }, /* (31) cmd ::= DROP DNODE dnode_endpoint */ + { 222, -4 }, /* (32) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 222, -5 }, /* (33) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 222, -4 }, /* (34) cmd ::= ALTER ALL DNODES NK_STRING */ + { 222, -5 }, /* (35) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 228, -1 }, /* (36) dnode_endpoint ::= NK_STRING */ + { 229, -1 }, /* (37) dnode_host_name ::= NK_ID */ + { 229, -1 }, /* (38) dnode_host_name ::= NK_IPTOKEN */ + { 222, -3 }, /* (39) cmd ::= ALTER LOCAL NK_STRING */ + { 222, -4 }, /* (40) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 222, -5 }, /* (41) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (42) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (43) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (44) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (45) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (46) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (47) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (48) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 222, -5 }, /* (49) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 222, -4 }, /* (50) cmd ::= DROP DATABASE exists_opt db_name */ + { 222, -2 }, /* (51) cmd ::= USE db_name */ + { 222, -4 }, /* (52) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 230, -3 }, /* (53) not_exists_opt ::= IF NOT EXISTS */ + { 230, 0 }, /* (54) not_exists_opt ::= */ + { 233, -2 }, /* (55) exists_opt ::= IF EXISTS */ + { 233, 0 }, /* (56) exists_opt ::= */ + { 232, 0 }, /* (57) db_options ::= */ + { 232, -3 }, /* (58) db_options ::= db_options BLOCKS NK_INTEGER */ + { 232, -3 }, /* (59) db_options ::= db_options CACHE NK_INTEGER */ + { 232, -3 }, /* (60) db_options ::= db_options CACHELAST NK_INTEGER */ + { 232, -3 }, /* (61) db_options ::= db_options COMP NK_INTEGER */ + { 232, -3 }, /* (62) db_options ::= db_options DAYS NK_INTEGER */ + { 232, -3 }, /* (63) db_options ::= db_options DAYS NK_VARIABLE */ + { 232, -3 }, /* (64) db_options ::= db_options FSYNC NK_INTEGER */ + { 232, -3 }, /* (65) db_options ::= db_options MAXROWS NK_INTEGER */ + { 232, -3 }, /* (66) db_options ::= db_options MINROWS NK_INTEGER */ + { 232, -3 }, /* (67) db_options ::= db_options KEEP integer_list */ + { 232, -3 }, /* (68) db_options ::= db_options KEEP variable_list */ + { 232, -3 }, /* (69) db_options ::= db_options PRECISION NK_STRING */ + { 232, -3 }, /* (70) db_options ::= db_options QUORUM NK_INTEGER */ + { 232, -3 }, /* (71) db_options ::= db_options REPLICA NK_INTEGER */ + { 232, -3 }, /* (72) db_options ::= db_options TTL NK_INTEGER */ + { 232, -3 }, /* (73) db_options ::= db_options WAL NK_INTEGER */ + { 232, -3 }, /* (74) db_options ::= db_options VGROUPS NK_INTEGER */ + { 232, -3 }, /* (75) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 232, -3 }, /* (76) db_options ::= db_options STREAM_MODE NK_INTEGER */ + { 232, -3 }, /* (77) db_options ::= db_options RETENTIONS retention_list */ + { 232, -3 }, /* (78) db_options ::= db_options STRICT NK_INTEGER */ + { 234, -1 }, /* (79) alter_db_options ::= alter_db_option */ + { 234, -2 }, /* (80) alter_db_options ::= alter_db_options alter_db_option */ + { 238, -2 }, /* (81) alter_db_option ::= BLOCKS NK_INTEGER */ + { 238, -2 }, /* (82) alter_db_option ::= FSYNC NK_INTEGER */ + { 238, -2 }, /* (83) alter_db_option ::= KEEP integer_list */ + { 238, -2 }, /* (84) alter_db_option ::= KEEP variable_list */ + { 238, -2 }, /* (85) alter_db_option ::= WAL NK_INTEGER */ + { 238, -2 }, /* (86) alter_db_option ::= QUORUM NK_INTEGER */ + { 238, -2 }, /* (87) alter_db_option ::= CACHELAST NK_INTEGER */ + { 238, -2 }, /* (88) alter_db_option ::= REPLICA NK_INTEGER */ + { 238, -2 }, /* (89) alter_db_option ::= STRICT NK_INTEGER */ + { 235, -1 }, /* (90) integer_list ::= NK_INTEGER */ + { 235, -3 }, /* (91) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 236, -1 }, /* (92) variable_list ::= NK_VARIABLE */ + { 236, -3 }, /* (93) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 237, -1 }, /* (94) retention_list ::= retention */ + { 237, -3 }, /* (95) retention_list ::= retention_list NK_COMMA retention */ + { 239, -3 }, /* (96) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 222, -9 }, /* (97) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 222, -3 }, /* (98) cmd ::= CREATE TABLE multi_create_clause */ + { 222, -9 }, /* (99) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 222, -3 }, /* (100) cmd ::= DROP TABLE multi_drop_clause */ + { 222, -4 }, /* (101) cmd ::= DROP STABLE exists_opt full_table_name */ + { 222, -3 }, /* (102) cmd ::= ALTER TABLE alter_table_clause */ + { 222, -3 }, /* (103) cmd ::= ALTER STABLE alter_table_clause */ + { 247, -2 }, /* (104) alter_table_clause ::= full_table_name alter_table_options */ + { 247, -5 }, /* (105) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 247, -4 }, /* (106) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 247, -5 }, /* (107) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 247, -5 }, /* (108) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 247, -5 }, /* (109) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 247, -4 }, /* (110) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 247, -5 }, /* (111) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 247, -5 }, /* (112) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 247, -6 }, /* (113) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ + { 244, -1 }, /* (114) multi_create_clause ::= create_subtable_clause */ + { 244, -2 }, /* (115) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 251, -9 }, /* (116) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_tags_opt TAGS NK_LP literal_list NK_RP */ + { 246, -1 }, /* (117) multi_drop_clause ::= drop_table_clause */ + { 246, -2 }, /* (118) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 254, -2 }, /* (119) drop_table_clause ::= exists_opt full_table_name */ + { 252, 0 }, /* (120) specific_tags_opt ::= */ + { 252, -3 }, /* (121) specific_tags_opt ::= NK_LP col_name_list NK_RP */ + { 240, -1 }, /* (122) full_table_name ::= table_name */ + { 240, -3 }, /* (123) full_table_name ::= db_name NK_DOT table_name */ + { 241, -1 }, /* (124) column_def_list ::= column_def */ + { 241, -3 }, /* (125) column_def_list ::= column_def_list NK_COMMA column_def */ + { 257, -2 }, /* (126) column_def ::= column_name type_name */ + { 257, -4 }, /* (127) column_def ::= column_name type_name COMMENT NK_STRING */ + { 250, -1 }, /* (128) type_name ::= BOOL */ + { 250, -1 }, /* (129) type_name ::= TINYINT */ + { 250, -1 }, /* (130) type_name ::= SMALLINT */ + { 250, -1 }, /* (131) type_name ::= INT */ + { 250, -1 }, /* (132) type_name ::= INTEGER */ + { 250, -1 }, /* (133) type_name ::= BIGINT */ + { 250, -1 }, /* (134) type_name ::= FLOAT */ + { 250, -1 }, /* (135) type_name ::= DOUBLE */ + { 250, -4 }, /* (136) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 250, -1 }, /* (137) type_name ::= TIMESTAMP */ + { 250, -4 }, /* (138) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 250, -2 }, /* (139) type_name ::= TINYINT UNSIGNED */ + { 250, -2 }, /* (140) type_name ::= SMALLINT UNSIGNED */ + { 250, -2 }, /* (141) type_name ::= INT UNSIGNED */ + { 250, -2 }, /* (142) type_name ::= BIGINT UNSIGNED */ + { 250, -1 }, /* (143) type_name ::= JSON */ + { 250, -4 }, /* (144) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 250, -1 }, /* (145) type_name ::= MEDIUMBLOB */ + { 250, -1 }, /* (146) type_name ::= BLOB */ + { 250, -4 }, /* (147) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 250, -1 }, /* (148) type_name ::= DECIMAL */ + { 250, -4 }, /* (149) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 250, -6 }, /* (150) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 242, 0 }, /* (151) tags_def_opt ::= */ + { 242, -1 }, /* (152) tags_def_opt ::= tags_def */ + { 245, -4 }, /* (153) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 243, 0 }, /* (154) table_options ::= */ + { 243, -3 }, /* (155) table_options ::= table_options COMMENT NK_STRING */ + { 243, -3 }, /* (156) table_options ::= table_options KEEP integer_list */ + { 243, -3 }, /* (157) table_options ::= table_options KEEP variable_list */ + { 243, -3 }, /* (158) table_options ::= table_options TTL NK_INTEGER */ + { 243, -5 }, /* (159) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 243, -5 }, /* (160) table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ + { 243, -3 }, /* (161) table_options ::= table_options FILE_FACTOR NK_FLOAT */ + { 243, -3 }, /* (162) table_options ::= table_options DELAY NK_INTEGER */ + { 248, -1 }, /* (163) alter_table_options ::= alter_table_option */ + { 248, -2 }, /* (164) alter_table_options ::= alter_table_options alter_table_option */ + { 259, -2 }, /* (165) alter_table_option ::= COMMENT NK_STRING */ + { 259, -2 }, /* (166) alter_table_option ::= KEEP integer_list */ + { 259, -2 }, /* (167) alter_table_option ::= KEEP variable_list */ + { 259, -2 }, /* (168) alter_table_option ::= TTL NK_INTEGER */ + { 255, -1 }, /* (169) col_name_list ::= col_name */ + { 255, -3 }, /* (170) col_name_list ::= col_name_list NK_COMMA col_name */ + { 260, -1 }, /* (171) col_name ::= column_name */ + { 222, -2 }, /* (172) cmd ::= SHOW DNODES */ + { 222, -2 }, /* (173) cmd ::= SHOW USERS */ + { 222, -2 }, /* (174) cmd ::= SHOW DATABASES */ + { 222, -4 }, /* (175) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 222, -4 }, /* (176) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 222, -3 }, /* (177) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 222, -2 }, /* (178) cmd ::= SHOW MNODES */ + { 222, -2 }, /* (179) cmd ::= SHOW MODULES */ + { 222, -2 }, /* (180) cmd ::= SHOW QNODES */ + { 222, -2 }, /* (181) cmd ::= SHOW FUNCTIONS */ + { 222, -5 }, /* (182) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 222, -2 }, /* (183) cmd ::= SHOW STREAMS */ + { 222, -2 }, /* (184) cmd ::= SHOW ACCOUNTS */ + { 222, -2 }, /* (185) cmd ::= SHOW APPS */ + { 222, -2 }, /* (186) cmd ::= SHOW CONNECTIONS */ + { 222, -2 }, /* (187) cmd ::= SHOW LICENCE */ + { 222, -2 }, /* (188) cmd ::= SHOW GRANTS */ + { 222, -4 }, /* (189) cmd ::= SHOW CREATE DATABASE db_name */ + { 222, -4 }, /* (190) cmd ::= SHOW CREATE TABLE full_table_name */ + { 222, -4 }, /* (191) cmd ::= SHOW CREATE STABLE full_table_name */ + { 222, -2 }, /* (192) cmd ::= SHOW QUERIES */ + { 222, -2 }, /* (193) cmd ::= SHOW SCORES */ + { 222, -2 }, /* (194) cmd ::= SHOW TOPICS */ + { 222, -2 }, /* (195) cmd ::= SHOW VARIABLES */ + { 222, -2 }, /* (196) cmd ::= SHOW BNODES */ + { 222, -2 }, /* (197) cmd ::= SHOW SNODES */ + { 222, -2 }, /* (198) cmd ::= SHOW CLUSTER */ + { 261, 0 }, /* (199) db_name_cond_opt ::= */ + { 261, -2 }, /* (200) db_name_cond_opt ::= db_name NK_DOT */ + { 262, 0 }, /* (201) like_pattern_opt ::= */ + { 262, -2 }, /* (202) like_pattern_opt ::= LIKE NK_STRING */ + { 263, -1 }, /* (203) table_name_cond ::= table_name */ + { 264, 0 }, /* (204) from_db_opt ::= */ + { 264, -2 }, /* (205) from_db_opt ::= FROM db_name */ + { 258, -1 }, /* (206) func_name_list ::= func_name */ + { 258, -3 }, /* (207) func_name_list ::= func_name_list NK_COMMA func_name */ + { 265, -1 }, /* (208) func_name ::= function_name */ + { 222, -8 }, /* (209) cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ + { 222, -10 }, /* (210) cmd ::= CREATE FULLTEXT INDEX not_exists_opt index_name ON table_name NK_LP col_name_list NK_RP */ + { 222, -6 }, /* (211) cmd ::= DROP INDEX exists_opt index_name ON table_name */ + { 268, 0 }, /* (212) index_options ::= */ + { 268, -9 }, /* (213) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ + { 268, -11 }, /* (214) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */ + { 269, -1 }, /* (215) func_list ::= func */ + { 269, -3 }, /* (216) func_list ::= func_list NK_COMMA func */ + { 272, -4 }, /* (217) func ::= function_name NK_LP expression_list NK_RP */ + { 222, -6 }, /* (218) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ + { 222, -6 }, /* (219) cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ + { 222, -4 }, /* (220) cmd ::= DROP TOPIC exists_opt topic_name */ + { 222, -2 }, /* (221) cmd ::= DESC full_table_name */ + { 222, -2 }, /* (222) cmd ::= DESCRIBE full_table_name */ + { 222, -3 }, /* (223) cmd ::= RESET QUERY CACHE */ + { 222, -4 }, /* (224) cmd ::= EXPLAIN analyze_opt explain_options query_expression */ + { 276, 0 }, /* (225) analyze_opt ::= */ + { 276, -1 }, /* (226) analyze_opt ::= ANALYZE */ + { 277, 0 }, /* (227) explain_options ::= */ + { 277, -3 }, /* (228) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 277, -3 }, /* (229) explain_options ::= explain_options RATIO NK_FLOAT */ + { 222, -6 }, /* (230) cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ + { 222, -10 }, /* (231) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 222, -3 }, /* (232) cmd ::= DROP FUNCTION function_name */ + { 278, 0 }, /* (233) agg_func_opt ::= */ + { 278, -1 }, /* (234) agg_func_opt ::= AGGREGATE */ + { 279, 0 }, /* (235) bufsize_opt ::= */ + { 279, -2 }, /* (236) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 222, -8 }, /* (237) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ + { 222, -4 }, /* (238) cmd ::= DROP STREAM exists_opt stream_name */ + { 282, 0 }, /* (239) into_opt ::= */ + { 282, -2 }, /* (240) into_opt ::= INTO full_table_name */ + { 281, 0 }, /* (241) stream_options ::= */ + { 281, -3 }, /* (242) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 281, -3 }, /* (243) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 281, -3 }, /* (244) stream_options ::= stream_options WATERMARK duration_literal */ + { 222, -3 }, /* (245) cmd ::= KILL CONNECTION NK_INTEGER */ + { 222, -3 }, /* (246) cmd ::= KILL QUERY NK_INTEGER */ + { 222, -4 }, /* (247) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 222, -4 }, /* (248) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 222, -3 }, /* (249) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 283, -2 }, /* (250) dnode_list ::= DNODE NK_INTEGER */ + { 283, -3 }, /* (251) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 222, -3 }, /* (252) cmd ::= SYNCDB db_name REPLICA */ + { 222, -1 }, /* (253) cmd ::= query_expression */ + { 225, -1 }, /* (254) literal ::= NK_INTEGER */ + { 225, -1 }, /* (255) literal ::= NK_FLOAT */ + { 225, -1 }, /* (256) literal ::= NK_STRING */ + { 225, -1 }, /* (257) literal ::= NK_BOOL */ + { 225, -2 }, /* (258) literal ::= TIMESTAMP NK_STRING */ + { 225, -1 }, /* (259) literal ::= duration_literal */ + { 225, -1 }, /* (260) literal ::= NULL */ + { 225, -1 }, /* (261) literal ::= NK_QUESTION */ + { 270, -1 }, /* (262) duration_literal ::= NK_VARIABLE */ + { 284, -1 }, /* (263) signed ::= NK_INTEGER */ + { 284, -2 }, /* (264) signed ::= NK_PLUS NK_INTEGER */ + { 284, -2 }, /* (265) signed ::= NK_MINUS NK_INTEGER */ + { 284, -1 }, /* (266) signed ::= NK_FLOAT */ + { 284, -2 }, /* (267) signed ::= NK_PLUS NK_FLOAT */ + { 284, -2 }, /* (268) signed ::= NK_MINUS NK_FLOAT */ + { 285, -1 }, /* (269) signed_literal ::= signed */ + { 285, -1 }, /* (270) signed_literal ::= NK_STRING */ + { 285, -1 }, /* (271) signed_literal ::= NK_BOOL */ + { 285, -2 }, /* (272) signed_literal ::= TIMESTAMP NK_STRING */ + { 285, -1 }, /* (273) signed_literal ::= duration_literal */ + { 285, -1 }, /* (274) signed_literal ::= NULL */ + { 253, -1 }, /* (275) literal_list ::= signed_literal */ + { 253, -3 }, /* (276) literal_list ::= literal_list NK_COMMA signed_literal */ + { 231, -1 }, /* (277) db_name ::= NK_ID */ + { 256, -1 }, /* (278) table_name ::= NK_ID */ + { 249, -1 }, /* (279) column_name ::= NK_ID */ + { 266, -1 }, /* (280) function_name ::= NK_ID */ + { 286, -1 }, /* (281) table_alias ::= NK_ID */ + { 287, -1 }, /* (282) column_alias ::= NK_ID */ + { 227, -1 }, /* (283) user_name ::= NK_ID */ + { 267, -1 }, /* (284) index_name ::= NK_ID */ + { 274, -1 }, /* (285) topic_name ::= NK_ID */ + { 280, -1 }, /* (286) stream_name ::= NK_ID */ + { 288, -1 }, /* (287) expression ::= literal */ + { 288, -1 }, /* (288) expression ::= pseudo_column */ + { 288, -1 }, /* (289) expression ::= column_reference */ + { 288, -1 }, /* (290) expression ::= function_expression */ + { 288, -1 }, /* (291) expression ::= subquery */ + { 288, -3 }, /* (292) expression ::= NK_LP expression NK_RP */ + { 288, -2 }, /* (293) expression ::= NK_PLUS expression */ + { 288, -2 }, /* (294) expression ::= NK_MINUS expression */ + { 288, -3 }, /* (295) expression ::= expression NK_PLUS expression */ + { 288, -3 }, /* (296) expression ::= expression NK_MINUS expression */ + { 288, -3 }, /* (297) expression ::= expression NK_STAR expression */ + { 288, -3 }, /* (298) expression ::= expression NK_SLASH expression */ + { 288, -3 }, /* (299) expression ::= expression NK_REM expression */ + { 288, -3 }, /* (300) expression ::= column_reference NK_ARROW NK_STRING */ + { 273, -1 }, /* (301) expression_list ::= expression */ + { 273, -3 }, /* (302) expression_list ::= expression_list NK_COMMA expression */ + { 290, -1 }, /* (303) column_reference ::= column_name */ + { 290, -3 }, /* (304) column_reference ::= table_name NK_DOT column_name */ + { 289, -1 }, /* (305) pseudo_column ::= ROWTS */ + { 289, -1 }, /* (306) pseudo_column ::= TBNAME */ + { 289, -1 }, /* (307) pseudo_column ::= QSTARTTS */ + { 289, -1 }, /* (308) pseudo_column ::= QENDTS */ + { 289, -1 }, /* (309) pseudo_column ::= WSTARTTS */ + { 289, -1 }, /* (310) pseudo_column ::= WENDTS */ + { 289, -1 }, /* (311) pseudo_column ::= WDURATION */ + { 291, -4 }, /* (312) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 291, -4 }, /* (313) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 291, -6 }, /* (314) function_expression ::= CAST NK_LP expression AS type_name NK_RP */ + { 291, -3 }, /* (315) function_expression ::= noarg_func NK_LP NK_RP */ + { 295, -1 }, /* (316) noarg_func ::= NOW */ + { 295, -1 }, /* (317) noarg_func ::= TODAY */ + { 295, -1 }, /* (318) noarg_func ::= TIMEZONE */ + { 293, -1 }, /* (319) star_func ::= COUNT */ + { 293, -1 }, /* (320) star_func ::= FIRST */ + { 293, -1 }, /* (321) star_func ::= LAST */ + { 293, -1 }, /* (322) star_func ::= LAST_ROW */ + { 294, -1 }, /* (323) star_func_para_list ::= NK_STAR */ + { 294, -1 }, /* (324) star_func_para_list ::= other_para_list */ + { 296, -1 }, /* (325) other_para_list ::= star_func_para */ + { 296, -3 }, /* (326) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 297, -1 }, /* (327) star_func_para ::= expression */ + { 297, -3 }, /* (328) star_func_para ::= table_name NK_DOT NK_STAR */ + { 298, -3 }, /* (329) predicate ::= expression compare_op expression */ + { 298, -5 }, /* (330) predicate ::= expression BETWEEN expression AND expression */ + { 298, -6 }, /* (331) predicate ::= expression NOT BETWEEN expression AND expression */ + { 298, -3 }, /* (332) predicate ::= expression IS NULL */ + { 298, -4 }, /* (333) predicate ::= expression IS NOT NULL */ + { 298, -3 }, /* (334) predicate ::= expression in_op in_predicate_value */ + { 299, -1 }, /* (335) compare_op ::= NK_LT */ + { 299, -1 }, /* (336) compare_op ::= NK_GT */ + { 299, -1 }, /* (337) compare_op ::= NK_LE */ + { 299, -1 }, /* (338) compare_op ::= NK_GE */ + { 299, -1 }, /* (339) compare_op ::= NK_NE */ + { 299, -1 }, /* (340) compare_op ::= NK_EQ */ + { 299, -1 }, /* (341) compare_op ::= LIKE */ + { 299, -2 }, /* (342) compare_op ::= NOT LIKE */ + { 299, -1 }, /* (343) compare_op ::= MATCH */ + { 299, -1 }, /* (344) compare_op ::= NMATCH */ + { 299, -1 }, /* (345) compare_op ::= CONTAINS */ + { 300, -1 }, /* (346) in_op ::= IN */ + { 300, -2 }, /* (347) in_op ::= NOT IN */ + { 301, -3 }, /* (348) in_predicate_value ::= NK_LP expression_list NK_RP */ + { 302, -1 }, /* (349) boolean_value_expression ::= boolean_primary */ + { 302, -2 }, /* (350) boolean_value_expression ::= NOT boolean_primary */ + { 302, -3 }, /* (351) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 302, -3 }, /* (352) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 303, -1 }, /* (353) boolean_primary ::= predicate */ + { 303, -3 }, /* (354) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 304, -1 }, /* (355) common_expression ::= expression */ + { 304, -1 }, /* (356) common_expression ::= boolean_value_expression */ + { 305, -2 }, /* (357) from_clause ::= FROM table_reference_list */ + { 306, -1 }, /* (358) table_reference_list ::= table_reference */ + { 306, -3 }, /* (359) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 307, -1 }, /* (360) table_reference ::= table_primary */ + { 307, -1 }, /* (361) table_reference ::= joined_table */ + { 308, -2 }, /* (362) table_primary ::= table_name alias_opt */ + { 308, -4 }, /* (363) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 308, -2 }, /* (364) table_primary ::= subquery alias_opt */ + { 308, -1 }, /* (365) table_primary ::= parenthesized_joined_table */ + { 310, 0 }, /* (366) alias_opt ::= */ + { 310, -1 }, /* (367) alias_opt ::= table_alias */ + { 310, -2 }, /* (368) alias_opt ::= AS table_alias */ + { 311, -3 }, /* (369) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 311, -3 }, /* (370) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 309, -6 }, /* (371) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 312, 0 }, /* (372) join_type ::= */ + { 312, -1 }, /* (373) join_type ::= INNER */ + { 314, -9 }, /* (374) 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 */ + { 315, 0 }, /* (375) set_quantifier_opt ::= */ + { 315, -1 }, /* (376) set_quantifier_opt ::= DISTINCT */ + { 315, -1 }, /* (377) set_quantifier_opt ::= ALL */ + { 316, -1 }, /* (378) select_list ::= NK_STAR */ + { 316, -1 }, /* (379) select_list ::= select_sublist */ + { 322, -1 }, /* (380) select_sublist ::= select_item */ + { 322, -3 }, /* (381) select_sublist ::= select_sublist NK_COMMA select_item */ + { 323, -1 }, /* (382) select_item ::= common_expression */ + { 323, -2 }, /* (383) select_item ::= common_expression column_alias */ + { 323, -3 }, /* (384) select_item ::= common_expression AS column_alias */ + { 323, -3 }, /* (385) select_item ::= table_name NK_DOT NK_STAR */ + { 317, 0 }, /* (386) where_clause_opt ::= */ + { 317, -2 }, /* (387) where_clause_opt ::= WHERE search_condition */ + { 318, 0 }, /* (388) partition_by_clause_opt ::= */ + { 318, -3 }, /* (389) partition_by_clause_opt ::= PARTITION BY expression_list */ + { 319, 0 }, /* (390) twindow_clause_opt ::= */ + { 319, -6 }, /* (391) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 319, -4 }, /* (392) twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ + { 319, -6 }, /* (393) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 319, -8 }, /* (394) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 271, 0 }, /* (395) sliding_opt ::= */ + { 271, -4 }, /* (396) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 324, 0 }, /* (397) fill_opt ::= */ + { 324, -4 }, /* (398) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 324, -6 }, /* (399) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 325, -1 }, /* (400) fill_mode ::= NONE */ + { 325, -1 }, /* (401) fill_mode ::= PREV */ + { 325, -1 }, /* (402) fill_mode ::= NULL */ + { 325, -1 }, /* (403) fill_mode ::= LINEAR */ + { 325, -1 }, /* (404) fill_mode ::= NEXT */ + { 320, 0 }, /* (405) group_by_clause_opt ::= */ + { 320, -3 }, /* (406) group_by_clause_opt ::= GROUP BY group_by_list */ + { 326, -1 }, /* (407) group_by_list ::= expression */ + { 326, -3 }, /* (408) group_by_list ::= group_by_list NK_COMMA expression */ + { 321, 0 }, /* (409) having_clause_opt ::= */ + { 321, -2 }, /* (410) having_clause_opt ::= HAVING search_condition */ + { 275, -4 }, /* (411) query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 327, -1 }, /* (412) query_expression_body ::= query_primary */ + { 327, -4 }, /* (413) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ + { 327, -3 }, /* (414) query_expression_body ::= query_expression_body UNION query_expression_body */ + { 331, -1 }, /* (415) query_primary ::= query_specification */ + { 328, 0 }, /* (416) order_by_clause_opt ::= */ + { 328, -3 }, /* (417) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 329, 0 }, /* (418) slimit_clause_opt ::= */ + { 329, -2 }, /* (419) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 329, -4 }, /* (420) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 329, -4 }, /* (421) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 330, 0 }, /* (422) limit_clause_opt ::= */ + { 330, -2 }, /* (423) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 330, -4 }, /* (424) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 330, -4 }, /* (425) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 292, -3 }, /* (426) subquery ::= NK_LP query_expression NK_RP */ + { 313, -1 }, /* (427) search_condition ::= common_expression */ + { 332, -1 }, /* (428) sort_specification_list ::= sort_specification */ + { 332, -3 }, /* (429) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 333, -3 }, /* (430) sort_specification ::= expression ordering_specification_opt null_ordering_opt */ + { 334, 0 }, /* (431) ordering_specification_opt ::= */ + { 334, -1 }, /* (432) ordering_specification_opt ::= ASC */ + { 334, -1 }, /* (433) ordering_specification_opt ::= DESC */ + { 335, 0 }, /* (434) null_ordering_opt ::= */ + { 335, -2 }, /* (435) null_ordering_opt ::= NULLS FIRST */ + { 335, -2 }, /* (436) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2727,11 +2749,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,222,&yymsp[0].minor); + yy_destructor(yypParser,223,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->valid = false; generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,223,&yymsp[0].minor); + yy_destructor(yypParser,224,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -2745,20 +2767,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,222,&yymsp[-2].minor); +{ yy_destructor(yypParser,223,&yymsp[-2].minor); { } - yy_destructor(yypParser,224,&yymsp[0].minor); + yy_destructor(yypParser,225,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,225,&yymsp[0].minor); +{ yy_destructor(yypParser,226,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,223,&yymsp[-1].minor); +{ yy_destructor(yypParser,224,&yymsp[-1].minor); { } - yy_destructor(yypParser,225,&yymsp[0].minor); + yy_destructor(yypParser,226,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -2772,31 +2794,31 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,224,&yymsp[0].minor); + yy_destructor(yypParser,225,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy0); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy359, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy449, 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.yy359, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy449, TSDB_ALTER_USER_PRIVILEGES, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy359); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy449); } break; case 28: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy359, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy449, NULL); } break; case 29: /* cmd ::= CREATE DNODE dnode_host_name PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy449, &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.yy359); } +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy449); } break; case 32: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -2813,25 +2835,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 276: /* db_name ::= NK_ID */ yytestcase(yyruleno==276); - case 277: /* table_name ::= NK_ID */ yytestcase(yyruleno==277); - case 278: /* column_name ::= NK_ID */ yytestcase(yyruleno==278); - case 279: /* function_name ::= NK_ID */ yytestcase(yyruleno==279); - case 280: /* table_alias ::= NK_ID */ yytestcase(yyruleno==280); - case 281: /* column_alias ::= NK_ID */ yytestcase(yyruleno==281); - case 282: /* user_name ::= NK_ID */ yytestcase(yyruleno==282); - case 283: /* index_name ::= NK_ID */ yytestcase(yyruleno==283); - case 284: /* topic_name ::= NK_ID */ yytestcase(yyruleno==284); - case 285: /* stream_name ::= NK_ID */ yytestcase(yyruleno==285); - case 315: /* noarg_func ::= NOW */ yytestcase(yyruleno==315); - case 316: /* noarg_func ::= TODAY */ yytestcase(yyruleno==316); - case 317: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==317); - case 318: /* star_func ::= COUNT */ yytestcase(yyruleno==318); - case 319: /* star_func ::= FIRST */ yytestcase(yyruleno==319); - case 320: /* star_func ::= LAST */ yytestcase(yyruleno==320); - case 321: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==321); -{ yylhsminor.yy359 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy359 = yylhsminor.yy359; + case 277: /* db_name ::= NK_ID */ yytestcase(yyruleno==277); + case 278: /* table_name ::= NK_ID */ yytestcase(yyruleno==278); + case 279: /* column_name ::= NK_ID */ yytestcase(yyruleno==279); + case 280: /* function_name ::= NK_ID */ yytestcase(yyruleno==280); + case 281: /* table_alias ::= NK_ID */ yytestcase(yyruleno==281); + case 282: /* column_alias ::= NK_ID */ yytestcase(yyruleno==282); + case 283: /* user_name ::= NK_ID */ yytestcase(yyruleno==283); + case 284: /* index_name ::= NK_ID */ yytestcase(yyruleno==284); + case 285: /* topic_name ::= NK_ID */ yytestcase(yyruleno==285); + case 286: /* stream_name ::= NK_ID */ yytestcase(yyruleno==286); + case 316: /* noarg_func ::= NOW */ yytestcase(yyruleno==316); + case 317: /* noarg_func ::= TODAY */ yytestcase(yyruleno==317); + case 318: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==318); + case 319: /* star_func ::= COUNT */ yytestcase(yyruleno==319); + case 320: /* star_func ::= FIRST */ yytestcase(yyruleno==320); + case 321: /* star_func ::= LAST */ yytestcase(yyruleno==321); + case 322: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==322); +{ yylhsminor.yy449 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy449 = yylhsminor.yy449; break; case 39: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } @@ -2864,420 +2886,420 @@ 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.yy237, &yymsp[-1].minor.yy359, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy89, &yymsp[-1].minor.yy449, yymsp[0].minor.yy392); } break; case 50: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy237, &yymsp[0].minor.yy359); } +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy449); } break; case 51: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy359); } +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy449); } break; case 52: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy359, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy449, yymsp[0].minor.yy392); } break; case 53: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy237 = true; } +{ yymsp[-2].minor.yy89 = true; } break; case 54: /* not_exists_opt ::= */ case 56: /* exists_opt ::= */ yytestcase(yyruleno==56); - case 224: /* analyze_opt ::= */ yytestcase(yyruleno==224); - case 232: /* agg_func_opt ::= */ yytestcase(yyruleno==232); - case 374: /* set_quantifier_opt ::= */ yytestcase(yyruleno==374); -{ yymsp[1].minor.yy237 = false; } + case 225: /* analyze_opt ::= */ yytestcase(yyruleno==225); + case 233: /* agg_func_opt ::= */ yytestcase(yyruleno==233); + case 375: /* set_quantifier_opt ::= */ yytestcase(yyruleno==375); +{ yymsp[1].minor.yy89 = false; } break; case 55: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy237 = true; } +{ yymsp[-1].minor.yy89 = true; } break; case 57: /* db_options ::= */ -{ yymsp[1].minor.yy42 = createDatabaseOptions(pCxt); } +{ yymsp[1].minor.yy392 = createDatabaseOptions(pCxt); } break; case 58: /* db_options ::= db_options BLOCKS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pNumOfBlocks = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 59: /* db_options ::= db_options CACHE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pCacheBlockSize = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 60: /* db_options ::= db_options CACHELAST NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pCachelast = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 61: /* db_options ::= db_options COMP NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pCompressionLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 62: /* db_options ::= db_options DAYS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pDaysPerFile = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 63: /* db_options ::= db_options DAYS NK_VARIABLE */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pDaysPerFile = (SValueNode*)createDurationValueNode(pCxt, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 64: /* db_options ::= db_options FSYNC NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pFsyncPeriod = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 65: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pMaxRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 66: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pMinRowsPerBlock = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; 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.yy42)->pKeep = yymsp[0].minor.yy244; yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pKeep = yymsp[0].minor.yy376; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 69: /* db_options ::= db_options PRECISION NK_STRING */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pPrecision = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 70: /* db_options ::= db_options QUORUM NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pQuorum = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 71: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pReplica = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 72: /* db_options ::= db_options TTL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 73: /* db_options ::= db_options WAL NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pWalLevel = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 74: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pNumOfVgroups = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 75: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pSingleStable = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 76: /* db_options ::= db_options STREAM_MODE NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pStreamMode = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 77: /* db_options ::= db_options RETENTIONS retention_list */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pRetentions = yymsp[0].minor.yy244; yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pRetentions = yymsp[0].minor.yy376; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 78: /* db_options ::= db_options STRICT NK_INTEGER */ -{ ((SDatabaseOptions*)yymsp[-2].minor.yy42)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((SDatabaseOptions*)yymsp[-2].minor.yy392)->pStrict = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 79: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy42 = createDatabaseOptions(pCxt); yylhsminor.yy42 = setDatabaseAlterOption(pCxt, yylhsminor.yy42, &yymsp[0].minor.yy325); } - yymsp[0].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createDatabaseOptions(pCxt); yylhsminor.yy392 = setDatabaseAlterOption(pCxt, yylhsminor.yy392, &yymsp[0].minor.yy221); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 80: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy42 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy42, &yymsp[0].minor.yy325); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = setDatabaseAlterOption(pCxt, yymsp[-1].minor.yy392, &yymsp[0].minor.yy221); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 81: /* alter_db_option ::= BLOCKS NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_BLOCKS; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 82: /* alter_db_option ::= FSYNC NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy221.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.yy325.type = DB_OPTION_KEEP; yymsp[-1].minor.yy325.pList = yymsp[0].minor.yy244; } +{ yymsp[-1].minor.yy221.type = DB_OPTION_KEEP; yymsp[-1].minor.yy221.pList = yymsp[0].minor.yy376; } break; case 85: /* alter_db_option ::= WAL NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_WAL; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_WAL; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 86: /* alter_db_option ::= QUORUM NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_QUORUM; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 87: /* alter_db_option ::= CACHELAST NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_CACHELAST; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 88: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 89: /* alter_db_option ::= STRICT NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = DB_OPTION_STRICT; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = DB_OPTION_STRICT; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 90: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy244 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy244 = yylhsminor.yy244; +{ yylhsminor.yy376 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; case 91: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 250: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==250); -{ yylhsminor.yy244 = addNodeToList(pCxt, yymsp[-2].minor.yy244, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; + case 251: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==251); +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-2].minor.yy376, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy376 = yylhsminor.yy376; break; case 92: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy244 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy244 = yylhsminor.yy244; +{ yylhsminor.yy376 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; case 93: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy244 = addNodeToList(pCxt, yymsp[-2].minor.yy244, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-2].minor.yy376, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy376 = yylhsminor.yy376; break; case 94: /* retention_list ::= retention */ case 114: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==114); case 117: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==117); case 124: /* column_def_list ::= column_def */ yytestcase(yyruleno==124); case 169: /* col_name_list ::= col_name */ yytestcase(yyruleno==169); - case 205: /* func_name_list ::= func_name */ yytestcase(yyruleno==205); - case 214: /* func_list ::= func */ yytestcase(yyruleno==214); - case 274: /* literal_list ::= signed_literal */ yytestcase(yyruleno==274); - case 324: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==324); - case 379: /* select_sublist ::= select_item */ yytestcase(yyruleno==379); - case 426: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==426); -{ yylhsminor.yy244 = createNodeList(pCxt, yymsp[0].minor.yy42); } - yymsp[0].minor.yy244 = yylhsminor.yy244; + case 206: /* func_name_list ::= func_name */ yytestcase(yyruleno==206); + case 215: /* func_list ::= func */ yytestcase(yyruleno==215); + case 275: /* literal_list ::= signed_literal */ yytestcase(yyruleno==275); + case 325: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==325); + case 380: /* select_sublist ::= select_item */ yytestcase(yyruleno==380); + case 428: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==428); +{ yylhsminor.yy376 = createNodeList(pCxt, yymsp[0].minor.yy392); } + yymsp[0].minor.yy376 = yylhsminor.yy376; 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 206: /* func_name_list ::= func_name_list NK_COMMA func_name */ yytestcase(yyruleno==206); - case 215: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==215); - case 275: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==275); - case 325: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==325); - case 380: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==380); - case 427: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==427); -{ yylhsminor.yy244 = addNodeToList(pCxt, yymsp[-2].minor.yy244, yymsp[0].minor.yy42); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; + 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 276: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==276); + case 326: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==326); + case 381: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==381); + case 429: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==429); +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-2].minor.yy376, yymsp[0].minor.yy392); } + yymsp[-2].minor.yy376 = yylhsminor.yy376; break; case 96: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy42 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; 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.yy237, yymsp[-5].minor.yy42, yymsp[-3].minor.yy244, yymsp[-1].minor.yy244, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy89, yymsp[-5].minor.yy392, yymsp[-3].minor.yy376, yymsp[-1].minor.yy376, yymsp[0].minor.yy392); } break; case 98: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy244); } +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy376); } break; case 100: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy244); } +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy376); } break; case 101: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy237, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy89, yymsp[0].minor.yy392); } break; case 102: /* cmd ::= ALTER TABLE alter_table_clause */ case 103: /* cmd ::= ALTER STABLE alter_table_clause */ yytestcase(yyruleno==103); - case 252: /* cmd ::= query_expression */ yytestcase(yyruleno==252); -{ pCxt->pRootNode = yymsp[0].minor.yy42; } + case 253: /* cmd ::= query_expression */ yytestcase(yyruleno==253); +{ pCxt->pRootNode = yymsp[0].minor.yy392; } break; case 104: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy42 = createAlterTableOption(pCxt, yymsp[-1].minor.yy42, yymsp[0].minor.yy42); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableOption(pCxt, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 105: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy42 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy359, yymsp[0].minor.yy314); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy449, yymsp[0].minor.yy112); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 106: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy42 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy42, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy359); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy449); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 107: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy42 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy359, yymsp[0].minor.yy314); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy449, yymsp[0].minor.yy112); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 108: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy42 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy359, &yymsp[0].minor.yy359); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy449, &yymsp[0].minor.yy449); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 109: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy42 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy359, yymsp[0].minor.yy314); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy449, yymsp[0].minor.yy112); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 110: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy42 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy42, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy359); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy392, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy449); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 111: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy42 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy359, yymsp[0].minor.yy314); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy449, yymsp[0].minor.yy112); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 112: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy42 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy42, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy359, &yymsp[0].minor.yy359); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy392, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy449, &yymsp[0].minor.yy449); } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 113: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ literal */ -{ yylhsminor.yy42 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy42, &yymsp[-2].minor.yy359, yymsp[0].minor.yy42); } - yymsp[-5].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy392, &yymsp[-2].minor.yy449, yymsp[0].minor.yy392); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; 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.yy244 = addNodeToList(pCxt, yymsp[-1].minor.yy244, yymsp[0].minor.yy42); } - yymsp[-1].minor.yy244 = yylhsminor.yy244; +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-1].minor.yy376, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy376 = yylhsminor.yy376; 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.yy42 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy237, yymsp[-7].minor.yy42, yymsp[-5].minor.yy42, yymsp[-4].minor.yy244, yymsp[-1].minor.yy244); } - yymsp[-8].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createCreateSubTableClause(pCxt, yymsp[-8].minor.yy89, yymsp[-7].minor.yy392, yymsp[-5].minor.yy392, yymsp[-4].minor.yy376, yymsp[-1].minor.yy376); } + yymsp[-8].minor.yy392 = yylhsminor.yy392; break; case 119: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy42 = createDropTableClause(pCxt, yymsp[-1].minor.yy237, yymsp[0].minor.yy42); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createDropTableClause(pCxt, yymsp[-1].minor.yy89, yymsp[0].minor.yy392); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 120: /* specific_tags_opt ::= */ case 151: /* tags_def_opt ::= */ yytestcase(yyruleno==151); - case 387: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==387); - case 404: /* group_by_clause_opt ::= */ yytestcase(yyruleno==404); - case 414: /* order_by_clause_opt ::= */ yytestcase(yyruleno==414); -{ yymsp[1].minor.yy244 = NULL; } + case 388: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==388); + case 405: /* group_by_clause_opt ::= */ yytestcase(yyruleno==405); + case 416: /* order_by_clause_opt ::= */ yytestcase(yyruleno==416); +{ yymsp[1].minor.yy376 = NULL; } break; case 121: /* specific_tags_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy244 = yymsp[-1].minor.yy244; } +{ yymsp[-2].minor.yy376 = yymsp[-1].minor.yy376; } break; case 122: /* full_table_name ::= table_name */ -{ yylhsminor.yy42 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy359, NULL); } - yymsp[0].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy449, NULL); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 123: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy42 = createRealTableNode(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy359, NULL); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy449, NULL); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 126: /* column_def ::= column_name type_name */ -{ yylhsminor.yy42 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy359, yymsp[0].minor.yy314, NULL); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy449, yymsp[0].minor.yy112, NULL); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 127: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy42 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy359, yymsp[-2].minor.yy314, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy449, yymsp[-2].minor.yy112, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; case 128: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_BOOL); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_BOOL); } break; case 129: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_TINYINT); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; case 130: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_SMALLINT); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; case 131: /* type_name ::= INT */ case 132: /* type_name ::= INTEGER */ yytestcase(yyruleno==132); -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_INT); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_INT); } break; case 133: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_BIGINT); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; case 134: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_FLOAT); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; case 135: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_DOUBLE); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; case 136: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy314 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy112 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; case 137: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; case 138: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy314 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy112 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; case 139: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy314 = createDataType(TSDB_DATA_TYPE_UTINYINT); } +{ yymsp[-1].minor.yy112 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; case 140: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy314 = createDataType(TSDB_DATA_TYPE_USMALLINT); } +{ yymsp[-1].minor.yy112 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; case 141: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy314 = createDataType(TSDB_DATA_TYPE_UINT); } +{ yymsp[-1].minor.yy112 = createDataType(TSDB_DATA_TYPE_UINT); } break; case 142: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy314 = createDataType(TSDB_DATA_TYPE_UBIGINT); } +{ yymsp[-1].minor.yy112 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; case 143: /* type_name ::= JSON */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_JSON); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_JSON); } break; case 144: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy314 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy112 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; case 145: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; case 146: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_BLOB); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_BLOB); } break; case 147: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy314 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } +{ yymsp[-3].minor.yy112 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; case 148: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy314 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[0].minor.yy112 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 149: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy314 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-3].minor.yy112 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 150: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy314 = createDataType(TSDB_DATA_TYPE_DECIMAL); } +{ yymsp[-5].minor.yy112 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; case 152: /* tags_def_opt ::= tags_def */ - case 323: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==323); - case 378: /* select_list ::= select_sublist */ yytestcase(yyruleno==378); -{ yylhsminor.yy244 = yymsp[0].minor.yy244; } - yymsp[0].minor.yy244 = yylhsminor.yy244; + case 324: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==324); + case 379: /* select_list ::= select_sublist */ yytestcase(yyruleno==379); +{ yylhsminor.yy376 = yymsp[0].minor.yy376; } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; case 153: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy244 = yymsp[-1].minor.yy244; } +{ yymsp[-3].minor.yy376 = yymsp[-1].minor.yy376; } break; case 154: /* table_options ::= */ -{ yymsp[1].minor.yy42 = createTableOptions(pCxt); } +{ yymsp[1].minor.yy392 = createTableOptions(pCxt); } break; case 155: /* table_options ::= table_options COMMENT NK_STRING */ -{ ((STableOptions*)yymsp[-2].minor.yy42)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-2].minor.yy392)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; 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.yy42)->pKeep = yymsp[0].minor.yy244; yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-2].minor.yy392)->pKeep = yymsp[0].minor.yy376; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 158: /* table_options ::= table_options TTL NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy42)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-2].minor.yy392)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 159: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy42)->pSma = yymsp[-1].minor.yy244; yylhsminor.yy42 = yymsp[-4].minor.yy42; } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-4].minor.yy392)->pSma = yymsp[-1].minor.yy376; yylhsminor.yy392 = yymsp[-4].minor.yy392; } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 160: /* table_options ::= table_options ROLLUP NK_LP func_name_list NK_RP */ -{ ((STableOptions*)yymsp[-4].minor.yy42)->pFuncs = yymsp[-1].minor.yy244; yylhsminor.yy42 = yymsp[-4].minor.yy42; } - yymsp[-4].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-4].minor.yy392)->pFuncs = yymsp[-1].minor.yy376; yylhsminor.yy392 = yymsp[-4].minor.yy392; } + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; case 161: /* table_options ::= table_options FILE_FACTOR NK_FLOAT */ -{ ((STableOptions*)yymsp[-2].minor.yy42)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-2].minor.yy392)->pFilesFactor = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 162: /* table_options ::= table_options DELAY NK_INTEGER */ -{ ((STableOptions*)yymsp[-2].minor.yy42)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; +{ ((STableOptions*)yymsp[-2].minor.yy392)->pDelay = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; case 163: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy42 = createTableOptions(pCxt); yylhsminor.yy42 = setTableAlterOption(pCxt, yylhsminor.yy42, &yymsp[0].minor.yy325); } - yymsp[0].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createTableOptions(pCxt); yylhsminor.yy392 = setTableAlterOption(pCxt, yylhsminor.yy392, &yymsp[0].minor.yy221); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 164: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy42 = setTableAlterOption(pCxt, yymsp[-1].minor.yy42, &yymsp[0].minor.yy325); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = setTableAlterOption(pCxt, yymsp[-1].minor.yy392, &yymsp[0].minor.yy221); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; case 165: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy325.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy221.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.yy325.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy325.pList = yymsp[0].minor.yy244; } +{ yymsp[-1].minor.yy221.type = TABLE_OPTION_KEEP; yymsp[-1].minor.yy221.pList = yymsp[0].minor.yy376; } break; case 168: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy325.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy325.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } +{ yymsp[-1].minor.yy221.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy221.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; case 171: /* col_name ::= column_name */ -{ yylhsminor.yy42 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy359); } - yymsp[0].minor.yy42 = yylhsminor.yy42; +{ yylhsminor.yy392 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy449); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; case 172: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL, NULL); } @@ -3289,13 +3311,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.yy42, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } 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.yy42, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } break; case 177: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy42, NULL); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy392, NULL); } break; case 178: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT, NULL, NULL); } @@ -3310,7 +3332,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.yy42, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; case 183: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); } @@ -3329,13 +3351,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.yy359); } +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy449); } break; case 190: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy392); } break; case 191: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy42); } +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy392); } break; case 192: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT, NULL, NULL); } @@ -3355,641 +3377,648 @@ static YYACTIONTYPE yy_reduce( case 197: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT, NULL, NULL); } break; - case 198: /* db_name_cond_opt ::= */ - case 203: /* from_db_opt ::= */ yytestcase(yyruleno==203); -{ yymsp[1].minor.yy42 = createDefaultDatabaseCondValue(pCxt); } + case 198: /* cmd ::= SHOW CLUSTER */ +{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT, NULL, NULL); } break; - case 199: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy359); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 199: /* db_name_cond_opt ::= */ + case 204: /* from_db_opt ::= */ yytestcase(yyruleno==204); +{ yymsp[1].minor.yy392 = createDefaultDatabaseCondValue(pCxt); } break; - case 200: /* like_pattern_opt ::= */ - case 211: /* index_options ::= */ yytestcase(yyruleno==211); - case 238: /* into_opt ::= */ yytestcase(yyruleno==238); - case 385: /* where_clause_opt ::= */ yytestcase(yyruleno==385); - case 389: /* twindow_clause_opt ::= */ yytestcase(yyruleno==389); - case 394: /* sliding_opt ::= */ yytestcase(yyruleno==394); - case 396: /* fill_opt ::= */ yytestcase(yyruleno==396); - case 408: /* having_clause_opt ::= */ yytestcase(yyruleno==408); - case 416: /* slimit_clause_opt ::= */ yytestcase(yyruleno==416); - case 420: /* limit_clause_opt ::= */ yytestcase(yyruleno==420); -{ yymsp[1].minor.yy42 = NULL; } + case 200: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy449); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 201: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 201: /* like_pattern_opt ::= */ + case 212: /* index_options ::= */ yytestcase(yyruleno==212); + case 239: /* into_opt ::= */ yytestcase(yyruleno==239); + case 386: /* where_clause_opt ::= */ yytestcase(yyruleno==386); + case 390: /* twindow_clause_opt ::= */ yytestcase(yyruleno==390); + case 395: /* sliding_opt ::= */ yytestcase(yyruleno==395); + case 397: /* fill_opt ::= */ yytestcase(yyruleno==397); + case 409: /* having_clause_opt ::= */ yytestcase(yyruleno==409); + case 418: /* slimit_clause_opt ::= */ yytestcase(yyruleno==418); + case 422: /* limit_clause_opt ::= */ yytestcase(yyruleno==422); +{ yymsp[1].minor.yy392 = NULL; } break; - case 202: /* table_name_cond ::= table_name */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy359); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 202: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 204: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy359); } + case 203: /* table_name_cond ::= table_name */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy449); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 207: /* func_name ::= function_name */ -{ yylhsminor.yy42 = createFunctionNode(pCxt, &yymsp[0].minor.yy359, NULL); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 205: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy449); } break; - case 208: /* cmd ::= CREATE SMA INDEX not_exists_opt index_name ON table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy237, &yymsp[-3].minor.yy359, &yymsp[-1].minor.yy359, NULL, yymsp[0].minor.yy42); } + case 208: /* func_name ::= function_name */ +{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[0].minor.yy449, NULL); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 209: /* 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.yy237, &yymsp[-5].minor.yy359, &yymsp[-3].minor.yy359, yymsp[-1].minor.yy244, NULL); } + 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.yy89, &yymsp[-3].minor.yy449, &yymsp[-1].minor.yy449, NULL, yymsp[0].minor.yy392); } break; - case 210: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy237, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy359); } + 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.yy89, &yymsp[-5].minor.yy449, &yymsp[-3].minor.yy449, yymsp[-1].minor.yy376, NULL); } break; - case 212: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ -{ yymsp[-8].minor.yy42 = createIndexOption(pCxt, yymsp[-6].minor.yy244, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), NULL, yymsp[0].minor.yy42); } + case 211: /* cmd ::= DROP INDEX exists_opt index_name ON table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-3].minor.yy89, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy449); } break; - case 213: /* 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.yy42 = createIndexOption(pCxt, yymsp[-8].minor.yy244, releaseRawExprNode(pCxt, yymsp[-4].minor.yy42), releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), yymsp[0].minor.yy42); } + case 213: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */ +{ yymsp[-8].minor.yy392 = createIndexOption(pCxt, yymsp[-6].minor.yy376, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL, yymsp[0].minor.yy392); } break; - case 216: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy42 = createFunctionNode(pCxt, &yymsp[-3].minor.yy359, yymsp[-1].minor.yy244); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + 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.yy392 = createIndexOption(pCxt, yymsp[-8].minor.yy376, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[0].minor.yy392); } break; - case 217: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy237, &yymsp[-2].minor.yy359, yymsp[0].minor.yy42, NULL); } + case 217: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy392 = createFunctionNode(pCxt, &yymsp[-3].minor.yy449, yymsp[-1].minor.yy376); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 218: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ -{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy237, &yymsp[-2].minor.yy359, NULL, &yymsp[0].minor.yy359); } + case 218: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_expression */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy89, &yymsp[-2].minor.yy449, yymsp[0].minor.yy392, NULL); } break; - case 219: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy237, &yymsp[0].minor.yy359); } + case 219: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS db_name */ +{ pCxt->pRootNode = createCreateTopicStmt(pCxt, yymsp[-3].minor.yy89, &yymsp[-2].minor.yy449, NULL, &yymsp[0].minor.yy449); } break; - case 220: /* cmd ::= DESC full_table_name */ - case 221: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==221); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy42); } + case 220: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy449); } break; - case 222: /* cmd ::= RESET QUERY CACHE */ + case 221: /* cmd ::= DESC full_table_name */ + case 222: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==222); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy392); } + break; + case 223: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 223: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy237, yymsp[-1].minor.yy42, yymsp[0].minor.yy42); } + case 224: /* cmd ::= EXPLAIN analyze_opt explain_options query_expression */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy89, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 225: /* analyze_opt ::= ANALYZE */ - case 233: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==233); - case 375: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==375); -{ yymsp[0].minor.yy237 = true; } + case 226: /* analyze_opt ::= ANALYZE */ + case 234: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==234); + case 376: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==376); +{ yymsp[0].minor.yy89 = true; } break; - case 226: /* explain_options ::= */ -{ yymsp[1].minor.yy42 = createDefaultExplainOptions(pCxt); } + case 227: /* explain_options ::= */ +{ yymsp[1].minor.yy392 = createDefaultExplainOptions(pCxt); } break; - case 227: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy42 = setExplainVerbose(pCxt, yymsp[-2].minor.yy42, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 228: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy392 = setExplainVerbose(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 228: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy42 = setExplainRatio(pCxt, yymsp[-2].minor.yy42, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 229: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy392 = setExplainRatio(pCxt, yymsp[-2].minor.yy392, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 229: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ -{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy244); } + case 230: /* cmd ::= COMPACT VNODES IN NK_LP integer_list NK_RP */ +{ pCxt->pRootNode = createCompactStmt(pCxt, yymsp[-1].minor.yy376); } break; - case 230: /* cmd ::= CREATE agg_func_opt FUNCTION function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-7].minor.yy237, &yymsp[-5].minor.yy359, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy314, yymsp[0].minor.yy240); } + case 231: /* 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.yy89, yymsp[-8].minor.yy89, &yymsp[-5].minor.yy449, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy112, yymsp[0].minor.yy4); } break; - case 231: /* cmd ::= DROP FUNCTION function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy359); } + case 232: /* cmd ::= DROP FUNCTION function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, &yymsp[0].minor.yy449); } break; - case 234: /* bufsize_opt ::= */ -{ yymsp[1].minor.yy240 = 0; } + case 235: /* bufsize_opt ::= */ +{ yymsp[1].minor.yy4 = 0; } break; - case 235: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ -{ yymsp[-1].minor.yy240 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } + case 236: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ +{ yymsp[-1].minor.yy4 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } break; - case 236: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy237, &yymsp[-4].minor.yy359, yymsp[-2].minor.yy42, yymsp[-3].minor.yy42, yymsp[0].minor.yy42); } + case 237: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options into_opt AS query_expression */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-5].minor.yy89, &yymsp[-4].minor.yy449, yymsp[-2].minor.yy392, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } break; - case 237: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy237, &yymsp[0].minor.yy359); } + case 238: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy89, &yymsp[0].minor.yy449); } break; - case 239: /* into_opt ::= INTO full_table_name */ - case 356: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==356); - case 386: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==386); - case 409: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==409); -{ yymsp[-1].minor.yy42 = yymsp[0].minor.yy42; } + case 240: /* into_opt ::= INTO full_table_name */ + case 357: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==357); + case 387: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==387); + case 410: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==410); +{ yymsp[-1].minor.yy392 = yymsp[0].minor.yy392; } break; - case 240: /* stream_options ::= */ -{ yymsp[1].minor.yy42 = createStreamOptions(pCxt); } + case 241: /* stream_options ::= */ +{ yymsp[1].minor.yy392 = createStreamOptions(pCxt); } break; - case 241: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy42)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 242: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 242: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy42)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 243: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 243: /* stream_options ::= stream_options WATERMARK duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy42)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy42); yylhsminor.yy42 = yymsp[-2].minor.yy42; } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 244: /* stream_options ::= stream_options WATERMARK duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy392)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); yylhsminor.yy392 = yymsp[-2].minor.yy392; } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 244: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 245: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 245: /* cmd ::= KILL QUERY NK_INTEGER */ + case 246: /* cmd ::= KILL QUERY NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_QUERY_STMT, &yymsp[0].minor.yy0); } break; - case 246: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 247: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 247: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy244); } + case 248: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy376); } break; - case 248: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 249: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 249: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy244 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + case 250: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy376 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } break; - case 251: /* cmd ::= SYNCDB db_name REPLICA */ -{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy359); } + case 252: /* cmd ::= SYNCDB db_name REPLICA */ +{ pCxt->pRootNode = createSyncdbStmt(pCxt, &yymsp[-1].minor.yy449); } break; - case 253: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 254: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 254: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 255: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 255: /* literal ::= NK_STRING */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 256: /* literal ::= NK_STRING */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 256: /* literal ::= NK_BOOL */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 257: /* literal ::= NK_BOOL */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 257: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 258: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 258: /* literal ::= duration_literal */ - case 268: /* signed_literal ::= signed */ yytestcase(yyruleno==268); - case 286: /* expression ::= literal */ yytestcase(yyruleno==286); - case 287: /* expression ::= pseudo_column */ yytestcase(yyruleno==287); - case 288: /* expression ::= column_reference */ yytestcase(yyruleno==288); - case 289: /* expression ::= function_expression */ yytestcase(yyruleno==289); - case 290: /* expression ::= subquery */ yytestcase(yyruleno==290); - case 348: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==348); - case 352: /* boolean_primary ::= predicate */ yytestcase(yyruleno==352); - case 354: /* common_expression ::= expression */ yytestcase(yyruleno==354); - case 355: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==355); - case 357: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==357); - case 359: /* table_reference ::= table_primary */ yytestcase(yyruleno==359); - case 360: /* table_reference ::= joined_table */ yytestcase(yyruleno==360); - case 364: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==364); - case 411: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==411); - case 413: /* query_primary ::= query_specification */ yytestcase(yyruleno==413); -{ yylhsminor.yy42 = yymsp[0].minor.yy42; } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 259: /* literal ::= duration_literal */ + case 269: /* signed_literal ::= signed */ yytestcase(yyruleno==269); + case 287: /* expression ::= literal */ yytestcase(yyruleno==287); + case 288: /* expression ::= pseudo_column */ yytestcase(yyruleno==288); + case 289: /* expression ::= column_reference */ yytestcase(yyruleno==289); + case 290: /* expression ::= function_expression */ yytestcase(yyruleno==290); + case 291: /* expression ::= subquery */ yytestcase(yyruleno==291); + case 349: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==349); + case 353: /* boolean_primary ::= predicate */ yytestcase(yyruleno==353); + case 355: /* common_expression ::= expression */ yytestcase(yyruleno==355); + case 356: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==356); + case 358: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==358); + case 360: /* table_reference ::= table_primary */ yytestcase(yyruleno==360); + case 361: /* table_reference ::= joined_table */ yytestcase(yyruleno==361); + case 365: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==365); + case 412: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==412); + case 415: /* query_primary ::= query_specification */ yytestcase(yyruleno==415); +{ yylhsminor.yy392 = yymsp[0].minor.yy392; } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 259: /* literal ::= NULL */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 260: /* literal ::= NULL */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 260: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 261: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 261: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 262: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 262: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 263: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 263: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } + case 264: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); } break; - case 264: /* signed ::= NK_MINUS NK_INTEGER */ + case 265: /* 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.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 265: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 266: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 266: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 267: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 267: /* signed ::= NK_MINUS NK_FLOAT */ + case 268: /* 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.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 269: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 270: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 270: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 271: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 271: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + case 272: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } break; - case 272: /* signed_literal ::= duration_literal */ - case 326: /* star_func_para ::= expression */ yytestcase(yyruleno==326); - case 381: /* select_item ::= common_expression */ yytestcase(yyruleno==381); - case 425: /* search_condition ::= common_expression */ yytestcase(yyruleno==425); -{ yylhsminor.yy42 = releaseRawExprNode(pCxt, yymsp[0].minor.yy42); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 273: /* signed_literal ::= duration_literal */ + case 327: /* star_func_para ::= expression */ yytestcase(yyruleno==327); + case 382: /* select_item ::= common_expression */ yytestcase(yyruleno==382); + case 427: /* search_condition ::= common_expression */ yytestcase(yyruleno==427); +{ yylhsminor.yy392 = releaseRawExprNode(pCxt, yymsp[0].minor.yy392); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 273: /* signed_literal ::= NULL */ -{ yymsp[0].minor.yy42 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } + case 274: /* signed_literal ::= NULL */ +{ yymsp[0].minor.yy392 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL); } break; - case 291: /* expression ::= NK_LP expression NK_RP */ - case 353: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==353); -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy42)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 292: /* expression ::= NK_LP expression NK_RP */ + case 354: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==354); +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 292: /* expression ::= NK_PLUS expression */ + case 293: /* expression ::= NK_PLUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy42)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 293: /* expression ::= NK_MINUS expression */ + case 294: /* expression ::= NK_MINUS expression */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy42), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 294: /* expression ::= expression NK_PLUS expression */ + case 295: /* expression ::= expression NK_PLUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 295: /* expression ::= expression NK_MINUS expression */ + case 296: /* expression ::= expression NK_MINUS expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 296: /* expression ::= expression NK_STAR expression */ + case 297: /* expression ::= expression NK_STAR expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 297: /* expression ::= expression NK_SLASH expression */ + case 298: /* expression ::= expression NK_SLASH expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 298: /* expression ::= expression NK_REM expression */ + case 299: /* expression ::= expression NK_REM expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 299: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 300: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 300: /* expression_list ::= expression */ -{ yylhsminor.yy244 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy42)); } - yymsp[0].minor.yy244 = yylhsminor.yy244; + case 301: /* expression_list ::= expression */ +{ yylhsminor.yy376 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; - case 301: /* expression_list ::= expression_list NK_COMMA expression */ -{ yylhsminor.yy244 = addNodeToList(pCxt, yymsp[-2].minor.yy244, releaseRawExprNode(pCxt, yymsp[0].minor.yy42)); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; + case 302: /* expression_list ::= expression_list NK_COMMA expression */ +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-2].minor.yy376, releaseRawExprNode(pCxt, yymsp[0].minor.yy392)); } + yymsp[-2].minor.yy376 = yylhsminor.yy376; break; - case 302: /* column_reference ::= column_name */ -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy359, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy359)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 303: /* column_reference ::= column_name */ +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy449, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy449)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 303: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy359, createColumnNode(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy359)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 304: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy449, createColumnNode(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy449)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 304: /* pseudo_column ::= ROWTS */ - case 305: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==305); - case 306: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==306); - case 307: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==307); - case 308: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==308); - case 309: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==309); - case 310: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==310); -{ yylhsminor.yy42 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy42 = yylhsminor.yy42; + case 305: /* pseudo_column ::= ROWTS */ + case 306: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==306); + case 307: /* pseudo_column ::= QSTARTTS */ yytestcase(yyruleno==307); + case 308: /* pseudo_column ::= QENDTS */ yytestcase(yyruleno==308); + case 309: /* pseudo_column ::= WSTARTTS */ yytestcase(yyruleno==309); + case 310: /* pseudo_column ::= WENDTS */ yytestcase(yyruleno==310); + case 311: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==311); +{ yylhsminor.yy392 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy392 = yylhsminor.yy392; break; - case 311: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 312: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==312); -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy359, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy359, yymsp[-1].minor.yy244)); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + case 312: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 313: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==313); +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy449, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy449, yymsp[-1].minor.yy376)); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 313: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy42), yymsp[-1].minor.yy314)); } - yymsp[-5].minor.yy42 = yylhsminor.yy42; + case 314: /* function_expression ::= CAST NK_LP expression AS type_name NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy112)); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 314: /* function_expression ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy0, createFunctionNodeNoArg(pCxt, &yymsp[-2].minor.yy359)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 315: /* function_expression ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy0, createFunctionNodeNoArg(pCxt, &yymsp[-2].minor.yy449)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 322: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy244 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy244 = yylhsminor.yy244; + case 323: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy376 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; - case 327: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 384: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==384); -{ yylhsminor.yy42 = createColumnNode(pCxt, &yymsp[-2].minor.yy359, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 328: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 385: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==385); +{ yylhsminor.yy392 = createColumnNode(pCxt, &yymsp[-2].minor.yy449, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 328: /* predicate ::= expression compare_op expression */ - case 333: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==333); + case 329: /* predicate ::= expression compare_op expression */ + case 334: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==334); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy270, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy380, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 329: /* predicate ::= expression BETWEEN expression AND expression */ + case 330: /* predicate ::= expression BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy42), releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-4].minor.yy42 = yylhsminor.yy42; + yymsp[-4].minor.yy392 = yylhsminor.yy392; break; - case 330: /* predicate ::= expression NOT BETWEEN expression AND expression */ + case 331: /* predicate ::= expression NOT BETWEEN expression AND expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy42), releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-5].minor.yy42 = yylhsminor.yy42; + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 331: /* predicate ::= expression IS NULL */ + case 332: /* predicate ::= expression IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), NULL)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 332: /* predicate ::= expression IS NOT NULL */ + case 333: /* predicate ::= expression IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy42), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL)); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 334: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy270 = OP_TYPE_LOWER_THAN; } + case 335: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_THAN; } break; - case 335: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy270 = OP_TYPE_GREATER_THAN; } + case 336: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_THAN; } break; - case 336: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy270 = OP_TYPE_LOWER_EQUAL; } + case 337: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy380 = OP_TYPE_LOWER_EQUAL; } break; - case 337: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy270 = OP_TYPE_GREATER_EQUAL; } + case 338: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy380 = OP_TYPE_GREATER_EQUAL; } break; - case 338: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy270 = OP_TYPE_NOT_EQUAL; } + case 339: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy380 = OP_TYPE_NOT_EQUAL; } break; - case 339: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy270 = OP_TYPE_EQUAL; } + case 340: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy380 = OP_TYPE_EQUAL; } break; - case 340: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy270 = OP_TYPE_LIKE; } + case 341: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy380 = OP_TYPE_LIKE; } break; - case 341: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy270 = OP_TYPE_NOT_LIKE; } + case 342: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_LIKE; } break; - case 342: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy270 = OP_TYPE_MATCH; } + case 343: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy380 = OP_TYPE_MATCH; } break; - case 343: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy270 = OP_TYPE_NMATCH; } + case 344: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy380 = OP_TYPE_NMATCH; } break; - case 344: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy270 = OP_TYPE_JSON_CONTAINS; } + case 345: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy380 = OP_TYPE_JSON_CONTAINS; } break; - case 345: /* in_op ::= IN */ -{ yymsp[0].minor.yy270 = OP_TYPE_IN; } + case 346: /* in_op ::= IN */ +{ yymsp[0].minor.yy380 = OP_TYPE_IN; } break; - case 346: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy270 = OP_TYPE_NOT_IN; } + case 347: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy380 = OP_TYPE_NOT_IN; } break; - case 347: /* in_predicate_value ::= NK_LP expression_list NK_RP */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy244)); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 348: /* in_predicate_value ::= NK_LP expression_list NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy376)); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 349: /* boolean_value_expression ::= NOT boolean_primary */ + case 350: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy42), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy392), NULL)); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 350: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 351: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 351: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 352: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy42); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy42); - yylhsminor.yy42 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy392); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy392); + yylhsminor.yy392 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 358: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy42 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy42, yymsp[0].minor.yy42, NULL); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 359: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy392 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy392, yymsp[0].minor.yy392, NULL); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 361: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy42 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy359, &yymsp[0].minor.yy359); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 362: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy392 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy449, &yymsp[0].minor.yy449); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 362: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy42 = createRealTableNode(pCxt, &yymsp[-3].minor.yy359, &yymsp[-1].minor.yy359, &yymsp[0].minor.yy359); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + case 363: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy392 = createRealTableNode(pCxt, &yymsp[-3].minor.yy449, &yymsp[-1].minor.yy449, &yymsp[0].minor.yy449); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 363: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy42 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy42), &yymsp[0].minor.yy359); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 364: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy392 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy449); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 365: /* alias_opt ::= */ -{ yymsp[1].minor.yy359 = nil_token; } + case 366: /* alias_opt ::= */ +{ yymsp[1].minor.yy449 = nil_token; } break; - case 366: /* alias_opt ::= table_alias */ -{ yylhsminor.yy359 = yymsp[0].minor.yy359; } - yymsp[0].minor.yy359 = yylhsminor.yy359; + case 367: /* alias_opt ::= table_alias */ +{ yylhsminor.yy449 = yymsp[0].minor.yy449; } + yymsp[0].minor.yy449 = yylhsminor.yy449; break; - case 367: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy359 = yymsp[0].minor.yy359; } + case 368: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy449 = yymsp[0].minor.yy449; } break; - case 368: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 369: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==369); -{ yymsp[-2].minor.yy42 = yymsp[-1].minor.yy42; } + case 369: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 370: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==370); +{ yymsp[-2].minor.yy392 = yymsp[-1].minor.yy392; } break; - case 370: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy42 = createJoinTableNode(pCxt, yymsp[-4].minor.yy102, yymsp[-5].minor.yy42, yymsp[-2].minor.yy42, yymsp[0].minor.yy42); } - yymsp[-5].minor.yy42 = yylhsminor.yy42; + case 371: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy392 = createJoinTableNode(pCxt, yymsp[-4].minor.yy372, yymsp[-5].minor.yy392, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-5].minor.yy392 = yylhsminor.yy392; break; - case 371: /* join_type ::= */ -{ yymsp[1].minor.yy102 = JOIN_TYPE_INNER; } + case 372: /* join_type ::= */ +{ yymsp[1].minor.yy372 = JOIN_TYPE_INNER; } break; - case 372: /* join_type ::= INNER */ -{ yymsp[0].minor.yy102 = JOIN_TYPE_INNER; } + case 373: /* join_type ::= INNER */ +{ yymsp[0].minor.yy372 = JOIN_TYPE_INNER; } break; - case 373: /* 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 374: /* 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.yy42 = createSelectStmt(pCxt, yymsp[-7].minor.yy237, yymsp[-6].minor.yy244, yymsp[-5].minor.yy42); - yymsp[-8].minor.yy42 = addWhereClause(pCxt, yymsp[-8].minor.yy42, yymsp[-4].minor.yy42); - yymsp[-8].minor.yy42 = addPartitionByClause(pCxt, yymsp[-8].minor.yy42, yymsp[-3].minor.yy244); - yymsp[-8].minor.yy42 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy42, yymsp[-2].minor.yy42); - yymsp[-8].minor.yy42 = addGroupByClause(pCxt, yymsp[-8].minor.yy42, yymsp[-1].minor.yy244); - yymsp[-8].minor.yy42 = addHavingClause(pCxt, yymsp[-8].minor.yy42, yymsp[0].minor.yy42); + yymsp[-8].minor.yy392 = createSelectStmt(pCxt, yymsp[-7].minor.yy89, yymsp[-6].minor.yy376, yymsp[-5].minor.yy392); + yymsp[-8].minor.yy392 = addWhereClause(pCxt, yymsp[-8].minor.yy392, yymsp[-4].minor.yy392); + yymsp[-8].minor.yy392 = addPartitionByClause(pCxt, yymsp[-8].minor.yy392, yymsp[-3].minor.yy376); + yymsp[-8].minor.yy392 = addWindowClauseClause(pCxt, yymsp[-8].minor.yy392, yymsp[-2].minor.yy392); + yymsp[-8].minor.yy392 = addGroupByClause(pCxt, yymsp[-8].minor.yy392, yymsp[-1].minor.yy376); + yymsp[-8].minor.yy392 = addHavingClause(pCxt, yymsp[-8].minor.yy392, yymsp[0].minor.yy392); } break; - case 376: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy237 = false; } + case 377: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy89 = false; } break; - case 377: /* select_list ::= NK_STAR */ -{ yymsp[0].minor.yy244 = NULL; } + case 378: /* select_list ::= NK_STAR */ +{ yymsp[0].minor.yy376 = NULL; } break; - case 382: /* select_item ::= common_expression column_alias */ -{ yylhsminor.yy42 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy42), &yymsp[0].minor.yy359); } - yymsp[-1].minor.yy42 = yylhsminor.yy42; + case 383: /* select_item ::= common_expression column_alias */ +{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392), &yymsp[0].minor.yy449); } + yymsp[-1].minor.yy392 = yylhsminor.yy392; break; - case 383: /* select_item ::= common_expression AS column_alias */ -{ yylhsminor.yy42 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), &yymsp[0].minor.yy359); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 384: /* select_item ::= common_expression AS column_alias */ +{ yylhsminor.yy392 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), &yymsp[0].minor.yy449); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 388: /* partition_by_clause_opt ::= PARTITION BY expression_list */ - case 405: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==405); - case 415: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==415); -{ yymsp[-2].minor.yy244 = yymsp[0].minor.yy244; } + case 389: /* partition_by_clause_opt ::= PARTITION BY expression_list */ + case 406: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==406); + case 417: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==417); +{ yymsp[-2].minor.yy376 = yymsp[0].minor.yy376; } break; - case 390: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy42 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy42), releaseRawExprNode(pCxt, yymsp[-1].minor.yy42)); } + case 391: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy392 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } break; - case 391: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ -{ yymsp[-3].minor.yy42 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy42)); } + case 392: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expression NK_RP */ +{ yymsp[-3].minor.yy392 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy392)); } break; - case 392: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy42 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy42), NULL, yymsp[-1].minor.yy42, yymsp[0].minor.yy42); } + case 393: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), NULL, yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 393: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy42 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy42), releaseRawExprNode(pCxt, yymsp[-3].minor.yy42), yymsp[-1].minor.yy42, yymsp[0].minor.yy42); } + case 394: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy392 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy392), releaseRawExprNode(pCxt, yymsp[-3].minor.yy392), yymsp[-1].minor.yy392, yymsp[0].minor.yy392); } break; - case 395: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ -{ yymsp[-3].minor.yy42 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy42); } + case 396: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ +{ yymsp[-3].minor.yy392 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy392); } break; - case 397: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy42 = createFillNode(pCxt, yymsp[-1].minor.yy544, NULL); } + case 398: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy392 = createFillNode(pCxt, yymsp[-1].minor.yy102, NULL); } break; - case 398: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy42 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy244)); } + case 399: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy392 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy376)); } break; - case 399: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy544 = FILL_MODE_NONE; } + case 400: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy102 = FILL_MODE_NONE; } break; - case 400: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy544 = FILL_MODE_PREV; } + case 401: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy102 = FILL_MODE_PREV; } break; - case 401: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy544 = FILL_MODE_NULL; } + case 402: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy102 = FILL_MODE_NULL; } break; - case 402: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy544 = FILL_MODE_LINEAR; } + case 403: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy102 = FILL_MODE_LINEAR; } break; - case 403: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy544 = FILL_MODE_NEXT; } + case 404: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy102 = FILL_MODE_NEXT; } break; - case 406: /* group_by_list ::= expression */ -{ yylhsminor.yy244 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); } - yymsp[0].minor.yy244 = yylhsminor.yy244; + case 407: /* group_by_list ::= expression */ +{ yylhsminor.yy376 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } + yymsp[0].minor.yy376 = yylhsminor.yy376; break; - case 407: /* group_by_list ::= group_by_list NK_COMMA expression */ -{ yylhsminor.yy244 = addNodeToList(pCxt, yymsp[-2].minor.yy244, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy42))); } - yymsp[-2].minor.yy244 = yylhsminor.yy244; + case 408: /* group_by_list ::= group_by_list NK_COMMA expression */ +{ yylhsminor.yy376 = addNodeToList(pCxt, yymsp[-2].minor.yy376, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy392))); } + yymsp[-2].minor.yy376 = yylhsminor.yy376; break; - case 410: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 411: /* query_expression ::= query_expression_body order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy42 = addOrderByClause(pCxt, yymsp[-3].minor.yy42, yymsp[-2].minor.yy244); - yylhsminor.yy42 = addSlimitClause(pCxt, yylhsminor.yy42, yymsp[-1].minor.yy42); - yylhsminor.yy42 = addLimitClause(pCxt, yylhsminor.yy42, yymsp[0].minor.yy42); + yylhsminor.yy392 = addOrderByClause(pCxt, yymsp[-3].minor.yy392, yymsp[-2].minor.yy376); + yylhsminor.yy392 = addSlimitClause(pCxt, yylhsminor.yy392, yymsp[-1].minor.yy392); + yylhsminor.yy392 = addLimitClause(pCxt, yylhsminor.yy392, yymsp[0].minor.yy392); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 412: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ -{ yylhsminor.yy42 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy42, yymsp[0].minor.yy42); } - yymsp[-3].minor.yy42 = yylhsminor.yy42; + case 413: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ +{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-3].minor.yy392 = yylhsminor.yy392; break; - case 417: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 421: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==421); -{ yymsp[-1].minor.yy42 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 414: /* query_expression_body ::= query_expression_body UNION query_expression_body */ +{ yylhsminor.yy392 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy392, yymsp[0].minor.yy392); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 418: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 422: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==422); -{ yymsp[-3].minor.yy42 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 419: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 423: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==423); +{ yymsp[-1].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 419: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 423: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==423); -{ yymsp[-3].minor.yy42 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 420: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 424: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==424); +{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 424: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy42 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy42); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 421: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 425: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==425); +{ yymsp[-3].minor.yy392 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 428: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy42 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy42), yymsp[-1].minor.yy508, yymsp[0].minor.yy197); } - yymsp[-2].minor.yy42 = yylhsminor.yy42; + case 426: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy392 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy392); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 429: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy508 = ORDER_ASC; } + case 430: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy392 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy392), yymsp[-1].minor.yy386, yymsp[0].minor.yy361); } + yymsp[-2].minor.yy392 = yylhsminor.yy392; break; - case 430: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy508 = ORDER_ASC; } + case 431: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy386 = ORDER_ASC; } break; - case 431: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy508 = ORDER_DESC; } + case 432: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy386 = ORDER_ASC; } break; - case 432: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy197 = NULL_ORDER_DEFAULT; } + case 433: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy386 = ORDER_DESC; } break; - case 433: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy197 = NULL_ORDER_FIRST; } + case 434: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy361 = NULL_ORDER_DEFAULT; } break; - case 434: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy197 = NULL_ORDER_LAST; } + case 435: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy361 = NULL_ORDER_FIRST; } + break; + case 436: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy361 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index 5427749d09..83dd71a834 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -22,6 +22,7 @@ typedef struct SLogicPlanContext { } 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 createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogicNode** pLogicNode); @@ -343,7 +344,9 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr) } pCol->node.resType = pExpr->resType; strcpy(pCol->colName, pExpr->aliasName); - strcpy(pCol->tableAlias, pStmtName); + if (NULL != pStmtName) { + strcpy(pCol->tableAlias, pStmtName); + } return pCol; } @@ -768,6 +771,137 @@ static int32_t createSelectLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSele return code; } +static int32_t createSetOpChildLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, FCreateSetOpLogicNode func, SLogicNode** pRoot) { + SLogicNode* pNode = NULL; + int32_t code = func(pCxt, pSetOperator, &pNode); + if (TSDB_CODE_SUCCESS == code && NULL != pNode) { + code = pushLogicNode(pCxt, pRoot, pNode); + } + if (TSDB_CODE_SUCCESS != code) { + nodesDestroyNode(pNode); + } + return code; +} + +static int32_t createSetOpSortLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { + if (NULL == pSetOperator->pOrderByList) { + return TSDB_CODE_SUCCESS; + } + + SSortLogicNode* pSort = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SORT); + if (NULL == pSort) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + int32_t code = TSDB_CODE_SUCCESS; + + pSort->node.pTargets = nodesCloneList(pSetOperator->pProjectionList); + if (NULL == pSort->node.pTargets) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + + if (TSDB_CODE_SUCCESS == code) { + pSort->pSortKeys = nodesCloneList(pSetOperator->pOrderByList); + if (NULL == pSort->pSortKeys) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = (SLogicNode*)pSort; + } else { + nodesDestroyNode(pSort); + } + + return code; +} + +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; + } + + if (NULL != pSetOperator->pLimit) { + pProject->limit = ((SLimitNode*)pSetOperator->pLimit)->limit; + pProject->offset = ((SLimitNode*)pSetOperator->pLimit)->offset; + } else { + pProject->limit = -1; + pProject->offset = -1; + } + + int32_t code = TSDB_CODE_SUCCESS; + + pProject->pProjections = nodesCloneList(pSetOperator->pProjectionList); + if (NULL == pProject->pProjections) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + + if (TSDB_CODE_SUCCESS == code) { + code = createColumnByProjections(pCxt, NULL, pSetOperator->pProjectionList, &pProject->node.pTargets); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = (SLogicNode*)pProject; + } else { + nodesDestroyNode(pProject); + } + + return code; +} + +static int32_t createSetOpLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { + SLogicNode* pSetOp = NULL; + int32_t code = TSDB_CODE_SUCCESS; + switch (pSetOperator->opType) { + case SET_OP_TYPE_UNION_ALL: + code = createSetOpProjectLogicNode(pCxt, pSetOperator, &pSetOp); + break; + default: + code = -1; + break; + } + + SLogicNode* pLeft = NULL; + if (TSDB_CODE_SUCCESS == code) { + code = createQueryLogicNode(pCxt, pSetOperator->pLeft, &pLeft); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodesListMakeStrictAppend(&pSetOp->pChildren, (SNode*)pLeft); + } + SLogicNode* pRight = NULL; + if (TSDB_CODE_SUCCESS == code) { + code = createQueryLogicNode(pCxt, pSetOperator->pRight, &pRight); + } + if (TSDB_CODE_SUCCESS == code) { + code = nodesListStrictAppend(pSetOp->pChildren, (SNode*)pRight); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = (SLogicNode*)pSetOp; + } else { + nodesDestroyNode(pSetOp); + } + + return code; +} + +static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator* pSetOperator, SLogicNode** pLogicNode) { + SLogicNode* pRoot = NULL; + int32_t code = createSetOpLogicNode(pCxt, pSetOperator, &pRoot); + if (TSDB_CODE_SUCCESS == code) { + code = createSetOpChildLogicNode(pCxt, pSetOperator, createSetOpSortLogicNode, &pRoot); + } + + if (TSDB_CODE_SUCCESS == code) { + *pLogicNode = pRoot; + } else { + nodesDestroyNode(pRoot); + } + + return code; +} + 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; } @@ -791,6 +925,8 @@ static int32_t createQueryLogicNode(SLogicPlanContext* pCxt, SNode* pStmt, SLogi return createVnodeModifLogicNode(pCxt, (SVnodeModifOpStmt*)pStmt, pLogicNode); case QUERY_NODE_EXPLAIN_STMT: return createQueryLogicNode(pCxt, ((SExplainStmt*)pStmt)->pQuery, pLogicNode); + case QUERY_NODE_SET_OPERATOR: + return createSetOperatorLogicNode(pCxt, (SSetOperator*)pStmt, pLogicNode); default: break; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index caeab20970..745029730f 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -38,7 +38,7 @@ typedef struct SPhysiPlanContext { static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { if (QUERY_NODE_COLUMN == nodeType(pNode)) { SColumnNode* pCol = (SColumnNode*)pNode; - if (NULL != pStmtName) { + if (NULL != pStmtName && '\0' != pStmtName[0]) { return sprintf(pKey, "%s.%s", pStmtName, pCol->node.aliasName); } if ('\0' == pCol->tableAlias[0]) { @@ -47,7 +47,7 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char* pKey) { return sprintf(pKey, "%s.%s", pCol->tableAlias, pCol->colName); } - if (NULL != pStmtName) { + if (NULL != pStmtName && '\0' != pStmtName[0]) { return sprintf(pKey, "%s.%s", pStmtName, ((SExprNode*)pNode)->aliasName); } return sprintf(pKey, "%s", ((SExprNode*)pNode)->aliasName); diff --git a/source/libs/planner/src/planScaleOut.c b/source/libs/planner/src/planScaleOut.c index 2b5fd12e22..7bb97b59d7 100644 --- a/source/libs/planner/src/planScaleOut.c +++ b/source/libs/planner/src/planScaleOut.c @@ -129,7 +129,7 @@ static int32_t pushHierarchicalPlan(SNodeList* pParentsGroup, SNodeList* pCurren return code; } -static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t* pLevel, SNodeList* pParentsGroup) { +static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32_t level, SNodeList* pParentsGroup) { SNodeList* pCurrentGroup = nodesMakeList(); if (NULL == pCurrentGroup) { return TSDB_CODE_OUT_OF_MEMORY; @@ -138,13 +138,13 @@ static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32 int32_t code = TSDB_CODE_SUCCESS; switch (pSubplan->subplanType) { case SUBPLAN_TYPE_MERGE: - code = scaleOutForMerge(pCxt, pSubplan, *pLevel, pCurrentGroup); + code = scaleOutForMerge(pCxt, pSubplan, level, pCurrentGroup); break; case SUBPLAN_TYPE_SCAN: - code = scaleOutForScan(pCxt, pSubplan, *pLevel, pCurrentGroup); + code = scaleOutForScan(pCxt, pSubplan, level, pCurrentGroup); break; case SUBPLAN_TYPE_MODIFY: - code = scaleOutForModify(pCxt, pSubplan, *pLevel, pCurrentGroup); + code = scaleOutForModify(pCxt, pSubplan, level, pCurrentGroup); break; default: break; @@ -152,13 +152,12 @@ static int32_t doScaleOut(SScaleOutContext* pCxt, SLogicSubplan* pSubplan, int32 if (TSDB_CODE_SUCCESS == code) { code = pushHierarchicalPlan(pParentsGroup, pCurrentGroup); - ++(*pLevel); } if (TSDB_CODE_SUCCESS == code) { SNode* pChild; FOREACH(pChild, pSubplan->pChildren) { - code = doScaleOut(pCxt, (SLogicSubplan*)pChild, pLevel, pCurrentGroup); + code = doScaleOut(pCxt, (SLogicSubplan*)pChild, level + 1, pCurrentGroup); if (TSDB_CODE_SUCCESS != code) { break; } @@ -194,7 +193,7 @@ int32_t scaleOutLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SQue } SScaleOutContext cxt = { .pPlanCxt = pCxt, .subplanId = 1 }; - int32_t code = doScaleOut(&cxt, pLogicSubplan, &(pPlan->totalLevel), pPlan->pTopSubplans); + 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 e54cf33934..f091682bc8 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -45,7 +45,12 @@ typedef struct SCtjInfo { SLogicSubplan* pSubplan; } SCtjInfo; -typedef bool (*FSplFindSplitNode)(SLogicSubplan* pSubplan, SStsInfo* pInfo); +typedef struct SUaInfo { + SProjectLogicNode* pProject; + SLogicSubplan* pSubplan; +} SUaInfo; + +typedef bool (*FSplFindSplitNode)(SLogicSubplan* pSubplan, void* pInfo); static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan, int32_t flag) { SLogicSubplan* pSubplan = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); @@ -132,16 +137,10 @@ static bool stsFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { SStsInfo info = {0}; - if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, stsFindSplitNode, &info)) { + if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - if (NULL == info.pSubplan->pChildren) { - info.pSubplan->pChildren = nodesMakeList(); - if (NULL == info.pSubplan->pChildren) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - int32_t code = nodesListStrictAppend(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); } @@ -173,7 +172,7 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) { return NULL; } -static bool ctjFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { +static bool ctjFindSplitNode(SLogicSubplan* pSubplan, SCtjInfo* pInfo) { SLogicNode* pSplitNode = ctjMatchByNode(pSubplan->pNode); if (NULL != pSplitNode) { pInfo->pScan = (SScanLogicNode*)pSplitNode; @@ -184,16 +183,10 @@ static bool ctjFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) { static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { SCtjInfo info = {0}; - if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, ctjFindSplitNode, &info)) { + if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) { return TSDB_CODE_SUCCESS; } - if (NULL == info.pSubplan->pChildren) { - info.pSubplan->pChildren = nodesMakeList(); - if (NULL == info.pSubplan->pChildren) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - int32_t code = nodesListStrictAppend(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); } @@ -202,9 +195,106 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { return code; } +static SLogicNode* uaMatchByNode(SLogicNode* pNode) { + if (QUERY_NODE_LOGIC_PLAN_PROJECT == nodeType(pNode) && LIST_LENGTH(pNode->pChildren) > 1) { + return pNode; + } + SNode* pChild; + FOREACH(pChild, pNode->pChildren) { + SLogicNode* pSplitNode = uaMatchByNode((SLogicNode*)pChild); + if (NULL != pSplitNode) { + return pSplitNode; + } + } + return NULL; +} + +static bool uaFindSplitNode(SLogicSubplan* pSubplan, SUaInfo* pInfo) { + SLogicNode* pSplitNode = uaMatchByNode(pSubplan->pNode); + if (NULL != pSplitNode) { + pInfo->pProject = (SProjectLogicNode*)pSplitNode; + pInfo->pSubplan = pSubplan; + } + return NULL != pSplitNode; +} + +static SLogicSubplan* uaCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode) { + SLogicSubplan* pSubplan = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); + if (NULL == pSubplan) { + return NULL; + } + pSubplan->id.groupId = pCxt->groupId; + pSubplan->subplanType = SUBPLAN_TYPE_SCAN; + pSubplan->pNode = pNode; + // TSWAP(pSubplan->pVgroupList, ((SScanLogicNode*)pSubplan->pNode)->pVgroupList, SVgroupsInfo*); + return pSubplan; +} + +static int32_t uaCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SProjectLogicNode* pProject) { + SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE); + if (NULL == pExchange) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pExchange->srcGroupId = pCxt->groupId; + // pExchange->precision = pScan->pMeta->tableInfo.precision; + pExchange->node.pTargets = nodesCloneList(pProject->node.pTargets); + if (NULL == pExchange->node.pTargets) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + pSubplan->subplanType = SUBPLAN_TYPE_MERGE; + + return nodesListMakeAppend(&pProject->node.pChildren, (SNode*)pExchange); + + // if (NULL == pProject->node.pParent) { + // pSubplan->pNode = (SLogicNode*)pExchange; + // nodesDestroyNode(pProject); + // return TSDB_CODE_SUCCESS; + // } + + // SNode* pNode; + // FOREACH(pNode, pProject->node.pParent->pChildren) { + // if (nodesEqualNode(pNode, pProject)) { + // REPLACE_NODE(pExchange); + // nodesDestroyNode(pNode); + // return TSDB_CODE_SUCCESS; + // } + // } + // nodesDestroyNode(pExchange); + // return TSDB_CODE_FAILED; +} + +static int32_t uaSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { + SUaInfo info = {0}; + if (!splMatch(pCxt, pSubplan, 0, (FSplFindSplitNode)uaFindSplitNode, &info)) { + return TSDB_CODE_SUCCESS; + } + + int32_t code = TSDB_CODE_SUCCESS; + + SNode* pChild = NULL; + FOREACH(pChild, info.pProject->node.pChildren) { + code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, uaCreateSubplan(pCxt, (SLogicNode*)pChild)); + if (TSDB_CODE_SUCCESS == code) { + REPLACE_NODE(NULL); + } else { + break; + } + } + if (TSDB_CODE_SUCCESS == code) { + nodesClearList(info.pProject->node.pChildren); + info.pProject->node.pChildren = NULL; + code = uaCreateExchangeNode(pCxt, info.pSubplan, info.pProject); + } + ++(pCxt->groupId); + pCxt->split = true; + return code; +} + static const SSplitRule splitRuleSet[] = { { .pName = "SuperTableScan", .splitFunc = stsSplit }, { .pName = "ChildTableJoin", .splitFunc = ctjSplit }, + { .pName = "UnionAll", .splitFunc = uaSplit }, }; static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule)); diff --git a/source/libs/planner/test/planSetOpTest.cpp b/source/libs/planner/test/planSetOpTest.cpp new file mode 100644 index 0000000000..d25323f2f3 --- /dev/null +++ b/source/libs/planner/test/planSetOpTest.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "planTestUtil.h" +#include "planner.h" + +using namespace std; + +class PlanSetOpTest : public PlannerTestBase { + +}; + +TEST_F(PlanSetOpTest, unionAll) { + useDb("root", "test"); + + run("select c1, c2 from t1 where c1 > 10 union all select c1, c2 from t1 where c1 > 20"); +} diff --git a/source/libs/planner/test/plannerTestMain.cpp b/source/libs/planner/test/planTestMain.cpp similarity index 100% rename from source/libs/planner/test/plannerTestMain.cpp rename to source/libs/planner/test/planTestMain.cpp diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index 25457d3e41..8198ae3fa0 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -63,6 +63,10 @@ public: SQueryPlan* pPlan = nullptr; doCreatePhysiPlan(&cxt, pLogicPlan, &pPlan, NULL); + + if (g_isDump) { + dump(); + } } catch (...) { dump(); throw; @@ -87,6 +91,7 @@ private: string splitLogicPlan_; string scaledLogicPlan_; string physiPlan_; + vector physiSubplans_; }; void reset() { @@ -115,6 +120,10 @@ private: cout << res_.scaledLogicPlan_ << endl; cout << "physical plan : " << endl; cout << res_.physiPlan_ << endl; + cout << "physical subplan : " << endl; + for (const auto& subplan : res_.physiSubplans_) { + cout << subplan << endl; + } } void doParseSql(const string& sql, SQuery** pQuery) { @@ -156,6 +165,13 @@ private: void doCreatePhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPlan, SArray* pExecNodeList) { DO_WITH_THROW(createPhysiPlan, pCxt, pLogicPlan, pPlan, pExecNodeList); res_.physiPlan_ = toString((SNode*)(*pPlan)); + SNode* pNode; + FOREACH(pNode, (*pPlan)->pSubplans) { + SNode* pSubplan; + FOREACH(pSubplan, ((SNodeListNode*)pNode)->pNodeList) { + res_.physiSubplans_.push_back(toString(pSubplan)); + } + } } void setPlanContext(SQuery* pQuery, SPlanContext* pCxt) { diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index 977fab2e85..2b9e3c7f39 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -308,7 +308,6 @@ struct SFilterInfo { #define FILTER_GET_COL_FIELD_DATA(fi, ri) (colDataGetData(((SColumnInfoData *)(fi)->data), (ri))) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((SValueNode *)((fi)->desc))->node.resType.type) #define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data) -#define FILTER_GET_JSON_VAL_FIELD_DATA(fi) ((char *)(fi)->desc) #define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) #define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) @@ -321,7 +320,6 @@ struct SFilterInfo { #define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_ID(i, u) FILTER_GET_COL_FIELD_ID(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) -#define FILTER_UNIT_JSON_VAL_DATA(i, u) FILTER_GET_JSON_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) #define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) #define FILTER_UNIT_OPTR(u) ((u)->compare.optr) #define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func) diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index f15116bdb7..adbdd13a84 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -56,6 +56,8 @@ static FORCE_INLINE double getVectorDoubleValue_BOOL(void *src, int32_t index) { return (double)*((bool *)src + index); } +double getVectorDoubleValue_JSON(void *src, int32_t index); + static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { _getDoubleValue_fn_t p = NULL; if (srcType == TSDB_DATA_TYPE_TINYINT) { @@ -80,6 +82,8 @@ static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) p = getVectorDoubleValue_DOUBLE; } else if (srcType == TSDB_DATA_TYPE_TIMESTAMP) { p = getVectorDoubleValue_BIGINT; + } else if (srcType == TSDB_DATA_TYPE_JSON) { + p = getVectorDoubleValue_JSON; } else if (srcType == TSDB_DATA_TYPE_BOOL) { p = getVectorDoubleValue_BOOL; } else { diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 191143de12..23047c2930 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -57,28 +57,24 @@ OptrStr gOptrStr[] = { {OP_TYPE_IS_NOT_UNKNOWN, "not unknown"}, // json operator - {OP_TYPE_JSON_GET_VALUE, "json get"}, + {OP_TYPE_JSON_GET_VALUE, "->"}, {OP_TYPE_JSON_CONTAINS, "json contains"} }; bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(maxv, minr); - //if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false; return result >= 0; } bool filterRangeCompGe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(maxv, minr); - //if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false; return result > 0; } bool filterRangeCompLi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(minv, maxr); - //if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false; return result <= 0; } bool filterRangeCompLe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { int32_t result = cfunc(minv, maxr); - //if (result == TSDB_DATA_JSON_CAN_NOT_COMPARE) return false; return result < 0; } bool filterRangeCompii (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { @@ -170,7 +166,7 @@ __compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, setChkInBytes1, setChkInBytes2, setChkInBytes4, setChkInBytes8, compareStrRegexCompMatch, compareStrRegexCompNMatch, setChkNotInBytes1, setChkNotInBytes2, setChkNotInBytes4, setChkNotInBytes8, - compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch + compareChkNotInString, compareStrPatternNotMatch, compareWStrPatternNotMatch, compareJsonContainsKey }; int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { @@ -221,7 +217,12 @@ int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { assert(0); } } - + + if (optr == OP_TYPE_JSON_CONTAINS && type == TSDB_DATA_TYPE_JSON) { + return 28; + } + + switch (type) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: comparFn = 1; break; @@ -1049,6 +1050,8 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { cell = cell->pNext; } + colDataDestroy(out.columnData); + taosMemoryFree(out.columnData); } else { filterAddFieldFromNode(info, node->pRight, &right); @@ -1778,9 +1781,9 @@ int32_t fltInitValFieldData(SFilterInfo *info) { bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; fi->data = taosMemoryCalloc(1, bytes); - } else if (type != TSDB_DATA_TYPE_JSON){ + } else{ if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE -/* +/* fi->data = taosMemoryCalloc(dType->bytes, tDataTypes[type].bytes); for (int32_t a = 0; a < dType->bytes; ++a) { int64_t *v = taosArrayGet(var->arr, a); @@ -1791,31 +1794,29 @@ int32_t fltInitValFieldData(SFilterInfo *info) { } else { fi->data = taosMemoryCalloc(1, sizeof(int64_t)); } - } else{ // type == TSDB_DATA_TYPE_JSON - // fi->data = null; use fi->desc as data, because json value is variable, so use tVariant (fi->desc) } - if(type != TSDB_DATA_TYPE_JSON) { - if (dType->type == type) { - assignVal(fi->data, nodesGetValueFromNode(var), dType->bytes, type); + if (dType->type == type) { + assignVal(fi->data, nodesGetValueFromNode(var), dType->bytes, type); + } else { + SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; + out.columnData->info.type = type; + if (IS_VAR_DATA_TYPE(type)) { + out.columnData->info.bytes = bytes; } else { - SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; - out.columnData->info.type = type; - if (IS_VAR_DATA_TYPE(type)) { - out.columnData->info.bytes = bytes; - } else { - out.columnData->info.bytes = tDataTypes[type].bytes; - } - - // todo refactor the convert - int32_t code = doConvertDataType(var, &out); - if (code != TSDB_CODE_SUCCESS) { - qError("convert value to type[%d] failed", type); - return TSDB_CODE_TSC_INVALID_OPERATION; - } - - memcpy(fi->data, out.columnData->pData, out.columnData->info.bytes); + out.columnData->info.bytes = tDataTypes[type].bytes; } + + // todo refactor the convert + int32_t code = doConvertDataType(var, &out); + if (code != TSDB_CODE_SUCCESS) { + qError("convert value to type[%d] failed", type); + return TSDB_CODE_TSC_INVALID_OPERATION; + } + + memcpy(fi->data, out.columnData->pData, out.columnData->info.bytes); + colDataDestroy(out.columnData); + taosMemoryFree(out.columnData); } // match/nmatch for nchar type need convert from ucs4 to mbs @@ -2556,11 +2557,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->cunits[i].colId = FILTER_UNIT_COL_ID(info, unit); if (unit->right.type == FLD_TYPE_VALUE) { - if(FILTER_UNIT_DATA_TYPE(unit) == TSDB_DATA_TYPE_JSON){ // json value is tVariant - info->cunits[i].valData = FILTER_UNIT_JSON_VAL_DATA(info, unit); - }else{ - info->cunits[i].valData = FILTER_UNIT_VAL_DATA(info, unit); - } + info->cunits[i].valData = FILTER_UNIT_VAL_DATA(info, unit); } else { info->cunits[i].valData = NULL; } @@ -2886,18 +2883,8 @@ static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, for (int32_t i = 0; i < numOfRows; ++i) { uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); - if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){ - if (!colData){ // for json->'key' is null - (*p)[i] = 1; - }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is null - colData = POINTER_SHIFT(colData, CHAR_BYTES); - (*p)[i] = colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL); - }else{ - (*p)[i] = 0; - } - }else{ - (*p)[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); - } + (*p)[i] = ((colData == NULL) || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); + if ((*p)[i] == 0) { all = false; } @@ -2921,19 +2908,7 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows uint32_t uidx = info->groups[0].unitIdxs[0]; void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i); - if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_JSON){ - if (!colData) { // for json->'key' is not null - (*p)[i] = 0; - }else if( *(char*)colData == TSDB_DATA_TYPE_JSON){ // for json is not null - colData = POINTER_SHIFT(colData, CHAR_BYTES); - (*p)[i] = !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL); - }else{ // for json->'key' is not null - (*p)[i] = 1; - } - }else { - (*p)[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); - } - + (*p)[i] = ((colData != NULL) && !colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)); if ((*p)[i] == 0) { all = false; } @@ -3566,6 +3541,11 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } + if (OP_TYPE_JSON_CONTAINS == node->opType) { + stat->scalarMode = true; + return DEAL_RES_CONTINUE; + } + if (QUERY_NODE_COLUMN != nodeType(node->pLeft)) { SNode *t = node->pLeft; node->pLeft = node->pRight; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 337a773d5c..145afbe984 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -132,6 +132,7 @@ void sclFreeRes(SHashObj *res) { void sclFreeParam(SScalarParam *param) { if (param->columnData != NULL) { colDataDestroy(param->columnData); + taosMemoryFree(param->columnData); } if (param->pHashFilter != NULL) { @@ -605,37 +606,48 @@ EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { STargetNode *target = (STargetNode *)pNode; - + if (target->dataBlockId >= taosArrayGetSize(ctx->pBlockList)) { sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } - SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, target->dataBlockId); + int32_t index = -1; + for(int32_t i = 0; i < taosArrayGetSize(ctx->pBlockList); ++i) { + SSDataBlock* pb = taosArrayGetP(ctx->pBlockList, i); + if (pb->info.blockId == target->dataBlockId) { + index = i; + break; + } + } + + if (index == -1) { + sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", target->dataBlockId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + ctx->code = TSDB_CODE_QRY_INVALID_INPUT; + return DEAL_RES_ERROR; + } + + SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, index); + if (target->slotId >= taosArrayGetSize(block->pDataBlock)) { sclError("target slot not exist, dataBlockId:%d, slotId:%d, dataBlockNum:%d", target->dataBlockId, target->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } + // if block->pDataBlock is not enough, there are problems if target->slotId bigger than the size of block->pDataBlock, SColumnInfoData *col = taosArrayGet(block->pDataBlock, target->slotId); - + SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); if (NULL == res) { sclError("no valid res in hash, node:%p, type:%d", target->pExpr, nodeType(target->pExpr)); ctx->code = TSDB_CODE_QRY_APP_ERROR; return DEAL_RES_ERROR; } - - for (int32_t i = 0; i < res->numOfRows; ++i) { - if (colDataIsNull(res->columnData, res->numOfRows, i, NULL)) { - colDataAppend(col, i, NULL, true); - } else { - char *p = colDataGetData(res->columnData, i); - colDataAppend(col, i, p, false); - } - } + + colDataAssign(col, res->columnData, res->numOfRows); + block->info.rows = res->numOfRows; sclFreeParam(res); taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index c49b053c22..0559792740 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -4,6 +4,7 @@ #include "ttime.h" #include "sclInt.h" #include "sclvector.h" +#include "tjson.h" typedef float (*_float_fn)(float); typedef double (*_double_fn)(double); @@ -587,10 +588,6 @@ static int32_t doTrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarPar } int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { - if (inputNum != 2 && inputNum!= 3) { - return TSDB_CODE_FAILED; - } - int32_t subPos = 0; GET_TYPED_DATA(subPos, int32_t, GET_PARAM_TYPE(&pInput[1]), pInput[1].columnData->pData); if (subPos == 0) { //subPos needs to be positive or negative values; @@ -719,7 +716,8 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false"); varDataSetLen(output, len); } else if (inputType == TSDB_DATA_TYPE_BINARY) { - int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), varDataVal(input)); + int32_t len = MIN(varDataLen(input), outputLen - VARSTR_HEADER_SIZE); + len = sprintf(varDataVal(output), "%.*s", len, varDataVal(input)); varDataSetLen(output, len); } else if (inputType == TSDB_DATA_TYPE_NCHAR) { //not support @@ -876,6 +874,59 @@ int32_t toUnixtimestampFunction(SScalarParam *pInput, int32_t inputNum, SScalarP return TSDB_CODE_SUCCESS; } +int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { + int32_t type = GET_PARAM_TYPE(pInput); + if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) { + return TSDB_CODE_FAILED; + } + + if (inputNum != 1) { + return TSDB_CODE_FAILED; + } + + char *input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0]; + char *tmp = taosMemoryCalloc(pInput[0].columnData->info.bytes + 1, 1); + for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { + if (colDataIsNull_s(pInput[0].columnData, i)) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + if(type == TSDB_DATA_TYPE_NCHAR){ + if (varDataTLen(input) > TSDB_MAX_JSON_TAG_LEN){ + colDataAppendNULL(pOutput->columnData, i); + continue; + } + int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), tmp); + if (len < 0) { + colDataAppendNULL(pOutput->columnData, i); + continue; + } + tmp[len] = 0; + }else{ + if (varDataLen(input) > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE){ + colDataAppendNULL(pOutput->columnData, i); + continue; + } + memcpy(tmp, varDataVal(input), varDataLen(input)); + tmp[varDataTLen(input)] = 0; + } + + if(!tjsonValidateJson(tmp)){ + colDataAppendNULL(pOutput->columnData, i); + continue; + } + + colDataAppend(pOutput->columnData, i, input, false); + input += varDataTLen(input); + } + taosMemoryFree(tmp); + + pOutput->numOfRows = pInput->numOfRows; + + return TSDB_CODE_SUCCESS; +} + int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t type = GET_PARAM_TYPE(&pInput[0]); int32_t timePrec = GET_PARAM_PRECISON(&pInput[0]); diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 0131a94fec..d484738328 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -25,6 +25,78 @@ #include "tdatablock.h" #include "ttypes.h" +#define LEFT_COL ((pLeftCol->info.type == TSDB_DATA_TYPE_JSON ? (void*)pLeftCol : pLeftCol->pData)) +#define RIGHT_COL ((pRightCol->info.type == TSDB_DATA_TYPE_JSON ? (void*)pRightCol : pRightCol->pData)) + +void convertNumberToNumber(const void *inData, void *outData, int8_t inType, int8_t outType){ + switch (outType) { + case TSDB_DATA_TYPE_BOOL: { + GET_TYPED_DATA(*((bool *)outData), bool, inType, inData); + break; + } + case TSDB_DATA_TYPE_TINYINT: { + GET_TYPED_DATA(*((int8_t *)outData), int8_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + GET_TYPED_DATA(*((int16_t *)outData), int16_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_INT: { + GET_TYPED_DATA(*((int32_t *)outData), int32_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: { + GET_TYPED_DATA(*((int64_t *)outData), int64_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_UTINYINT: { + GET_TYPED_DATA(*((uint8_t *)outData), uint8_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_USMALLINT: { + GET_TYPED_DATA(*((uint16_t *)outData), uint16_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_UINT: { + GET_TYPED_DATA(*((uint32_t *)outData), uint32_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_UBIGINT: { + GET_TYPED_DATA(*((uint64_t *)outData), uint64_t, inType, inData); + break; + } + case TSDB_DATA_TYPE_FLOAT: { + GET_TYPED_DATA(*((float *)outData), float, inType, inData); + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + GET_TYPED_DATA(*((double *)outData), double, inType, inData); + break; + } + default:{ + ASSERT(0); + } + } +} + +void convertStringToDouble(const void *inData, void *outData, int8_t inType, int8_t outType){ + char *tmp = taosMemoryMalloc(varDataTLen(inData)); + int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); + if (len < 0) { + sclError("castConvert taosUcs4ToMbs error 1"); + } + + tmp[len] = 0; + + ASSERT(outType == TSDB_DATA_TYPE_DOUBLE); + double value = strtod(tmp, NULL); + + *((double *)outData) = value; + taosMemoryFreeClear(tmp); +} + typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { @@ -61,6 +133,20 @@ int64_t getVectorBigintValue_BOOL(void *src, int32_t index) { return (int64_t)*((bool *)src + index); } +int64_t getVectorBigintValue_JSON(void *src, int32_t index){ + ASSERT(!colDataIsNull_var(((SColumnInfoData*)src), index)); + char *data = colDataGetVarData((SColumnInfoData*)src, index); + double out = 0; + if (*data == TSDB_DATA_TYPE_NULL){ + return 0; + } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY + convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + } else { + convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + } + return (int64_t)out; +} + _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { _getBigintValue_fn_t p = NULL; if(srcType==TSDB_DATA_TYPE_TINYINT) { @@ -87,6 +173,8 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { 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); } @@ -213,7 +301,8 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in func = varToUnsigned; } else if (IS_FLOAT_TYPE(outType)) { func = varToFloat; - } else if (outType == TSDB_DATA_TYPE_NCHAR) { + } else if (outType == TSDB_DATA_TYPE_NCHAR) { // binary -> nchar + ASSERT(inType == TSDB_DATA_TYPE_VARCHAR); func = varToNchar; vton = true; } else { @@ -228,14 +317,28 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in continue; } - char* data = colDataGetData(pIn->columnData, i); + char* data = colDataGetVarData(pIn->columnData, i); + int32_t convertType = inType; + if(inType == TSDB_DATA_TYPE_JSON){ + if(*data == TSDB_DATA_TYPE_NULL) { + colDataAppendNULL(pOut->columnData, i); + continue; + } + else if(*data == TSDB_DATA_TYPE_NCHAR) { + data += CHAR_BYTES; + convertType = TSDB_DATA_TYPE_NCHAR; + } else { + convertNumberToNumber(data+CHAR_BYTES, colDataGetNumData(pOut->columnData, i), *data, outType); + continue; + } + } if (vton) { memcpy(tmp, data, varDataTLen(data)); } else { - if (TSDB_DATA_TYPE_VARCHAR == inType) { + if (TSDB_DATA_TYPE_VARCHAR == convertType) { memcpy(tmp, varDataVal(data), varDataLen(data)); tmp[varDataLen(data)] = 0; - } else { + } else if (TSDB_DATA_TYPE_NCHAR == convertType){ ASSERT(varDataLen(data) <= bufSize); int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp); @@ -256,6 +359,66 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in return TSDB_CODE_SUCCESS; } +double getVectorDoubleValue_JSON(void *src, int32_t index){ + char *data = colDataGetVarData((SColumnInfoData*)src, index); + double out = 0; + if (*data == TSDB_DATA_TYPE_NULL){ + return out; + } else if(*data == TSDB_DATA_TYPE_NCHAR) { // json inner type can not be BINARY + convertStringToDouble(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + } else { + convertNumberToNumber(data+CHAR_BYTES, &out, *data, TSDB_DATA_TYPE_DOUBLE); + } + return out; +} + +void convertJsonValue(__compar_fn_t *fp, int32_t optr, int8_t typeLeft, int8_t typeRight, char **pLeftData, char **pRightData, void *pLeftOut, void *pRightOut, bool *isNull){ + if(optr == OP_TYPE_JSON_CONTAINS) { + return; + } + + if(typeLeft != TSDB_DATA_TYPE_JSON && typeRight != TSDB_DATA_TYPE_JSON){ + return; + } + + if(typeLeft == TSDB_DATA_TYPE_JSON){ + typeLeft = **pLeftData; + (*pLeftData) ++; + } + if(typeRight == TSDB_DATA_TYPE_JSON){ + typeRight = **pRightData; + (*pRightData) ++; + } + if(typeLeft == TSDB_DATA_TYPE_NULL || typeRight == TSDB_DATA_TYPE_NULL){ + *isNull = true; + return; + } + int8_t type = vectorGetConvertType(typeLeft, typeRight); + + if(type == 0) { + *fp = filterGetCompFunc(typeLeft, optr); + return; + } + + *fp = filterGetCompFunc(type, optr); + + if(typeLeft == TSDB_DATA_TYPE_NCHAR) { + convertStringToDouble(*pLeftData, pLeftOut, typeLeft, type); + *pLeftData = pLeftOut; + } else if(typeLeft != type) { + convertNumberToNumber(*pLeftData, pLeftOut, typeLeft, type); + *pLeftData = pLeftOut; + } + + if(typeRight == TSDB_DATA_TYPE_NCHAR) { + convertStringToDouble(*pRightData, pRightOut, typeRight, type); + *pRightData = pRightOut; + } else if(typeRight != type) { + convertNumberToNumber(*pRightData, pRightOut, typeRight, type); + *pRightData = pRightOut; + } +} + // TODO opt performance int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { SColumnInfoData* pInputCol = pIn->columnData; @@ -422,24 +585,24 @@ int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) { } int8_t gConvertTypes[TSDB_DATA_TYPE_BLOB+1][TSDB_DATA_TYPE_BLOB+1] = { -/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG VARB JSON DECI BLOB */ +/* NULL BOOL TINY SMAL INT BIG FLOA DOUB VARC TIME NCHA UTIN USMA UINT UBIG JSON VARB DECI BLOB */ /*NULL*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -/*BOOL*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 0, 12, 13, 14, 7, 0, 0, 0, -/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 0, 0, 0, -/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 7, 0, 0, 0, -/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 7, 0, 0, 0, -/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 5, 5, 5, 7, 7, 0, 0, 0, -/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 7, 0, 0, 0, -/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 0, 0, 0, +/*BOOL*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 0, 12, 13, 14, 0, 7, 0, 0, +/*TINY*/ 0, 0, 0, 3, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, +/*SMAL*/ 0, 0, 0, 0, 4, 5, 6, 7, 7, 9, 7, 3, 4, 5, 7, 0, 7, 0, 0, +/*INT */ 0, 0, 0, 0, 0, 5, 6, 7, 7, 9, 7, 4, 4, 5, 7, 0, 7, 0, 0, +/*BIGI*/ 0, 0, 0, 0, 0, 0, 6, 7, 7, 0, 7, 5, 5, 5, 7, 0, 7, 0, 0, +/*FLOA*/ 0, 0, 0, 0, 0, 0, 0, 7, 7, 6, 7, 6, 6, 6, 6, 0, 7, 0, 0, +/*DOUB*/ 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 0, 7, 0, 0, /*VARC*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 7, 7, 7, 7, 0, 0, 0, 0, -/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 9, 7, 7, 0, 0, 0, +/*TIME*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 9, 7, 0, 7, 0, 0, /*NCHA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 0, 0, 0, -/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 7, 0, 0, 0, -/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 7, 0, 0, 0, -/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 7, 0, 0, 0, -/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, -/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*UTIN*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, 0, 7, 0, 0, +/*USMA*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 14, 0, 7, 0, 0, +/*UINT*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 7, 0, 0, +/*UBIG*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, /*JSON*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/*VARB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*DECI*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /*BLOB*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -530,7 +693,7 @@ enum { static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) { SColumnInfoData* pCol = pParam->columnData; - if (IS_VAR_DATA_TYPE(pCol->info.type)) { + if (IS_VAR_DATA_TYPE(pCol->info.type) && pCol->info.type != TSDB_DATA_TYPE_JSON) { pDest->numOfRows = pParam->numOfRows; SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; @@ -564,11 +727,12 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0); - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + + getVectorDoubleValueFnRight(RIGHT_COL, 0); } } } @@ -583,12 +747,12 @@ static void vectorMathBigintAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, 0); } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); - } } } @@ -614,6 +778,50 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) { } } +char *getJsonValue(char *json, char *key){ //todo + int16_t cols = kvRowNCols(json); + for (int i = 0; i < cols; ++i) { + SColIdx *pColIdx = kvRowColIdxAt(json, i); + char *data = kvRowColVal(json, pColIdx); + if(i == 0){ + if(*data == TSDB_DATA_TYPE_NULL) { + return NULL; + } + continue; + } + if(memcmp(key, data, varDataTLen(data)) == 0){ + return data + varDataTLen(data); + } + } + return NULL; +} + +void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows); + + char *pRightData = colDataGetVarData(pRight->columnData, 0); + for (; i >= 0 && i < pLeft->numOfRows; i += step) { + if (colDataIsNull_var(pLeft->columnData, i)) { + colDataSetNull_var(pOutputCol, i); + pOutputCol->hasNull = true; + continue; + } + char *pLeftData = colDataGetVarData(pLeft->columnData, i); + char *value = getJsonValue(pLeftData, pRightData); + if (!value) { + colDataSetNull_var(pOutputCol, i); + pOutputCol->hasNull = true; + continue; + } + colDataAppend(pOutputCol, i, value, false); + } +} + void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { SColumnInfoData *pOutputCol = pOut->columnData; @@ -636,17 +844,12 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, i); } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; - } - } - } else if (pLeft->numOfRows == 1) { vectorMathBigintAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); } else if (pRight->numOfRows == 1) { @@ -659,17 +862,12 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + getVectorDoubleValueFnRight(RIGHT_COL, i); } - } else if (pLeft->numOfRows == 1) { vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); } else if (pRight->numOfRows == 1) { @@ -692,11 +890,12 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { - *output = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor; - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = (getVectorDoubleValueFnLeft(LEFT_COL, i) + - getVectorDoubleValueFnRight(RIGHT_COL, 0)) * factor; } } } @@ -711,12 +910,12 @@ static void vectorMathBigintSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } *output = (getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, 0)) * factor; } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); - } } } @@ -740,17 +939,12 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, i); } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; - } - } - } else if (pLeft->numOfRows == 1) { vectorMathBigintSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i); } else if (pRight->numOfRows == 1) { @@ -763,17 +957,12 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) - getVectorDoubleValueFnRight(RIGHT_COL, i); } - } else if (pLeft->numOfRows == 1) { vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i); } else if (pRight->numOfRows == 1) { @@ -796,11 +985,12 @@ static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0); - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + * getVectorDoubleValueFnRight(RIGHT_COL, 0); } } } @@ -822,17 +1012,13 @@ void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam double *output = (double *)pOutputCol->pData; if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + * getVectorDoubleValueFnRight(RIGHT_COL, i); } - } else if (pLeft->numOfRows == 1) { vectorMathMultiplyHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); } else if (pRight->numOfRows == 1) { @@ -860,39 +1046,37 @@ void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *p double *output = (double *)pOutputCol->pData; if (pLeft->numOfRows == pRight->numOfRows) { // check for the 0 value for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + /getVectorDoubleValueFnRight(RIGHT_COL, i); } - } else if (pLeft->numOfRows == 1) { - if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + if (colDataIsNull_s(pLeftCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, 0) / getVectorDoubleValueFnRight(pRightCol->pData, i); - } - pOutputCol->hasNull = pRightCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pRightCol->nullbitmap, BitmapLen(pRight->numOfRows)); + if (colDataIsNull_s(pRightCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorDoubleValueFnLeft(LEFT_COL, 0) + / getVectorDoubleValueFnRight(RIGHT_COL, i); } } } else if (pRight->numOfRows == 1) { - if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + if (colDataIsNull_s(pRightCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { - *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0); - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorDoubleValueFnLeft(LEFT_COL, i) + / getVectorDoubleValueFnRight(RIGHT_COL, 0); } } } @@ -920,13 +1104,13 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) { + if (colDataIsNull_s(pLeftCol, i) || colDataIsNull_s(pRightCol, i)) { colDataAppendNULL(pOutputCol, i); continue; } - double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); - double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + double lx = getVectorDoubleValueFnLeft(LEFT_COL, i); + double rx = getVectorDoubleValueFnRight(RIGHT_COL, i); if (isnan(lx) || isinf(lx) || isnan(rx) || isinf(rx)) { colDataAppendNULL(pOutputCol, i); continue; @@ -935,17 +1119,17 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output = lx - ((int64_t)(lx / rx)) * rx; } } else if (pLeft->numOfRows == 1) { - double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, 0); - if (colDataIsNull_f(pLeftCol->nullbitmap, 0) || isnan(lx) || isinf(lx)) { // Set pLeft->numOfRows NULL value + double lx = getVectorDoubleValueFnLeft(LEFT_COL, 0); + if (colDataIsNull_s(pLeftCol, 0) || isnan(lx) || isinf(lx)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pRight->numOfRows); } else { for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { - if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + if (colDataIsNull_s(pRightCol, i)) { colDataAppendNULL(pOutputCol, i); continue; } - double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + double rx = getVectorDoubleValueFnRight(RIGHT_COL, i); if (isnan(rx) || isinf(rx) || FLT_EQUAL(rx, 0)) { colDataAppendNULL(pOutputCol, i); continue; @@ -955,17 +1139,17 @@ void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam } } } else if (pRight->numOfRows == 1) { - double rx = getVectorDoubleValueFnRight(pRightCol->pData, 0); - if (colDataIsNull_f(pRightCol->nullbitmap, 0) || FLT_EQUAL(rx, 0)) { // Set pLeft->numOfRows NULL value + double rx = getVectorDoubleValueFnRight(RIGHT_COL, 0); + if (colDataIsNull_s(pRightCol, 0) || FLT_EQUAL(rx, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, pLeft->numOfRows); } else { for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { - if (colDataIsNull_f(pLeftCol->nullbitmap, i)) { + if (colDataIsNull_s(pLeftCol, i)) { colDataAppendNULL(pOutputCol, i); continue; } - double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); + double lx = getVectorDoubleValueFnLeft(LEFT_COL, i); if (isnan(lx) || isinf(lx)) { colDataAppendNULL(pOutputCol, i); continue; @@ -995,12 +1179,11 @@ void vectorMathMinus(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO double *output = (double *)pOutputCol->pData; for (; i < pLeft->numOfRows && i >= 0; i += step, output += 1) { - *output = - getVectorDoubleValueFnLeft(pLeftCol->pData, i); - } - - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows)); + if (colDataIsNull_s(pLeft->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = - getVectorDoubleValueFnLeft(LEFT_COL, i); } doReleaseVec(pLeftCol, leftConvert); @@ -1063,15 +1246,15 @@ static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRigh double *output = (double *)pOutputCol->pData; - if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + if (colDataIsNull_s(pRightCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { for (; i >= 0 && i < numOfRows; i += step, output += 1) { - *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0); - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorBigintValueFnLeft(LEFT_COL, i) & getVectorBigintValueFnRight(RIGHT_COL, 0); } } } @@ -1093,17 +1276,12 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int64_t *output = (int64_t *)pOutputCol->pData; if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] & pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorBigintValueFnLeft(LEFT_COL, i) & getVectorBigintValueFnRight(RIGHT_COL, i); } - } else if (pLeft->numOfRows == 1) { vectorBitAndHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); } else if (pRight->numOfRows == 1) { @@ -1120,16 +1298,16 @@ static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRight int64_t *output = (int64_t *)pOutputCol->pData; - if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + if (colDataIsNull_s(pRightCol, 0)) { // Set pLeft->numOfRows NULL value colDataAppendNNULL(pOutputCol, 0, numOfRows); } else { - int64_t rx = getVectorBigintValueFnRight(pRightCol->pData, 0); + int64_t rx = getVectorBigintValueFnRight(RIGHT_COL, 0); for (; i >= 0 && i < numOfRows; i += step, output += 1) { - *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | rx; - } - pOutputCol->hasNull = pLeftCol->hasNull; - if (pOutputCol->hasNull) { - memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + if (colDataIsNull_s(pLeftCol, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore + } + *output = getVectorBigintValueFnLeft(LEFT_COL, i) | rx; } } } @@ -1151,15 +1329,11 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int64_t *output = (int64_t *)pOutputCol->pData; if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { - *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | getVectorBigintValueFnRight(pRightCol->pData, i); - } - - pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); - if (pOutputCol->hasNull) { - int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); - for (int32_t j = 0; j < numOfBitLen; ++j) { - pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOutputCol, i); + continue; // TODO set null or ignore } + *output = getVectorBigintValueFnLeft(LEFT_COL, i) | getVectorBigintValueFnRight(RIGHT_COL, i); } } else if (pLeft->numOfRows == 1) { vectorBitOrHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); @@ -1181,6 +1355,7 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * if (pRight->pHashFilter != NULL) { for (; i >= 0 && i < pLeft->numOfRows; i += step) { if (colDataIsNull_s(pLeft->columnData, i)) { + colDataAppendNULL(pOut->columnData, i); continue; } @@ -1194,35 +1369,62 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam * if (pLeft->numOfRows == pRight->numOfRows) { for (; i < pRight->numOfRows && i >= 0; i += step) { if (colDataIsNull_s(pLeft->columnData, i) || colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOut->columnData, i); continue; // TODO set null or ignore } char *pLeftData = colDataGetData(pLeft->columnData, i); char *pRightData = colDataGetData(pRight->columnData, i); + + int64_t leftOut = 0; + int64_t rightOut = 0; + bool isJsonnull = false; + convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); + if(isJsonnull){ + colDataAppendNULL(pOut->columnData, i); + continue; // TODO set null or ignore + } bool res = filterDoCompare(fp, optr, pLeftData, pRightData); colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } } else if (pRight->numOfRows == 1) { - char *pRightData = colDataGetData(pRight->columnData, 0); ASSERT(pLeft->pHashFilter == NULL); - for (; i >= 0 && i < pLeft->numOfRows; i += step) { if (colDataIsNull_s(pLeft->columnData, i)) { + colDataAppendNULL(pOut->columnData, i); continue; } char *pLeftData = colDataGetData(pLeft->columnData, i); + char *pRightData = colDataGetData(pRight->columnData, 0); + int64_t leftOut = 0; + int64_t rightOut = 0; + bool isJsonnull = false; + convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); + if(isJsonnull){ + colDataAppendNULL(pOut->columnData, i); + continue; // TODO set null or ignore + } bool res = filterDoCompare(fp, optr, pLeftData, pRightData); colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } } else if (pLeft->numOfRows == 1) { - char *pLeftData = colDataGetData(pLeft->columnData, 0); for (; i >= 0 && i < pRight->numOfRows; i += step) { if (colDataIsNull_s(pRight->columnData, i)) { + colDataAppendNULL(pOut->columnData, i); continue; } + char *pLeftData = colDataGetData(pLeft->columnData, 0); char *pRightData = colDataGetData(pLeft->columnData, i); + int64_t leftOut = 0; + int64_t rightOut = 0; + bool isJsonnull = false; + convertJsonValue(&fp, optr, GET_PARAM_TYPE(pLeft), GET_PARAM_TYPE(pRight), &pLeftData, &pRightData, &leftOut, &rightOut, &isJsonnull); + if(isJsonnull){ + colDataAppendNULL(pOut->columnData, i); + continue; // TODO set null or ignore + } bool res = filterDoCompare(fp, optr, pLeftData, pRightData); colDataAppendInt8(pOut->columnData, i, (int8_t*)&res); } @@ -1303,6 +1505,10 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH); } +void vectorJsonContains(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_JSON_CONTAINS); +} + void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { for(int32_t i = 0; i < pLeft->numOfRows; ++i) { int8_t v = colDataIsNull_s(pLeft->columnData, i)? 1:0; @@ -1371,8 +1577,13 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { return vectorBitOr; case OP_TYPE_IS_TRUE: return vectorIsTrue; + case OP_TYPE_JSON_GET_VALUE: + return vectorJsonArrow; + case OP_TYPE_JSON_CONTAINS: + return vectorJsonContains; default: assert(0); return NULL; } } + diff --git a/source/libs/scalar/test/scalar/CMakeLists.txt b/source/libs/scalar/test/scalar/CMakeLists.txt index 6cbac1e25d..03418d17ac 100644 --- a/source/libs/scalar/test/scalar/CMakeLists.txt +++ b/source/libs/scalar/test/scalar/CMakeLists.txt @@ -8,11 +8,12 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(scalarTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( scalarTest - PUBLIC os util common gtest qcom function nodes scalar + PUBLIC os util common gtest qcom function nodes scalar parser ) TARGET_INCLUDE_DIRECTORIES( scalarTest PUBLIC "${TD_SOURCE_DIR}/include/libs/scalar/" + PUBLIC "${TD_SOURCE_DIR}/source/libs/parser/inc" PRIVATE "${TD_SOURCE_DIR}/source/libs/scalar/inc" ) diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 09d6528dd8..de76e7e274 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -38,6 +38,7 @@ #include "scalar.h" #include "nodes.h" #include "tlog.h" +#include "parUtil.h" #define _DEBUG_PRINT_ 0 @@ -92,6 +93,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s blockDataEnsureCapacity(res, rows); *dataBlockId = taosArrayGetSize(pBlockList) - 1; + res->info.blockId = *dataBlockId; *slotId = 0; } else { SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); @@ -909,6 +911,264 @@ TEST(constantTest, greater_and_lower) { nodesDestroyNode(res); } +void makeJsonArrow(SSDataBlock **src, SNode **opNode, void *json, char *key){ + char keyVar[32] = {0}; + memcpy(varDataVal(keyVar), key, strlen(key)); + varDataLen(keyVar) = strlen(key); + + SNode *pLeft = NULL, *pRight = NULL; + scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, keyVar); + scltMakeColumnNode(&pLeft, src, TSDB_DATA_TYPE_JSON, varDataLen(json), 1, json); + scltMakeOpNode(opNode, OP_TYPE_JSON_GET_VALUE, TSDB_DATA_TYPE_JSON, pLeft, pRight); +} + +void makeOperator(SNode **opNode, SArray *blockList, EOperatorType opType, int32_t rightType, void *rightData){ + int32_t resType = TSDB_DATA_TYPE_NULL; + if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || + opType == OP_TYPE_DIV || opType == OP_TYPE_MOD || opType == OP_TYPE_MINUS){ + resType = TSDB_DATA_TYPE_DOUBLE; + }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){ + resType = TSDB_DATA_TYPE_BIGINT; + }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || + opType == OP_TYPE_LOWER_THAN || opType == OP_TYPE_LOWER_EQUAL || + opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || + opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || + opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || + opType == OP_TYPE_NMATCH){ + resType = TSDB_DATA_TYPE_BOOL; + } + + SNode *right = NULL; + scltMakeValueNode(&right, rightType, rightData); + scltMakeOpNode(opNode, opType, resType, *opNode, right); + + SColumnInfo colInfo = createColumnInfo(1, resType, tDataTypes[resType].bytes); + int16_t dataBlockId = 0, slotId = 0; + scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, 1, &colInfo); + scltMakeTargetNode(opNode, dataBlockId, slotId, *opNode); +} + +void makeCalculate(void *json, void *key, int32_t rightType, void *rightData, double exceptValue, EOperatorType opType){ + SArray *blockList = taosArrayInit(2, POINTER_BYTES); + SSDataBlock *src = NULL; + SNode *opNode = NULL; + + makeJsonArrow(&src, &opNode, json, (char*)key); + taosArrayPush(blockList, &src); + + makeOperator(&opNode, blockList, opType, rightType, rightData); + + int32_t code = scalarCalculate(opNode, blockList, NULL); + ASSERT_EQ(code, 0); + + SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(blockList); + ASSERT_EQ(res->info.rows, 1); + SColumnInfoData *column = (SColumnInfoData *)taosArrayGetLast(res->pDataBlock); + + if(colDataIsNull_f(column->nullbitmap, 0)){ + ASSERT_EQ(DBL_MAX, exceptValue); + printf("result:NULL\n"); + + }else if(opType == OP_TYPE_ADD || opType == OP_TYPE_SUB || opType == OP_TYPE_MULTI || opType == OP_TYPE_DIV || + opType == OP_TYPE_MOD || opType == OP_TYPE_MINUS){ + double tmp = *((double *)colDataGetData(column, 0)); + ASSERT_TRUE(tmp == exceptValue); + printf("result:%lf\n", tmp); + }else if(opType == OP_TYPE_BIT_AND || opType == OP_TYPE_BIT_OR){ + ASSERT_EQ(*((int64_t *)colDataGetData(column, 0)), exceptValue); + printf("result:%ld\n", *((int64_t *)colDataGetData(column, 0))); + }else if(opType == OP_TYPE_GREATER_THAN || opType == OP_TYPE_GREATER_EQUAL || opType == OP_TYPE_LOWER_THAN || + opType == OP_TYPE_LOWER_EQUAL || opType == OP_TYPE_EQUAL || opType == OP_TYPE_NOT_EQUAL || + opType == OP_TYPE_IS_NULL || opType == OP_TYPE_IS_NOT_NULL || opType == OP_TYPE_IS_TRUE || + opType == OP_TYPE_LIKE || opType == OP_TYPE_NOT_LIKE || opType == OP_TYPE_MATCH || opType == OP_TYPE_NMATCH){ + ASSERT_EQ(*((bool *)colDataGetData(column, 0)), exceptValue); + printf("result:%d\n", *((bool *)colDataGetData(column, 0))); + } + + taosArrayDestroyEx(blockList, scltFreeDataBlock); + nodesDestroyNode(opNode); +} + +TEST(columnTest, json_column_arith_op) { + scltInitLogFile(); + char *rightv= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44}"; + + SKVRowBuilder kvRowBuilder; + tdInitKVRowBuilder(&kvRowBuilder); + parseJsontoTagData(rightv, &kvRowBuilder, NULL, 0); + SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); + + const int32_t len = 8; + EOperatorType op[len] = {OP_TYPE_ADD, OP_TYPE_SUB, OP_TYPE_MULTI, OP_TYPE_DIV, + OP_TYPE_MOD, OP_TYPE_MINUS, OP_TYPE_BIT_AND, OP_TYPE_BIT_OR}; + int32_t input[len] = {1, 8, 2, 2, 3, 0, -4, 9}; + + printf("--------------------json int---------------------\n"); + char *key = "k1"; + double eRes[len] = {5.0, -4, 8.0, 2.0, 1.0, -4, 4&-4, 4|9}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i]); + } + + printf("--------------------json string---------------------\n"); + + key = "k2"; + double eRes1[len] = {1.0, -8, 0, 0, 0, 0, 0, 9}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i]); + } + + printf("---------------------json null--------------------\n"); + + key = "k3"; + double eRes2[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i]); + } + + printf("---------------------json bool--------------------\n"); + + key = "k4"; + double eRes3[len] = {2.0, -7, 2, 0.5, 1, -1, 1&-4, 1|9}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i]); + } + + printf("----------------------json double-------------------\n"); + + key = "k5"; + double eRes4[len] = {6.44, -2.56, 10.88, 2.72, 2.44, -5.44, 5&-4, 5|9}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i]); + } + + printf("---------------------json not exist--------------------\n"); + + key = "k10"; + double eRes5[len] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i]); + } +} + +void *prepareNchar(char* rightData){ + int32_t len = 0; + int32_t inputLen = strlen(rightData); + + char* t = (char*)taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); + taosMbsToUcs4(rightData, inputLen, (TdUcs4*) varDataVal(t), inputLen * TSDB_NCHAR_SIZE, &len); + varDataSetLen(t, len); + return t; +} + +TEST(columnTest, json_column_logic_op) { + scltInitLogFile(); + char *rightv= "{\"k1\":4,\"k2\":\"hello\",\"k3\":null,\"k4\":true,\"k5\":5.44,\"k6\":\"6.6hello\"}"; + + SKVRowBuilder kvRowBuilder; + tdInitKVRowBuilder(&kvRowBuilder); + parseJsontoTagData(rightv, &kvRowBuilder, NULL, 0); + SKVRow row = tdGetKVRowFromBuilder(&kvRowBuilder); + + const int32_t len = 9; + const int32_t len1 = 4; + EOperatorType op[len+len1] = {OP_TYPE_GREATER_THAN, OP_TYPE_GREATER_EQUAL, OP_TYPE_LOWER_THAN, OP_TYPE_LOWER_EQUAL, OP_TYPE_EQUAL, OP_TYPE_NOT_EQUAL, + OP_TYPE_IS_NULL, OP_TYPE_IS_NOT_NULL, OP_TYPE_IS_TRUE, OP_TYPE_LIKE, OP_TYPE_NOT_LIKE, OP_TYPE_MATCH, OP_TYPE_NMATCH}; + + int32_t input[len] = {1, 8, 2, 2, 3, 0, 0, 0, 0}; + char *inputNchar[len1] = {"hell_", "hel%", "hell", "llll"}; + + printf("--------------------json int---------------------\n"); + char *key = "k1"; + bool eRes[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes[i], op[i]); + taosMemoryFree(rightData); + } + + printf("--------------------json string---------------------\n"); + + key = "k2"; + bool eRes1[len+len1] = {false, false, true, true, false, false, false, true, false, true, false, true, true}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes1[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes1[i], op[i]); + taosMemoryFree(rightData); + } + + printf("--------------------json null---------------------\n"); + + key = "k3"; + double eRes2[len+len1] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, true, false, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes2[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes2[i], op[i]); + taosMemoryFree(rightData); + } + + printf("--------------------json bool---------------------\n"); + + key = "k4"; + bool eRes3[len+len1] = {false, false, true, true, false, true, false, true, true, false, false, false, false}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes3[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes3[i], op[i]); + taosMemoryFree(rightData); + } + + printf("--------------------json double---------------------\n"); + + key = "k5"; + bool eRes4[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, false}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes4[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes4[i], op[i]); + taosMemoryFree(rightData); + } + + printf("--------------------json double---------------------\n"); + + key = "k6"; + bool eRes5[len+len1] = {true, false, false, false, false, true, false, true, true, false, false, false, true}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes5[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes5[i], op[i]); + taosMemoryFree(rightData); + } + + printf("---------------------json not exist--------------------\n"); + + key = "k10"; + double eRes10[len+len1] = {DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, true, false, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX, DBL_MAX}; + for(int i = 0; i < len; i++){ + makeCalculate(row, key, TSDB_DATA_TYPE_INT, &input[i], eRes10[i], op[i]); + } + for(int i = len; i < len + len1; i++){ + void* rightData = prepareNchar(inputNchar[i-len]); + makeCalculate(row, key, TSDB_DATA_TYPE_NCHAR, rightData, eRes10[i], op[i]); + taosMemoryFree(rightData); + } +} + TEST(columnTest, smallint_value_add_int_column) { scltInitLogFile(); @@ -928,7 +1188,7 @@ TEST(columnTest, smallint_value_add_int_column) { int16_t dataBlockId = 0, slotId = 0; scltAppendReservedSlot(blockList, &dataBlockId, &slotId, true, rowNum, &colInfo); scltMakeTargetNode(&opNode, dataBlockId, slotId, opNode); - + int32_t code = scalarCalculate(opNode, blockList, NULL); ASSERT_EQ(code, 0); @@ -3097,3 +3357,4 @@ int main(int argc, char** argv) { } #pragma GCC diagnostic pop + diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index 1b8cbb0f04..e18538cf27 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -158,6 +158,7 @@ typedef struct { char secured : 2; char spi : 2; + char user[TSDB_UNI_LEN]; uint64_t ahandle; // ahandle assigned by client uint32_t code; // del later uint32_t msgType; @@ -186,23 +187,23 @@ typedef enum { Normal, Quit, Release, Register } STransMsgType; typedef enum { ConnNormal, ConnAcquire, ConnRelease, ConnBroken, ConnInPool } ConnStatus; #define container_of(ptr, type, member) ((type*)((char*)(ptr)-offsetof(type, member))) -#define RPC_RESERVE_SIZE (sizeof(STranConnCtx)) +#define RPC_RESERVE_SIZE (sizeof(STranConnCtx)) -#define RPC_MSG_OVERHEAD (sizeof(SRpcHead) + sizeof(SRpcDigest)) -#define rpcHeadFromCont(cont) ((SRpcHead*)((char*)cont - sizeof(SRpcHead))) -#define rpcContFromHead(msg) (msg + sizeof(SRpcHead)) +#define RPC_MSG_OVERHEAD (sizeof(SRpcHead) + sizeof(SRpcDigest)) +#define rpcHeadFromCont(cont) ((SRpcHead*)((char*)cont - sizeof(SRpcHead))) +#define rpcContFromHead(msg) (msg + sizeof(SRpcHead)) #define rpcMsgLenFromCont(contLen) (contLen + sizeof(SRpcHead)) -#define rpcContLenFromMsg(msgLen) (msgLen - sizeof(SRpcHead)) -#define rpcIsReq(type) (type & 1U) +#define rpcContLenFromMsg(msgLen) (msgLen - sizeof(SRpcHead)) +#define rpcIsReq(type) (type & 1U) #define TRANS_RESERVE_SIZE (sizeof(STranConnCtx)) -#define TRANS_MSG_OVERHEAD (sizeof(STransMsgHead)) -#define transHeadFromCont(cont) ((STransMsgHead*)((char*)cont - sizeof(STransMsgHead))) -#define transContFromHead(msg) (msg + sizeof(STransMsgHead)) +#define TRANS_MSG_OVERHEAD (sizeof(STransMsgHead)) +#define transHeadFromCont(cont) ((STransMsgHead*)((char*)cont - sizeof(STransMsgHead))) +#define transContFromHead(msg) (msg + sizeof(STransMsgHead)) #define transMsgLenFromCont(contLen) (contLen + sizeof(STransMsgHead)) -#define transContLenFromMsg(msgLen) (msgLen - sizeof(STransMsgHead)); -#define transIsReq(type) (type & 1U) +#define transContLenFromMsg(msgLen) (msgLen - sizeof(STransMsgHead)); +#define transIsReq(type) (type & 1U) int rpcAuthenticateMsg(void* pMsg, int msgLen, void* pAuth, void* pKey); void rpcBuildAuthHead(void* pMsg, int msgLen, void* pAuth, void* pKey); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 8eb1a3ee7d..b81310b90b 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -614,35 +614,16 @@ void cliSend(SCliConn* pConn) { pMsg->pCont = (void*)rpcMallocCont(0); pMsg->contLen = 0; } - STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); - pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; - int msgLen = transMsgLenFromCont(pMsg->contLen); - if (!pConn->secured) { - char* buf = taosMemoryCalloc(1, msgLen + sizeof(STransUserMsg)); - memcpy(buf, (char*)pHead, msgLen); - - STransUserMsg* uMsg = (STransUserMsg*)(buf + msgLen); - memcpy(uMsg->user, pTransInst->user, tListLen(uMsg->user)); - memcpy(uMsg->secret, pTransInst->secret, tListLen(uMsg->secret)); - - // to avoid mem leak - destroyUserdata(pMsg); - - pMsg->pCont = (char*)buf + sizeof(STransMsgHead); - pMsg->contLen = msgLen + sizeof(STransUserMsg) - sizeof(STransMsgHead); - - pHead = (STransMsgHead*)buf; - pHead->secured = 1; - msgLen += sizeof(STransUserMsg); - } - + STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); + pHead->ahandle = pCtx != NULL ? (uint64_t)pCtx->ahandle : 0; pHead->noResp = REQUEST_NO_RESP(pMsg) ? 1 : 0; pHead->persist = REQUEST_PERSIS_HANDLE(pMsg) ? 1 : 0; pHead->msgType = pMsg->msgType; pHead->msgLen = (int32_t)htonl((uint32_t)msgLen); pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0; + memcpy(pHead->user, pTransInst->user, strlen(pTransInst->user)); uv_buf_t wb = uv_buf_init((char*)pHead, msgLen); tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, diff --git a/source/libs/transport/src/transSrv.c b/source/libs/transport/src/transSrv.c index 158d599bdf..ec66f3e8df 100644 --- a/source/libs/transport/src/transSrv.c +++ b/source/libs/transport/src/transSrv.c @@ -46,7 +46,6 @@ typedef struct SSrvConn { struct sockaddr_in addr; struct sockaddr_in locaddr; - char secured; int spi; char info[64]; char user[TSDB_UNI_LEN]; // user ID for the link @@ -104,6 +103,13 @@ static void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) static void uvWorkerAsyncCb(uv_async_t* handle); static void uvAcceptAsyncCb(uv_async_t* handle); static void uvShutDownCb(uv_shutdown_t* req, int status); + +/* + * time-consuming task throwed into BG work thread + */ +static void uvWorkDoTask(uv_work_t* req); +static void uvWorkAfterTask(uv_work_t* req, int status); + static void uvWalkCb(uv_handle_t* handle, void* arg); static void uvFreeCb(uv_handle_t* handle); @@ -181,16 +187,16 @@ static void uvHandleReq(SSrvConn* pConn) { uint32_t msgLen = pBuf->len; STransMsgHead* pHead = (STransMsgHead*)msg; - if (pHead->secured == 1) { - STransUserMsg* uMsg = (STransUserMsg*)((char*)msg + msgLen - sizeof(STransUserMsg)); - memcpy(pConn->user, uMsg->user, tListLen(uMsg->user)); - memcpy(pConn->secret, uMsg->secret, tListLen(uMsg->secret)); - } pHead->code = htonl(pHead->code); pHead->msgLen = htonl(pHead->msgLen); - if (pHead->secured == 1) { - pHead->msgLen -= sizeof(STransUserMsg); - } + memcpy(pConn->user, pHead->user, strlen(pHead->user)); + + // TODO(dengyihao): time-consuming task throwed into BG Thread + // uv_work_t* wreq = taosMemoryMalloc(sizeof(uv_work_t)); + // wreq->data = pConn; + // uv_read_stop((uv_stream_t*)pConn->pTcp); + // transRefSrvHandle(pConn); + // uv_queue_work(((SWorkThrdObj*)pConn->hostThrd)->loop, wreq, uvWorkDoTask, uvWorkAfterTask); CONN_SHOULD_RELEASE(pConn, pHead); @@ -344,12 +350,6 @@ static void uvPrepareSendData(SSrvMsg* smsg, uv_buf_t* wb) { STransMsgHead* pHead = transHeadFromCont(pMsg->pCont); pHead->ahandle = (uint64_t)pMsg->ahandle; - // pHead->secured = pMsg->code == 0 ? 1 : 0; // - if (!pConn->secured) { - pConn->secured = pMsg->code == 0 ? 1 : 0; - } - pHead->secured = pConn->secured; - if (pConn->status == ConnNormal) { pHead->msgType = pConn->inType + 1; } else { @@ -464,6 +464,24 @@ static void uvShutDownCb(uv_shutdown_t* req, int status) { taosMemoryFree(req); } +static void uvWorkDoTask(uv_work_t* req) { + // doing time-consumeing task + // only auth conn currently, add more func later + tTrace("server conn %p start to be processed in BG Thread", req->data); + return; +} + +static void uvWorkAfterTask(uv_work_t* req, int status) { + if (status != 0) { + tTrace("server conn %p failed to processed ", req->data); + } + // Done time-consumeing task + // add more func later + // this func called in main loop + tTrace("server conn %p already processed ", req->data); + taosMemoryFree(req); +} + void uvOnAcceptCb(uv_stream_t* stream, int status) { if (status == -1) { return; diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index c2c4af18e5..3d3d13fcb6 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -38,7 +38,7 @@ extern int openU(const char *, int, ...); /* MsvcLibX UTF-8 version of open */ #include #if !defined(_TD_DARWIN_64) - #include +#include #endif #include #include @@ -58,9 +58,9 @@ typedef int32_t FileFd; typedef struct TdFile { TdThreadRwlock rwlock; - int refId; - FileFd fd; - FILE *fp; + int refId; + FileFd fd; + FILE *fp; } * TdFilePtr, TdFile; #define FILE_WITH_LOCK 1 @@ -182,7 +182,7 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) { return 0; #else struct stat fileStat; - int32_t code = stat(path, &fileStat); + int32_t code = stat(path, &fileStat); if (code < 0) { return code; } @@ -203,7 +203,7 @@ int32_t taosDevInoFile(const char *path, int64_t *stDev, int64_t *stIno) { return 0; #else struct stat fileStat; - int32_t code = stat(path, &fileStat); + int32_t code = stat(path, &fileStat); if (code < 0) { return code; } @@ -226,7 +226,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) return NULL; #else - int fd = -1; + int fd = -1; FILE *fp = NULL; if (tdFileOptions & TD_FILE_STREAM) { char *mode = NULL; @@ -325,7 +325,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t leftbytes = count; int64_t readbytes; char *tbuf = (char *)buf; @@ -365,7 +365,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t ret = pread(pFile->fd, buf, count, offset); #if FILE_WITH_LOCK taosThreadRwlockUnlock(&(pFile->rwlock)); @@ -380,7 +380,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { #if FILE_WITH_LOCK taosThreadRwlockWrlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); // Please check if you have closed the file. + /*assert(pFile->fd >= 0); // Please check if you have closed the file.*/ int64_t nleft = count; int64_t nwritten = 0; @@ -414,7 +414,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { #if FILE_WITH_LOCK taosThreadRwlockRdlock(&(pFile->rwlock)); #endif - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. int64_t ret = lseek(pFile->fd, (long)offset, whence); #if FILE_WITH_LOCK taosThreadRwlockUnlock(&(pFile->rwlock)); @@ -429,10 +429,10 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. struct stat fileStat; - int32_t code = fstat(pFile->fd, &fileStat); + int32_t code = fstat(pFile->fd, &fileStat); if (code < 0) { return code; } @@ -456,7 +456,7 @@ int32_t taosLockFile(TdFilePtr pFile) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. return (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB); #endif @@ -469,7 +469,7 @@ int32_t taosUnLockFile(TdFilePtr pFile) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. return (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB); #endif @@ -529,7 +529,7 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { if (pFile == NULL) { return 0; } - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. return ftruncate(pFile->fd, l_size); #endif @@ -637,7 +637,7 @@ int64_t taosFSendFile(FILE *out_file, FILE *in_file, int64_t *offset, int64_t co } off_t len = count; while (len > 0) { - char buf[1024 * 16]; + char buf[1024 * 16]; off_t n = sizeof(buf); if (len < n) n = len; size_t m = fread(buf, 1, n, in_file); @@ -662,7 +662,7 @@ int64_t taosSendFile(SocketFd dfd, FileFd sfd, int64_t *offset, int64_t count) { } off_t len = count; while (len > 0) { - char buf[1024 * 16]; + char buf[1024 * 16]; off_t n = sizeof(buf); if (len < n) n = len; size_t m = read(sfd, buf, n); @@ -750,7 +750,7 @@ void *taosMmapReadOnlyFile(TdFilePtr pFile, int64_t length) { if (pFile == NULL) { return NULL; } - assert(pFile->fd >= 0); // Please check if you have closed the file. + assert(pFile->fd >= 0); // Please check if you have closed the file. void *ptr = mmap(NULL, length, PROT_READ, MAP_SHARED, pFile->fd, 0); return ptr; @@ -811,4 +811,4 @@ bool taosCheckAccessFile(const char *pathname, int32_t tdFileAccessOptions) { bool taosCheckExistFile(const char *pathname) { return taosCheckAccessFile(pathname, TD_FILE_ACCESS_EXIST_OK); }; -#endif // WINDOWS +#endif // WINDOWS diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 4477a5cacd..1c655fc2bf 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "tarray.h" +#include "tcoding.h" SArray* taosArrayInit(size_t size, size_t elemSize) { assert(elemSize > 0); @@ -75,7 +76,7 @@ int32_t taosArrayEnsureCap(SArray* pArray, size_t newCap) { } void* taosArrayAddBatch(SArray* pArray, const void* pData, int32_t nEles) { - if (pArray == NULL || pData == NULL) { + if (pData == NULL) { return NULL; } @@ -317,7 +318,6 @@ void taosArrayClearEx(SArray* pArray, void (*fp)(void*)) { pArray->size = 0; } - void* taosArrayDestroy(SArray* pArray) { if (pArray) { taosMemoryFree(pArray->pData); @@ -327,7 +327,14 @@ void* taosArrayDestroy(SArray* pArray) { return NULL; } -void taosArrayDestroyEx(SArray* pArray, void (*fp)(void*)) { +void taosArrayDestroyP(SArray* pArray, FDelete fp) { + for (int32_t i = 0; i < pArray->size; i++) { + fp(*(void**)TARRAY_GET_ELEM(pArray, i)); + } + taosArrayDestroy(pArray); +} + +void taosArrayDestroyEx(SArray* pArray, FDelete fp) { if (pArray == NULL) { return; } @@ -436,6 +443,39 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void return; } +SArray* taosArrayDeepCopy(const SArray* pSrc, FCopy deepCopy) { + ASSERT(pSrc->elemSize == sizeof(void*)); + SArray* pArray = taosArrayInit(pSrc->size, sizeof(void*)); + for (int32_t i = 0; i < pSrc->size; i++) { + void* clone = deepCopy(taosArrayGetP(pSrc, i)); + taosArrayPush(pArray, &clone); + } + return pArray; +} + +int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode) { + int32_t tlen = 0; + int32_t sz = pArray->size; + tlen += taosEncodeFixedI32(buf, sz); + for (int32_t i = 0; i < sz; i++) { + void* data = taosArrayGetP(pArray, i); + tlen += encode(buf, data); + } + return tlen; +} + +void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t dataSz) { + int32_t sz; + buf = taosDecodeFixedI32(buf, &sz); + *pArray = taosArrayInit(sz, sizeof(void*)); + for (int32_t i = 0; i < sz; i++) { + void* data = taosMemoryCalloc(1, dataSz); + buf = decode(buf, data); + taosArrayPush(*pArray, &data); + } + return (void*)buf; +} + // order array void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param) { taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param); diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 93022de021..0ddc76e415 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -222,6 +222,11 @@ int32_t compareLenPrefixedWStrDesc(const void *pLeft, const void *pRight) { return compareLenPrefixedWStr(pRight, pLeft); } +int32_t compareJsonContainsKey(const void* pLeft, const void* pRight) { + if(pLeft) return 0; + return 1; +} + /* * Compare two strings * TSDB_MATCH: Match diff --git a/source/util/src/terror.c b/source/util/src/terror.c index ded42365b6..9332cb481e 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -138,6 +138,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON, "Invalid JSON format") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_JSON_TYPE, "Invalid JSON data type") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_VALUE_OUT_OF_RANGE, "Value out of range") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_INPUT, "Invalid tsc input") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_API_ERROR, "Stmt API usage error") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_TBNAME_ERROR, "Stmt table name not set") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_STMT_CLAUSE_ERROR, "not supported stmt clause") // mnode-common TAOS_DEFINE_ERROR(TSDB_CODE_MND_APP_ERROR, "Mnode internal error") diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 93a843fee8..59dab76989 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -276,3 +276,37 @@ int32_t tjsonToArray(const SJson* pJson, const char* pName, FToObject func, void } SJson* tjsonParse(const char* pStr) { return cJSON_Parse(pStr); } + +bool tjsonValidateJson(const char *jIn) { + if (!jIn){ + return false; + } + + // set json real data + cJSON *root = cJSON_Parse(jIn); + if (root == NULL){ + return false; + } + + if(!cJSON_IsObject(root)){ + return false; + } + int size = cJSON_GetArraySize(root); + for(int i = 0; i < size; i++) { + cJSON* item = cJSON_GetArrayItem(root, i); + if (!item) { + return false; + } + + char* jsonKey = item->string; + if (!jsonKey) return false; + for (size_t j = 0; j < strlen(jsonKey); ++i) { + if (isprint(jsonKey[i]) == 0) return false; + } + + if (item->type == cJSON_Object || item->type == cJSON_Array) { + return false; + } + } + return true; +} \ No newline at end of file diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 3dce260b10..6da4913114 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -91,6 +91,7 @@ int32_t sDebugFlag = 135; int32_t tsdbDebugFlag = 131; int32_t tqDebugFlag = 135; int32_t fsDebugFlag = 135; +int32_t fnDebugFlag = 135; int64_t dbgEmptyW = 0; int64_t dbgWN = 0; @@ -752,6 +753,7 @@ void taosSetAllDebugFlag(int32_t flag) { tsdbDebugFlag = flag; tqDebugFlag = flag; fsDebugFlag = flag; + fnDebugFlag = flag; uInfo("all debug flag are set to %d", flag); } diff --git a/source/util/src/tutil.c b/source/util/src/tutil.c index 8133e4d237..adb6a37ba7 100644 --- a/source/util/src/tutil.c +++ b/source/util/src/tutil.c @@ -47,65 +47,6 @@ int32_t strdequote(char *z) { return j + 1; // only one quote, do nothing } -int32_t strRmquote(char *z, int32_t len) { - // delete escape character: \\, \', \" - char delim = z[0]; - if (delim != '\'' && delim != '\"') { - return len; - } - - int32_t cnt = 0; - int32_t j = 0; - for (uint32_t k = 1; k < len - 1; ++k) { - if (z[k] == '\\' || (z[k] == delim && z[k + 1] == delim)) { - if (z[k] == '\\' && z[k + 1] == '_') { - // match '_' self - } else { - z[j] = z[k + 1]; - cnt++; - j++; - k++; - continue; - } - } - - z[j] = z[k]; - j++; - } - - z[j] = 0; - - return len - 2 - cnt; -} - -int32_t strndequote(char *dst, const char *z, int32_t len) { - assert(dst != NULL); - if (z == NULL || len == 0) { - return 0; - } - - int32_t quote = z[0]; - int32_t i = 1, j = 0; - - while (z[i] != 0) { - if (z[i] == quote) { - if (z[i + 1] == quote) { - dst[j++] = (char)quote; - i++; - } else { - dst[j++] = 0; - return (j - 1); - } - } else { - dst[j++] = z[i]; - } - - i++; - } - - return j + 1; // only one quote, do nothing -} - size_t strtrim(char *z) { int32_t i = 0; int32_t j = 0; diff --git a/tests/pytest/insert/binary.py b/tests/pytest/insert/binary.py index ffd1d6cb8c..28621f777b 100644 --- a/tests/pytest/insert/binary.py +++ b/tests/pytest/insert/binary.py @@ -35,8 +35,8 @@ class TDTestCase: tdSql.prepare() tdLog.info('=============== step1') - tdLog.info('create table tb (ts timestamp, speed binary(5))') - tdSql.execute('create table tb (ts timestamp, speed binary(5))') + tdLog.info('create table tb (ts timestamp, speed binary(10))') + tdSql.execute('create table tb (ts timestamp, speed binary(10))') tdLog.info("insert into tb values (now, ) -x step1") tdSql.error("insert into tb values (now, )") tdLog.info('=============== step2') @@ -49,27 +49,29 @@ class TDTestCase: tdLog.info("tdSql.checkData(0, 0, '1234')") tdSql.checkData(0, 0, '1234') tdLog.info('=============== step3') - tdLog.info("insert into tb values (now+2a, '23456')") - tdSql.execute("insert into tb values (now+2a, '23456')") + tdLog.info("insert into tb values (now+2a, '0123456789')") + tdSql.execute("insert into tb values (now+2a, '0123456789')") tdLog.info('select speed from tb order by ts desc') tdSql.query('select speed from tb order by ts desc') tdLog.info('tdSql.checkRow(2)') tdSql.checkRows(2) tdLog.info('==> $data00') - tdLog.info("tdSql.checkData(0, 0, '23456')") - tdSql.checkData(0, 0, '23456') + tdLog.info("tdSql.checkData(0, 0, '0123456789')") + tdSql.checkData(0, 0, '0123456789') tdLog.info('=============== step4') - tdLog.info("insert into tb values (now+3a, '345678')") - tdSql.error("insert into tb values (now+3a, '345678')") + tdLog.info("insert into tb values (now+3a, '01234567890')") + tdSql.error("insert into tb values (now+3a, '01234567890')") tdLog.info("insert into tb values (now+3a, '34567')") tdSql.execute("insert into tb values (now+3a, '34567')") + tdLog.info("insert into tb values (now+4a, NULL)") + tdSql.execute("insert into tb values (now+4a, NULL)") tdLog.info('select speed from tb order by ts desc') tdSql.query('select speed from tb order by ts desc') - tdLog.info('tdSql.checkRow(3)') - tdSql.checkRows(3) - tdLog.info('==> $data00') - tdLog.info("tdSql.checkData(0, 0, '34567')") - tdSql.checkData(0, 0, '34567') + tdSql.checkRows(4) + tdLog.info("tdSql.checkData(0, 0, '0123456789')") + tdSql.checkData(0, 0, '0123456789') + tdLog.info("tdSql.checkData(3, 0, None)") + tdSql.checkData(3, 0, None) tdLog.info("insert into tb values (now+4a, \"'';\")") if platform.system() == "Linux": diff --git a/tests/script/api/batchprepare.c b/tests/script/api/batchprepare.c index de1050850d..2e046bd3ff 100644 --- a/tests/script/api/batchprepare.c +++ b/tests/script/api/batchprepare.c @@ -5,840 +5,932 @@ #include #include #include +#include #include #include "../../../include/client/taos.h" +int32_t shortColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_INT}; +int32_t fullColList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_BOOL, TSDB_DATA_TYPE_TINYINT, TSDB_DATA_TYPE_UTINYINT, TSDB_DATA_TYPE_SMALLINT, TSDB_DATA_TYPE_USMALLINT, TSDB_DATA_TYPE_INT, TSDB_DATA_TYPE_UINT, TSDB_DATA_TYPE_BIGINT, TSDB_DATA_TYPE_UBIGINT, TSDB_DATA_TYPE_FLOAT, TSDB_DATA_TYPE_DOUBLE, TSDB_DATA_TYPE_BINARY, TSDB_DATA_TYPE_NCHAR}; +int32_t bindColTypeList[] = {TSDB_DATA_TYPE_TIMESTAMP, TSDB_DATA_TYPE_NCHAR}; + +#define tListLen(x) (sizeof(x) / sizeof((x)[0])) + typedef struct { - TAOS *taos; - int idx; -}T_par; + int64_t* tsData; + bool* boolData; + int8_t* tinyData; + uint8_t* utinyData; + int16_t* smallData; + uint16_t* usmallData; + int32_t* intData; + uint32_t* uintData; + int64_t* bigData; + uint64_t* ubigData; + float* floatData; + double* doubleData; + char* binaryData; + char* isNull; + int32_t* binaryLen; + TAOS_BIND_v2* pBind; + char* sql; + int32_t* colTypes; + int32_t colNum; +} BindData; -void taosMsleep(int mseconds); +int32_t gVarCharSize = 10; +int32_t gVarCharLen = 5; -unsigned long long getCurrentTime(){ - struct timeval tv; - if (taosGetTimeOfDay(&tv) != 0) { - perror("Failed to get current time in ms"); - exit(EXIT_FAILURE); +int32_t gExecLoopTimes = 1; // no change +int32_t gFullColNum = tListLen(fullColList); + +int insertMBSETest1(TAOS_STMT *stmt); +int insertMBSETest2(TAOS_STMT *stmt); +int insertMBMETest1(TAOS_STMT *stmt); +int insertMBMETest2(TAOS_STMT *stmt); +int insertMBMETest3(TAOS_STMT *stmt); +int insertMBMETest4(TAOS_STMT *stmt); +int insertMPMETest1(TAOS_STMT *stmt); + + + + +typedef struct { + char caseDesc[128]; + int32_t colNum; + int32_t *colList; // full table column list + bool autoCreate; + bool fullCol; + int32_t (*runFn)(TAOS_STMT*); + int32_t tblNum; + int32_t rowNum; + int32_t bindRowNum; + int32_t bindColNum; // equal colNum in full column case + int32_t bindNullNum; + int32_t runTimes; +} CaseCfg; + +CaseCfg gCase[] = { + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, false, true, insertMBSETest1, 1, 10, 10, 0, 0, 1}, + {"insert:MBSE1-FULL", tListLen(shortColList), shortColList, false, true, insertMBSETest1, 10, 100, 10, 0, 0, 1}, + + {"insert:MBSE1-FULL", tListLen(fullColList), fullColList, false, true, insertMBSETest1, 10, 10, 2, 0, 0, 1}, + {"insert:MBSE1-C012", tListLen(fullColList), fullColList, false, false, insertMBSETest1, 10, 10, 2, 12, 0, 1}, + {"insert:MBSE1-C002", tListLen(fullColList), fullColList, false, false, insertMBSETest1, 10, 10, 2, 2, 0, 1}, + + {"insert:MBSE2-FULL", tListLen(fullColList), fullColList, false, true, insertMBSETest2, 10, 10, 2, 0, 0, 1}, + {"insert:MBSE2-C012", tListLen(fullColList), fullColList, false, false, insertMBSETest2, 10, 10, 2, 12, 0, 1}, + {"insert:MBSE2-C002", tListLen(fullColList), fullColList, false, false, insertMBSETest2, 10, 10, 2, 2, 0, 1}, + + {"insert:MBME1-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest1, 10, 10, 2, 0, 0, 1}, + {"insert:MBME1-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest1, 10, 10, 2, 12, 0, 1}, + {"insert:MBME1-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest1, 10, 10, 2, 2, 0, 1}, + + {"insert:MBME2-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest2, 10, 10, 2, 0, 0, 1}, + {"insert:MBME2-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest2, 10, 10, 2, 12, 0, 1}, + {"insert:MBME2-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest2, 10, 10, 2, 2, 0, 1}, + + {"insert:MBME3-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest3, 10, 10, 2, 0, 0, 1}, + {"insert:MBME3-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest3, 10, 10, 2, 12, 0, 1}, + {"insert:MBME3-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest3, 10, 10, 2, 2, 0, 1}, + + {"insert:MBME4-FULL", tListLen(fullColList), fullColList, false, true, insertMBMETest4, 10, 10, 2, 0, 0, 1}, + {"insert:MBME4-C012", tListLen(fullColList), fullColList, false, false, insertMBMETest4, 10, 10, 2, 12, 0, 1}, + {"insert:MBME4-C002", tListLen(fullColList), fullColList, false, false, insertMBMETest4, 10, 10, 2, 2, 0, 1}, + + + {"insert:MPME1-FULL", tListLen(fullColList), fullColList, false, true, insertMPMETest1, 10, 10, 2, 0, 0, 1}, + {"insert:MPME1-C012", tListLen(fullColList), fullColList, false, false, insertMPMETest1, 10, 10, 2, 12, 0, 1}, + +}; + +CaseCfg *gCurCase = NULL; + +typedef struct { + int32_t bindNullNum; + bool autoCreate; + bool checkParamNum; + bool printRes; + bool printCreateTblSql; + bool printInsertSql; + int32_t rowNum; //row num for one table + int32_t bindColNum; + int32_t bindRowNum; //row num for once bind + int32_t bindColTypeNum; + int32_t* bindColTypeList; + int32_t runTimes; +} CaseCtrl; + +CaseCtrl gCaseCtrl = { + .bindNullNum = 0, + .autoCreate = false, + .printCreateTblSql = false, + .printInsertSql = true, + .rowNum = 0, + .bindColNum = 0, + .bindRowNum = 0, + .bindColTypeNum = 0, + .bindColTypeList = NULL, + .checkParamNum = false, + .printRes = true, + .runTimes = 0, +}; + +int32_t taosGetTimeOfDay(struct timeval *tv) { + return gettimeofday(tv, NULL); +} +void *taosMemoryMalloc(uint64_t size) { + return malloc(size); +} + +void *taosMemoryCalloc(int32_t num, int32_t size) { + return calloc(num, size); +} +void taosMemoryFree(const void *ptr) { + if (ptr == NULL) return; + + return free((void*)ptr); +} + +static int64_t taosGetTimestampMs() { + struct timeval systemTime; + taosGetTimeOfDay(&systemTime); + return (int64_t)systemTime.tv_sec * 1000L + (int64_t)systemTime.tv_usec/1000; +} + +static int64_t taosGetTimestampUs() { + struct timeval systemTime; + taosGetTimeOfDay(&systemTime); + return (int64_t)systemTime.tv_sec * 1000000L + (int64_t)systemTime.tv_usec; +} + +bool colExists(TAOS_BIND_v2* pBind, int32_t dataType) { + int32_t i = 0; + while (true) { + if (0 == pBind[i].buffer_type) { + return false; } - return (uint64_t)tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec; + if (pBind[i].buffer_type == dataType) { + return true; + } + + ++i; + } +} + +void generateInsertSQL(BindData *data) { + int32_t len = sprintf(data->sql, "insert into %s ", (gCurCase->tblNum > 1 ? "? " : "t0 ")); + if (!gCurCase->fullCol) { + len += sprintf(data->sql + len, "("); + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + switch (data->pBind[c].buffer_type) { + case TSDB_DATA_TYPE_BOOL: + len += sprintf(data->sql + len, "booldata"); + break; + case TSDB_DATA_TYPE_TINYINT: + len += sprintf(data->sql + len, "tinydata"); + break; + case TSDB_DATA_TYPE_SMALLINT: + len += sprintf(data->sql + len, "smalldata"); + break; + case TSDB_DATA_TYPE_INT: + len += sprintf(data->sql + len, "intdata"); + break; + case TSDB_DATA_TYPE_BIGINT: + len += sprintf(data->sql + len, "bigdata"); + break; + case TSDB_DATA_TYPE_FLOAT: + len += sprintf(data->sql + len, "floatdata"); + break; + case TSDB_DATA_TYPE_DOUBLE: + len += sprintf(data->sql + len, "doubledata"); + break; + case TSDB_DATA_TYPE_VARCHAR: + len += sprintf(data->sql + len, "binarydata"); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + len += sprintf(data->sql + len, "ts"); + break; + case TSDB_DATA_TYPE_NCHAR: + len += sprintf(data->sql + len, "nchardata"); + break; + case TSDB_DATA_TYPE_UTINYINT: + len += sprintf(data->sql + len, "utinydata"); + break; + case TSDB_DATA_TYPE_USMALLINT: + len += sprintf(data->sql + len, "usmalldata"); + break; + case TSDB_DATA_TYPE_UINT: + len += sprintf(data->sql + len, "uintdata"); + break; + case TSDB_DATA_TYPE_UBIGINT: + len += sprintf(data->sql + len, "ubigdata"); + break; + default: + printf("invalid col type:%d", data->pBind[c].buffer_type); + exit(1); + } + } + + len += sprintf(data->sql + len, ") "); + } + + len += sprintf(data->sql + len, "values ("); + for (int c = 0; c < gCurCase->bindColNum; ++c) { + if (c) { + len += sprintf(data->sql + len, ","); + } + len += sprintf(data->sql + len, "?"); + } + len += sprintf(data->sql + len, ")"); + + if (gCaseCtrl.printInsertSql) { + printf("SQL: %s\n", data->sql); + } +} + +void generateDataType(BindData *data, int32_t bindIdx, int32_t colIdx, int32_t *dataType) { + if (bindIdx < gCurCase->bindColNum) { + if (gCaseCtrl.bindColTypeNum) { + *dataType = gCaseCtrl.bindColTypeList[colIdx]; + return; + } else if (gCurCase->fullCol) { + *dataType = gCurCase->colList[bindIdx]; + return; + } else if (0 == colIdx) { + *dataType = TSDB_DATA_TYPE_TIMESTAMP; + return; + } else { + while (true) { + *dataType = rand() % (TSDB_DATA_TYPE_MAX - 1) + 1; + if (*dataType == TSDB_DATA_TYPE_JSON || *dataType == TSDB_DATA_TYPE_DECIMAL + || *dataType == TSDB_DATA_TYPE_BLOB || *dataType == TSDB_DATA_TYPE_MEDIUMBLOB + || *dataType == TSDB_DATA_TYPE_VARBINARY) { + continue; + } + + if (colExists(data->pBind, *dataType)) { + continue; + } + + break; + } + } + } else { + *dataType = data->pBind[bindIdx%gCurCase->bindColNum].buffer_type; + } +} + +int32_t prepareColData(BindData *data, int32_t bindIdx, int32_t rowIdx, int32_t colIdx) { + int32_t dataType = TSDB_DATA_TYPE_TIMESTAMP; + + generateDataType(data, bindIdx, colIdx, &dataType); + + switch (dataType) { + case TSDB_DATA_TYPE_BOOL: + data->pBind[bindIdx].buffer_length = sizeof(bool); + data->pBind[bindIdx].buffer = data->boolData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_TINYINT: + data->pBind[bindIdx].buffer_length = sizeof(int8_t); + data->pBind[bindIdx].buffer = data->tinyData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_SMALLINT: + data->pBind[bindIdx].buffer_length = sizeof(int16_t); + data->pBind[bindIdx].buffer = data->smallData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_INT: + data->pBind[bindIdx].buffer_length = sizeof(int32_t); + data->pBind[bindIdx].buffer = data->intData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_BIGINT: + data->pBind[bindIdx].buffer_length = sizeof(int64_t); + data->pBind[bindIdx].buffer = data->bigData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_FLOAT: + data->pBind[bindIdx].buffer_length = sizeof(float); + data->pBind[bindIdx].buffer = data->floatData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_DOUBLE: + data->pBind[bindIdx].buffer_length = sizeof(double); + data->pBind[bindIdx].buffer = data->doubleData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_VARCHAR: + data->pBind[bindIdx].buffer_length = gVarCharSize; + data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + data->pBind[bindIdx].length = data->binaryLen; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_TIMESTAMP: + data->pBind[bindIdx].buffer_length = sizeof(int64_t); + data->pBind[bindIdx].buffer = data->tsData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = NULL; + break; + case TSDB_DATA_TYPE_NCHAR: + data->pBind[bindIdx].buffer_length = gVarCharSize; + data->pBind[bindIdx].buffer = data->binaryData + rowIdx * gVarCharSize; + data->pBind[bindIdx].length = data->binaryLen; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UTINYINT: + data->pBind[bindIdx].buffer_length = sizeof(uint8_t); + data->pBind[bindIdx].buffer = data->utinyData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_USMALLINT: + data->pBind[bindIdx].buffer_length = sizeof(uint16_t); + data->pBind[bindIdx].buffer = data->usmallData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UINT: + data->pBind[bindIdx].buffer_length = sizeof(uint32_t); + data->pBind[bindIdx].buffer = data->uintData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + case TSDB_DATA_TYPE_UBIGINT: + data->pBind[bindIdx].buffer_length = sizeof(uint64_t); + data->pBind[bindIdx].buffer = data->ubigData + rowIdx; + data->pBind[bindIdx].length = NULL; + data->pBind[bindIdx].is_null = data->isNull ? (data->isNull + rowIdx) : NULL; + break; + default: + printf("invalid col type:%d", dataType); + exit(1); + } + + data->pBind[bindIdx].buffer_type = dataType; + data->pBind[bindIdx].num = gCurCase->bindRowNum; + + return 0; } - - - -int stmt_scol_func1(TAOS_STMT *stmt) { - struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; - } v = {0}; +int32_t prepareData(BindData *data) { + static int64_t tsData = 1591060628000; + uint64_t allRowNum = gCurCase->rowNum * gCurCase->tblNum; - TAOS_BIND params[10]; - params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts); - params[0].buffer = &v.ts; - params[0].length = ¶ms[0].buffer_length; - params[0].is_null = NULL; - - params[1].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[1].buffer_length = sizeof(v.v1); - params[1].buffer = &v.v1; - params[1].length = ¶ms[1].buffer_length; - params[1].is_null = NULL; - - params[2].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[2].buffer_length = sizeof(v.v2); - params[2].buffer = &v.v2; - params[2].length = ¶ms[2].buffer_length; - params[2].is_null = NULL; - - params[3].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[3].buffer_length = sizeof(v.f4); - params[3].buffer = &v.f4; - params[3].length = ¶ms[3].buffer_length; - params[3].is_null = NULL; - - params[4].buffer_type = TSDB_DATA_TYPE_BINARY; - params[4].buffer_length = sizeof(v.bin); - params[4].buffer = v.bin; - params[4].length = ¶ms[4].buffer_length; - params[4].is_null = NULL; - - params[5].buffer_type = TSDB_DATA_TYPE_BINARY; - params[5].buffer_length = sizeof(v.bin); - params[5].buffer = v.bin; - params[5].length = ¶ms[5].buffer_length; - params[5].is_null = NULL; - - char *sql = "insert into ? (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + data->colNum = 0; + data->colTypes = taosMemoryCalloc(30, sizeof(int32_t)); + data->sql = taosMemoryCalloc(1, 1024); + data->pBind = taosMemoryCalloc((allRowNum/gCurCase->bindRowNum)*gCurCase->bindColNum, sizeof(TAOS_BIND_v2)); + data->tsData = taosMemoryMalloc(allRowNum * sizeof(int64_t)); + data->boolData = taosMemoryMalloc(allRowNum * sizeof(bool)); + data->tinyData = taosMemoryMalloc(allRowNum * sizeof(int8_t)); + data->utinyData = taosMemoryMalloc(allRowNum * sizeof(uint8_t)); + data->smallData = taosMemoryMalloc(allRowNum * sizeof(int16_t)); + data->usmallData = taosMemoryMalloc(allRowNum * sizeof(uint16_t)); + data->intData = taosMemoryMalloc(allRowNum * sizeof(int32_t)); + data->uintData = taosMemoryMalloc(allRowNum * sizeof(uint32_t)); + data->bigData = taosMemoryMalloc(allRowNum * sizeof(int64_t)); + data->ubigData = taosMemoryMalloc(allRowNum * sizeof(uint64_t)); + data->floatData = taosMemoryMalloc(allRowNum * sizeof(float)); + data->doubleData = taosMemoryMalloc(allRowNum * sizeof(double)); + data->binaryData = taosMemoryMalloc(allRowNum * gVarCharSize); + data->binaryLen = taosMemoryMalloc(allRowNum * sizeof(int32_t)); + if (gCurCase->bindNullNum) { + data->isNull = taosMemoryCalloc(allRowNum, sizeof(char)); } - for (int zz = 0; zz < 10; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - exit(1); - } - v.ts = 1591060628000 + zz * 10; - for (int i = 0; i < 10; ++i) { - v.ts += 1; + for (int32_t i = 0; i < allRowNum; ++i) { + data->tsData[i] = tsData++; + data->boolData[i] = i % 2; + data->tinyData[i] = i; + data->utinyData[i] = i+1; + data->smallData[i] = i; + data->usmallData[i] = i+1; + data->intData[i] = i; + data->uintData[i] = i+1; + data->bigData[i] = i; + data->ubigData[i] = i+1; + data->floatData[i] = i; + data->doubleData[i] = i+1; + memset(data->binaryData + gVarCharSize * i, 'a'+i%26, gVarCharLen); + if (gCurCase->bindNullNum) { + data->isNull[i] = i % 2; + } + data->binaryLen[i] = gVarCharLen; + } - v.b = (int8_t)(i+zz*10) % 2; - v.v1 = (int8_t)(i+zz*10); - v.v2 = (int16_t)((i+zz*10) * 2); - v.v4 = (int32_t)((i+zz*10) * 4); - v.v8 = (int64_t)((i+zz*10) * 8); - v.f4 = (float)((i+zz*10) * 40); - v.f8 = (double)((i+zz*10) * 80); - for (int j = 0; j < sizeof(v.bin) - 1; ++j) { - v.bin[j] = (char)((i)%10 + '0'); - } - - taos_stmt_bind_param(stmt, params); - taos_stmt_add_batch(stmt); + for (int b = 0; b < (allRowNum/gCurCase->bindRowNum); b++) { + for (int c = 0; c < gCurCase->bindColNum; ++c) { + prepareColData(data, b*gCurCase->bindColNum+c, b*gCurCase->bindRowNum, c); } } - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); + generateInsertSQL(data); + + return 0; +} + +void destroyData(BindData *data) { + taosMemoryFree(data->tsData); + taosMemoryFree(data->boolData); + taosMemoryFree(data->tinyData); + taosMemoryFree(data->utinyData); + taosMemoryFree(data->smallData); + taosMemoryFree(data->usmallData); + taosMemoryFree(data->intData); + taosMemoryFree(data->uintData); + taosMemoryFree(data->bigData); + taosMemoryFree(data->ubigData); + taosMemoryFree(data->floatData); + taosMemoryFree(data->doubleData); + taosMemoryFree(data->binaryData); + taosMemoryFree(data->binaryLen); + taosMemoryFree(data->isNull); + taosMemoryFree(data->pBind); + taosMemoryFree(data->colTypes); +} + +int32_t bpBindParam(TAOS_STMT *stmt, TAOS_BIND_v2 *bind) { + static int32_t n = 0; + + if (gCurCase->bindRowNum > 1) { + if (0 == (n++%2)) { + if (taos_stmt_bind_param_batch(stmt, bind)) { + printf("taos_stmt_bind_param_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } else { + for (int32_t i = 0; i < gCurCase->bindColNum; ++i) { + if (taos_stmt_bind_single_param_batch(stmt, bind++, i)) { + printf("taos_stmt_bind_single_param_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + } + } else { + if (taos_stmt_bind_param(stmt, bind)) { + printf("taos_stmt_bind_param error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + return 0; +} + +void bpCheckIsInsert(TAOS_STMT *stmt) { + int32_t isInsert = 0; + if (taos_stmt_is_insert(stmt, &isInsert)) { + printf("taos_stmt_is_insert error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - return 0; + if (0 == isInsert) { + printf("is insert failed\n"); + exit(1); + } } - - -int stmt_scol_func2(TAOS_STMT *stmt) { - struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; - } v = {0}; - - TAOS_BIND params[10]; - params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts); - params[0].buffer = &v.ts; - params[0].length = ¶ms[0].buffer_length; - params[0].is_null = NULL; - - params[1].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[1].buffer_length = sizeof(v.v1); - params[1].buffer = &v.v1; - params[1].length = ¶ms[1].buffer_length; - params[1].is_null = NULL; - - params[2].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[2].buffer_length = sizeof(v.v2); - params[2].buffer = &v.v2; - params[2].length = ¶ms[2].buffer_length; - params[2].is_null = NULL; - - params[3].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[3].buffer_length = sizeof(v.f4); - params[3].buffer = &v.f4; - params[3].length = ¶ms[3].buffer_length; - params[3].is_null = NULL; - - params[4].buffer_type = TSDB_DATA_TYPE_BINARY; - params[4].buffer_length = sizeof(v.bin); - params[4].buffer = v.bin; - params[4].length = ¶ms[4].buffer_length; - params[4].is_null = NULL; - - params[5].buffer_type = TSDB_DATA_TYPE_BINARY; - params[5].buffer_length = sizeof(v.bin); - params[5].buffer = v.bin; - params[5].length = ¶ms[5].buffer_length; - params[5].is_null = NULL; - - char *sql = "insert into m0 (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - for (int zz = 0; zz < 10; zz++) { - v.ts = 1591060628000 + zz * 10; - for (int i = 0; i < 10; ++i) { - v.ts += 1; - - v.b = (int8_t)(i+zz*10) % 2; - v.v1 = (int8_t)(i+zz*10); - v.v2 = (int16_t)((i+zz*10) * 2); - v.v4 = (int32_t)((i+zz*10) * 4); - v.v8 = (int64_t)((i+zz*10) * 8); - v.f4 = (float)((i+zz*10) * 40); - v.f8 = (double)((i+zz*10) * 80); - for (int j = 0; j < sizeof(v.bin) - 1; ++j) { - v.bin[j] = (char)((i)%10 + '0'); - } - - taos_stmt_bind_param(stmt, params); - taos_stmt_add_batch(stmt); - } - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); +void bpCheckParamNum(TAOS_STMT *stmt) { + int32_t num = 0; + if (taos_stmt_num_params(stmt, &num)) { + printf("taos_stmt_num_params error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - return 0; + if (gCurCase->bindColNum != num) { + printf("is insert failed\n"); + exit(1); + } +} + +void bpCheckAffectedRows(TAOS_STMT *stmt, int32_t times) { + int32_t rows = taos_stmt_affected_rows(stmt); + int32_t insertNum = gCurCase->rowNum * gCurCase->tblNum * times; + if (insertNum != rows) { + printf("affected rows %d mis-match with insert num %d\n", rows, insertNum); + exit(1); + } } +/* prepare [settbname [bind add]] exec */ +int insertMBSETest1(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); - -//300 tables 60 records -int stmt_scol_func3(TAOS_STMT *stmt) { - struct { - int64_t *ts; - int8_t b[60]; - int8_t v1[60]; - int16_t v2[60]; - int32_t v4[60]; - int64_t v8[60]; - float f4[60]; - double f8[60]; - char bin[60][40]; - } v = {0}; - - v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - - int *lb = taosMemoryMalloc(60 * sizeof(int)); - - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = taosMemoryMalloc(sizeof(char) * 60); - char* no_null = taosMemoryMalloc(sizeof(char) * 60); - - for (int i = 0; i < 60; ++i) { - lb[i] = 40; - no_null[i] = 0; - is_null[i] = (i % 10 == 2) ? 1 : 0; - v.b[i] = (int8_t)(i % 2); - v.v1[i] = (int8_t)((i+1) % 2); - v.v2[i] = (int16_t)i; - v.v4[i] = (int32_t)(i+1); - v.v8[i] = (int64_t)(i+2); - v.f4[i] = (float)(i+3); - v.f8[i] = (double)(i+4); - memset(v.bin[i], '0'+i%10, 40); - } - - for (int i = 0; i < 9000000; i+=10) { - params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[i+0].buffer_length = sizeof(int64_t); - params[i+0].buffer = &v.ts[10*i/10]; - params[i+0].length = NULL; - params[i+0].is_null = no_null; - params[i+0].num = 10; - - params[i+1].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[i+1].buffer_length = sizeof(int8_t); - params[i+1].buffer = v.v1; - params[i+1].length = NULL; - params[i+1].is_null = no_null; - params[i+1].num = 10; - - params[i+2].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[i+2].buffer_length = sizeof(int16_t); - params[i+2].buffer = v.v2; - params[i+2].length = NULL; - params[i+2].is_null = no_null; - params[i+2].num = 10; - - params[i+3].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[i+3].buffer_length = sizeof(float); - params[i+3].buffer = v.f4; - params[i+3].length = NULL; - params[i+3].is_null = no_null; - params[i+3].num = 10; - - params[i+4].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+4].buffer_length = 40; - params[i+4].buffer = v.bin; - params[i+4].length = lb; - params[i+4].is_null = no_null; - params[i+4].num = 10; - - params[i+5].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+5].buffer_length = 40; - params[i+5].buffer = v.bin; - params[i+5].length = lb; - params[i+5].is_null = no_null; - params[i+5].num = 10; - - } - - int64_t tts = 1591060628000; - for (int i = 0; i < 54000000; ++i) { - v.ts[i] = tts + i; - } - - unsigned long long starttime = getCurrentTime(); - - char *sql = "insert into ? (ts, v1,v2,f4,bin,bin2) values(?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); + int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - int id = 0; - for (int l = 0; l < 2; l++) { - for (int zz = 0; zz < 300; zz++) { + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { char buf[32]; - sprintf(buf, "m%d", zz); + sprintf(buf, "t%d", t); code = taos_stmt_set_tbname(stmt, buf); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } - - taos_stmt_bind_param_batch(stmt, params + id * 10); - taos_stmt_add_batch(stmt); - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); } - ++id; - } - - unsigned long long endtime = getCurrentTime(); - printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - - taosMemoryFree(v.ts); - taosMemoryFree(lb); - taosMemoryFree(params); - taosMemoryFree(is_null); - taosMemoryFree(no_null); - - return 0; -} - - - -//10 tables 10 records single column bind -int stmt_scol_func4(TAOS_STMT *stmt) { - struct { - int64_t *ts; - int8_t b[60]; - int8_t v1[60]; - int16_t v2[60]; - int32_t v4[60]; - int64_t v8[60]; - float f4[60]; - double f8[60]; - char bin[60][40]; - } v = {0}; - - v.ts = taosMemoryMalloc(sizeof(int64_t) * 1000 * 60); - - int *lb = taosMemoryMalloc(60 * sizeof(int)); - - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1000*10); - char* is_null = taosMemoryMalloc(sizeof(char) * 60); - char* no_null = taosMemoryMalloc(sizeof(char) * 60); - - for (int i = 0; i < 60; ++i) { - lb[i] = 40; - no_null[i] = 0; - is_null[i] = (i % 10 == 2) ? 1 : 0; - v.b[i] = (int8_t)(i % 2); - v.v1[i] = (int8_t)((i+1) % 2); - v.v2[i] = (int16_t)i; - v.v4[i] = (int32_t)(i+1); - v.v8[i] = (int64_t)(i+2); - v.f4[i] = (float)(i+3); - v.f8[i] = (double)(i+4); - memset(v.bin[i], '0'+i%10, 40); - } - - for (int i = 0; i < 10000; i+=10) { - params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[i+0].buffer_length = sizeof(int64_t); - params[i+0].buffer = &v.ts[10*i/10]; - params[i+0].length = NULL; - params[i+0].is_null = no_null; - params[i+0].num = 2; + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } - params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[i+1].buffer_length = sizeof(int8_t); - params[i+1].buffer = v.b; - params[i+1].length = NULL; - params[i+1].is_null = no_null; - params[i+1].num = 2; - - params[i+2].buffer_type = TSDB_DATA_TYPE_INT; - params[i+2].buffer_length = sizeof(int32_t); - params[i+2].buffer = v.v4; - params[i+2].length = NULL; - params[i+2].is_null = no_null; - params[i+2].num = 2; - - params[i+3].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[i+3].buffer_length = sizeof(int64_t); - params[i+3].buffer = v.v8; - params[i+3].length = NULL; - params[i+3].is_null = no_null; - params[i+3].num = 2; - - params[i+4].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[i+4].buffer_length = sizeof(double); - params[i+4].buffer = v.f8; - params[i+4].length = NULL; - params[i+4].is_null = no_null; - params[i+4].num = 2; - } - - int64_t tts = 1591060628000; - for (int i = 0; i < 60000; ++i) { - v.ts[i] = tts + i; - } - - unsigned long long starttime = getCurrentTime(); - - char *sql = "insert into ? (ts,b,v4,v8,f8) values(?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - int id = 0; - for (int l = 0; l < 10; l++) { - for (int zz = 0; zz < 10; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - - for (int col=0; col < 10; ++col) { - taos_stmt_bind_single_param_batch(stmt, params + id++, col); + for (int32_t b = 0; b bindColNum + b*gCurCase->bindColNum)) { + exit(1); } - taos_stmt_add_batch(stmt); - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } } } - unsigned long long endtime = getCurrentTime(); - printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } - taosMemoryFree(v.ts); - taosMemoryFree(lb); - taosMemoryFree(params); - taosMemoryFree(is_null); - taosMemoryFree(no_null); + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); return 0; } +/* prepare [settbname bind add] exec */ +int insertMBSETest2(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); -int stmt_func1(TAOS_STMT *stmt) { - struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; - } v = {0}; - - TAOS_BIND params[10]; - params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts); - params[0].buffer = &v.ts; - params[0].length = ¶ms[0].buffer_length; - params[0].is_null = NULL; - - params[1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[1].buffer_length = sizeof(v.b); - params[1].buffer = &v.b; - params[1].length = ¶ms[1].buffer_length; - params[1].is_null = NULL; - - params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[2].buffer_length = sizeof(v.v1); - params[2].buffer = &v.v1; - params[2].length = ¶ms[2].buffer_length; - params[2].is_null = NULL; - - params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[3].buffer_length = sizeof(v.v2); - params[3].buffer = &v.v2; - params[3].length = ¶ms[3].buffer_length; - params[3].is_null = NULL; - - params[4].buffer_type = TSDB_DATA_TYPE_INT; - params[4].buffer_length = sizeof(v.v4); - params[4].buffer = &v.v4; - params[4].length = ¶ms[4].buffer_length; - params[4].is_null = NULL; - - params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[5].buffer_length = sizeof(v.v8); - params[5].buffer = &v.v8; - params[5].length = ¶ms[5].buffer_length; - params[5].is_null = NULL; - - params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[6].buffer_length = sizeof(v.f4); - params[6].buffer = &v.f4; - params[6].length = ¶ms[6].buffer_length; - params[6].is_null = NULL; - - params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[7].buffer_length = sizeof(v.f8); - params[7].buffer = &v.f8; - params[7].length = ¶ms[7].buffer_length; - params[7].is_null = NULL; - - params[8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[8].buffer_length = sizeof(v.bin); - params[8].buffer = v.bin; - params[8].length = ¶ms[8].buffer_length; - params[8].is_null = NULL; - - params[9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[9].buffer_length = sizeof(v.bin); - params[9].buffer = v.bin; - params[9].length = ¶ms[9].buffer_length; - params[9].is_null = NULL; - - int is_null = 1; - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); + int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } + + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + + for (int32_t b = 0; b tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + } + + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [bind add] exec] */ +int insertMBMETest1(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); - for (int zz = 0; zz < 10; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [bind add exec]] */ +int insertMBMETest2(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); + + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + for (int32_t b = 0; b bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* prepare [settbname [settbname bind add exec]] */ +int insertMBMETest3(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); + + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + + +/* prepare [settbname bind add exec] */ +int insertMBMETest4(TAOS_STMT *stmt) { + BindData data = {0}; + prepareData(&data); + + int code = taos_stmt_prepare(stmt, data.sql, 0); + if (code != 0){ + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + bpCheckIsInsert(stmt); + + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + + for (int32_t b = 0; b tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + + if (bpBindParam(stmt, data.pBind + t*bindTimes*gCurCase->bindColNum + b*gCurCase->bindColNum)) { + exit(1); + } + + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } + } + + bpCheckIsInsert(stmt); + bpCheckAffectedRows(stmt, 1); + + destroyData(&data); + + return 0; +} + +/* [prepare [settbname [bind add] exec]] */ +int insertMPMETest1(TAOS_STMT *stmt) { + int32_t loop = 0; + + while (gCurCase->bindColNum >= 2) { + BindData data = {0}; + prepareData(&data); + + int code = taos_stmt_prepare(stmt, data.sql, 0); if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - v.ts = 1591060628000 + zz * 10; - for (int i = 0; i < 10; ++i) { - v.ts += 1; - for (int j = 1; j < 10; ++j) { - params[j].is_null = ((i == j) ? &is_null : 0); - } - v.b = (int8_t)(i+zz*10) % 2; - v.v1 = (int8_t)(i+zz*10); - v.v2 = (int16_t)((i+zz*10) * 2); - v.v4 = (int32_t)((i+zz*10) * 4); - v.v8 = (int64_t)((i+zz*10) * 8); - v.f4 = (float)((i+zz*10) * 40); - v.f8 = (double)((i+zz*10) * 80); - for (int j = 0; j < sizeof(v.bin) - 1; ++j) { - v.bin[j] = (char)((i+zz)%10 + '0'); - } - - taos_stmt_bind_param(stmt, params); - taos_stmt_add_batch(stmt); - } - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); - } - - return 0; -} - - -int stmt_func2(TAOS_STMT *stmt) { - struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; - } v = {0}; - - TAOS_BIND params[10]; - params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts); - params[0].buffer = &v.ts; - params[0].length = ¶ms[0].buffer_length; - params[0].is_null = NULL; - - params[1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[1].buffer_length = sizeof(v.b); - params[1].buffer = &v.b; - params[1].length = ¶ms[1].buffer_length; - params[1].is_null = NULL; - - params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[2].buffer_length = sizeof(v.v1); - params[2].buffer = &v.v1; - params[2].length = ¶ms[2].buffer_length; - params[2].is_null = NULL; - - params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[3].buffer_length = sizeof(v.v2); - params[3].buffer = &v.v2; - params[3].length = ¶ms[3].buffer_length; - params[3].is_null = NULL; - - params[4].buffer_type = TSDB_DATA_TYPE_INT; - params[4].buffer_length = sizeof(v.v4); - params[4].buffer = &v.v4; - params[4].length = ¶ms[4].buffer_length; - params[4].is_null = NULL; - - params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[5].buffer_length = sizeof(v.v8); - params[5].buffer = &v.v8; - params[5].length = ¶ms[5].buffer_length; - params[5].is_null = NULL; - - params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[6].buffer_length = sizeof(v.f4); - params[6].buffer = &v.f4; - params[6].length = ¶ms[6].buffer_length; - params[6].is_null = NULL; - - params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[7].buffer_length = sizeof(v.f8); - params[7].buffer = &v.f8; - params[7].length = ¶ms[7].buffer_length; - params[7].is_null = NULL; - - params[8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[8].buffer_length = sizeof(v.bin); - params[8].buffer = v.bin; - params[8].length = ¶ms[8].buffer_length; - params[8].is_null = NULL; - - params[9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[9].buffer_length = sizeof(v.bin); - params[9].buffer = v.bin; - params[9].length = ¶ms[9].buffer_length; - params[9].is_null = NULL; - - int is_null = 1; - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - for (int l = 0; l < 100; l++) { - for (int zz = 0; zz < 10; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - v.ts = 1591060628000 + zz * 100 * l; - for (int i = 0; i < zz; ++i) { - v.ts += 1; - for (int j = 1; j < 10; ++j) { - params[j].is_null = ((i == j) ? &is_null : 0); - } - v.b = (int8_t)(i+zz*10) % 2; - v.v1 = (int8_t)(i+zz*10); - v.v2 = (int16_t)((i+zz*10) * 2); - v.v4 = (int32_t)((i+zz*10) * 4); - v.v8 = (int64_t)((i+zz*10) * 8); - v.f4 = (float)((i+zz*10) * 40); - v.f8 = (double)((i+zz*10) * 80); - for (int j = 0; j < sizeof(v.bin) - 1; ++j) { - v.bin[j] = (char)((i+zz)%10 + '0'); - } - - taos_stmt_bind_param(stmt, params); - taos_stmt_add_batch(stmt); - } - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); + printf("failed to execute taos_stmt_prepare. error:%s\n", taos_stmt_errstr(stmt)); exit(1); } - } + bpCheckIsInsert(stmt); + int32_t bindTimes = gCurCase->rowNum/gCurCase->bindRowNum; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + char buf[32]; + sprintf(buf, "t%d", t); + code = taos_stmt_set_tbname(stmt, buf); + if (code != 0){ + printf("taos_stmt_set_tbname error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + } - return 0; -} - - - - -int stmt_func3(TAOS_STMT *stmt) { - struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; - } v = {0}; - - TAOS_BIND params[10]; - params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[0].buffer_length = sizeof(v.ts); - params[0].buffer = &v.ts; - params[0].length = ¶ms[0].buffer_length; - params[0].is_null = NULL; - - params[1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[1].buffer_length = sizeof(v.b); - params[1].buffer = &v.b; - params[1].length = ¶ms[1].buffer_length; - params[1].is_null = NULL; - - params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[2].buffer_length = sizeof(v.v1); - params[2].buffer = &v.v1; - params[2].length = ¶ms[2].buffer_length; - params[2].is_null = NULL; - - params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[3].buffer_length = sizeof(v.v2); - params[3].buffer = &v.v2; - params[3].length = ¶ms[3].buffer_length; - params[3].is_null = NULL; - - params[4].buffer_type = TSDB_DATA_TYPE_INT; - params[4].buffer_length = sizeof(v.v4); - params[4].buffer = &v.v4; - params[4].length = ¶ms[4].buffer_length; - params[4].is_null = NULL; - - params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[5].buffer_length = sizeof(v.v8); - params[5].buffer = &v.v8; - params[5].length = ¶ms[5].buffer_length; - params[5].is_null = NULL; - - params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[6].buffer_length = sizeof(v.f4); - params[6].buffer = &v.f4; - params[6].length = ¶ms[6].buffer_length; - params[6].is_null = NULL; - - params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[7].buffer_length = sizeof(v.f8); - params[7].buffer = &v.f8; - params[7].length = ¶ms[7].buffer_length; - params[7].is_null = NULL; - - params[8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[8].buffer_length = sizeof(v.bin); - params[8].buffer = v.bin; - params[8].length = ¶ms[8].buffer_length; - params[8].is_null = NULL; - - params[9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[9].buffer_length = sizeof(v.bin); - params[9].buffer = v.bin; - params[9].length = ¶ms[9].buffer_length; - params[9].is_null = NULL; - - int is_null = 1; - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - for (int l = 0; l < 100; l++) { - for (int zz = 0; zz < 10; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - v.ts = 1591060628000 + zz * 100 * l; - for (int i = 0; i < zz; ++i) { - v.ts += 1; - for (int j = 1; j < 10; ++j) { - params[j].is_null = ((i == j) ? &is_null : 0); + if (gCaseCtrl.checkParamNum) { + bpCheckParamNum(stmt); + } + + for (int32_t b = 0; b bindColNum + b*gCurCase->bindColNum)) { + exit(1); } - v.b = (int8_t)(i+zz*10) % 2; - v.v1 = (int8_t)(i+zz*10); - v.v2 = (int16_t)((i+zz*10) * 2); - v.v4 = (int32_t)((i+zz*10) * 4); - v.v8 = (int64_t)((i+zz*10) * 8); - v.f4 = (float)((i+zz*10) * 40); - v.f8 = (double)((i+zz*10) * 80); - for (int j = 0; j < sizeof(v.bin) - 1; ++j) { - v.bin[j] = (char)((i+zz)%10 + '0'); + + if (taos_stmt_add_batch(stmt)) { + printf("taos_stmt_add_batch error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } + } - taos_stmt_bind_param(stmt, params); - taos_stmt_add_batch(stmt); + if (taos_stmt_execute(stmt) != 0) { + printf("taos_stmt_execute error:%s\n", taos_stmt_errstr(stmt)); + exit(1); } } + + bpCheckIsInsert(stmt); + + destroyData(&data); + + gCurCase->bindColNum -= 2; + gCurCase->fullCol = false; + loop++; } + bpCheckAffectedRows(stmt, loop); + + gExecLoopTimes = loop; - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); - } - - return 0; } +#if 0 //1 tables 10 records int stmt_funcb_autoctb1(TAOS_STMT *stmt) { @@ -859,7 +951,7 @@ int stmt_funcb_autoctb1(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -1008,7 +1100,7 @@ int stmt_funcb_autoctb1(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1037,7 +1129,7 @@ int stmt_funcb_autoctb1(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -1072,7 +1164,7 @@ int stmt_funcb_autoctb2(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -1221,7 +1313,7 @@ int stmt_funcb_autoctb2(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(1,true,2,3,4,5.0,6.0,'a','b') values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1250,7 +1342,7 @@ int stmt_funcb_autoctb2(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -1286,7 +1378,7 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -1410,7 +1502,7 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1439,7 +1531,7 @@ int stmt_funcb_autoctb3(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -1477,7 +1569,7 @@ int stmt_funcb_autoctb4(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*5); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*5); // int one_null = 1; int one_not_null = 0; @@ -1565,7 +1657,7 @@ int stmt_funcb_autoctb4(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(1,?,2,?,4,?,6.0,?,'b') (ts,b,v4,v8,f8) values(?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1594,7 +1686,7 @@ int stmt_funcb_autoctb4(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -1630,7 +1722,7 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -1754,7 +1846,7 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(1,?,2,?,4,?,6.0,?,'b') values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1783,7 +1875,7 @@ int stmt_funcb_autoctb_e1(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -1819,7 +1911,7 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -1968,7 +2060,7 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -1998,7 +2090,7 @@ int stmt_funcb_autoctb_e2(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -2036,7 +2128,7 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -2185,7 +2277,7 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 (id1,id2,id3,id4,id5,id6,id7,id8,id9) tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -2216,7 +2308,7 @@ int stmt_funcb_autoctb_e3(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -2251,7 +2343,7 @@ int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -2400,7 +2492,7 @@ int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -2441,7 +2533,7 @@ int stmt_funcb_autoctb_e4(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -2478,7 +2570,7 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(10 * sizeof(int)); TAOS_BIND *tags = taosMemoryCalloc(1, sizeof(TAOS_BIND) * 9 * 1); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 1*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 1*10); // int one_null = 1; int one_not_null = 0; @@ -2627,7 +2719,7 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? using stb1 tags(?,?,?,?,?,?,?,?,?) values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(NULL, sql, 0); @@ -2668,7 +2760,7 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { ++id; - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 10, (endtime-starttime)/1000000UL, (endtime-starttime)/(10)); taosMemoryFree(v.ts); @@ -2681,488 +2773,6 @@ int stmt_funcb_autoctb_e5(TAOS_STMT *stmt) { return 0; } - - -//300 tables 60 records -int stmt_funcb1(TAOS_STMT *stmt) { - struct { - int64_t *ts; - int8_t b[60]; - int8_t v1[60]; - int16_t v2[60]; - int32_t v4[60]; - int64_t v8[60]; - float f4[60]; - double f8[60]; - char bin[60][40]; - } v = {0}; - - v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - - int *lb = taosMemoryMalloc(60 * sizeof(int)); - - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = taosMemoryMalloc(sizeof(char) * 60); - char* no_null = taosMemoryMalloc(sizeof(char) * 60); - - for (int i = 0; i < 60; ++i) { - lb[i] = 40; - no_null[i] = 0; - is_null[i] = (i % 10 == 2) ? 1 : 0; - v.b[i] = (int8_t)(i % 2); - v.v1[i] = (int8_t)((i+1) % 2); - v.v2[i] = (int16_t)i; - v.v4[i] = (int32_t)(i+1); - v.v8[i] = (int64_t)(i+2); - v.f4[i] = (float)(i+3); - v.f8[i] = (double)(i+4); - memset(v.bin[i], '0'+i%10, 40); - } - - for (int i = 0; i < 9000000; i+=10) { - params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[i+0].buffer_length = sizeof(int64_t); - params[i+0].buffer = &v.ts[60*i/10]; - params[i+0].length = NULL; - params[i+0].is_null = no_null; - params[i+0].num = 60; - - params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[i+1].buffer_length = sizeof(int8_t); - params[i+1].buffer = v.b; - params[i+1].length = NULL; - params[i+1].is_null = is_null; - params[i+1].num = 60; - - params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[i+2].buffer_length = sizeof(int8_t); - params[i+2].buffer = v.v1; - params[i+2].length = NULL; - params[i+2].is_null = is_null; - params[i+2].num = 60; - - params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[i+3].buffer_length = sizeof(int16_t); - params[i+3].buffer = v.v2; - params[i+3].length = NULL; - params[i+3].is_null = is_null; - params[i+3].num = 60; - - params[i+4].buffer_type = TSDB_DATA_TYPE_INT; - params[i+4].buffer_length = sizeof(int32_t); - params[i+4].buffer = v.v4; - params[i+4].length = NULL; - params[i+4].is_null = is_null; - params[i+4].num = 60; - - params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[i+5].buffer_length = sizeof(int64_t); - params[i+5].buffer = v.v8; - params[i+5].length = NULL; - params[i+5].is_null = is_null; - params[i+5].num = 60; - - params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[i+6].buffer_length = sizeof(float); - params[i+6].buffer = v.f4; - params[i+6].length = NULL; - params[i+6].is_null = is_null; - params[i+6].num = 60; - - params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[i+7].buffer_length = sizeof(double); - params[i+7].buffer = v.f8; - params[i+7].length = NULL; - params[i+7].is_null = is_null; - params[i+7].num = 60; - - params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+8].buffer_length = 40; - params[i+8].buffer = v.bin; - params[i+8].length = lb; - params[i+8].is_null = is_null; - params[i+8].num = 60; - - params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+9].buffer_length = 40; - params[i+9].buffer = v.bin; - params[i+9].length = lb; - params[i+9].is_null = is_null; - params[i+9].num = 60; - - } - - int64_t tts = 1591060628000; - for (int i = 0; i < 54000000; ++i) { - v.ts[i] = tts + i; - } - - unsigned long long starttime = getCurrentTime(); - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - int id = 0; - for (int l = 0; l < 3000; l++) { - for (int zz = 0; zz < 300; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - - taos_stmt_bind_param_batch(stmt, params + id * 10); - taos_stmt_add_batch(stmt); - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); - } - - ++id; - } - - unsigned long long endtime = getCurrentTime(); - printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - - taosMemoryFree(v.ts); - taosMemoryFree(lb); - taosMemoryFree(params); - taosMemoryFree(is_null); - taosMemoryFree(no_null); - - return 0; -} - - -//1table 18000 reocrds -int stmt_funcb2(TAOS_STMT *stmt) { - struct { - int64_t *ts; - int8_t b[18000]; - int8_t v1[18000]; - int16_t v2[18000]; - int32_t v4[18000]; - int64_t v8[18000]; - float f4[18000]; - double f8[18000]; - char bin[18000][40]; - } v = {0}; - - v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - - int *lb = taosMemoryMalloc(18000 * sizeof(int)); - - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); - char* is_null = taosMemoryMalloc(sizeof(char) * 18000); - char* no_null = taosMemoryMalloc(sizeof(char) * 18000); - - for (int i = 0; i < 18000; ++i) { - lb[i] = 40; - no_null[i] = 0; - is_null[i] = (i % 10 == 2) ? 1 : 0; - v.b[i] = (int8_t)(i % 2); - v.v1[i] = (int8_t)((i+1) % 2); - v.v2[i] = (int16_t)i; - v.v4[i] = (int32_t)(i+1); - v.v8[i] = (int64_t)(i+2); - v.f4[i] = (float)(i+3); - v.f8[i] = (double)(i+4); - memset(v.bin[i], '0'+i%10, 40); - } - - for (int i = 0; i < 30000; i+=10) { - params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[i+0].buffer_length = sizeof(int64_t); - params[i+0].buffer = &v.ts[18000*i/10]; - params[i+0].length = NULL; - params[i+0].is_null = no_null; - params[i+0].num = 18000; - - params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[i+1].buffer_length = sizeof(int8_t); - params[i+1].buffer = v.b; - params[i+1].length = NULL; - params[i+1].is_null = is_null; - params[i+1].num = 18000; - - params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[i+2].buffer_length = sizeof(int8_t); - params[i+2].buffer = v.v1; - params[i+2].length = NULL; - params[i+2].is_null = is_null; - params[i+2].num = 18000; - - params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[i+3].buffer_length = sizeof(int16_t); - params[i+3].buffer = v.v2; - params[i+3].length = NULL; - params[i+3].is_null = is_null; - params[i+3].num = 18000; - - params[i+4].buffer_type = TSDB_DATA_TYPE_INT; - params[i+4].buffer_length = sizeof(int32_t); - params[i+4].buffer = v.v4; - params[i+4].length = NULL; - params[i+4].is_null = is_null; - params[i+4].num = 18000; - - params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[i+5].buffer_length = sizeof(int64_t); - params[i+5].buffer = v.v8; - params[i+5].length = NULL; - params[i+5].is_null = is_null; - params[i+5].num = 18000; - - params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[i+6].buffer_length = sizeof(float); - params[i+6].buffer = v.f4; - params[i+6].length = NULL; - params[i+6].is_null = is_null; - params[i+6].num = 18000; - - params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[i+7].buffer_length = sizeof(double); - params[i+7].buffer = v.f8; - params[i+7].length = NULL; - params[i+7].is_null = is_null; - params[i+7].num = 18000; - - params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+8].buffer_length = 40; - params[i+8].buffer = v.bin; - params[i+8].length = lb; - params[i+8].is_null = is_null; - params[i+8].num = 18000; - - params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+9].buffer_length = 40; - params[i+9].buffer = v.bin; - params[i+9].length = lb; - params[i+9].is_null = is_null; - params[i+9].num = 18000; - - } - - int64_t tts = 1591060628000; - for (int i = 0; i < 54000000; ++i) { - v.ts[i] = tts + i; - } - - unsigned long long starttime = getCurrentTime(); - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - int id = 0; - for (int l = 0; l < 10; l++) { - for (int zz = 0; zz < 300; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - - taos_stmt_bind_param_batch(stmt, params + id * 10); - taos_stmt_add_batch(stmt); - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); - } - ++id; - - } - - } - - unsigned long long endtime = getCurrentTime(); - printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - - taosMemoryFree(v.ts); - taosMemoryFree(lb); - taosMemoryFree(params); - taosMemoryFree(is_null); - taosMemoryFree(no_null); - - return 0; -} - - -//disorder -int stmt_funcb3(TAOS_STMT *stmt) { - struct { - int64_t *ts; - int8_t b[60]; - int8_t v1[60]; - int16_t v2[60]; - int32_t v4[60]; - int64_t v8[60]; - float f4[60]; - double f8[60]; - char bin[60][40]; - } v = {0}; - - v.ts = taosMemoryMalloc(sizeof(int64_t) * 900000 * 60); - - int *lb = taosMemoryMalloc(60 * sizeof(int)); - - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); - char* is_null = taosMemoryMalloc(sizeof(char) * 60); - char* no_null = taosMemoryMalloc(sizeof(char) * 60); - - for (int i = 0; i < 60; ++i) { - lb[i] = 40; - no_null[i] = 0; - is_null[i] = (i % 10 == 2) ? 1 : 0; - v.b[i] = (int8_t)(i % 2); - v.v1[i] = (int8_t)((i+1) % 2); - v.v2[i] = (int16_t)i; - v.v4[i] = (int32_t)(i+1); - v.v8[i] = (int64_t)(i+2); - v.f4[i] = (float)(i+3); - v.f8[i] = (double)(i+4); - memset(v.bin[i], '0'+i%10, 40); - } - - for (int i = 0; i < 9000000; i+=10) { - params[i+0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; - params[i+0].buffer_length = sizeof(int64_t); - params[i+0].buffer = &v.ts[60*i/10]; - params[i+0].length = NULL; - params[i+0].is_null = no_null; - params[i+0].num = 60; - - params[i+1].buffer_type = TSDB_DATA_TYPE_BOOL; - params[i+1].buffer_length = sizeof(int8_t); - params[i+1].buffer = v.b; - params[i+1].length = NULL; - params[i+1].is_null = is_null; - params[i+1].num = 60; - - params[i+2].buffer_type = TSDB_DATA_TYPE_TINYINT; - params[i+2].buffer_length = sizeof(int8_t); - params[i+2].buffer = v.v1; - params[i+2].length = NULL; - params[i+2].is_null = is_null; - params[i+2].num = 60; - - params[i+3].buffer_type = TSDB_DATA_TYPE_SMALLINT; - params[i+3].buffer_length = sizeof(int16_t); - params[i+3].buffer = v.v2; - params[i+3].length = NULL; - params[i+3].is_null = is_null; - params[i+3].num = 60; - - params[i+4].buffer_type = TSDB_DATA_TYPE_INT; - params[i+4].buffer_length = sizeof(int32_t); - params[i+4].buffer = v.v4; - params[i+4].length = NULL; - params[i+4].is_null = is_null; - params[i+4].num = 60; - - params[i+5].buffer_type = TSDB_DATA_TYPE_BIGINT; - params[i+5].buffer_length = sizeof(int64_t); - params[i+5].buffer = v.v8; - params[i+5].length = NULL; - params[i+5].is_null = is_null; - params[i+5].num = 60; - - params[i+6].buffer_type = TSDB_DATA_TYPE_FLOAT; - params[i+6].buffer_length = sizeof(float); - params[i+6].buffer = v.f4; - params[i+6].length = NULL; - params[i+6].is_null = is_null; - params[i+6].num = 60; - - params[i+7].buffer_type = TSDB_DATA_TYPE_DOUBLE; - params[i+7].buffer_length = sizeof(double); - params[i+7].buffer = v.f8; - params[i+7].length = NULL; - params[i+7].is_null = is_null; - params[i+7].num = 60; - - params[i+8].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+8].buffer_length = 40; - params[i+8].buffer = v.bin; - params[i+8].length = lb; - params[i+8].is_null = is_null; - params[i+8].num = 60; - - params[i+9].buffer_type = TSDB_DATA_TYPE_BINARY; - params[i+9].buffer_length = 40; - params[i+9].buffer = v.bin; - params[i+9].length = lb; - params[i+9].is_null = is_null; - params[i+9].num = 60; - - } - - int64_t tts = 1591060628000; - int64_t ttt = 0; - for (int i = 0; i < 54000000; ++i) { - v.ts[i] = tts + i; - if (i > 0 && i%60 == 0) { - ttt = v.ts[i-1]; - v.ts[i-1] = v.ts[i-60]; - v.ts[i-60] = ttt; - } - } - - unsigned long long starttime = getCurrentTime(); - - char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; - int code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ - printf("failed to execute taos_stmt_prepare. code:0x%x\n", code); - } - - int id = 0; - for (int l = 0; l < 3000; l++) { - for (int zz = 0; zz < 300; zz++) { - char buf[32]; - sprintf(buf, "m%d", zz); - code = taos_stmt_set_tbname(stmt, buf); - if (code != 0){ - printf("failed to execute taos_stmt_set_tbname. code:0x%x\n", code); - } - - taos_stmt_bind_param_batch(stmt, params + id * 10); - taos_stmt_add_batch(stmt); - } - - if (taos_stmt_execute(stmt) != 0) { - printf("failed to execute insert statement.\n"); - exit(1); - } - - ++id; - } - - unsigned long long endtime = getCurrentTime(); - printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); - - taosMemoryFree(v.ts); - taosMemoryFree(lb); - taosMemoryFree(params); - taosMemoryFree(is_null); - taosMemoryFree(no_null); - - return 0; -} - - - - //samets int stmt_funcb4(TAOS_STMT *stmt) { struct { @@ -3181,7 +2791,7 @@ int stmt_funcb4(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 900000*10); char* is_null = taosMemoryMalloc(sizeof(char) * 60); char* no_null = taosMemoryMalloc(sizeof(char) * 60); @@ -3277,7 +2887,7 @@ int stmt_funcb4(TAOS_STMT *stmt) { v.ts[i] = tts; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -3307,7 +2917,7 @@ int stmt_funcb4(TAOS_STMT *stmt) { ++id; } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -3340,7 +2950,7 @@ int stmt_funcb5(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(18000 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 3000*10); char* is_null = taosMemoryMalloc(sizeof(char) * 18000); char* no_null = taosMemoryMalloc(sizeof(char) * 18000); @@ -3436,7 +3046,7 @@ int stmt_funcb5(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into m0 values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -3460,7 +3070,7 @@ int stmt_funcb5(TAOS_STMT *stmt) { } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -3484,7 +3094,7 @@ int stmt_funcb_ssz1(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(30000 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 3000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 3000*10); char* no_null = taosMemoryMalloc(sizeof(int) * 200000); for (int i = 0; i < 30000; ++i) { @@ -3514,7 +3124,7 @@ int stmt_funcb_ssz1(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -3545,7 +3155,7 @@ int stmt_funcb_ssz1(TAOS_STMT *stmt) { } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -3575,7 +3185,7 @@ int stmt_funcb_s1(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 900000*10); char* is_null = taosMemoryMalloc(sizeof(char) * 60); char* no_null = taosMemoryMalloc(sizeof(char) * 60); @@ -3671,7 +3281,7 @@ int stmt_funcb_s1(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -3702,7 +3312,7 @@ int stmt_funcb_s1(TAOS_STMT *stmt) { } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -3737,7 +3347,7 @@ int stmt_funcb_sc1(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 900000*10); char* is_null = taosMemoryMalloc(sizeof(char) * 60); char* no_null = taosMemoryMalloc(sizeof(char) * 60); @@ -3833,7 +3443,7 @@ int stmt_funcb_sc1(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -3864,7 +3474,7 @@ int stmt_funcb_sc1(TAOS_STMT *stmt) { } } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -3895,7 +3505,7 @@ int stmt_funcb_sc2(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 900000*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 900000*10); char* is_null = taosMemoryMalloc(sizeof(char) * 60); char* no_null = taosMemoryMalloc(sizeof(char) * 60); @@ -3991,7 +3601,7 @@ int stmt_funcb_sc2(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -4024,7 +3634,7 @@ int stmt_funcb_sc2(TAOS_STMT *stmt) { } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -4055,7 +3665,7 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { int *lb = taosMemoryMalloc(60 * sizeof(int)); - TAOS_MULTI_BIND *params = taosMemoryCalloc(1, sizeof(TAOS_MULTI_BIND) * 60*10); + TAOS_BIND_v2 *params = taosMemoryCalloc(1, sizeof(TAOS_BIND_v2) * 60*10); char* is_null = taosMemoryMalloc(sizeof(char) * 60); char* no_null = taosMemoryMalloc(sizeof(char) * 60); @@ -4152,7 +3762,7 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { v.ts[i] = tts + i; } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); char *sql = "insert into ? values(?,?,?,?,?,?,?,?,?,?)"; int code = taos_stmt_prepare(stmt, sql, 0); @@ -4181,7 +3791,7 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { exit(1); } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%u useconds\n", 3000*300*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*300*60)); taosMemoryFree(v.ts); @@ -4192,15 +3802,12 @@ int stmt_funcb_sc3(TAOS_STMT *stmt) { return 0; } +#endif - -void check_result(TAOS *taos, char *tname, int printr, int expected) { +void prepareCheckResultImpl(TAOS *taos, char *tname, bool printr, int expected) { char sql[255] = "SELECT * FROM "; TAOS_RES *result; - //FORCE NO PRINT - printr = 0; - strcat(sql, tname); result = taos_query(taos, sql); @@ -4229,9 +3836,9 @@ void check_result(TAOS *taos, char *tname, int printr, int expected) { } if (rows == expected) { - printf("%d rows are fetched as expectation\n", rows); + printf("%d rows are fetched as expected from %s\n", rows, tname); } else { - printf("!!!expect %d rows, but %d rows are fetched\n", expected, rows); + printf("!!!expect %d rows, but %d rows are fetched from %s\n", expected, rows, tname); exit(1); } @@ -4240,6 +3847,22 @@ void check_result(TAOS *taos, char *tname, int printr, int expected) { } +void prepareCheckResult(TAOS *taos) { + char buf[32]; + for (int32_t t = 0; t< gCurCase->tblNum; ++t) { + if (gCurCase->tblNum > 1) { + sprintf(buf, "t%d", t); + } else { + sprintf(buf, "t%d", 0); + } + + prepareCheckResultImpl(taos, buf, gCaseCtrl.printRes, gCurCase->rowNum * gExecLoopTimes); + } + + gExecLoopTimes = 1; +} + + //120table 60 record each table int sql_perf1(TAOS *taos) { @@ -4263,7 +3886,7 @@ int sql_perf1(TAOS *taos) { } - unsigned long long starttime = getCurrentTime(); + int64_t starttime = taosGetTimestampUs(); for (int i = 0; i < 3000; ++i) { result = taos_query(taos, sql[i]); int code = taos_errno(result); @@ -4275,7 +3898,7 @@ int sql_perf1(TAOS *taos) { taos_free_result(result); } - unsigned long long endtime = getCurrentTime(); + int64_t endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 3000; i++) { @@ -4291,7 +3914,7 @@ int sql_perf1(TAOS *taos) { //one table 60 records one time int sql_perf_s1(TAOS *taos) { - char **sql = taosMemoryCalloc(1, sizeof(char*) * 360000); + char **sql = calloc(1, sizeof(char*) * 360000); TAOS_RES *result; for (int i = 0; i < 360000; i++) { @@ -4316,7 +3939,7 @@ int sql_perf_s1(TAOS *taos) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); for (int i = 0; i < 360000; ++i) { result = taos_query(taos, sql[i]); int code = taos_errno(result); @@ -4328,7 +3951,7 @@ int sql_perf_s1(TAOS *taos) { taos_free_result(result); } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 360000; i++) { @@ -4363,7 +3986,7 @@ int sql_s_perf1(TAOS *taos) { } - unsigned long long starttime = getCurrentTime(); + unsigned long long starttime = taosGetTimestampUs(); for (int i = 0; i < 3000; ++i) { result = taos_query(taos, sql[i]); int code = taos_errno(result); @@ -4375,7 +3998,7 @@ int sql_s_perf1(TAOS *taos) { taos_free_result(result); } - unsigned long long endtime = getCurrentTime(); + unsigned long long endtime = taosGetTimestampUs(); printf("insert total %d records, used %u seconds, avg:%.1f useconds\n", 3000*120*60, (endtime-starttime)/1000000UL, (endtime-starttime)/(3000*120*60)); for (int i = 0; i < 3000; i++) { @@ -4385,8 +4008,131 @@ int sql_s_perf1(TAOS *taos) { return 0; } +void generateCreateTableSQL(char *buf, int32_t tblIdx, int32_t colNum, int32_t *colList, bool stable) { + int32_t blen = 0; + blen = sprintf(buf, "create table %s%d ", (stable ? "st" : "t"), tblIdx); + if (stable) { + blen += sprintf(buf + blen, "tags ("); + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "tbooldata bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "ttinydata tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "tsmalldata smallint"); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "tintdata int"); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "tbigdata bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "tfloatdata float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "tdoubledata double"); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "tbinarydata binary(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "tts ts"); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "tnchardata nchar(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "tutinydata tinyint unsigned"); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "tusmalldata smallint unsigned"); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "tuintdata int unsigned"); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "tubigdata bigint unsigned"); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } -void prepare(TAOS *taos, int bigsize, int createChildTable) { + blen += sprintf(buf + blen, ")"); + } + + blen += sprintf(buf + blen, " ("); + + for (int c = 0; c < colNum; ++c) { + if (c > 0) { + blen += sprintf(buf + blen, ","); + } + + switch (colList[c]) { + case TSDB_DATA_TYPE_BOOL: + blen += sprintf(buf + blen, "booldata bool"); + break; + case TSDB_DATA_TYPE_TINYINT: + blen += sprintf(buf + blen, "tinydata tinyint"); + break; + case TSDB_DATA_TYPE_SMALLINT: + blen += sprintf(buf + blen, "smalldata smallint"); + break; + case TSDB_DATA_TYPE_INT: + blen += sprintf(buf + blen, "intdata int"); + break; + case TSDB_DATA_TYPE_BIGINT: + blen += sprintf(buf + blen, "bigdata bigint"); + break; + case TSDB_DATA_TYPE_FLOAT: + blen += sprintf(buf + blen, "floatdata float"); + break; + case TSDB_DATA_TYPE_DOUBLE: + blen += sprintf(buf + blen, "doubledata double"); + break; + case TSDB_DATA_TYPE_VARCHAR: + blen += sprintf(buf + blen, "binarydata binary(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + blen += sprintf(buf + blen, "ts timestamp"); + break; + case TSDB_DATA_TYPE_NCHAR: + blen += sprintf(buf + blen, "nchardata nchar(%d)", gVarCharSize); + break; + case TSDB_DATA_TYPE_UTINYINT: + blen += sprintf(buf + blen, "utinydata tinyint unsigned"); + break; + case TSDB_DATA_TYPE_USMALLINT: + blen += sprintf(buf + blen, "usmalldata smallint unsigned"); + break; + case TSDB_DATA_TYPE_UINT: + blen += sprintf(buf + blen, "uintdata int unsigned"); + break; + case TSDB_DATA_TYPE_UBIGINT: + blen += sprintf(buf + blen, "ubigdata bigint unsigned"); + break; + default: + printf("invalid col type:%d", colList[c]); + exit(1); + } + } + + blen += sprintf(buf + blen, ")"); + + if (gCaseCtrl.printCreateTblSql) { + printf("Create Table SQL:%s\n", buf); + } +} + +void prepare(TAOS *taos, int32_t colNum, int32_t *colList, int autoCreate) { TAOS_RES *result; int code; @@ -4405,15 +4151,11 @@ void prepare(TAOS *taos, int bigsize, int createChildTable) { result = taos_query(taos, "use demo"); taos_free_result(result); - if (createChildTable) { + if (!autoCreate) { // create table - for (int i = 0 ; i < 300; i++) { + for (int i = 0 ; i < 10; i++) { char buf[1024]; - if (bigsize) { - sprintf(buf, "create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))", i) ; - } else { - sprintf(buf, "create table m%d (ts timestamp, b int)", i) ; - } + generateCreateTableSQL(buf, i, colNum, colList, false); result = taos_query(taos, buf); code = taos_errno(result); if (code != 0) { @@ -4425,12 +4167,7 @@ void prepare(TAOS *taos, int bigsize, int createChildTable) { } } else { char buf[1024]; - if (bigsize) { - sprintf(buf, "create stable stb1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))" - " tags(id1 int, id2 bool, id3 tinyint, id4 smallint, id5 bigint, id6 float, id7 double, id8 binary(40), id9 nchar(40))") ; - } else { - sprintf(buf, "create stable stb1 (ts timestamp, b int) tags(id1 int, id2 bool, id3 tinyint, id4 smallint, id5 bigint, id6 float, id7 double, id8 binary(40), id9 nchar(40))") ; - } + generateCreateTableSQL(buf, 1, colNum, colList, true); result = taos_query(taos, buf); code = taos_errno(result); @@ -4444,652 +4181,135 @@ void prepare(TAOS *taos, int bigsize, int createChildTable) { } +void* runcase(TAOS *taos) { + TAOS_STMT *stmt = NULL; + int32_t caseIdx = 0; + for (int32_t i = 0; i < sizeof(gCase)/sizeof(gCase[0]); ++i) { + CaseCfg cfg = gCase[i]; + gCurCase = &cfg; -void preparem(TAOS *taos, int bigsize, int idx) { - TAOS_RES *result; - int code; - char dbname[32],sql[255]; - - sprintf(dbname, "demo%d", idx); - sprintf(sql, "drop database %s", dbname); - - - result = taos_query(taos, sql); - taos_free_result(result); - - sprintf(sql, "create database %s keep 36500", dbname); - result = taos_query(taos, sql); - code = taos_errno(result); - if (code != 0) { - printf("failed to create database, reason:%s\n", taos_errstr(result)); - taos_free_result(result); - exit(1); - } - taos_free_result(result); - - sprintf(sql, "use %s", dbname); - result = taos_query(taos, sql); - taos_free_result(result); - - // create table - for (int i = 0 ; i < 300; i++) { - char buf[1024]; - if (bigsize) { - sprintf(buf, "create table m%d (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), bin2 binary(40))", i) ; - } else { - sprintf(buf, "create table m%d (ts timestamp, b int)", i) ; + if ((gCaseCtrl.bindColTypeNum || gCaseCtrl.bindColNum) && (gCurCase->colNum != gFullColNum)) { + continue; } - result = taos_query(taos, buf); - code = taos_errno(result); - if (code != 0) { - printf("failed to create table, reason:%s\n", taos_errstr(result)); - taos_free_result(result); - exit(1); + + printf("* Case %d - %s Begin *\n", caseIdx, gCurCase->caseDesc); + + if (gCaseCtrl.runTimes) { + gCurCase->runTimes = gCaseCtrl.runTimes; } - taos_free_result(result); + + if (gCaseCtrl.rowNum) { + gCurCase->rowNum = gCaseCtrl.rowNum; + } + + if (gCurCase->fullCol) { + gCurCase->bindColNum = gCurCase->colNum; + } + + gCurCase->bindNullNum = gCaseCtrl.bindNullNum; + gCurCase->autoCreate = gCaseCtrl.autoCreate; + if (gCaseCtrl.bindColNum) { + gCurCase->bindColNum = gCaseCtrl.bindColNum; + gCurCase->fullCol = false; + } + if (gCaseCtrl.bindRowNum) { + gCurCase->bindRowNum = gCaseCtrl.bindRowNum; + } + if (gCaseCtrl.bindColTypeNum) { + gCurCase->bindColNum = gCaseCtrl.bindColTypeNum; + gCurCase->fullCol = false; + } + + for (int32_t n = 0; n < gCurCase->runTimes; ++n) { + prepare(taos, gCurCase->colNum, gCurCase->colList, gCurCase->autoCreate); + + stmt = taos_stmt_init(taos); + if (NULL == stmt) { + printf("taos_stmt_init failed, error:%s\n", taos_stmt_errstr(stmt)); + exit(1); + } + + (*gCurCase->runFn)(stmt); + + prepareCheckResult(taos); + + taos_stmt_close(stmt); + } + + printf("* Case %d - %s End *\n", caseIdx, gCurCase->caseDesc); + + caseIdx++; } -} - - - -//void runcase(TAOS *taos, int idx) { -void* runcase(void *par) { - T_par* tpar = (T_par *)par; - TAOS *taos = tpar->taos; - int idx = tpar->idx; - - TAOS_STMT *stmt; - - (void)idx; - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+10records+specifycol start\n"); - stmt_scol_func1(stmt); - printf("10t+10records+specifycol end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - check_result(taos, "m1", 1, 10); - check_result(taos, "m2", 1, 10); - check_result(taos, "m3", 1, 10); - check_result(taos, "m4", 1, 10); - check_result(taos, "m5", 1, 10); - check_result(taos, "m6", 1, 10); - check_result(taos, "m7", 1, 10); - check_result(taos, "m8", 1, 10); - check_result(taos, "m9", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("1t+100records+specifycol start\n"); - stmt_scol_func2(stmt); - printf("1t+100records+specifycol end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 100); - printf("check result end\n"); - taos_stmt_close(stmt); -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("300t+10r+bm+specifycol start\n"); - stmt_scol_func3(stmt); - printf("300t+10r+bm+specifycol end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 20); - check_result(taos, "m1", 1, 20); - check_result(taos, "m111", 1, 20); - check_result(taos, "m223", 1, 20); - check_result(taos, "m299", 1, 20); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+2r+bm+specifycol start\n"); - stmt_scol_func4(stmt); - printf("10t+2r+bm+specifycol end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 20); - check_result(taos, "m1", 1, 20); - check_result(taos, "m2", 1, 20); - check_result(taos, "m3", 1, 20); - check_result(taos, "m4", 1, 20); - check_result(taos, "m5", 1, 20); - check_result(taos, "m6", 1, 20); - check_result(taos, "m7", 1, 20); - check_result(taos, "m8", 1, 20); - check_result(taos, "m9", 1, 20); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+10records start\n"); - stmt_func1(stmt); - printf("10t+10records end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - check_result(taos, "m1", 1, 10); - check_result(taos, "m2", 1, 10); - check_result(taos, "m3", 1, 10); - check_result(taos, "m4", 1, 10); - check_result(taos, "m5", 1, 10); - check_result(taos, "m6", 1, 10); - check_result(taos, "m7", 1, 10); - check_result(taos, "m8", 1, 10); - check_result(taos, "m9", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+[0,1,2...9]records start\n"); - stmt_func2(stmt); - printf("10t+[0,1,2...9]records end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 0); - check_result(taos, "m1", 0, 100); - check_result(taos, "m2", 0, 200); - check_result(taos, "m3", 0, 300); - check_result(taos, "m4", 0, 400); - check_result(taos, "m5", 0, 500); - check_result(taos, "m6", 0, 600); - check_result(taos, "m7", 0, 700); - check_result(taos, "m8", 0, 800); - check_result(taos, "m9", 0, 900); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+[0,100,200...900]records start\n"); - stmt_func3(stmt); - printf("10t+[0,100,200...900]records end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 0); - check_result(taos, "m1", 0, 100); - check_result(taos, "m2", 0, 200); - check_result(taos, "m3", 0, 300); - check_result(taos, "m4", 0, 400); - check_result(taos, "m5", 0, 500); - check_result(taos, "m6", 0, 600); - check_result(taos, "m7", 0, 700); - check_result(taos, "m8", 0, 800); - check_result(taos, "m9", 0, 900); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("300t+60r+bm start\n"); - stmt_funcb1(stmt); - printf("300t+60r+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb1 start\n"); - stmt_funcb_autoctb1(stmt); - printf("1t+10r+bm+autoctb1 end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb2 start\n"); - stmt_funcb_autoctb2(stmt); - printf("1t+10r+bm+autoctb2 end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb3 start\n"); - stmt_funcb_autoctb3(stmt); - printf("1t+10r+bm+autoctb3 end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb4 start\n"); - stmt_funcb_autoctb4(stmt); - printf("1t+10r+bm+autoctb4 end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); -#endif - - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb+e1 start\n"); - stmt_funcb_autoctb_e1(stmt); - printf("1t+10r+bm+autoctb+e1 end\n"); - printf("check result start\n"); - //check_result(taos, "m0", 1, 0); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb+e2 start\n"); - stmt_funcb_autoctb_e2(stmt); - printf("1t+10r+bm+autoctb+e2 end\n"); - printf("check result start\n"); - //check_result(taos, "m0", 1, 0); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb+e3 start\n"); - stmt_funcb_autoctb_e3(stmt); - printf("1t+10r+bm+autoctb+e3 end\n"); - printf("check result start\n"); - //check_result(taos, "m0", 1, 0); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb+e4 start\n"); - stmt_funcb_autoctb_e4(stmt); - printf("1t+10r+bm+autoctb+e4 end\n"); - printf("check result start\n"); - //check_result(taos, "m0", 1, 0); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 0); - - stmt = taos_stmt_init(taos); - - printf("1t+10r+bm+autoctb+e5 start\n"); - stmt_funcb_autoctb_e5(stmt); - printf("1t+10r+bm+autoctb+e5 end\n"); - printf("check result start\n"); - //check_result(taos, "m0", 1, 0); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("1t+18000r+bm start\n"); - stmt_funcb2(stmt); - printf("1t+18000r+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("300t+60r+disorder+bm start\n"); - stmt_funcb3(stmt); - printf("300t+60r+disorder+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("300t+60r+samets+bm start\n"); - stmt_funcb4(stmt); - printf("300t+60r+samets+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 1); - check_result(taos, "m1", 0, 1); - check_result(taos, "m111", 0, 1); - check_result(taos, "m223", 0, 1); - check_result(taos, "m299", 0, 1); - printf("check result end\n"); - taos_stmt_close(stmt); -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("1t+18000r+nodyntable+bm start\n"); - stmt_funcb5(stmt); - printf("1t+18000r+nodyntable+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("300t+60r+bm+sc start\n"); - stmt_funcb_sc1(stmt); - printf("300t+60r+bm+sc end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("1t+60r+bm+sc start\n"); - stmt_funcb_sc2(stmt); - printf("1t+60r+bm+sc end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("10t+[1...10]r+bm+sc start\n"); - stmt_funcb_sc3(stmt); - printf("10t+[1...10]r+bm+sc end\n"); - printf("check result start\n"); - check_result(taos, "m0", 1, 1); - check_result(taos, "m1", 1, 2); - check_result(taos, "m2", 1, 3); - check_result(taos, "m3", 1, 4); - check_result(taos, "m4", 1, 5); - check_result(taos, "m5", 1, 6); - check_result(taos, "m6", 1, 7); - check_result(taos, "m7", 1, 8); - check_result(taos, "m8", 1, 9); - check_result(taos, "m9", 1, 10); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - stmt = taos_stmt_init(taos); - - printf("1t+60r+bm start\n"); - stmt_funcb_s1(stmt); - printf("1t+60r+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m111", 0, 180000); - check_result(taos, "m223", 0, 180000); - check_result(taos, "m299", 0, 180000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - - -#if 1 - prepare(taos, 1, 1); - - (void)stmt; - printf("120t+60r+sql start\n"); - sql_perf1(taos); - printf("120t+60r+sql end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m34", 0, 180000); - check_result(taos, "m67", 0, 180000); - check_result(taos, "m99", 0, 180000); - printf("check result end\n"); -#endif - -#if 1 - prepare(taos, 1, 1); - - (void)stmt; - printf("1t+60r+sql start\n"); - sql_perf_s1(taos); - printf("1t+60r+sql end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 180000); - check_result(taos, "m1", 0, 180000); - check_result(taos, "m34", 0, 180000); - check_result(taos, "m67", 0, 180000); - check_result(taos, "m99", 0, 180000); - printf("check result end\n"); -#endif - - -#if 1 - preparem(taos, 0, idx); - - stmt = taos_stmt_init(taos); - - printf("1t+30000r+bm start\n"); - stmt_funcb_ssz1(stmt); - printf("1t+30000r+bm end\n"); - printf("check result start\n"); - check_result(taos, "m0", 0, 300000); - check_result(taos, "m1", 0, 300000); - check_result(taos, "m111", 0, 300000); - check_result(taos, "m223", 0, 300000); - check_result(taos, "m299", 0, 300000); - printf("check result end\n"); - taos_stmt_close(stmt); - -#endif - printf("test end\n"); return NULL; } +void runAll(TAOS *taos) { + printf("Normal Test\n"); + runcase(taos); + + printf("Null Test\n"); + gCaseCtrl.bindNullNum = 1; + runcase(taos); + gCaseCtrl.bindNullNum = 0; + + printf("Bind Row Test\n"); + gCaseCtrl.bindRowNum = 1; + runcase(taos); + gCaseCtrl.bindRowNum = 0; + + printf("Row Num Test\n"); + gCaseCtrl.rowNum = 1000; + gCaseCtrl.printRes = false; + runcase(taos); + gCaseCtrl.rowNum = 0; + gCaseCtrl.printRes = true; + + printf("Runtimes Test\n"); + gCaseCtrl.runTimes = 2; + runcase(taos); + gCaseCtrl.runTimes = 0; + + printf("Check Param Test\n"); + gCaseCtrl.checkParamNum = true; + runcase(taos); + gCaseCtrl.checkParamNum = false; + + printf("Bind Col Num Test\n"); + gCaseCtrl.bindColNum = 6; + runcase(taos); + gCaseCtrl.bindColNum = 0; + + printf("Bind Col Type Test\n"); + gCaseCtrl.bindColTypeNum = tListLen(bindColTypeList); + gCaseCtrl.bindColTypeList = bindColTypeList; + runcase(taos); +} + int main(int argc, char *argv[]) { - TAOS *taos[4]; + TAOS *taos = NULL; + srand(time(NULL)); + // connect to server if (argc < 2) { printf("please input server ip \n"); return 0; } - taos[0] = taos_connect(argv[1], "root", "taosdata", NULL, 0); + taos = taos_connect(argv[1], "root", "taosdata", NULL, 0); if (taos == NULL) { printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); exit(1); } - taos[1] = taos_connect(argv[1], "root", "taosdata", NULL, 0); - if (taos == NULL) { - printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); - exit(1); - } + runAll(taos); - taos[2] = taos_connect(argv[1], "root", "taosdata", NULL, 0); - if (taos == NULL) { - printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - taos[3] = taos_connect(argv[1], "root", "taosdata", NULL, 0); - if (taos == NULL) { - printf("failed to connect to db, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - TdThread *pThreadList = (TdThread *) taosMemoryCalloc(sizeof(TdThread), 4); - - TdThreadAttr thattr; - taosThreadAttrInit(&thattr); - taosThreadAttrSetDetachState(&thattr, PTHREAD_CREATE_JOINABLE); - T_par par[4]; - - par[0].taos = taos[0]; - par[0].idx = 0; - par[1].taos = taos[1]; - par[1].idx = 1; - par[2].taos = taos[2]; - par[2].idx = 2; - par[3].taos = taos[3]; - par[3].idx = 3; - - taosThreadCreate(&(pThreadList[0]), &thattr, runcase, (void *)&par[0]); - //taosThreadCreate(&(pThreadList[1]), &thattr, runcase, (void *)&par[1]); - //taosThreadCreate(&(pThreadList[2]), &thattr, runcase, (void *)&par[2]); - //taosThreadCreate(&(pThreadList[3]), &thattr, runcase, (void *)&par[3]); - - while(1) { - taosSsleep(1); - } return 0; } diff --git a/tests/script/api/makefile b/tests/script/api/makefile index 92d0a89b0f..46a172cc3a 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -4,18 +4,14 @@ ROOT=./ TARGET=exe LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt -CFLAGS = -O0 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ +CFLAGS = -O0 -g -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ -Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \ - -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \ - -fsanitize=address + -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 -Wno-sign-conversion all: $(TARGET) exe: gcc $(CFLAGS) ./batchprepare.c -o $(ROOT)batchprepare $(LFLAGS) - gcc $(CFLAGS) ./stmtBatchTest.c -o $(ROOT)stmtBatchTest $(LFLAGS) - gcc $(CFLAGS) ./stmtTest.c -o $(ROOT)stmtTest $(LFLAGS) - gcc $(CFLAGS) ./stmt_function.c -o $(ROOT)stmt_function $(LFLAGS) clean: rm $(ROOT)batchprepare diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 64ea437648..506abf3fc5 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -93,4 +93,7 @@ # --- sma ./test.sh -f tsim/sma/tsmaCreateInsertData.sim +# --- valgrind +./test.sh -f tsim/valgrind/checkError.sim -v + #======================b1-end=============== diff --git a/tests/script/runAllSimCases.sh b/tests/script/runAllSimCases.sh index 279bc8363e..97bebd9eb8 100755 --- a/tests/script/runAllSimCases.sh +++ b/tests/script/runAllSimCases.sh @@ -1,4 +1,4 @@ -!/bin/bash +#!/bin/bash ################################################## # diff --git a/tests/script/sh/checkValgrind.sh b/tests/script/sh/checkValgrind.sh new file mode 100755 index 0000000000..17d7ce1aff --- /dev/null +++ b/tests/script/sh/checkValgrind.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +set +e +#set -x + +NODE_NAME= + +while getopts "n:" arg +do + case $arg in + n) + NODE_NAME=$OPTARG + ;; + ?) + echo "unkown argument" + ;; + esac +done + +SCRIPT_DIR=`dirname $0` +cd $SCRIPT_DIR/../ +SCRIPT_DIR=`pwd` + +IN_TDINTERNAL="community" +if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then + cd ../../.. +else + cd ../../ +fi + +TAOS_DIR=`pwd` +LOG_DIR=$TAOS_DIR/sim/$NODE_NAME/log +#CFG_DIR=$TAOS_DIR/sim/$NODE_NAME/cfg + +#echo ---- $LOG_DIR + +errors=`grep "ERROR SUMMARY:" ${LOG_DIR}/valgrind-taosd-*.log | cut -d ' ' -f 2,3,4,5 | tr -d "\n"` +echo $errors diff --git a/tests/script/tmp/data.sim b/tests/script/tmp/data.sim index 92fc9dccc9..4e714c01ee 100644 --- a/tests/script/tmp/data.sim +++ b/tests/script/tmp/data.sim @@ -1,9 +1,14 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c telemetryReporting -v 1 +system sh/cfg.sh -n dnode1 -c telemetryInterval -v 1 +system sh/cfg.sh -n dnode1 -c telemetryServer -v localhost +system sh/cfg.sh -n dnode1 -c telemetryPort -v 80 + +return system sh/exec.sh -n dnode1 -s start sql connect -return sql create database db sql create table db.tb (ts timestamp, i int) sql insert into db.tb values(now, 1) diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim index f7bd273624..60064b174e 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -33,8 +33,8 @@ endi sql connect $dbNamme = d0 -print =============== create database , vgroup 1 -sql create database $dbNamme vgroups 1 +print =============== create database , vgroup 4 +sql create database $dbNamme vgroups 4 sql use $dbNamme print =============== create super table diff --git a/tests/script/tsim/valgrind/checkError.sim b/tests/script/tsim/valgrind/checkError.sim new file mode 100644 index 0000000000..80700dcbce --- /dev/null +++ b/tests/script/tsim/valgrind/checkError.sim @@ -0,0 +1,83 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +#system sh/deploy.sh -n dnode2 -i 2 +#system sh/deploy.sh -n dnode3 -i 3 +#system sh/deploy.sh -n dnode4 -i 4 +#system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +#system sh/exec.sh -n dnode2 -s start +#system sh/exec.sh -n dnode3 -s start +#system sh/exec.sh -n dnode4 -s start + +sleep 2000 + +#$loop_cnt = 0 +#check_dnode_ready: +# $loop_cnt = $loop_cnt + 1 +# sleep 200 +# if $loop_cnt == 10 then +# print ====> dnode not ready! +# return -1 +# endi +#sql show dnodes +#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +#if $data[0][0] != 1 then +# return -1 +#endi +#if $data[0][4] != ready then +# goto check_dnode_ready +#endi +# +##sql connect +#sql create dnode $hostname port 7200 +#sql create dnode $hostname port 7300 +#sql create dnode $hostname port 7400 +# +#$loop_cnt = 0 +#check_dnode_ready_1: +#$loop_cnt = $loop_cnt + 1 +#sleep 200 +#if $loop_cnt == 10 then +# print ====> dnodes not ready! +# return -1 +#endi +#sql show dnodes +#print ===> $rows $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] +#print ===> $rows $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] $data[1][5] $data[1][6] +#print ===> $rows $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] +#print ===> $rows $data[3][0] $data[3][1] $data[3][2] $data[3][3] $data[3][4] $data[3][5] $data[3][6] +#if $data[0][4] != ready then +# goto check_dnode_ready_1 +#endi +#if $data[1][4] != ready then +# goto check_dnode_ready_1 +#endi +#if $data[2][4] != ready then +# goto check_dnode_ready_1 +#endi +#if $data[3][4] != ready then +# goto check_dnode_ready_1 +#endi + +#=========== please add any actions above ================= + +print ====> stop all dondes to output valgrind log file +system sh/exec.sh -n dnode1 -s stop -x SIGINT + +print ====> start to check if there are ERRORS in vagrind log file for each dnode +# -n : dnode[x] be check +system_content sh/checkValgrind.sh -n dnode1 +print cmd return result----> [ $system_content ] +if $system_content == @ERROR SUMMARY: 0 errors@ then + return 0 +endi + +$null= +if $system_content == $null then + return 0 +endi + +return -1 \ No newline at end of file diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index 2561aad1ef..f09e7d1f63 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -1,5 +1,7 @@ import taos import sys +import datetime +import inspect from util.log import * from util.sql import * @@ -65,73 +67,541 @@ class TDTestCase: ) tdSql.query("select c1 from ct4") - data_ct4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + data_ct4_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdSql.query("select c1 from t1") - data_t1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] - - # tdLog.printNoPrefix("==========step1: cast int to int, expect no changes") - - # tdSql.query("select cast(c1 as int) as b from ct4") - # for i in range(len(data_ct4)): - # tdSql.checkData( i, 0, data_ct4[i]) - - # tdSql.query("select cast(c1 as int) as b from t1") - # for i in range(len(data_t1)): - # tdSql.checkData( i, 0, data_t1[i]) + data_t1_c1 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] tdLog.printNoPrefix("==========step2: cast int to bigint, expect no changes") tdSql.query("select cast(c1 as bigint) as b from ct4") - for i in range(len(data_ct4)): - tdSql.checkData( i, 0, data_ct4[i]) + for i in range(len(data_ct4_c1)): + tdSql.checkData( i, 0, data_ct4_c1[i]) tdSql.query("select cast(c1 as bigint) as b from t1") - for i in range(len(data_t1)): - tdSql.checkData( i, 0, data_t1[i]) + for i in range(len(data_t1_c1)): + tdSql.checkData( i, 0, data_t1_c1[i]) - # tdLog.printNoPrefix("==========step3: cast int to float, expect no changes") - - # tdSql.query("select cast(c1 as float) as b from ct4") - # for i in range(len(data_ct4)): - # tdSql.checkData( i, 0, data_ct4[i]) - # tdSql.query("select cast(c1 as float) as b from t1") - # for i in range(len(data_t1)): - # tdSql.checkData( i, 0, data_t1[i]) - - # tdLog.printNoPrefix("==========step4: cast int to double, expect no changes") - - # tdSql.query("select cast(c1 as double) as b from ct4") - # for i in range(len(data_ct4)): - # tdSql.checkData( i, 0, data_ct4[i]) - # tdSql.query("select cast(c1 as double) as b from t1") - # for i in range(len(data_t1)): - # tdSql.checkData( i, 0, data_t1[i]) - - tdLog.printNoPrefix("==========step5: cast int to binary, expect no changes") + tdLog.printNoPrefix("==========step5: cast int to binary, expect changes to str(int) ") tdSql.query("select cast(c1 as binary(32)) as b from ct4") - for i in range(len(data_ct4)): - tdSql.checkData( i, 0, str(data_ct4[i]) ) + for i in range(len(data_ct4_c1)): + tdSql.checkData( i, 0, str(data_ct4_c1[i]) ) tdSql.query("select cast(c1 as binary(32)) as b from t1") - for i in range(len(data_t1)): - tdSql.checkData( i, 0, str(data_t1[i]) ) + for i in range(len(data_t1_c1)): + tdSql.checkData( i, 0, str(data_t1_c1[i]) ) - tdLog.printNoPrefix("==========step6: cast int to nchar, expect no changes") + tdLog.printNoPrefix("==========step6: cast int to nchar, expect changes to str(int) ") tdSql.query("select cast(c1 as nchar(32)) as b from ct4") - for i in range(len(data_ct4)): - tdSql.checkData( i, 0, str(data_ct4[i]) ) + for i in range(len(data_ct4_c1)): + tdSql.checkData( i, 0, str(data_ct4_c1[i]) ) tdSql.query("select cast(c1 as nchar(32)) as b from t1") - for i in range(len(data_t1)): - tdSql.checkData( i, 0, str(data_t1[i]) ) + for i in range(len(data_t1_c1)): + tdSql.checkData( i, 0, str(data_t1_c1[i]) ) - tdLog.printNoPrefix("==========step7: cast int to timestamp, expect no changes") + tdLog.printNoPrefix("==========step7: cast int to timestamp, expect changes to timestamp ") tdSql.query("select cast(c1 as timestamp) as b from ct4") - for i in range(len(data_ct4)): - tdSql.checkData( i, 0, data_ct4[i]) + for i in range(len(data_ct4_c1)): + if data_ct4_c1[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c1[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + tdSql.query("select cast(c1 as timestamp) as b from t1") - for i in range(len(data_t1)): - tdSql.checkData( i, 0, data_t1[i]) + for i in range(len(data_t1_c1)): + if data_ct4_c1[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c1[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdLog.printNoPrefix("==========step8: cast bigint to bigint, expect no changes") + tdSql.query("select c2 from ct4") + data_ct4_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c2 from t1") + data_t1_c2 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c2 as bigint) as b from ct4") + for i in range(len(data_ct4_c2)): + tdSql.checkData( i, 0, data_ct4_c2[i]) + tdSql.query("select cast(c2 as bigint) as b from t1") + for i in range(len(data_t1_c2)): + tdSql.checkData( i, 0, data_t1_c2[i]) + + + tdLog.printNoPrefix("==========step9: cast bigint to binary, expect changes to str(int) ") + + tdSql.query("select cast(c2 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c2)): + tdSql.checkData( i, 0, str(data_ct4_c2[i]) ) + tdSql.query("select cast(c2 as binary(32)) as b from t1") + for i in range(len(data_t1_c2)): + tdSql.checkData( i, 0, str(data_t1_c2[i]) ) + + tdLog.printNoPrefix("==========step10: cast bigint to nchar, expect changes to str(int) ") + + tdSql.query("select cast(c2 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c2)): + tdSql.checkData( i, 0, str(data_ct4_c2[i]) ) + tdSql.query("select cast(c2 as nchar(32)) as b from t1") + for i in range(len(data_t1_c2)): + tdSql.checkData( i, 0, str(data_t1_c2[i]) ) + + tdLog.printNoPrefix("==========step11: cast bigint to timestamp, expect changes to timestamp ") + + tdSql.query("select cast(c2 as timestamp) as b from ct4") + for i in range(len(data_ct4_c2)): + if data_ct4_c2[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c2[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdSql.query("select cast(c2 as timestamp) as b from t1") + for i in range(len(data_t1_c2)): + if data_t1_c2[i] is None: + tdSql.checkData( i, 0 , None ) + elif i == 10: + continue + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_t1_c2[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdLog.printNoPrefix("==========step12: cast smallint to bigint, expect no changes") + tdSql.query("select c3 from ct4") + data_ct4_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c3 from t1") + data_t1_c3 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c3 as bigint) as b from ct4") + for i in range(len(data_ct4_c3)): + tdSql.checkData( i, 0, data_ct4_c3[i]) + tdSql.query("select cast(c3 as bigint) as b from t1") + for i in range(len(data_t1_c3)): + tdSql.checkData( i, 0, data_t1_c3[i]) + + + tdLog.printNoPrefix("==========step13: cast smallint to binary, expect changes to str(int) ") + + tdSql.query("select cast(c3 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c3)): + tdSql.checkData( i, 0, str(data_ct4_c3[i]) ) + tdSql.query("select cast(c3 as binary(32)) as b from t1") + for i in range(len(data_t1_c3)): + tdSql.checkData( i, 0, str(data_t1_c3[i]) ) + + tdLog.printNoPrefix("==========step14: cast smallint to nchar, expect changes to str(int) ") + + tdSql.query("select cast(c3 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c3)): + tdSql.checkData( i, 0, str(data_ct4_c3[i]) ) + tdSql.query("select cast(c3 as nchar(32)) as b from t1") + for i in range(len(data_t1_c3)): + tdSql.checkData( i, 0, str(data_t1_c3[i]) ) + + tdLog.printNoPrefix("==========step15: cast smallint to timestamp, expect changes to timestamp ") + + tdSql.query("select cast(c3 as timestamp) as b from ct4") + for i in range(len(data_ct4_c3)): + if data_ct4_c3[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c3[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + tdSql.query("select cast(c3 as timestamp) as b from t1") + for i in range(len(data_t1_c3)): + if data_ct4_c3[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c3[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdLog.printNoPrefix("==========step16: cast smallint to bigint, expect no changes") + tdSql.query("select c4 from ct4") + data_ct4_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c4 from t1") + data_t1_c4 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c4 as bigint) as b from ct4") + for i in range(len(data_ct4_c4)): + tdSql.checkData( i, 0, data_ct4_c4[i]) + tdSql.query("select cast(c4 as bigint) as b from t1") + for i in range(len(data_t1_c4)): + tdSql.checkData( i, 0, data_t1_c4[i]) + + + tdLog.printNoPrefix("==========step17: cast smallint to binary, expect changes to str(int) ") + + tdSql.query("select cast(c4 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c4)): + tdSql.checkData( i, 0, str(data_ct4_c4[i]) ) + tdSql.query("select cast(c4 as binary(32)) as b from t1") + for i in range(len(data_t1_c4)): + tdSql.checkData( i, 0, str(data_t1_c4[i]) ) + + tdLog.printNoPrefix("==========step18: cast smallint to nchar, expect changes to str(int) ") + + tdSql.query("select cast(c4 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c4)): + tdSql.checkData( i, 0, str(data_ct4_c4[i]) ) + tdSql.query("select cast(c4 as nchar(32)) as b from t1") + for i in range(len(data_t1_c4)): + tdSql.checkData( i, 0, str(data_t1_c4[i]) ) + + tdLog.printNoPrefix("==========step19: cast smallint to timestamp, expect changes to timestamp ") + + tdSql.query("select cast(c4 as timestamp) as b from ct4") + for i in range(len(data_ct4_c4)): + if data_ct4_c4[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c4[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + tdSql.query("select cast(c4 as timestamp) as b from t1") + for i in range(len(data_t1_c4)): + if data_ct4_c4[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(data_ct4_c4[i]/1000) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdLog.printNoPrefix("==========step20: cast float to bigint, expect no changes") + tdSql.query("select c5 from ct4") + data_ct4_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c5 from t1") + data_t1_c5 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c5 as bigint) as b from ct4") + for i in range(len(data_ct4_c5)): + tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, int(data_ct4_c5[i]) ) + tdSql.query("select cast(c5 as bigint) as b from t1") + for i in range(len(data_t1_c5)): + tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, int(data_t1_c5[i]) ) + + tdLog.printNoPrefix("==========step21: cast float to binary, expect changes to str(int) ") + tdSql.query("select cast(c5 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c5)): + tdSql.checkData( i, 0, str(data_ct4_c5[i]) ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' ) + tdSql.query("select cast(c5 as binary(32)) as b from t1") + for i in range(len(data_t1_c5)): + tdSql.checkData( i, 0, str(data_t1_c5[i]) ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' ) + + tdLog.printNoPrefix("==========step22: cast float to nchar, expect changes to str(int) ") + tdSql.query("select cast(c5 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c5)): + tdSql.checkData( i, 0, None ) if data_ct4_c5[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c5[i]:.6f}' ) + tdSql.query("select cast(c5 as nchar(32)) as b from t1") + for i in range(len(data_t1_c5)): + tdSql.checkData( i, 0, None ) if data_t1_c5[i] is None else tdSql.checkData( i, 0, f'{data_t1_c5[i]:.6f}' ) + + tdLog.printNoPrefix("==========step23: cast float to timestamp, expect changes to timestamp ") + tdSql.query("select cast(c5 as timestamp) as b from ct4") + for i in range(len(data_ct4_c5)): + if data_ct4_c5[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c5[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + tdSql.query("select cast(c5 as timestamp) as b from t1") + for i in range(len(data_t1_c5)): + if data_t1_c5[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c5[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + tdLog.printNoPrefix("==========step24: cast double to bigint, expect no changes") + tdSql.query("select c6 from ct4") + data_ct4_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c6 from t1") + data_t1_c6 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c6 as bigint) as b from ct4") + for i in range(len(data_ct4_c6)): + tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, int(data_ct4_c6[i]) ) + tdSql.query("select cast(c6 as bigint) as b from t1") + for i in range(len(data_t1_c6)): + if data_t1_c6[i] is None: + tdSql.checkData( i, 0, None ) + elif data_t1_c6[i] > 99999999 or data_t1_c6[i] < -999999: + continue + else: + tdSql.checkData( i, 0, int(data_t1_c6[i]) ) + + tdLog.printNoPrefix("==========step25: cast double to binary, expect changes to str(int) ") + tdSql.query("select cast(c6 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c6)): + tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' ) + tdSql.query("select cast(c6 as binary(32)) as b from t1") + for i in range(len(data_t1_c6)): + tdSql.checkData( i, 0, None ) if data_t1_c6[i] is None else tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' ) + + tdLog.printNoPrefix("==========step26: cast double to nchar, expect changes to str(int) ") + tdSql.query("select cast(c6 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c6)): + tdSql.checkData( i, 0, None ) if data_ct4_c6[i] is None else tdSql.checkData( i, 0, f'{data_ct4_c6[i]:.6f}' ) + tdSql.query("select cast(c6 as nchar(32)) as b from t1") + for i in range(len(data_t1_c6)): + tdSql.checkData( i, 0, None ) if data_t1_c6[i] is None else tdSql.checkData( i, 0, f'{data_t1_c6[i]:.6f}' ) + + tdLog.printNoPrefix("==========step27: cast double to timestamp, expect changes to timestamp ") + tdSql.query("select cast(c6 as timestamp) as b from ct4") + for i in range(len(data_ct4_c6)): + if data_ct4_c6[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c6[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + tdSql.query("select cast(c6 as timestamp) as b from t1") + for i in range(len(data_t1_c6)): + if data_t1_c6[i] is None: + tdSql.checkData( i, 0 , None ) + elif i == 10: + continue + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c6[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + tdLog.printNoPrefix("==========step28: cast bool to bigint, expect no changes") + tdSql.query("select c7 from ct4") + data_ct4_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c7 from t1") + data_t1_c7 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdSql.query("select cast(c7 as bigint) as b from ct4") + for i in range(len(data_ct4_c7)): + tdSql.checkData( i, 0, data_ct4_c7[i]) + tdSql.query("select cast(c7 as bigint) as b from t1") + for i in range(len(data_t1_c7)): + tdSql.checkData( i, 0, data_t1_c7[i]) + + tdLog.printNoPrefix("==========step29: cast bool to binary, expect changes to str(int) ") + tdSql.query("select cast(c7 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c7)): + tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() ) + tdSql.query("select cast(c7 as binary(32)) as b from t1") + for i in range(len(data_t1_c7)): + tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() ) + + tdLog.printNoPrefix("==========step30: cast bool to nchar, expect changes to str(int) ") + tdSql.query("select cast(c7 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c7)): + tdSql.checkData( i, 0, None ) if data_ct4_c7[i] is None else tdSql.checkData( i, 0, str(data_ct4_c7[i]).lower() ) + tdSql.query("select cast(c7 as nchar(32)) as b from t1") + for i in range(len(data_t1_c7)): + tdSql.checkData( i, 0, None ) if data_t1_c7[i] is None else tdSql.checkData( i, 0, str(data_t1_c7[i]).lower() ) + + tdLog.printNoPrefix("==========step31: cast bool to timestamp, expect changes to timestamp ") + tdSql.query("select cast(c7 as timestamp) as b from ct4") + for i in range(len(data_ct4_c7)): + if data_ct4_c7[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_ct4_c7[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + tdSql.query("select cast(c7 as timestamp) as b from t1") + for i in range(len(data_t1_c7)): + if data_t1_c7[i] is None: + tdSql.checkData( i, 0 , None ) + else: + utc_zone = datetime.timezone.utc + utc_8 = datetime.timezone(datetime.timedelta(hours=8)) + date_init_stamp = datetime.datetime.utcfromtimestamp(int(data_t1_c7[i]/1000)) + date_data = date_init_stamp.replace(tzinfo=utc_zone).astimezone(utc_8).strftime("%Y-%m-%d %H:%M:%S.%f") + tdSql.checkData( i, 0, date_data) + + + tdSql.query("select c8 from ct4") + data_ct4_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c8 from t1") + data_t1_c8 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdLog.printNoPrefix("==========step32: cast binary to binary, expect no changes ") + tdSql.query("select cast(c8 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c8)): + tdSql.checkData( i, 0, None ) if data_ct4_c8[i] is None else tdSql.checkData(i,0,data_ct4_c8[i]) + + tdSql.query("select cast(c8 as binary(32)) as b from t1") + for i in range(len(data_t1_c8)): + tdSql.checkData( i, 0, None ) if data_t1_c8[i] is None else tdSql.checkData(i,0,data_t1_c8[i]) + + tdLog.printNoPrefix("==========step33: cast binary to binary, expect truncate ") + tdSql.query("select cast(c8 as binary(2)) as b from ct4") + for i in range(len(data_ct4_c8)): + if data_ct4_c8[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_ct4_c8[i][:2]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c8[i][:2]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i][:2]}") + tdSql.query("select cast(c8 as binary(2)) as b from t1") + for i in range(len(data_t1_c8)): + if data_t1_c8[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_t1_c8[i][:2]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c8[i][:2]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i][:2]}") + + tdLog.printNoPrefix("==========step34: cast binary to nchar, expect changes to str(int) ") + tdSql.query("select cast(c8 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c8)): + if data_ct4_c8[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_ct4_c8[i]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c8[i]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c8[i]}") + tdSql.query("select cast(c8 as nchar(32)) as b from t1") + for i in range(len(data_t1_c8)): + if data_t1_c8[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_t1_c8[i]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c8[i]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c8[i]}") + + + tdSql.query("select c9 from ct4") + data_ct4_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c9 from t1") + data_t1_c9 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + "c10 timestamp" + + tdLog.printNoPrefix("==========step35: cast nchar to nchar, expect no changes ") + tdSql.query("select cast(c9 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c9)): + if data_ct4_c9[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_ct4_c9[i]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c9[i]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i]}") + tdSql.query("select cast(c9 as nchar(32)) as b from t1") + for i in range(len(data_t1_c9)): + tdSql.checkData( i, 0, data_t1_c9[i] ) + if data_t1_c9[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_t1_c9[i]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c9[i]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i]}") + + tdLog.printNoPrefix("==========step36: cast nchar to nchar, expect truncate ") + tdSql.query("select cast(c9 as nchar(2)) as b from ct4") + for i in range(len(data_ct4_c9)): + if data_ct4_c9[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_ct4_c9[i][:2]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_ct4_c9[i][:2]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_ct4_c9[i][:2]}") + tdSql.query("select cast(c9 as nchar(2)) as b from t1") + for i in range(len(data_t1_c9)): + if data_t1_c9[i] is None: + tdSql.checkData( i, 0, None) + elif tdSql.getData(i,0) == data_t1_c9[i][:2]: + tdLog.info( f"sql:{tdSql.sql}, row:{i} col:0 data:{tdSql.queryResult[i][0]} == expect:{data_t1_c9[i][:2]}" ) + else: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + tdLog.exit(f"{caller.filename}({caller.lineno}) failed: sql:{tdSql.sql} row:{i} col:0 data:{tdSql.queryResult[i][0]} != expect:{data_t1_c9[i][:2]}") + + tdSql.query("select c10 from ct4") + data_ct4_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + tdSql.query("select c10 from t1") + data_t1_c10 = [tdSql.getData(i,0) for i in range(tdSql.queryRows)] + + tdLog.printNoPrefix("==========step37: cast timestamp to nchar, expect no changes ") + tdSql.query("select cast(c10 as nchar(32)) as b from ct4") + for i in range(len(data_ct4_c10)): + if data_ct4_c10[i] is None: + tdSql.checkData( i, 0, None ) + else: + time2str = str(int(datetime.datetime.timestamp(data_ct4_c10[i])*1000)) + tdSql.checkData( i, 0, time2str ) + tdSql.query("select cast(c10 as nchar(32)) as b from t1") + for i in range(len(data_t1_c10)): + if data_t1_c10[i] is None: + tdSql.checkData( i, 0, None ) + elif i == 10: + continue + else: + time2str = str(int(datetime.datetime.timestamp(data_t1_c10[i])*1000)) + tdSql.checkData( i, 0, time2str ) + + tdLog.printNoPrefix("==========step38: cast timestamp to binary, expect no changes ") + tdSql.query("select cast(c10 as binary(32)) as b from ct4") + for i in range(len(data_ct4_c10)): + if data_ct4_c10[i] is None: + tdSql.checkData( i, 0, None ) + else: + time2str = str(int(datetime.datetime.timestamp(data_ct4_c10[i])*1000)) + tdSql.checkData( i, 0, time2str ) + tdSql.query("select cast(c10 as binary(32)) as b from t1") + for i in range(len(data_t1_c10)): + if data_t1_c10[i] is None: + tdSql.checkData( i, 0, None ) + elif i == 10: + continue + else: + time2str = str(int(datetime.datetime.timestamp(data_t1_c10[i])*1000)) + tdSql.checkData( i, 0, time2str ) + tdSql.error("select cast(c1 as int) as b from ct4") tdSql.error("select cast(c1 as bool) as b from ct4") @@ -152,11 +622,8 @@ class TDTestCase: tdSql.error("select cast(c8 as tinyint unsigned) as b from ct4") tdSql.error("select cast(c8 as timestamp ) as b from ct4") - - tdSql.error("select cast(c9 as binary(64) ) as b from ct4") tdSql.error("select cast(c9 as timestamp ) as b from ct4") - tdSql.error("select cast(c10 as binary(64) ) as b from ct4") - tdSql.error("select cast(c10 as nchar(64) ) as b from ct4") + tdSql.error("select cast(c9 as binary(64) ) as b from ct4") def stop(self): diff --git a/tests/system-test/2-query/distinct.py b/tests/system-test/2-query/distinct.py new file mode 100644 index 0000000000..a82f3a6f59 --- /dev/null +++ b/tests/system-test/2-query/distinct.py @@ -0,0 +1,262 @@ +import taos +import sys + +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, remove-redundant-fstring + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table") + tdSql.execute("create stable db.stb1 (ts timestamp, c1 int, c2 int) tags(t0 tinyint, t1 int, t2 int)") + tdSql.execute("create stable db.stb2 (ts timestamp, c2 int, c3 binary(16)) tags(t2 binary(16), t3 binary(16), t4 int)") + maxRemainderNum=7 + tbnum=101 + for i in range(tbnum-1): + sql = f"create table db.t{i} using db.stb1 tags({i%maxRemainderNum}, {(i-1)%maxRemainderNum}, {i%2})" + tdSql.execute(sql) + tdSql.execute(f"insert into db.t{i} values (now-10d, {i}, {i%3})") + tdSql.execute(f"insert into db.t{i} values (now-9d, {i}, {(i-1)%3})") + tdSql.execute(f"insert into db.t{i} values (now-8d, {i}, {(i-2)%3})") + tdSql.execute(f"insert into db.t{i} (ts )values (now-7d)") + + tdSql.execute(f"create table db.t0{i} using db.stb2 tags('{i%maxRemainderNum}', '{(i-1)%maxRemainderNum}', {i%3})") + tdSql.execute(f"insert into db.t0{i} values (now-10d, {i}, '{(i+1)%3}')") + tdSql.execute(f"insert into db.t0{i} values (now-9d, {i}, '{(i+2)%3}')") + tdSql.execute(f"insert into db.t0{i} values (now-8d, {i}, '{(i)%3}')") + tdSql.execute(f"insert into db.t0{i} (ts )values (now-7d)") + # tdSql.execute("create table db.t100num using db.stb1 tags(null, null, null)") + # tdSql.execute("create table db.t0100num using db.stb2 tags(null, null, null)") + # tdSql.execute(f"insert into db.t100num values (now-10d, {tbnum-1}, 1)") + # tdSql.execute(f"insert into db.t100num values (now-9d, {tbnum-1}, 0)") + # tdSql.execute(f"insert into db.t100num values (now-8d, {tbnum-1}, 2)") + # tdSql.execute(f"insert into db.t100num (ts )values (now-7d)") + # tdSql.execute(f"insert into db.t0100num values (now-10d, {tbnum-1}, 1)") + # tdSql.execute(f"insert into db.t0100num values (now-9d, {tbnum-1}, 0)") + # tdSql.execute(f"insert into db.t0100num values (now-8d, {tbnum-1}, 2)") + # tdSql.execute(f"insert into db.t0100num (ts )values (now-7d)") + + #========== distinct multi-data-coloumn ========== + # tdSql.query(f"select distinct c1 from stb1 where c1 <{tbnum}") + # tdSql.checkRows(tbnum) + # tdSql.query(f"select distinct c2 from stb1") + # tdSql.checkRows(4) + # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum}") + # tdSql.checkRows(tbnum*3) + # tdSql.query(f"select distinct c1,c1 from stb1 where c1 <{tbnum}") + # tdSql.checkRows(tbnum) + # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum} limit 3") + # tdSql.checkRows(3) + # tdSql.query(f"select distinct c1,c2 from stb1 where c1 <{tbnum} limit 3 offset {tbnum*3-2}") + # tdSql.checkRows(2) + + tdSql.query(f"select distinct c1 from t1 where c1 <{tbnum}") + tdSql.checkRows(1) + tdSql.query(f"select distinct c2 from t1") + tdSql.checkRows(4) + tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum}") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1,c1 from t1 ") + tdSql.checkRows(2) + tdSql.query(f"select distinct c1,c1 from t1 where c1 <{tbnum}") + tdSql.checkRows(1) + tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum} limit 3") + tdSql.checkRows(3) + tdSql.query(f"select distinct c1,c2 from t1 where c1 <{tbnum} limit 3 offset 2") + tdSql.checkRows(1) + + # tdSql.query(f"select distinct c3 from stb2 where c2 <{tbnum} ") + # tdSql.checkRows(3) + # tdSql.query(f"select distinct c3, c2 from stb2 where c2 <{tbnum} limit 2") + # tdSql.checkRows(2) + + # tdSql.error("select distinct c5 from stb1") + tdSql.error("select distinct c5 from t1") + tdSql.error("select distinct c1 from db.*") + tdSql.error("select c2, distinct c1 from stb1") + tdSql.error("select c2, distinct c1 from t1") + tdSql.error("select distinct c2 from ") + tdSql.error("distinct c2 from stb1") + tdSql.error("distinct c2 from t1") + tdSql.error("select distinct c1, c2, c3 from stb1") + tdSql.error("select distinct c1, c2, c3 from t1") + tdSql.error("select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from stb1") + tdSql.error("select distinct stb1.c1, stb1.c2, stb2.c2, stb2.c3 from t1") + tdSql.error("select distinct t1.c1, t1.c2, t2.c1, t2.c2 from t1") + # tdSql.query(f"select distinct c1 c2, c2 c3 from stb1 where c1 <{tbnum}") + # tdSql.checkRows(tbnum*3) + tdSql.query(f"select distinct c1 c2, c2 c3 from t1 where c1 <{tbnum}") + tdSql.checkRows(3) + # tdSql.error("select distinct c1, c2 from stb1 order by ts") + tdSql.error("select distinct c1, c2 from t1 order by ts") + # tdSql.error("select distinct c1, ts from stb1 group by c2") + tdSql.error("select distinct c1, ts from t1 group by c2") + # tdSql.error("select distinct c1, max(c2) from stb1 ") + tdSql.error("select distinct c1, max(c2) from t1 ") + # tdSql.error("select max(c2), distinct c1 from stb1 ") + tdSql.error("select max(c2), distinct c1 from t1 ") + # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 group by t0") + tdSql.error("select distinct c1, c2 from t1 where c1 > 3 group by t0") + # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) ") + tdSql.error("select distinct c1, c2 from t1 where c1 > 3 interval(1d) ") + # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)") + tdSql.error("select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)") + # tdSql.error("select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)") + tdSql.error("select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)") + # tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 slimit 1") + # tdSql.error("select distinct c1, c2 from t1 where c1 > 3 slimit 1") + # tdSql.query(f"select distinct c1, c2 from stb1 where c1 between {tbnum-2} and {tbnum} ") + # tdSql.checkRows(6) + tdSql.query(f"select distinct c1, c2 from t1 where c1 between {tbnum-2} and {tbnum} ") + # tdSql.checkRows(1) + # tdSql.query("select distinct c1, c2 from stb1 where c1 in (1,2,3,4,5)") + # tdSql.checkRows(15) + tdSql.query("select distinct c1, c2 from t1 where c1 in (1,2,3,4,5)") + # tdSql.checkRows(1) + # tdSql.query("select distinct c1, c2 from stb1 where c1 in (100,1000,10000)") + # tdSql.checkRows(3) + tdSql.query("select distinct c1, c2 from t1 where c1 in (100,1000,10000)") + # tdSql.checkRows(0) + + # tdSql.query(f"select distinct c1,c2 from (select * from stb1 where c1 > {tbnum-2}) ") + # tdSql.checkRows(3) + # tdSql.query(f"select distinct c1,c2 from (select * from t1 where c1 < {tbnum}) ") + # tdSql.checkRows(3) + # tdSql.query(f"select distinct c1,c2 from (select * from stb1 where t2 !=0 and t2 != 1) ") + # tdSql.checkRows(0) + # tdSql.error("select distinct c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") + # tdSql.error("select c1, c2 from (select distinct c1, c2 from stb1 where t0 > 2 and t1 < 3) ") + # tdSql.query("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 ) where c1 < 4") + # tdSql.checkRows(3) + # tdSql.error("select distinct c1, c2 from (select c1 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.error("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 order by ts)") + # tdSql.error("select distinct c1, c2 from (select c2, c1 from t1 where c1 > 2 order by ts)") + # tdSql.error("select distinct c1, c2 from (select c2, c1 from stb1 where c1 > 2 group by c1)") + # tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 group by c1)") + # tdSql.error("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 group by c1)") + # tdSql.query("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from stb1 )") + # tdSql.checkRows(1) + # tdSql.query("select distinct c1, c2 from (select max(c1) c1, max(c2) c2 from t1 )") + # tdSql.checkRows(1) + # tdSql.error("select distinct stb1.c1, stb1.c2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") + # tdSql.error("select distinct t1.c1, t1.c2 from t1 , t2 where t1.ts=t2.ts ") + + # tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from stb1 group by ts)") + # tdSql.error("select distinct c1, c2 from (select count(c1) c1, count(c2) c2 from t1 group by ts)") + + + + # #========== suport distinct multi-tags-coloumn ========== + # tdSql.query("select distinct t1 from stb1") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t0, t1 from stb1") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t1, t0 from stb1") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t1, t2 from stb1") + # tdSql.checkRows(maxRemainderNum*2+1) + # tdSql.query("select distinct t0, t1, t2 from stb1") + # tdSql.checkRows(maxRemainderNum*2+1) + # tdSql.query("select distinct t0 t1, t1 t2 from stb1") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t0, t0, t0 from stb1") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t0, t1 from t1") + # tdSql.checkRows(1) + # tdSql.query("select distinct t0, t1 from t100num") + # tdSql.checkRows(1) + + # tdSql.query("select distinct t3 from stb2") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t2, t3 from stb2") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t3, t2 from stb2") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t4, t2 from stb2") + # tdSql.checkRows(maxRemainderNum*3+1) + # tdSql.query("select distinct t2, t3, t4 from stb2") + # tdSql.checkRows(maxRemainderNum*3+1) + # tdSql.query("select distinct t2 t1, t3 t2 from stb2") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t3, t3, t3 from stb2") + # tdSql.checkRows(maxRemainderNum+1) + # tdSql.query("select distinct t2, t3 from t01") + # tdSql.checkRows(1) + # tdSql.query("select distinct t3, t4 from t0100num") + # tdSql.checkRows(1) + + + # ########## should be error ######### + # tdSql.error("select distinct from stb1") + # tdSql.error("select distinct t3 from stb1") + # tdSql.error("select distinct t1 from db.*") + # tdSql.error("select distinct t2 from ") + # tdSql.error("distinct t2 from stb1") + # tdSql.error("select distinct stb1") + # tdSql.error("select distinct t0, t1, t2, t3 from stb1") + # tdSql.error("select distinct stb1.t0, stb1.t1, stb2.t2, stb2.t3 from stb1") + + # tdSql.error("select dist t0 from stb1") + # tdSql.error("select distinct stb2.t2, stb2.t3 from stb1") + # tdSql.error("select distinct stb2.t2 t1, stb2.t3 t2 from stb1") + + # tdSql.error("select distinct t0, t1 from t1 where t0 < 7") + + # ########## add where condition ########## + # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3") + # tdSql.checkRows(3) + # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 limit 2") + # tdSql.checkRows(2) + # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 limit 2 offset 2") + # tdSql.checkRows(1) + # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 slimit 2") + # tdSql.checkRows(3) + # tdSql.error("select distinct t0, t1 from stb1 where c1 > 2") + # tdSql.query("select distinct t0, t1 from stb1 where t1 > 3 and t1 < 5") + # tdSql.checkRows(1) + # tdSql.error("select distinct stb1.t0, stb1.t1 from stb1, stb2 where stb1.t2=stb2.t4") + # tdSql.error("select distinct t0, t1 from stb1 where stb2.t4 > 2") + # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 group by t0") + # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 interval(1d) ") + # tdSql.error("select distinct t0, t1 from stb1 where t1 > 3 interval(1d) fill(next)") + # tdSql.error("select distinct t0, t1 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)") + + # tdSql.error("select max(c1), distinct t0 from stb1 where t0 > 2") + # tdSql.error("select distinct t0, max(c1) from stb1 where t0 > 2") + # tdSql.error("select distinct t0 from stb1 where t0 in (select t0 from stb1 where t0 > 2)") + # tdSql.query("select distinct t0, t1 from stb1 where t0 in (1,2,3,4,5)") + # tdSql.checkRows(5) + # tdSql.query("select distinct t1 from (select t0, t1 from stb1 where t0 > 2) ") + # tdSql.checkRows(4) + # tdSql.error("select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 and t1 < 3) ") + # tdSql.error("select distinct t1 from (select distinct t0, t1 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.query("select distinct t1 from (select t0, t1 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.checkRows(1) + # tdSql.error("select distinct t1, t0 from (select t1 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.error("select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1 group by t1)") + # tdSql.error("select distinct t1, t0 from (select max(t1) t1, max(t0) t0 from stb1)") + # tdSql.query("select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.checkRows(1) + # tdSql.error(" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 order by ts) where t1 < 3") + # tdSql.error("select t1, t0 from (select distinct t1,t0 from stb1 where t0 > 2 ) where t1 < 3") + # tdSql.error(" select distinct t1, t0 from (select t1,t0 from stb1 where t0 > 2 group by ts) where t1 < 3") + # tdSql.error("select distinct stb1.t1, stb1.t2 from stb1 , stb2 where stb1.ts=stb2.ts and stb1.t2=stb2.t4") + # tdSql.error("select distinct t1.t1, t1.t2 from t1 , t2 where t1.ts=t2.ts ") + + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index 0b8bbd24b2..65e4785b5d 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -1,17 +1,7 @@ -python3 ./test.py -f 2-query/between.py - - - - - - - - - - - - - - - +#!/bin/bash +set -e +#python3 ./test.py -f 2-query/between.py +python3 ./test.py -f 2-query/distinct.py +python3 ./test.py -f 2-query/varchar.py +python3 ./test.py -f 2-query/cast.py diff --git a/tests/test/c/tmqDemo.c b/tests/test/c/tmqDemo.c index 2b3e9963f0..50b4a0800f 100644 --- a/tests/test/c/tmqDemo.c +++ b/tests/test/c/tmqDemo.c @@ -340,7 +340,7 @@ tmq_t* build_consumer() { tmq_conf_set(conf, "td.connect.user", "root"); tmq_conf_set(conf, "td.connect.pass", "taosdata"); tmq_conf_set(conf, "td.connect.db", g_stConfInfo.dbName); - tmq_t* tmq = tmq_consumer_new1(conf, NULL, 0); + tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); assert(tmq); tmq_conf_destroy(conf); return tmq; @@ -367,7 +367,7 @@ void sync_consume_loop(tmq_t* tmq, tmq_list_t* topics) { TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 1); if (tmqmessage) { /*msg_process(tmqmessage);*/ - tmq_message_destroy(tmqmessage); + taos_free_result(tmqmessage); if ((++msg_count % MIN_COMMIT_COUNT) == 0) tmq_commit(tmq, NULL, 0); } @@ -400,7 +400,7 @@ void perf_loop(tmq_t* tmq, tmq_list_t* topics, int32_t totalMsgs, int64_t walLog if (0 != g_stConfInfo.showMsgFlag) { /*msg_process(tmqmessage);*/ } - tmq_message_destroy(tmqmessage); + taos_free_result(tmqmessage); } else { break; } diff --git a/tests/test/c/tmqSim.c b/tests/test/c/tmqSim.c index 5546e514cc..d3bed600dd 100644 --- a/tests/test/c/tmqSim.c +++ b/tests/test/c/tmqSim.c @@ -31,46 +31,46 @@ #define NC "\033[0m" #define min(a, b) (((a) < (b)) ? (a) : (b)) -#define MAX_SQL_STR_LEN (1024 * 1024) -#define MAX_ROW_STR_LEN (16 * 1024) -#define MAX_CONSUMER_THREAD_CNT (16) +#define MAX_SQL_STR_LEN (1024 * 1024) +#define MAX_ROW_STR_LEN (16 * 1024) +#define MAX_CONSUMER_THREAD_CNT (16) typedef struct { - TdThread thread; - int32_t consumerId; + TdThread thread; + int32_t consumerId; - int32_t ifCheckData; - int64_t expectMsgCnt; - - int64_t consumeMsgCnt; - int32_t checkresult; + int32_t ifCheckData; + int64_t expectMsgCnt; - char topicString[1024]; - char keyString[1024]; + int64_t consumeMsgCnt; + int32_t checkresult; - int32_t numOfTopic; - char topics[32][64]; + char topicString[1024]; + char keyString[1024]; - int32_t numOfKey; - char key[32][64]; - char value[32][64]; + int32_t numOfTopic; + char topics[32][64]; + + int32_t numOfKey; + char key[32][64]; + char value[32][64]; tmq_t* tmq; tmq_list_t* topicList; - + } SThreadInfo; typedef struct { // input from argvs - char dbName[32]; - int32_t showMsgFlag; - int32_t consumeDelay; // unit s - int32_t numOfThread; - SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT]; + char dbName[32]; + int32_t showMsgFlag; + int32_t consumeDelay; // unit s + int32_t numOfThread; + SThreadInfo stThreads[MAX_CONSUMER_THREAD_CNT]; } SConfInfo; static SConfInfo g_stConfInfo; -TdFilePtr g_fp = NULL; +TdFilePtr g_fp = NULL; // char* g_pRowValue = NULL; // TdFilePtr g_fp = NULL; @@ -95,7 +95,7 @@ void initLogFile() { TdFilePtr pFile = taosOpenFile("./tmqlog.txt", TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | 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; @@ -103,27 +103,27 @@ void initLogFile() { struct tm tm = *taosLocalTime(&tTime, NULL); taosFprintfFile(pFile, "###################################################################\n"); - taosFprintfFile(pFile, "# configDir: %s\n", configDir); - taosFprintfFile(pFile, "# dbName: %s\n", g_stConfInfo.dbName); - taosFprintfFile(pFile, "# showMsgFlag: %d\n", g_stConfInfo.showMsgFlag); - taosFprintfFile(pFile, "# consumeDelay: %d\n", g_stConfInfo.consumeDelay); + taosFprintfFile(pFile, "# configDir: %s\n", configDir); + taosFprintfFile(pFile, "# dbName: %s\n", g_stConfInfo.dbName); + taosFprintfFile(pFile, "# showMsgFlag: %d\n", g_stConfInfo.showMsgFlag); + taosFprintfFile(pFile, "# consumeDelay: %d\n", g_stConfInfo.consumeDelay); - for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { + for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { taosFprintfFile(pFile, "# consumer %d info:\n", g_stConfInfo.stThreads[i].consumerId); - taosFprintfFile(pFile, " Topics: "); - for (int i = 0 ; i < g_stConfInfo.stThreads[i].numOfTopic; i++) { - taosFprintfFile(pFile, "%s, ", g_stConfInfo.stThreads[i].topics[i]); + taosFprintfFile(pFile, " Topics: "); + for (int i = 0; i < g_stConfInfo.stThreads[i].numOfTopic; i++) { + taosFprintfFile(pFile, "%s, ", g_stConfInfo.stThreads[i].topics[i]); } - taosFprintfFile(pFile, "\n"); + taosFprintfFile(pFile, "\n"); taosFprintfFile(pFile, " Key: "); - for (int i = 0 ; i < g_stConfInfo.stThreads[i].numOfKey; i++) { - taosFprintfFile(pFile, "%s:%s, ", g_stConfInfo.stThreads[i].key[i], g_stConfInfo.stThreads[i].value[i]); + for (int i = 0; i < g_stConfInfo.stThreads[i].numOfKey; i++) { + taosFprintfFile(pFile, "%s:%s, ", g_stConfInfo.stThreads[i].key[i], g_stConfInfo.stThreads[i].value[i]); } taosFprintfFile(pFile, "\n"); } - + taosFprintfFile(pFile, "# Test time: %d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year + 1900, tm.tm_mon + 1, - tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); taosFprintfFile(pFile, "###################################################################\n"); } @@ -180,23 +180,23 @@ void ltrim(char* str) { // return str; } -static int running = 1; +static int running = 1; static void msg_process(TAOS_RES* msg, int32_t msgIndex, int32_t threadLable) { char buf[1024]; - //printf("topic: %s\n", tmq_get_topic_name(msg)); - //printf("vg:%d\n", tmq_get_vgroup_id(msg)); - taosFprintfFile(g_fp, "msg index:%d, threadLable: %d\n", msgIndex, threadLable); - taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), tmq_get_vgroup_id(msg)); - + // printf("topic: %s\n", tmq_get_topic_name(msg)); + // printf("vg:%d\n", tmq_get_vgroup_id(msg)); + taosFprintfFile(g_fp, "msg index:%d, threadLable: %d\n", msgIndex, threadLable); + taosFprintfFile(g_fp, "topic: %s, vgroupId: %d\n", tmq_get_topic_name(msg), tmq_get_vgroup_id(msg)); + while (1) { TAOS_ROW row = taos_fetch_row(msg); if (row == NULL) break; TAOS_FIELD* fields = taos_fetch_fields(msg); int32_t numOfFields = taos_field_count(msg); - //taos_print_row(buf, row, fields, numOfFields); - //printf("%s\n", buf); - //taosFprintfFile(g_fp, "%s\n", buf); + // taos_print_row(buf, row, fields, numOfFields); + // printf("%s\n", buf); + // taosFprintfFile(g_fp, "%s\n", buf); } } @@ -213,7 +213,7 @@ int queryDB(TAOS* taos, char* command) { return 0; } -void build_consumer(SThreadInfo *pInfo) { +void build_consumer(SThreadInfo* pInfo) { char sqlStr[1024] = {0}; TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); @@ -233,11 +233,11 @@ void build_consumer(SThreadInfo *pInfo) { for (int32_t i = 0; i < pInfo->numOfKey; i++) { tmq_conf_set(conf, pInfo->key[i], pInfo->value[i]); } - pInfo->tmq = tmq_consumer_new(pConn, conf, NULL, 0); + pInfo->tmq = tmq_consumer_new(conf, NULL, 0); return; } -void build_topic_list(SThreadInfo *pInfo) { +void build_topic_list(SThreadInfo* pInfo) { pInfo->topicList = tmq_list_new(); // tmq_list_append(topic_list, "test_stb_topic_1"); for (int32_t i = 0; i < pInfo->numOfTopic; i++) { @@ -246,48 +246,45 @@ void build_topic_list(SThreadInfo *pInfo) { return; } -int32_t saveConsumeResult(SThreadInfo *pInfo) { +int32_t saveConsumeResult(SThreadInfo* pInfo) { char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); assert(pConn != NULL); - + // schema: ts timestamp, consumerid int, consummsgcnt bigint, checkresult int - sprintf(sqlStr, "insert into %s.consumeresult values (now, %d, %" PRId64 ", %d)", - g_stConfInfo.dbName, - pInfo->consumerId, - pInfo->consumeMsgCnt, - pInfo->checkresult); - + sprintf(sqlStr, "insert into %s.consumeresult values (now, %d, %" PRId64 ", %d)", g_stConfInfo.dbName, + pInfo->consumerId, pInfo->consumeMsgCnt, pInfo->checkresult); + TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { printf("error in save consumeinfo, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); exit(-1); } - + taos_free_result(pRes); return 0; } -void loop_consume(SThreadInfo *pInfo) { +void loop_consume(SThreadInfo* pInfo) { tmq_resp_err_t err; - + int64_t totalMsgs = 0; - //int64_t totalRows = 0; + // int64_t totalRows = 0; while (running) { TAOS_RES* tmqMsg = tmq_consumer_poll(pInfo->tmq, g_stConfInfo.consumeDelay * 1000); - if (tmqMsg) { + if (tmqMsg) { if (0 != g_stConfInfo.showMsgFlag) { msg_process(tmqMsg, totalMsgs, 0); } - - tmq_message_destroy(tmqMsg); - + + taos_free_result(tmqMsg); + totalMsgs++; - + if (totalMsgs >= pInfo->expectMsgCnt) { break; } @@ -295,7 +292,7 @@ void loop_consume(SThreadInfo *pInfo) { break; } } - + err = tmq_consumer_close(pInfo->tmq); if (err) { printf("tmq_consumer_close() fail, reason: %s\n", tmq_err2str(err)); @@ -303,35 +300,34 @@ void loop_consume(SThreadInfo *pInfo) { } pInfo->consumeMsgCnt = totalMsgs; - } -void *consumeThreadFunc(void *param) { +void* consumeThreadFunc(void* param) { int32_t totalMsgs = 0; - SThreadInfo *pInfo = (SThreadInfo *)param; + SThreadInfo* pInfo = (SThreadInfo*)param; build_consumer(pInfo); build_topic_list(pInfo); - if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)){ + if ((NULL == pInfo->tmq) || (NULL == pInfo->topicList)) { return NULL; } - + tmq_resp_err_t err = tmq_subscribe(pInfo->tmq, pInfo->topicList); if (err) { printf("tmq_subscribe() fail, reason: %s\n", tmq_err2str(err)); exit(-1); } - + loop_consume(pInfo); err = tmq_unsubscribe(pInfo->tmq); if (err) { printf("tmq_unsubscribe() fail, reason: %s\n", tmq_err2str(err)); - pInfo->consumeMsgCnt = -1; + pInfo->consumeMsgCnt = -1; return NULL; - } - + } + // save consume result into consumeresult table saveConsumeResult(pInfo); @@ -343,7 +339,7 @@ void parseConsumeInfo() { const char delim[2] = ","; const char ch = ':'; - for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { + for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { token = strtok(g_stConfInfo.stThreads[i].topicString, delim); while (token != NULL) { // printf("%s\n", token ); @@ -351,10 +347,10 @@ void parseConsumeInfo() { ltrim(g_stConfInfo.stThreads[i].topics[g_stConfInfo.stThreads[i].numOfTopic]); // printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]); g_stConfInfo.stThreads[i].numOfTopic++; - + token = strtok(NULL, delim); } - + token = strtok(g_stConfInfo.stThreads[i].keyString, delim); while (token != NULL) { // printf("%s\n", token ); @@ -368,7 +364,7 @@ void parseConsumeInfo() { // g_stConfInfo.value[g_stConfInfo.numOfKey]); g_stConfInfo.stThreads[i].numOfKey++; } - + token = strtok(NULL, delim); } } @@ -376,46 +372,47 @@ void parseConsumeInfo() { int32_t getConsumeInfo() { char sqlStr[1024] = {0}; - + TAOS* pConn = taos_connect(NULL, "root", "taosdata", NULL, 0); assert(pConn != NULL); - + sprintf(sqlStr, "select * from %s.consumeinfo", g_stConfInfo.dbName); TAOS_RES* pRes = taos_query(pConn, sqlStr); if (taos_errno(pRes) != 0) { printf("error in get consumeinfo, reason:%s\n", taos_errstr(pRes)); taos_free_result(pRes); exit(-1); - } - - TAOS_ROW row = NULL; - int num_fields = taos_num_fields(pRes); - TAOS_FIELD* fields = taos_fetch_fields(pRes); - - // schema: ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, ifcheckdata int - + } + + TAOS_ROW row = NULL; + int num_fields = taos_num_fields(pRes); + TAOS_FIELD* fields = taos_fetch_fields(pRes); + + // schema: ts timestamp, consumerid int, topiclist binary(1024), keylist binary(1024), expectmsgcnt bigint, + // ifcheckdata int + int32_t numOfThread = 0; while ((row = taos_fetch_row(pRes))) { - int32_t* lengths = taos_fetch_lengths(pRes); - - for (int i = 0; i < num_fields; ++i) { + int32_t* lengths = taos_fetch_lengths(pRes); + + for (int i = 0; i < num_fields; ++i) { if (row[i] == NULL || 0 == i) { continue; } - + if ((1 == i) && (fields[i].type == TSDB_DATA_TYPE_INT)) { - g_stConfInfo.stThreads[numOfThread].consumerId = *((int32_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].consumerId = *((int32_t*)row[i]); } else if ((2 == i) && (fields[i].type == TSDB_DATA_TYPE_BINARY)) { memcpy(g_stConfInfo.stThreads[numOfThread].topicString, row[i], lengths[i]); } else if ((3 == i) && (fields[i].type == TSDB_DATA_TYPE_BINARY)) { memcpy(g_stConfInfo.stThreads[numOfThread].keyString, row[i], lengths[i]); } else if ((4 == i) && (fields[i].type == TSDB_DATA_TYPE_BIGINT)) { - g_stConfInfo.stThreads[numOfThread].expectMsgCnt = *((int64_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].expectMsgCnt = *((int64_t*)row[i]); } else if ((5 == i) && (fields[i].type == TSDB_DATA_TYPE_INT)) { - g_stConfInfo.stThreads[numOfThread].ifCheckData = *((int32_t *)row[i]); + g_stConfInfo.stThreads[numOfThread].ifCheckData = *((int32_t*)row[i]); } } - numOfThread ++; + numOfThread++; } g_stConfInfo.numOfThread = numOfThread; @@ -426,7 +423,6 @@ int32_t getConsumeInfo() { return 0; } - int main(int32_t argc, char* argv[]) { parseArgument(argc, argv); getConsumeInfo(); @@ -438,18 +434,19 @@ int main(int32_t argc, char* argv[]) { // pthread_create one thread to consume for (int32_t i = 0; i < g_stConfInfo.numOfThread; ++i) { - taosThreadCreate(&(g_stConfInfo.stThreads[i].thread), &thattr, consumeThreadFunc, (void *)(&(g_stConfInfo.stThreads[i]))); + taosThreadCreate(&(g_stConfInfo.stThreads[i].thread), &thattr, consumeThreadFunc, + (void*)(&(g_stConfInfo.stThreads[i]))); } for (int32_t i = 0; i < g_stConfInfo.numOfThread; i++) { taosThreadJoin(g_stConfInfo.stThreads[i].thread, NULL); } - //printf("consumer: %d, cosumer1: %d\n", totalMsgs, pInfo->consumeMsgCnt); - - taosFprintfFile(g_fp, "\n"); - taosCloseFile(&g_fp); - + // printf("consumer: %d, cosumer1: %d\n", totalMsgs, pInfo->consumeMsgCnt); + + taosFprintfFile(g_fp, "\n"); + taosCloseFile(&g_fp); + return 0; } diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 8b3edb6035..dbc3c2c460 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -441,6 +441,12 @@ void simStoreSystemContentResult(SScript *script, char *filename) { // if ((fd = fopen(filename, "r")) != NULL) { if ((pFile = taosOpenFile(filename, TD_FILE_READ)) != NULL) { taosReadFile(pFile, script->system_ret_content, MAX_SYSTEM_RESULT_LEN - 1); + int32_t len = strlen(script->system_ret_content); + for (int32_t i = 0; i < len; ++i) { + if (script->system_ret_content[i] == '\n' || script->system_ret_content[i] == '\r') { + script->system_ret_content[i] = 0; + } + } taosCloseFile(&pFile); char rmCmd[MAX_FILE_NAME_LEN] = {0}; sprintf(rmCmd, "rm -f %s", filename); diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index 36d2866fb5..ca5bf69795 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -224,63 +224,27 @@ int32_t shellRunCommand(TAOS *con, char *command) { } } - bool esc = false; - char quote = 0, *cmd = command, *p = command; + char quote = 0, *cmd = command; for (char c = *command++; c != 0; c = *command++) { - if (esc) { - switch (c) { - case 'n': - c = '\n'; - break; - case 'r': - c = '\r'; - break; - case 't': - c = '\t'; - break; - case 'G': - *p++ = '\\'; - break; - case '\'': - case '"': - if (quote) { - *p++ = '\\'; - } - break; - } - *p++ = c; - esc = false; + if (c == '\\' && (*command == '\'' || *command == '"' || *command == '`')) { + command ++; continue; } - if (c == '\\') { - if (quote != 0 && (*command == '_' || *command == '\\')) { - // DO nothing - } else { - esc = true; - continue; - } - } - if (quote == c) { quote = 0; - } else if (quote == 0 && (c == '\'' || c == '"')) { + } else if (quote == 0 && (c == '\'' || c == '"' || c == '`')) { quote = c; - } - - *p++ = c; - if (c == ';' && quote == 0) { - c = *p; - *p = 0; + } else if (c == ';' && quote == 0) { + c = *command; + *command = 0; if (shellRunSingleCommand(con, cmd) < 0) { return -1; } - *p = c; - p = cmd; + *command = c; + cmd = command; } } - - *p = 0; return shellRunSingleCommand(con, cmd); } @@ -574,19 +538,23 @@ static void shellPrintNChar(const char *str, int length, int width) { while (pos < length) { TdWchar wc; int bytes = taosMbToWchar(&wc, str + pos, MB_CUR_MAX); - if (bytes == 0) { + if (bytes <= 0) { break; } - pos += bytes; - if (pos > length) { + if (pos + bytes > length) { break; } - + int w = 0; #ifdef WINDOWS - int w = bytes; + w = bytes; #else - int w = taosWcharWidth(wc); + if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){ + w = bytes; + }else{ + w = taosWcharWidth(wc); + } #endif + pos += bytes; if (w <= 0) { continue; } @@ -680,6 +648,7 @@ static void printField(const char *val, TAOS_FIELD *field, int width, int32_t le break; case TSDB_DATA_TYPE_BINARY: case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_JSON: shellPrintNChar(val, length, width); break; case TSDB_DATA_TYPE_TIMESTAMP: @@ -792,7 +761,8 @@ static int calcColWidth(TAOS_FIELD *field, int precision) { return TMAX(field->bytes, width); } - case TSDB_DATA_TYPE_NCHAR: { + case TSDB_DATA_TYPE_NCHAR: + case TSDB_DATA_TYPE_JSON:{ int16_t bytes = field->bytes * TSDB_NCHAR_SIZE; if (bytes > tsMaxBinaryDisplayWidth) { return TMAX(tsMaxBinaryDisplayWidth, width);