Merge branch 'develop' into feature/fangstatic

This commit is contained in:
fang 2019-12-11 13:51:19 +08:00
commit e0c005c71b
65 changed files with 575 additions and 572 deletions

View File

@ -67,7 +67,7 @@ typedef struct SJoinSubquerySupporter {
} SJoinSubquerySupporter; } SJoinSubquerySupporter;
void tscDestroyDataBlock(STableDataBlocks* pDataBlock); void tscDestroyDataBlock(STableDataBlocks* pDataBlock);
STableDataBlocks* tscCreateDataBlock(int32_t size); STableDataBlocks* tscCreateDataBlock(size_t initialBufSize, int32_t rowSize, int32_t startOffset, const char* name);
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks); void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks);
SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes, SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes,
uint32_t offset); uint32_t offset);
@ -78,9 +78,7 @@ int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDa
void tscFreeUnusedDataBlocks(SDataBlockList* pList); void tscFreeUnusedDataBlocks(SDataBlockList* pList);
int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList); int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SDataBlockList* pDataList);
STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size, STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
int32_t startOffset, int32_t rowSize, char* tableId); int32_t startOffset, int32_t rowSize, const char* tableId);
STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name);
SVnodeSidList* tscGetVnodeSidList(SMetricMeta* pMetricmeta, int32_t vnodeIdx); SVnodeSidList* tscGetVnodeSidList(SMetricMeta* pMetricmeta, int32_t vnodeIdx);
SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx); SMeterSidExtInfo* tscGetMeterSidInfo(SVnodeSidList* pSidList, int32_t idx);

View File

@ -231,17 +231,22 @@ typedef struct SParamInfo {
typedef struct STableDataBlocks { typedef struct STableDataBlocks {
char meterId[TSDB_METER_ID_LEN]; char meterId[TSDB_METER_ID_LEN];
int8_t tsSource; int8_t tsSource; // where does the UNIX timestamp come from, server or client
bool ordered; bool ordered; // if current rows are ordered or not
int64_t vgid; // virtual group id
int64_t prevTS; // previous timestamp, recorded to decide if the records array is ts ascending
int32_t numOfMeters; // number of tables in current submit block
int64_t vgid; int32_t rowSize; // row size for current table
int64_t prevTS;
int32_t numOfMeters;
int32_t rowSize;
uint32_t nAllocSize; uint32_t nAllocSize;
uint32_t size; uint32_t size;
/*
* the metermeta for current table, the metermeta will be used during submit stage, keep a ref
* to avoid it to be removed from cache
*/
SMeterMeta* pMeterMeta;
union { union {
char *filename; char *filename;
char *pData; char *pData;
@ -255,8 +260,8 @@ typedef struct STableDataBlocks {
typedef struct SDataBlockList { typedef struct SDataBlockList {
int32_t idx; int32_t idx;
int32_t nSize; uint32_t nSize;
int32_t nAlloc; uint32_t nAlloc;
char * userParam; /* user assigned parameters for async query */ char * userParam; /* user assigned parameters for async query */
void * udfp; /* user defined function pointer, used in async model */ void * udfp; /* user defined function pointer, used in async model */
STableDataBlocks **pData; STableDataBlocks **pData;
@ -274,7 +279,7 @@ typedef struct {
int8_t isInsertFromFile; // load data from file or not int8_t isInsertFromFile; // load data from file or not
bool import; // import/insert type bool import; // import/insert type
char msgType; uint8_t msgType;
uint16_t type; // query type uint16_t type; // query type
char intervalTimeUnit; char intervalTimeUnit;
int64_t etime, stime; int64_t etime, stime;
@ -378,14 +383,14 @@ typedef struct _sql_obj {
char * sqlstr; char * sqlstr;
char retry; char retry;
char maxRetry; char maxRetry;
char index; uint8_t index;
char freed : 4; char freed : 4;
char listed : 4; char listed : 4;
tsem_t rspSem; tsem_t rspSem;
tsem_t emptyRspSem; tsem_t emptyRspSem;
SSqlCmd cmd; SSqlCmd cmd;
SSqlRes res; SSqlRes res;
char numOfSubs; uint8_t numOfSubs;
struct _sql_obj **pSubs; struct _sql_obj **pSubs;
struct _sql_obj * prev, *next; struct _sql_obj * prev, *next;
} SSqlObj; } SSqlObj;

View File

@ -643,13 +643,12 @@ int32_t intersect(tQueryResultset *pLeft, tQueryResultset *pRight, tQueryResults
} }
/* /*
* * traverse the result and apply the function to each item to check if the item is qualified or not
*/ */
void tSQLListTraverseOnResult(struct tSQLBinaryExpr *pExpr, bool (*fp)(tSkipListNode *, void *), static void tSQLListTraverseOnResult(struct tSQLBinaryExpr *pExpr, __result_filter_fn_t fp, tQueryResultset *pResult) {
tQueryResultset * pResult) {
assert(pExpr->pLeft->nodeType == TSQL_NODE_COL && pExpr->pRight->nodeType == TSQL_NODE_VALUE); assert(pExpr->pLeft->nodeType == TSQL_NODE_COL && pExpr->pRight->nodeType == TSQL_NODE_VALUE);
// brutal force search // brutal force scan the result list and check for each item in the list
int64_t num = pResult->num; int64_t num = pResult->num;
for (int32_t i = 0, j = 0; i < pResult->num; ++i) { for (int32_t i = 0, j = 0; i < pResult->num; ++i) {
if (fp == NULL || (fp(pResult->pRes[i], pExpr->info) == true)) { if (fp == NULL || (fp(pResult->pRes[i], pExpr->info) == true)) {

View File

@ -13,8 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tast.h" #include "tast.h"
@ -71,7 +69,8 @@ for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
} \ } \
} while(0); } while(0);
void noop(SQLFunctionCtx *UNUSED_PARAM(pCtx)) {} void noop1(SQLFunctionCtx *UNUSED_PARAM(pCtx)) {}
void noop2(SQLFunctionCtx *UNUSED_PARAM(pCtx), int32_t UNUSED_PARAM(index)) {}
typedef struct tValuePair { typedef struct tValuePair {
tVariant v; tVariant v;
@ -509,10 +508,10 @@ static void do_sum(SQLFunctionCtx *pCtx) {
assert(pCtx->size >= pCtx->preAggVals.numOfNull); assert(pCtx->size >= pCtx->preAggVals.numOfNull);
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) { if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
int64_t *retVal = pCtx->aOutputBuf; int64_t *retVal = (int64_t*) pCtx->aOutputBuf;
*retVal += pCtx->preAggVals.sum; *retVal += pCtx->preAggVals.sum;
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE || pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
double *retVal = pCtx->aOutputBuf; double *retVal = (double*) pCtx->aOutputBuf;
*retVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.sum)); *retVal += GET_DOUBLE_VAL(&(pCtx->preAggVals.sum));
} }
} else { // computing based on the true data block } else { // computing based on the true data block
@ -520,7 +519,7 @@ static void do_sum(SQLFunctionCtx *pCtx) {
notNullElems = 0; notNullElems = 0;
if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) { if (pCtx->inputType >= TSDB_DATA_TYPE_TINYINT && pCtx->inputType <= TSDB_DATA_TYPE_BIGINT) {
int64_t *retVal = pCtx->aOutputBuf; int64_t *retVal = (int64_t*) pCtx->aOutputBuf;
if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) { if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) {
LIST_ADD_N(*retVal, pCtx, pData, int8_t, notNullElems, pCtx->inputType); LIST_ADD_N(*retVal, pCtx, pData, int8_t, notNullElems, pCtx->inputType);
@ -532,10 +531,10 @@ static void do_sum(SQLFunctionCtx *pCtx) {
LIST_ADD_N(*retVal, pCtx, pData, int64_t, notNullElems, pCtx->inputType); LIST_ADD_N(*retVal, pCtx, pData, int64_t, notNullElems, pCtx->inputType);
} }
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
double *retVal = pCtx->aOutputBuf; double *retVal = (double*) pCtx->aOutputBuf;
LIST_ADD_N(*retVal, pCtx, pData, double, notNullElems, pCtx->inputType); LIST_ADD_N(*retVal, pCtx, pData, double, notNullElems, pCtx->inputType);
} else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
double *retVal = pCtx->aOutputBuf; double *retVal = (double*) pCtx->aOutputBuf;
LIST_ADD_N(*retVal, pCtx, pData, float, notNullElems, pCtx->inputType); LIST_ADD_N(*retVal, pCtx, pData, float, notNullElems, pCtx->inputType);
} }
} }
@ -555,7 +554,7 @@ static void do_sum_f(SQLFunctionCtx *pCtx, int32_t index) {
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
int64_t *res = pCtx->aOutputBuf; int64_t *res = (int64_t*) pCtx->aOutputBuf;
if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) { if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) {
*res += GET_INT8_VAL(pData); *res += GET_INT8_VAL(pData);
@ -566,10 +565,10 @@ static void do_sum_f(SQLFunctionCtx *pCtx, int32_t index) {
} else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) {
*res += GET_INT64_VAL(pData); *res += GET_INT64_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
double *retVal = pCtx->aOutputBuf; double *retVal = (double*) pCtx->aOutputBuf;
*retVal += GET_DOUBLE_VAL(pData); *retVal += GET_DOUBLE_VAL(pData);
} else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
double *retVal = pCtx->aOutputBuf; double *retVal = (double*) pCtx->aOutputBuf;
*retVal += GET_FLOAT_VAL(pData); *retVal += GET_FLOAT_VAL(pData);
} }
@ -696,7 +695,7 @@ static int32_t first_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
SFirstLastInfo *pInfo = (pCtx->aOutputBuf + pCtx->inputBytes); SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { // data in current block is not earlier than current result } else { // data in current block is not earlier than current result
@ -710,7 +709,7 @@ static int32_t last_dist_data_req_info(SQLFunctionCtx *pCtx, TSKEY start, TSKEY
return BLK_DATA_NO_NEEDED; return BLK_DATA_NO_NEEDED;
} }
SFirstLastInfo *pInfo = (pCtx->aOutputBuf + pCtx->inputBytes); SFirstLastInfo *pInfo = (SFirstLastInfo*) (pCtx->aOutputBuf + pCtx->inputBytes);
if (pInfo->hasResult != DATA_SET_FLAG) { if (pInfo->hasResult != DATA_SET_FLAG) {
return BLK_DATA_ALL_NEEDED; return BLK_DATA_ALL_NEEDED;
} else { } else {
@ -844,7 +843,7 @@ static void avg_func_merge(SQLFunctionCtx *pCtx) {
static void avg_func_second_merge(SQLFunctionCtx *pCtx) { static void avg_func_second_merge(SQLFunctionCtx *pCtx) {
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
double *sum = pCtx->aOutputBuf; double *sum = (double*) pCtx->aOutputBuf;
char * input = GET_INPUT_CHAR(pCtx); char * input = GET_INPUT_CHAR(pCtx);
for (int32_t i = 0; i < pCtx->size; ++i, input += pCtx->inputBytes) { for (int32_t i = 0; i < pCtx->size; ++i, input += pCtx->inputBytes) {
@ -969,10 +968,10 @@ static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin,
TYPED_LOOPCHECK_N(int16_t, pOutput, p, pCtx, pCtx->inputType, isMin, *notNullElems); TYPED_LOOPCHECK_N(int16_t, pOutput, p, pCtx, pCtx->inputType, isMin, *notNullElems);
} else if (pCtx->inputType == TSDB_DATA_TYPE_INT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_INT) {
int32_t *pData = p; int32_t *pData = p;
int32_t *retVal = pOutput; int32_t *retVal = (int32_t*) pOutput;
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*)&pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -1217,27 +1216,27 @@ static void minMax_function_f(SQLFunctionCtx *pCtx, int32_t index, int32_t isMin
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
} else if (pCtx->inputType == TSDB_DATA_TYPE_SMALLINT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_SMALLINT) {
int16_t *output = pCtx->aOutputBuf; int16_t *output = (int16_t*) pCtx->aOutputBuf;
int16_t i = GET_INT16_VAL(pData); int16_t i = GET_INT16_VAL(pData);
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
} else if (pCtx->inputType == TSDB_DATA_TYPE_INT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_INT) {
int32_t *output = pCtx->aOutputBuf; int32_t *output = (int32_t*) pCtx->aOutputBuf;
int32_t i = GET_INT32_VAL(pData); int32_t i = GET_INT32_VAL(pData);
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
} else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) {
int64_t *output = pCtx->aOutputBuf; int64_t *output = (int64_t*) pCtx->aOutputBuf;
int64_t i = GET_INT64_VAL(pData); int64_t i = GET_INT64_VAL(pData);
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
} else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) { } else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
float *output = pCtx->aOutputBuf; float *output = (float*) pCtx->aOutputBuf;
float i = GET_FLOAT_VAL(pData); float i = GET_FLOAT_VAL(pData);
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { } else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
double *output = pCtx->aOutputBuf; double *output = (double*) pCtx->aOutputBuf;
double i = GET_DOUBLE_VAL(pData); double i = GET_DOUBLE_VAL(pData);
UPDATE_DATA(pCtx, *output, i, num, isMin, key); UPDATE_DATA(pCtx, *output, i, num, isMin, key);
@ -1301,7 +1300,7 @@ static void stddev_function(SQLFunctionCtx *pCtx) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
if (pCtx->hasNull && isNull(&((int32_t *)pData)[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) (&((int32_t *)pData)[i]), pCtx->inputType)) {
continue; continue;
} }
*retVal += POW2(((int32_t *)pData)[i] - avg); *retVal += POW2(((int32_t *)pData)[i] - avg);
@ -1585,7 +1584,7 @@ static void first_dist_func_second_merge(SQLFunctionCtx *pCtx) {
assert(pCtx->resultInfo->superTableQ); assert(pCtx->resultInfo->superTableQ);
char * pData = GET_INPUT_CHAR(pCtx); char * pData = GET_INPUT_CHAR(pCtx);
SFirstLastInfo *pInput = (pData + pCtx->outputBytes); SFirstLastInfo *pInput = (SFirstLastInfo*) (pData + pCtx->outputBytes);
if (pInput->hasResult != DATA_SET_FLAG) { if (pInput->hasResult != DATA_SET_FLAG) {
return; return;
} }
@ -1668,7 +1667,7 @@ static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t ind
if (pInfo->hasResult != DATA_SET_FLAG || pInfo->ts < timestamp[index]) { if (pInfo->hasResult != DATA_SET_FLAG || pInfo->ts < timestamp[index]) {
#if defined(_DEBUG_VIEW) #if defined(_DEBUG_VIEW)
pTrace("assign index:%d, ts:%lld, val:%d, ", index, timestamp[index], *(int32_t *)pData); pTrace("assign index:%d, ts:%" PRId64 ", val:%d, ", index, timestamp[index], *(int32_t *)pData);
#endif #endif
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes); memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
@ -1763,7 +1762,7 @@ static void last_dist_func_merge(SQLFunctionCtx *pCtx) {
static void last_dist_func_second_merge(SQLFunctionCtx *pCtx) { static void last_dist_func_second_merge(SQLFunctionCtx *pCtx) {
char *pData = GET_INPUT_CHAR(pCtx); char *pData = GET_INPUT_CHAR(pCtx);
SFirstLastInfo *pInput = (pData + pCtx->outputBytes); SFirstLastInfo *pInput = (SFirstLastInfo*) (pData + pCtx->outputBytes);
if (pInput->hasResult != DATA_SET_FLAG) { if (pInput->hasResult != DATA_SET_FLAG) {
return; return;
} }
@ -1871,7 +1870,7 @@ static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData,
val.i64Key >= pList[pInfo->num - 1]->v.i64Key) || val.i64Key >= pList[pInfo->num - 1]->v.i64Key) ||
((type >= TSDB_DATA_TYPE_FLOAT && type <= TSDB_DATA_TYPE_DOUBLE) && ((type >= TSDB_DATA_TYPE_FLOAT && type <= TSDB_DATA_TYPE_DOUBLE) &&
val.dKey >= pList[pInfo->num - 1]->v.dKey)) { val.dKey >= pList[pInfo->num - 1]->v.dKey)) {
valuePairAssign(pList[pInfo->num], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[pInfo->num], type, (const char*)&val.i64Key, ts, pTags, pTagInfo, stage);
} else { } else {
int32_t i = pInfo->num - 1; int32_t i = pInfo->num - 1;
@ -1887,7 +1886,7 @@ static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData,
} }
} }
valuePairAssign(pList[i + 1], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[i + 1], type, (const char*) &val.i64Key, ts, pTags, pTagInfo, stage);
} }
pInfo->num++; pInfo->num++;
@ -1909,7 +1908,7 @@ static void do_top_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pData,
} }
} }
valuePairAssign(pList[i], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[i], type, (const char*) &val.i64Key, ts, pTags, pTagInfo, stage);
} }
} }
} }
@ -1923,7 +1922,7 @@ static void do_bottom_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pDa
if (pInfo->num < maxLen) { if (pInfo->num < maxLen) {
if (pInfo->num == 0) { if (pInfo->num == 0) {
valuePairAssign(pList[pInfo->num], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[pInfo->num], type, (const char*) &val.i64Key, ts, pTags, pTagInfo, stage);
} else { } else {
int32_t i = pInfo->num - 1; int32_t i = pInfo->num - 1;
@ -1939,7 +1938,7 @@ static void do_bottom_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pDa
} }
} }
valuePairAssign(pList[i + 1], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[i + 1], type, (const char*)&val.i64Key, ts, pTags, pTagInfo, stage);
} }
pInfo->num++; pInfo->num++;
@ -1961,7 +1960,7 @@ static void do_bottom_function_add(STopBotInfo *pInfo, int32_t maxLen, void *pDa
} }
} }
valuePairAssign(pList[i], type, &val.i64Key, ts, pTags, pTagInfo, stage); valuePairAssign(pList[i], type, (const char*)&val.i64Key, ts, pTags, pTagInfo, stage);
} }
} }
} }
@ -2101,7 +2100,7 @@ bool top_bot_datablock_filter(SQLFunctionCtx *pCtx, int32_t functionId, char *mi
return true; return true;
} }
tValuePair *pRes = pTopBotInfo->res; tValuePair *pRes = (tValuePair*) pTopBotInfo->res;
if (functionId == TSDB_FUNC_TOP) { if (functionId == TSDB_FUNC_TOP) {
switch (pCtx->inputType) { switch (pCtx->inputType) {
@ -2153,7 +2152,7 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) {
// only the first_stage_merge is directly written data into final output buffer // only the first_stage_merge is directly written data into final output buffer
if (pResInfo->superTableQ && pCtx->currentStage != SECONDARY_STAGE_MERGE) { if (pResInfo->superTableQ && pCtx->currentStage != SECONDARY_STAGE_MERGE) {
return pCtx->aOutputBuf; return (STopBotInfo*) pCtx->aOutputBuf;
} else { // for normal table query and super table at the secondary_stage, result is written to intermediate buffer } else { // for normal table query and super table at the secondary_stage, result is written to intermediate buffer
return pResInfo->interResultBuf; return pResInfo->interResultBuf;
} }
@ -2167,14 +2166,14 @@ static STopBotInfo *getTopBotOutputInfo(SQLFunctionCtx *pCtx) {
*/ */
static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) { static void buildTopBotStruct(STopBotInfo *pTopBotInfo, SQLFunctionCtx *pCtx) {
char *tmp = (char *)pTopBotInfo + sizeof(STopBotInfo); char *tmp = (char *)pTopBotInfo + sizeof(STopBotInfo);
pTopBotInfo->res = tmp; pTopBotInfo->res = (tValuePair**) tmp;
tmp += POINTER_BYTES * pCtx->param[0].i64Key; tmp += POINTER_BYTES * pCtx->param[0].i64Key;
size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen; size_t size = sizeof(tValuePair) + pCtx->tagInfo.tagsLen;
for (int32_t i = 0; i < pCtx->param[0].i64Key; ++i) { for (int32_t i = 0; i < pCtx->param[0].i64Key; ++i) {
pTopBotInfo->res[i] = tmp; pTopBotInfo->res[i] = (tValuePair*) tmp;
pTopBotInfo->res[i]->pTags = tmp + sizeof(tValuePair); pTopBotInfo->res[i]->pTags = tmp + sizeof(tValuePair);
tmp += size; tmp += size;
} }
@ -2479,7 +2478,7 @@ static SAPercentileInfo *getAPerctInfo(SQLFunctionCtx *pCtx) {
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->superTableQ && pCtx->currentStage != SECONDARY_STAGE_MERGE) { if (pResInfo->superTableQ && pCtx->currentStage != SECONDARY_STAGE_MERGE) {
return pCtx->aOutputBuf; return (SAPercentileInfo*) pCtx->aOutputBuf;
} else { } else {
return pResInfo->interResultBuf; return pResInfo->interResultBuf;
} }
@ -2590,8 +2589,8 @@ static void apercentile_func_merge(SQLFunctionCtx *pCtx) {
SAPercentileInfo *pInput = (SAPercentileInfo *)GET_INPUT_CHAR(pCtx); SAPercentileInfo *pInput = (SAPercentileInfo *)GET_INPUT_CHAR(pCtx);
pInput->pHisto = (char *)pInput + sizeof(SAPercentileInfo); pInput->pHisto = (SHistogramInfo*) ((char *)pInput + sizeof(SAPercentileInfo));
pInput->pHisto->elems = (char *)pInput->pHisto + sizeof(SHistogramInfo); pInput->pHisto->elems = (SHistBin*) ((char *)pInput->pHisto + sizeof(SHistogramInfo));
if (pInput->pHisto->numOfElems <= 0) { if (pInput->pHisto->numOfElems <= 0) {
return; return;
@ -2604,13 +2603,13 @@ static void apercentile_func_merge(SQLFunctionCtx *pCtx) {
if (pHisto->numOfElems <= 0) { if (pHisto->numOfElems <= 0) {
memcpy(pHisto, pInput->pHisto, size); memcpy(pHisto, pInput->pHisto, size);
pHisto->elems = (char *)pHisto + sizeof(SHistogramInfo); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo));
} else { } else {
pHisto->elems = (char *)pHisto + sizeof(SHistogramInfo); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo));
SHistogramInfo *pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN); SHistogramInfo *pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN);
memcpy(pHisto, pRes, sizeof(SHistogramInfo) + sizeof(SHistBin) * MAX_HISTOGRAM_BIN); memcpy(pHisto, pRes, sizeof(SHistogramInfo) + sizeof(SHistBin) * MAX_HISTOGRAM_BIN);
pHisto->elems = (char *)pHisto + sizeof(SHistogramInfo); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo));
tHistogramDestroy(&pRes); tHistogramDestroy(&pRes);
} }
@ -2622,8 +2621,8 @@ static void apercentile_func_merge(SQLFunctionCtx *pCtx) {
static void apercentile_func_second_merge(SQLFunctionCtx *pCtx) { static void apercentile_func_second_merge(SQLFunctionCtx *pCtx) {
SAPercentileInfo *pInput = (SAPercentileInfo *)GET_INPUT_CHAR(pCtx); SAPercentileInfo *pInput = (SAPercentileInfo *)GET_INPUT_CHAR(pCtx);
pInput->pHisto = (char *)pInput + sizeof(SAPercentileInfo); pInput->pHisto = (SHistogramInfo*) ((char *)pInput + sizeof(SAPercentileInfo));
pInput->pHisto->elems = (char *)pInput->pHisto + sizeof(SHistogramInfo); pInput->pHisto->elems = (SHistBin*) ((char *)pInput->pHisto + sizeof(SHistogramInfo));
if (pInput->pHisto->numOfElems <= 0) { if (pInput->pHisto->numOfElems <= 0) {
return; return;
@ -2634,9 +2633,9 @@ static void apercentile_func_second_merge(SQLFunctionCtx *pCtx) {
if (pHisto->numOfElems <= 0) { if (pHisto->numOfElems <= 0) {
memcpy(pHisto, pInput->pHisto, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1)); memcpy(pHisto, pInput->pHisto, sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1));
pHisto->elems = (char *)pHisto + sizeof(SHistogramInfo); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo));
} else { } else {
pHisto->elems = (char *)pHisto + sizeof(SHistogramInfo); pHisto->elems = (SHistBin*) ((char *)pHisto + sizeof(SHistogramInfo));
SHistogramInfo *pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN); SHistogramInfo *pRes = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN);
tHistogramDestroy(&pOutput->pHisto); tHistogramDestroy(&pOutput->pHisto);
@ -2730,7 +2729,7 @@ static void leastsquares_function(SQLFunctionCtx *pCtx) {
int32_t *p = pData; int32_t *p = pData;
// LEASTSQR_CAL_LOOP(pCtx, param, pParamData, p); // LEASTSQR_CAL_LOOP(pCtx, param, pParamData, p);
for (int32_t i = 0; i < pCtx->size; ++i) { for (int32_t i = 0; i < pCtx->size; ++i) {
if (pCtx->hasNull && isNull(p, pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) p, pCtx->inputType)) {
continue; continue;
} }
@ -2872,6 +2871,10 @@ static void date_col_output_function(SQLFunctionCtx *pCtx) {
*(int64_t *)(pCtx->aOutputBuf) = pCtx->nStartQueryTimestamp; *(int64_t *)(pCtx->aOutputBuf) = pCtx->nStartQueryTimestamp;
} }
static FORCE_INLINE void date_col_output_function_f(SQLFunctionCtx *pCtx, int32_t index) {
date_col_output_function(pCtx);
}
static void col_project_function(SQLFunctionCtx *pCtx) { static void col_project_function(SQLFunctionCtx *pCtx) {
INC_INIT_VAL(pCtx, pCtx->size); INC_INIT_VAL(pCtx, pCtx->size);
@ -2982,7 +2985,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int32_t *pOutput = (int32_t *)pCtx->aOutputBuf; int32_t *pOutput = (int32_t *)pCtx->aOutputBuf;
for (; i < pCtx->size && i >= 0; i += step) { for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -3014,7 +3017,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int64_t *pOutput = (int64_t *)pCtx->aOutputBuf; int64_t *pOutput = (int64_t *)pCtx->aOutputBuf;
for (; i < pCtx->size && i >= 0; i += step) { for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -3046,7 +3049,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
double *pOutput = (double *)pCtx->aOutputBuf; double *pOutput = (double *)pCtx->aOutputBuf;
for (; i < pCtx->size && i >= 0; i += step) { for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -3076,7 +3079,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
float *pOutput = (float *)pCtx->aOutputBuf; float *pOutput = (float *)pCtx->aOutputBuf;
for (; i < pCtx->size && i >= 0; i += step) { for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -3107,7 +3110,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
int16_t *pOutput = (int16_t *)pCtx->aOutputBuf; int16_t *pOutput = (int16_t *)pCtx->aOutputBuf;
for (; i < pCtx->size && i >= 0; i += step) { for (; i < pCtx->size && i >= 0; i += step) {
if (pCtx->hasNull && isNull(&pData[i], pCtx->inputType)) { if (pCtx->hasNull && isNull((const char*) &pData[i], pCtx->inputType)) {
continue; continue;
} }
@ -3277,7 +3280,7 @@ static void arithmetic_function(SQLFunctionCtx *pCtx) {
pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size * GET_FORWARD_DIRECTION_FACTOR(pCtx->order); pCtx->aOutputBuf += pCtx->outputBytes * pCtx->size * GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
} }
static bool arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
INC_INIT_VAL(pCtx, 1); INC_INIT_VAL(pCtx, 1);
SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[0].pz; SArithmeticSupport *sas = (SArithmeticSupport *)pCtx->param[0].pz;
@ -3286,7 +3289,6 @@ static bool arithmetic_function_f(SQLFunctionCtx *pCtx, int32_t index) {
arithmetic_callback_function); arithmetic_callback_function);
pCtx->aOutputBuf += pCtx->outputBytes * GET_FORWARD_DIRECTION_FACTOR(pCtx->order); pCtx->aOutputBuf += pCtx->outputBytes * GET_FORWARD_DIRECTION_FACTOR(pCtx->order);
return true;
} }
#define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \ #define LIST_MINMAX_N(ctx, minOutput, maxOutput, elemCnt, data, type, tsdbType, numOfNotNullElem) \
@ -3709,7 +3711,7 @@ static void getStatics_i16(int64_t *primaryKey, int16_t *data, int32_t numOfRow,
// int16_t lastVal = TSDB_DATA_SMALLINT_NULL; // int16_t lastVal = TSDB_DATA_SMALLINT_NULL;
for (int32_t i = 0; i < numOfRow; ++i) { for (int32_t i = 0; i < numOfRow; ++i) {
if (isNull(&data[i], TSDB_DATA_TYPE_SMALLINT)) { if (isNull((const char*) &data[i], TSDB_DATA_TYPE_SMALLINT)) {
(*numOfNull) += 1; (*numOfNull) += 1;
continue; continue;
} }
@ -3749,7 +3751,7 @@ static void getStatics_i32(int64_t *primaryKey, int32_t *data, int32_t numOfRow,
// int32_t lastVal = TSDB_DATA_INT_NULL; // int32_t lastVal = TSDB_DATA_INT_NULL;
for (int32_t i = 0; i < numOfRow; ++i) { for (int32_t i = 0; i < numOfRow; ++i) {
if (isNull(&data[i], TSDB_DATA_TYPE_INT)) { if (isNull((const char*) &data[i], TSDB_DATA_TYPE_INT)) {
(*numOfNull) += 1; (*numOfNull) += 1;
continue; continue;
} }
@ -3786,7 +3788,7 @@ static void getStatics_i64(int64_t *primaryKey, int64_t *data, int32_t numOfRow,
assert(numOfRow <= INT16_MAX); assert(numOfRow <= INT16_MAX);
for (int32_t i = 0; i < numOfRow; ++i) { for (int32_t i = 0; i < numOfRow; ++i) {
if (isNull(&data[i], TSDB_DATA_TYPE_BIGINT)) { if (isNull((const char*) &data[i], TSDB_DATA_TYPE_BIGINT)) {
(*numOfNull) += 1; (*numOfNull) += 1;
continue; continue;
} }
@ -3824,7 +3826,7 @@ static void getStatics_f(int64_t *primaryKey, float *data, int32_t numOfRow, dou
assert(numOfRow <= INT16_MAX); assert(numOfRow <= INT16_MAX);
for (int32_t i = 0; i < numOfRow; ++i) { for (int32_t i = 0; i < numOfRow; ++i) {
if (isNull(&data[i], TSDB_DATA_TYPE_FLOAT)) { if (isNull((const char*) &data[i], TSDB_DATA_TYPE_FLOAT)) {
(*numOfNull) += 1; (*numOfNull) += 1;
continue; continue;
} }
@ -3877,7 +3879,7 @@ static void getStatics_d(int64_t *primaryKey, double *data, int32_t numOfRow, do
assert(numOfRow <= INT16_MAX); assert(numOfRow <= INT16_MAX);
for (int32_t i = 0; i < numOfRow; ++i) { for (int32_t i = 0; i < numOfRow; ++i) {
if (isNull(&data[i], TSDB_DATA_TYPE_DOUBLE)) { if (isNull((const char*) &data[i], TSDB_DATA_TYPE_DOUBLE)) {
(*numOfNull) += 1; (*numOfNull) += 1;
continue; continue;
} }
@ -3938,9 +3940,9 @@ void getStatistics(char *priData, char *data, int32_t size, int32_t numOfRow, in
} else if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP) { } else if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP) {
getStatics_i64(primaryKey, (int64_t *)data, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull); getStatics_i64(primaryKey, (int64_t *)data, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull);
} else if (type == TSDB_DATA_TYPE_DOUBLE) { } else if (type == TSDB_DATA_TYPE_DOUBLE) {
getStatics_d(primaryKey, (double *)data, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull); getStatics_d(primaryKey, (double *)data, numOfRow, (double*) min, (double*) max, (double*) sum, minIndex, maxIndex, numOfNull);
} else if (type == TSDB_DATA_TYPE_FLOAT) { } else if (type == TSDB_DATA_TYPE_FLOAT) {
getStatics_f(primaryKey, (float *)data, numOfRow, min, max, sum, minIndex, maxIndex, numOfNull); getStatics_f(primaryKey, (float *)data, numOfRow, (double*) min, (double*) max, (double*) sum, minIndex, maxIndex, numOfNull);
} }
} }
} }
@ -4058,44 +4060,42 @@ static void twa_function(SQLFunctionCtx *pCtx) {
// pCtx->numOfIteratedElems += notNullElems; // pCtx->numOfIteratedElems += notNullElems;
} }
static bool twa_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void twa_function_f(SQLFunctionCtx *pCtx, int32_t index) {
void *pData = GET_INPUT_CHAR_INDEX(pCtx, index); void *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { if (pCtx->hasNull && isNull(pData, pCtx->inputType)) {
return true; return;
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
TSKEY *primaryKey = pCtx->ptsList; TSKEY *primaryKey = pCtx->ptsList;
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
STwaInfo * pInfo = pResInfo->interResultBuf; STwaInfo *pInfo = pResInfo->interResultBuf;
if (pInfo->lastKey == INT64_MIN) { if (pInfo->lastKey == INT64_MIN) {
pInfo->lastKey = pCtx->nStartQueryTimestamp; pInfo->lastKey = pCtx->nStartQueryTimestamp;
setTWALastVal(pCtx, pData, 0, pInfo); setTWALastVal(pCtx, pData, 0, pInfo);
pInfo->hasResult = DATA_SET_FLAG; pInfo->hasResult = DATA_SET_FLAG;
} }
if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT || pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) { if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT || pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
pInfo->dOutput += pInfo->dLastValue * (primaryKey[index] - pInfo->lastKey); pInfo->dOutput += pInfo->dLastValue * (primaryKey[index] - pInfo->lastKey);
} else { } else {
pInfo->iOutput += pInfo->iLastValue * (primaryKey[index] - pInfo->lastKey); pInfo->iOutput += pInfo->iLastValue * (primaryKey[index] - pInfo->lastKey);
} }
// record the last key/value // record the last key/value
pInfo->lastKey = primaryKey[index]; pInfo->lastKey = primaryKey[index];
setTWALastVal(pCtx, pData, 0, pInfo); setTWALastVal(pCtx, pData, 0, pInfo);
// pCtx->numOfIteratedElems += 1; // pCtx->numOfIteratedElems += 1;
pResInfo->hasResult = DATA_SET_FLAG; pResInfo->hasResult = DATA_SET_FLAG;
if (pResInfo->superTableQ) { if (pResInfo->superTableQ) {
memcpy(pCtx->aOutputBuf, pResInfo->interResultBuf, sizeof(STwaInfo)); memcpy(pCtx->aOutputBuf, pResInfo->interResultBuf, sizeof(STwaInfo));
} }
return true;
} }
static void twa_func_merge(SQLFunctionCtx *pCtx) { static void twa_func_merge(SQLFunctionCtx *pCtx) {
@ -4107,7 +4107,7 @@ static void twa_func_merge(SQLFunctionCtx *pCtx) {
int32_t numOfNotNull = 0; int32_t numOfNotNull = 0;
for (int32_t i = 0; i < pCtx->size; ++i, indicator += sizeof(STwaInfo)) { for (int32_t i = 0; i < pCtx->size; ++i, indicator += sizeof(STwaInfo)) {
STwaInfo *pInput = indicator; STwaInfo *pInput = (STwaInfo*) indicator;
if (pInput->hasResult != DATA_SET_FLAG) { if (pInput->hasResult != DATA_SET_FLAG) {
continue; continue;
@ -4209,7 +4209,7 @@ static void interp_function(SQLFunctionCtx *pCtx) {
if (pCtx->outputType == TSDB_DATA_TYPE_FLOAT) { if (pCtx->outputType == TSDB_DATA_TYPE_FLOAT) {
float v = GET_DOUBLE_VAL(pVal); float v = GET_DOUBLE_VAL(pVal);
assignVal(pCtx->aOutputBuf, &v, pCtx->outputBytes, pCtx->outputType); assignVal(pCtx->aOutputBuf, (const char*) &v, pCtx->outputBytes, pCtx->outputType);
} else { } else {
assignVal(pCtx->aOutputBuf, pVal, pCtx->outputBytes, pCtx->outputType); assignVal(pCtx->aOutputBuf, pVal, pCtx->outputBytes, pCtx->outputType);
} }
@ -4370,7 +4370,7 @@ SQLAggFuncElem aAggs[28] = {{
count_function, count_function,
count_function_f, count_function_f,
no_next_step, no_next_step,
noop, noop1,
count_func_merge, count_func_merge,
count_func_merge, count_func_merge,
count_load_data_info, count_load_data_info,
@ -4446,8 +4446,8 @@ SQLAggFuncElem aAggs[28] = {{
stddev_function_f, stddev_function_f,
stddev_next_step, stddev_next_step,
stddev_finalizer, stddev_finalizer,
noop, noop1,
noop, noop1,
data_req_load_info, data_req_load_info,
}, },
{ {
@ -4461,8 +4461,8 @@ SQLAggFuncElem aAggs[28] = {{
percentile_function_f, percentile_function_f,
no_next_step, no_next_step,
percentile_finalizer, percentile_finalizer,
noop, noop1,
noop, noop1,
data_req_load_info, data_req_load_info,
}, },
{ {
@ -4491,8 +4491,8 @@ SQLAggFuncElem aAggs[28] = {{
first_function_f, first_function_f,
no_next_step, no_next_step,
function_finalizer, function_finalizer,
noop, noop1,
noop, noop1,
first_data_req_info, first_data_req_info,
}, },
{ {
@ -4506,8 +4506,8 @@ SQLAggFuncElem aAggs[28] = {{
last_function_f, last_function_f,
no_next_step, no_next_step,
function_finalizer, function_finalizer,
noop, noop1,
noop, noop1,
last_data_req_info, last_data_req_info,
}, },
{ {
@ -4519,10 +4519,10 @@ SQLAggFuncElem aAggs[28] = {{
TSDB_FUNCSTATE_SELECTIVITY, TSDB_FUNCSTATE_SELECTIVITY,
first_last_function_setup, first_last_function_setup,
last_row_function, last_row_function,
noop, noop2,
no_next_step, no_next_step,
last_row_finalizer, last_row_finalizer,
noop, noop1,
last_dist_func_second_merge, last_dist_func_second_merge,
data_req_load_info, data_req_load_info,
}, },
@ -4599,8 +4599,8 @@ SQLAggFuncElem aAggs[28] = {{
leastsquares_function_f, leastsquares_function_f,
no_next_step, no_next_step,
leastsquares_finalizer, leastsquares_finalizer,
noop, noop1,
noop, noop1,
data_req_load_info, data_req_load_info,
}, },
{ {
@ -4611,9 +4611,9 @@ SQLAggFuncElem aAggs[28] = {{
TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS,
function_setup, function_setup,
date_col_output_function, date_col_output_function,
date_col_output_function, date_col_output_function_f,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
@ -4625,10 +4625,10 @@ SQLAggFuncElem aAggs[28] = {{
TSDB_FUNC_TS_DUMMY, TSDB_FUNC_TS_DUMMY,
TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS,
function_setup, function_setup,
noop, noop1,
noop, noop2,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
@ -4641,9 +4641,9 @@ SQLAggFuncElem aAggs[28] = {{
TSDB_BASE_FUNC_SO, TSDB_BASE_FUNC_SO,
function_setup, function_setup,
tag_function, tag_function,
noop, noop2,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
@ -4673,7 +4673,7 @@ SQLAggFuncElem aAggs[28] = {{
tag_function, tag_function,
tag_function_f, tag_function_f,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
@ -4688,7 +4688,7 @@ SQLAggFuncElem aAggs[28] = {{
col_project_function, col_project_function,
col_project_function_f, col_project_function_f,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
@ -4703,7 +4703,7 @@ SQLAggFuncElem aAggs[28] = {{
tag_project_function, tag_project_function,
tag_project_function_f, tag_project_function_f,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
no_data_info, no_data_info,
@ -4718,7 +4718,7 @@ SQLAggFuncElem aAggs[28] = {{
arithmetic_function, arithmetic_function,
arithmetic_function_f, arithmetic_function_f,
no_next_step, no_next_step,
noop, noop1,
copy_function, copy_function,
copy_function, copy_function,
data_req_load_info, data_req_load_info,
@ -4733,9 +4733,9 @@ SQLAggFuncElem aAggs[28] = {{
diff_function, diff_function,
diff_function_f, diff_function_f,
no_next_step, no_next_step,
noop, noop1,
noop, noop1,
noop, noop1,
data_req_load_info, data_req_load_info,
}, },
// distributed version used in two-stage aggregation processes // distributed version used in two-stage aggregation processes
@ -4779,8 +4779,8 @@ SQLAggFuncElem aAggs[28] = {{
interp_function, interp_function,
do_sum_f, // todo filter handle do_sum_f, // todo filter handle
no_next_step, no_next_step,
noop, noop1,
noop, noop1,
copy_function, copy_function,
no_data_info, no_data_info,
}}; }};

View File

@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "tscJoinProcess.h"
#include "os.h" #include "os.h"
#include "tscJoinProcess.h"
#include "tcache.h" #include "tcache.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tsclient.h" #include "tsclient.h"
@ -88,7 +88,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
#ifdef _DEBUG_VIEW #ifdef _DEBUG_VIEW
// for debug purpose // for debug purpose
tscPrint("%lld, tags:%d \t %lld, tags:%d", elem1.ts, elem1.tag, elem2.ts, elem2.tag); tscPrint("%" PRId64 ", tags:%d \t %" PRId64 ", tags:%d", elem1.ts, elem1.tag, elem2.ts, elem2.tag);
#endif #endif
if (elem1.tag < elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem1.ts, elem2.ts))) { if (elem1.tag < elem2.tag || (elem1.tag == elem2.tag && doCompare(order, elem1.ts, elem2.ts))) {
@ -150,7 +150,7 @@ static int64_t doTSBlockIntersect(SSqlObj* pSql, SJoinSubquerySupporter* pSuppor
tsBufDestory(pSupporter1->pTSBuf); tsBufDestory(pSupporter1->pTSBuf);
tsBufDestory(pSupporter2->pTSBuf); tsBufDestory(pSupporter2->pTSBuf);
tscTrace("%p input1:%lld, input2:%lld, final:%lld for secondary query after ts blocks intersecting", pSql, tscTrace("%p input1:%" PRId64 ", input2:%" PRId64 ", final:%" PRId64 " for secondary query after ts blocks intersecting", pSql,
numOfInput1, numOfInput2, output1->numOfTotal); numOfInput1, numOfInput2, output1->numOfTotal);
return output1->numOfTotal; return output1->numOfTotal;
@ -528,8 +528,8 @@ void tscFetchDatablockFromSubquery(SSqlObj* pSql) {
numOfFetch++; numOfFetch++;
} }
} else { } else {
if ((pRes->row >= pRes->numOfRows && (!tscHasReachLimitation(pSql->pSubs[i])) && tscProjectionQueryOnTable(pSql)) if ((pRes->row >= pRes->numOfRows && (!tscHasReachLimitation(pSql->pSubs[i])) &&
|| (pRes->numOfRows == 0)) { tscProjectionQueryOnTable(&pSql->cmd)) || (pRes->numOfRows == 0)) {
numOfFetch++; numOfFetch++;
} }
} }
@ -1619,7 +1619,7 @@ void tsBufDisplay(STSBuf* pTSBuf) {
while (tsBufNextPos(pTSBuf)) { while (tsBufNextPos(pTSBuf)) {
STSElem elem = tsBufGetElem(pTSBuf); STSElem elem = tsBufGetElem(pTSBuf);
printf("%d-%lld-%lld\n", elem.vnode, elem.tag, elem.ts); printf("%d-%" PRId64 "-%" PRId64 "\n", elem.vnode, *(int64_t*) elem.tag, elem.ts);
} }
pTSBuf->cur.order = old; pTSBuf->cur.order = old;

View File

@ -64,7 +64,7 @@ static int32_t getToStringLength(const char *pData, int32_t length, int32_t type
} break; } break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
len = sprintf(buf, "%lld", *(int64_t *)pData); len = sprintf(buf, "%" PRId64 "", *(int64_t *)pData);
break; break;
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
len = MAX_BOOL_TYPE_LENGTH; len = MAX_BOOL_TYPE_LENGTH;
@ -228,7 +228,7 @@ static int32_t tscSetValueToResObj(SSqlObj *pSql, int32_t rowLen) {
sprintf(target, "%d", *(int32_t *)pTagValue); sprintf(target, "%d", *(int32_t *)pTagValue);
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
sprintf(target, "%lld", *(int64_t *)pTagValue); sprintf(target, "%" PRId64 "", *(int64_t *)pTagValue);
break; break;
case TSDB_DATA_TYPE_BOOL: { case TSDB_DATA_TYPE_BOOL: {
char *val = (*((int8_t *)pTagValue) == 0) ? "false" : "true"; char *val = (*((int8_t *)pTagValue) == 0) ? "false" : "true";

View File

@ -18,9 +18,6 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#pragma GCC diagnostic ignored "-Woverflow"
#pragma GCC diagnostic ignored "-Wunused-variable"
#include "os.h" #include "os.h"
#include "ihash.h" #include "ihash.h"
#include "tscSecondaryMerge.h" #include "tscSecondaryMerge.h"
@ -985,7 +982,7 @@ int doParserInsertSql(SSqlObj *pSql, char *str) {
strcpy(fname, full_path.we_wordv[0]); strcpy(fname, full_path.we_wordv[0]);
wordfree(&full_path); wordfree(&full_path);
STableDataBlocks *pDataBlock = tscCreateDataBlockEx(PATH_MAX, pMeterMetaInfo->pMeterMeta->rowSize, STableDataBlocks *pDataBlock = tscCreateDataBlock(PATH_MAX, pMeterMetaInfo->pMeterMeta->rowSize,
sizeof(SShellSubmitBlock), pMeterMetaInfo->name); sizeof(SShellSubmitBlock), pMeterMetaInfo->name);
tscAppendDataBlock(pCmd->pDataBlocks, pDataBlock); tscAppendDataBlock(pCmd->pDataBlocks, pDataBlock);
@ -1222,8 +1219,8 @@ static int tscInsertDataFromFile(SSqlObj *pSql, FILE *fp, char *tmpTokenBuf) {
int32_t rowSize = pMeterMeta->rowSize; int32_t rowSize = pMeterMeta->rowSize;
pCmd->pDataBlocks = tscCreateBlockArrayList(); pCmd->pDataBlocks = tscCreateBlockArrayList();
STableDataBlocks *pTableDataBlock = STableDataBlocks *pTableDataBlock = tscCreateDataBlock(TSDB_PAYLOAD_SIZE, pMeterMeta->rowSize,
tscCreateDataBlockEx(TSDB_PAYLOAD_SIZE, pMeterMeta->rowSize, sizeof(SShellSubmitBlock), pMeterMetaInfo->name); sizeof(SShellSubmitBlock), pMeterMetaInfo->name);
tscAppendDataBlock(pCmd->pDataBlocks, pTableDataBlock); tscAppendDataBlock(pCmd->pDataBlocks, pTableDataBlock);

View File

@ -93,10 +93,10 @@ void tscSaveSlowQuery(SSqlObj *pSql) {
const static int64_t SLOW_QUERY_INTERVAL = 3000000L; const static int64_t SLOW_QUERY_INTERVAL = 3000000L;
if (pSql->res.useconds < SLOW_QUERY_INTERVAL) return; if (pSql->res.useconds < SLOW_QUERY_INTERVAL) return;
tscTrace("%p query time:%lld sql:%s", pSql, pSql->res.useconds, pSql->sqlstr); tscTrace("%p query time:%" PRId64 " sql:%s", pSql, pSql->res.useconds, pSql->sqlstr);
char *sql = malloc(200); char *sql = malloc(200);
int len = snprintf(sql, 200, "insert into %s.slowquery values(now, '%s', %lld, %lld, '", tsMonitorDbName, int len = snprintf(sql, 200, "insert into %s.slowquery values(now, '%s', %" PRId64 ", %" PRId64 ", '", tsMonitorDbName,
pSql->pTscObj->user, pSql->stime, pSql->res.useconds); pSql->pTscObj->user, pSql->stime, pSql->res.useconds);
int sqlLen = snprintf(sql + len, TSDB_SHOW_SQL_LEN, "%s", pSql->sqlstr); int sqlLen = snprintf(sql + len, TSDB_SHOW_SQL_LEN, "%s", pSql->sqlstr);
if (sqlLen > TSDB_SHOW_SQL_LEN - 1) { if (sqlLen > TSDB_SHOW_SQL_LEN - 1) {

View File

@ -20,15 +20,13 @@
#include "taos.h" #include "taos.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tstoken.h" #include "tstoken.h"
#include "ttime.h"
#include "tstrbuild.h" #include "tstrbuild.h"
#include "ttime.h"
#include "tscSQLParser.h"
#include "tscUtil.h" #include "tscUtil.h"
#include "tschemautil.h" #include "tschemautil.h"
#include "tsclient.h" #include "tsclient.h"
#include "tscSQLParser.h"
#pragma GCC diagnostic ignored "-Wunused-variable"
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
@ -53,7 +51,7 @@ typedef struct SColumnIdListRes {
static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t outputIndex, int32_t colIdx, int32_t tableIndex); static SSqlExpr* doAddProjectCol(SSqlCmd* pCmd, int32_t outputIndex, int32_t colIdx, int32_t tableIndex);
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static char* getAccountId(SSqlObj* pSql); static char* getAccountId(SSqlObj* pSql);
static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name); static bool has(tFieldList* pFieldList, int32_t startIdx, const char* name);
static void getCurrentDBName(SSqlObj* pSql, SSQLToken* pDBToken); static void getCurrentDBName(SSqlObj* pSql, SSQLToken* pDBToken);
@ -112,7 +110,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString);
static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex); static int32_t getMeterIndex(SSQLToken* pTableToken, SSqlCmd* pCmd, SColumnIndex* pIndex);
static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql); static int32_t doFunctionsCompatibleCheck(SSqlObj* pSql);
static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd); static int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd);
static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate); static int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate);
static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex); static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t columnIndex);
@ -120,7 +118,7 @@ static SColumnList getColumnList(int32_t num, int16_t tableIndex, int32_t column
* Used during parsing query sql. Since the query sql usually small in length, error position * Used during parsing query sql. Since the query sql usually small in length, error position
* is not needed in the final error message. * is not needed in the final error message.
*/ */
static int32_t invalidSqlErrMsg(SSqlCmd *pCmd, const char* errMsg) { static int32_t invalidSqlErrMsg(SSqlCmd* pCmd, const char* errMsg) {
return tscInvalidSQLErrMsg(pCmd->payload, errMsg, NULL); return tscInvalidSQLErrMsg(pCmd->payload, errMsg, NULL);
} }
@ -257,7 +255,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
if (pToken->n > TSDB_DB_NAME_LEN) { if (pToken->n > TSDB_DB_NAME_LEN) {
const char* msg = "db name too long"; const char* msg = "db name too long";
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
@ -288,14 +286,13 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
case SHOW_STREAMS: case SHOW_STREAMS:
case SHOW_SCORES: case SHOW_SCORES:
case SHOW_GRANTS: case SHOW_GRANTS:
case SHOW_CONFIGS: case SHOW_CONFIGS:
case SHOW_VNODES: { case SHOW_VNODES: {
return setShowInfo(pSql, pInfo); return setShowInfo(pSql, pInfo);
} }
case ALTER_DATABASE: case ALTER_DATABASE:
case CREATE_DATABASE: { case CREATE_DATABASE: {
if (pInfo->sqlType == ALTER_DATABASE) { if (pInfo->sqlType == ALTER_DATABASE) {
pCmd->command = TSDB_SQL_ALTER_DB; pCmd->command = TSDB_SQL_ALTER_DB;
} else { } else {
@ -311,7 +308,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL); int32_t ret = setObjFullName(pMeterMetaInfo->name, getAccountId(pSql), &(pCreateDB->dbname), NULL, NULL);
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
const char* msg2 = "name too long"; const char* msg2 = "name too long";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
@ -363,12 +360,12 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) { if (pInfo->pDCLInfo->a[0].n > TSDB_USER_LEN || pInfo->pDCLInfo->a[1].n > TSDB_PASSWORD_LEN) {
const char* msg = "name or password too long"; const char* msg = "name or password too long";
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) { if (tscValidateName(&pInfo->pDCLInfo->a[0]) != TSDB_CODE_SUCCESS) {
const char* msg2 = "invalid user/account name"; const char* msg2 = "invalid user/account name";
return invalidSqlErrMsg(pCmd, msg2); return invalidSqlErrMsg(pCmd, msg2);
} }
strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name strncpy(pMeterMetaInfo->name, pInfo->pDCLInfo->a[0].z, pInfo->pDCLInfo->a[0].n); // name
@ -402,7 +399,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
pCmd->defaultVal[8] = 0; pCmd->defaultVal[8] = 0;
} else { } else {
const char* msg4 = "invalid state option, available options[no, r, w, all]"; const char* msg4 = "invalid state option, available options[no, r, w, all]";
return invalidSqlErrMsg(pCmd, msg4); return invalidSqlErrMsg(pCmd, msg4);
} }
} }
} }
@ -838,7 +835,7 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
const char* msg7 = "illegal number of tables in from clause"; const char* msg7 = "illegal number of tables in from clause";
const char* msg8 = "too many columns in selection clause"; const char* msg8 = "too many columns in selection clause";
const char* msg9 = "TWA query requires both the start and end time"; const char* msg9 = "TWA query requires both the start and end time";
int32_t code = TSDB_CODE_SUCCESS; int32_t code = TSDB_CODE_SUCCESS;
// too many result columns not support order by in query // too many result columns not support order by in query
@ -1019,8 +1016,8 @@ int32_t tscToSQLCmd(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
setColumnOffsetValueInResultset(pCmd); setColumnOffsetValueInResultset(pCmd);
for(int32_t i = 0; i < pCmd->numOfTables; ++i) { for (int32_t i = 0; i < pCmd->numOfTables; ++i) {
updateTagColumnIndex(pCmd, i); updateTagColumnIndex(pCmd, i);
} }
@ -1798,7 +1795,7 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, tSQLExprItem* pItem) {
} }
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_METER_NAME_LEN}; SSchema colSchema = {.type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_METER_NAME_LEN};
strcpy(colSchema.name, TSQL_TBNAME_L); strcpy(colSchema.name, TSQL_TBNAME_L);
pCmd->type = TSDB_QUERY_TYPE_STABLE_QUERY; pCmd->type = TSDB_QUERY_TYPE_STABLE_QUERY;
@ -2162,8 +2159,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
int8_t resultType = pSchema[index.columnIndex].type; int8_t resultType = pSchema[index.columnIndex].type;
int16_t resultSize = pSchema[index.columnIndex].bytes; int16_t resultSize = pSchema[index.columnIndex].bytes;
char val[8] = {0}; char val[8] = {0};
int32_t numOfAddedColumn = 1; int32_t numOfAddedColumn = 1;
if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) { if (optr == TK_PERCENTILE || optr == TK_APERCENTILE) {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE); tVariantDump(pVariant, val, TSDB_DATA_TYPE_DOUBLE);
@ -2188,7 +2185,6 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, int32_t colIdx, tSQLExprItem* pItem
SSqlExpr* pExpr = tscSqlExprInsert(pCmd, colIdx, functionId, &index, resultType, resultSize, resultSize); SSqlExpr* pExpr = tscSqlExprInsert(pCmd, colIdx, functionId, &index, resultType, resultSize, resultSize);
addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0); addExprParams(pExpr, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double), 0);
} else { } else {
tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT); tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT);
int64_t nTop = *((int32_t*)val); int64_t nTop = *((int32_t*)val);
@ -2547,7 +2543,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) {
} }
} }
} }
}else if (type == SHOW_VNODES) { } else if (type == SHOW_VNODES) {
if (NULL == pInfo->pDCLInfo) { if (NULL == pInfo->pDCLInfo) {
return invalidSqlErrMsg(pCmd, "No specified ip of dnode"); return invalidSqlErrMsg(pCmd, "No specified ip of dnode");
} }
@ -2676,8 +2672,7 @@ void tscRestoreSQLFunctionForMetricQuery(SSqlCmd* pCmd) {
bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) { bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
const char* msg1 = "TWA not allowed to apply to super table directly"; const char* msg1 = "TWA not allowed to apply to super table directly";
const char* msg2 = "functions not supported for super table"; const char* msg2 = "TWA only support group by tbname for super table query";
const char* msg3 = "TWA only support group by tbname for super table query";
// filter sql function not supported by metric query yet. // filter sql function not supported by metric query yet.
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
@ -2694,7 +2689,7 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
} }
if (pCmd->groupbyExpr.numOfGroupCols != 1 || pCmd->groupbyExpr.columnInfo[0].colIdx != TSDB_TBNAME_COLUMN_INDEX) { if (pCmd->groupbyExpr.numOfGroupCols != 1 || pCmd->groupbyExpr.columnInfo[0].colIdx != TSDB_TBNAME_COLUMN_INDEX) {
invalidSqlErrMsg(pCmd, msg3); invalidSqlErrMsg(pCmd, msg2);
return true; return true;
} }
} }
@ -2703,8 +2698,6 @@ bool hasUnsupportFunctionsForMetricQuery(SSqlCmd* pCmd) {
} }
static bool functionCompatibleCheck(SSqlCmd* pCmd) { static bool functionCompatibleCheck(SSqlCmd* pCmd) {
const char* msg1 = "column on select clause not allowed";
int32_t startIdx = 0; int32_t startIdx = 0;
int32_t functionID = tscSqlExprGet(pCmd, startIdx)->functionId; int32_t functionID = tscSqlExprGet(pCmd, startIdx)->functionId;
@ -2747,7 +2740,7 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
if (pCmd->groupbyExpr.numOfGroupCols > 0 && pCmd->groupbyExpr.tableIndex == tableIndex) { if (pCmd->groupbyExpr.numOfGroupCols > 0 && pCmd->groupbyExpr.tableIndex == tableIndex) {
for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) { for (int32_t i = 0; i < pCmd->groupbyExpr.numOfGroupCols; ++i) {
int32_t index = pCmd->groupbyExpr.columnInfo[i].colIdx; int32_t index = pCmd->groupbyExpr.columnInfo[i].colIdx;
for (int32_t j = 0; j < pMeterMetaInfo->numOfTags; ++j) { for (int32_t j = 0; j < pMeterMetaInfo->numOfTags; ++j) {
int32_t tagColIndex = pMeterMetaInfo->tagColumnIndex[j]; int32_t tagColIndex = pMeterMetaInfo->tagColumnIndex[j];
if (tagColIndex == index) { if (tagColIndex == index) {
@ -2761,11 +2754,11 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
// update tags column index for expression // update tags column index for expression
for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue if (!TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { // not tags, continue
continue; continue;
} }
// not belongs to this table // not belongs to this table
if (pExpr->uid != pMeterMetaInfo->pMeterMeta->uid) { if (pExpr->uid != pMeterMetaInfo->pMeterMeta->uid) {
continue; continue;
@ -2778,40 +2771,37 @@ void updateTagColumnIndex(SSqlCmd* pCmd, int32_t tableIndex) {
} }
} }
} }
// update join condition tag column index // update join condition tag column index
SJoinInfo* pJoinInfo = &pCmd->tagCond.joinInfo; SJoinInfo* pJoinInfo = &pCmd->tagCond.joinInfo;
if (!pJoinInfo->hasJoin) { // not join query if (!pJoinInfo->hasJoin) { // not join query
return; return;
} }
assert(pJoinInfo->left.uid != pJoinInfo->right.uid); assert(pJoinInfo->left.uid != pJoinInfo->right.uid);
// the join condition expression node belongs to this table(super table) // the join condition expression node belongs to this table(super table)
if (pMeterMetaInfo->pMeterMeta->uid == pJoinInfo->left.uid) { if (pMeterMetaInfo->pMeterMeta->uid == pJoinInfo->left.uid) {
for(int32_t i = 0; i < pMeterMetaInfo->numOfTags; ++i) { for (int32_t i = 0; i < pMeterMetaInfo->numOfTags; ++i) {
if (pJoinInfo->left.tagCol == pMeterMetaInfo->tagColumnIndex[i]) { if (pJoinInfo->left.tagCol == pMeterMetaInfo->tagColumnIndex[i]) {
pJoinInfo->left.tagCol = i; pJoinInfo->left.tagCol = i;
} }
} }
} }
if (pMeterMetaInfo->pMeterMeta->uid == pJoinInfo->right.uid) { if (pMeterMetaInfo->pMeterMeta->uid == pJoinInfo->right.uid) {
for(int32_t i = 0; i < pMeterMetaInfo->numOfTags; ++i) { for (int32_t i = 0; i < pMeterMetaInfo->numOfTags; ++i) {
if (pJoinInfo->right.tagCol == pMeterMetaInfo->tagColumnIndex[i]) { if (pJoinInfo->right.tagCol == pMeterMetaInfo->tagColumnIndex[i]) {
pJoinInfo->right.tagCol = i; pJoinInfo->right.tagCol = i;
} }
} }
} }
} }
int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) { int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
const char* msg1 = "too many columns in group by clause"; const char* msg1 = "too many columns in group by clause";
const char* msg2 = "invalid column name in group by clause"; const char* msg2 = "invalid column name in group by clause";
const char* msg4 = "group by only available for STable query"; const char* msg3 = "group by columns must belong to one table";
const char* msg5 = "group by columns must belong to one table";
const char* msg6 = "only support group by one ordinary column";
const char* msg7 = "not support group by expression"; const char* msg7 = "not support group by expression";
const char* msg8 = "not allowed column type for group by"; const char* msg8 = "not allowed column type for group by";
const char* msg9 = "tags not allowed for table query"; const char* msg9 = "tags not allowed for table query";
@ -2830,9 +2820,8 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
SMeterMeta* pMeterMeta = NULL; SMeterMeta* pMeterMeta = NULL;
SSchema* pSchema = NULL; SSchema* pSchema = NULL;
SSchema s = tsGetTbnameColumnSchema();
SSchema s = {0};
int32_t numOfReqTags = 0;
int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL; int32_t tableIndex = COLUMN_INDEX_INITIAL_VAL;
for (int32_t i = 0; i < pList->nExpr; ++i) { for (int32_t i = 0; i < pList->nExpr; ++i) {
@ -2846,7 +2835,7 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
} }
if (tableIndex != index.tableIndex && tableIndex >= 0) { if (tableIndex != index.tableIndex && tableIndex >= 0) {
return invalidSqlErrMsg(pCmd, msg5); return invalidSqlErrMsg(pCmd, msg3);
} }
tableIndex = index.tableIndex; tableIndex = index.tableIndex;
@ -2854,22 +2843,12 @@ int32_t parseGroupbyClause(SSqlCmd* pCmd, tVariantList* pList) {
pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex);
pMeterMeta = pMeterMetaInfo->pMeterMeta; pMeterMeta = pMeterMetaInfo->pMeterMeta;
// TODO refactor!!!!!!!!!!!!!!1
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
s.colId = TSDB_TBNAME_COLUMN_INDEX;
s.type = TSDB_DATA_TYPE_BINARY;
s.bytes = TSDB_METER_NAME_LEN;
strcpy(s.name, TSQL_TBNAME_L);
pSchema = &s; pSchema = &s;
} else { } else {
pSchema = tsGetColumnSchema(pMeterMeta, index.columnIndex); pSchema = tsGetColumnSchema(pMeterMeta, index.columnIndex);
} }
int16_t type = 0;
int16_t bytes = 0;
char* name = NULL;
bool groupTag = false; bool groupTag = false;
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || index.columnIndex >= pMeterMeta->numOfColumns) { if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || index.columnIndex >= pMeterMeta->numOfColumns) {
groupTag = true; groupTag = true;
@ -3140,7 +3119,7 @@ static int32_t optrToString(tSQLExpr* pExpr, char** exprString) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tablenameListToString(tSQLExpr* pExpr, /*char* str*/SStringBuilder* sb) { static int32_t tablenameListToString(tSQLExpr* pExpr, /*char* str*/ SStringBuilder* sb) {
tSQLExprList* pList = pExpr->pParam; tSQLExprList* pList = pExpr->pParam;
if (pList->nExpr <= 0) { if (pList->nExpr <= 0) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
@ -3150,7 +3129,6 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, /*char* str*/SStringBuilde
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN); taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_IN, QUERY_COND_REL_PREFIX_IN_LEN);
} }
int32_t len = 0;
for (int32_t i = 0; i < pList->nExpr; ++i) { for (int32_t i = 0; i < pList->nExpr; ++i) {
tSQLExpr* pSub = pList->a[i].pNode; tSQLExpr* pSub = pList->a[i].pNode;
taosStringBuilderAppendStringLen(sb, pSub->val.pz, pSub->val.nLen); taosStringBuilderAppendStringLen(sb, pSub->val.pz, pSub->val.nLen);
@ -3167,7 +3145,7 @@ static int32_t tablenameListToString(tSQLExpr* pExpr, /*char* str*/SStringBuilde
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t tablenameCondToString(tSQLExpr* pExpr, /*char* str*/SStringBuilder* sb) { static int32_t tablenameCondToString(tSQLExpr* pExpr, /*char* str*/ SStringBuilder* sb) {
taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN); taosStringBuilderAppendStringLen(sb, QUERY_COND_REL_PREFIX_LIKE, QUERY_COND_REL_PREFIX_LIKE_LEN);
taosStringBuilderAppendString(sb, pExpr->val.pz); taosStringBuilderAppendString(sb, pExpr->val.pz);
@ -3189,7 +3167,6 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SColumnIndex* pIndex, tSQL
const char* msg1 = "non binary column not support like operator"; const char* msg1 = "non binary column not support like operator";
const char* msg2 = "binary column not support this operator"; const char* msg2 = "binary column not support this operator";
const char* msg3 = "OR is not supported on different column filter";
SColumnBase* pColumn = tscColumnBaseInfoInsert(pCmd, pIndex); SColumnBase* pColumn = tscColumnBaseInfoInsert(pCmd, pIndex);
SColumnFilterInfo* pColFilter = NULL; SColumnFilterInfo* pColFilter = NULL;
@ -3273,7 +3250,7 @@ static int32_t getTagCondString(SSqlCmd* pCmd, tSQLExpr* pExpr, char** str) {
return tSQLExprLeafToString(pExpr, true, str); return tSQLExprLeafToString(pExpr, true, str);
} }
static int32_t getTablenameCond(SSqlCmd* pCmd, tSQLExpr* pTableCond, /*char* str*/SStringBuilder* sb) { static int32_t getTablenameCond(SSqlCmd* pCmd, tSQLExpr* pTableCond, /*char* str*/ SStringBuilder* sb) {
const char* msg0 = "invalid table name list"; const char* msg0 = "invalid table name list";
if (pTableCond == NULL) { if (pTableCond == NULL) {
@ -3617,10 +3594,9 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
const char* msg2 = "illegal column name"; const char* msg2 = "illegal column name";
const char* msg3 = "only one query time range allowed"; const char* msg3 = "only one query time range allowed";
const char* msg4 = "only one join condition allowed"; const char* msg4 = "only one join condition allowed";
const char* msg5 = "AND is allowed to filter on different ordinary columns"; const char* msg5 = "not support ordinary column join";
const char* msg6 = "not support ordinary column join"; const char* msg6 = "only one query condition on tbname allowed";
const char* msg7 = "only one query condition on tbname allowed"; const char* msg7 = "only in/like allowed in filter table name";
const char* msg8 = "only in/like allowed in filter table name";
tSQLExpr* pLeft = (*pExpr)->pLeft; tSQLExpr* pLeft = (*pExpr)->pLeft;
tSQLExpr* pRight = (*pExpr)->pRight; tSQLExpr* pRight = (*pExpr)->pRight;
@ -3682,7 +3658,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
// in case of in operator, keep it in a seperate attribute // in case of in operator, keep it in a seperate attribute
if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) {
if (!validTableNameOptr(*pExpr)) { if (!validTableNameOptr(*pExpr)) {
return invalidSqlErrMsg(pCmd, msg8); return invalidSqlErrMsg(pCmd, msg7);
} }
if (pCondExpr->pTableCond == NULL) { if (pCondExpr->pTableCond == NULL) {
@ -3690,7 +3666,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
pCondExpr->relType = parentOptr; pCondExpr->relType = parentOptr;
pCondExpr->tableCondIndex = index.tableIndex; pCondExpr->tableCondIndex = index.tableIndex;
} else { } else {
return invalidSqlErrMsg(pCmd, msg7); return invalidSqlErrMsg(pCmd, msg6);
} }
*type = TSQL_EXPR_TBNAME; *type = TSQL_EXPR_TBNAME;
@ -3721,7 +3697,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, tSQLExpr** pExpr, SCondExpr*
*type = TSQL_EXPR_COLUMN; *type = TSQL_EXPR_COLUMN;
if (pRight->nSQLOptr == TK_ID) { // other column cannot be served as the join column if (pRight->nSQLOptr == TK_ID) { // other column cannot be served as the join column
return invalidSqlErrMsg(pCmd, msg6); return invalidSqlErrMsg(pCmd, msg5);
} }
ret = setExprToCond(pCmd, &pCondExpr->pColumnCond, *pExpr, NULL, parentOptr); ret = setExprToCond(pCmd, &pCondExpr->pColumnCond, *pExpr, NULL, parentOptr);
@ -3888,9 +3864,9 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
// remove the duplicated input table names // remove the duplicated input table names
int32_t num = 0; int32_t num = 0;
char* tableNameString = taosStringBuilderGetResult(sb, NULL); char* tableNameString = taosStringBuilderGetResult(sb, NULL);
char** segments = strsplit(tableNameString + QUERY_COND_REL_PREFIX_IN_LEN, TBNAME_LIST_SEP, &num); char** segments = strsplit(tableNameString + QUERY_COND_REL_PREFIX_IN_LEN, TBNAME_LIST_SEP, &num);
qsort(segments, num, POINTER_BYTES, tableNameCompar); qsort(segments, num, POINTER_BYTES, tableNameCompar);
int32_t j = 1; int32_t j = 1;
@ -3908,8 +3884,8 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
if (i >= 1) { if (i >= 1) {
taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1); taosStringBuilderAppendStringLen(&sb1, TBNAME_LIST_SEP, 1);
} }
char idBuf[TSDB_METER_ID_LEN + 1] = {0}; char idBuf[TSDB_METER_ID_LEN + 1] = {0};
int32_t xlen = strlen(segments[i]); int32_t xlen = strlen(segments[i]);
SSQLToken t = {.z = segments[i], .n = xlen, .type = TK_STRING}; SSQLToken t = {.z = segments[i], .n = xlen, .type = TK_STRING};
@ -3917,17 +3893,17 @@ static int32_t setTableCondForMetricQuery(SSqlObj* pSql, tSQLExpr* pExpr, int16_
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
taosStringBuilderDestroy(&sb1); taosStringBuilderDestroy(&sb1);
tfree(segments); tfree(segments);
invalidSqlErrMsg(pCmd, msg); invalidSqlErrMsg(pCmd, msg);
return ret; return ret;
} }
taosStringBuilderAppendString(&sb1, idBuf); taosStringBuilderAppendString(&sb1, idBuf);
} }
char* str = taosStringBuilderGetResult(&sb1, NULL); char* str = taosStringBuilderGetResult(&sb1, NULL);
pCmd->tagCond.tbnameCond.cond = strdup(str); pCmd->tagCond.tbnameCond.cond = strdup(str);
taosStringBuilderDestroy(&sb1); taosStringBuilderDestroy(&sb1);
tfree(segments); tfree(segments);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -4054,21 +4030,20 @@ static void cleanQueryExpr(SCondExpr* pCondExpr) {
} }
} }
static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SCondExpr* pCondExpr) { static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SCondExpr* pCondExpr) {
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
if (QUERY_IS_JOIN_QUERY(pCmd->type) && UTIL_METER_IS_METRIC(pMeterMetaInfo)) { if (QUERY_IS_JOIN_QUERY(pCmd->type) && UTIL_METER_IS_METRIC(pMeterMetaInfo)) {
SColumnIndex index = {0}; SColumnIndex index = {0};
getColumnIndexByNameEx(&pCondExpr->pJoinExpr->pLeft->colInfo, pCmd, &index); getColumnIndexByNameEx(&pCondExpr->pJoinExpr->pLeft->colInfo, pCmd, &index);
pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex);
int32_t columnInfo = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; int32_t columnInfo = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns;
addRequiredTagColumn(pCmd, columnInfo, index.tableIndex); addRequiredTagColumn(pCmd, columnInfo, index.tableIndex);
getColumnIndexByNameEx(&pCondExpr->pJoinExpr->pRight->colInfo, pCmd, &index); getColumnIndexByNameEx(&pCondExpr->pJoinExpr->pRight->colInfo, pCmd, &index);
pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex); pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, index.tableIndex);
columnInfo = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; columnInfo = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns;
addRequiredTagColumn(pCmd, columnInfo, index.tableIndex); addRequiredTagColumn(pCmd, columnInfo, index.tableIndex);
} }
@ -4076,48 +4051,48 @@ static void doAddJoinTagsColumnsIntoTagList(SSqlCmd* pCmd, SCondExpr* pCondExpr)
static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr** pExpr) { static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SCondExpr* pCondExpr, tSQLExpr** pExpr) {
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
if (pCondExpr->pTagCond != NULL) { if (pCondExpr->pTagCond != NULL) {
for (int32_t i = 0; i < pCmd->numOfTables; ++i) { for (int32_t i = 0; i < pCmd->numOfTables; ++i) {
tSQLExpr* p1 = extractExprForSTable(pExpr, pCmd, i); tSQLExpr* p1 = extractExprForSTable(pExpr, pCmd, i);
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, i);
char c[TSDB_MAX_TAGS_LEN] = {0}; char c[TSDB_MAX_TAGS_LEN] = {0};
char* str = c; char* str = c;
if ((ret = getTagCondString(pCmd, p1, &str)) != TSDB_CODE_SUCCESS) { if ((ret = getTagCondString(pCmd, p1, &str)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
tsSetMetricQueryCond(&pCmd->tagCond, pMeterMetaInfo->pMeterMeta->uid, c); tsSetMetricQueryCond(&pCmd->tagCond, pMeterMetaInfo->pMeterMeta->uid, c);
doCompactQueryExpr(pExpr); doCompactQueryExpr(pExpr);
tSQLExprDestroy(p1); tSQLExprDestroy(p1);
} }
pCondExpr->pTagCond = NULL; pCondExpr->pTagCond = NULL;
} }
return ret; return ret;
} }
int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) { int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) {
if (pExpr == NULL) { if (pExpr == NULL) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
const char* msg = "invalid filter expression"; const char* msg = "invalid filter expression";
const char* msg1 = "invalid expression"; const char* msg1 = "invalid expression";
int32_t ret = TSDB_CODE_SUCCESS; int32_t ret = TSDB_CODE_SUCCESS;
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
pCmd->stime = 0; pCmd->stime = 0;
pCmd->etime = INT64_MAX; pCmd->etime = INT64_MAX;
//tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space // tags query condition may be larger than 512bytes, therefore, we need to prepare enough large space
SStringBuilder sb = {0}; SStringBuilder sb = {0};
SCondExpr condExpr = {0}; SCondExpr condExpr = {0};
if ((*pExpr)->pLeft == NULL || (*pExpr)->pRight == NULL) { if ((*pExpr)->pLeft == NULL || (*pExpr)->pRight == NULL) {
return invalidSqlErrMsg(pCmd, msg1); return invalidSqlErrMsg(pCmd, msg1);
@ -4127,54 +4102,54 @@ int32_t parseWhereClause(SSqlObj* pSql, tSQLExpr** pExpr) {
if ((ret = getQueryCondExpr(pCmd, pExpr, &condExpr, &type, (*pExpr)->nSQLOptr)) != TSDB_CODE_SUCCESS) { if ((ret = getQueryCondExpr(pCmd, pExpr, &condExpr, &type, (*pExpr)->nSQLOptr)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
doCompactQueryExpr(pExpr); doCompactQueryExpr(pExpr);
// after expression compact, the expression tree is only include tag query condition // after expression compact, the expression tree is only include tag query condition
condExpr.pTagCond = (*pExpr); condExpr.pTagCond = (*pExpr);
// 1. check if it is a join query // 1. check if it is a join query
if ((ret = validateJoinExpr(pCmd, &condExpr)) != TSDB_CODE_SUCCESS) { if ((ret = validateJoinExpr(pCmd, &condExpr)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 2. get the query time range // 2. get the query time range
if ((ret = getTimeRangeFromExpr(pCmd, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { if ((ret = getTimeRangeFromExpr(pCmd, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 3. get the tag query condition // 3. get the tag query condition
if ((ret = getTagQueryCondExpr(pCmd, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { if ((ret = getTagQueryCondExpr(pCmd, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 4. get the table name query condition // 4. get the table name query condition
if ((ret = getTablenameCond(pCmd, condExpr.pTableCond, &sb)) != TSDB_CODE_SUCCESS) { if ((ret = getTablenameCond(pCmd, condExpr.pTableCond, &sb)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 5. other column query condition // 5. other column query condition
if ((ret = getColumnQueryCondInfo(pCmd, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { if ((ret = getColumnQueryCondInfo(pCmd, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 6. join condition // 6. join condition
if ((ret = getJoinCondInfo(pSql, condExpr.pJoinExpr)) != TSDB_CODE_SUCCESS) { if ((ret = getJoinCondInfo(pSql, condExpr.pJoinExpr)) != TSDB_CODE_SUCCESS) {
return ret; return ret;
} }
// 7. query condition for table name // 7. query condition for table name
pCmd->tagCond.relType = (condExpr.relType == TK_AND) ? TSDB_RELATION_AND : TSDB_RELATION_OR; pCmd->tagCond.relType = (condExpr.relType == TK_AND) ? TSDB_RELATION_AND : TSDB_RELATION_OR;
ret = setTableCondForMetricQuery(pSql, condExpr.pTableCond, condExpr.tableCondIndex, &sb); ret = setTableCondForMetricQuery(pSql, condExpr.pTableCond, condExpr.tableCondIndex, &sb);
taosStringBuilderDestroy(&sb); taosStringBuilderDestroy(&sb);
if (!validateFilterExpr(pCmd)) { if (!validateFilterExpr(pCmd)) {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
doAddJoinTagsColumnsIntoTagList(pCmd, &condExpr); doAddJoinTagsColumnsIntoTagList(pCmd, &condExpr);
cleanQueryExpr(&condExpr); cleanQueryExpr(&condExpr);
return ret; return ret;
} }
@ -4449,7 +4424,6 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQuerySQL* pQuerySql, SSchema* pSchema
bool orderByTags = false; bool orderByTags = false;
bool orderByTS = false; bool orderByTS = false;
bool orderByCol = false;
if (index.columnIndex >= pMeterMetaInfo->pMeterMeta->numOfColumns) { if (index.columnIndex >= pMeterMetaInfo->pMeterMeta->numOfColumns) {
int32_t relTagIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns; int32_t relTagIndex = index.columnIndex - pMeterMetaInfo->pMeterMeta->numOfColumns;
@ -4826,7 +4800,6 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd) {
int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) { int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd) {
bool isProjectionFunction = false; bool isProjectionFunction = false;
const char* msg1 = "column projection is not compatible with interval"; const char* msg1 = "column projection is not compatible with interval";
const char* msg2 = "interval not allowed for tag queries";
// multi-output set/ todo refactor // multi-output set/ todo refactor
for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) { for (int32_t k = 0; k < pCmd->fieldsInfo.numOfOutputCols; ++k) {
@ -5008,7 +4981,7 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
// handle the limit offset value, validate the limit // handle the limit offset value, validate the limit
pCmd->limit = pQuerySql->limit; pCmd->limit = pQuerySql->limit;
pCmd->globalLimit = pCmd->limit.limit; pCmd->globalLimit = pCmd->limit.limit;
pCmd->slimit = pQuerySql->slimit; pCmd->slimit = pQuerySql->slimit;
if (pCmd->slimit.offset < 0 || pCmd->limit.offset < 0) { if (pCmd->slimit.offset < 0 || pCmd->limit.offset < 0) {
@ -5078,11 +5051,11 @@ int32_t parseLimitClause(SSqlObj* pSql, SQuerySQL* pQuerySql) {
static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) { static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
const char* msg = "invalid number of options"; const char* msg = "invalid number of options";
pMsg->daysToKeep = htonl(-1); pMsg->daysToKeep = htonl(-1);
pMsg->daysToKeep1 = htonl(-1); pMsg->daysToKeep1 = htonl(-1);
pMsg->daysToKeep2 = htonl(-1); pMsg->daysToKeep2 = htonl(-1);
tVariantList* pKeep = pCreateDb->keep; tVariantList* pKeep = pCreateDb->keep;
if (pKeep != NULL) { if (pKeep != NULL) {
switch (pKeep->nExpr) { switch (pKeep->nExpr) {
@ -5100,36 +5073,34 @@ static int32_t setKeepOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* p
pMsg->daysToKeep2 = htonl(pKeep->a[2].pVar.i64Key); pMsg->daysToKeep2 = htonl(pKeep->a[2].pVar.i64Key);
break; break;
} }
default: { default: { return invalidSqlErrMsg(pCmd, msg); }
return invalidSqlErrMsg(pCmd, msg);
}
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t setTimePrecisionOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) { static int32_t setTimePrecisionOption(SSqlCmd* pCmd, SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDbInfo) {
const char* msg = "invalid time precision"; const char* msg = "invalid time precision";
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
SSQLToken* pToken = &pCreateDbInfo->precision; SSQLToken* pToken = &pCreateDbInfo->precision;
if (pToken->n > 0) { if (pToken->n > 0) {
pToken->n = strdequote(pToken->z); pToken->n = strdequote(pToken->z);
if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 && if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) { strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) {
// time precision for this db: million second // time precision for this db: million second
pMsg->precision = TSDB_TIME_PRECISION_MILLI; pMsg->precision = TSDB_TIME_PRECISION_MILLI;
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 && } else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) { strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) {
pMsg->precision = TSDB_TIME_PRECISION_MICRO; pMsg->precision = TSDB_TIME_PRECISION_MICRO;
} else { } else {
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -5137,7 +5108,7 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
pMsg->blocksPerMeter = htons(pCreateDb->numOfBlocksPerTable); pMsg->blocksPerMeter = htons(pCreateDb->numOfBlocksPerTable);
pMsg->compression = pCreateDb->compressionLevel; pMsg->compression = pCreateDb->compressionLevel;
pMsg->commitLog = (char) pCreateDb->commitLog; pMsg->commitLog = (char)pCreateDb->commitLog;
pMsg->commitTime = htonl(pCreateDb->commitTime); pMsg->commitTime = htonl(pCreateDb->commitTime);
pMsg->maxSessions = htonl(pCreateDb->tablesPerVnode); pMsg->maxSessions = htonl(pCreateDb->tablesPerVnode);
pMsg->cacheNumOfBlocks.fraction = pCreateDb->numOfAvgCacheBlocks; pMsg->cacheNumOfBlocks.fraction = pCreateDb->numOfAvgCacheBlocks;
@ -5150,19 +5121,19 @@ static void setCreateDBOption(SCreateDbMsg* pMsg, SCreateDBInfo* pCreateDb) {
int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) { int32_t parseCreateDBOptions(SSqlCmd* pCmd, SCreateDBInfo* pCreateDbSql) {
SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead)); SCreateDbMsg* pMsg = (SCreateDbMsg*)(pCmd->payload + tsRpcHeadSize + sizeof(SMgmtHead));
setCreateDBOption(pMsg, pCreateDbSql); setCreateDBOption(pMsg, pCreateDbSql);
if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { if (setKeepOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
if (setTimePrecisionOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) { if (setTimePrecisionOption(pCmd, pMsg, pCreateDbSql) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) { if (tscCheckCreateDbParams(pCmd, pMsg) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_INVALID_SQL; return TSDB_CODE_INVALID_SQL;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -5256,9 +5227,6 @@ static void doUpdateSqlFunctionForTagPrj(SSqlCmd* pCmd) {
} }
} }
int16_t resType = 0;
int16_t resBytes = 0;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta); SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
@ -5355,11 +5323,9 @@ static void updateTagPrjFunction(SSqlCmd* pCmd) {
*/ */
static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) { static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
const char* msg1 = "only one selectivity function allowed in presence of tags function"; const char* msg1 = "only one selectivity function allowed in presence of tags function";
const char* msg2 = "functions not allowed";
const char* msg3 = "aggregation function should not be mixed up with projection"; const char* msg3 = "aggregation function should not be mixed up with projection";
bool tagColExists = false; bool tagColExists = false;
int16_t numOfTimestamp = 0; // primary timestamp column
int16_t numOfSelectivity = 0; int16_t numOfSelectivity = 0;
int16_t numOfAggregation = 0; int16_t numOfAggregation = 0;
@ -5374,7 +5340,8 @@ static int32_t checkUpdateTagPrjFunctions(SSqlCmd* pCmd) {
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
int16_t functionId = tscSqlExprGet(pCmd, i)->functionId; int16_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS) { if (functionId == TSDB_FUNC_TAGPRJ || functionId == TSDB_FUNC_PRJ || functionId == TSDB_FUNC_TS ||
functionId == TSDB_FUNC_ARITHM) {
continue; continue;
} }
@ -5501,13 +5468,10 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd) {
int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) { int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
const char* msg1 = "functions/columns not allowed in group by query"; const char* msg1 = "functions/columns not allowed in group by query";
const char* msg2 = "interval not allowed in group by normal column";
const char* msg3 = "group by not allowed on projection query"; const char* msg3 = "group by not allowed on projection query";
const char* msg4 = "tags retrieve not compatible with group by";
const char* msg5 = "retrieve tags not compatible with group by or interval query"; const char* msg5 = "retrieve tags not compatible with group by or interval query";
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd* pCmd = &pSql->cmd;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
// only retrieve tags, group by is not supportted // only retrieve tags, group by is not supportted
if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) {
@ -5519,11 +5483,6 @@ int32_t doFunctionsCompatibleCheck(SSqlObj* pSql) {
} }
if (pCmd->groupbyExpr.numOfGroupCols > 0) { if (pCmd->groupbyExpr.numOfGroupCols > 0) {
SSchema* pSchema = tsGetSchema(pMeterMetaInfo->pMeterMeta);
int16_t bytes = 0;
int16_t type = 0;
char* name = NULL;
// check if all the tags prj columns belongs to the group by columns // check if all the tags prj columns belongs to the group by columns
if (onlyTagPrjFunction(pCmd) && allTagPrjInGroupby(pCmd)) { if (onlyTagPrjFunction(pCmd) && allTagPrjInGroupby(pCmd)) {
updateTagPrjFunction(pCmd); updateTagPrjFunction(pCmd);
@ -5641,84 +5600,81 @@ int32_t doLocalQueryProcess(SQuerySQL* pQuerySql, SSqlCmd* pCmd) {
case 4: case 4:
pCmd->command = TSDB_SQL_CURRENT_USER; pCmd->command = TSDB_SQL_CURRENT_USER;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
default: { default: { return invalidSqlErrMsg(pCmd, msg3); }
return invalidSqlErrMsg(pCmd, msg3);
}
} }
} }
// can only perform the parameters based on the macro definitation // can only perform the parameters based on the macro definitation
int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg *pCreate) { int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCreateDbMsg* pCreate) {
char msg[512] = {0}; char msg[512] = {0};
if (pCreate->commitLog != -1 && (pCreate->commitLog < 0 || pCreate->commitLog > 1)) { if (pCreate->commitLog != -1 && (pCreate->commitLog < 0 || pCreate->commitLog > 1)) {
snprintf(msg, tListLen(msg), "invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog); snprintf(msg, tListLen(msg), "invalid db option commitLog: %d, only 0 or 1 allowed", pCreate->commitLog);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (pCreate->replications != -1 && if (pCreate->replications != -1 &&
(pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM)) { (pCreate->replications < TSDB_REPLICA_MIN_NUM || pCreate->replications > TSDB_REPLICA_MAX_NUM)) {
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications, TSDB_REPLICA_MIN_NUM, snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications,
TSDB_REPLICA_MAX_NUM); TSDB_REPLICA_MIN_NUM, TSDB_REPLICA_MAX_NUM);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
int32_t val = htonl(pCreate->daysPerFile); int32_t val = htonl(pCreate->daysPerFile);
if (val != -1 && (val < TSDB_FILE_MIN_PARTITION_RANGE || val > TSDB_FILE_MAX_PARTITION_RANGE)) { if (val != -1 && (val < TSDB_FILE_MIN_PARTITION_RANGE || val > TSDB_FILE_MAX_PARTITION_RANGE)) {
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val, snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val,
TSDB_FILE_MIN_PARTITION_RANGE, TSDB_FILE_MAX_PARTITION_RANGE); TSDB_FILE_MIN_PARTITION_RANGE, TSDB_FILE_MAX_PARTITION_RANGE);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
val = htonl(pCreate->rowsInFileBlock); val = htonl(pCreate->rowsInFileBlock);
if (val != -1 && (val < TSDB_MIN_ROWS_IN_FILEBLOCK || val > TSDB_MAX_ROWS_IN_FILEBLOCK)) { if (val != -1 && (val < TSDB_MIN_ROWS_IN_FILEBLOCK || val > TSDB_MAX_ROWS_IN_FILEBLOCK)) {
snprintf(msg, tListLen(msg), "invalid db option rowsInFileBlock: %d valid range: [%d, %d]", val, snprintf(msg, tListLen(msg), "invalid db option rowsInFileBlock: %d valid range: [%d, %d]", val,
TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK); TSDB_MIN_ROWS_IN_FILEBLOCK, TSDB_MAX_ROWS_IN_FILEBLOCK);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
val = htonl(pCreate->cacheBlockSize); val = htonl(pCreate->cacheBlockSize);
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) { if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val, snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE); TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
val = htonl(pCreate->maxSessions); val = htonl(pCreate->maxSessions);
if (val != -1 && (val < TSDB_MIN_TABLES_PER_VNODE || val > TSDB_MAX_TABLES_PER_VNODE)) { if (val != -1 && (val < TSDB_MIN_TABLES_PER_VNODE || val > TSDB_MAX_TABLES_PER_VNODE)) {
snprintf(msg, tListLen(msg), "invalid db option maxSessions: %d valid range: [%d, %d]", val, TSDB_MIN_TABLES_PER_VNODE, snprintf(msg, tListLen(msg), "invalid db option maxSessions: %d valid range: [%d, %d]", val,
TSDB_MAX_TABLES_PER_VNODE); TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (pCreate->precision != -1 && if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO) {
(pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO)) { snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision,
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d]", pCreate->precision, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO);
TSDB_TIME_PRECISION_MICRO);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (pCreate->cacheNumOfBlocks.fraction != -1 && (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS || if (pCreate->cacheNumOfBlocks.fraction != -1 && (pCreate->cacheNumOfBlocks.fraction < TSDB_MIN_AVG_BLOCKS ||
pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS)) { pCreate->cacheNumOfBlocks.fraction > TSDB_MAX_AVG_BLOCKS)) {
snprintf(msg, tListLen(msg), "invalid db option ablocks: %f valid value: [%d, %d]", pCreate->cacheNumOfBlocks.fraction, snprintf(msg, tListLen(msg), "invalid db option ablocks: %f valid value: [%d, %d]",
TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS); pCreate->cacheNumOfBlocks.fraction, TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
val = htonl(pCreate->commitTime); val = htonl(pCreate->commitTime);
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME_INTERVAL || val > TSDB_MAX_COMMIT_TIME_INTERVAL)) { if (val != -1 && (val < TSDB_MIN_COMMIT_TIME_INTERVAL || val > TSDB_MAX_COMMIT_TIME_INTERVAL)) {
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val, snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val,
TSDB_MIN_COMMIT_TIME_INTERVAL, TSDB_MAX_COMMIT_TIME_INTERVAL); TSDB_MIN_COMMIT_TIME_INTERVAL, TSDB_MAX_COMMIT_TIME_INTERVAL);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
if (pCreate->compression != -1 && if (pCreate->compression != -1 &&
(pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL)) { (pCreate->compression < TSDB_MIN_COMPRESSION_LEVEL || pCreate->compression > TSDB_MAX_COMPRESSION_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression, TSDB_MIN_COMPRESSION_LEVEL, snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
TSDB_MAX_COMPRESSION_LEVEL); TSDB_MIN_COMPRESSION_LEVEL, TSDB_MAX_COMPRESSION_LEVEL);
return invalidSqlErrMsg(pCmd, msg); return invalidSqlErrMsg(pCmd, msg);
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -5727,24 +5683,24 @@ void tscPrintSelectClause(SSqlCmd* pCmd) {
if (pCmd == NULL || pCmd->exprsInfo.numOfExprs == 0) { if (pCmd == NULL || pCmd->exprsInfo.numOfExprs == 0) {
return; return;
} }
char* str = calloc(1, 10240); char* str = calloc(1, 10240);
int32_t offset = 0; int32_t offset = 0;
offset += sprintf(str, "%d [", pCmd->exprsInfo.numOfExprs); offset += sprintf(str, "%d [", pCmd->exprsInfo.numOfExprs);
for(int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) { for (int32_t i = 0; i < pCmd->exprsInfo.numOfExprs; ++i) {
SSqlExpr* pExpr = tscSqlExprGet(pCmd, i); SSqlExpr* pExpr = tscSqlExprGet(pCmd, i);
int32_t size = sprintf(str + offset, "%s(%d)", aAggs[pExpr->functionId].aName, pExpr->colInfo.colId); int32_t size = sprintf(str + offset, "%s(%d)", aAggs[pExpr->functionId].aName, pExpr->colInfo.colId);
offset += size; offset += size;
if (i < pCmd->exprsInfo.numOfExprs - 1) { if (i < pCmd->exprsInfo.numOfExprs - 1) {
str[offset++] = ','; str[offset++] = ',';
} }
} }
str[offset] = ']'; str[offset] = ']';
printf("%s\n", str); printf("%s\n", str);
free(str); free(str);
} }

View File

@ -83,6 +83,13 @@ struct SSchema* tsGetColumnSchema(SMeterMeta* pMeta, int32_t startCol) {
return (SSchema*)(((char*)pMeta + sizeof(SMeterMeta)) + startCol * sizeof(SSchema)); return (SSchema*)(((char*)pMeta + sizeof(SMeterMeta)) + startCol * sizeof(SSchema));
} }
struct SSchema tsGetTbnameColumnSchema() {
struct SSchema s = {.colId = TSDB_TBNAME_COLUMN_INDEX, .type = TSDB_DATA_TYPE_BINARY, .bytes = TSDB_METER_NAME_LEN};
strcpy(s.name, TSQL_TBNAME_L);
return s;
}
/** /**
* the MeterMeta data format in memory is as follows: * the MeterMeta data format in memory is as follows:
* *
@ -123,7 +130,7 @@ bool tsMeterMetaIdentical(SMeterMeta* p1, SMeterMeta* p2) {
return memcmp(p1, p2, size) == 0; return memcmp(p1, p2, size) == 0;
} }
//todo refactor // todo refactor
static FORCE_INLINE char* skipSegments(char* input, char delimiter, int32_t num) { static FORCE_INLINE char* skipSegments(char* input, char delimiter, int32_t num) {
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
while (*input != 0 && *input++ != delimiter) { while (*input != 0 && *input++ != delimiter) {

View File

@ -3351,7 +3351,7 @@ int tscProcessShowRsp(SSqlObj *pSql) {
} }
int tscProcessConnectRsp(SSqlObj *pSql) { int tscProcessConnectRsp(SSqlObj *pSql) {
char temp[TSDB_METER_ID_LEN]; char temp[TSDB_METER_ID_LEN*2];
SConnectRsp *pConnect; SConnectRsp *pConnect;
STscObj *pObj = pSql->pTscObj; STscObj *pObj = pSql->pTscObj;
@ -3359,8 +3359,11 @@ int tscProcessConnectRsp(SSqlObj *pSql) {
pConnect = (SConnectRsp *)pRes->pRsp; pConnect = (SConnectRsp *)pRes->pRsp;
strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response strcpy(pObj->acctId, pConnect->acctId); // copy acctId from response
sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db); int32_t len =sprintf(temp, "%s%s%s", pObj->acctId, TS_PATH_DELIMITER, pObj->db);
strcpy(pObj->db, temp);
assert(len <= tListLen(pObj->db));
strncpy(pObj->db, temp, tListLen(pObj->db));
#ifdef CLUSTER #ifdef CLUSTER
SIpList * pIpList; SIpList * pIpList;
char *rsp = pRes->pRsp + sizeof(SConnectRsp); char *rsp = pRes->pRsp + sizeof(SConnectRsp);
@ -3635,7 +3638,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
*/ */
if (pMeterMetaInfo->pMeterMeta == NULL || !tscQueryOnMetric(pCmd)) { if (pMeterMetaInfo->pMeterMeta == NULL || !tscQueryOnMetric(pCmd)) {
if (pMeterMetaInfo->pMeterMeta) { if (pMeterMetaInfo->pMeterMeta) {
tscTrace("%p update meter meta, old: numOfTags:%d, numOfCols:%d, uid:%lld, addr:%p", pSql, tscTrace("%p update meter meta, old: numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
pMeterMetaInfo->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid, pMeterMetaInfo->pMeterMeta); pMeterMetaInfo->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid, pMeterMetaInfo->pMeterMeta);
} }
tscWaitingForCreateTable(&pSql->cmd); tscWaitingForCreateTable(&pSql->cmd);
@ -3643,7 +3646,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *meterId) {
code = tscDoGetMeterMeta(pSql, meterId, 0); // todo ?? code = tscDoGetMeterMeta(pSql, meterId, 0); // todo ??
} else { } else {
tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%lld, addr:%p", pSql, tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql,
pMeterMetaInfo->pMeterMeta->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid, pMeterMetaInfo->pMeterMeta->numOfTags, pCmd->numOfCols, pMeterMetaInfo->pMeterMeta->uid,
pMeterMetaInfo->pMeterMeta); pMeterMetaInfo->pMeterMeta);
} }

View File

@ -532,7 +532,7 @@ static void **tscJoinResultsetFromBuf(SSqlObj *pSql) {
doSetResultRowData(pSql->pSubs[1]); doSetResultRowData(pSql->pSubs[1]);
// TSKEY key1 = *(TSKEY *)pRes1->tsrow[0]; // TSKEY key1 = *(TSKEY *)pRes1->tsrow[0];
// TSKEY key2 = *(TSKEY *)pRes2->tsrow[0]; // TSKEY key2 = *(TSKEY *)pRes2->tsrow[0];
// printf("first:%lld, second:%lld\n", key1, key2); // printf("first:%" PRId64 ", second:%" PRId64 "\n", key1, key2);
success = true; success = true;
pRes1->row++; pRes1->row++;
pRes2->row++; pRes2->row++;
@ -903,7 +903,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
len += sprintf(str + len, "%lld ", *((int64_t *)row[i])); len += sprintf(str + len, "%" PRId64 " ", *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_FLOAT:
@ -928,7 +928,7 @@ int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields)
} break; } break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
len += sprintf(str + len, "%lld ", *((int64_t *)row[i])); len += sprintf(str + len, "%" PRId64 " ", *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:

View File

@ -85,7 +85,7 @@ static void tscProcessStreamLaunchQuery(SSchedMsg *pMsg) {
// failed to get meter/metric meta, retry in 10sec. // failed to get meter/metric meta, retry in 10sec.
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
tscError("%p stream:%p,get metermeta failed, retry in %lldms", pStream->pSql, pStream, retryDelayTime); tscError("%p stream:%p,get metermeta failed, retry in %" PRId64 "ms", pStream->pSql, pStream, retryDelayTime);
tscSetRetryTimer(pStream, pSql, retryDelayTime); tscSetRetryTimer(pStream, pSql, retryDelayTime);
return; return;
@ -136,7 +136,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf
SSqlStream *pStream = (SSqlStream *)param; SSqlStream *pStream = (SSqlStream *)param;
if (tres == NULL || numOfRows < 0) { if (tres == NULL || numOfRows < 0) {
int64_t retryDelay = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); int64_t retryDelay = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
tscError("%p stream:%p, query data failed, code:%d, retry in %lldms", pStream->pSql, pStream, numOfRows, tscError("%p stream:%p, query data failed, code:%d, retry in %" PRId64 "ms", pStream->pSql, pStream, numOfRows,
retryDelay); retryDelay);
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pStream->pSql->cmd, 0); SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(&pStream->pSql->cmd, 0);
@ -158,7 +158,7 @@ static void tscSetTimestampForRes(SSqlStream *pStream, SSqlObj *pSql) {
if (timestamp != actualTimestamp) { if (timestamp != actualTimestamp) {
// reset the timestamp of each agg point by using start time of each interval // reset the timestamp of each agg point by using start time of each interval
*((int64_t *)pRes->data) = actualTimestamp; *((int64_t *)pRes->data) = actualTimestamp;
tscWarn("%p stream:%p, timestamp of points is:%lld, reset to %lld", pSql, pStream, timestamp, actualTimestamp); tscWarn("%p stream:%p, timestamp of points is:%" PRId64 ", reset to %" PRId64 "", pSql, pStream, timestamp, actualTimestamp);
} }
} }
@ -169,7 +169,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
if (pSql == NULL || numOfRows < 0) { if (pSql == NULL || numOfRows < 0) {
int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision); int64_t retryDelayTime = tscGetRetryDelayTime(pStream->slidingTime, pStream->precision);
tscError("%p stream:%p, retrieve data failed, code:%d, retry in %lldms", pSql, pStream, numOfRows, retryDelayTime); tscError("%p stream:%p, retrieve data failed, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retryDelayTime);
tscClearMeterMetaInfo(pMeterMetaInfo, true); tscClearMeterMetaInfo(pMeterMetaInfo, true);
tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime); tscSetRetryTimer(pStream, pStream->pSql, retryDelayTime);
@ -235,7 +235,7 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf
/* no resuls in the query range, retry */ /* no resuls in the query range, retry */
// todo set retry dynamic time // todo set retry dynamic time
int32_t retry = tsProjectExecInterval; int32_t retry = tsProjectExecInterval;
tscError("%p stream:%p, retrieve no data, code:%d, retry in %lldms", pSql, pStream, numOfRows, retry); tscError("%p stream:%p, retrieve no data, code:%d, retry in %" PRId64 "ms", pSql, pStream, numOfRows, retry);
tscClearSqlMetaInfoForce(&(pStream->pSql->cmd)); tscClearSqlMetaInfoForce(&(pStream->pSql->cmd));
tscSetRetryTimer(pStream, pStream->pSql, retry); tscSetRetryTimer(pStream, pStream->pSql, retry);
@ -265,7 +265,7 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
/* /*
* current time window will be closed, since it too early to exceed the maxRetentWindow value * current time window will be closed, since it too early to exceed the maxRetentWindow value
*/ */
tscTrace("%p stream:%p, etime:%lld is too old, exceeds the max retention time window:%lld, stop the stream", tscTrace("%p stream:%p, etime:%" PRId64 " is too old, exceeds the max retention time window:%" PRId64 ", stop the stream",
pStream->pSql, pStream, pStream->stime, pStream->etime); pStream->pSql, pStream, pStream->stime, pStream->etime);
// TODO : How to terminate stream here // TODO : How to terminate stream here
taos_close_stream(pStream); taos_close_stream(pStream);
@ -276,10 +276,10 @@ static void tscSetRetryTimer(SSqlStream *pStream, SSqlObj *pSql, int64_t timer)
return; return;
} }
tscTrace("%p stream:%p, next query start at %lld, in %lldms. query range %lld-%lld", pStream->pSql, pStream, tscTrace("%p stream:%p, next query start at %" PRId64 ", in %" PRId64 "ms. query range %" PRId64 "-%" PRId64 "", pStream->pSql, pStream,
now + timer, timer, pStream->stime, etime); now + timer, timer, pStream->stime, etime);
} else { } else {
tscTrace("%p stream:%p, next query start at %lld, in %lldms. query range %lld-%lld", pStream->pSql, pStream, tscTrace("%p stream:%p, next query start at %" PRId64 ", in %" PRId64 "ms. query range %" PRId64 "-%" PRId64 "", pStream->pSql, pStream,
pStream->stime, timer, pStream->stime - pStream->interval, pStream->stime - 1); pStream->stime, timer, pStream->stime - pStream->interval, pStream->stime - 1);
} }
@ -299,7 +299,7 @@ static void tscSetNextLaunchTimer(SSqlStream *pStream, SSqlObj *pSql) {
*/ */
timer = pStream->slidingTime; timer = pStream->slidingTime;
if (pStream->stime > pStream->etime) { if (pStream->stime > pStream->etime) {
tscTrace("%p stream:%p, stime:%lld is larger than end time: %lld, stop the stream", pStream->pSql, pStream, tscTrace("%p stream:%p, stime:%" PRId64 " is larger than end time: %" PRId64 ", stop the stream", pStream->pSql, pStream,
pStream->stime, pStream->etime); pStream->stime, pStream->etime);
// TODO : How to terminate stream here // TODO : How to terminate stream here
taos_close_stream(pStream); taos_close_stream(pStream);
@ -353,7 +353,7 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
int64_t minIntervalTime = int64_t minIntervalTime =
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime; (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinIntervalTime * 1000L : tsMinIntervalTime;
if (pCmd->nAggTimeInterval < minIntervalTime) { if (pCmd->nAggTimeInterval < minIntervalTime) {
tscWarn("%p stream:%p, original sample interval:%ld too small, reset to:%lld", pSql, pStream, tscWarn("%p stream:%p, original sample interval:%ld too small, reset to:%" PRId64 "", pSql, pStream,
pCmd->nAggTimeInterval, minIntervalTime); pCmd->nAggTimeInterval, minIntervalTime);
pCmd->nAggTimeInterval = minIntervalTime; pCmd->nAggTimeInterval = minIntervalTime;
} }
@ -368,14 +368,14 @@ static void tscSetSlidingWindowInfo(SSqlObj *pSql, SSqlStream *pStream) {
(pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime; (pStream->precision == TSDB_TIME_PRECISION_MICRO) ? tsMinSlidingTime * 1000L : tsMinSlidingTime;
if (pCmd->nSlidingTime < minSlidingTime) { if (pCmd->nSlidingTime < minSlidingTime) {
tscWarn("%p stream:%p, original sliding value:%lld too small, reset to:%lld", pSql, pStream, pCmd->nSlidingTime, tscWarn("%p stream:%p, original sliding value:%" PRId64 " too small, reset to:%" PRId64 "", pSql, pStream, pCmd->nSlidingTime,
minSlidingTime); minSlidingTime);
pCmd->nSlidingTime = minSlidingTime; pCmd->nSlidingTime = minSlidingTime;
} }
if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) { if (pCmd->nSlidingTime > pCmd->nAggTimeInterval) {
tscWarn("%p stream:%p, sliding value:%lld can not be larger than interval range, reset to:%lld", pSql, pStream, tscWarn("%p stream:%p, sliding value:%" PRId64 " can not be larger than interval range, reset to:%" PRId64 "", pSql, pStream,
pCmd->nSlidingTime, pCmd->nAggTimeInterval); pCmd->nSlidingTime, pCmd->nAggTimeInterval);
pCmd->nSlidingTime = pCmd->nAggTimeInterval; pCmd->nSlidingTime = pCmd->nAggTimeInterval;
@ -401,11 +401,11 @@ static int64_t tscGetStreamStartTimestamp(SSqlObj *pSql, SSqlStream *pStream, in
} else { // timewindow based aggregation stream } else { // timewindow based aggregation stream
if (stime == 0) { // no data in meter till now if (stime == 0) { // no data in meter till now
stime = ((int64_t)taosGetTimestamp(pStream->precision) / pStream->interval) * pStream->interval; stime = ((int64_t)taosGetTimestamp(pStream->precision) / pStream->interval) * pStream->interval;
tscWarn("%p stream:%p, last timestamp:0, reset to:%lld", pSql, pStream, stime); tscWarn("%p stream:%p, last timestamp:0, reset to:%" PRId64 "", pSql, pStream, stime);
} else { } else {
int64_t newStime = (stime / pStream->interval) * pStream->interval; int64_t newStime = (stime / pStream->interval) * pStream->interval;
if (newStime != stime) { if (newStime != stime) {
tscWarn("%p stream:%p, last timestamp:%lld, reset to:%lld", pSql, pStream, stime, newStime); tscWarn("%p stream:%p, last timestamp:%" PRId64 ", reset to:%" PRId64 "", pSql, pStream, stime, newStime);
stime = newStime; stime = newStime;
} }
} }
@ -447,7 +447,10 @@ static void setErrorInfo(STscObj* pObj, int32_t code, char* info) {
SSqlCmd* pCmd = &pObj->pSql->cmd; SSqlCmd* pCmd = &pObj->pSql->cmd;
pObj->pSql->res.code = code; pObj->pSql->res.code = code;
strncpy(pCmd->payload, info, pCmd->payloadLen);
if (info != NULL) {
strncpy(pCmd->payload, info, pCmd->payloadLen);
}
} }
TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row),
@ -537,7 +540,7 @@ TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sqlstr, void (*fp)(void *p
int64_t starttime = tscGetLaunchTimestamp(pStream); int64_t starttime = tscGetLaunchTimestamp(pStream);
taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer); taosTmrReset(tscProcessStreamTimer, starttime, pStream, tscTmr, &pStream->pTimer);
tscTrace("%p stream:%p is opened, query on:%s, interval:%lld, sliding:%lld, first launched in:%lld, sql:%s", pSql, tscTrace("%p stream:%p is opened, query on:%s, interval:%" PRId64 ", sliding:%" PRId64 ", first launched in:%" PRId64 ", sql:%s", pSql,
pStream, pMeterMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr); pStream, pMeterMetaInfo->name, pStream->interval, pStream->slidingTime, starttime, sqlstr);
return pStream; return pStream;

View File

@ -56,7 +56,7 @@ TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, c
if (pSub->taos == NULL) { if (pSub->taos == NULL) {
tfree(pSub); tfree(pSub);
} else { } else {
char qstr[128]; char qstr[256] = {0};
sprintf(qstr, "use %s", db); sprintf(qstr, "use %s", db);
int res = taos_query(pSub->taos, qstr); int res = taos_query(pSub->taos, qstr);
if (res != 0) { if (res != 0) {
@ -64,7 +64,7 @@ TAOS_SUB *taos_subscribe(const char *host, const char *user, const char *pass, c
taos_close(pSub->taos); taos_close(pSub->taos);
tfree(pSub); tfree(pSub);
} else { } else {
sprintf(qstr, "select * from %s where _c0 > now+1000d", pSub->name); snprintf(qstr, tListLen(qstr), "select * from %s where _c0 > now+1000d", pSub->name);
if (taos_query(pSub->taos, qstr)) { if (taos_query(pSub->taos, qstr)) {
tscTrace("failed to select, reason:%s", taos_errstr(pSub->taos)); tscTrace("failed to select, reason:%s", taos_errstr(pSub->taos));
taos_close(pSub->taos); taos_close(pSub->taos);
@ -106,7 +106,7 @@ TAOS_ROW taos_consume(TAOS_SUB *tsub) {
pSub->stime = taosGetTimestampMs(); pSub->stime = taosGetTimestampMs();
sprintf(qstr, "select * from %s where _c0 > %lld order by _c0 asc", pSub->name, pSub->lastKey); sprintf(qstr, "select * from %s where _c0 > %" PRId64 " order by _c0 asc", pSub->name, pSub->lastKey);
if (taos_query(pSub->taos, qstr)) { if (taos_query(pSub->taos, qstr)) {
tscTrace("failed to select, reason:%s", taos_errstr(pSub->taos)); tscTrace("failed to select, reason:%s", taos_errstr(pSub->taos));
return NULL; return NULL;

View File

@ -198,7 +198,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
switch (option) { switch (option) {
case TSDB_OPTION_CONFIGDIR: case TSDB_OPTION_CONFIGDIR:
cfg = tsGetConfigOption("configDir"); cfg = tsGetConfigOption("configDir");
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { assert(cfg != NULL);
if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
strncpy(configDir, pStr, TSDB_FILENAME_LEN); strncpy(configDir, pStr, TSDB_FILENAME_LEN);
cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
tscPrint("set config file directory:%s", pStr); tscPrint("set config file directory:%s", pStr);
@ -210,7 +212,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
case TSDB_OPTION_SHELL_ACTIVITY_TIMER: case TSDB_OPTION_SHELL_ACTIVITY_TIMER:
cfg = tsGetConfigOption("shellActivityTimer"); cfg = tsGetConfigOption("shellActivityTimer");
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { assert(cfg != NULL);
if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
tsShellActivityTimer = atoi(pStr); tsShellActivityTimer = atoi(pStr);
if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; if (tsShellActivityTimer < 1) tsShellActivityTimer = 1;
if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600;
@ -224,13 +228,15 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
case TSDB_OPTION_LOCALE: { // set locale case TSDB_OPTION_LOCALE: { // set locale
cfg = tsGetConfigOption("locale"); cfg = tsGetConfigOption("locale");
assert(cfg != NULL);
size_t len = strlen(pStr); size_t len = strlen(pStr);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscPrint("Invalid locale:%s, use default", pStr); tscPrint("Invalid locale:%s, use default", pStr);
return -1; return -1;
} }
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
char sep = '.'; char sep = '.';
if (strlen(tsLocale) == 0) { // locale does not set yet if (strlen(tsLocale) == 0) { // locale does not set yet
@ -285,13 +291,15 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
case TSDB_OPTION_CHARSET: { case TSDB_OPTION_CHARSET: {
/* set charset will override the value of charset, assigned during system locale changed */ /* set charset will override the value of charset, assigned during system locale changed */
cfg = tsGetConfigOption("charset"); cfg = tsGetConfigOption("charset");
assert(cfg != NULL);
size_t len = strlen(pStr); size_t len = strlen(pStr);
if (len == 0 || len > TSDB_LOCALE_LEN) { if (len == 0 || len > TSDB_LOCALE_LEN) {
tscPrint("failed to set charset:%s", pStr); tscPrint("failed to set charset:%s", pStr);
return -1; return -1;
} }
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
if (taosValidateEncodec(pStr)) { if (taosValidateEncodec(pStr)) {
if (strlen(tsCharset) == 0) { if (strlen(tsCharset) == 0) {
tscPrint("charset is set:%s", pStr); tscPrint("charset is set:%s", pStr);
@ -314,7 +322,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
case TSDB_OPTION_TIMEZONE: case TSDB_OPTION_TIMEZONE:
cfg = tsGetConfigOption("timezone"); cfg = tsGetConfigOption("timezone");
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { assert(cfg != NULL);
if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
strcpy(tsTimezone, pStr); strcpy(tsTimezone, pStr);
tsSetTimeZone(); tsSetTimeZone();
cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION;
@ -327,7 +337,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
case TSDB_OPTION_SOCKET_TYPE: case TSDB_OPTION_SOCKET_TYPE:
cfg = tsGetConfigOption("sockettype"); cfg = tsGetConfigOption("sockettype");
if (cfg && cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { assert(cfg != NULL);
if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) {
if (strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_TCP) != 0) { if (strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_TCP) != 0) {
tscError("only 'tcp' or 'udp' allowed for configuring the socket type"); tscError("only 'tcp' or 'udp' allowed for configuring the socket type");
return -1; return -1;
@ -340,6 +352,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
break; break;
default: default:
// TODO return the correct error code to client in the format for taos_errstr()
tscError("Invalid option %d", option); tscError("Invalid option %d", option);
return -1; return -1;
} }

View File

@ -246,7 +246,7 @@ bool tscProjectionQueryOnMetric(SSqlCmd* pCmd) {
for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) { for (int32_t i = 0; i < pCmd->fieldsInfo.numOfOutputCols; ++i) {
int32_t functionId = tscSqlExprGet(pCmd, i)->functionId; int32_t functionId = tscSqlExprGet(pCmd, i)->functionId;
if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ && if (functionId != TSDB_FUNC_PRJ && functionId != TSDB_FUNC_TAGPRJ &&
functionId != TSDB_FUNC_TAG && functionId != TSDB_FUNC_TS) { functionId != TSDB_FUNC_TAG && functionId != TSDB_FUNC_TS && functionId != TSDB_FUNC_ARITHM) {
return false; return false;
} }
} }
@ -451,15 +451,6 @@ void tscFreeSqlObj(SSqlObj* pSql) {
free(pSql); free(pSql);
} }
STableDataBlocks* tscCreateDataBlock(int32_t size) {
STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks));
dataBuf->nAllocSize = (uint32_t)size;
dataBuf->pData = calloc(1, dataBuf->nAllocSize);
dataBuf->ordered = true;
dataBuf->prevTS = INT64_MIN;
return dataBuf;
}
void tscDestroyDataBlock(STableDataBlocks* pDataBlock) { void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
if (pDataBlock == NULL) { if (pDataBlock == NULL) {
return; return;
@ -467,6 +458,9 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) {
tfree(pDataBlock->pData); tfree(pDataBlock->pData);
tfree(pDataBlock->params); tfree(pDataBlock->params);
// free the refcount for metermeta
taosRemoveDataFromCache(tscCacheHandle, (void**) &(pDataBlock->pMeterMeta), false);
tfree(pDataBlock); tfree(pDataBlock);
} }
@ -513,11 +507,11 @@ SDataBlockList* tscCreateBlockArrayList() {
void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks) { void tscAppendDataBlock(SDataBlockList* pList, STableDataBlocks* pBlocks) {
if (pList->nSize >= pList->nAlloc) { if (pList->nSize >= pList->nAlloc) {
pList->nAlloc = pList->nAlloc << 1; pList->nAlloc = (pList->nAlloc) << 1U;
pList->pData = realloc(pList->pData, sizeof(void*) * (size_t)pList->nAlloc); pList->pData = realloc(pList->pData, POINTER_BYTES * (size_t)pList->nAlloc);
// reset allocated memory // reset allocated memory
memset(pList->pData + pList->nSize, 0, sizeof(void*) * (pList->nAlloc - pList->nSize)); memset(pList->pData + pList->nSize, 0, POINTER_BYTES * (pList->nAlloc - pList->nSize));
} }
pList->pData[pList->nSize++] = pBlocks; pList->pData[pList->nSize++] = pBlocks;
@ -539,29 +533,43 @@ void* tscDestroyBlockArrayList(SDataBlockList* pList) {
} }
int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) { int32_t tscCopyDataBlockToPayload(SSqlObj* pSql, STableDataBlocks* pDataBlock) {
SSqlCmd* pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
assert(pDataBlock->pMeterMeta != NULL);
pCmd->count = pDataBlock->numOfMeters; pCmd->count = pDataBlock->numOfMeters;
SMeterMetaInfo* pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0); SMeterMetaInfo *pMeterMetaInfo = tscGetMeterMetaInfo(pCmd, 0);
strcpy(pMeterMetaInfo->name, pDataBlock->meterId);
//set the correct metermeta object, the metermeta has been locked in pDataBlocks, so it must be in the cache
if (pMeterMetaInfo->pMeterMeta != pDataBlock->pMeterMeta) {
strcpy(pMeterMetaInfo->name, pDataBlock->meterId);
taosRemoveDataFromCache(tscCacheHandle, (void**) &(pMeterMetaInfo->pMeterMeta), false);
pMeterMetaInfo->pMeterMeta = pDataBlock->pMeterMeta;
pDataBlock->pMeterMeta = NULL; // delegate the ownership of metermeta to pMeterMetaInfo
} else {
assert(strncmp(pMeterMetaInfo->name, pDataBlock->meterId, tListLen(pDataBlock->meterId)) == 0);
}
/* /*
* the submit message consists of : [RPC header|message body|digest] * the submit message consists of : [RPC header|message body|digest]
* the dataBlock only includes the RPC Header buffer and actual submit messsage body, space for digest needs * the dataBlock only includes the RPC Header buffer and actual submit messsage body, space for digest needs
* additional space. * additional space.
*/ */
int ret = tscAllocPayload(pCmd, pDataBlock->nAllocSize + sizeof(STaosDigest)); int ret = tscAllocPayload(pCmd, pDataBlock->nAllocSize + sizeof(STaosDigest));
if (TSDB_CODE_SUCCESS != ret) return ret; if (TSDB_CODE_SUCCESS != ret) {
return ret;
}
memcpy(pCmd->payload, pDataBlock->pData, pDataBlock->nAllocSize); memcpy(pCmd->payload, pDataBlock->pData, pDataBlock->nAllocSize);
/* /*
* the payloadLen should be actual message body size * the payloadLen should be actual message body size
* the old value of payloadLen is the allocated payload size * the old value of payloadLen is the allocated payload size
*/ */
pCmd->payloadLen = pDataBlock->nAllocSize - tsRpcHeadSize; pCmd->payloadLen = pDataBlock->nAllocSize - tsRpcHeadSize;
assert(pCmd->allocSize >= pCmd->payloadLen + tsRpcHeadSize + sizeof(STaosDigest)); assert(pCmd->allocSize >= pCmd->payloadLen + tsRpcHeadSize + sizeof(STaosDigest));
return tscGetMeterMeta(pSql, pMeterMetaInfo->name, 0); return TSDB_CODE_SUCCESS;
} }
void tscFreeUnusedDataBlocks(SDataBlockList* pList) { void tscFreeUnusedDataBlocks(SDataBlockList* pList) {
@ -573,19 +581,38 @@ void tscFreeUnusedDataBlocks(SDataBlockList* pList) {
} }
} }
STableDataBlocks* tscCreateDataBlockEx(size_t size, int32_t rowSize, int32_t startOffset, char* name) { /**
STableDataBlocks* dataBuf = tscCreateDataBlock(size); * create the in-memory buffer for each table to keep the submitted data block
* @param initialSize
* @param rowSize
* @param startOffset
* @param name
* @param pMeterMeta the ownership of pMeterMeta should be transfer to STableDataBlocks
* @return
*/
STableDataBlocks* tscCreateDataBlock(size_t initialSize, int32_t rowSize, int32_t startOffset, const char* name) {
STableDataBlocks* dataBuf = (STableDataBlocks*)calloc(1, sizeof(STableDataBlocks));
dataBuf->nAllocSize = (uint32_t) initialSize;
dataBuf->pData = calloc(1, dataBuf->nAllocSize);
dataBuf->ordered = true;
dataBuf->prevTS = INT64_MIN;
dataBuf->rowSize = rowSize; dataBuf->rowSize = rowSize;
dataBuf->size = startOffset; dataBuf->size = startOffset;
dataBuf->tsSource = -1; dataBuf->tsSource = -1;
strncpy(dataBuf->meterId, name, TSDB_METER_ID_LEN); strncpy(dataBuf->meterId, name, TSDB_METER_ID_LEN);
// sure that the metermeta must be in the local client cache
dataBuf->pMeterMeta = taosGetDataFromCache(tscCacheHandle, dataBuf->meterId);
assert(dataBuf->pMeterMeta != NULL && initialSize > 0);
return dataBuf; return dataBuf;
} }
STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size, STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pDataBlockList, int64_t id, int32_t size,
int32_t startOffset, int32_t rowSize, char* tableId) { int32_t startOffset, int32_t rowSize, const char* tableId) {
STableDataBlocks* dataBuf = NULL; STableDataBlocks* dataBuf = NULL;
STableDataBlocks** t1 = (STableDataBlocks**)taosGetIntHashData(pHashList, id); STableDataBlocks** t1 = (STableDataBlocks**)taosGetIntHashData(pHashList, id);
@ -594,7 +621,7 @@ STableDataBlocks* tscGetDataBlockFromList(void* pHashList, SDataBlockList* pData
} }
if (dataBuf == NULL) { if (dataBuf == NULL) {
dataBuf = tscCreateDataBlockEx((size_t)size, rowSize, startOffset, tableId); dataBuf = tscCreateDataBlock((size_t)size, rowSize, startOffset, tableId);
dataBuf = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)&dataBuf); dataBuf = *(STableDataBlocks**)taosAddIntHash(pHashList, id, (char*)&dataBuf);
tscAppendDataBlock(pDataBlockList, dataBuf); tscAppendDataBlock(pDataBlockList, dataBuf);
} }
@ -1138,7 +1165,8 @@ void tscColumnFilterInfoCopy(SColumnFilterInfo* dst, const SColumnFilterInfo* sr
*dst = *src; *dst = *src;
if (dst->filterOnBinary) { if (dst->filterOnBinary) {
size_t len = (size_t) dst->len + 1; size_t len = (size_t) dst->len + 1;
dst->pz = calloc(1, len); char* pTmp = calloc(1, len);
dst->pz = (int64_t) pTmp;
memcpy((char*) dst->pz, (char*) src->pz, (size_t) len); memcpy((char*) dst->pz, (char*) src->pz, (size_t) len);
} }
} }
@ -1202,7 +1230,8 @@ void tscColumnBaseInfoDestroy(SColumnBaseInfo* pColumnBaseInfo) {
assert(pColBase->filterInfo[j].filterOnBinary == 0 || pColBase->filterInfo[j].filterOnBinary == 1); assert(pColBase->filterInfo[j].filterOnBinary == 0 || pColBase->filterInfo[j].filterOnBinary == 1);
if (pColBase->filterInfo[j].filterOnBinary) { if (pColBase->filterInfo[j].filterOnBinary) {
tfree(pColBase->filterInfo[j].pz); free((char*) pColBase->filterInfo[j].pz);
pColBase->filterInfo[j].pz = 0;
} }
} }
} }

View File

@ -279,7 +279,7 @@ typedef struct {
} SShellSubmitMsg; } SShellSubmitMsg;
typedef struct SSchema { typedef struct SSchema {
char type; uint8_t type;
char name[TSDB_COL_NAME_LEN]; char name[TSDB_COL_NAME_LEN];
short colId; short colId;
short bytes; short bytes;
@ -622,7 +622,7 @@ typedef struct {
char repStrategy; char repStrategy;
char loadLatest; // load into mem or not char loadLatest; // load into mem or not
char precision; // time resoluation uint8_t precision; // time resolution
char reserved[16]; char reserved[16];
} SVnodeCfg, SCreateDbMsg, SDbCfg, SAlterDbMsg; } SVnodeCfg, SCreateDbMsg, SDbCfg, SAlterDbMsg;

View File

@ -47,6 +47,7 @@ struct SSchema *tsGetSchema(SMeterMeta *pMeta);
struct SSchema *tsGetTagSchema(SMeterMeta *pMeta); struct SSchema *tsGetTagSchema(SMeterMeta *pMeta);
struct SSchema *tsGetColumnSchema(SMeterMeta *pMeta, int32_t startCol); struct SSchema *tsGetColumnSchema(SMeterMeta *pMeta, int32_t startCol);
struct SSchema tsGetTbnameColumnSchema();
char *tsGetTagsValue(SMeterMeta *pMeta); char *tsGetTagsValue(SMeterMeta *pMeta);

View File

@ -227,8 +227,6 @@ typedef struct SPatternCompareInfo {
int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type,
int16_t *len, int16_t *interResBytes, int16_t extLength, bool isSuperTable); int16_t *len, int16_t *interResBytes, int16_t extLength, bool isSuperTable);
SResultInfo *getResultSupportInfo(SQLFunctionCtx *pCtx);
int patternMatch(const char *zPattern, const char *zString, size_t size, const SPatternCompareInfo *pInfo); int patternMatch(const char *zPattern, const char *zString, size_t size, const SPatternCompareInfo *pInfo);
int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo); int WCSPatternMatch(const wchar_t *zPattern, const wchar_t *zString, size_t size, const SPatternCompareInfo *pInfo);

View File

@ -50,7 +50,7 @@ bool isNull(const char *val, int32_t type);
void setNull(char *val, int32_t type, int32_t bytes); void setNull(char *val, int32_t type, int32_t bytes);
void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems); void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems);
void assignVal(char *val, char *src, int32_t len, int32_t type); void assignVal(char *val, const char *src, int32_t len, int32_t type);
void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size); void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size);
// variant, each number/string/field_id has a corresponding struct during parsing sql // variant, each number/string/field_id has a corresponding struct during parsing sql

View File

@ -37,8 +37,8 @@ extern "C" {
#define tfree(x) \ #define tfree(x) \
{ \ { \
if (x) { \ if (x) { \
free(x); \ free((void*)(x)); \
x = NULL; \ x = 0; \
} \ } \
} }
@ -175,7 +175,7 @@ bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len)
bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); bool taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs);
bool taosValidateEncodec(char *encodec); bool taosValidateEncodec(const char *encodec);
bool taosGetVersionNumber(char *versionStr, int *versionNubmer); bool taosGetVersionNumber(char *versionStr, int *versionNubmer);
@ -189,6 +189,8 @@ static FORCE_INLINE void taosEncryptPass(uint8_t *inBuf, unsigned int inLen, cha
char *taosIpStr(uint32_t ipInt); char *taosIpStr(uint32_t ipInt);
uint32_t ip2uint(const char *const ip_addr);
#define TAOS_ALLOC_MODE_DEFAULT 0 #define TAOS_ALLOC_MODE_DEFAULT 0
#define TAOS_ALLOC_MODE_RANDOM_FAIL 1 #define TAOS_ALLOC_MODE_RANDOM_FAIL 1
#define TAOS_ALLOC_MODE_DETECT_LEAK 2 #define TAOS_ALLOC_MODE_DETECT_LEAK 2

View File

@ -19,6 +19,8 @@
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
extern int wcwidth(wchar_t c);
extern int wcswidth(const wchar_t *s, size_t n);
typedef struct { typedef struct {
char widthInString; char widthInString;
char widthOnScreen; char widthOnScreen;

View File

@ -16,6 +16,7 @@
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include <inttypes.h>
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
@ -446,7 +447,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
printf("%*d|", l[i], *((int *)row[i])); printf("%*d|", l[i], *((int *)row[i]));
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
printf("%*lld|", l[i], *((int64_t *)row[i])); printf("%*" PRId64 "|", l[i], *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
@ -481,7 +482,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (args.is_raw_time) { if (args.is_raw_time) {
printf(" %lld|", *(int64_t *)row[i]); printf(" %" PRId64 "|", *(int64_t *)row[i]);
} else { } else {
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) { if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
tt = (time_t)((*(int64_t *)row[i]) / 1000000); tt = (time_t)((*(int64_t *)row[i]) / 1000000);
@ -531,7 +532,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
printf("%d\n", *((int *)row[i])); printf("%d\n", *((int *)row[i]));
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
printf("%lld\n", *((int64_t *)row[i])); printf("%" PRId64 "\n", *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
@ -564,7 +565,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (args.is_raw_time) { if (args.is_raw_time) {
printf("%lld\n", *(int64_t *)row[i]); printf("%" PRId64 "\n", *(int64_t *)row[i]);
} else { } else {
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) { if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
tt = (time_t)((*(int64_t *)row[i]) / 1000000); tt = (time_t)((*(int64_t *)row[i]) / 1000000);
@ -619,7 +620,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
fprintf(fp, "%d", *((int *)row[i])); fprintf(fp, "%d", *((int *)row[i]));
break; break;
case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_BIGINT:
fprintf(fp, "%lld", *((int64_t *)row[i])); fprintf(fp, "%" PRId64, *((int64_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_FLOAT: { case TSDB_DATA_TYPE_FLOAT: {
#ifdef _TD_ARM_32_ #ifdef _TD_ARM_32_
@ -651,7 +652,7 @@ int shellDumpResult(TAOS *con, char *fname, int *error_no, bool printMode) {
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (args.is_raw_time) { if (args.is_raw_time) {
fprintf(fp, "%lld", *(int64_t *)row[i]); fprintf(fp, "%" PRId64, *(int64_t *)row[i]);
} else { } else {
if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) { if (taos_result_precision(result) == TSDB_TIME_PRECISION_MICRO) {
tt = (time_t)((*(int64_t *)row[i]) / 1000000); tt = (time_t)((*(int64_t *)row[i]) / 1000000);

View File

@ -26,6 +26,7 @@
int indicator = 1; int indicator = 1;
struct termios oldtio; struct termios oldtio;
extern int wcwidth(wchar_t c);
void insertChar(Command *cmd, char *c, int size); void insertChar(Command *cmd, char *c, int size);
const char *argp_program_version = version; const char *argp_program_version = version;
const char *argp_program_bug_address = "<support@taosdata.com>"; const char *argp_program_bug_address = "<support@taosdata.com>";

View File

@ -33,8 +33,6 @@
extern char configDir[]; extern char configDir[];
#pragma GCC diagnostic ignored "-Wmissing-braces"
#define BUFFER_SIZE 65536 #define BUFFER_SIZE 65536
#define MAX_DB_NAME_SIZE 64 #define MAX_DB_NAME_SIZE 64
#define MAX_TB_NAME_SIZE 64 #define MAX_TB_NAME_SIZE 64
@ -267,30 +265,35 @@ double getCurrentTime();
void callBack(void *param, TAOS_RES *res, int code); void callBack(void *param, TAOS_RES *res, int code);
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
struct arguments arguments = {NULL, struct arguments arguments = {NULL, // host
0, 0, // port
"root", "root", // user
"taosdata", "taosdata", // password
"test", "test", // database
"t", "t", // tb_prefix
false, false, // use_metric
false, false, // insert_only
"./output.txt", "./output.txt", // output_file
0, 0, // mode
"int", {
"int", // datatype
"", "",
"", "",
"", "",
"", "",
"", "",
"", "",
"", ""
8, },
1, 8, // len_of_binary
1, 1, // num_of_CPR
1, 1, // num_of_connections
1, 1, // num_of_RPR
50000}; 1, // num_of_tables
50000, // num_of_DPT
0, // abort
NULL // arg_list
};
/* Parse our arguments; every option seen by parse_opt will be /* Parse our arguments; every option seen by parse_opt will be
reflected in arguments. */ reflected in arguments. */

View File

@ -106,7 +106,7 @@ void httpCleanUpContextTimer(HttpContext *pContext) {
} }
} }
void httpCleanUpContext(HttpContext *pContext) { void httpCleanUpContext(HttpContext *pContext, void *unused) {
httpTrace("context:%p, start the clean up operation, sig:%p", pContext, pContext->signature); httpTrace("context:%p, start the clean up operation, sig:%p", pContext, pContext->signature);
void *sig = atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0); void *sig = atomic_val_compare_exchange_ptr(&pContext->signature, pContext, 0);
if (sig == NULL) { if (sig == NULL) {
@ -184,7 +184,7 @@ bool httpInitContext(HttpContext *pContext) {
void httpCloseContext(HttpThread *pThread, HttpContext *pContext) { void httpCloseContext(HttpThread *pThread, HttpContext *pContext) {
taosTmrReset(httpCleanUpContext, HTTP_DELAY_CLOSE_TIME_MS, pContext, pThread->pServer->timerHandle, &pContext->timer); taosTmrReset((TAOS_TMR_CALLBACK)httpCleanUpContext, HTTP_DELAY_CLOSE_TIME_MS, pContext, pThread->pServer->timerHandle, &pContext->timer);
httpTrace("context:%p, fd:%d, ip:%s, state:%s will be closed after:%d ms, timer:%p", httpTrace("context:%p, fd:%d, ip:%s, state:%s will be closed after:%d ms, timer:%p",
pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), HTTP_DELAY_CLOSE_TIME_MS, pContext->timer); pContext, pContext->fd, pContext->ipstr, httpContextStateStr(pContext->state), HTTP_DELAY_CLOSE_TIME_MS, pContext->timer);
} }
@ -273,7 +273,7 @@ void httpCleanUpConnect(HttpServer *pServer) {
taosCloseSocket(pThread->pollFd); taosCloseSocket(pThread->pollFd);
while (pThread->pHead) { while (pThread->pHead) {
httpCleanUpContext(pThread->pHead); httpCleanUpContext(pThread->pHead, 0);
} }
pthread_cancel(pThread->thread); pthread_cancel(pThread->thread);

View File

@ -215,7 +215,7 @@ ParseEnd:
} }
} }
int tgParseSchema(char *content, char*fileName) { int tgParseSchema(const char *content, char*fileName) {
cJSON *root = cJSON_Parse(content); cJSON *root = cJSON_Parse(content);
if (root == NULL) { if (root == NULL) {
httpError("failed to parse telegraf schema file:%s, invalid json format, content:%s", fileName, content); httpError("failed to parse telegraf schema file:%s, invalid json format, content:%s", fileName, content);
@ -248,7 +248,7 @@ int tgParseSchema(char *content, char*fileName) {
return size; return size;
} }
int tgReadSchema(const char *fileName) { int tgReadSchema(char *fileName) {
FILE *fp = fopen(fileName, "r"); FILE *fp = fopen(fileName, "r");
if (fp == NULL) { if (fp == NULL) {
return -1; return -1;

View File

@ -14,6 +14,7 @@
*/ */
#include "monitor.h" #include "monitor.h"
#include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -376,7 +377,7 @@ void monitorSaveSystemInfo() {
int64_t ts = taosGetTimestampUs(); int64_t ts = taosGetTimestampUs();
char * sql = monitor->sql; char * sql = monitor->sql;
int pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%ld", tsMonitorDbName, monitor->privateIpStr, ts); int pos = snprintf(sql, SQL_LENGTH, "insert into %s.dn_%s values(%" PRId64, tsMonitorDbName, monitor->privateIpStr, ts);
pos += monitorBuildCpuSql(sql + pos); pos += monitorBuildCpuSql(sql + pos);
pos += monitorBuildMemorySql(sql + pos); pos += monitorBuildMemorySql(sql + pos);
@ -402,16 +403,16 @@ void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t ma
char sql[1024] = {0}; char sql[1024] = {0};
sprintf(sql, sprintf(sql,
"insert into %s.acct_%s using %s.acct tags('%s') values(now" "insert into %s.acct_%s using %s.acct tags('%s') values(now"
", %ld, %ld " ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %ld, %ld" ", %" PRId64, "%" PRId64
", %d)", ", %d)",
tsMonitorDbName, acctId, tsMonitorDbName, acctId, currentPointsPerSecond, maxPointsPerSecond, totalTimeSeries, tsMonitorDbName, acctId, tsMonitorDbName, acctId, currentPointsPerSecond, maxPointsPerSecond, totalTimeSeries,
maxTimeSeries, totalStorage, maxStorage, totalQueryTime, maxQueryTime, totalInbound, maxInbound, maxTimeSeries, totalStorage, maxStorage, totalQueryTime, maxQueryTime, totalInbound, maxInbound,
@ -431,7 +432,7 @@ void monitorSaveLog(int level, const char *const format, ...) {
return; return;
} }
int len = snprintf(sql, (size_t)max_length, "import into %s.log values(%ld, %d,'", tsMonitorDbName, int len = snprintf(sql, (size_t)max_length, "import into %s.log values(%\" PRId64 \", %d,'", tsMonitorDbName,
taosGetTimestampUs(), level); taosGetTimestampUs(), level);
va_start(argpointer, format); va_start(argpointer, format);

View File

@ -23,6 +23,7 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <error.h>
#include <argp.h> #include <argp.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
@ -71,6 +72,7 @@ extern "C" {
#include <wchar.h> #include <wchar.h>
#include <wordexp.h> #include <wordexp.h>
#include <wctype.h> #include <wctype.h>
#include <inttypes.h>
#define taosCloseSocket(x) \ #define taosCloseSocket(x) \

View File

@ -12,7 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <locale.h> #include <locale.h>
#include <netdb.h> #include <netdb.h>
@ -99,7 +99,7 @@ bool taosGetProcMemory(float *memoryUsedMB) {
int64_t memKB = 0; int64_t memKB = 0;
char tmp[10]; char tmp[10];
sscanf(line, "%s %ld", tmp, &memKB); sscanf(line, "%s %" PRId64, tmp, &memKB);
*memoryUsedMB = (float)((double)memKB / 1024); *memoryUsedMB = (float)((double)memKB / 1024);
tfree(line); tfree(line);
@ -124,7 +124,7 @@ bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) {
} }
char cpu[10] = {0}; char cpu[10] = {0};
sscanf(line, "%s %lu %lu %lu %lu", cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle);
tfree(line); tfree(line);
fclose(fp); fclose(fp);
@ -150,7 +150,7 @@ bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) {
for (int i = 0, blank = 0; line[i] != 0; ++i) { for (int i = 0, blank = 0; line[i] != 0; ++i) {
if (line[i] == ' ') blank++; if (line[i] == ' ') blank++;
if (blank == PROCESS_ITEM) { if (blank == PROCESS_ITEM) {
sscanf(line + i + 1, "%lu %lu %lu %lu", &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime); sscanf(line + i + 1, "%" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, &cpuInfo->utime, &cpuInfo->stime, &cpuInfo->cutime, &cpuInfo->cstime);
break; break;
} }
} }
@ -420,7 +420,7 @@ bool taosGetCardInfo(int64_t *bytes) {
} }
} }
if (line != NULL) { if (line != NULL) {
sscanf(line, "%s %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3, sscanf(line, "%s %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64 " %" PRId64, nouse0, &rbytes, &rpackts, &nouse1, &nouse2, &nouse3,
&nouse4, &nouse5, &nouse6, &tbytes, &tpackets); &nouse4, &nouse5, &nouse6, &tbytes, &tpackets);
*bytes = rbytes + tbytes; *bytes = rbytes + tbytes;
tfree(line); tfree(line);
@ -488,10 +488,10 @@ bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) {
break; break;
} }
if (strstr(line, "rchar:") != NULL) { if (strstr(line, "rchar:") != NULL) {
sscanf(line, "%s %ld", tmp, readbyte); sscanf(line, "%s %" PRId64, tmp, readbyte);
readIndex++; readIndex++;
} else if (strstr(line, "wchar:") != NULL) { } else if (strstr(line, "wchar:") != NULL) {
sscanf(line, "%s %ld", tmp, writebyte); sscanf(line, "%s %" PRId64, tmp, writebyte);
readIndex++; readIndex++;
} else { } else {
} }
@ -564,9 +564,9 @@ void taosGetSystemInfo() {
} }
void tsPrintOsInfo() { void tsPrintOsInfo() {
pPrint(" os pageSize: %ld(KB)", tsPageSize); pPrint(" os pageSize: %" PRId64 "(KB)", tsPageSize);
pPrint(" os openMax: %ld", tsOpenMax); pPrint(" os openMax: %" PRId64, tsOpenMax);
pPrint(" os streamMax: %ld", tsStreamMax); pPrint(" os streamMax: %" PRId64, tsStreamMax);
pPrint(" os numOfCores: %d", tsNumOfCores); pPrint(" os numOfCores: %d", tsNumOfCores);
pPrint(" os totalDisk: %f(GB)", tsTotalDataDirGB); pPrint(" os totalDisk: %f(GB)", tsTotalDataDirGB);
pPrint(" os totalMemory: %d(MB)", tsTotalMemoryMB); pPrint(" os totalMemory: %d(MB)", tsTotalMemoryMB);

View File

@ -246,9 +246,7 @@ char *taosBuildReqHeader(void *param, char type, char *msg) {
pHeader->destId = pConn->peerId; pHeader->destId = pConn->peerId;
pHeader->port = 0; pHeader->port = 0;
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" pHeader->uid = (uint32_t)((int64_t)pConn + (int64_t)getpid());
pHeader->uid = (uint32_t)pConn + (uint32_t)getpid();
#pragma GCC diagnostic warning "-Wpointer-to-int-cast"
memcpy(pHeader->meterId, pConn->meterId, tListLen(pHeader->meterId)); memcpy(pHeader->meterId, pConn->meterId, tListLen(pHeader->meterId));
@ -280,9 +278,7 @@ char *taosBuildReqMsgWithSize(void *param, char type, int size) {
pHeader->sourceId = pConn->ownId; pHeader->sourceId = pConn->ownId;
pHeader->destId = pConn->peerId; pHeader->destId = pConn->peerId;
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast" pHeader->uid = (uint32_t)((int64_t)pConn + (int64_t)getpid());
pHeader->uid = (uint32_t)pConn + (uint32_t)getpid();
#pragma GCC diagnostic warning "-Wpointer-to-int-cast"
memcpy(pHeader->meterId, pConn->meterId, tListLen(pHeader->meterId)); memcpy(pHeader->meterId, pConn->meterId, tListLen(pHeader->meterId));

View File

@ -419,7 +419,7 @@ void mgmtCleanupBalance();
int mgmtAllocVnodes(SVgObj *pVgroup); int mgmtAllocVnodes(SVgObj *pVgroup);
void mgmtSetDnodeShellRemoving(SDnodeObj *pDnode); void mgmtSetDnodeShellRemoving(SDnodeObj *pDnode);
void mgmtSetDnodeUnRemove(SDnodeObj *pDnode); void mgmtSetDnodeUnRemove(SDnodeObj *pDnode);
void mgmtStartBalanceTimer(int mseconds); void mgmtStartBalanceTimer(int64_t mseconds);
void mgmtSetDnodeOfflineOnSdbChanged(); void mgmtSetDnodeOfflineOnSdbChanged();
void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp); void mgmtUpdateVgroupState(SVgObj *pVgroup, int lbStatus, int srcIp);
bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode); bool mgmtAddVnode(SVgObj *pVgroup, SDnodeObj *pSrcDnode, SDnodeObj *pDestDnode);

View File

@ -37,6 +37,6 @@ int32_t mgmtRetrieveMetersFromMetric(SMetricMetaMsg* pInfo, int32_t tableIndex,
int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes); int32_t mgmtDoJoin(SMetricMetaMsg* pMetricMetaMsg, tQueryResultset* pRes);
void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pInfo, int32_t index, tQueryResultset* pRes); void mgmtReorganizeMetersInMetricMeta(SMetricMetaMsg* pInfo, int32_t index, tQueryResultset* pRes);
bool tSkipListNodeFilterCallback(struct tSkipListNode *pNode, void *param); bool tSkipListNodeFilterCallback(const void *pNode, void *param);
#endif //TBASE_MGMTUTIL_H #endif //TBASE_MGMTUTIL_H

View File

@ -26,9 +26,6 @@
#include "tglobalcfg.h" #include "tglobalcfg.h"
#include "vnode.h" #include "vnode.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverflow"
SModule tsModule[TSDB_MOD_MAX] = {0}; SModule tsModule[TSDB_MOD_MAX] = {0};
uint32_t tsModuleStatus = 0; uint32_t tsModuleStatus = 0;
pthread_mutex_t dmutex; pthread_mutex_t dmutex;
@ -219,5 +216,3 @@ void dnodeCountRequest(SCountInfo *info) {
info->selectReqNum = atomic_exchange_32(&vnodeSelectReqNum, 0); info->selectReqNum = atomic_exchange_32(&vnodeSelectReqNum, 0);
info->insertReqNum = atomic_exchange_32(&vnodeInsertReqNum, 0); info->insertReqNum = atomic_exchange_32(&vnodeInsertReqNum, 0);
} }
#pragma GCC diagnostic pop

View File

@ -54,8 +54,8 @@ void mgmtDbActionInit() {
} }
void *mgmtDbAction(char action, void *row, char *str, int size, int *ssize) { void *mgmtDbAction(char action, void *row, char *str, int size, int *ssize) {
if (mgmtDbActionFp[action] != NULL) { if (mgmtDbActionFp[(uint8_t)action] != NULL) {
return (*(mgmtDbActionFp[action]))(row, str, size, ssize); return (*(mgmtDbActionFp[(uint8_t)action]))(row, str, size, ssize);
} }
return NULL; return NULL;
} }

View File

@ -59,7 +59,7 @@ void mgmtCalcNumOfFreeVnodes(SDnodeObj *pDnode) {
if (pVload->vgId != 0) { if (pVload->vgId != 0) {
mTrace("%d-dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s", mTrace("%d-dnode:%s, calc free vnodes, exist vnode:%d, vgroup:%d, state:%d %s, dropstate:%d %s, syncstatus:%d %s",
totalVnodes, taosIpStr(pDnode->privateIp), i, pVload->vgId, totalVnodes, taosIpStr(pDnode->privateIp), i, pVload->vgId,
pVload->status, taosGetDnodeStatusStr(pVload->status), pVload->status, taosGetVnodeStatusStr(pVload->status),
pVload->dropStatus, taosGetVnodeDropStatusStr(pVload->dropStatus), pVload->dropStatus, taosGetVnodeDropStatusStr(pVload->dropStatus),
pVload->syncStatus, taosGetVnodeSyncStatusStr(pVload->syncStatus)); pVload->syncStatus, taosGetVnodeSyncStatusStr(pVload->syncStatus));
totalVnodes++; totalVnodes++;
@ -461,7 +461,6 @@ int mgmtRetrieveVnodes(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
char * pWrite; char * pWrite;
int cols = 0; int cols = 0;
char ipstr[20];
if (0 == rows) return 0; if (0 == rows) return 0;

View File

@ -418,8 +418,8 @@ void *mgmtMeterActionAfterBatchUpdate(void *row, char *str, int size, int *ssize
} }
void *mgmtMeterAction(char action, void *row, char *str, int size, int *ssize) { void *mgmtMeterAction(char action, void *row, char *str, int size, int *ssize) {
if (mgmtMeterActionFp[action] != NULL) { if (mgmtMeterActionFp[(uint8_t)action] != NULL) {
return (*(mgmtMeterActionFp[action]))(row, str, size, ssize); return (*(mgmtMeterActionFp[(uint8_t)action]))(row, str, size, ssize);
} }
return NULL; return NULL;
} }

View File

@ -23,12 +23,6 @@
#include "tlog.h" #include "tlog.h"
#include "tstatus.h" #include "tstatus.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverflow"
#pragma GCC diagnostic ignored "-Wpointer-sign"
#pragma GCC diagnostic ignored "-Wint-conversion"
#define MAX_LEN_OF_METER_META (sizeof(SMultiMeterMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS + sizeof(SSchema) * TSDB_MAX_TAGS + TSDB_MAX_TAGS_LEN) #define MAX_LEN_OF_METER_META (sizeof(SMultiMeterMeta) + sizeof(SSchema) * TSDB_MAX_COLUMNS + sizeof(SSchema) * TSDB_MAX_TAGS + TSDB_MAX_TAGS_LEN)
void * pShellConn = NULL; void * pShellConn = NULL;
@ -695,7 +689,7 @@ int mgmtProcessAlterUserMsg(char *pMsg, int msgLen, SConnObj *pConn) {
(strcmp(pConn->pUser->user, "root") == 0)) { (strcmp(pConn->pUser->user, "root") == 0)) {
if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) { if ((pAlter->flag & TSDB_ALTER_USER_PASSWD) != 0) {
memset(pUser->pass, 0, sizeof(pUser->pass)); memset(pUser->pass, 0, sizeof(pUser->pass));
taosEncryptPass(pAlter->pass, strlen(pAlter->pass), pUser->pass); taosEncryptPass((uint8_t *)pAlter->pass, strlen(pAlter->pass), pUser->pass);
} }
if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) { if ((pAlter->flag & TSDB_ALTER_USER_PRIVILEGES) != 0) {
if (pAlter->privilege == 1) { // super if (pAlter->privilege == 1) { // super
@ -840,11 +834,11 @@ int mgmtProcessShowMsg(char *pMsg, int msgLen, SConnObj *pConn) {
pShowRsp->qhandle = (uint64_t)pShow; // qhandle; pShowRsp->qhandle = (uint64_t)pShow; // qhandle;
pConn->qhandle = pShowRsp->qhandle; pConn->qhandle = pShowRsp->qhandle;
code = (*mgmtGetMetaFp[pShowMsg->type])(&pShowRsp->meterMeta, pShow, pConn); code = (*mgmtGetMetaFp[(uint8_t)pShowMsg->type])(&pShowRsp->meterMeta, pShow, pConn);
if (code == 0) { if (code == 0) {
pMsg += sizeof(SShowRspMsg) + sizeof(SSchema) * pShow->numOfColumns; pMsg += sizeof(SShowRspMsg) + sizeof(SSchema) * pShow->numOfColumns;
} else { } else {
mError("pShow:%p, type:%d %s, failed to get Meta, code:%d", pShow, pShowMsg->type, taosMsg[pShowMsg->type], code); mError("pShow:%p, type:%d %s, failed to get Meta, code:%d", pShow, pShowMsg->type, taosMsg[(uint8_t)pShowMsg->type], code);
free(pShow); free(pShow);
} }
} }
@ -915,7 +909,7 @@ int mgmtProcessRetrieveMsg(char *pMsg, int msgLen, SConnObj *pConn) {
// if free flag is set, client wants to clean the resources // if free flag is set, client wants to clean the resources
if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE) if ((pRetrieve->free & TSDB_QUERY_TYPE_FREE_RESOURCE) != TSDB_QUERY_TYPE_FREE_RESOURCE)
rowsRead = (*mgmtRetrieveFp[pShow->type])(pShow, pRsp->data, rowsToRead, pConn); rowsRead = (*mgmtRetrieveFp[(uint8_t)pShow->type])(pShow, pRsp->data, rowsToRead, pConn);
if (rowsRead < 0) { if (rowsRead < 0) {
rowsRead = 0; rowsRead = 0;
@ -931,7 +925,7 @@ int mgmtProcessRetrieveMsg(char *pMsg, int msgLen, SConnObj *pConn) {
taosSendMsgToPeer(pConn->thandle, pStart, msgLen); taosSendMsgToPeer(pConn->thandle, pStart, msgLen);
if (rowsToRead == 0) { if (rowsToRead == 0) {
uintptr_t oldSign = atomic_val_compare_exchange_ptr(&pShow->signature, pShow, 0); uintptr_t oldSign = (uintptr_t)atomic_val_compare_exchange_ptr(&pShow->signature, pShow, 0);
if (oldSign != (uintptr_t)pShow) { if (oldSign != (uintptr_t)pShow) {
return msgLen; return msgLen;
} }
@ -1139,8 +1133,9 @@ void mgmtEstablishConn(SConnObj *pConn) {
} }
} }
uint32_t temp; int32_t tempint32;
taosGetRpcConnInfo(pConn->thandle, &temp, &pConn->ip, &pConn->port, &temp, &temp); uint32_t tempuint32;
taosGetRpcConnInfo(pConn->thandle, &tempuint32, &pConn->ip, &pConn->port, &tempint32, &tempint32);
mgmtAddConnIntoAcct(pConn); mgmtAddConnIntoAcct(pConn);
} }
@ -1368,5 +1363,3 @@ void mgmtInitProcessShellMsg() {
mgmtProcessShellMsg[TSDB_MSG_TYPE_KILL_STREAM] = mgmtProcessKillStreamMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_KILL_STREAM] = mgmtProcessKillStreamMsg;
mgmtProcessShellMsg[TSDB_MSG_TYPE_KILL_CONNECTION] = mgmtProcessKillConnectionMsg; mgmtProcessShellMsg[TSDB_MSG_TYPE_KILL_CONNECTION] = mgmtProcessKillConnectionMsg;
} }
#pragma GCC diagnostic pop

View File

@ -203,7 +203,7 @@ static bool mgmtTablenameFilterCallback(tSkipListNode* pNode, void* param) {
static void mgmtRetrieveFromLikeOptr(tQueryResultset* pRes, const char* str, STabObj* pMetric) { static void mgmtRetrieveFromLikeOptr(tQueryResultset* pRes, const char* str, STabObj* pMetric) {
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
SMeterNameFilterSupporter supporter = {info, str}; SMeterNameFilterSupporter supporter = {info, (char*) str};
pRes->num = pRes->num =
tSkipListIterateList(pMetric->pSkipList, (tSkipListNode***)&pRes->pRes, mgmtTablenameFilterCallback, &supporter); tSkipListIterateList(pMetric->pSkipList, (tSkipListNode***)&pRes->pRes, mgmtTablenameFilterCallback, &supporter);
@ -230,7 +230,7 @@ static void mgmtFilterByTableNameCond(tQueryResultset* pRes, char* condStr, int3
free(str); free(str);
} }
static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param) { UNUSED_FUNC static bool mgmtJoinFilterCallback(tSkipListNode* pNode, void* param) {
SJoinSupporter* pSupporter = (SJoinSupporter*)param; SJoinSupporter* pSupporter = (SJoinSupporter*)param;
SSchema s = {0}; SSchema s = {0};
@ -639,7 +639,8 @@ static void getTagColumnInfo(SSyntaxTreeFilterSupporter* pSupporter, SSchema* pS
} }
} }
void filterPrepare(tSQLBinaryExpr* pExpr, void* param) { void filterPrepare(void* expr, void* param) {
tSQLBinaryExpr *pExpr = (tSQLBinaryExpr*) expr;
if (pExpr->info != NULL) { if (pExpr->info != NULL) {
return; return;
} }
@ -691,7 +692,9 @@ static int32_t mgmtFilterMeterByIndex(STabObj* pMetric, tQueryResultset* pRes, c
return TSDB_CODE_OPS_NOT_SUPPORT; return TSDB_CODE_OPS_NOT_SUPPORT;
} else { // query according to the binary expression } else { // query according to the binary expression
SSyntaxTreeFilterSupporter s = {.pTagSchema = pTagSchema, .numOfTags = pMetric->numOfTags}; SSyntaxTreeFilterSupporter s = {.pTagSchema = pTagSchema, .numOfTags = pMetric->numOfTags};
SBinaryFilterSupp supp = {.fp = tSkipListNodeFilterCallback, .setupInfoFn = filterPrepare, .pExtInfo = &s}; SBinaryFilterSupp supp = {.fp = (__result_filter_fn_t)tSkipListNodeFilterCallback,
.setupInfoFn = (__do_filter_suppl_fn_t)filterPrepare,
.pExtInfo = &s};
tSQLBinaryExprTraverse(pExpr, pMetric->pSkipList, pRes, &supp); tSQLBinaryExprTraverse(pExpr, pMetric->pSkipList, pRes, &supp);
tSQLBinaryExprDestroy(&pExpr, tSQLListTraverseDestroyInfo); tSQLBinaryExprDestroy(&pExpr, tSQLListTraverseDestroyInfo);
@ -791,9 +794,10 @@ static char* getTagValueFromMeter(STabObj* pMeter, int32_t offset, void* param)
} }
} }
bool tSkipListNodeFilterCallback(tSkipListNode* pNode, void* param) { bool tSkipListNodeFilterCallback(const void* pNode, void* param) {
tQueryInfo* pInfo = (tQueryInfo*)param; tQueryInfo* pInfo = (tQueryInfo*)param;
STabObj* pMeter = (STabObj*)pNode->pData; STabObj* pMeter = (STabObj*)(((tSkipListNode*)pNode)->pData);
char name[TSDB_METER_NAME_LEN + 1] = {0}; char name[TSDB_METER_NAME_LEN + 1] = {0};
char* val = getTagValueFromMeter(pMeter, pInfo->offset, name); char* val = getTagValueFromMeter(pMeter, pInfo->offset, name);

View File

@ -54,8 +54,8 @@ void mgmtUserActionInit() {
} }
void *mgmtUserAction(char action, void *row, char *str, int size, int *ssize) { void *mgmtUserAction(char action, void *row, char *str, int size, int *ssize) {
if (mgmtUserActionFp[action] != NULL) { if (mgmtUserActionFp[(uint8_t)action] != NULL) {
return (*(mgmtUserActionFp[action]))(row, str, size, ssize); return (*(mgmtUserActionFp[(uint8_t)action]))(row, str, size, ssize);
} }
return NULL; return NULL;
} }

View File

@ -55,8 +55,8 @@ void mgmtVgroupActionInit() {
} }
void *mgmtVgroupAction(char action, void *row, char *str, int size, int *ssize) { void *mgmtVgroupAction(char action, void *row, char *str, int size, int *ssize) {
if (mgmtVgroupActionFp[action] != NULL) { if (mgmtVgroupActionFp[(uint8_t)action] != NULL) {
return (*(mgmtVgroupActionFp[action]))(row, str, size, ssize); return (*(mgmtVgroupActionFp[(uint8_t)action]))(row, str, size, ssize);
} }
return NULL; return NULL;
} }

View File

@ -187,13 +187,13 @@ int vnodeCreateNeccessaryFiles(SVnodeObj *pVnode) {
if (pVnode->lastKeyOnFile == 0) { if (pVnode->lastKeyOnFile == 0) {
if (pCfg->daysPerFile == 0) pCfg->daysPerFile = 10; if (pCfg->daysPerFile == 0) pCfg->daysPerFile = 10;
pVnode->fileId = pVnode->firstKey / tsMsPerDay[pVnode->cfg.precision] / pCfg->daysPerFile; pVnode->fileId = pVnode->firstKey / tsMsPerDay[(uint8_t)pVnode->cfg.precision] / pCfg->daysPerFile;
pVnode->lastKeyOnFile = (int64_t)(pVnode->fileId + 1) * pCfg->daysPerFile * tsMsPerDay[pVnode->cfg.precision] - 1; pVnode->lastKeyOnFile = (int64_t)(pVnode->fileId + 1) * pCfg->daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision] - 1;
pVnode->numOfFiles = 1; pVnode->numOfFiles = 1;
if (vnodeCreateEmptyCompFile(vnode, pVnode->fileId) < 0) return -1; if (vnodeCreateEmptyCompFile(vnode, pVnode->fileId) < 0) return -1;
} }
numOfFiles = (pVnode->lastKeyOnFile - pVnode->commitFirstKey) / tsMsPerDay[pVnode->cfg.precision] / pCfg->daysPerFile; numOfFiles = (pVnode->lastKeyOnFile - pVnode->commitFirstKey) / tsMsPerDay[(uint8_t)pVnode->cfg.precision] / pCfg->daysPerFile;
if (pVnode->commitFirstKey > pVnode->lastKeyOnFile) numOfFiles = -1; if (pVnode->commitFirstKey > pVnode->lastKeyOnFile) numOfFiles = -1;
dTrace("vid:%d, commitFirstKey:%ld lastKeyOnFile:%ld numOfFiles:%d fileId:%d vnodeNumOfFiles:%d", pVnode->vnode, dTrace("vid:%d, commitFirstKey:%ld lastKeyOnFile:%ld numOfFiles:%d fileId:%d vnodeNumOfFiles:%d", pVnode->vnode,
@ -221,15 +221,15 @@ int vnodeCreateNeccessaryFiles(SVnodeObj *pVnode) {
#else #else
return -1; return -1;
#endif #endif
pVnode->lastKeyOnFile += (int64_t)tsMsPerDay[pVnode->cfg.precision] * pCfg->daysPerFile; pVnode->lastKeyOnFile += (int64_t)tsMsPerDay[(uint8_t)pVnode->cfg.precision] * pCfg->daysPerFile;
filesAdded = 1; filesAdded = 1;
numOfFiles = 0; // hacker way numOfFiles = 0; // hacker way
} }
fileId = pVnode->fileId - numOfFiles; fileId = pVnode->fileId - numOfFiles;
pVnode->commitLastKey = pVnode->commitLastKey =
pVnode->lastKeyOnFile - (int64_t)numOfFiles * tsMsPerDay[pVnode->cfg.precision] * pCfg->daysPerFile; pVnode->lastKeyOnFile - (int64_t)numOfFiles * tsMsPerDay[(uint8_t)pVnode->cfg.precision] * pCfg->daysPerFile;
pVnode->commitFirstKey = pVnode->commitLastKey - (int64_t)tsMsPerDay[pVnode->cfg.precision] * pCfg->daysPerFile + 1; pVnode->commitFirstKey = pVnode->commitLastKey - (int64_t)tsMsPerDay[(uint8_t)pVnode->cfg.precision] * pCfg->daysPerFile + 1;
pVnode->commitFileId = fileId; pVnode->commitFileId = fileId;
pVnode->numOfFiles = pVnode->numOfFiles + filesAdded; pVnode->numOfFiles = pVnode->numOfFiles + filesAdded;
@ -244,8 +244,7 @@ int vnodeOpenCommitFiles(SVnodeObj *pVnode, int noTempLast) {
int len = 0; int len = 0;
struct stat filestat; struct stat filestat;
int vnode = pVnode->vnode; int vnode = pVnode->vnode;
int fileId, numOfFiles, filesAdded = 0; int fileId;
SVnodeCfg * pCfg = &pVnode->cfg;
if (vnodeCreateNeccessaryFiles(pVnode) < 0) return -1; if (vnodeCreateNeccessaryFiles(pVnode) < 0) return -1;
@ -1246,7 +1245,7 @@ int vnodeWriteBlockToFile(SMeterObj *pObj, SCompBlock *pCompBlock, SData *data[]
// assert(data[i]->len == points*pObj->schema[i].bytes); // assert(data[i]->len == points*pObj->schema[i].bytes);
if (pCfg->compression) { if (pCfg->compression) {
cdata[i]->len = (*pCompFunc[pObj->schema[i].type])(data[i]->data, points * pObj->schema[i].bytes, points, cdata[i]->len = (*pCompFunc[(uint8_t)pObj->schema[i].type])(data[i]->data, points * pObj->schema[i].bytes, points,
cdata[i]->data, pObj->schema[i].bytes*pObj->pointsPerFileBlock+EXTRA_BYTES, cdata[i]->data, pObj->schema[i].bytes*pObj->pointsPerFileBlock+EXTRA_BYTES,
pCfg->compression, buffer, bufferSize); pCfg->compression, buffer, bufferSize);
fields[i].len = cdata[i]->len; fields[i].len = cdata[i]->len;
@ -1338,7 +1337,7 @@ int vnodeSearchPointInFile(SMeterObj *pObj, SQuery *pQuery) {
if (pVnode->numOfFiles <= 0) return 0; if (pVnode->numOfFiles <= 0) return 0;
SVnodeCfg *pCfg = &pVnode->cfg; SVnodeCfg *pCfg = &pVnode->cfg;
delta = (int64_t)pCfg->daysPerFile * tsMsPerDay[pVnode->cfg.precision]; delta = (int64_t)pCfg->daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision];
latest = pObj->lastKeyOnFile; latest = pObj->lastKeyOnFile;
oldest = (pVnode->fileId - pVnode->numOfFiles + 1) * delta; oldest = (pVnode->fileId - pVnode->numOfFiles + 1) * delta;

View File

@ -146,7 +146,7 @@ int vnodeFindKeyInCache(SImportInfo *pImport, int order) {
void vnodeGetValidDataRange(int vnode, TSKEY now, TSKEY *minKey, TSKEY *maxKey) { void vnodeGetValidDataRange(int vnode, TSKEY now, TSKEY *minKey, TSKEY *maxKey) {
SVnodeObj *pVnode = vnodeList + vnode; SVnodeObj *pVnode = vnodeList + vnode;
int64_t delta = pVnode->cfg.daysPerFile * tsMsPerDay[pVnode->cfg.precision]; int64_t delta = pVnode->cfg.daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision];
int fid = now / delta; int fid = now / delta;
*minKey = (fid - pVnode->maxFiles + 1) * delta; *minKey = (fid - pVnode->maxFiles + 1) * delta;
*maxKey = (fid + 2) * delta - 1; *maxKey = (fid + 2) * delta - 1;
@ -682,7 +682,7 @@ static int vnodeMergeDataIntoFile(SImportInfo *pImport, const char *payload, int
SCacheInfo * pInfo = (SCacheInfo *)(pObj->pCache); SCacheInfo * pInfo = (SCacheInfo *)(pObj->pCache);
TSKEY lastKeyImported = 0; TSKEY lastKeyImported = 0;
TSKEY delta = pVnode->cfg.daysPerFile * tsMsPerDay[pVnode->cfg.precision]; TSKEY delta = pVnode->cfg.daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision];
TSKEY minFileKey = fid * delta; TSKEY minFileKey = fid * delta;
TSKEY maxFileKey = minFileKey + delta - 1; TSKEY maxFileKey = minFileKey + delta - 1;
TSKEY firstKey = KEY_AT_INDEX(payload, pObj->bytesPerPoint, 0); TSKEY firstKey = KEY_AT_INDEX(payload, pObj->bytesPerPoint, 0);
@ -1499,7 +1499,7 @@ int vnodeImportDataToFiles(SImportInfo *pImport, char *payload, const int rows)
SMeterObj *pObj = (SMeterObj *)(pImport->pObj); SMeterObj *pObj = (SMeterObj *)(pImport->pObj);
SVnodeObj *pVnode = vnodeList + pObj->vnode; SVnodeObj *pVnode = vnodeList + pObj->vnode;
int64_t delta = pVnode->cfg.daysPerFile * tsMsPerDay[pVnode->cfg.precision]; int64_t delta = pVnode->cfg.daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision];
int sfid = KEY_AT_INDEX(payload, pObj->bytesPerPoint, 0) / delta; int sfid = KEY_AT_INDEX(payload, pObj->bytesPerPoint, 0) / delta;
int efid = KEY_AT_INDEX(payload, pObj->bytesPerPoint, rows - 1) / delta; int efid = KEY_AT_INDEX(payload, pObj->bytesPerPoint, rows - 1) / delta;

View File

@ -26,8 +26,6 @@
#include "vnodeUtil.h" #include "vnodeUtil.h"
#include "tstatus.h" #include "tstatus.h"
#pragma GCC diagnostic ignored "-Wpointer-sign"
#define VALID_TIMESTAMP(key, curKey, prec) (((key) >= 0) && ((key) <= ((curKey) + 36500 * tsMsPerDay[prec]))) #define VALID_TIMESTAMP(key, curKey, prec) (((key) >= 0) && ((key) <= ((curKey) + 36500 * tsMsPerDay[prec])))
int tsMeterSizeOnFile; int tsMeterSizeOnFile;
@ -604,10 +602,10 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi
TSKEY firstKey = *((TSKEY *)pData); TSKEY firstKey = *((TSKEY *)pData);
TSKEY lastKey = *((TSKEY *)(pData + pObj->bytesPerPoint * (numOfPoints - 1))); TSKEY lastKey = *((TSKEY *)(pData + pObj->bytesPerPoint * (numOfPoints - 1)));
int cfid = now/pVnode->cfg.daysPerFile/tsMsPerDay[pVnode->cfg.precision]; int cfid = now/pVnode->cfg.daysPerFile/tsMsPerDay[(uint8_t)pVnode->cfg.precision];
TSKEY minAllowedKey = (cfid - pVnode->maxFiles + 1)*pVnode->cfg.daysPerFile*tsMsPerDay[pVnode->cfg.precision]; TSKEY minAllowedKey = (cfid - pVnode->maxFiles + 1)*pVnode->cfg.daysPerFile*tsMsPerDay[(uint8_t)pVnode->cfg.precision];
TSKEY maxAllowedKey = (cfid + 2)*pVnode->cfg.daysPerFile*tsMsPerDay[pVnode->cfg.precision] - 2; TSKEY maxAllowedKey = (cfid + 2)*pVnode->cfg.daysPerFile*tsMsPerDay[(uint8_t)pVnode->cfg.precision] - 2;
if (firstKey < minAllowedKey || firstKey > maxAllowedKey || lastKey < minAllowedKey || lastKey > maxAllowedKey) { if (firstKey < minAllowedKey || firstKey > maxAllowedKey || lastKey < minAllowedKey || lastKey > maxAllowedKey) {
dError("vid:%d sid:%d id:%s, vnode lastKeyOnFile:%lld, data is out of range, numOfPoints:%d firstKey:%lld lastKey:%lld minAllowedKey:%lld maxAllowedKey:%lld", dError("vid:%d sid:%d id:%s, vnode lastKeyOnFile:%lld, data is out of range, numOfPoints:%d firstKey:%lld lastKey:%lld minAllowedKey:%lld maxAllowedKey:%lld",
pObj->vnode, pObj->sid, pObj->meterId, pVnode->lastKeyOnFile, numOfPoints,firstKey, lastKey, minAllowedKey, maxAllowedKey); pObj->vnode, pObj->sid, pObj->meterId, pVnode->lastKeyOnFile, numOfPoints,firstKey, lastKey, minAllowedKey, maxAllowedKey);
@ -634,7 +632,7 @@ int vnodeInsertPoints(SMeterObj *pObj, char *cont, int contLen, char source, voi
continue; continue;
} }
if (!VALID_TIMESTAMP(*((TSKEY *)pData), tsKey, pVnode->cfg.precision)) { if (!VALID_TIMESTAMP(*((TSKEY *)pData), tsKey, (uint8_t)pVnode->cfg.precision)) {
code = TSDB_CODE_TIMESTAMP_OUT_OF_RANGE; code = TSDB_CODE_TIMESTAMP_OUT_OF_RANGE;
break; break;
} }

View File

@ -252,15 +252,31 @@ static void vnodeSetOpenedFileNames(SQueryFilesInfo* pVnodeFilesInfo) {
SHeaderFileInfo* pCurrentFileInfo = &pVnodeFilesInfo->pFileInfo[pVnodeFilesInfo->current]; SHeaderFileInfo* pCurrentFileInfo = &pVnodeFilesInfo->pFileInfo[pVnodeFilesInfo->current];
// set the full file path for current opened files /*
snprintf(pVnodeFilesInfo->headerFilePath, PATH_MAX, "%sv%df%d.head", pVnodeFilesInfo->dbFilePathPrefix, * set the full file path for current opened files
pVnodeFilesInfo->vnodeId, pCurrentFileInfo->fileID); * the maximum allowed path string length is PATH_MAX in Linux, 100 bytes is used to
* suppress the compiler warnings
*/
char str[PATH_MAX + 100] = {0};
int32_t PATH_WITH_EXTRA = PATH_MAX + 100;
snprintf(pVnodeFilesInfo->dataFilePath, PATH_MAX, "%sv%df%d.data", pVnodeFilesInfo->dbFilePathPrefix, int32_t vnodeId = pVnodeFilesInfo->vnodeId;
pVnodeFilesInfo->vnodeId, pCurrentFileInfo->fileID); int32_t fileId = pCurrentFileInfo->fileID;
snprintf(pVnodeFilesInfo->lastFilePath, PATH_MAX, "%sv%df%d.last", pVnodeFilesInfo->dbFilePathPrefix, int32_t len = snprintf(str, PATH_WITH_EXTRA, "%sv%df%d.head", pVnodeFilesInfo->dbFilePathPrefix, vnodeId, fileId);
pVnodeFilesInfo->vnodeId, pCurrentFileInfo->fileID); assert(len <= PATH_MAX);
strncpy(pVnodeFilesInfo->headerFilePath, str, PATH_MAX);
len = snprintf(str, PATH_WITH_EXTRA, "%sv%df%d.data", pVnodeFilesInfo->dbFilePathPrefix, vnodeId, fileId);
assert(len <= PATH_MAX);
strncpy(pVnodeFilesInfo->dataFilePath, str, PATH_MAX);
len = snprintf(str, PATH_WITH_EXTRA, "%sv%df%d.last", pVnodeFilesInfo->dbFilePathPrefix, vnodeId, fileId);
assert(len <= PATH_MAX);
strncpy(pVnodeFilesInfo->lastFilePath, str, PATH_MAX);
} }
/** /**
@ -1055,7 +1071,7 @@ static void *getGenericDataBlock(SMeterObj *pMeterObj, SQuery *pQuery, int32_t s
static int32_t getFileIdFromKey(int32_t vid, TSKEY key) { static int32_t getFileIdFromKey(int32_t vid, TSKEY key) {
SVnodeObj *pVnode = &vnodeList[vid]; SVnodeObj *pVnode = &vnodeList[vid];
int64_t delta = (int64_t)pVnode->cfg.daysPerFile * tsMsPerDay[pVnode->cfg.precision]; int64_t delta = (int64_t)pVnode->cfg.daysPerFile * tsMsPerDay[(uint8_t)pVnode->cfg.precision];
return (int32_t)(key / delta); // set the starting fileId return (int32_t)(key / delta); // set the starting fileId
} }
@ -2227,7 +2243,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) {
// get maximum time interval in each file // get maximum time interval in each file
static int64_t getOldestKey(int32_t numOfFiles, int64_t fileId, SVnodeCfg *pCfg) { static int64_t getOldestKey(int32_t numOfFiles, int64_t fileId, SVnodeCfg *pCfg) {
int64_t duration = pCfg->daysPerFile * tsMsPerDay[pCfg->precision]; int64_t duration = pCfg->daysPerFile * tsMsPerDay[(uint8_t)pCfg->precision];
return (fileId - numOfFiles + 1) * duration; return (fileId - numOfFiles + 1) * duration;
} }
@ -6331,6 +6347,8 @@ int32_t setIntervalQueryExecutionContext(SMeterQuerySupportObj *pSupporter, int3
tsBufSetCursor(pSupporter->runtimeEnv.pTSBuf, &pMeterQueryInfo->cur); tsBufSetCursor(pSupporter->runtimeEnv.pTSBuf, &pMeterQueryInfo->cur);
} }
} }
return 0;
} }
static void doApplyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pInfo, static void doApplyIntervalQueryOnBlock(SMeterQuerySupportObj *pSupporter, SMeterQueryInfo *pInfo,

View File

@ -1213,8 +1213,8 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
dTrace("QInfo:%p reset signature", pQInfo); dTrace("QInfo:%p reset signature", pQInfo);
TSDB_QINFO_RESET_SIG(pQInfo);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
TSDB_QINFO_RESET_SIG(pQInfo);
return; return;
} }
@ -1235,8 +1235,8 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
dTrace("QInfo:%p reset signature", pQInfo); dTrace("QInfo:%p reset signature", pQInfo);
TSDB_QINFO_RESET_SIG(pQInfo);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
TSDB_QINFO_RESET_SIG(pQInfo);
return; return;
} }
} }
@ -1247,8 +1247,8 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQInfo->pointsRead); pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQInfo->pointsRead);
vnodePrintQueryStatistics(pQInfo->pMeterQuerySupporter); vnodePrintQueryStatistics(pQInfo->pMeterQuerySupporter);
TSDB_QINFO_RESET_SIG(pQInfo);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
TSDB_QINFO_RESET_SIG(pQInfo);
return; return;
} }
@ -1284,8 +1284,8 @@ void vnodeSingleMeterQuery(SSchedMsg *pMsg) {
pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead); pQInfo, pMeterObj->vnode, pMeterObj->sid, pMeterObj->meterId, pQuery->pointsRead);
} }
TSDB_QINFO_RESET_SIG(pQInfo);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
TSDB_QINFO_RESET_SIG(pQInfo);
} }
void vnodeMultiMeterQuery(SSchedMsg *pMsg) { void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
@ -1335,6 +1335,6 @@ void vnodeMultiMeterQuery(SSchedMsg *pMsg) {
vnodePrintQueryStatistics(pSupporter); vnodePrintQueryStatistics(pSupporter);
} }
TSDB_QINFO_RESET_SIG(pQInfo);
sem_post(&pQInfo->dataReady); sem_post(&pQInfo->dataReady);
TSDB_QINFO_RESET_SIG(pQInfo);
} }

View File

@ -26,8 +26,6 @@
#include "vnodeRead.h" #include "vnodeRead.h"
#include "vnodeUtil.h" #include "vnodeUtil.h"
#pragma GCC diagnostic ignored "-Wint-conversion"
int (*pQueryFunc[])(SMeterObj *, SQuery *) = {vnodeQueryFromCache, vnodeQueryFromFile}; int (*pQueryFunc[])(SMeterObj *, SQuery *) = {vnodeQueryFromCache, vnodeQueryFromFile};
int vnodeInterpolationSearchKey(char *pValue, int num, TSKEY key, int order) { int vnodeInterpolationSearchKey(char *pValue, int num, TSKEY key, int order) {
@ -1003,8 +1001,9 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
if (pDestFilterInfo->filterOnBinary) { if (pDestFilterInfo->filterOnBinary) {
pDestFilterInfo->len = htobe64(pFilterInfo->len); pDestFilterInfo->len = htobe64(pFilterInfo->len);
pDestFilterInfo->pz = calloc(1, pDestFilterInfo->len + 1);
memcpy(pDestFilterInfo->pz, pMsg, pDestFilterInfo->len + 1); pDestFilterInfo->pz = (int64_t)calloc(1, pDestFilterInfo->len + 1);
memcpy((void*)pDestFilterInfo->pz, pMsg, pDestFilterInfo->len + 1);
pMsg += (pDestFilterInfo->len + 1); pMsg += (pDestFilterInfo->len + 1);
} else { } else {
pDestFilterInfo->lowerBndi = htobe64(pFilterInfo->lowerBndi); pDestFilterInfo->lowerBndi = htobe64(pFilterInfo->lowerBndi);
@ -1022,8 +1021,7 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
* 1. simple projection query on meters, we only record the pSqlFuncExprs[i].colIdx value * 1. simple projection query on meters, we only record the pSqlFuncExprs[i].colIdx value
* 2. for complex queries, whole SqlExprs object is required. * 2. for complex queries, whole SqlExprs object is required.
*/ */
pQueryMsg->pSqlFuncExprs = malloc(POINTER_BYTES * pQueryMsg->numOfOutputCols); pQueryMsg->pSqlFuncExprs = (int64_t)malloc(POINTER_BYTES * pQueryMsg->numOfOutputCols);
SSqlFuncExprMsg *pExprMsg = (SSqlFuncExprMsg *)pMsg; SSqlFuncExprMsg *pExprMsg = (SSqlFuncExprMsg *)pMsg;
for (int32_t i = 0; i < pQueryMsg->numOfOutputCols; ++i) { for (int32_t i = 0; i < pQueryMsg->numOfOutputCols; ++i) {
@ -1070,7 +1068,7 @@ int32_t vnodeConvertQueryMeterMsg(SQueryMeterMsg *pQueryMsg) {
pQueryMsg->colNameLen = htonl(pQueryMsg->colNameLen); pQueryMsg->colNameLen = htonl(pQueryMsg->colNameLen);
if (hasArithmeticFunction) { // column name array if (hasArithmeticFunction) { // column name array
assert(pQueryMsg->colNameLen > 0); assert(pQueryMsg->colNameLen > 0);
pQueryMsg->colNameList = pMsg; pQueryMsg->colNameList = (int64_t)pMsg;
pMsg += pQueryMsg->colNameLen; pMsg += pQueryMsg->colNameLen;
} }

View File

@ -30,7 +30,6 @@
#include "vnodeStore.h" #include "vnodeStore.h"
#include "tstatus.h" #include "tstatus.h"
#pragma GCC diagnostic ignored "-Wint-conversion"
extern int tsMaxQueues; extern int tsMaxQueues;
void * pShellServer = NULL; void * pShellServer = NULL;
@ -390,7 +389,7 @@ _query_over:
tfree(pMeterObjList); tfree(pMeterObjList);
ret = vnodeSendQueryRspMsg(pObj, code, pObj->qhandle); ret = vnodeSendQueryRspMsg(pObj, code, pObj->qhandle);
free(pQueryMsg->pSidExtInfo); tfree(pQueryMsg->pSidExtInfo);
for(int32_t i = 0; i < pQueryMsg->numOfCols; ++i) { for(int32_t i = 0; i < pQueryMsg->numOfCols; ++i) {
vnodeFreeColumnInfo(&pQueryMsg->colList[i]); vnodeFreeColumnInfo(&pQueryMsg->colList[i]);
} }
@ -455,7 +454,7 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
pRsp->precision = htons(timePrec); pRsp->precision = htons(timePrec);
if (code == TSDB_CODE_SUCCESS) { if (code == TSDB_CODE_SUCCESS) {
pRsp->offset = htobe64(vnodeGetOffsetVal(pRetrieve->qhandle)); pRsp->offset = htobe64(vnodeGetOffsetVal((void*)pRetrieve->qhandle));
pRsp->useconds = htobe64(((SQInfo *)(pRetrieve->qhandle))->useconds); pRsp->useconds = htobe64(((SQInfo *)(pRetrieve->qhandle))->useconds);
} else { } else {
pRsp->offset = 0; pRsp->offset = 0;
@ -473,7 +472,7 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) { if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) {
dTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code); dTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code);
vnodeFreeQInfoInQueue(pObj->qhandle); vnodeFreeQInfo(pObj->qhandle, true);
pObj->qhandle = NULL; pObj->qhandle = NULL;
} }
@ -481,8 +480,6 @@ void vnodeExecuteRetrieveReq(SSchedMsg *pSched) {
_exit: _exit:
free(pSched->msg); free(pSched->msg);
return;
} }
int vnodeProcessRetrieveRequest(char *pMsg, int msgLen, SShellObj *pObj) { int vnodeProcessRetrieveRequest(char *pMsg, int msgLen, SShellObj *pObj) {

View File

@ -24,9 +24,6 @@
#include "vnodeUtil.h" #include "vnodeUtil.h"
#include "tstatus.h" #include "tstatus.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic warning "-Woverflow"
int tsMaxVnode = -1; int tsMaxVnode = -1;
int tsOpenVnodes = 0; int tsOpenVnodes = 0;
SVnodeObj *vnodeList = NULL; SVnodeObj *vnodeList = NULL;
@ -386,6 +383,3 @@ void vnodeCalcOpenVnodes() {
void vnodeUpdateHeadFile(int vnode, int oldTables, int newTables) { void vnodeUpdateHeadFile(int vnode, int oldTables, int newTables) {
//todo rewrite the head file with newTables //todo rewrite the head file with newTables
} }
#pragma GCC diagnostic pop

View File

@ -23,8 +23,6 @@
#include "vnodeDataFilterFunc.h" #include "vnodeDataFilterFunc.h"
#include "vnodeUtil.h" #include "vnodeUtil.h"
#pragma GCC diagnostic ignored "-Wint-conversion"
int vnodeCheckFileIntegrity(FILE* fp) { int vnodeCheckFileIntegrity(FILE* fp) {
/* /*
int savedSessions, savedMeterSize; int savedSessions, savedMeterSize;

View File

@ -50,7 +50,7 @@ char *taosBuildReqMsgToMnode(SMgmtObj *pObj, char type) {
} }
int taosSendMsgToMnode(SMgmtObj *pObj, char *msg, int msgLen) { int taosSendMsgToMnode(SMgmtObj *pObj, char *msg, int msgLen) {
dTrace("msg:%s is sent to mnode", taosMsg[*(msg-1)]); dTrace("msg:%s is sent to mnode", taosMsg[(uint8_t)(*(msg-1))]);
/* /*
* Lite version has no message header, so minus one * Lite version has no message header, so minus one
@ -81,7 +81,7 @@ void vnodeProcessMsgFromMgmtSpec(SSchedMsg *sched) {
char msgType = *sched->msg; char msgType = *sched->msg;
char *content = sched->msg + 1; char *content = sched->msg + 1;
dTrace("msg:%s is received from mgmt", taosMsg[msgType]); dTrace("msg:%s is received from mgmt", taosMsg[(uint8_t)msgType]);
vnodeProcessMsgFromMgmt(content, 0, msgType, 0); vnodeProcessMsgFromMgmt(content, 0, msgType, 0);

View File

@ -17,7 +17,7 @@
#include "mgmtBalance.h" #include "mgmtBalance.h"
#include "tstatus.h" #include "tstatus.h"
void mgmtStartBalanceTimer(int mseconds) {} void mgmtStartBalanceTimer(int64_t mseconds) {}
int mgmtInitBalance() { return 0; } int mgmtInitBalance() { return 0; }

View File

@ -61,7 +61,7 @@ char *taosBuildReqMsgToDnode(SDnodeObj *pObj, char type) {
int taosSendSimpleRspToDnode(SDnodeObj *pObj, char rsptype, char code) { return 0; } int taosSendSimpleRspToDnode(SDnodeObj *pObj, char rsptype, char code) { return 0; }
int taosSendMsgToDnode(SDnodeObj *pObj, char *msg, int msgLen) { int taosSendMsgToDnode(SDnodeObj *pObj, char *msg, int msgLen) {
mTrace("msg:%s is sent to dnode", taosMsg[*(msg-1)]); mTrace("msg:%s is sent to dnode", taosMsg[(uint8_t)(*(msg-1))]);
/* /*
* Lite version has no message header, so minus one * Lite version has no message header, so minus one
@ -142,7 +142,7 @@ void mgmtProcessDnodeStatus(void *handle, void *tmrId) {
void mgmtProcessMsgFromDnodeSpec(SSchedMsg *sched) { void mgmtProcessMsgFromDnodeSpec(SSchedMsg *sched) {
char msgType = *sched->msg; char msgType = *sched->msg;
char *content = sched->msg + 1; char *content = sched->msg + 1;
mTrace("msg:%s is received from dnode", taosMsg[msgType]); mTrace("msg:%s is received from dnode", taosMsg[(uint8_t)msgType]);
mgmtProcessMsgFromDnode(content, 0, msgType, mgmtGetDnode(0)); mgmtProcessMsgFromDnode(content, 0, msgType, mgmtGetDnode(0));
free(sched->msg); free(sched->msg);

View File

@ -24,7 +24,7 @@ char* vnodeGetDataDir(int vnode, int fileId) { return dataDir; }
void vnodeAdustVnodeFile(SVnodeObj *pVnode) { void vnodeAdustVnodeFile(SVnodeObj *pVnode) {
// Retention policy here // Retention policy here
int fileId = pVnode->fileId - pVnode->numOfFiles + 1; int fileId = pVnode->fileId - pVnode->numOfFiles + 1;
int cfile = taosGetTimestamp(pVnode->cfg.precision)/pVnode->cfg.daysPerFile/tsMsPerDay[pVnode->cfg.precision]; int cfile = taosGetTimestamp(pVnode->cfg.precision)/pVnode->cfg.daysPerFile/tsMsPerDay[(uint8_t)pVnode->cfg.precision];
while (fileId <= cfile - pVnode->maxFiles) { while (fileId <= cfile - pVnode->maxFiles) {
vnodeRemoveFile(pVnode->vnode, fileId); vnodeRemoveFile(pVnode->vnode, fileId);
pVnode->numOfFiles--; pVnode->numOfFiles--;

View File

@ -25,8 +25,6 @@
#include <stdlib.h> #include <stdlib.h>
#include "tcrc32c.h" #include "tcrc32c.h"
//todo : use the original source code
//#pragma GCC diagnostic ignored "-Wunused-function"
#define POLY 0x82f63b78 #define POLY 0x82f63b78
#define LONG_SHIFT 8192 #define LONG_SHIFT 8192

View File

@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h>
#include "os.h" #include "os.h"
#include "taos.h" #include "taos.h"
#include "taosmsg.h" #include "taosmsg.h"
@ -23,8 +22,6 @@
#include "ttypes.h" #include "ttypes.h"
#include "tutil.h" #include "tutil.h"
//#pragma GCC diagnostic ignored "-Wformat"
#define COLMODEL_GET_VAL(data, schema, allrow, rowId, colId) \ #define COLMODEL_GET_VAL(data, schema, allrow, rowId, colId) \
(data + (schema)->colOffset[colId] * (allrow) + (rowId) * (schema)->pFields[colId].bytes) (data + (schema)->colOffset[colId] * (allrow) + (rowId) * (schema)->pFields[colId].bytes)

View File

@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h>
#include "os.h" #include "os.h"
#include "taosmsg.h" #include "taosmsg.h"

View File

@ -12,11 +12,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h> #include "os.h"
#include <float.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include "tlog.h" #include "tlog.h"
#include "tsdb.h" #include "tsdb.h"

View File

@ -19,8 +19,6 @@
#include "tsocket.h" #include "tsocket.h"
#include "tutil.h" #include "tutil.h"
unsigned int ip2uint(const char *const ip_addr);
/* /*
* Function to get the public ip address of current machine. If get IP * Function to get the public ip address of current machine. If get IP
* successfully, return 0, else, return -1. The return values is ip. * successfully, return 0, else, return -1. The return values is ip.
@ -105,7 +103,7 @@ int taosGetPublicIp(char *const ip) {
} }
// Function converting an IP address string to an unsigned int. // Function converting an IP address string to an unsigned int.
unsigned int ip2uint(const char *const ip_addr) { uint32_t ip2uint(const char *const ip_addr) {
char ip_addr_cpy[20]; char ip_addr_cpy[20];
char ip[5]; char ip[5];

View File

@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h>
#include "os.h" #include "os.h"
#include "tstrbuild.h" #include "tstrbuild.h"

View File

@ -14,7 +14,6 @@
*/ */
#include "os.h" #include "os.h"
#include <inttypes.h>
#include "tlog.h" #include "tlog.h"
#include "tsched.h" #include "tsched.h"
#include "ttime.h" #include "ttime.h"

View File

@ -510,7 +510,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
if ((z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || z[i] == 'y' || if ((z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' || z[i] == 'n' || z[i] == 'y' ||
z[i] == 'w' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'w' || z[i] == 'A' || z[i] == 'S' || z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' ||
z[i] == 'Y' || z[i] == 'W') && z[i] == 'Y' || z[i] == 'W') &&
(isIdChar[(int)(z[i + 1])] == 0)) { (isIdChar[(uint8_t)z[i + 1]] == 0)) {
*tokenType = TK_VARIABLE; *tokenType = TK_VARIABLE;
i += 1; i += 1;
return i; return i;
@ -551,7 +551,7 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
case 't': case 't':
case 'F': case 'F':
case 'f': { case 'f': {
for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(int)(z[i])]; i++) { for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) {
} }
if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) { if ((i == 4 && strncasecmp(z, "true", 4) == 0) || (i == 5 && strncasecmp(z, "false", 5) == 0)) {
@ -560,10 +560,10 @@ uint32_t tSQLGetToken(char* z, uint32_t* tokenType) {
} }
} }
default: { default: {
if (((*z & 0x80) != 0) || !isIdChar[(int)(*z)]) { if (((*z & 0x80) != 0) || !isIdChar[(uint8_t) *z]) {
break; break;
} }
for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(int)(z[i])]; i++) { for (i = 1; ((z[i] & 0x80) == 0) && isIdChar[(uint8_t) z[i]]; i++) {
} }
*tokenType = tSQLKeywordCode(z, i); *tokenType = tSQLKeywordCode(z, i);
return i; return i;

View File

@ -12,7 +12,6 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <inttypes.h>
#include "os.h" #include "os.h"
#include "taos.h" #include "taos.h"
#include "tsdb.h" #include "tsdb.h"
@ -140,7 +139,7 @@ void tVariantCreateFromBinary(tVariant *pVar, char *pz, uint32_t len, uint32_t t
} }
case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length case TSDB_DATA_TYPE_NCHAR: { // here we get the nchar length from raw binary bits length
pVar->nLen = len / TSDB_NCHAR_SIZE; pVar->nLen = len / TSDB_NCHAR_SIZE;
pVar->wpz = malloc((pVar->nLen + 1) * TSDB_NCHAR_SIZE); pVar->wpz = calloc(1, (pVar->nLen + 1) * TSDB_NCHAR_SIZE);
wcsncpy(pVar->wpz, (wchar_t *)pz, pVar->nLen); wcsncpy(pVar->wpz, (wchar_t *)pz, pVar->nLen);
pVar->wpz[pVar->nLen] = 0; pVar->wpz[pVar->nLen] = 0;
@ -971,7 +970,7 @@ void setNullN(char *val, int32_t type, int32_t bytes, int32_t numOfElems) {
} }
} }
void assignVal(char *val, char *src, int32_t len, int32_t type) { void assignVal(char *val, const char *src, int32_t len, int32_t type) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_INT: { case TSDB_DATA_TYPE_INT: {
*((int32_t *)val) = GET_INT32_VAL(src); *((int32_t *)val) = GET_INT32_VAL(src);
@ -999,6 +998,14 @@ void assignVal(char *val, char *src, int32_t len, int32_t type) {
*((int8_t *)val) = GET_INT8_VAL(src); *((int8_t *)val) = GET_INT8_VAL(src);
break; break;
}; };
case TSDB_DATA_TYPE_BINARY: {
strncpy(val, src, len);
break;
};
case TSDB_DATA_TYPE_NCHAR: {
wcsncpy((wchar_t*)val, (wchar_t*)src, len / TSDB_NCHAR_SIZE);
break;
};
default: { default: {
memcpy(val, src, len); memcpy(val, src, len);
break; break;

View File

@ -444,7 +444,7 @@ bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len)
#endif #endif
} }
bool taosValidateEncodec(char *encodec) { bool taosValidateEncodec(const char *encodec) {
#ifdef USE_LIBICONV #ifdef USE_LIBICONV
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC); iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
if (cd == (iconv_t)(-1)) { if (cd == (iconv_t)(-1)) {

View File

@ -1,5 +1,5 @@
char version[64] = "1.6.4.1"; char version[64] = "1.6.4.2";
char compatible_version[64] = "1.6.1.0"; char compatible_version[64] = "1.6.1.0";
char gitinfo[128] = "27f51a5cea1bdcb0e7b2ef0df5649e59e6ae38ed"; char gitinfo[128] = "b9a62d60dc1d4a41452a9bc94e3a0924485c3a75";
char gitinfoOfInternal[128] = "afd592a8d3aedfd7e90d5510840ba3fc73e36160"; char gitinfoOfInternal[128] = "e6445addc77e8c96dcb57221fa6ab5dcde0458f7";
char buildinfo[512] = "Built by root at 2019-12-09 17:39"; char buildinfo[512] = "Built by root at 2019-12-10 10:31";