From 74b1797cfab98962a7d61d489c704b957381b41f Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 11 Jun 2021 18:39:07 +0800 Subject: [PATCH 001/100] filter feature --- src/client/src/tscSQLParser.c | 7 +- src/query/inc/qFilter.h | 94 ++++++++++++ src/query/inc/qTableMeta.h | 3 + src/query/src/qFilter.c | 272 ++++++++++++++++++++++++++++++++++ 4 files changed, 375 insertions(+), 1 deletion(-) create mode 100644 src/query/inc/qFilter.h create mode 100644 src/query/src/qFilter.c diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 298bd8dacc..a1f9772b29 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -36,6 +36,7 @@ #include "ttype.h" #include "qUtil.h" #include "qPlan.h" +#include "qFilter.h" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" @@ -4594,6 +4595,10 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE SArray* colList = taosArrayInit(10, sizeof(SColIndex)); ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL); + if (ret == TSDB_CODE_SUCCESS) { + ret = filterInitFromTree(p, &pQueryInfo->colFilter, (int32_t)taosArrayGetSize(colList)); + } + SBufferWriter bw = tbufInitWriter(NULL, false); TRY(0) { @@ -4627,7 +4632,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE } tSqlExprDestroy(p1); - tExprTreeDestroy(p, NULL); + //tExprTreeDestroy(p, NULL); TODO taosArrayDestroy(colList); if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0 && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h new file mode 100644 index 0000000000..a8a1ffc5ec --- /dev/null +++ b/src/query/inc/qFilter.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_QFILTER_H +#define TDENGINE_QFILTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "texpr.h" + +enum { + F_FIELD_COLUMN = 0, + F_FIELD_VALUE, + F_FIELD_MAX +}; + +typedef struct OptrStr { + uint16_t optr; + char *str; +} OptrStr; + + +typedef struct SFilterField { + uint16_t type; + void* desc; + void* data; +} SFilterField; + +typedef struct SFilterFields { + uint16_t num; + SFilterField *fields; +} SFilterFields; + +typedef struct SFilterGroup { + uint16_t unitNum; + uint16_t *unitIdxs; + uint8_t *unitFlags; // !unit result +} SFilterGroup; + +typedef struct SFilterCompare { + __compar_fn_t pCompareFunc; + uint8_t optr; +} SFilterCompare; + +typedef struct SFilterUnit { + SFilterCompare compare; + SFilterField *left; + SFilterField *right; +} SFilterUnit; + +typedef struct SFilterInfo { + uint16_t unitNum; + uint16_t groupNum; + SFilterFields fileds[F_FIELD_MAX]; + SFilterGroup *groups; + SFilterUnit *units; + uint8_t *unitRes; // result + uint8_t *unitFlags; // got result +} SFilterInfo; + +#define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0) +#define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0) +#define ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _err_return; } } while (0) + +#define CHK_RETV(c) do { if (c) { return; } } while (0) +#define CHK_RET(c, r) do { if (c) { return r; } } while (0) +#define CHK_LRETV(c,...) do { if (c) { qError(__VA_ARGS__); return; } } while (0) +#define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) + +typedef int32_t(*filter_desc_compare_func)(const void *, const void *); + + +extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo *info, int32_t colSize); + + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_QFILTER_H diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 1fd78ed324..0b402c31ab 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -3,6 +3,7 @@ #include "tsdb.h" //todo tsdb should not be here #include "qSqlparser.h" +#include "qFilter.h" typedef struct SFieldInfo { int16_t numOfOutput; // number of column in result @@ -105,6 +106,8 @@ typedef struct SQueryInfo { SLimitVal slimit; STagCond tagCond; + SFilterInfo colFilter; + SOrderVal order; int16_t fillType; // final result fill type int16_t numOfTables; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c new file mode 100644 index 0000000000..c9dcd3a348 --- /dev/null +++ b/src/query/src/qFilter.c @@ -0,0 +1,272 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +#include "os.h" +#include "queryLog.h" +#include "qFilter.h" + +OptrStr gOptrStr[] = { + {TSDB_RELATION_INVALID, "invalid"}, + {TSDB_RELATION_LESS, "<"}, + {TSDB_RELATION_GREATER, ">"}, + {TSDB_RELATION_EQUAL, "="}, + {TSDB_RELATION_LESS_EQUAL, "<="}, + {TSDB_RELATION_GREATER_EQUAL, ">="}, + {TSDB_RELATION_NOT_EQUAL, "!="}, + {TSDB_RELATION_LIKE, "like"}, + {TSDB_RELATION_ISNULL, "is null"}, + {TSDB_RELATION_NOTNULL, "not null"}, + {TSDB_RELATION_IN, "in"}, + {TSDB_RELATION_AND, "and"}, + {TSDB_RELATION_OR, "or"}, + {TSDB_RELATION_NOT, "not"} +}; + +static FORCE_INLINE int32_t filterFieldColDescCompare(const void *desc1, const void *desc2) { + const SSchema *sch1 = desc1; + const SSchema *sch2 = desc2; + + return sch1->colId != sch2->colId; +} + +static FORCE_INLINE int32_t filterFieldValDescCompare(const void *desc1, const void *desc2) { + const tVariant *val1 = desc1; + const tVariant *val2 = desc2; + + return tVariantCompare(val1, val2); +} + + +filter_desc_compare_func gDescCompare [F_FIELD_MAX] = { + filterFieldColDescCompare, + filterFieldValDescCompare +}; + + +int32_t filterMergeGroup(SArray* group, SArray* left, SArray* right) { + int32_t leftSize = (int32_t)taosArrayGetSize(left); + int32_t rightSize = (int32_t)taosArrayGetSize(right); + + CHK_LRET(taosArrayGetSize(left) <= 0, TSDB_CODE_QRY_APP_ERROR, "empty group"); + CHK_LRET(taosArrayGetSize(right) <= 0, TSDB_CODE_QRY_APP_ERROR, "empty group"); + + SFilterGroup gp = {0}; + + for (int32_t l = 0; l < leftSize; ++l) { + SFilterGroup *gp1 = taosArrayGet(left, l); + + for (int32_t r = 0; r < rightSize; ++r) { + SFilterGroup *gp2 = taosArrayGet(right, r); + + gp.unitNum = gp1->unitNum + gp2->unitNum; + gp.unitIdxs = calloc(gp.unitNum, sizeof(*gp.unitIdxs)); + memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); + memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); + + gp.unitFlags = NULL; + + taosArrayPush(group, &gp); + } + } + + + return TSDB_CODE_SUCCESS; +} + +int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { + for (uint16_t i = 0; i < fields->num; ++i) { + if (0 == gDescCompare[type](fields->fields[i].desc, v)) { + return i; + } + } + + return -1; +} + + +SFilterField* filterAddField(SFilterInfo *info, tExprNode *node) { + CHK_LRET(node == NULL, NULL, "empty node"); + CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, NULL, "invalid nodeType"); + int32_t type, idx = -1; + uint16_t *num; + void *v; + + if (node->nodeType == TSQL_NODE_COL) { + type = F_FIELD_COLUMN; + v = node->pSchema; + } else { + type = F_FIELD_VALUE; + v = node->pVal; + } + + num = &info->fileds[type].num; + + if (num > 0) { + idx = filterGetFiled(&info->fileds[type], type, v); + } + + if (idx < 0) { + idx = *num; + info->fileds[type].fields[idx].type = type; + info->fileds[type].fields[idx].desc = v; + ++(*num); + } + + return &info->fileds[type].fields[idx]; +} + +int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterField *left, SFilterField *right) { + info->units[info->unitNum].compare.optr = optr; + info->units[info->unitNum].left = left; + info->units[info->unitNum].right = right; + + ++info->unitNum; + + return TSDB_CODE_SUCCESS; +} + +int32_t filterAddGroup(SFilterGroup *group, uint16_t unitIdx) { + group->unitNum = 1; + group->unitIdxs= calloc(1, sizeof(*group->unitIdxs)); + group->unitIdxs[0] = unitIdx; + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { + int32_t code = TSDB_CODE_SUCCESS; + SArray* leftGroup = NULL; + SArray* rightGroup = NULL; + + if (tree->nodeType != TSQL_NODE_EXPR) { + qError("invalid nodeType:%d", tree->nodeType); + return TSDB_CODE_QRY_APP_ERROR; + } + + if (tree->_node.optr == TSDB_RELATION_AND) { + leftGroup = taosArrayInit(4, sizeof(SFilterGroup)); + rightGroup = taosArrayInit(4, sizeof(SFilterGroup)); + ERR_JRET(filterTreeToGroup(tree->_node.pLeft, info, leftGroup)); + ERR_JRET(filterTreeToGroup(tree->_node.pRight, info, rightGroup)); + + ERR_JRET(filterMergeGroup(group, leftGroup, rightGroup)); + + return TSDB_CODE_SUCCESS; + } + + if (tree->_node.optr == TSDB_RELATION_OR) { + ERR_RET(filterTreeToGroup(tree->_node.pLeft, info, group)); + ERR_RET(filterTreeToGroup(tree->_node.pRight, info, group)); + + return TSDB_CODE_SUCCESS; + } + + SFilterField *left = filterAddField(info, tree->_node.pLeft); + SFilterField *right = filterAddField(info, tree->_node.pRight); + + filterAddUnit(info, tree->_node.optr, left, right); + + SFilterGroup fgroup = {0}; + filterAddGroup(&fgroup, info->unitNum - 1); + + taosArrayPush(group, &fgroup); + +_err_return: + + taosArrayDestroy(leftGroup); + taosArrayDestroy(rightGroup); + + return code; +} + +void filterDumpInfoToString(SFilterInfo *info) { + CHK_LRETV(info == NULL, "FilterInfo: empty"); + + qDebug("FilterInfo:"); + qDebug("Col F Num:%u", info->fileds[F_FIELD_COLUMN].num); + for (uint16_t i = 0; i < info->fileds[F_FIELD_COLUMN].num; ++i) { + SFilterField *field = &info->fileds[F_FIELD_COLUMN].fields[i]; + SSchema *sch = field->desc; + qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); + } + + qDebug("Unit Num:%u", info->unitNum); + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit *unit = &info->units[i]; + SFilterField *left = unit->left; + SFilterField *right = unit->right; + + SSchema *sch = left->desc; + tVariant *var = right->desc; + qDebug("UNIT%d => [%d][%s] %s %" PRId64, i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str, IS_NUMERIC_TYPE(var->nType) ? var->i64 : -1); + } + + qDebug("Group Num:%u", info->groupNum); + for (uint16_t i = 0; i < info->groupNum; ++i) { + SFilterGroup *group = &info->groups[i]; + qDebug("Group%d : unit num[%u]", i, group->unitNum); + + for (uint16_t u = 0; u < group->unitNum; ++u) { + qDebug("unit id:%u", group->unitIdxs[u]); + } + } +} + +int32_t filterInitFromTree(tExprNode* tree, SFilterInfo *info, int32_t colSize) { + int32_t code = TSDB_CODE_SUCCESS; + + CHK_RET(colSize <= 0, code); + CHK_LRET(tree == NULL || info == NULL, TSDB_CODE_QRY_APP_ERROR, "invalid param"); + + SArray* group = taosArrayInit(4, sizeof(SFilterGroup)); + + info->units = calloc(colSize, sizeof(SFilterUnit)); + + info->fileds[F_FIELD_COLUMN].num = 0; + info->fileds[F_FIELD_COLUMN].fields = calloc(colSize, sizeof(SFilterField)); + info->fileds[F_FIELD_VALUE].num = 0; + info->fileds[F_FIELD_VALUE].fields = calloc(colSize, sizeof(SFilterField)); + + code = filterTreeToGroup(tree, info, group); + + ERR_RET(code); + + size_t groupSize = taosArrayGetSize(group); + + info->groupNum = (uint16_t)groupSize; + + if (info->groupNum > 0) { + info->groups = calloc(info->groupNum, sizeof(*info->groups)); + } + + for (size_t i = 0; i < groupSize; ++i) { + SFilterGroup *pg = taosArrayGet(group, i); + info->groups[i].unitNum = pg->unitNum; + info->groups[i].unitIdxs = pg->unitIdxs; + info->groups[i].unitFlags = pg->unitFlags; + } + + filterDumpInfoToString(info); + + return code; +} + +void filterFreeInfo(SFilterInfo *info) { + CHK_RETV(info == NULL); + + //TODO +} + + From bc65d9eba70a4b466f465180517ef4ce98452f9d Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 17 Jun 2021 16:20:01 +0800 Subject: [PATCH 002/100] support column filter --- src/client/inc/tscUtil.h | 1 + src/client/src/tscSQLParser.c | 162 ++++++++++--- src/client/src/tscServer.c | 10 + src/client/src/tscUtil.c | 18 ++ src/inc/taosmsg.h | 1 + src/query/inc/qExecutor.h | 12 +- src/query/inc/qFilter.h | 36 ++- src/query/inc/qTableMeta.h | 7 +- src/query/src/qExecutor.c | 95 +++++++- src/query/src/qFilter.c | 274 ++++++++++++++++++---- src/query/src/queryMain.c | 8 +- tests/script/general/parser/condition.sim | 198 ++++++++++++++++ 12 files changed, 727 insertions(+), 95 deletions(-) create mode 100644 tests/script/general/parser/condition.sim diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 2c4d711520..83d5bb9108 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -338,6 +338,7 @@ char* strdup_throw(const char* str); bool vgroupInfoIdentical(SNewVgroupInfo *pExisted, SVgroupMsg* src); SNewVgroupInfo createNewVgroupInfo(SVgroupMsg *pVgroupMsg); +SCond* tsGetTableFilter(SArray* filters, uint64_t uid); #ifdef __cplusplus } diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index a1f9772b29..56dc921873 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -137,6 +137,7 @@ static int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlE static bool validateDebugFlag(int32_t v); static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo); +static tSqlExpr* extractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo* pQueryInfo, int32_t tableIndex); static bool isTimeWindowQuery(SQueryInfo* pQueryInfo) { return pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0; @@ -3458,10 +3459,10 @@ static int32_t tablenameCondToString(tSqlExpr* pExpr, SStringBuilder* sb) { } enum { - TSQL_EXPR_TS = 0, - TSQL_EXPR_TAG = 1, - TSQL_EXPR_COLUMN = 2, - TSQL_EXPR_TBNAME = 3, + TSQL_EXPR_TS = 1, + TSQL_EXPR_TAG = 2, + TSQL_EXPR_COLUMN = 4, + TSQL_EXPR_TBNAME = 8, }; static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) { @@ -3568,6 +3569,63 @@ static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* return ret; } +static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr) { + int32_t ret = TSDB_CODE_SUCCESS; + + for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { + tSqlExpr* p1 = extractExprForSTable(pCmd, pExpr, pQueryInfo, i); + if (p1 == NULL) { // no query condition on this table + continue; + } + + tExprNode* p = NULL; + //SFilterInfo colFilter = {0}; + + SArray* colList = taosArrayInit(10, sizeof(SColIndex)); + ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL); + //if (ret == TSDB_CODE_SUCCESS) { + // ret = filterInitFromTree(p, &colFilter, (int32_t)taosArrayGetSize(colList)); + //} + + + SBufferWriter bw = tbufInitWriter(NULL, false); + + TRY(0) { + exprTreeToBinary(&bw, p); + } CATCH(code) { + tbufCloseWriter(&bw); + UNUSED(code); + // TODO: more error handling + } END_TRY + + // add to required table column list + STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, i); + int64_t uid = pTableMetaInfo->pTableMeta->id.uid; + + SCond cond = { + .uid = uid, + .len = (int32_t)(tbufTell(&bw)), + .cond = tbufGetData(&bw, true) + }; + + if (pQueryInfo->colCond == NULL) { + pQueryInfo->colCond = taosArrayInit(2, sizeof(SCond)); + } + + taosArrayPush(pQueryInfo->colCond, &cond); + + tSqlExprDestroy(p1); + tExprTreeDestroy(p, NULL); + + if (ret) { + break; + } + } + + return ret; +} + + static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, int32_t relOptr) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; @@ -3967,6 +4025,17 @@ static int32_t setExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, const char* msg return TSDB_CODE_SUCCESS; } +static int32_t setNormalExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, int32_t parentOptr) { + if (*parent != NULL) { + *parent = tSqlExprCreate((*parent), pExpr, parentOptr); + } else { + *parent = pExpr; + } + + return TSDB_CODE_SUCCESS; +} + + static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { const char* msg = "only support is [not] null"; @@ -4001,7 +4070,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t } static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr, - int32_t* type, int32_t parentOptr) { + int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr) { const char* msg1 = "table query cannot use tags filter"; const char* msg2 = "illegal column name"; const char* msg3 = "only one query time range allowed"; @@ -4098,7 +4167,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql } *pExpr = NULL; // remove this expression - *type = TSQL_EXPR_TS; + *type |= TSQL_EXPR_TAG; } else if (index.columnIndex >= tscGetNumOfColumns(pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { // query on tags, check for tag query condition if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { @@ -4123,7 +4192,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - *type = TSQL_EXPR_TBNAME; + *type |= TSQL_EXPR_TAG; *pExpr = NULL; } else { if (pRight != NULL && pRight->tokenId == TK_ID) { // join on tag columns for stable query @@ -4140,17 +4209,17 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql // *pExpr, NULL, parentOptr); } - *type = TSQL_EXPR_TAG; + *type |= TSQL_EXPR_TAG; } } else { // query on other columns - *type = TSQL_EXPR_COLUMN; + *type |= TSQL_EXPR_COLUMN; if (pRight->tokenId == TK_ID) { // other column cannot be served as the join column return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } - ret = setExprToCond(&pCondExpr->pColumnCond, *pExpr, NULL, parentOptr, pQueryInfo->msg); + ret = setNormalExprToCond(columnExpr, *pExpr, parentOptr); *pExpr = NULL; // remove it from expr tree } @@ -4158,12 +4227,16 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql } int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr, - int32_t* type, int32_t parentOptr) { + int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } - const char* msg1 = "query condition between different columns must use 'AND'"; + tSqlExpr *columnLeft = NULL; + tSqlExpr *columnRight = NULL; + int32_t ret = 0; + + const char* msg1 = "query condition between columns and tags/timestamp must use 'AND'"; if ((*pExpr)->flags & (1 << EXPR_FLAG_TS_ERROR)) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -4176,45 +4249,66 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr return TSDB_CODE_TSC_INVALID_OPERATION; } - int32_t leftType = -1; - int32_t rightType = -1; + int32_t leftType = 0; + int32_t rightType = 0; if (!tSqlExprIsParentOfLeaf(*pExpr)) { - int32_t ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->tokenId); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->tokenId, &columnLeft); if (ret != TSDB_CODE_SUCCESS) { - return ret; + goto err_ret; } - ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->tokenId); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->tokenId, &columnRight); if (ret != TSDB_CODE_SUCCESS) { - return ret; + goto err_ret; } /* * if left child and right child do not belong to the same group, the sub * expression is not valid for parent node, it must be TK_AND operator. */ - if (leftType != rightType) { - if ((*pExpr)->tokenId == TK_OR && (leftType + rightType != TSQL_EXPR_TBNAME + TSQL_EXPR_TAG)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); - } + if (((leftType != rightType) || (leftType == (TSQL_EXPR_COLUMN|TSQL_EXPR_TAG ))) && (*pExpr)->tokenId == TK_OR) { + ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + goto err_ret; } - *type = rightType; + if (columnLeft && columnRight) { + setNormalExprToCond(&columnLeft, columnRight, (*pExpr)->tokenId); + + *columnExpr = columnLeft; + } else { + *columnExpr = columnLeft ? columnLeft : columnRight; + } + + *type = leftType|rightType; + return TSDB_CODE_SUCCESS; } exchangeExpr(*pExpr); if (pLeft->tokenId == TK_ID && pRight->tokenId == TK_TIMESTAMP && (pRight->flags & (1 << EXPR_FLAG_TIMESTAMP_VAR))) { - return TSDB_CODE_TSC_INVALID_OPERATION; + ret = TSDB_CODE_TSC_INVALID_OPERATION; + goto err_ret; } if ((pLeft->flags & (1 << EXPR_FLAG_TS_ERROR)) || (pRight->flags & (1 << EXPR_FLAG_TS_ERROR))) { - return TSDB_CODE_TSC_INVALID_OPERATION; + ret = TSDB_CODE_TSC_INVALID_OPERATION; + goto err_ret; } - return handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, parentOptr); + ret = handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, parentOptr, columnExpr); + if (ret) { + goto err_ret; + } + + return TSDB_CODE_SUCCESS; + +err_ret: + + tSqlExprDestroy(columnLeft); + tSqlExprDestroy(columnRight); + return ret; } static void doExtractExprForSTable(SSqlCmd* pCmd, tSqlExpr** pExpr, SQueryInfo* pQueryInfo, tSqlExpr** pOut, int32_t tableIndex) { @@ -4595,9 +4689,9 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE SArray* colList = taosArrayInit(10, sizeof(SColIndex)); ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL); - if (ret == TSDB_CODE_SUCCESS) { - ret = filterInitFromTree(p, &pQueryInfo->colFilter, (int32_t)taosArrayGetSize(colList)); - } + //if (ret == TSDB_CODE_SUCCESS) { + // ret = filterInitFromTree(p, &pQueryInfo->tagFilter, (int32_t)taosArrayGetSize(colList)); + //} SBufferWriter bw = tbufInitWriter(NULL, false); @@ -4632,7 +4726,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE } tSqlExprDestroy(p1); - //tExprTreeDestroy(p, NULL); TODO + tExprTreeDestroy(p, NULL); //TODO taosArrayDestroy(colList); if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0 && !UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { @@ -4763,11 +4857,12 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } int32_t type = 0; - if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId)) != TSDB_CODE_SUCCESS) { + if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId, &condExpr.pColumnCond)) != TSDB_CODE_SUCCESS) { return ret; } tSqlExprCompact(pExpr); + tSqlExprCompact(&condExpr.pColumnCond); // after expression compact, the expression tree is only include tag query condition condExpr.pTagCond = (*pExpr); @@ -4792,6 +4887,11 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq goto PARSE_WHERE_EXIT; } + if ((ret = getColQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr.pColumnCond)) != TSDB_CODE_SUCCESS) { + goto PARSE_WHERE_EXIT; + } + + // 5. other column query condition if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b4c7a64fd0..aca8ed3083 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -888,6 +888,16 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg); } + if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) { + SCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid); + if (pCond != NULL && pCond->cond != NULL) { + pQueryMsg->colCondLen = htons(pCond->len); + memcpy(pMsg, pCond->cond, pCond->len); + + pMsg += pCond->len; + } + } + for (int32_t i = 0; i < query.numOfOutput; ++i) { code = serializeSqlExpr(&query.pExpr1[i].base, pTableMetaInfo, &pMsg, pSql->self, true); if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index c17cd21c42..423dc3dc49 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -118,6 +118,24 @@ SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) { return NULL; } +SCond* tsGetTableFilter(SArray* filters, uint64_t uid) { + if (filters == NULL) { + return NULL; + } + + size_t size = taosArrayGetSize(filters); + for (int32_t i = 0; i < size; ++i) { + SCond* cond = taosArrayGet(filters, i); + + if (uid == cond->uid) { + return cond; + } + } + + return NULL; +} + + void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw) { if (tbufTell(bw) == 0) { return; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index c7fe649748..e269c66bfe 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -484,6 +484,7 @@ typedef struct { SInterval interval; SSessionWindow sw; // session window uint16_t tagCondLen; // tag length in current query + uint16_t colCondLen; // column length in current query uint32_t tbnameCondLen; // table name filter condition string length int16_t numOfGroupCols; // num of group by columns int16_t orderByIdx; diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 955dd734cf..59e32bc754 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -225,8 +225,10 @@ typedef struct SQueryAttr { int32_t numOfFilterCols; int64_t* fillVal; SOrderedPrjQueryInfo prjInfo; // limit value for each vgroup, only available in global order projection query. - SSingleColumnFilterInfo* pFilterInfo; + SSingleColumnFilterInfo* pFilterInfo; + SFilterInfo *pFilters; + void* tsdb; SMemRef memRef; STableGroupInfo tableGroupInfo; // table list SArray @@ -352,6 +354,7 @@ typedef struct SQInfo { typedef struct SQueryParam { char *sql; char *tagCond; + char *colCond; char *tbnameCond; char *prevResult; SArray *pTableIdList; @@ -360,6 +363,8 @@ typedef struct SQueryParam { SExprInfo *pExprs; SExprInfo *pSecExprs; + SFilterInfo *pFilters; + SColIndex *pGroupColIndex; SColumnInfo *pTagColumnInfo; SGroupbyExpr *pGroupbyExpr; @@ -540,6 +545,7 @@ SSDataBlock* doSLimit(void* param, bool* newgroup); int32_t doCreateFilterInfo(SColumnInfo* pCols, int32_t numOfCols, int32_t numOfFilterCols, SSingleColumnFilterInfo** pFilterInfo, uint64_t qId); void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, SSDataBlock* pBlock); +void doSetFilterColInfo(SFilterInfo *pFilters, SSDataBlock* pBlock); bool doFilterDataBlock(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFilterCols, int32_t numOfRows, int8_t* p); void doCompactSDataBlock(SSDataBlock* pBlock, int32_t numOfRows, int8_t* p); @@ -559,9 +565,11 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlExpr **pExpr, SExprInfo *prevExpr); +int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters); + SGroupbyExpr *createGroupbyExprFromMsg(SQueryTableMsg *pQueryMsg, SColIndex *pColIndex, int32_t *code); SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SGroupbyExpr *pGroupbyExpr, SExprInfo *pExprs, - SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, int32_t vgId, char* sql, uint64_t *qId); + SExprInfo *pSecExprs, STableGroupInfo *pTableGroupInfo, SColumnInfo* pTagCols, SFilterInfo* pFilters, int32_t vgId, char* sql, uint64_t *qId); int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, SQueryParam* param, char* start, int32_t prevResultLen, void* merger); diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index a8a1ffc5ec..6db81bd242 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -22,6 +22,10 @@ extern "C" { #include "texpr.h" +#define FILTER_DEFAULT_UNIT_SIZE 4 +#define FILTER_DEFAULT_FIELD_SIZE 4 +#define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 + enum { F_FIELD_COLUMN = 0, F_FIELD_VALUE, @@ -41,10 +45,16 @@ typedef struct SFilterField { } SFilterField; typedef struct SFilterFields { + uint16_t size; uint16_t num; SFilterField *fields; } SFilterFields; +typedef struct SFilterFieldId { + uint16_t type; + uint16_t idx; +} SFilterFieldId; + typedef struct SFilterGroup { uint16_t unitNum; uint16_t *unitIdxs; @@ -57,15 +67,16 @@ typedef struct SFilterCompare { } SFilterCompare; typedef struct SFilterUnit { - SFilterCompare compare; - SFilterField *left; - SFilterField *right; + SFilterCompare compare; + SFilterFieldId left; + SFilterFieldId right; } SFilterUnit; typedef struct SFilterInfo { + uint16_t unitSize; uint16_t unitNum; uint16_t groupNum; - SFilterFields fileds[F_FIELD_MAX]; + SFilterFields fields[F_FIELD_MAX]; SFilterGroup *groups; SFilterUnit *units; uint8_t *unitRes; // result @@ -81,11 +92,24 @@ typedef struct SFilterInfo { #define CHK_LRETV(c,...) do { if (c) { qError(__VA_ARGS__); return; } } while (0) #define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) +#define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) +#define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) +#define FILTER_GET_VAL_FIELD_DATA(fi) (&((tVariant *)((fi)->desc))->i64) + + + +#define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) +#define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 +#define FILTER_UNIT_GET_F(i, idx) ((i)->unitFlags[idx]) +#define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx]) +#define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v) + typedef int32_t(*filter_desc_compare_func)(const void *, const void *); -extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo *info, int32_t colSize); - +extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo); +extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); +extern int32_t filterSetColData(SFilterInfo *info, int16_t colId, void *data); #ifdef __cplusplus } diff --git a/src/query/inc/qTableMeta.h b/src/query/inc/qTableMeta.h index 0b402c31ab..0eec94fa22 100644 --- a/src/query/inc/qTableMeta.h +++ b/src/query/inc/qTableMeta.h @@ -89,6 +89,11 @@ typedef struct STableMetaInfo { struct SQInfo; // global merge operator struct SQueryAttr; // query object +typedef struct STableFilter { + uint64_t uid; + SFilterInfo info; +} STableFilter; + typedef struct SQueryInfo { int16_t command; // the command may be different for each subclause, so keep it seperately. uint32_t type; // query/insert type @@ -106,7 +111,7 @@ typedef struct SQueryInfo { SLimitVal slimit; STagCond tagCond; - SFilterInfo colFilter; + SArray * colCond; SOrderVal order; int16_t fillType; // final result fill type diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 80d45facdf..9e5fec813a 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2557,6 +2557,49 @@ void filterRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSingleColumnFilterInf tfree(p); } +void filterColRowsInDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SSDataBlock* pBlock, bool ascQuery) { + int32_t numOfRows = pBlock->info.rows; + + int8_t *p = calloc(numOfRows, sizeof(int8_t)); + bool all = true; + + if (pRuntimeEnv->pTsBuf != NULL) { + SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, 0); + + TSKEY* k = (TSKEY*) pColInfoData->pData; + for (int32_t i = 0; i < numOfRows; ++i) { + int32_t offset = ascQuery? i:(numOfRows - i - 1); + int32_t ret = doTSJoinFilter(pRuntimeEnv, k[offset], ascQuery); + if (ret == TS_JOIN_TAG_NOT_EQUALS) { + break; + } else if (ret == TS_JOIN_TS_NOT_EQUALS) { + all = false; + continue; + } else { + assert(ret == TS_JOIN_TS_EQUAL); + p[offset] = true; + } + + if (!tsBufNextPos(pRuntimeEnv->pTsBuf)) { + break; + } + } + + // save the cursor status + pRuntimeEnv->current->cur = tsBufGetCursor(pRuntimeEnv->pTsBuf); + } else { + all = filterExecute(pRuntimeEnv->pQueryAttr->pFilters, numOfRows, p); + } + + if (!all) { + doCompactSDataBlock(pBlock, numOfRows, p); + } + + tfree(p); +} + + + static SColumnInfo* doGetTagColumnInfoById(SColumnInfo* pTagColList, int32_t numOfTags, int16_t colId); static void doSetTagValueInParam(void* pTable, int32_t tagColId, tVariant *tag, int16_t type, int16_t bytes); @@ -2597,6 +2640,15 @@ void doSetFilterColumnInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFi } } + +void doSetFilterColInfo(SFilterInfo * pFilters, SSDataBlock* pBlock) { + for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { + SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, j); + + filterSetColData(pFilters, pColInfo->info.colId, pColInfo->pData); + } +} + int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { *status = BLK_DATA_NO_NEEDED; @@ -2735,9 +2787,9 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa return terrno; } - doSetFilterColumnInfo(pQueryAttr->pFilterInfo, pQueryAttr->numOfFilterCols, pBlock); - if (pQueryAttr->numOfFilterCols > 0 || pRuntimeEnv->pTsBuf != NULL) { - filterRowsInDataBlock(pRuntimeEnv, pQueryAttr->pFilterInfo, pQueryAttr->numOfFilterCols, pBlock, ascQuery); + doSetFilterColInfo(pQueryAttr->pFilters, pBlock); + if (pQueryAttr->pFilters != NULL || pRuntimeEnv->pTsBuf != NULL) { + filterColRowsInDataBlock(pRuntimeEnv, pBlock, ascQuery); } } @@ -6365,6 +6417,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput); pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols); pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen); + pQueryMsg->colCondLen = htons(pQueryMsg->colCondLen); pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset); pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen); pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks); @@ -6415,6 +6468,18 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { } } + if (pQueryMsg->colCondLen > 0) { + param->colCond = calloc(1, pQueryMsg->colCondLen); + if (param->colCond == NULL) { + code = TSDB_CODE_QRY_OUT_OF_MEMORY; + goto _cleanup; + } + + memcpy(param->colCond, pMsg, pQueryMsg->colCondLen); + pMsg += pQueryMsg->colCondLen; + } + + param->tableScanOperator = pQueryMsg->tableScanOperator; param->pExpr = calloc(pQueryMsg->numOfOutput, POINTER_BYTES); if (param->pExpr == NULL) { @@ -6831,6 +6896,25 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp return TSDB_CODE_SUCCESS; } +int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { + tExprNode* expr = NULL; + + TRY(TSDB_MAX_TAG_CONDITIONS) { + expr = exprTreeFromBinary(data, len); + } CATCH( code ) { + CLEANUP_EXECUTE(); + return code; + } END_TRY + + if (expr == NULL) { + qError("failed to create expr tree"); + return TSDB_CODE_QRY_APP_ERROR; + } + + return filterInitFromTree(expr, pFilters); +} + + // todo refactor int32_t createIndirectQueryFuncExprFromMsg(SQueryTableMsg* pQueryMsg, int32_t numOfOutput, SExprInfo** pExprInfo, SSqlExpr** pExpr, SExprInfo* prevExpr) { @@ -7061,7 +7145,7 @@ FORCE_INLINE bool checkQIdEqual(void *qHandle, uint64_t qId) { } SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, SExprInfo* pExprs, - SExprInfo* pSecExprs, STableGroupInfo* pTableGroupInfo, SColumnInfo* pTagCols, int32_t vgId, + SExprInfo* pSecExprs, STableGroupInfo* pTableGroupInfo, SColumnInfo* pTagCols, SFilterInfo* pFilters, int32_t vgId, char* sql, uint64_t *qId) { int16_t numOfCols = pQueryMsg->numOfCols; int16_t numOfOutput = pQueryMsg->numOfOutput; @@ -7110,7 +7194,8 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S pQueryAttr->needReverseScan = pQueryMsg->needReverseScan; pQueryAttr->stateWindow = pQueryMsg->stateWindow; pQueryAttr->vgId = vgId; - + pQueryAttr->pFilters = pFilters; + pQueryAttr->tableCols = calloc(numOfCols, sizeof(SSingleColumnFilterInfo)); if (pQueryAttr->tableCols == NULL) { goto _cleanup; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index c9dcd3a348..e495bded03 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -15,6 +15,7 @@ #include "os.h" #include "queryLog.h" #include "qFilter.h" +#include "tcompare.h" OptrStr gOptrStr[] = { {TSDB_RELATION_INVALID, "invalid"}, @@ -53,30 +54,38 @@ filter_desc_compare_func gDescCompare [F_FIELD_MAX] = { filterFieldValDescCompare }; +int32_t filterMergeGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { + SFilterGroup gp = {0}; -int32_t filterMergeGroup(SArray* group, SArray* left, SArray* right) { + //TODO CHECK DUP + + gp.unitNum = gp1->unitNum + gp2->unitNum; + gp.unitIdxs = calloc(gp.unitNum, sizeof(*gp.unitIdxs)); + memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); + memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); + + gp.unitFlags = NULL; + + taosArrayPush(group, &gp); + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterMergeGroups(SArray* group, SArray* left, SArray* right) { int32_t leftSize = (int32_t)taosArrayGetSize(left); int32_t rightSize = (int32_t)taosArrayGetSize(right); CHK_LRET(taosArrayGetSize(left) <= 0, TSDB_CODE_QRY_APP_ERROR, "empty group"); CHK_LRET(taosArrayGetSize(right) <= 0, TSDB_CODE_QRY_APP_ERROR, "empty group"); - - SFilterGroup gp = {0}; for (int32_t l = 0; l < leftSize; ++l) { SFilterGroup *gp1 = taosArrayGet(left, l); for (int32_t r = 0; r < rightSize; ++r) { SFilterGroup *gp2 = taosArrayGet(right, r); - - gp.unitNum = gp1->unitNum + gp2->unitNum; - gp.unitIdxs = calloc(gp.unitNum, sizeof(*gp.unitIdxs)); - memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); - memcpy(gp.unitIdxs + gp1->unitNum, gp2->unitIdxs, gp2->unitNum * sizeof(*gp.unitIdxs)); - gp.unitFlags = NULL; - - taosArrayPush(group, &gp); + filterMergeGroup(gp1, gp2, group); } } @@ -95,9 +104,10 @@ int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { } -SFilterField* filterAddField(SFilterInfo *info, tExprNode *node) { - CHK_LRET(node == NULL, NULL, "empty node"); - CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, NULL, "invalid nodeType"); +int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) { + CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node"); + CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType"); + int32_t type, idx = -1; uint16_t *num; void *v; @@ -110,26 +120,39 @@ SFilterField* filterAddField(SFilterInfo *info, tExprNode *node) { v = node->pVal; } - num = &info->fileds[type].num; + num = &info->fields[type].num; - if (num > 0) { - idx = filterGetFiled(&info->fileds[type], type, v); + if (*num > 0) { + idx = filterGetFiled(&info->fields[type], type, v); } if (idx < 0) { idx = *num; - info->fileds[type].fields[idx].type = type; - info->fileds[type].fields[idx].desc = v; + if (idx >= info->fields[type].size) { + info->fields[type].size += FILTER_DEFAULT_FIELD_SIZE; + info->fields[type].fields = realloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); + } + + info->fields[type].fields[idx].type = type; + info->fields[type].fields[idx].desc = v; ++(*num); } + + fid->type = type; + fid->idx = idx; - return &info->fileds[type].fields[idx]; + return TSDB_CODE_SUCCESS; } -int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterField *left, SFilterField *right) { +int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right) { + if (info->unitNum >= info->unitSize) { + info->unitSize += FILTER_DEFAULT_UNIT_SIZE; + info->units = realloc(info->units, info->unitSize * sizeof(SFilterUnit)); + } + info->units[info->unitNum].compare.optr = optr; - info->units[info->unitNum].left = left; - info->units[info->unitNum].right = right; + info->units[info->unitNum].left = *left; + info->units[info->unitNum].right = *right; ++info->unitNum; @@ -138,12 +161,20 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterField *left, SFilt int32_t filterAddGroup(SFilterGroup *group, uint16_t unitIdx) { group->unitNum = 1; - group->unitIdxs= calloc(1, sizeof(*group->unitIdxs)); + group->unitIdxs= calloc(group->unitNum, sizeof(*group->unitIdxs)); group->unitIdxs[0] = unitIdx; return TSDB_CODE_SUCCESS; } +static void filterFreeGroup(void *pItem) { + SFilterGroup* p = (SFilterGroup*) pItem; + if (p) { + tfree(p->unitIdxs); + tfree(p->unitFlags); + } +} + int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { int32_t code = TSDB_CODE_SUCCESS; @@ -161,7 +192,10 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { ERR_JRET(filterTreeToGroup(tree->_node.pLeft, info, leftGroup)); ERR_JRET(filterTreeToGroup(tree->_node.pRight, info, rightGroup)); - ERR_JRET(filterMergeGroup(group, leftGroup, rightGroup)); + ERR_JRET(filterMergeGroups(group, leftGroup, rightGroup)); + + taosArrayDestroyEx(leftGroup, filterFreeGroup); + taosArrayDestroyEx(rightGroup, filterFreeGroup); return TSDB_CODE_SUCCESS; } @@ -173,10 +207,11 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } - SFilterField *left = filterAddField(info, tree->_node.pLeft); - SFilterField *right = filterAddField(info, tree->_node.pRight); + SFilterFieldId left, right; + filterAddField(info, tree->_node.pLeft, &left); + filterAddField(info, tree->_node.pRight, &right); - filterAddUnit(info, tree->_node.optr, left, right); + filterAddUnit(info, tree->_node.optr, &left, &right); SFilterGroup fgroup = {0}; filterAddGroup(&fgroup, info->unitNum - 1); @@ -185,32 +220,52 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { _err_return: - taosArrayDestroy(leftGroup); - taosArrayDestroy(rightGroup); + taosArrayDestroyEx(leftGroup, filterFreeGroup); + taosArrayDestroyEx(rightGroup, filterFreeGroup); return code; } +int32_t filterInitUnitFunc(SFilterInfo *info) { + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit* unit = &info->units[i]; + SFilterField *left = FILTER_GET_FIELD(info, unit->left); + + unit->compare.pCompareFunc = getComparFunc(left->type, unit->compare.optr); + } + + return TSDB_CODE_SUCCESS; +} + + + void filterDumpInfoToString(SFilterInfo *info) { CHK_LRETV(info == NULL, "FilterInfo: empty"); qDebug("FilterInfo:"); - qDebug("Col F Num:%u", info->fileds[F_FIELD_COLUMN].num); - for (uint16_t i = 0; i < info->fileds[F_FIELD_COLUMN].num; ++i) { - SFilterField *field = &info->fileds[F_FIELD_COLUMN].fields[i]; + qDebug("Field Col Num:%u", info->fields[F_FIELD_COLUMN].num); + for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { + SFilterField *field = &info->fields[F_FIELD_COLUMN].fields[i]; SSchema *sch = field->desc; qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); } + qDebug("Field Val Num:%u", info->fields[F_FIELD_VALUE].num); + for (uint16_t i = 0; i < info->fields[F_FIELD_VALUE].num; ++i) { + SFilterField *field = &info->fields[F_FIELD_VALUE].fields[i]; + tVariant *var = field->desc; + qDebug("VAL%d => [type:%d][val:%" PRIu64"]", i, var->nType, var->u64); //TODO + } + qDebug("Unit Num:%u", info->unitNum); for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; - SFilterField *left = unit->left; - SFilterField *right = unit->right; + SFilterField *left = FILTER_GET_FIELD(info, unit->left); + SFilterField *right = FILTER_GET_FIELD(info, unit->right); SSchema *sch = left->desc; tVariant *var = right->desc; - qDebug("UNIT%d => [%d][%s] %s %" PRId64, i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str, IS_NUMERIC_TYPE(var->nType) ? var->i64 : -1); + qDebug("UNIT%d => [%d][%s] %s %" PRId64, i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str, IS_NUMERIC_TYPE(var->nType) ? var->i64 : -1); //TODO } qDebug("Group Num:%u", info->groupNum); @@ -224,24 +279,33 @@ void filterDumpInfoToString(SFilterInfo *info) { } } -int32_t filterInitFromTree(tExprNode* tree, SFilterInfo *info, int32_t colSize) { +int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { int32_t code = TSDB_CODE_SUCCESS; + SFilterInfo *info = NULL; + + CHK_LRET(tree == NULL || pinfo == NULL, TSDB_CODE_QRY_APP_ERROR, "invalid param"); - CHK_RET(colSize <= 0, code); - CHK_LRET(tree == NULL || info == NULL, TSDB_CODE_QRY_APP_ERROR, "invalid param"); + if (*pinfo == NULL) { + *pinfo = calloc(1, sizeof(SFilterInfo)); + } + + info = *pinfo; SArray* group = taosArrayInit(4, sizeof(SFilterGroup)); + + info->unitSize = FILTER_DEFAULT_UNIT_SIZE; + info->units = calloc(info->unitSize, sizeof(SFilterUnit)); - info->units = calloc(colSize, sizeof(SFilterUnit)); - - info->fileds[F_FIELD_COLUMN].num = 0; - info->fileds[F_FIELD_COLUMN].fields = calloc(colSize, sizeof(SFilterField)); - info->fileds[F_FIELD_VALUE].num = 0; - info->fileds[F_FIELD_VALUE].fields = calloc(colSize, sizeof(SFilterField)); + info->fields[F_FIELD_COLUMN].num = 0; + info->fields[F_FIELD_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, sizeof(SFilterField)); + info->fields[F_FIELD_VALUE].num = 0; + info->fields[F_FIELD_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[F_FIELD_VALUE].fields = calloc(info->fields[F_FIELD_VALUE].size, sizeof(SFilterField)); code = filterTreeToGroup(tree, info, group); - ERR_RET(code); + ERR_JRET(code); size_t groupSize = taosArrayGetSize(group); @@ -253,13 +317,20 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo *info, int32_t colSize) for (size_t i = 0; i < groupSize; ++i) { SFilterGroup *pg = taosArrayGet(group, i); - info->groups[i].unitNum = pg->unitNum; - info->groups[i].unitIdxs = pg->unitIdxs; - info->groups[i].unitFlags = pg->unitFlags; + info->groups[i] = *pg; } + ERR_JRET(filterInitUnitFunc(info)); + + info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); + info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); + filterDumpInfoToString(info); + +_err_return: + taosArrayDestroy(group); + return code; } @@ -269,4 +340,109 @@ void filterFreeInfo(SFilterInfo *info) { //TODO } +int32_t filterSetColData(SFilterInfo *info, int16_t colId, void *data) { + CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); + CHK_LRET(info->fields[F_FIELD_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); + + for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[F_FIELD_COLUMN].fields[i]; + SSchema* sch = fi->desc; + if (sch->colId == colId) { + fi->data = data; + break; + } + } + + return TSDB_CODE_SUCCESS; +} + + +bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { + int32_t ret = unit->compare.pCompareFunc(left, right); + + switch (unit->compare.optr) { + case TSDB_RELATION_EQUAL: { + return ret == 0; + } + case TSDB_RELATION_NOT_EQUAL: { + return ret != 0; + } + case TSDB_RELATION_GREATER_EQUAL: { + return ret >= 0; + } + case TSDB_RELATION_GREATER: { + return ret > 0; + } + case TSDB_RELATION_LESS_EQUAL: { + return ret <= 0; + } + case TSDB_RELATION_LESS: { + return ret < 0; + } + case TSDB_RELATION_LIKE: { + return ret == 0; + } + case TSDB_RELATION_IN: { + return ret == 1; + } + + default: + assert(false); + } + + return true; +} + + +bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + FILTER_UNIT_CLR_F(info); + + p[i] = 0; + + for (uint16_t g = 0; g < info->groupNum; ++g) { + SFilterGroup* group = &info->groups[g]; + bool qualified = true; + + for (uint16_t u = 0; u < group->unitNum; ++u) { + uint16_t uidx = group->unitIdxs[u]; + uint8_t ures = 0; + + if (FILTER_UNIT_GET_F(info, uidx)) { + ures = FILTER_UNIT_GET_R(info, uidx); + } else { + SFilterUnit *unit = &info->units[uidx]; + SFilterField *left = FILTER_GET_FIELD(info, unit->left); + SFilterField *right = FILTER_GET_FIELD(info, unit->right); + + ures = filterDoCompare(unit, FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_VAL_FIELD_DATA(right)); + + FILTER_UNIT_SET_R(info, uidx, ures); + FILTER_UNIT_SET_F(info, uidx); + } + + if (!ures) { + qualified = ures; + break; + } + } + + if (qualified) { + p[i] = 1; + break; + } + } + + if (p[i] != 1) { + all = false; + } + } + + return all; +} + + + diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index 38ef81e793..ef18575371 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -103,6 +103,12 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi } } + if (param.colCond != NULL) { + if ((code = createQueryFilter(param.colCond, pQueryMsg->colCondLen, ¶m.pFilters)) != TSDB_CODE_SUCCESS) { + goto _over; + } + } + param.pGroupbyExpr = createGroupbyExprFromMsg(pQueryMsg, param.pGroupColIndex, &code); if ((param.pGroupbyExpr == NULL && pQueryMsg->numOfGroupCols != 0) || code != TSDB_CODE_SUCCESS) { goto _over; @@ -162,7 +168,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi assert(pQueryMsg->stableQuery == isSTableQuery); (*pQInfo) = createQInfoImpl(pQueryMsg, param.pGroupbyExpr, param.pExprs, param.pSecExprs, &tableGroupInfo, - param.pTagColumnInfo, vgId, param.sql, qId); + param.pTagColumnInfo, param.pFilters, vgId, param.sql, qId); param.sql = NULL; param.pExprs = NULL; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim new file mode 100644 index 0000000000..4b4750d0be --- /dev/null +++ b/tests/script/general/parser/condition.sim @@ -0,0 +1,198 @@ +system sh/stop_dnodes.sh + +system sh/deploy.sh -n dnode1 -i 1 +system sh/cfg.sh -n dnode1 -c walLevel -v 1 +system sh/cfg.sh -n dnode1 -c maxtablespervnode -v 4 +system sh/exec.sh -n dnode1 -s start + +sleep 100 +sql connect + +sql drop database if exists cdb +sql create database if not exists cdb +sql use cdb +sql create table stb1 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double) + +sql create table tb1 using stb1 tags(1,'1',1.0) +sql create table tb2 using stb1 tags(2,'2',2.0) +sql create table tb3 using stb1 tags(3,'3',3.0) +sql create table tb4 using stb1 tags(4,'4',4.0) +sql create table tb5 using stb1 tags(5,'5',5.0) +sql create table tb6 using stb1 tags(6,'6',6.0) + +sql insert into tb1 values ('2021-05-05 18:19:00',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb1 values ('2021-05-05 18:19:01',2,2.0,2,2,2,2.0,true ,'2','2') +sql insert into tb1 values ('2021-05-05 18:19:02',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb1 values ('2021-05-05 18:19:03',4,4.0,4,4,4,4.0,false,'4','4') +sql insert into tb1 values ('2021-05-05 18:19:04',11,11.0,11,11,11,11.0,true ,'11','11') +sql insert into tb1 values ('2021-05-05 18:19:05',12,12.0,12,12,12,12.0,true ,'12','12') +sql insert into tb1 values ('2021-05-05 18:19:06',13,13.0,13,13,13,13.0,false,'13','13') +sql insert into tb1 values ('2021-05-05 18:19:07',14,14.0,14,14,14,14.0,false,'14','14') +sql insert into tb2 values ('2021-05-05 18:19:08',21,21.0,21,21,21,21.0,true ,'21','21') +sql insert into tb2 values ('2021-05-05 18:19:09',22,22.0,22,22,22,22.0,true ,'22','22') +sql insert into tb2 values ('2021-05-05 18:19:10',23,23.0,23,23,23,23.0,false,'23','23') +sql insert into tb2 values ('2021-05-05 18:19:11',24,24.0,24,24,24,24.0,false,'24','24') +sql insert into tb3 values ('2021-05-05 18:19:12',31,31.0,31,31,31,31.0,true ,'31','31') +sql insert into tb3 values ('2021-05-05 18:19:13',32,32.0,32,32,32,32.0,true ,'32','32') +sql insert into tb3 values ('2021-05-05 18:19:14',33,33.0,33,33,33,33.0,false,'33','33') +sql insert into tb3 values ('2021-05-05 18:19:15',34,34.0,34,34,34,34.0,false,'34','34') +sql insert into tb4 values ('2021-05-05 18:19:16',41,41.0,41,41,41,41.0,true ,'41','41') +sql insert into tb4 values ('2021-05-05 18:19:17',42,42.0,42,42,42,42.0,true ,'42','42') +sql insert into tb4 values ('2021-05-05 18:19:18',43,43.0,43,43,43,43.0,false,'43','43') +sql insert into tb4 values ('2021-05-05 18:19:19',44,44.0,44,44,44,44.0,false,'44','44') +sql insert into tb5 values ('2021-05-05 18:19:20',51,51.0,51,51,51,51.0,true ,'51','51') +sql insert into tb5 values ('2021-05-05 18:19:21',52,52.0,52,52,52,52.0,true ,'52','52') +sql insert into tb5 values ('2021-05-05 18:19:22',53,53.0,53,53,53,53.0,false,'53','53') +sql insert into tb5 values ('2021-05-05 18:19:23',54,54.0,54,54,54,54.0,false,'54','54') +sql insert into tb6 values ('2021-05-05 18:19:24',61,61.0,61,61,61,61.0,true ,'61','61') +sql insert into tb6 values ('2021-05-05 18:19:25',62,62.0,62,62,62,62.0,true ,'62','62') +sql insert into tb6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'63','63') +sql insert into tb6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') + +sleep 100 + +print "column test" +sql select * from stb1 where c1 > 0 +if $rows != 28 then + return -1 +endi +#sql select * from stb1 where c1 > 0 and c1 > 3 +#sql select * from stb1 where c1 > 0 or c1 > 3 +#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 2 +#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 +#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 +#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 +#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 1 and c1 > 4 +#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 1 or c1 > 4 +#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 and c1 > 4 +#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 and c1 > 4 +#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 or c1 > 4 +#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 or c1 > 4 +#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 and c1 > 4 +#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 or c1 > 4 +# +#sql select * from stb1 where (c1 > 0 and c1 > 3) and c1 < 2 +#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 2) +#sql select * from stb1 where (c1 > 0 or c1 > 3) or c1 < 1 +#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) +#sql select * from stb1 where (c1 > 0 and c1 > 3) or c1 < 1 +#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) +#sql select * from stb1 where (c1 > 0 or c1 > 3) and c1 < 1 +#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) +#sql select * from stb1 where (c1 > 0 and c1 > 3) and (c1 < 1 and c1 > 4) +#sql select * from stb1 where (c1 > 0 and c1 > 3 and c1 < 1) and c1 > 4 +#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 1) and c1 > 4 +#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 1 or c1 > 4) +#sql select * from stb1 where (c1 > 0 and c1 > 3) or (c1 < 1 and c1 > 4) +#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) and c1 > 4 +#sql select * from stb1 where (c1 > 0 and c1 > 3 or c1 < 1) and c1 > 4 +#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1 and c1 > 4) +#sql select * from stb1 where (c1 > 0 or c1 > 3) and (c1 < 1 and c1 > 4) +#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1 and c1 > 4) +#sql select * from stb1 where (c1 > 0 or c1 > 3 and c1 < 1) and c1 > 4 +#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) and c1 > 4 +#sql select * from stb1 where (c1 > 0 and c1 > 3) or (c1 < 1 or c1 > 4) +#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1 or c1 > 4) +#sql select * from stb1 where (c1 > 0 and c1 > 3 or c1 < 1) or c1 > 4 +#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) or c1 > 4 +#sql select * from stb1 where (c1 > 0 or c1 > 3) and (c1 < 1 or c1 > 4) +#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1 or c1 > 4) +#sql select * from stb1 where (c1 > 0 or c1 > 3 and c1 < 1) or c1 > 4 +#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) or c1 > 4 +#sql select * from stb1 where (c1 > 0 or c1 > 3) or (c1 < 1 and c1 > 4) +#sql select * from stb1 where (c1 > 0 or c1 > 3 or c1 < 1) and c1 > 4 +#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1 and c1 > 4) +#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) and c1 > 4 +#sql select * from stb1 where (c1 > 0 or c1 > 3) or (c1 < 1 or c1 > 4) +#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1 or c1 > 4) +#sql select * from stb1 where (c1 > 0 or c1 > 3 or c1 < 1) or c1 > 4 +#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) or c1 > 4 + +sql select * from stb1 where (c1 > 40 or c1 < 20) and (c2 < 53 or c2 >= 63) and c3 > 1 and c3 < 5 + + +print "ts test" + +print "tbname test" + +print "tag test" + +print "join test" + + + + +print "column&ts test" + +print "column&tbname test" + + + +print "column&tag test" +#sql_error select * from stb1 where t1 > 0 or c1 > 0 +#sql_error select * from stb1 where c1 > 0 or t1 > 0 +#sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 +#sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 +#sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 +#sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +#sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +#sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 +#sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) +#sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 +# +# +#sql select * from stb1 where c1 > 0 and t1 > 0 +#sql select * from stb1 where t1 > 0 and c1 > 0 +#sql select * from stb1 where t1 > 0 and t1 > 3 and c1 > 1 +#sql select * from stb1 where t1 > 0 and c1 > 0 and t1 > 1 +#sql select * from stb1 where c1 > 0 and t1 > 0 and c1 > 1 +#sql select * from stb1 where c1 > 0 and (t1 > 0 or t1 > 1) +#sql select * from stb1 where (t1 > 0 or t1 > 2 ) and (c1 > 1 or c1 > 3) +#sql select * from stb1 where c1 > 0 and (t1 > 0 or t1 > 1) + +print "column&join test" + +print "ts&tbname test" + +print "ts&tag test" + +print "ts&join test" + +print "tbname&tag test" + +print "tbname&join test" + +print "tag&join test" + + + + + +print "column&ts&tbname test" + +print "column&ts&tag test" + +print "column&ts&join test" + +print "column&tbname&tag test" + +print "column&tbname&join test" +print "column&tag&join test" +print "ts&tbname&tag test" +print "ts&tbname&join test" +print "ts&tag&join test" +print "tbname&tag&join test" + + + + +print "column&ts&tbname&tag test" +print "column&ts&tbname&join test" +print "column&ts&tag&join test" +print "column&tbname&tag&join test" +print "ts&tbname&tag&join test" + + +print "column&ts&tbname&tag&join test" + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT From ea497d386cc38af603a187e85abe1e201c1ee847 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Thu, 17 Jun 2021 18:38:34 +0800 Subject: [PATCH 003/100] fix value convert issue --- src/query/inc/qFilter.h | 6 +- src/query/src/qExecutor.c | 2 +- src/query/src/qFilter.c | 160 ++++++++++++++-------- tests/script/general/parser/condition.sim | 56 ++++++++ 4 files changed, 163 insertions(+), 61 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 6db81bd242..5fd25e40a9 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -93,8 +93,10 @@ typedef struct SFilterInfo { #define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) #define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) +#define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type) #define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) -#define FILTER_GET_VAL_FIELD_DATA(fi) (&((tVariant *)((fi)->desc))->i64) +#define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) +#define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) @@ -109,7 +111,7 @@ typedef int32_t(*filter_desc_compare_func)(const void *, const void *); extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); -extern int32_t filterSetColData(SFilterInfo *info, int16_t colId, void *data); +extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); #ifdef __cplusplus } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 9e5fec813a..4b38b8c031 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2645,7 +2645,7 @@ void doSetFilterColInfo(SFilterInfo * pFilters, SSDataBlock* pBlock) { for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) { SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, j); - filterSetColData(pFilters, pColInfo->info.colId, pColInfo->pData); + filterSetColFieldData(pFilters, pColInfo->info.colId, pColInfo->pData); } } diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index e495bded03..ed3a3d5057 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -122,7 +122,7 @@ int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) num = &info->fields[type].num; - if (*num > 0) { + if (*num > 0 && type != F_FIELD_VALUE) { idx = filterGetFiled(&info->fields[type], type, v); } @@ -231,7 +231,7 @@ int32_t filterInitUnitFunc(SFilterInfo *info) { SFilterUnit* unit = &info->units[i]; SFilterField *left = FILTER_GET_FIELD(info, unit->left); - unit->compare.pCompareFunc = getComparFunc(left->type, unit->compare.optr); + unit->compare.pCompareFunc = getComparFunc(FILTER_GET_COL_FIELD_TYPE(left), unit->compare.optr); } return TSDB_CODE_SUCCESS; @@ -279,68 +279,13 @@ void filterDumpInfoToString(SFilterInfo *info) { } } -int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { - int32_t code = TSDB_CODE_SUCCESS; - SFilterInfo *info = NULL; - - CHK_LRET(tree == NULL || pinfo == NULL, TSDB_CODE_QRY_APP_ERROR, "invalid param"); - - if (*pinfo == NULL) { - *pinfo = calloc(1, sizeof(SFilterInfo)); - } - - info = *pinfo; - - SArray* group = taosArrayInit(4, sizeof(SFilterGroup)); - - info->unitSize = FILTER_DEFAULT_UNIT_SIZE; - info->units = calloc(info->unitSize, sizeof(SFilterUnit)); - - info->fields[F_FIELD_COLUMN].num = 0; - info->fields[F_FIELD_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, sizeof(SFilterField)); - info->fields[F_FIELD_VALUE].num = 0; - info->fields[F_FIELD_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[F_FIELD_VALUE].fields = calloc(info->fields[F_FIELD_VALUE].size, sizeof(SFilterField)); - - code = filterTreeToGroup(tree, info, group); - - ERR_JRET(code); - - size_t groupSize = taosArrayGetSize(group); - - info->groupNum = (uint16_t)groupSize; - - if (info->groupNum > 0) { - info->groups = calloc(info->groupNum, sizeof(*info->groups)); - } - - for (size_t i = 0; i < groupSize; ++i) { - SFilterGroup *pg = taosArrayGet(group, i); - info->groups[i] = *pg; - } - - ERR_JRET(filterInitUnitFunc(info)); - - info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); - info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); - - filterDumpInfoToString(info); - -_err_return: - - taosArrayDestroy(group); - - return code; -} - void filterFreeInfo(SFilterInfo *info) { CHK_RETV(info == NULL); //TODO } -int32_t filterSetColData(SFilterInfo *info, int16_t colId, void *data) { +int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); CHK_LRET(info->fields[F_FIELD_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); @@ -356,6 +301,46 @@ int32_t filterSetColData(SFilterInfo *info, int16_t colId, void *data) { return TSDB_CODE_SUCCESS; } +int32_t filterInitValFieldData(SFilterInfo *info) { + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit* unit = &info->units[i]; + SFilterField* left = FILTER_GET_FIELD(info, unit->left); + SFilterField* right = FILTER_GET_FIELD(info, unit->right); + + if (left->type != F_FIELD_VALUE && right->type != F_FIELD_VALUE) { + continue; + } + + uint32_t type = 0; + SFilterField* fi = NULL; + if (left->type == F_FIELD_COLUMN) { + type = FILTER_GET_COL_FIELD_TYPE(left); + fi = right; + } else if (right->type == F_FIELD_COLUMN) { + type = FILTER_GET_COL_FIELD_TYPE(right); + fi = left; + } else { + type = FILTER_GET_VAL_FIELD_TYPE(left); + fi = right; + } + + tVariant* var = fi->desc; + + if (type == TSDB_DATA_TYPE_BINARY) { + fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); + } else if (type == TSDB_DATA_TYPE_NCHAR) { + fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); + } else { + fi->data = calloc(1, sizeof(int64_t)); + } + + ERR_LRET(tVariantDump(var, (char*)fi->data, type, false), "dump type[%d] failed", type); + } + + return TSDB_CODE_SUCCESS; +} + + bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { int32_t ret = unit->compare.pCompareFunc(left, right); @@ -445,4 +430,63 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { +int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { + int32_t code = TSDB_CODE_SUCCESS; + SFilterInfo *info = NULL; + + CHK_LRET(tree == NULL || pinfo == NULL, TSDB_CODE_QRY_APP_ERROR, "invalid param"); + + if (*pinfo == NULL) { + *pinfo = calloc(1, sizeof(SFilterInfo)); + } + + info = *pinfo; + + SArray* group = taosArrayInit(4, sizeof(SFilterGroup)); + + info->unitSize = FILTER_DEFAULT_UNIT_SIZE; + info->units = calloc(info->unitSize, sizeof(SFilterUnit)); + + info->fields[F_FIELD_COLUMN].num = 0; + info->fields[F_FIELD_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, sizeof(SFilterField)); + info->fields[F_FIELD_VALUE].num = 0; + info->fields[F_FIELD_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[F_FIELD_VALUE].fields = calloc(info->fields[F_FIELD_VALUE].size, sizeof(SFilterField)); + + code = filterTreeToGroup(tree, info, group); + + ERR_JRET(code); + + size_t groupSize = taosArrayGetSize(group); + + info->groupNum = (uint16_t)groupSize; + + if (info->groupNum > 0) { + info->groups = calloc(info->groupNum, sizeof(*info->groups)); + } + + for (size_t i = 0; i < groupSize; ++i) { + SFilterGroup *pg = taosArrayGet(group, i); + info->groups[i] = *pg; + } + + ERR_JRET(filterInitUnitFunc(info)); + + ERR_JRET(filterInitValFieldData(info)); + + info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); + info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); + + filterDumpInfoToString(info); + +_err_return: + + taosArrayDestroy(group); + + return code; +} + + + diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 4b4750d0be..9ef9da44c3 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -109,6 +109,62 @@ endi #sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) or c1 > 4 sql select * from stb1 where (c1 > 40 or c1 < 20) and (c2 < 53 or c2 >= 63) and c3 > 1 and c3 < 5 +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi + +sql select * from stb1 where (c1 > 52 or c1 < 10) and (c2 > 1 and c2 < 61) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data31 != 53 then + return -1 +endi +if $data40 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data41 != 54 then + return -1 +endi print "ts test" From a1627c5d649b7397c05108cfc7db029df4839fbe Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Fri, 18 Jun 2021 16:49:39 +0800 Subject: [PATCH 004/100] support like --- src/client/src/tscSQLParser.c | 105 +- src/client/src/tscServer.c | 5 +- src/kit/shell/src/shellEngine.c | 2 +- src/query/src/qExecutor.c | 4 +- src/query/src/qFilter.c | 16 +- tests/script/general/parser/condition.sim | 1180 ++++++++++++++++++++- 6 files changed, 1184 insertions(+), 128 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 56dc921873..9a5f73f4dd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -185,10 +185,12 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType) break; } + uint32_t tType = pSub->token.type; toTSDBType(pSub->token.type); tVariant var; tVariantCreate(&var, &pSub->token); + pSub->token.type = tType; if (type == TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_SMALLINT || type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_INT) { tbufWriteInt64(&bw, var.i64); @@ -3465,44 +3467,28 @@ enum { TSQL_EXPR_TBNAME = 8, }; -static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) { +static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex); STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, pIndex->columnIndex); - + int32_t ret = 0; const char* msg1 = "non binary column not support like operator"; const char* msg2 = "binary column not support this operator"; const char* msg3 = "bool column not support this operator"; SColumn* pColumn = tscColumnListInsert(pQueryInfo->colList, pIndex->columnIndex, pTableMeta->id.uid, pSchema); - SColumnFilterInfo* pColFilter = NULL; /* * in case of TK_AND filter condition, we first find the corresponding column and build the query condition together * the already existed condition. */ - if (sqlOptr == TK_AND) { - // this is a new filter condition on this column - if (pColumn->info.flist.numOfFilters == 0) { - pColFilter = addColumnFilterInfo(&pColumn->info.flist); - } else { // update the existed column filter information, find the filter info here - pColFilter = &pColumn->info.flist.filterInfo[0]; - } - - if (pColFilter == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - } else if (sqlOptr == TK_OR) { - // TODO fixme: failed to invalid the filter expression: "col1 = 1 OR col2 = 2" - pColFilter = addColumnFilterInfo(&pColumn->info.flist); - if (pColFilter == NULL) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - } else { // error; + if (sqlOptr != TK_AND && sqlOptr != TK_OR) { return TSDB_CODE_TSC_INVALID_OPERATION; } + SColumnFilterInfo* pColFilter = calloc(1, sizeof(SColumnFilterInfo)); + pColFilter->filterstr = ((pSchema->type == TSDB_DATA_TYPE_BINARY || pSchema->type == TSDB_DATA_TYPE_NCHAR) ? 1 : 0); @@ -3513,17 +3499,20 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC && pExpr->tokenId != TK_NOTNULL && pExpr->tokenId != TK_LIKE && pExpr->tokenId != TK_IN) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + goto _err_ret; } } else { if (pExpr->tokenId == TK_LIKE) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + goto _err_ret; } if (pSchema->type == TSDB_DATA_TYPE_BOOL) { int32_t t = pExpr->tokenId; if (t != TK_EQ && t != TK_NE && t != TK_NOTNULL && t != TK_ISNULL && t != TK_IN) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); + goto _err_ret; } } } @@ -3532,7 +3521,12 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC pColumn->tableUid = pTableMeta->id.uid; STableComInfo tinfo = tscGetTableInfo(pTableMeta); - return doExtractColumnFilterInfo(pCmd, pQueryInfo, tinfo.precision, pColFilter, pSchema->type, pExpr); + ret = doExtractColumnFilterInfo(pCmd, pQueryInfo, tinfo.precision, pColFilter, pSchema->type, pExpr); + +_err_ret: + freeColumnFilterInfo(pColFilter, 1); + + return ret; } static int32_t getTablenameCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pTableCond, SStringBuilder* sb) { @@ -3626,25 +3620,25 @@ static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlEx } -static int32_t getColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, int32_t relOptr) { +static int32_t checkColumnQueryCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, int32_t relOptr) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } if (!tSqlExprIsParentOfLeaf(pExpr)) { // internal node - int32_t ret = getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pLeft, pExpr->tokenId); + int32_t ret = checkColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pLeft, pExpr->tokenId); if (ret != TSDB_CODE_SUCCESS) { return ret; } - return getColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pRight, pExpr->tokenId); + return checkColumnQueryCondInfo(pCmd, pQueryInfo, pExpr->pRight, pExpr->tokenId); } else { // handle leaf node SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } - return extractColumnFilterInfo(pCmd, pQueryInfo, &index, pExpr, relOptr); + return checkColumnFilterInfo(pCmd, pQueryInfo, &index, pExpr, relOptr); } } @@ -4050,7 +4044,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { // check for like expression static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t index, char* msgBuf) { const char* msg1 = "wildcard string should be less than 20 characters"; - const char* msg2 = "illegal column name"; + const char* msg2 = "illegal column type for like"; tSqlExpr* pLeft = pExpr->pLeft; tSqlExpr* pRight = pExpr->pRight; @@ -4433,36 +4427,9 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, return TSDB_CODE_SUCCESS; } -static bool validateFilterExpr(SQueryInfo* pQueryInfo) { - SArray* pColList = pQueryInfo->colList; - - size_t num = taosArrayGetSize(pColList); - - for (int32_t i = 0; i < num; ++i) { - SColumn* pCol = taosArrayGetP(pColList, i); - - for (int32_t j = 0; j < pCol->info.flist.numOfFilters; ++j) { - SColumnFilterInfo* pColFilter = &pCol->info.flist.filterInfo[j]; - int32_t lowerOptr = pColFilter->lowerRelOptr; - int32_t upperOptr = pColFilter->upperRelOptr; - - if ((lowerOptr == TSDB_RELATION_GREATER_EQUAL || lowerOptr == TSDB_RELATION_GREATER) && - (upperOptr == TSDB_RELATION_LESS_EQUAL || upperOptr == TSDB_RELATION_LESS)) { - continue; - } - - // there must be at least two range, not support yet. - if (lowerOptr * upperOptr != TSDB_RELATION_INVALID) { - return false; - } - } - } - - return true; -} static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { - const char* msg0 = "invalid timestamp"; + const char* msg0 = "invalid timestamp or operator for timestamp"; const char* msg1 = "only one time stamp window allowed"; int32_t code = 0; @@ -4844,7 +4811,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } const char* msg1 = "invalid expression"; - const char* msg2 = "invalid filter expression"; +// const char* msg2 = "invalid filter expression"; int32_t ret = TSDB_CODE_SUCCESS; @@ -4887,16 +4854,16 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq goto PARSE_WHERE_EXIT; } + // 5. other column query condition + if ((ret = checkColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { + goto PARSE_WHERE_EXIT; + } + if ((ret = getColQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr.pColumnCond)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } - // 5. other column query condition - if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pColumnCond, TK_AND)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; - } - // 6. join condition if ((ret = getJoinCondInfo(&pSql->cmd, pQueryInfo, condExpr.pJoinExpr)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; @@ -4911,10 +4878,10 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq goto PARSE_WHERE_EXIT; } - if (!validateFilterExpr(pQueryInfo)) { - ret = invalidOperationMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); - goto PARSE_WHERE_EXIT; - } + //if (!validateFilterExpr(pQueryInfo)) { + // ret = invalidOperationMsg(tscGetErrorMsgPayload(&pSql->cmd), msg2); + // goto PARSE_WHERE_EXIT; + //} //doAddJoinTagsColumnsIntoTagList(&pSql->cmd, pQueryInfo, &condExpr); if (condExpr.tsJoin) { @@ -4945,7 +4912,7 @@ int32_t getTimeRange(STimeWindow* win, tSqlExpr* pRight, int32_t optr, int16_t t * filter primary ts filter expression like: * where ts in ('2015-12-12 4:8:12') */ - if (pRight->tokenId == TK_SET || optr == TK_IN) { + if (pRight->tokenId == TK_SET || optr == TK_IN || optr == TK_NE) { return TSDB_CODE_TSC_INVALID_OPERATION; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index aca8ed3083..b4c71b11db 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -882,10 +882,11 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->tableCols[i].colId = htons(pCol->colId); pQueryMsg->tableCols[i].bytes = htons(pCol->bytes); pQueryMsg->tableCols[i].type = htons(pCol->type); - pQueryMsg->tableCols[i].flist.numOfFilters = htons(pCol->flist.numOfFilters); + //pQueryMsg->tableCols[i].flist.numOfFilters = htons(pCol->flist.numOfFilters); + pQueryMsg->tableCols[i].flist.numOfFilters = 0; // append the filter information after the basic column information - serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg); + //serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg); } if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) { diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index d5fa0a9e09..f6cb135dd1 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -248,7 +248,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { if (quote == c) { quote = 0; - } else if (c == '\'' || c == '"') { + } else if (quote == 0 && (c == '\'' || c == '"')) { quote = c; } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 4b38b8c031..a77fff3fb1 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6445,7 +6445,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pColInfo->colId = htons(pColInfo->colId); pColInfo->type = htons(pColInfo->type); pColInfo->bytes = htons(pColInfo->bytes); - pColInfo->flist.numOfFilters = htons(pColInfo->flist.numOfFilters); + pColInfo->flist.numOfFilters = 0; if (!isValidDataType(pColInfo->type)) { qDebug("qmsg:%p, invalid data type in source column, index:%d, type:%d", pQueryMsg, col, pColInfo->type); @@ -6453,6 +6453,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { goto _cleanup; } +/* int32_t numOfFilters = pColInfo->flist.numOfFilters; if (numOfFilters > 0) { pColInfo->flist.filterInfo = calloc(numOfFilters, sizeof(SColumnFilterInfo)); @@ -6466,6 +6467,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { if (code != TSDB_CODE_SUCCESS) { goto _cleanup; } +*/ } if (pQueryMsg->colCondLen > 0) { diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index ed3a3d5057..cfd894b408 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -334,7 +334,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) { fi->data = calloc(1, sizeof(int64_t)); } - ERR_LRET(tVariantDump(var, (char*)fi->data, type, false), "dump type[%d] failed", type); + ERR_LRET(tVariantDump(var, (char*)fi->data, type, true), "dump type[%d] failed", type); } return TSDB_CODE_SUCCESS; @@ -402,8 +402,18 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { SFilterField *left = FILTER_GET_FIELD(info, unit->left); SFilterField *right = FILTER_GET_FIELD(info, unit->right); - ures = filterDoCompare(unit, FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_VAL_FIELD_DATA(right)); - + if (isNull(FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_COL_FIELD_TYPE(left))) { + ures = unit->compare.optr == TSDB_RELATION_ISNULL ? true : false; + } else { + if (unit->compare.optr == TSDB_RELATION_NOTNULL) { + ures = true; + } else if (unit->compare.optr == TSDB_RELATION_ISNULL) { + ures = false; + } else { + ures = filterDoCompare(unit, FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_VAL_FIELD_DATA(right)); + } + } + FILTER_UNIT_SET_R(info, uidx, ures); FILTER_UNIT_SET_F(info, uidx); } diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 9ef9da44c3..ee35ec1660 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -48,65 +48,820 @@ sql insert into tb6 values ('2021-05-05 18:19:24',61,61.0,61,61,61,61.0,true ,'6 sql insert into tb6 values ('2021-05-05 18:19:25',62,62.0,62,62,62,62.0,true ,'62','62') sql insert into tb6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'63','63') sql insert into tb6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') - +sql insert into tb6 values ('2021-05-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) sleep 100 print "column test" +sql select * from stb1 +if $rows != 29 then + return -1 +endi sql select * from stb1 where c1 > 0 if $rows != 28 then return -1 endi -#sql select * from stb1 where c1 > 0 and c1 > 3 -#sql select * from stb1 where c1 > 0 or c1 > 3 -#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 2 -#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 -#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 -#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 -#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 1 and c1 > 4 -#sql select * from stb1 where c1 > 0 and c1 > 3 and c1 < 1 or c1 > 4 -#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 and c1 > 4 -#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 and c1 > 4 -#sql select * from stb1 where c1 > 0 and c1 > 3 or c1 < 1 or c1 > 4 -#sql select * from stb1 where c1 > 0 or c1 > 3 and c1 < 1 or c1 > 4 -#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 and c1 > 4 -#sql select * from stb1 where c1 > 0 or c1 > 3 or c1 < 1 or c1 > 4 -# -#sql select * from stb1 where (c1 > 0 and c1 > 3) and c1 < 2 -#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 2) -#sql select * from stb1 where (c1 > 0 or c1 > 3) or c1 < 1 -#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) -#sql select * from stb1 where (c1 > 0 and c1 > 3) or c1 < 1 -#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) -#sql select * from stb1 where (c1 > 0 or c1 > 3) and c1 < 1 -#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) -#sql select * from stb1 where (c1 > 0 and c1 > 3) and (c1 < 1 and c1 > 4) -#sql select * from stb1 where (c1 > 0 and c1 > 3 and c1 < 1) and c1 > 4 -#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 1) and c1 > 4 -#sql select * from stb1 where c1 > 0 and (c1 > 3 and c1 < 1 or c1 > 4) -#sql select * from stb1 where (c1 > 0 and c1 > 3) or (c1 < 1 and c1 > 4) -#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) and c1 > 4 -#sql select * from stb1 where (c1 > 0 and c1 > 3 or c1 < 1) and c1 > 4 -#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1 and c1 > 4) -#sql select * from stb1 where (c1 > 0 or c1 > 3) and (c1 < 1 and c1 > 4) -#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1 and c1 > 4) -#sql select * from stb1 where (c1 > 0 or c1 > 3 and c1 < 1) and c1 > 4 -#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) and c1 > 4 -#sql select * from stb1 where (c1 > 0 and c1 > 3) or (c1 < 1 or c1 > 4) -#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1 or c1 > 4) -#sql select * from stb1 where (c1 > 0 and c1 > 3 or c1 < 1) or c1 > 4 -#sql select * from stb1 where c1 > 0 and (c1 > 3 or c1 < 1) or c1 > 4 -#sql select * from stb1 where (c1 > 0 or c1 > 3) and (c1 < 1 or c1 > 4) -#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1 or c1 > 4) -#sql select * from stb1 where (c1 > 0 or c1 > 3 and c1 < 1) or c1 > 4 -#sql select * from stb1 where c1 > 0 or (c1 > 3 and c1 < 1) or c1 > 4 -#sql select * from stb1 where (c1 > 0 or c1 > 3) or (c1 < 1 and c1 > 4) -#sql select * from stb1 where (c1 > 0 or c1 > 3 or c1 < 1) and c1 > 4 -#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1 and c1 > 4) -#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) and c1 > 4 -#sql select * from stb1 where (c1 > 0 or c1 > 3) or (c1 < 1 or c1 > 4) -#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1 or c1 > 4) -#sql select * from stb1 where (c1 > 0 or c1 > 3 or c1 < 1) or c1 > 4 -#sql select * from stb1 where c1 > 0 or (c1 > 3 or c1 < 1) or c1 > 4 + +sql_error select * from stb1 where c8 > 0 +sql_error select * from stb1 where c1 in (0,1); +sql_error select ts,c1,c7 from stb1 where c7 > false +sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; +sql_error select * from stb1 where c1 > NULL; +sql_error select * from stb1 where c1 = NULL; +sql_error select * from stb1 where c1 LIKE '%1'; + +sql select * from stb1 where c2 > 3.0 or c2 < 60; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c2 > 3.0 or c2 < 60 and c2 > 50; +if $rows != 25 then + return -1 +endi +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50; +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 and c2 != 63); +if $rows != 6 then + return -1 +endi + +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 or c2 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c3 > 3.0 or c3 < 60) and c3 > 50 and (c3 != 53 or c3 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c4 > 3.0 or c4 < 60) and c4 > 50 and (c4 != 53 or c4 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c5 > 3.0 or c5 < 60) and c5 > 50 and (c5 != 53 or c5 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c6 > 3.0 or c6 < 60) and c6 > 50 and (c6 != 53 or c6 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where c8 = '51'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi + +sql select * from stb1 where c8 != '51'; +if $rows != 27 then + return -1 +endi + +sql select * from stb1 where c8 = '51' and c8 != '51'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c8 = '51' or c8 != '51'; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c9 = '51'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi + +sql select * from stb1 where c9 != '51'; +if $rows != 27 then + return -1 +endi + +sql select * from stb1 where c9 = '51' and c9 != '51'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = '51' or c9 != '51'; +if $rows != 28 then + return -1 +endi + +sql select ts,c1,c7 from stb1 where c7 = false +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data12 != 0 then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data21 != 13 then + return -1 +endi +if $data22 != 0 then + return -1 +endi +if $data30 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data32 != 0 then + return -1 +endi + + +sql select ts,c1,c7 from stb1 where c7 = true +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data20 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data21 != 11 then + return -1 +endi +if $data22 != 1 then + return -1 +endi +if $data30 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data31 != 12 then + return -1 +endi +if $data32 != 1 then + return -1 +endi + + +sql select * from stb1 where c8 = '51' or c8 = '4' +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data01 != 4 then + return -1 +endi +if $data10 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data11 != 51 then + return -1 +endi + + +sql select * from stb1 where c1 > 50 and c1 > 53 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 52 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 and c1 > 54 +if $rows != 4 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 or c1 > 54 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 51 or c1 > 54 +if $rows != 4 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 and c1 > 54 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 > 51 and c1 < 54 +if $rows != 7 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 or c1 > 54 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 or c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 > 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 or c1 > 54 +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where (c1 > 50 and c1 > 53) and c1 < 52 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 52) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or c1 < 51 +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) +if $rows != 28 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or c1 < 51 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) +if $rows != 5 then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and c1 < 51 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) +if $rows != 8 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) and (c1 < 51 and c1 > 54) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51 or c1 > 54) +if $rows != 4 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 and c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 and c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 and c1 > 54) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 or c1 > 54) +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 or c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 or c1 > 54) +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 or c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) or c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) or c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 62 or (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 or c1 > 54) +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 or c1 > 54) +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select ts,c1 from stb1 where (c1 > 60 or c1 < 10 or (c1 > 20 and c1 < 30)) and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:25.000' and c1 != 21 and c1 != 22 +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data31 != 23 then + return -1 +endi +if $data40 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data41 != 24 then + return -1 +endi +if $data50 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data51 != 61 then + return -1 +endi + sql select * from stb1 where (c1 > 40 or c1 < 20) and (c2 < 53 or c2 >= 63) and c3 > 1 and c3 < 5 if $rows != 3 then @@ -166,6 +921,327 @@ if $data41 != 54 then return -1 endi +sql select * from stb1 where (c3 > 52 or c3 < 10) and (c4 > 1 and c4 < 61) and (c5 = 2 or c6 = 3.0 or c6 = 4.0 or c6 = 53); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data31 != 53 then + return -1 +endi + +sql select * from stb1 where c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c2 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c3 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c4 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c5 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c6 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c7 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c8 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c9 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql select * from stb1 where c1 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c2 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c3 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c4 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c5 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c6 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c7 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c8 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c9 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c1 > 63 or c1 is null; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data01 != 64 then + return -1 +endi +if $data10 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null and c3 is not null; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:28.000'; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:21.000@ then + return -1 +endi + +sql select * from stb1 where c8 LIKE '%1'; +if $rows != 7 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c9 LIKE '%1'; +if $rows != 7 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c8 LIKE '%1' or c9 like '_2') and (c5 > 50 or c6 > 30) and ( c8 like '3_' or c9 like '4_') and (c4 <= 31 or c4 >= 42); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi print "ts test" From 547fa5c03d8051dd6f008fda13d3ced4cca49da4 Mon Sep 17 00:00:00 2001 From: dapan1121 <89396746@qq.com> Date: Sat, 19 Jun 2021 14:35:11 +0800 Subject: [PATCH 005/100] add case --- tests/script/general/parser/condition.sim | 85 +++++++++++++++++------ 1 file changed, 64 insertions(+), 21 deletions(-) diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index ee35ec1660..53d795e143 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1261,26 +1261,53 @@ print "column&tbname test" print "column&tag test" -#sql_error select * from stb1 where t1 > 0 or c1 > 0 -#sql_error select * from stb1 where c1 > 0 or t1 > 0 -#sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 -#sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 -#sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 -#sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -#sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -#sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 -#sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) -#sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 -# -# -#sql select * from stb1 where c1 > 0 and t1 > 0 -#sql select * from stb1 where t1 > 0 and c1 > 0 -#sql select * from stb1 where t1 > 0 and t1 > 3 and c1 > 1 -#sql select * from stb1 where t1 > 0 and c1 > 0 and t1 > 1 -#sql select * from stb1 where c1 > 0 and t1 > 0 and c1 > 1 -#sql select * from stb1 where c1 > 0 and (t1 > 0 or t1 > 1) -#sql select * from stb1 where (t1 > 0 or t1 > 2 ) and (c1 > 1 or c1 > 3) -#sql select * from stb1 where c1 > 0 and (t1 > 0 or t1 > 1) +sql_error select * from stb1 where t1 > 0 or c1 > 0 +sql_error select * from stb1 where c1 > 0 or t1 > 0 +sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 +sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 + + +sql select * from stb1 where c1 < 63 and t1 > 5 +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select * from stb1 where t1 > 3 and t1 < 5 and c1 != 42 and c1 != 44; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:18.000@ then + return -1 +endi +sql select * from stb1 where t1 > 1 and c1 > 21 and t1 < 3 and c1 < 24 and t1 != 3 and c1 != 23; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:09.000@ then + return -1 +endi +sql select * from stb1 where c1 > 1 and (t1 > 3 or t1 < 2) and (c2 > 2 and c2 < 62 and t1 != 4) and (t1 > 2 and t1 < 6) and c7 = true and c8 like '%2'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:21.000@ then + return -1 +endi + print "column&join test" @@ -1303,7 +1330,20 @@ print "tag&join test" print "column&ts&tbname test" print "column&ts&tag test" - +sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +sql select * from stb1 where ts > '2021-05-05 18:19:00.000' and c1 > 2 and t1 != 1 and c2 >= 23 and t2 >= 3 and c3 < 63 and c7 = false and t3 > 3 and t3 < 6 and c8 like '4%' and ts < '2021-05-05 18:19:19.000' and c2 > 40 and c3 != 42; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:18.000@ then + return -1 +endi print "column&ts&join test" print "column&tbname&tag test" @@ -1319,6 +1359,9 @@ print "tbname&tag&join test" print "column&ts&tbname&tag test" +select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; !!!!! + + print "column&ts&tbname&join test" print "column&ts&tag&join test" print "column&tbname&tag&join test" From 254dd64184fad142aa9c845e767d0fac003bf4df Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 21 Jun 2021 10:51:35 +0800 Subject: [PATCH 006/100] add case --- tests/script/general/parser/condition.sim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 53d795e143..839c3c8bb4 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1359,7 +1359,11 @@ print "tbname&tag&join test" print "column&ts&tbname&tag test" -select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; !!!!! +# select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; +#=> select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (tbname like 'tb%' or (t1 > 5 or t1 < 4)) and c1 > 0; +# select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; +#=> select * from stb1 where (ts > '2021-05-05 18:19:01.000' or ts > '2021-05-05 18:19:02.000') and t1 > 3 and (t1 > 5 or t1 < 4) and c1 > 0; +#select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; print "column&ts&tbname&join test" From 4cb2fca7000d0c9a92cd3c7ac08f7aad3b3c3fe5 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 21 Jun 2021 18:23:36 +0800 Subject: [PATCH 007/100] support IN --- src/common/inc/texpr.h | 1 + src/common/src/texpr.c | 171 ++++++++++++++++++++++ src/query/src/qFilter.c | 7 + src/util/src/tcompare.c | 41 ++++++ src/util/src/thashutil.c | 1 + tests/script/general/parser/condition.sim | 51 ++++++- 6 files changed, 271 insertions(+), 1 deletion(-) diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 2e49a69366..65ff05ad3e 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -95,6 +95,7 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, char *(*cb)(void *, const char*, int32_t)); void buildFilterSetFromBinary(void **q, const char *buf, int32_t len); +void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType); #ifdef __cplusplus } diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 0e9ec053cc..74a406f4ef 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -495,6 +495,177 @@ void buildFilterSetFromBinary(void **q, const char *buf, int32_t len) { *q = (void *)pObj; } +void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType) { + SBufferReader br = tbufInitReader(buf, len, false); + uint32_t sType = tbufReadUint32(&br); + SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false); + + taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType)); + + int dummy = -1; + tVariant tmpVar = {0}; + size_t t = 0; + int32_t sz = tbufReadInt32(&br); + void *pvar = NULL; + int32_t bufLen = 0; + if (IS_NUMERIC_TYPE(sType)) { + bufLen = 60; // The maximum length of string that a number is converted to. + } else { + bufLen = 128; + } + + char *tmp = calloc(1, bufLen * TSDB_NCHAR_SIZE); + + for (int32_t i = 0; i < sz; i++) { + switch (sType) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: { + int8_t val = tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + int16_t val = tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_INT: { + int32_t val = tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_BIGINT: { + int64_t val = tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + double val = tbufReadDouble(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_FLOAT: { + float val = tbufReadDouble(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_BINARY: { + char *val = (char *)tbufReadBinary(&br, &t); + pvar = val; + break; + } + case TSDB_DATA_TYPE_NCHAR: { + char *val = (char *)tbufReadBinary(&br, &t); + pvar = val; + break; + } + default: + taosHashCleanup(pObj); + *q = NULL; + return; + } + + tVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType); + + if (bufLen < t) { + tmp = realloc(tmp, t * TSDB_NCHAR_SIZE); + bufLen = t; + } + + switch (tType) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: { + int8_t val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_SMALLINT: { + int16_t val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_INT: { + int32_t val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_BIGINT: { + int64_t val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + double val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_FLOAT: { + float val = 0; + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto err_ret; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_BINARY: { + if (tVariantDump(&tmpVar, tmp, tType, true)) { + goto err_ret; + } + t = varDataLen(tmp); + pvar = varDataVal(tmp); + break; + } + case TSDB_DATA_TYPE_NCHAR: { + if (tVariantDump(&tmpVar, tmp, tType, true)) { + goto err_ret; + } + t = varDataLen(tmp); + pvar = varDataVal(tmp); + break; + } + default: + goto err_ret; + } + + taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy)); + } + + *q = (void *)pObj; + pObj = NULL; + +err_ret: + taosHashCleanup(pObj); + tfree(tmp); +} + + tExprNode* exprdup(tExprNode* pNode) { if (pNode == NULL) { return NULL; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index cfd894b408..c2d7646636 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -326,6 +326,13 @@ int32_t filterInitValFieldData(SFilterInfo *info) { tVariant* var = fi->desc; + if (unit->compare.optr == TSDB_RELATION_IN) { + convertFilterSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); + CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); + + continue; + } + if (type == TSDB_DATA_TYPE_BINARY) { fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); } else if (type == TSDB_DATA_TYPE_NCHAR) { diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index e953f4c464..4cc8eeece6 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -19,6 +19,22 @@ #include "tarray.h" #include "hash.h" +int32_t setCompareBytes1(const void *pLeft, const void *pRight) { + return NULL != taosHashGet((SHashObj *)pRight, pLeft, 1) ? 1 : 0; +} + +int32_t setCompareBytes2(const void *pLeft, const void *pRight) { + return NULL != taosHashGet((SHashObj *)pRight, pLeft, 2) ? 1 : 0; +} + +int32_t setCompareBytes4(const void *pLeft, const void *pRight) { + return NULL != taosHashGet((SHashObj *)pRight, pLeft, 4) ? 1 : 0; +} + +int32_t setCompareBytes8(const void *pLeft, const void *pRight) { + return NULL != taosHashGet((SHashObj *)pRight, pLeft, 8) ? 1 : 0; +} + int32_t compareInt32Val(const void *pLeft, const void *pRight) { int32_t left = GET_INT32_VAL(pLeft), right = GET_INT32_VAL(pRight); if (left > right) return 1; @@ -309,6 +325,29 @@ static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { __compar_fn_t getComparFunc(int32_t type, int32_t optr) { __compar_fn_t comparFn = NULL; + + if (optr == TSDB_RELATION_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + return setCompareBytes1; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + return setCompareBytes2; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_FLOAT: + return setCompareBytes4; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_TIMESTAMP: + return setCompareBytes8; + default: + assert(0); + } + } switch (type) { case TSDB_DATA_TYPE_BOOL: @@ -334,6 +373,8 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr) { case TSDB_DATA_TYPE_NCHAR: { if (optr == TSDB_RELATION_LIKE) { comparFn = compareWStrPatternComp; + } else if (optr == TSDB_RELATION_IN) { + comparFn = compareFindItemInSet; } else { comparFn = compareLenPrefixedWStr; } diff --git a/src/util/src/thashutil.c b/src/util/src/thashutil.c index ffe167977b..fa2c95aaad 100644 --- a/src/util/src/thashutil.c +++ b/src/util/src/thashutil.c @@ -131,6 +131,7 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { case TSDB_DATA_TYPE_NCHAR: fn = MurmurHash3_32;break; case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break; case TSDB_DATA_TYPE_SMALLINT: fn = taosIntHash_16; break; + case TSDB_DATA_TYPE_BOOL: fn = taosIntHash_8; break; case TSDB_DATA_TYPE_TINYINT: fn = taosIntHash_8; break; case TSDB_DATA_TYPE_FLOAT: fn = taosFloatHash; break; case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleHash; break; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 839c3c8bb4..7a132d039a 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -62,7 +62,12 @@ if $rows != 28 then endi sql_error select * from stb1 where c8 > 0 -sql_error select * from stb1 where c1 in (0,1); +sql_error select * from stb1 where c2 in (0,1); +sql_error select * from stb1 where c6 in (0,2,3,1); +sql_error select * from stb1 where c7 in (0,2,3,1); +sql_error select * from stb1 where c8 in (true); +sql_error select * from stb1 where c8 in (1,2); +sql_error select * from stb1 where t3 in (3); sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; @@ -1243,6 +1248,50 @@ if $data10 != @21-05-05 18:19:17.000@ then return -1 endi +sql select * from stb1 where c1 in (1,3); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where c3 in (11,22); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi + +sql select * from stb1 where c4 in (3,33); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:14.000@ then + return -1 +endi + +#sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); +#if $rows != 2 then +# return -1 +#endi +#if $data00 != @21-05-05 18:19:02.000@ then +# return -1 +#endi +#if $data10 != @21-05-05 18:19:14.000@ then +# return -1 +#endi + print "ts test" print "tbname test" From 518a2ae8184b2fbafda33364c8a78edd56a82189 Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 22 Jun 2021 10:01:24 +0800 Subject: [PATCH 008/100] support unsigned --- src/common/src/texpr.c | 18 +++-- src/util/src/thashutil.c | 4 + tests/script/general/parser/condition.sim | 95 ++++++++++++++++++++--- 3 files changed, 102 insertions(+), 15 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index ede60b5001..32689e9abb 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -526,26 +526,30 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t for (int32_t i = 0; i < sz; i++) { switch (sType) { case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { - int8_t val = tbufReadInt64(&br); + uint8_t val = (uint8_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { - int16_t val = tbufReadInt64(&br); + uint16_t val = (uint16_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { - int32_t val = tbufReadInt64(&br); + uint32_t val = (uint32_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { - int64_t val = tbufReadInt64(&br); + uint64_t val = (uint64_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; @@ -557,7 +561,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t break; } case TSDB_DATA_TYPE_FLOAT: { - float val = tbufReadDouble(&br); + float val = (float)tbufReadDouble(&br); t = sizeof(val); pvar = &val; break; @@ -587,6 +591,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t switch (tType) { case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { int8_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -596,6 +601,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { int16_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -605,6 +611,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { int32_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { @@ -614,6 +621,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { int64_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { diff --git a/src/util/src/thashutil.c b/src/util/src/thashutil.c index fa2c95aaad..13df8e4ee6 100644 --- a/src/util/src/thashutil.c +++ b/src/util/src/thashutil.c @@ -126,12 +126,16 @@ _hash_fn_t taosGetDefaultHashFunction(int32_t type) { _hash_fn_t fn = NULL; switch(type) { case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: fn = taosIntHash_64;break; case TSDB_DATA_TYPE_BINARY: fn = MurmurHash3_32;break; case TSDB_DATA_TYPE_NCHAR: fn = MurmurHash3_32;break; + case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: fn = taosIntHash_32; break; + case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: fn = taosIntHash_16; break; case TSDB_DATA_TYPE_BOOL: fn = taosIntHash_8; break; + case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: fn = taosIntHash_8; break; case TSDB_DATA_TYPE_FLOAT: fn = taosFloatHash; break; case TSDB_DATA_TYPE_DOUBLE: fn = taosDoubleHash; break; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 7a132d039a..228bc90fd1 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -49,6 +49,29 @@ sql insert into tb6 values ('2021-05-05 18:19:25',62,62.0,62,62,62,62.0,true ,'6 sql insert into tb6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'63','63') sql insert into tb6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') sql insert into tb6 values ('2021-05-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) + +sql create table stb2 (ts timestamp, u1 int unsigned, u2 bigint unsigned, u3 smallint unsigned, u4 tinyint unsigned, ts2 timestamp) TAGS(t1 int unsigned, t2 bigint unsigned, t3 timestamp) + +sql create table tb2_1 using stb2 tags(1,1,'2021-05-05 18:38:38') +sql create table tb2_2 using stb2 tags(2,2,'2021-05-05 18:58:58') + +sql insert into tb2_1 values ('2021-05-05 18:19:00',1,2,3,4,'2021-05-05 18:28:01') +sql insert into tb2_1 values ('2021-05-05 18:19:01',5,6,7,8,'2021-05-05 18:28:02') +sql insert into tb2_1 values ('2021-05-05 18:19:02',2,2,3,4,'2021-05-05 18:28:03') +sql insert into tb2_1 values ('2021-05-05 18:19:03',5,6,7,8,'2021-05-05 18:28:04') +sql insert into tb2_1 values ('2021-05-05 18:19:04',3,2,3,4,'2021-05-05 18:28:05') +sql insert into tb2_1 values ('2021-05-05 18:19:05',5,6,7,8,'2021-05-05 18:28:06') +sql insert into tb2_1 values ('2021-05-05 18:19:06',4,2,3,4,'2021-05-05 18:28:07') +sql insert into tb2_1 values ('2021-05-05 18:19:07',5,6,7,8,'2021-05-05 18:28:08') +sql insert into tb2_1 values ('2021-05-05 18:19:08',5,2,3,4,'2021-05-05 18:28:09') +sql insert into tb2_1 values ('2021-05-05 18:19:09',5,6,7,8,'2021-05-05 18:28:10') +sql insert into tb2_1 values ('2021-05-05 18:19:10',6,2,3,4,'2021-05-05 18:28:11') +sql insert into tb2_2 values ('2021-05-05 18:19:11',5,6,7,8,'2021-05-05 18:28:12') +sql insert into tb2_2 values ('2021-05-05 18:19:12',7,2,3,4,'2021-05-05 18:28:13') +sql insert into tb2_2 values ('2021-05-05 18:19:13',5,6,7,8,'2021-05-05 18:28:14') +sql insert into tb2_2 values ('2021-05-05 18:19:14',8,2,3,4,'2021-05-05 18:28:15') +sql insert into tb2_2 values ('2021-05-05 18:19:15',5,6,7,8,'2021-05-05 18:28:16') + sleep 100 print "column test" @@ -68,6 +91,7 @@ sql_error select * from stb1 where c7 in (0,2,3,1); sql_error select * from stb1 where c8 in (true); sql_error select * from stb1 where c8 in (1,2); sql_error select * from stb1 where t3 in (3); +sql_error select * from stb1 where t2 in (3.0); sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; @@ -1281,22 +1305,73 @@ if $data10 != @21-05-05 18:19:14.000@ then return -1 endi -#sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); -#if $rows != 2 then -# return -1 -#endi -#if $data00 != @21-05-05 18:19:02.000@ then -# return -1 -#endi -#if $data10 != @21-05-05 18:19:14.000@ then -# return -1 -#endi +sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) and c8 in ('33','54'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) or c8 in ('22','54'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select * from stb1 where (c9 in ('3','1','2','4','5') or c9 in ('33','11','22','44','55')) and c9 in ('1','3','11','13'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:04.000@ then + return -1 +endi + +#sql select * from stb2 where (u1 in (1,2,3,4) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) print "ts test" print "tbname test" print "tag test" +sql select * from stb1 where t1 in (1,2) and t1 in (2,3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi print "join test" From 4b4913bc89ca562b6c30bd57478078f024154cba Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 23 Jun 2021 08:55:46 +0800 Subject: [PATCH 009/100] support unsigned/ts --- src/client/inc/tscUtil.h | 3 +- src/client/src/tscSQLParser.c | 9 ++-- src/client/src/tscSubquery.c | 5 ++ src/client/src/tscUtil.c | 59 +++++++++++++++++++++++ src/common/src/texpr.c | 2 + src/query/src/qExecutor.c | 2 +- tests/script/general/parser/condition.sim | 35 +++++++++++++- 7 files changed, 108 insertions(+), 7 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index d6ce0d48a6..5e8805e49d 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -230,8 +230,9 @@ SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid); void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw); int32_t tscTagCondCopy(STagCond* dest, const STagCond* src); +int32_t tscColCondCopy(SArray** dest, const SArray* src); void tscTagCondRelease(STagCond* pCond); - +void tscColCondRelease(SArray** pCond); void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo); bool tscShouldBeFreed(SSqlObj* pSql); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 68ee81904e..fab97bdf5a 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8222,8 +8222,9 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS } else if (pSqlExpr->tokenId == TK_SET) { int32_t colType = -1; STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta; - if (pCols != NULL && taosArrayGetSize(pCols) > 0) { - SColIndex* idx = taosArrayGet(pCols, 0); + size_t colSize = taosArrayGetSize(pCols); + if (pCols != NULL && colSize > 0) { + SColIndex* idx = taosArrayGet(pCols, colSize - 1); SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); if (pSchema != NULL) { colType = pSchema->type; @@ -8295,4 +8296,6 @@ bool hasNormalColumnFilter(SQueryInfo* pQueryInfo) { return false; } - \ No newline at end of file + + + diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 22a603b71e..75ee8bcea7 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2318,6 +2318,11 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) { goto _error; } + if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond) != 0) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto _error; + } + pNewQueryInfo->window = pQueryInfo->window; pNewQueryInfo->interval = pQueryInfo->interval; pNewQueryInfo->sessionWindow = pQueryInfo->sessionWindow; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 5067febdb2..d7ae97da1a 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2703,6 +2703,54 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { return 0; } +int32_t tscColCondCopy(SArray** dest, const SArray* src) { + if (src == NULL) { + return 0; + } + + size_t s = taosArrayGetSize(src); + *dest = taosArrayInit(s, sizeof(SCond)); + + for (int32_t i = 0; i < s; ++i) { + SCond* pCond = taosArrayGet(src, i); + + SCond c = {0}; + c.len = pCond->len; + c.uid = pCond->uid; + + if (pCond->len > 0) { + assert(pCond->cond != NULL); + c.cond = malloc(c.len); + if (c.cond == NULL) { + return -1; + } + + memcpy(c.cond, pCond->cond, c.len); + } + + taosArrayPush(*dest, &c); + } + + return 0; +} + +void tscColCondRelease(SArray** pCond) { + if (*pCond == NULL) { + return; + } + + size_t s = taosArrayGetSize(*pCond); + for (int32_t i = 0; i < s; ++i) { + SCond* p = taosArrayGet(*pCond, i); + tfree(p->cond); + } + + taosArrayDestroy(*pCond); + + *pCond = NULL; +} + + void tscTagCondRelease(STagCond* pTagCond) { free(pTagCond->tbnameCond.cond); @@ -2894,6 +2942,7 @@ int32_t tscAddQueryInfo(SSqlCmd* pCmd) { static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { tscTagCondRelease(&pQueryInfo->tagCond); + tscColCondRelease(&pQueryInfo->colCond); tscFieldInfoClear(&pQueryInfo->fieldsInfo); tscExprDestroy(pQueryInfo->exprList); @@ -2978,6 +3027,11 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { goto _error; } + if (tscColCondCopy(&pQueryInfo->colCond, pSrc->colCond) != 0) { + code = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto _error; + } + if (pSrc->fillType != TSDB_FILL_NONE) { pQueryInfo->fillVal = malloc(pSrc->fieldsInfo.numOfOutput * sizeof(int64_t)); if (pQueryInfo->fillVal == NULL) { @@ -3342,6 +3396,11 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t goto _error; } + if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond) != 0) { + terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; + goto _error; + } + if (pQueryInfo->fillType != TSDB_FILL_NONE) { pNewQueryInfo->fillVal = malloc(pQueryInfo->fieldsInfo.numOfOutput * sizeof(int64_t)); if (pNewQueryInfo->fillVal == NULL) { diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 32689e9abb..285ebfcf31 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -547,6 +547,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t pvar = &val; break; } + case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { uint64_t val = (uint64_t)tbufReadInt64(&br); @@ -621,6 +622,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t t = sizeof(val); break; } + case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { int64_t val = 0; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 7d50c32e3c..93a19ce636 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2695,7 +2695,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa // Calculate all time windows that are overlapping or contain current data block. // If current data block is contained by all possible time window, do not load current data block. - if (pQueryAttr->numOfFilterCols > 0 || pQueryAttr->groupbyColumn || pQueryAttr->sw.gap > 0 || + if (pQueryAttr->pFilters || pQueryAttr->groupbyColumn || pQueryAttr->sw.gap > 0 || (QUERY_IS_INTERVAL_QUERY(pQueryAttr) && overlapWithTimeWindow(pQueryAttr, &pBlock->info))) { (*status) = BLK_DATA_ALL_NEEDED; } diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 228bc90fd1..85c9d8c2ce 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1349,7 +1349,24 @@ if $data20 != @21-05-05 18:19:04.000@ then return -1 endi -#sql select * from stb2 where (u1 in (1,2,3,4) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) +sql select * from stb2 where (u1 in (1) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) and ts2 in ('2021-05-05 18:28:02.000','2021-05-05 18:28:15.000','2021-05-05 18:28:01.000'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi + +sql select * from stb2 where u2 in (2) and u3 in (1,2,3) and u4 in (1,2,4,5) and u1 > 3 and u1 < 6 and u1 != 4; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi print "ts test" @@ -1373,6 +1390,11 @@ if $data30 != @21-05-05 18:19:11.000@ then return -1 endi +sql select * from stb2 where t1 in (1,2) and t2 in (2) and t3 in ('2021-05-05 18:58:57.000'); +if $rows != 0 then + return -1 +endi + print "join test" @@ -1438,7 +1460,16 @@ print "column&join test" print "ts&tbname test" print "ts&tag test" - +sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:12.000@ then + return -1 +endi print "ts&join test" print "tbname&tag test" From f617458496a94e1fceac31247d66690cd974cc64 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 23 Jun 2021 18:24:53 +0800 Subject: [PATCH 010/100] support ts condition --- src/client/src/tscSQLParser.c | 122 +++++++++++++++++----- src/client/src/tscServer.c | 2 +- tests/script/general/parser/condition.sim | 27 +++-- 3 files changed, 113 insertions(+), 38 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index fab97bdf5a..ab6bfa6c23 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3502,6 +3502,8 @@ enum { TSQL_EXPR_TBNAME = 8, }; +#define GET_MIXED_TYPE(t) ((t) > TSQL_EXPR_COLUMN || (t) == (TSQL_EXPR_TS|TSQL_EXPR_TAG)) + static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex); @@ -4103,10 +4105,9 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t } static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr, - int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr) { + int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr, tSqlExpr** tsExpr) { const char* msg1 = "table query cannot use tags filter"; const char* msg2 = "illegal column name"; - const char* msg3 = "only one query time range allowed"; const char* msg4 = "too many join tables"; const char* msg5 = "not support ordinary column join"; const char* msg6 = "only one query condition on tbname allowed"; @@ -4196,11 +4197,11 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql */ tSqlExprDestroy(*pExpr); } else { - ret = setExprToCond(&pCondExpr->pTimewindow, *pExpr, msg3, parentOptr, pQueryInfo->msg); + ret = setNormalExprToCond(tsExpr, *pExpr, parentOptr); } *pExpr = NULL; // remove this expression - *type |= TSQL_EXPR_TAG; + *type |= TSQL_EXPR_TS; } else if (index.columnIndex >= tscGetNumOfColumns(pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { // query on tags, check for tag query condition if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { @@ -4260,16 +4261,19 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql } int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr, - int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr) { + int32_t* type, int32_t parentOptr, tSqlExpr** columnExpr, tSqlExpr** tsExpr) { if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } tSqlExpr *columnLeft = NULL; tSqlExpr *columnRight = NULL; + tSqlExpr *tsLeft = NULL; + tSqlExpr *tsRight = NULL; + int32_t ret = 0; - const char* msg1 = "query condition between columns and tags/timestamp must use 'AND'"; + const char* msg1 = "query condition between columns and tags and timestamp must use 'AND'"; if ((*pExpr)->flags & (1 << EXPR_FLAG_TS_ERROR)) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -4286,12 +4290,12 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr int32_t rightType = 0; if (!tSqlExprIsParentOfLeaf(*pExpr)) { - ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->tokenId, &columnLeft); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, (*pExpr)->tokenId, &columnLeft, &tsLeft); if (ret != TSDB_CODE_SUCCESS) { goto err_ret; } - ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->tokenId, &columnRight); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, (*pExpr)->tokenId, &columnRight, &tsRight); if (ret != TSDB_CODE_SUCCESS) { goto err_ret; } @@ -4300,7 +4304,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr * if left child and right child do not belong to the same group, the sub * expression is not valid for parent node, it must be TK_AND operator. */ - if (((leftType != rightType) || (leftType == (TSQL_EXPR_COLUMN|TSQL_EXPR_TAG ))) && (*pExpr)->tokenId == TK_OR) { + if (((leftType != rightType) || GET_MIXED_TYPE(leftType)) && ((*pExpr)->tokenId == TK_OR)) { ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); goto err_ret; } @@ -4313,6 +4317,14 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr *columnExpr = columnLeft ? columnLeft : columnRight; } + if (tsLeft && tsRight) { + setNormalExprToCond(&tsLeft, tsRight, (*pExpr)->tokenId); + + *tsExpr = tsLeft; + } else { + *tsExpr = tsLeft ? tsLeft : tsRight; + } + *type = leftType|rightType; return TSDB_CODE_SUCCESS; @@ -4330,7 +4342,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr goto err_ret; } - ret = handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, parentOptr, columnExpr); + ret = handleExprInQueryCond(pCmd, pQueryInfo, pExpr, pCondExpr, type, parentOptr, columnExpr, tsExpr); if (ret) { goto err_ret; } @@ -4466,11 +4478,59 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, return TSDB_CODE_SUCCESS; } +int32_t mergeTimeRange(SSqlCmd* pCmd, STimeWindow* res, STimeWindow* win, int32_t optr) { + const char* msg0 = "only one time stamp window allowed"; -static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { +#define SET_EMPTY_RANGE(w) do { (w)->skey = INT64_MAX; (w)->ekey = INT64_MIN; } while (0) +#define IS_EMPTY_RANGE(w) ((w)->skey == INT64_MAX && (w)->ekey == INT64_MIN) + + if (optr == TSDB_RELATION_AND) { + if (res->skey > win->ekey || win->skey > res->ekey) { + SET_EMPTY_RANGE(res); + return TSDB_CODE_SUCCESS; + } + + if (res->skey < win->skey) { + res->skey = win->skey; + } + + if (res->ekey > win->ekey) { + res->ekey = win->ekey; + } + + return TSDB_CODE_SUCCESS; + } + + if (res->skey > win->ekey || win->skey > res->ekey) { + if (IS_EMPTY_RANGE(res)) { + res->skey = win->skey; + res->ekey = win->ekey; + return TSDB_CODE_SUCCESS; + } + + if (IS_EMPTY_RANGE(win)) { + return TSDB_CODE_SUCCESS; + } + + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); + } + + if (res->skey > win->skey) { + res->skey = win->skey; + } + + if (res->ekey < win->ekey) { + res->ekey = win->ekey; + } + + return TSDB_CODE_SUCCESS; +} + + +static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, STimeWindow* win) { const char* msg0 = "invalid timestamp or operator for timestamp"; - const char* msg1 = "only one time stamp window allowed"; int32_t code = 0; + STimeWindow win2 = {.skey = INT64_MIN, .ekey = INT64_MAX}; if (pExpr == NULL) { return TSDB_CODE_SUCCESS; @@ -4478,15 +4538,25 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE if (!tSqlExprIsParentOfLeaf(pExpr)) { if (pExpr->tokenId == TK_OR) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); + code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft, win); + if (code) { + return code; + } + + code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight, &win2); + if (code) { + return code; + } + + return mergeTimeRange(pCmd, win, &win2, TSDB_RELATION_OR); } - code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft); + code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft, win); if (code) { return code; } - return getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight); + return getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight, win); } else { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { @@ -4498,19 +4568,11 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE tSqlExpr* pRight = pExpr->pRight; - STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; - if (getTimeRange(&win, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) { + if (getTimeRange(&win2, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); } - // update the timestamp query range - if (pQueryInfo->window.skey < win.skey) { - pQueryInfo->window.skey = win.skey; - } - - if (pQueryInfo->window.ekey > win.ekey) { - pQueryInfo->window.ekey = win.ekey; - } + return mergeTimeRange(pCmd, win, &win2, TSDB_RELATION_AND); } return TSDB_CODE_SUCCESS; @@ -4859,12 +4921,11 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } int32_t type = 0; - if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId, &condExpr.pColumnCond)) != TSDB_CODE_SUCCESS) { + if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, (*pExpr)->tokenId, &condExpr.pColumnCond, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { return ret; } tSqlExprCompact(pExpr); - tSqlExprCompact(&condExpr.pColumnCond); // after expression compact, the expression tree is only include tag query condition condExpr.pTagCond = (*pExpr); @@ -4875,7 +4936,12 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } // 2. get the query time range - if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { + STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; + if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow, &win)) != TSDB_CODE_SUCCESS) { + return ret; + } + + if ((ret = mergeTimeRange(&pSql->cmd, &pQueryInfo->window,&win, TSDB_RELATION_AND)) != TSDB_CODE_SUCCESS) { return ret; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 156445ec36..76945c50b5 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2580,7 +2580,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool uint32_t size = tscGetTableMetaMaxSize(); if (pTableMetaInfo->pTableMeta == NULL) { - pTableMetaInfo->pTableMeta = calloc(1, size); + pTableMetaInfo->pTableMeta = malloc(size); pTableMetaInfo->tableMetaSize = size; } else if (pTableMetaInfo->tableMetaSize < size) { char *tmp = realloc(pTableMetaInfo->pTableMeta, size); diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 85c9d8c2ce..6b10101eaa 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -93,9 +93,6 @@ sql_error select * from stb1 where c8 in (1,2); sql_error select * from stb1 where t3 in (3); sql_error select * from stb1 where t2 in (3.0); sql_error select ts,c1,c7 from stb1 where c7 > false -sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; sql_error select * from stb1 where c1 > NULL; sql_error select * from stb1 where c1 = NULL; sql_error select * from stb1 where c1 LIKE '%1'; @@ -1369,6 +1366,9 @@ if $data00 != @21-05-05 18:19:08.000@ then endi print "ts test" +sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; print "tbname test" @@ -1401,9 +1401,10 @@ print "join test" print "column&ts test" +sql_error select count(*) from stb1 where ts > 0 or c1 > 0; print "column&tbname test" - +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; print "column&tag test" @@ -1458,8 +1459,11 @@ endi print "column&join test" print "ts&tbname test" +sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; print "ts&tag test" +sql_error select count(*) from stb1 where ts > 0 or t1 > 0; + sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; if $rows != 2 then return -1 @@ -1483,8 +1487,12 @@ print "tag&join test" print "column&ts&tbname test" +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0 or ts > 0; print "column&ts&tag test" +sql_error select count(*) from stb1 where t1 > 0 or c1 > 0 or ts > 0; +sql_error select count(*) from stb1 where c1 > 0 or t1 > 0 or ts > 0; + sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; if $rows != 1 then return -1 @@ -1502,10 +1510,13 @@ endi print "column&ts&join test" print "column&tbname&tag test" +sql_error select count(*) from stb1 where c1 > 0 or tbname in ('tb1') or t1 > 0; print "column&tbname&join test" print "column&tag&join test" print "ts&tbname&tag test" +sql_error select count(*) from stb1 where ts > 0 or tbname in ('tb1') or t1 > 0; + print "ts&tbname&join test" print "ts&tag&join test" print "tbname&tag&join test" @@ -1514,11 +1525,9 @@ print "tbname&tag&join test" print "column&ts&tbname&tag test" -# select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; -#=> select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (tbname like 'tb%' or (t1 > 5 or t1 < 4)) and c1 > 0; -# select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; -#=> select * from stb1 where (ts > '2021-05-05 18:19:01.000' or ts > '2021-05-05 18:19:02.000') and t1 > 3 and (t1 > 5 or t1 < 4) and c1 > 0; -#select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000'; +sql_error select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col > 0 and t1 > 0; print "column&ts&tbname&join test" From 39521a1b747de20df4dc628ce0e08871f196dfac Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 24 Jun 2021 18:20:11 +0800 Subject: [PATCH 011/100] fix test case and bugs --- src/client/src/tscSQLParser.c | 33 +++- src/inc/taosdef.h | 1 + tests/script/general/parser/condition.sim | 204 ++++++++++++++++++++++ tests/script/general/parser/where.sim | 38 ++-- 4 files changed, 243 insertions(+), 33 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ab6bfa6c23..1721c9bcd5 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4071,7 +4071,7 @@ static int32_t setNormalExprToCond(tSqlExpr** parent, tSqlExpr* pExpr, int32_t p } -static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { +static int32_t validateNullExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t index, char* msgBuf) { const char* msg = "only support is [not] null"; tSqlExpr* pRight = pExpr->pRight; @@ -4079,6 +4079,27 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { return invalidOperationMsg(msgBuf, msg); } + if (pRight->tokenId == TK_STRING) { + SSchema* pSchema = tscGetTableSchema(pTableMeta); + if (IS_VAR_DATA_TYPE(pSchema[index].type)) { + return TSDB_CODE_SUCCESS; + } + + char *v = strndup(pRight->token.z, pRight->token.n); + int32_t len = strRmquote(v, pRight->token.n); + if (len > 0) { + uint32_t type = 0; + tGetToken(v, &type); + + if (type == TK_NULL) { + free(v); + return invalidOperationMsg(msgBuf, msg); + } + } + + free(v); + } + return TSDB_CODE_SUCCESS; } @@ -4129,7 +4150,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; // validate the null expression - int32_t code = validateNullExpr(*pExpr, tscGetErrorMsgPayload(pCmd)); + int32_t code = validateNullExpr(*pExpr, pTableMeta, index.columnIndex, tscGetErrorMsgPayload(pCmd)); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -8086,12 +8107,8 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf SExprInfo* pExpr1 = tscExprGet(pQueryInfo, 0); if (pExpr1->base.functionId != TSDB_FUNC_TID_TAG) { - int32_t numOfCols = (int32_t)taosArrayGetSize(pQueryInfo->colList); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumn* pCols = taosArrayGetP(pQueryInfo->colList, i); - if (pCols->info.flist.numOfFilters > 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); - } + if ((pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) || IS_TSWINDOW_SPECIFIED(pQueryInfo->window)) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } } } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index dac2dc84b6..ac0cb02a3a 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -34,6 +34,7 @@ extern "C" { #define TSWINDOW_INITIALIZER ((STimeWindow) {INT64_MIN, INT64_MAX}) #define TSWINDOW_DESC_INITIALIZER ((STimeWindow) {INT64_MAX, INT64_MIN}) +#define IS_TSWINDOW_SPECIFIED(win) (((win).skey != INT64_MIN) || ((win).ekey != INT64_MAX)) #define TSKEY_INITIAL_VAL INT64_MIN diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 6b10101eaa..ddba3040c2 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -96,6 +96,15 @@ sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select * from stb1 where c1 > NULL; sql_error select * from stb1 where c1 = NULL; sql_error select * from stb1 where c1 LIKE '%1'; +sql_error select * from stb1 where c1 = 'NULL'; +sql_error select * from stb1 where c2 > 'NULL'; +sql_error select * from stb1 where c3 <> 'NULL'; +sql_error select * from stb1 where c4 != 'null'; +sql_error select * from stb1 where c5 >= 'null'; +sql_error select * from stb1 where c6 <= 'null'; +sql_error select * from stb1 where c7 < 'nuLl'; +sql_error select * from stb1 where c8 < 'nuLl'; +sql_error select * from stb1 where c9 > 'nuLl'; sql select * from stb1 where c2 > 3.0 or c2 < 60; if $rows != 28 then @@ -1365,10 +1374,205 @@ if $data00 != @21-05-05 18:19:08.000@ then return -1 endi +sql select avg(c1) from tb1 where (c1 > 12 or c2 > 10) and (c3 < 12 or c3 > 13); +if $rows != 1 then + return -1 +endi +if $data00 != 12.500000000 then + return -1 +endi + +sql select count(c1),sum(c3) from tb1 where ((c7 = true and c6 > 2) or (c1 > 10 or c3 < 3)) and ((c8 like '1%') or (c9 like '%2' or c9 like '%3')) interval(5s); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data02 != 14 then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 39 then + return -1 +endi + +sql select * from stb1 where c8 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c8 = 'NULL'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'NULL'; +if $rows != 0 then + return -1 +endi + +#sql select * from (select * from stb1 where (c1 > 60 or c1 < 10) and (c7 = true or c5 > 2 and c5 < 63)) where (c3 > 61 or c3 < 3); + + print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; +sql_error select * from stb1 where ts2 like '2021-05-05%'; + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; +if $rows != 29 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi print "tbname test" diff --git a/tests/script/general/parser/where.sim b/tests/script/general/parser/where.sim index 00a22eede6..682c5c688c 100644 --- a/tests/script/general/parser/where.sim +++ b/tests/script/general/parser/where.sim @@ -65,7 +65,14 @@ $tb = $tbPrefix . $i sql_error select * from $tb where c7 # TBASE-654 : invalid filter expression cause server crashed -sql_error select count(*) from $tb where c1<10 and c1<>2 +sql select count(*) from $tb where c1<10 and c1<>2 +if $rows != 1 then + return -1 +endi +if $data00 != 900 then + return -1 +endi + sql select * from $tb where c7 = false $val = $rowNum / 100 @@ -253,30 +260,11 @@ sql insert into tb_where_NULL values ('2019-01-01 09:00:02.000', 2, 'val2') sql_error select * from tb_where_NULL where c1 = NULL sql_error select * from tb_where_NULL where c1 <> NULL sql_error select * from tb_where_NULL where c1 < NULL -sql select * from tb_where_NULL where c1 = "NULL" -if $rows != 0 then - return -1 -endi - -sql select * from tb_where_NULL where c1 <> "NULL" -if $rows != 2 then - return -1 -endi -sql select * from tb_where_NULL where c1 <> "nulL" -if $rows != 2 then - return -1 -endi - -sql select * from tb_where_NULL where c1 > "NULL" -if $rows != 0 then - return -1 -endi - -sql select * from tb_where_NULL where c1 >= "NULL" -if $rows != 0 then - return -1 -endi - +sql_error select * from tb_where_NULL where c1 = "NULL" +sql_error select * from tb_where_NULL where c1 <> "NULL" +sql_error select * from tb_where_NULL where c1 <> "nulL" +sql_error select * from tb_where_NULL where c1 > "NULL" +sql_error select * from tb_where_NULL where c1 >= "NULL" sql select * from tb_where_NULL where c2 = "NULL" if $rows != 0 then return -1 From 385552c60dc0a21cb30cb25b16994f17fb4ec78e Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 25 Jun 2021 09:57:59 +0800 Subject: [PATCH 012/100] support join filter --- src/client/inc/tscUtil.h | 1 + src/client/src/tscSQLParser.c | 2 ++ src/client/src/tscServer.c | 2 +- src/client/src/tscSubquery.c | 4 ++++ src/client/src/tscUtil.c | 5 +++++ src/common/src/tname.c | 2 +- src/query/src/qExecutor.c | 2 +- 7 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 5e8805e49d..21941d81d4 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -61,6 +61,7 @@ typedef struct SJoinSupporter { uint64_t uid; // query table uid SArray* colList; // previous query information, no need to use this attribute, and the corresponding attribution SArray* exprList; + SArray* colCond; SFieldInfo fieldsInfo; STagCond tagCond; SGroupbyExpr groupInfo; // group by info diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 1721c9bcd5..315125d411 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3517,6 +3517,8 @@ static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCol SColumn* pColumn = tscColumnListInsert(pQueryInfo->colList, pIndex->columnIndex, pTableMeta->id.uid, pSchema); + pColumn->info.flist.numOfFilters++; + /* * in case of TK_AND filter condition, we first find the corresponding column and build the query condition together * the already existed condition. diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 76945c50b5..45e131d8a5 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -914,7 +914,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { //serializeColFilterInfo(pCol->flist.filterInfo, pCol->flist.numOfFilters, &pMsg); } - if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) { + if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0 && !onlyQueryTags(&query) ) { SCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid); if (pCond != NULL && pCond->cond != NULL) { pQueryMsg->colCondLen = htons(pCond->len); diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 75ee8bcea7..06809a6406 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -808,6 +808,7 @@ static void issueTsCompQuery(SSqlObj* pSql, SJoinSupporter* pSupporter, SSqlObj* STimeWindow window = pQueryInfo->window; tscInitQueryInfo(pQueryInfo); + pQueryInfo->colCond = pSupporter->colCond; pQueryInfo->window = window; TSDB_QUERY_CLEAR_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TAG_FILTER_QUERY); TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_MULTITABLE_QUERY); @@ -1883,6 +1884,9 @@ int32_t tscCreateJoinSubquery(SSqlObj *pSql, int16_t tableIndex, SJoinSupporter if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) { // return the tableId & tag SColumnIndex colIndex = {0}; + pSupporter->colCond = pNewQueryInfo->colCond; + pNewQueryInfo->colCond = NULL; + STagCond* pTagCond = &pSupporter->tagCond; assert(pTagCond->joinInfo.hasJoin); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index d7ae97da1a..d5d5292e2b 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2011,6 +2011,11 @@ int32_t tscGetResRowLength(SArray* pExprList) { } static void destroyFilterInfo(SColumnFilterList* pFilterList) { + if (pFilterList->filterInfo == NULL) { + pFilterList->numOfFilters = 0; + return; + } + for(int32_t i = 0; i < pFilterList->numOfFilters; ++i) { if (pFilterList->filterInfo[i].filterstr) { tfree(pFilterList->filterInfo[i].pz); diff --git a/src/common/src/tname.c b/src/common/src/tname.c index c1c6ffa4b3..692338acdf 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -61,7 +61,7 @@ bool tscValidateTableNameLength(size_t len) { // TODO refactor SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters) { - if (numOfFilters == 0) { + if (numOfFilters == 0 || src == NULL) { assert(src == NULL); return NULL; } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 93a19ce636..458c956cea 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -7078,7 +7078,7 @@ void* doDestroyFilterInfo(SSingleColumnFilterInfo* pFilterInfo, int32_t numOfFil int32_t createFilterInfo(SQueryAttr* pQueryAttr, uint64_t qId) { for (int32_t i = 0; i < pQueryAttr->numOfCols; ++i) { - if (pQueryAttr->tableCols[i].flist.numOfFilters > 0) { + if (pQueryAttr->tableCols[i].flist.numOfFilters > 0 && pQueryAttr->tableCols[i].flist.filterInfo != NULL) { pQueryAttr->numOfFilterCols++; } } From 45cd731d7bf1513d4c3bc5d8c69e2f68e7f905dd Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 30 Jun 2021 13:16:08 +0800 Subject: [PATCH 013/100] support range merge --- src/client/src/tscSQLParser.c | 57 +- src/common/src/ttypes.c | 62 +++ src/query/inc/qFilter.h | 37 ++ src/query/src/qFilter.c | 195 ++++++- src/query/tests/CMakeLists.txt | 13 +- src/query/tests/astTest.cpp | 635 ---------------------- src/query/tests/histogramTest.cpp | 142 ----- src/query/tests/patternMatchTest.cpp | 86 --- src/query/tests/percentileTest.cpp | 257 --------- src/query/tests/rangeMergeTest.cpp | 163 ++++++ src/query/tests/resultBufferTest.cpp | 163 ------ src/query/tests/tsBufTest.cpp | 515 ------------------ tests/script/general/parser/condition.sim | 170 +++++- tests/script/test.sh | 1 + 14 files changed, 669 insertions(+), 1827 deletions(-) delete mode 100644 src/query/tests/astTest.cpp delete mode 100644 src/query/tests/histogramTest.cpp delete mode 100644 src/query/tests/patternMatchTest.cpp delete mode 100644 src/query/tests/percentileTest.cpp create mode 100644 src/query/tests/rangeMergeTest.cpp delete mode 100644 src/query/tests/resultBufferTest.cpp delete mode 100644 src/query/tests/tsBufTest.cpp diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 830bfa3993..dc441dd280 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3494,9 +3494,10 @@ enum { TSQL_EXPR_TAG = 2, TSQL_EXPR_COLUMN = 4, TSQL_EXPR_TBNAME = 8, + TSQL_EXPR_JOIN = 16, }; -#define GET_MIXED_TYPE(t) ((t) > TSQL_EXPR_COLUMN || (t) == (TSQL_EXPR_TS|TSQL_EXPR_TAG)) +#define GET_MIXED_TYPE(t) (((t) >= TSQL_EXPR_JOIN) || ((t) > TSQL_EXPR_COLUMN && (t) < TSQL_EXPR_TBNAME) || ((t) == (TSQL_EXPR_TS|TSQL_EXPR_TAG))) static int32_t checkColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SColumnIndex* pIndex, tSqlExpr* pExpr, int32_t sqlOptr) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex); @@ -4216,12 +4217,17 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql * since this expression is used to set the join query type */ tSqlExprDestroy(*pExpr); + if (type) { + *type |= TSQL_EXPR_JOIN; + } } else { ret = setNormalExprToCond(tsExpr, *pExpr, parentOptr); + if (type) { + *type |= TSQL_EXPR_TS; + } } *pExpr = NULL; // remove this expression - *type |= TSQL_EXPR_TS; } else if (index.columnIndex >= tscGetNumOfColumns(pTableMeta) || index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { // query on tags, check for tag query condition if (UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) { @@ -4246,7 +4252,9 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - *type |= TSQL_EXPR_TAG; + if (type) { + *type |= TSQL_EXPR_TAG; + } *pExpr = NULL; } else { if (pRight != NULL && pRight->tokenId == TK_ID) { // join on tag columns for stable query @@ -4257,18 +4265,23 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql pQueryInfo->type |= TSDB_QUERY_TYPE_JOIN_QUERY; ret = setExprToCond(&pCondExpr->pJoinExpr, *pExpr, NULL, parentOptr, pQueryInfo->msg); *pExpr = NULL; + if (type) { + *type |= TSQL_EXPR_JOIN; + } } else { // do nothing // ret = setExprToCond(pCmd, &pCondExpr->pTagCond, // *pExpr, NULL, parentOptr); + if (type) { + *type |= TSQL_EXPR_TAG; + } } - - *type |= TSQL_EXPR_TAG; } - } else { // query on other columns - *type |= TSQL_EXPR_COLUMN; - + if (type) { + *type |= TSQL_EXPR_COLUMN; + } + if (pRight->tokenId == TK_ID) { // other column cannot be served as the join column return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } @@ -4293,7 +4306,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr int32_t ret = 0; - const char* msg1 = "query condition between columns and tags and timestamp must use 'AND'"; + const char* msg1 = "query condition between columns/tags/timestamp/join fields must use 'AND'"; const char* msg2 = "query condition between tables must use 'AND'"; if ((*pExpr)->flags & (1 << EXPR_FLAG_TS_ERROR)) { @@ -4313,12 +4326,12 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr int32_t rightTbIdx = 0; if (!tSqlExprIsParentOfLeaf(*pExpr)) { - ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, &leftType, &leftTbIdx, (*pExpr)->tokenId, &columnLeft, &tsLeft); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pLeft, pCondExpr, type ? &leftType : NULL, &leftTbIdx, (*pExpr)->tokenId, &columnLeft, &tsLeft); if (ret != TSDB_CODE_SUCCESS) { goto err_ret; } - ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, &rightType, &rightTbIdx, (*pExpr)->tokenId, &columnRight, &tsRight); + ret = getQueryCondExpr(pCmd, pQueryInfo, &(*pExpr)->pRight, pCondExpr, type ? &rightType : NULL, &rightTbIdx, (*pExpr)->tokenId, &columnRight, &tsRight); if (ret != TSDB_CODE_SUCCESS) { goto err_ret; } @@ -4327,7 +4340,7 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr * if left child and right child do not belong to the same group, the sub * expression is not valid for parent node, it must be TK_AND operator. */ - if (((leftType != rightType) || GET_MIXED_TYPE(leftType)) && ((*pExpr)->tokenId == TK_OR)) { + if (type != NULL && ((leftType != rightType) || GET_MIXED_TYPE(leftType)) && ((*pExpr)->tokenId == TK_OR)) { ret = invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1); goto err_ret; } @@ -4353,7 +4366,9 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr *tsExpr = tsLeft ? tsLeft : tsRight; } - *type = leftType|rightType; + if (type) { + *type = leftType|rightType; + } *tbIdx = (leftTbIdx == rightTbIdx) ? leftTbIdx : -1; return TSDB_CODE_SUCCESS; @@ -4956,10 +4971,24 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq int32_t type = 0; int32_t tbIdx = 0; - if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, &type, &tbIdx, (*pExpr)->tokenId, &condExpr.pColumnCond, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { + int32_t *etype = &type; + +#if 0 + //DISABLE PARENT CONDITION GROUP TYPE CHECK + if (taosArrayGetSize(pQueryInfo->pUpstream) > 0) { + etype = NULL; + } +#endif + + if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, etype, &tbIdx, (*pExpr)->tokenId, &condExpr.pColumnCond, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { return ret; } + if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 && condExpr.pTimewindow != NULL) { + setNormalExprToCond(&condExpr.pColumnCond, condExpr.pTimewindow, TK_AND); + condExpr.pTimewindow = NULL; + } + tSqlExprCompact(pExpr); // after expression compact, the expression tree is only include tag query condition diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 34dda32401..ffbdbd1bbe 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -560,6 +560,68 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { } } +int8_t getInt8Val(void *s) { + return (int8_t)GET_INT8_VAL(s); +} +uint8_t getUint8Val(void *s) { + return (uint8_t)GET_INT8_VAL(s); +} +int16_t getInt16Val(void *s) { + return (int16_t)GET_INT16_VAL(s); +} +uint16_t getUint16Val(void *s) { + return (uint16_t)GET_INT16_VAL(s); +} +int32_t getInt32Val(void *s) { + return (int32_t)GET_INT32_VAL(s); +} +uint32_t getUint32Val(void *s) { + return (uint32_t)GET_INT32_VAL(s); +} +int64_t getInt64Val(void *s) { + return (int64_t)GET_INT64_VAL(s); +} +uint64_t getUint64Val(void *s) { + return (uint64_t)GET_INT64_VAL(s); +} +float getFloatVal(void *s) { + return GET_FLOAT_VAL(s); +} +double getDoubleVal(void *s) { + return GET_DOUBLE_VAL(s); +} +void setInt8Val(void *d, void *s) { + *((int8_t *)d) = (int8_t)GET_INT8_VAL(s); +} +void setUint8Val(void *d, void *s) { + *((uint8_t *)d) = GET_INT8_VAL(s); +} +void setInt16Val(void *d, void *s) { + *((int16_t *)d) = (int16_t)GET_INT16_VAL(s); +} +void setUint16Val(void *d, void *s) { + *((uint16_t *)d) = GET_INT16_VAL(s); +} +void setInt32Val(void *d, void *s) { + *((int32_t *)d) = GET_INT32_VAL(s); +} +void setUint32Val(void *d, void *s) { + *((uint32_t *)d) = GET_INT32_VAL(s); +} +void setInt64Val(void *d, void *s) { + *((int64_t *)d) = GET_INT64_VAL(s); +} +void setUint64Val(void *d, void *s) { + *((uint64_t *)d) = GET_INT64_VAL(s); +} +void setFloatVal(void *d, void *s) { + SET_FLOAT_VAL(d, GET_FLOAT_VAL(s)); +} +void setDoubleVal(void *d, void *s) { + SET_DOUBLE_VAL(d, GET_DOUBLE_VAL(s)); +} + + void tsDataSwap(void *pLeft, void *pRight, int32_t type, int32_t size, void* buf) { switch (type) { case TSDB_DATA_TYPE_INT: diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 5fd25e40a9..afa8423244 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -32,11 +32,34 @@ enum { F_FIELD_MAX }; +enum { + MR_ST_START = 1, + MR_ST_FIN = 2, +}; + +enum { + MR_OPT_TS = 1, +}; + typedef struct OptrStr { uint16_t optr; char *str; } OptrStr; +typedef struct SFilterRange { + struct SFilterRange* prev; + struct SFilterRange* next; + int64_t s; + int64_t e; +} SFilterRange; + +typedef struct SFilterRMCtx { + int32_t type; + int32_t options; + int8_t status; + __compar_fn_t pCompareFunc; + SFilterRange *rs; +} SFilterRMCtx ; typedef struct SFilterField { uint16_t type; @@ -83,6 +106,15 @@ typedef struct SFilterInfo { uint8_t *unitFlags; // got result } SFilterInfo; +#define MR_GET_FLAG(st, f) (st & f) +#define MR_SET_FLAG(st, f) st |= (f) + +#define GEN_RANGE(r, t, s, e) do { r = calloc(1, sizeof(SFilterRange)); assignVal((char*)&(r)->s, s, 0, t); assignVal((char*)&(r)->e, e, 0, t); } while (0) +#define FREE_RANGE(rs, r) do { if (r->prev) { r->prev->next = r->next; } else { rs = r->next;} if (r->next) { r->next->prev = r->prev; } free(r); } while (0) +#define FREE_FROM_RANGE(rs, r) do { if (r->prev) { r->prev->next = NULL; } else { rs = NULL;} while (r) {SFilterRange *n = r->next; free(r); r = n; } } while (0) +#define INSERT_RANGE(rs, r, t, s, e) do { SFilterRange *n = calloc(1, sizeof(SFilterRange)); assignVal((char*)&n->s, s, 0, t); assignVal((char*)&n->e, e, 0, t); n->prev = r->prev; r->prev = n; if (r->prev) { r->prev->next = n; } else { rs->next = n; } n->next = r; } while (0) +#define APPEND_RANGE(r, t, s, e) do { SFilterRange *n = calloc(1, sizeof(SFilterRange)); assignVal((char*)&n->s, s, 0, t); assignVal((char*)&n->e, e, 0, t); n->prev = r; r->next = n; } while (0) + #define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0) #define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0) #define ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _err_return; } } while (0) @@ -112,6 +144,11 @@ typedef int32_t(*filter_desc_compare_func)(const void *, const void *); extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); +extern void* filterInitMergeRange(int32_t type, int32_t options); +extern int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr); +extern int32_t filterGetMergeRangeNum(void* h, int32_t* num); +extern int32_t filterGetMergeRangeRes(void* h, void *s, void* e); +extern int32_t filterFreeMergeRange(void* h); #ifdef __cplusplus } diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index c2d7646636..06f85d4af1 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -54,6 +54,199 @@ filter_desc_compare_func gDescCompare [F_FIELD_MAX] = { filterFieldValDescCompare }; +void* filterInitMergeRange(int32_t type, int32_t options) { + if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + qError("not supported range type:%d", type); + return NULL; + } + + SFilterRMCtx *ctx = calloc(1, sizeof(SFilterRMCtx)); + + ctx->type = type; + ctx->pCompareFunc = getComparFunc(type, 0); + + return ctx; +} + +int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + + if (ctx->rs == NULL) { + if (MR_GET_FLAG(ctx->status, MR_ST_START) == 0 || optr == TSDB_RELATION_OR) { + GEN_RANGE(ctx->rs, ctx->type, s, e); + MR_SET_FLAG(ctx->status, MR_ST_START); + } + + return TSDB_CODE_SUCCESS; + } + + SFilterRange *r = ctx->rs; + SFilterRange *rn = NULL; + + if (optr == TSDB_RELATION_AND) { + while (r != NULL) { + if (ctx->pCompareFunc(&r->s, e) > 0) { + FREE_FROM_RANGE(ctx->rs, r); + break; + } + + if (ctx->pCompareFunc(s, &r->e) > 0) { + rn = r->next; + FREE_RANGE(ctx->rs, r); + r = rn; + continue; + } + + if (ctx->pCompareFunc(s, &r->s) > 0) { + assignVal((char *)&r->s, s, 0, ctx->type); + } + + if (ctx->pCompareFunc(&r->e, e) > 0) { + assignVal((char *)&r->e, e, 0, ctx->type); + break; + } + + r = r->next; + } + + return TSDB_CODE_SUCCESS; + } + + + //TSDB_RELATION_OR + bool smerged = false; + bool emerged = false; + + while (r != NULL) { + if (ctx->pCompareFunc(&r->s, e) > 0) { + if (emerged == false) { + INSERT_RANGE(ctx->rs, r, ctx->type, s, e); + } + + break; + } + + if (ctx->pCompareFunc(s, &r->e) > 0) { + if (r->next) { + r= r->next; + continue; + } + + APPEND_RANGE(r, ctx->type, s, e); + break; + } + + if (smerged == false) { + if (ctx->pCompareFunc(&r->s, s) > 0) { + assignVal((char *)&r->s, s, 0, ctx->type); + } + + smerged = true; + } + + if (emerged == false) { + if (ctx->pCompareFunc(e, &r->e) > 0) { + assignVal((char *)&r->e, e, 0, ctx->type); + emerged = true; + e = &r->e; + r = r->next; + continue; + } + + break; + } + + if (ctx->pCompareFunc(e, &r->e) > 0) { + rn = r->next; + FREE_RANGE(ctx->rs, r); + r = rn; + + continue; + } else { + assignVal(e, (char *)&r->e, 0, ctx->type); + FREE_RANGE(ctx->rs, r); + + break; + } + } + + return TSDB_CODE_SUCCESS; +} + +int32_t filterFinMergeRange(void* h) { + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + + if (MR_GET_FLAG(ctx->status, MR_ST_FIN)) { + return TSDB_CODE_SUCCESS; + } + + if (MR_GET_FLAG(ctx->options, MR_OPT_TS)) { + + } + + MR_SET_FLAG(ctx->status, MR_ST_FIN); + + return TSDB_CODE_SUCCESS; +} + +int32_t filterGetMergeRangeNum(void* h, int32_t* num) { + filterFinMergeRange(h); + + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + + *num = 0; + + SFilterRange *r = ctx->rs; + + while (r) { + ++(*num); + r = r->next; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { + filterFinMergeRange(h); + + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + uint32_t num = 0; + SFilterRange* r = ctx->rs; + + while (r) { + assignVal(s + num * tDataTypes[ctx->type].bytes, (char *)&r->s, 0, ctx->type); + assignVal(e + num * tDataTypes[ctx->type].bytes, (char *)&r->e, 0, ctx->type); + + ++num; + r = r->next; + } + + if (num == 0) { + qError("no range result"); + return TSDB_CODE_QRY_APP_ERROR; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t filterFreeMergeRange(void* h) { + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + SFilterRange *r = ctx->rs; + SFilterRange *rn = NULL; + + while (r) { + rn = r->next; + free(r); + r = rn; + } + + free(ctx); + + return TSDB_CODE_SUCCESS; +} + + int32_t filterMergeGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { SFilterGroup gp = {0}; @@ -505,5 +698,3 @@ _err_return: } - - diff --git a/src/query/tests/CMakeLists.txt b/src/query/tests/CMakeLists.txt index 0cfe2ff165..475ade5c2f 100644 --- a/src/query/tests/CMakeLists.txt +++ b/src/query/tests/CMakeLists.txt @@ -20,9 +20,10 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread) ENDIF() -SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) -SET_SOURCE_FILES_PROPERTIES(./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w) -SET_SOURCE_FILES_PROPERTIES(./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w) -SET_SOURCE_FILES_PROPERTIES(./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w) -SET_SOURCE_FILES_PROPERTIES(./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w) -SET_SOURCE_FILES_PROPERTIES(./unitTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w) +#SET_SOURCE_FILES_PROPERTIES(./unitTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./rangeMergeTest.cpp PROPERTIES COMPILE_FLAGS -w) diff --git a/src/query/tests/astTest.cpp b/src/query/tests/astTest.cpp deleted file mode 100644 index 1143d00e8d..0000000000 --- a/src/query/tests/astTest.cpp +++ /dev/null @@ -1,635 +0,0 @@ -#include -#include -#include -#include - -#include "texpr.h" -#include "taosmsg.h" -#include "tsdb.h" -#include "tskiplist.h" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wwrite-strings" -#pragma GCC diagnostic ignored "-Wunused-function" - -typedef struct ResultObj { - int32_t numOfResult; - char * resultName[64]; -} ResultObj; - -static void initSchema(SSchema *pSchema, int32_t numOfCols); - -static void initSchema_binary(SSchema *schema, int32_t numOfCols); - -static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags); -static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags); - -static void dropMeter(SSkipList *pSkipList); - -static void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); - -static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); - -static void IllegalExprTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); - -static void Left2RightTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); -static void Right2LeftTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); - -void setValue(ResultObj *pResult, int32_t num, char **val) { - pResult->numOfResult = num; - for (int32_t i = 0; i < num; ++i) { - pResult->resultName[i] = val[i]; - } -} - -static void initSchema_binary(SSchema *schema, int32_t numOfCols) { - schema[0].type = TSDB_DATA_TYPE_BINARY; - schema[0].bytes = 8; - strcpy(schema[0].name, "a"); - - schema[1].type = TSDB_DATA_TYPE_DOUBLE; - schema[1].bytes = 8; - strcpy(schema[1].name, "b"); - - schema[2].type = TSDB_DATA_TYPE_INT; - schema[2].bytes = 20; - strcpy(schema[2].name, "c"); - - schema[3].type = TSDB_DATA_TYPE_BIGINT; - schema[3].bytes = 8; - strcpy(schema[3].name, "d"); - - schema[4].type = TSDB_DATA_TYPE_SMALLINT; - schema[4].bytes = 2; - strcpy(schema[4].name, "e"); - - schema[5].type = TSDB_DATA_TYPE_TINYINT; - schema[5].bytes = 1; - strcpy(schema[5].name, "f"); - - schema[6].type = TSDB_DATA_TYPE_FLOAT; - schema[6].bytes = 4; - strcpy(schema[6].name, "g"); - - schema[7].type = TSDB_DATA_TYPE_BOOL; - schema[7].bytes = 1; - strcpy(schema[7].name, "h"); -} - -static void initSchema(SSchema *schema, int32_t numOfCols) { - schema[0].type = TSDB_DATA_TYPE_INT; - schema[0].bytes = 8; - strcpy(schema[0].name, "a"); - - schema[1].type = TSDB_DATA_TYPE_DOUBLE; - schema[1].bytes = 8; - strcpy(schema[1].name, "b"); - - schema[2].type = TSDB_DATA_TYPE_BINARY; - schema[2].bytes = 20; - strcpy(schema[2].name, "c"); - - schema[3].type = TSDB_DATA_TYPE_BIGINT; - schema[3].bytes = 8; - strcpy(schema[3].name, "d"); - - schema[4].type = TSDB_DATA_TYPE_SMALLINT; - schema[4].bytes = 2; - strcpy(schema[4].name, "e"); - - schema[5].type = TSDB_DATA_TYPE_TINYINT; - schema[5].bytes = 1; - strcpy(schema[5].name, "f"); - - schema[6].type = TSDB_DATA_TYPE_FLOAT; - schema[6].bytes = 4; - strcpy(schema[6].name, "g"); - - schema[7].type = TSDB_DATA_TYPE_BOOL; - schema[7].bytes = 1; - strcpy(schema[7].name, "h"); -} - -// static void addOneNode(SSchema *pSchema, int32_t tagsLen, SSkipList *pSkipList, -// char *meterId, int32_t a, double b, char *c, int64_t d, int16_t e, int8_t f, float g, -// bool h, int32_t numOfTags) { -// STabObj *pMeter = calloc(1, sizeof(STabObj)); -// pMeter->numOfTags = numOfTags; -// pMeter->pTagData = calloc(1, tagsLen + TSDB_METER_ID_LEN); -// strcpy(pMeter->meterId, meterId); -// -// char *tags = pMeter->pTagData + TSDB_METER_ID_LEN; -// int32_t offset = 0; -// -// *(int32_t *) tags = a; -// -// offset += pSchema[0].bytes; -// *(double *) (tags + offset) = b; -// -// offset += pSchema[1].bytes; -// memcpy(tags + offset, c, 3); -// -// offset += pSchema[2].bytes; -// *(int64_t *) (tags + offset) = d; -// -// offset += pSchema[3].bytes; -// *(int16_t *) (tags + offset) = e; -// -// offset += pSchema[4].bytes; -// *(int8_t *) (tags + offset) = f; -// -// offset += pSchema[5].bytes; -// *(float *) (tags + offset) = g; -// -// offset += pSchema[6].bytes; -// *(int8_t *) (tags + offset) = h ? 1 : 0; -// -// SSkipListKey pKey = SSkipListCreateKey(pSchema[0].type, tags, pSchema[0].bytes); -// SSkipListPut(pSkipList, pMeter, &pKey, 1); -//} -// -// static void addOneNode_binary(SSchema *pSchema, int32_t tagsLen, SSkipList *pSkipList, -// char *meterId, int32_t a, double b, char *c, int64_t d, int16_t e, int8_t f, float g, -// bool h, int32_t numOfTags) { -// STabObj *pMeter = calloc(1, sizeof(STabObj)); -// pMeter->numOfTags = numOfTags; -// pMeter->pTagData = calloc(1, tagsLen + TSDB_METER_ID_LEN); -// strcpy(pMeter->meterId, meterId); -// -// char *tags = pMeter->pTagData + TSDB_METER_ID_LEN; -// int32_t offset = 0; -// memcpy(tags, c, pSchema[0].bytes); -// -// offset += pSchema[0].bytes; -// *(double *) (tags + offset) = b; -// -// offset += pSchema[1].bytes; -// *(int32_t *) (tags + offset) = a; -// -// offset += pSchema[2].bytes; -// *(int64_t *) (tags + offset) = d; -// -// offset += pSchema[3].bytes; -// *(int16_t *) (tags + offset) = e; -// -// offset += pSchema[4].bytes; -// *(int8_t *) (tags + offset) = f; -// -// offset += pSchema[5].bytes; -// *(float *) (tags + offset) = g; -// -// offset += pSchema[6].bytes; -// *(int8_t *) (tags + offset) = h ? 1 : 0; -// -// SSkipListKey pKey = SSkipListCreateKey(pSchema[0].type, tags, pSchema[0].bytes); -// SSkipListPut(pSkipList, pMeter, &pKey, 1); -// SSkipListDestroyKey(&pKey); -//} - -// static void dropMeter(SSkipList *pSkipList) { -// SSkipListNode **pRes = NULL; -// int32_t num = SSkipListIterateList(pSkipList, &pRes, NULL, NULL); -// for (int32_t i = 0; i < num; ++i) { -// SSkipListNode *pNode = pRes[i]; -// STabObj *pMeter = (STabObj *) pNode->pData; -// free(pMeter->pTagData); -// free(pMeter); -// pNode->pData = NULL; -// } -// free(pRes); -//} - -// static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags) { -// int32_t tagsLen = 0; -// for (int32_t i = 0; i < numOfTags; ++i) { -// tagsLen += pSchema[i].bytes; -// } -// -// SSkipList *pSkipList = SSkipListCreate(10, pSchema[0].type, 4); -// -// addOneNode(pSchema, tagsLen, pSkipList, "tm0\0", 0, 10.5, "abc", 1000, -10000, -20, 1.0, true, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm1\0", 1, 20.5, "def", 1100, -10500, -30, 2.0, false, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm2\0", 2, 30.5, "ghi", 1200, -11000, -40, 3.0, true, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm3\0", 3, 40.5, "jkl", 1300, -11500, -50, 4.0, false, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm4\0", 4, 50.5, "mno", 1400, -12000, -60, 5.0, true, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm5\0", 5, 60.5, "pqr", 1500, -12500, -70, 6.0, false, 8); -// addOneNode(pSchema, tagsLen, pSkipList, "tm6\0", 6, 70.5, "stu", 1600, -13000, -80, 7.0, true, 8); -// -// return pSkipList; -//} -// -// static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags) { -// int32_t tagsLen = 0; -// for (int32_t i = 0; i < numOfTags; ++i) { -// tagsLen += pSchema[i].bytes; -// } -// -// SSkipList *pSkipList = SSkipListCreate(10, pSchema[0].type, 4); -// -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm0\0", 0, 10.5, "abc", 1000, -10000, -20, 1.0, true, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm1\0", 1, 20.5, "def", 1100, -10500, -30, 2.0, false, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm2\0", 2, 30.5, "ghi", 1200, -11000, -40, 3.0, true, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm3\0", 3, 40.5, "jkl", 1300, -11500, -50, 4.0, false, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm4\0", 4, 50.5, "mno", 1400, -12000, -60, 5.0, true, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm5\0", 5, 60.5, "pqr", 1500, -12500, -70, 6.0, false, 8); -// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm6\0", 6, 70.5, "stu", 1600, -13000, -80, 7.0, true, 8); -// -// return pSkipList; -//} - -//static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, SSkipList *pSkipList, ResultObj *pResult) { -// tExprNode *pExpr = NULL; -// tSQLBinaryExprFromString(&pExpr, schema, numOfCols, sql, strlen(sql)); -// -// char str[512] = {0}; -// int32_t len = 0; -// if (pExpr == NULL) { -// printf("-----error in parse syntax:%s\n\n", sql); -// assert(pResult == NULL); -// return; -// } -// -// tSQLBinaryExprToString(pExpr, str, &len); -// printf("expr is: %s\n", str); -// -// SArray *result = NULL; -// // tExprTreeTraverse(pExpr, pSkipList, result, SSkipListNodeFilterCallback, &result); -// // printf("the result is:%lld\n", result.num); -// // -// // bool findResult = false; -// // for (int32_t i = 0; i < result.num; ++i) { -// // STabObj *pm = (STabObj *)result.pRes[i]; -// // printf("meterid:%s,\t", pm->meterId); -// // -// // for (int32_t j = 0; j < pResult->numOfResult; ++j) { -// // if (strcmp(pm->meterId, pResult->resultName[j]) == 0) { -// // findResult = true; -// // break; -// // } -// // } -// // assert(findResult == true); -// // findResult = false; -// // } -// -// printf("\n\n"); -// tExprTreeDestroy(&pExpr, NULL); -//} - -#if 0 -static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { - char str[256] = {0}; - - char *t0[1] = {"tm0"}; - char *t1[1] = {"tm1"}; - char *sql = NULL; - - ResultObj res = {1, {"tm1"}}; - testQueryStr(schema, numOfCols, "a=1", pSkipList, &res); - - char *tt[1] = {"tm6"}; - setValue(&res, 1, tt); - testQueryStr(schema, numOfCols, "a>=6", pSkipList, &res); - - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, "b<=10.6", pSkipList, &res); - - strcpy(str, "c<>'pqr'"); - char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; - setValue(&res, 6, t2); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - strcpy(str, "c='abc'"); - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - char *t3[6] = {"tm1", "tm2", "tm3", "tm4", "tm5", "tm6"}; - setValue(&res, 6, t3); - testQueryStr(schema, numOfCols, "d>1050", pSkipList, &res); - - char *t4[3] = {"tm4", "tm5", "tm6"}; - setValue(&res, 3, t4); - testQueryStr(schema, numOfCols, "g>4.5980765", pSkipList, &res); - - char *t5[4] = {"tm0", "tm2", "tm4", "tm6"}; - setValue(&res, 4, t5); - testQueryStr(schema, numOfCols, "h=true", pSkipList, &res); - - char *t6[3] = {"tm1", "tm3", "tm5"}; - setValue(&res, 3, t6); - testQueryStr(schema, numOfCols, "h=0", pSkipList, &res); - - sql = "(((b<40)))\0"; - char *t7[3] = {"tm0", "tm1", "tm2"}; - setValue(&res, 3, t7); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); - - sql = "((a=1) or (a=10)) or ((b=12))"; - setValue(&res, 1, t1); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); - - sql = "((((((a>0 and a<2))) or a=6) or a=3) or (b=50.5)) and h=0"; - char *t8[2] = {"tm1", "tm3"}; - setValue(&res, 2, t8); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); - - char *tf[1] = {"tm6"}; - setValue(&res, 1, tf); - testQueryStr(schema, numOfCols, "e = -13000", pSkipList, &res); - - char *ft[5] = {"tm0", "tm1", "tm2", "tm3", "tm4"}; - setValue(&res, 5, ft); - testQueryStr(schema, numOfCols, "f > -65", pSkipList, &res); -} - -void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { - ResultObj res = {1, {"tm1"}}; - testQueryStr(schema, numOfCols, "((1=a))", pSkipList, &res); - - char *t9[2] = {"tm0", "tm1"}; - setValue(&res, 2, t9); - testQueryStr(schema, numOfCols, "1>=a", pSkipList, &res); - - char *t0[1] = {"tm0"}; - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, "10.6>=b", pSkipList, &res); - - char *t10[3] = {"tm1", "tm3", "tm5"}; - setValue(&res, 3, t10); - testQueryStr(schema, numOfCols, "0=h", pSkipList, &res); -} - -static void IllegalExprTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { - testQueryStr(schema, numOfCols, "h=", pSkipList, NULL); - testQueryStr(schema, numOfCols, "h<", pSkipList, NULL); - testQueryStr(schema, numOfCols, "a=1 and ", pSkipList, NULL); - testQueryStr(schema, numOfCols, "and or", pSkipList, NULL); - testQueryStr(schema, numOfCols, "and a = 1 or", pSkipList, NULL); - testQueryStr(schema, numOfCols, "(())", pSkipList, NULL); - testQueryStr(schema, numOfCols, "(", pSkipList, NULL); - testQueryStr(schema, numOfCols, "(a", pSkipList, NULL); - testQueryStr(schema, numOfCols, "(a)", pSkipList, NULL); - testQueryStr(schema, numOfCols, "())", pSkipList, NULL); - testQueryStr(schema, numOfCols, "a===1", pSkipList, NULL); - testQueryStr(schema, numOfCols, "a=1 and ", pSkipList, NULL); -} - -static void Left2RightTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { - char str[256] = {0}; - char *sql = NULL; - - char *t0[1] = {"tm0"}; - char *t1[1] = {"tm1"}; - - ResultObj res = {1, {"tm0"}}; - strcpy(str, "a='abc'"); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - char *tt[1] = {"tm6"}; - setValue(&res, 1, tt); - testQueryStr(schema, numOfCols, "c>=6", pSkipList, &res); - - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, "b<=10.6", pSkipList, &res); - - strcpy(str, "a<>'pqr'"); - char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; - setValue(&res, 6, t2); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - strcpy(str, "a='abc'"); - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - char *t3[6] = {"tm1", "tm2", "tm3", "tm4", "tm5", "tm6"}; - setValue(&res, 6, t3); - testQueryStr(schema, numOfCols, "d>1050", pSkipList, &res); - - char *t4[3] = {"tm4", "tm5", "tm6"}; - setValue(&res, 3, t4); - testQueryStr(schema, numOfCols, "g>4.5980765", pSkipList, &res); - - char *t5[4] = {"tm0", "tm2", "tm4", "tm6"}; - setValue(&res, 4, t5); - testQueryStr(schema, numOfCols, "h=true", pSkipList, &res); - - char *t6[3] = {"tm1", "tm3", "tm5"}; - setValue(&res, 3, t6); - testQueryStr(schema, numOfCols, "h=0", pSkipList, &res); - - sql = "(((b<40)))\0"; - char *t7[3] = {"tm0", "tm1", "tm2"}; - setValue(&res, 3, t7); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); - - sql = "((c=1) or (c=10)) or ((b=12))\0"; - setValue(&res, 1, t1); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); - - sql = "((((((c>0 and c<2))) or c=6) or c=3) or (b=50.5)) and h=false\0"; - char *t8[2] = {"tm1", "tm3"}; - setValue(&res, 2, t8); - testQueryStr(schema, numOfCols, sql, pSkipList, &res); -} - -static void Right2LeftTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { - char str[256] = {0}; - char *sql = NULL; - - char *t0[1] = {"tm0"}; - char *t1[1] = {"tm1"}; - - ResultObj res = {1, {"tm0"}}; - strcpy(str, "'abc'=a"); - testQueryStr(schema, numOfCols, str, pSkipList, &res); - - char *tt[1] = {"tm6"}; - setValue(&res, 1, tt); - testQueryStr(schema, numOfCols, "6<=c", pSkipList, &res); - - setValue(&res, 1, t0); - testQueryStr(schema, numOfCols, "10.6>=b", pSkipList, &res); - - strcpy(str, "'pqr'<>a"); - char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; - setValue(&res, 6, t2); - testQueryStr(schema, numOfCols, str, pSkipList, &res); -} - -namespace { -// two level expression tree -tExprNode *createExpr1() { - auto *pLeft = (tExprNode*) calloc(1, sizeof(tExprNode)); - pLeft->nodeType = TSQL_NODE_COL; - pLeft->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); - - strcpy(pLeft->pSchema->name, "col_a"); - pLeft->pSchema->type = TSDB_DATA_TYPE_INT; - pLeft->pSchema->bytes = sizeof(int32_t); - pLeft->pSchema->colId = 1; - - auto *pRight = (tExprNode*) calloc(1, sizeof(tExprNode)); - pRight->nodeType = TSQL_NODE_VALUE; - pRight->pVal = (tVariant*) calloc(1, sizeof(tVariant)); - - pRight->pVal->nType = TSDB_DATA_TYPE_INT; - pRight->pVal->i64 = 12; - - auto *pRoot = (tExprNode*) calloc(1, sizeof(tExprNode)); - pRoot->nodeType = TSQL_NODE_EXPR; - - pRoot->_node.optr = TSDB_RELATION_EQUAL; - pRoot->_node.pLeft = pLeft; - pRoot->_node.pRight = pRight; - pRoot->_node.hasPK = true; - - return pRoot; -} - -// thress level expression tree -tExprNode* createExpr2() { - auto *pLeft2 = (tExprNode*) calloc(1, sizeof(tExprNode)); - pLeft2->nodeType = TSQL_NODE_COL; - pLeft2->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); - - strcpy(pLeft2->pSchema->name, "col_a"); - pLeft2->pSchema->type = TSDB_DATA_TYPE_BINARY; - pLeft2->pSchema->bytes = 20; - pLeft2->pSchema->colId = 1; - - auto *pRight2 = (tExprNode*) calloc(1, sizeof(tExprNode)); - pRight2->nodeType = TSQL_NODE_VALUE; - pRight2->pVal = (tVariant*) calloc(1, sizeof(tVariant)); - - pRight2->pVal->nType = TSDB_DATA_TYPE_BINARY; - const char* v = "hello world!"; - pRight2->pVal->pz = strdup(v); - pRight2->pVal->nLen = strlen(v); - - auto *p1 = (tExprNode*) calloc(1, sizeof(tExprNode)); - p1->nodeType = TSQL_NODE_EXPR; - - p1->_node.optr = TSDB_RELATION_LIKE; - p1->_node.pLeft = pLeft2; - p1->_node.pRight = pRight2; - p1->_node.hasPK = false; - - auto *pLeft1 = (tExprNode*) calloc(1, sizeof(tExprNode)); - pLeft1->nodeType = TSQL_NODE_COL; - pLeft1->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); - - strcpy(pLeft1->pSchema->name, "col_b"); - pLeft1->pSchema->type = TSDB_DATA_TYPE_DOUBLE; - pLeft1->pSchema->bytes = 8; - pLeft1->pSchema->colId = 99; - - auto *pRight1 = (tExprNode*) calloc(1, sizeof(tExprNode)); - pRight1->nodeType = TSQL_NODE_VALUE; - pRight1->pVal = (tVariant*) calloc(1, sizeof(tVariant)); - - pRight1->pVal->nType = TSDB_DATA_TYPE_DOUBLE; - pRight1->pVal->dKey = 91.99; - - auto *p2 = (tExprNode*) calloc(1, sizeof(tExprNode)); - p2->nodeType = TSQL_NODE_EXPR; - - p2->_node.optr = TSDB_RELATION_GREATER_EQUAL; - p2->_node.pLeft = pLeft1; - p2->_node.pRight = pRight1; - p2->_node.hasPK = false; - - auto *pRoot = (tExprNode*) calloc(1, sizeof(tExprNode)); - pRoot->nodeType = TSQL_NODE_EXPR; - - pRoot->_node.optr = TSDB_RELATION_OR; - pRoot->_node.pLeft = p1; - pRoot->_node.pRight = p2; - pRoot->_node.hasPK = true; - return pRoot; -} - -void exprSerializeTest1() { - tExprNode* p1 = createExpr1(); - SBufferWriter bw = tbufInitWriter(NULL, false); - exprTreeToBinary(&bw, p1); - - size_t size = tbufTell(&bw); - ASSERT_TRUE(size > 0); - char* b = tbufGetData(&bw, false); - - tExprNode* p2 = exprTreeFromBinary(b, size); - ASSERT_EQ(p1->nodeType, p2->nodeType); - - ASSERT_EQ(p2->_node.optr, p1->_node.optr); - ASSERT_EQ(p2->_node.pLeft->nodeType, p1->_node.pLeft->nodeType); - ASSERT_EQ(p2->_node.pRight->nodeType, p1->_node.pRight->nodeType); - - SSchema* s1 = p1->_node.pLeft->pSchema; - SSchema* s2 = p2->_node.pLeft->pSchema; - - ASSERT_EQ(s2->colId, s1->colId); - ASSERT_EQ(s2->type, s1->type); - ASSERT_EQ(s2->bytes, s1->bytes); - ASSERT_STRCASEEQ(s2->name, s1->name); - - tVariant* v1 = p1->_node.pRight->pVal; - tVariant* v2 = p2->_node.pRight->pVal; - - ASSERT_EQ(v1->nType, v2->nType); - ASSERT_EQ(v1->i64, v2->i64); - ASSERT_EQ(p1->_node.hasPK, p2->_node.hasPK); - - tExprTreeDestroy(&p1, nullptr); - tExprTreeDestroy(&p2, nullptr); - - // tbufClose(&bw); -} - -void exprSerializeTest2() { - tExprNode* p1 = createExpr2(); - SBufferWriter bw = tbufInitWriter(NULL, false); - exprTreeToBinary(&bw, p1); - - size_t size = tbufTell(&bw); - ASSERT_TRUE(size > 0); - char* b = tbufGetData(&bw, false); - - tExprNode* p2 = exprTreeFromBinary(b, size); - ASSERT_EQ(p1->nodeType, p2->nodeType); - - ASSERT_EQ(p2->_node.optr, p1->_node.optr); - ASSERT_EQ(p2->_node.pLeft->nodeType, p1->_node.pLeft->nodeType); - ASSERT_EQ(p2->_node.pRight->nodeType, p1->_node.pRight->nodeType); - - tExprNode* c1Left = p1->_node.pLeft; - tExprNode* c2Left = p2->_node.pLeft; - - ASSERT_EQ(c1Left->nodeType, c2Left->nodeType); - - ASSERT_EQ(c2Left->nodeType, TSQL_NODE_EXPR); - ASSERT_EQ(c2Left->_node.optr, TSDB_RELATION_LIKE); - - ASSERT_STRCASEEQ(c2Left->_node.pLeft->pSchema->name, "col_a"); - ASSERT_EQ(c2Left->_node.pRight->nodeType, TSQL_NODE_VALUE); - - ASSERT_STRCASEEQ(c2Left->_node.pRight->pVal->pz, "hello world!"); - - tExprNode* c1Right = p1->_node.pRight; - tExprNode* c2Right = p2->_node.pRight; - - ASSERT_EQ(c1Right->nodeType, c2Right->nodeType); - ASSERT_EQ(c2Right->nodeType, TSQL_NODE_EXPR); - ASSERT_EQ(c2Right->_node.optr, TSDB_RELATION_GREATER_EQUAL); - ASSERT_EQ(c2Right->_node.pRight->pVal->dKey, 91.99); - - ASSERT_EQ(p2->_node.hasPK, true); - - tExprTreeDestroy(&p1, nullptr); - tExprTreeDestroy(&p2, nullptr); - - // tbufClose(&bw); -} -} // namespace -TEST(testCase, astTest) { -// exprSerializeTest2(); -} -#endif \ No newline at end of file diff --git a/src/query/tests/histogramTest.cpp b/src/query/tests/histogramTest.cpp deleted file mode 100644 index 0266ecffc1..0000000000 --- a/src/query/tests/histogramTest.cpp +++ /dev/null @@ -1,142 +0,0 @@ -#include -#include -#include -#include - -#include "taos.h" -#include "qHistogram.h" - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-variable" - -namespace { -void doHistogramAddTest() { - SHistogramInfo* pHisto = NULL; - - /** - * use arrayList, elapsed time is: - * before: - * 10,000,000 45sec, bin:1000 (-O0) / 17sec. bin:1000, (-O3) - * - * after: - * - */ - struct timeval systemTime; - gettimeofday(&systemTime, NULL); - int64_t st = - (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; - for (int32_t i = 0; i < 10000; ++i) { - tHistogramAdd(&pHisto, i); - // tHistogramPrint(pHisto); - } - // - gettimeofday(&systemTime, NULL); - int64_t et = - (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; - printf("total elapsed time: %ld\n", et - st); - - printf("elements: %d, slot:%d \n", pHisto->numOfElems, pHisto->numOfEntries); - tHistogramPrint(pHisto); - - printf("%ld\n", tHistogramSum(pHisto, 1.5)); - printf("%ld\n", tHistogramSum(pHisto, 2)); - printf("%ld\n", tHistogramSum(pHisto, 3)); - printf("%ld\n", tHistogramSum(pHisto, 4)); - printf("%ld\n", tHistogramSum(pHisto, 5)); - printf("%ld\n", tHistogramSum(pHisto, 6)); - - for (int32_t i = 399; i < 400; ++i) { - printf("val:%d, %ld\n", i, tHistogramSum(pHisto, i)); - } - - double ratio[] = {0 / 100, 20.0 / 100, 88.0 / 100, 100 / 100}; - double* res = tHistogramUniform(pHisto, ratio, 4); - for (int32_t i = 0; i < 4; ++i) { - printf("%f\n", res[i]); - } - - SHistogramInfo* pHisto1 = NULL; - for (int32_t i = (90000 - 1); i >= 80000; --i) { - tHistogramAdd(&pHisto1, i); - } - tHistogramPrint(pHisto1); - - SHistogramInfo* pRes = tHistogramMerge(pHisto1, pHisto, MAX_HISTOGRAM_BIN); - assert(pRes->numOfElems == pHisto->numOfElems + pHisto1->numOfElems); - tHistogramPrint(pRes); - - tHistogramDestroy(&pHisto); - tHistogramDestroy(&pHisto1); - tHistogramDestroy(&pRes); - free(res); -} -void doHistogramRepeatTest() { - SHistogramInfo* pHisto = NULL; - struct timeval systemTime; - - gettimeofday(&systemTime, NULL); - int64_t st = - (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; - - for (int32_t i = 0; i < 1000; ++i) { - tHistogramAdd(&pHisto, -24 + i); - // tHistogramPrint(pHisto); - } - - tHistogramDestroy(&pHisto); - -} -} - -/* test validate the names for table/database */ -TEST(testCase, histogram_binary_search) { - SHistogramInfo* pHisto = tHistogramCreate(MAX_HISTOGRAM_BIN); - - pHisto->numOfEntries = 10; - for (int32_t i = 0; i < 10; ++i) { - pHisto->elems[i].num = 1; - pHisto->elems[i].val = i; - } - - int32_t idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 1); - assert(idx == 1); - - idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 9); - assert(idx == 9); - - idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 20); - assert(idx == 10); - - idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, -1); - assert(idx == 0); - - idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 3.9); - assert(idx == 4); - - free(pHisto); -} - -TEST(testCase, histogram_add) { - doHistogramAddTest(); - doHistogramRepeatTest(); -} - -TEST(testCase, heapsort) { - // int32_t num = 20; - // - // SHeapEntry* pEntry = tHeapCreate(num); - // - // for(int32_t i=0; i -#include -#include -#include - -#include "qAggMain.h" -#include "tcompare.h" - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-variable" - -TEST(testCase, patternMatchTest) { - SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; - - const char* str = "abcdef"; - int32_t ret = patternMatch("a%b%", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "tm01"; - ret = patternMatch("tm__", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "tkm1"; - ret = patternMatch("t%m1", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "tkm1"; - ret = patternMatch("%m1", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = ""; - ret = patternMatch("%_", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); - - str = "1"; - ret = patternMatch("%__", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); - - str = ""; - ret = patternMatch("%", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = " "; - ret = patternMatch("_", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "!"; - ret = patternMatch("%_", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "abcdefg"; - ret = patternMatch("abc%fg", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("abc%fg", str, 7, &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("abc%f_", str, 6, &info); - EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("abc%f_", str, 1, &info); // pattern string is longe than the size - EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("ab", str, 2, &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("a%", str, 2, &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "abcdefgabcdeju"; - ret = patternMatch("a__", str, 2, &info); - EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); - - str = "carzero"; - ret = patternMatch("%o", str, strlen(str), &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); - - str = "19"; - ret = patternMatch("%9", str, 2, &info); - EXPECT_EQ(ret, TSDB_PATTERN_MATCH); -} diff --git a/src/query/tests/percentileTest.cpp b/src/query/tests/percentileTest.cpp deleted file mode 100644 index 1b6951201a..0000000000 --- a/src/query/tests/percentileTest.cpp +++ /dev/null @@ -1,257 +0,0 @@ -#include -#include - -#include "qResultbuf.h" -#include "taos.h" -#include "taosdef.h" - -#include "qPercentile.h" - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-variable" - -namespace { -tMemBucket *createBigIntDataBucket(int32_t start, int32_t end) { - tMemBucket *pBucket = tMemBucketCreate(sizeof(int64_t), TSDB_DATA_TYPE_BIGINT, start, end); - for (int32_t i = start; i <= end; ++i) { - int64_t val = i; - tMemBucketPut(pBucket, &val, 1); - } - - return pBucket; -} - -tMemBucket *createIntDataBucket(int32_t start, int32_t end) { - tMemBucket *pBucket = tMemBucketCreate(sizeof(int32_t), TSDB_DATA_TYPE_INT, start, end); - - for (int32_t i = start; i <= end; ++i) { - int32_t val = i; - tMemBucketPut(pBucket, &val, 1); - } - - return pBucket; -} - -tMemBucket *createDoubleDataBucket(int32_t start, int32_t end) { - tMemBucket *pBucket = tMemBucketCreate(sizeof(double), TSDB_DATA_TYPE_DOUBLE, start, end); - for (int32_t i = start; i <= end; ++i) { - double val = i; - int32_t ret = tMemBucketPut(pBucket, &val, 1); - if (ret != 0) { - printf("value out of range:%f", val); - } - } - - return pBucket; -} - -tMemBucket *createUnsignedDataBucket(int32_t start, int32_t end, int32_t type) { - tMemBucket *pBucket = tMemBucketCreate(tDataTypes[type].bytes, type, start, end); - for (int32_t i = start; i <= end; ++i) { - uint64_t k = i; - int32_t ret = tMemBucketPut(pBucket, &k, 1); - if (ret != 0) { - printf("value out of range:%" PRId64, k); - } - } - - return pBucket; -} - -void intDataTest() { - printf("running %s\n", __FUNCTION__); - - tMemBucket *pBucket = NULL; - double result = 0.; - - pBucket = createIntDataBucket(0, 0); - result = getPercentile(pBucket, 0); - ASSERT_DOUBLE_EQ(result, 0); - tMemBucketDestroy(pBucket); - - pBucket = createIntDataBucket(0, 1); - result = getPercentile(pBucket, 100); - ASSERT_DOUBLE_EQ(result, 1); - - result = getPercentile(pBucket, 0); - ASSERT_DOUBLE_EQ(result, 0); - tMemBucketDestroy(pBucket); - - pBucket = createIntDataBucket(-1, 1); - - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 0); - - result = getPercentile(pBucket, 0); - ASSERT_DOUBLE_EQ(result, -1); - - result = getPercentile(pBucket, 75); - ASSERT_DOUBLE_EQ(result, 0.5); - - result = getPercentile(pBucket, 100); - ASSERT_DOUBLE_EQ(result, 1); - tMemBucketDestroy(pBucket); - - pBucket = createIntDataBucket(0, 99999); - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 49999.5); - - tMemBucketDestroy(pBucket); -} - -void bigintDataTest() { - printf("running %s\n", __FUNCTION__); - - tMemBucket *pBucket = NULL; - double result = 0.0; - - pBucket = createBigIntDataBucket(-1000, 1000); - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 0.); - tMemBucketDestroy(pBucket); - - pBucket = createBigIntDataBucket(-10000, 10000); - result = getPercentile(pBucket, 100); - ASSERT_DOUBLE_EQ(result, 10000.0); - tMemBucketDestroy(pBucket); - - pBucket = createBigIntDataBucket(-10000, 10000); - result = getPercentile(pBucket, 75); - ASSERT_DOUBLE_EQ(result, 5000.0); - - tMemBucketDestroy(pBucket); -} - -void doubleDataTest() { - printf("running %s\n", __FUNCTION__); - - tMemBucket *pBucket = NULL; - double result = 0; - - pBucket = createDoubleDataBucket(-10, 10); - result = getPercentile(pBucket, 0); - ASSERT_DOUBLE_EQ(result, -10.0); - - printf("result is: %lf\n", result); - tMemBucketDestroy(pBucket); - - pBucket = createDoubleDataBucket(-100000, 100000); - result = getPercentile(pBucket, 25); - ASSERT_DOUBLE_EQ(result, -50000); - - printf("result is: %lf\n", result); - - tMemBucketDestroy(pBucket); - - pBucket = createDoubleDataBucket(-100000, 100000); - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 0); - - tMemBucketDestroy(pBucket); - - pBucket = createDoubleDataBucket(-100000, 100000); - result = getPercentile(pBucket, 75); - ASSERT_DOUBLE_EQ(result, 50000); - tMemBucketDestroy(pBucket); - - pBucket = createDoubleDataBucket(-100000, 100000); - - result = getPercentile(pBucket, 100); - ASSERT_DOUBLE_EQ(result, 100000.0); - - printf("result is: %lf\n", result); - tMemBucketDestroy(pBucket); -} - -/* - * large data test, we employ 0.1billion double data to calculated the percentile - * which is 800MB data - */ -void largeDataTest() { - printf("running : %s\n", __FUNCTION__); - - tMemBucket *pBucket = NULL; - double result = 0; - - struct timeval tv; - gettimeofday(&tv, NULL); - - int64_t start = tv.tv_sec; - printf("start time: %" PRId64 "\n", tv.tv_sec); - pBucket = createDoubleDataBucket(0, 100000000); - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 50000000); - - gettimeofday(&tv, NULL); - - printf("total elapsed time: %" PRId64 " sec.", -start + tv.tv_sec); - printf("the result of %d is: %lf\n", 50, result); - tMemBucketDestroy(pBucket); -} - -void qsortTest() { - printf("running : %s\n", __FUNCTION__); - - SSchema field[1] = { - {TSDB_DATA_TYPE_INT, "k", sizeof(int32_t)}, - }; - - const int32_t num = 2000; - - int32_t *d = (int32_t *)malloc(sizeof(int32_t) * num); - for (int32_t i = 0; i < num; ++i) { - d[i] = i % 4; - } - - const int32_t numOfOrderCols = 1; - int32_t orderColIdx = 0; - SColumnModel * pModel = createColumnModel(field, 1, 1000); - tOrderDescriptor *pDesc = tOrderDesCreate(&orderColIdx, numOfOrderCols, pModel, 1); - - tColDataQSort(pDesc, num, 0, num - 1, (char *)d, 1); - - for (int32_t i = 0; i < num; ++i) { - printf("%d\t", d[i]); - } - printf("\n"); - - destroyColumnModel(pModel); -} - -void unsignedDataTest() { - printf("running %s\n", __FUNCTION__); - - tMemBucket *pBucket = NULL; - double result = 0.0; - - pBucket = createUnsignedDataBucket(0, 1000, TSDB_DATA_TYPE_UINT); - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 500.0); - tMemBucketDestroy(pBucket); - - pBucket = createUnsignedDataBucket(0, 10000, TSDB_DATA_TYPE_UBIGINT); - result = getPercentile(pBucket, 100); - ASSERT_DOUBLE_EQ(result, 10000.0); - - result = getPercentile(pBucket, 0); - ASSERT_DOUBLE_EQ(result, 0.0); - - result = getPercentile(pBucket, 50); - ASSERT_DOUBLE_EQ(result, 5000); - - result = getPercentile(pBucket, 75); - ASSERT_DOUBLE_EQ(result, 7500); - tMemBucketDestroy(pBucket); - -} - -} // namespace - -TEST(testCase, percentileTest) { -// qsortTest(); - intDataTest(); - bigintDataTest(); - doubleDataTest(); - unsignedDataTest(); - largeDataTest(); -} diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp new file mode 100644 index 0000000000..b64c1a7494 --- /dev/null +++ b/src/query/tests/rangeMergeTest.cpp @@ -0,0 +1,163 @@ +#include +#include + +#include "qResultbuf.h" +#include "taos.h" +#include "taosdef.h" + +#include "qFilter.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace { + +void intDataTest() { + printf("running %s\n", __FUNCTION__); + int32_t s0[3] = {-100, 1, 3}; + int32_t e0[3] = {0 , 2, 4}; + int64_t s1[3] = {INT64_MIN, 0 , 3}; + int64_t e1[3] = {100 , 50, 4}; + int64_t s2[5] = {1 , 3 , 10,30,70}; + int64_t e2[5] = {10, 100, 20,50,120}; + int64_t s3[3] = {1 , 20 , 5}; + int64_t e3[3] = {10, 100, 25}; + + int32_t rs0[3]; + int32_t re0[3]; + int64_t rs1[3]; + int64_t re1[3]; + int64_t rs2[5]; + int64_t re2[5]; + int64_t rs3[5]; + int64_t re3[5]; + + int32_t num = 0; + + void *h = filterInitMergeRange(TSDB_DATA_TYPE_INT, 0); + for (int32_t i = 0; i < sizeof(s0)/sizeof(s0[0]); ++i) { + filterAddMergeRange(h, s0 + i, e0 + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + + h = filterInitMergeRange(TSDB_DATA_TYPE_INT, 0); + for (int32_t i = 0; i < sizeof(s0)/sizeof(s0[0]); ++i) { + filterAddMergeRange(h, s0 + i, e0 + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 3); + filterGetMergeRangeRes(h, rs0, re0); + ASSERT_EQ(rs0[0], -100); + ASSERT_EQ(re0[0], 0); + ASSERT_EQ(rs0[1], 1); + ASSERT_EQ(re0[1], 2); + ASSERT_EQ(rs0[2], 3); + ASSERT_EQ(re0[2], 4); + filterFreeMergeRange(h); + + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s1)/sizeof(s1[0]); ++i) { + filterAddMergeRange(h, s1 + i, e1 + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs1, re1); + ASSERT_EQ(rs1[0], 3); + ASSERT_EQ(re1[0], 4); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s1)/sizeof(s1[0]); ++i) { + filterAddMergeRange(h, s1 + i, e1 + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs1, re1); + ASSERT_EQ(rs1[0], INT64_MIN); + ASSERT_EQ(re1[0], 100); + filterFreeMergeRange(h); + + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { + filterAddMergeRange(h, s2 + i, e2 + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { + filterAddMergeRange(h, s2 + i, e2 + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs2, re2); + ASSERT_EQ(rs2[0], 1); + ASSERT_EQ(re2[0], 120); + filterFreeMergeRange(h); + + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { + filterAddMergeRange(h, s2 + i, e2 + i, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { + filterAddMergeRange(h, s2 + i, e2 + i, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs2, re2); + ASSERT_EQ(rs2[0], 70); + ASSERT_EQ(re2[0], 120); + filterFreeMergeRange(h); + + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s3)/sizeof(s3[0]); ++i) { + filterAddMergeRange(h, s3 + i, e3 + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < sizeof(s3)/sizeof(s3[0]); ++i) { + filterAddMergeRange(h, s3 + i, e3 + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs3, re3); + ASSERT_EQ(rs3[0], 1); + ASSERT_EQ(re3[0], 100); + filterFreeMergeRange(h); + + + +} + + +} // namespace + +TEST(testCase, rangeMergeTest) { + intDataTest(); + +} diff --git a/src/query/tests/resultBufferTest.cpp b/src/query/tests/resultBufferTest.cpp deleted file mode 100644 index 54ac0bf4e5..0000000000 --- a/src/query/tests/resultBufferTest.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include -#include -#include - -#include "qResultbuf.h" -#include "taos.h" -#include "tsdb.h" - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-variable" - -namespace { -// simple test -void simpleTest() { - SDiskbasedResultBuf* pResultBuf = NULL; - int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4096, 1); - - int32_t pageId = 0; - int32_t groupId = 0; - - tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); - ASSERT_TRUE(pBufPage != NULL); - - ASSERT_EQ(getResBufSize(pResultBuf), 1024); - - SIDList list = getDataBufPagesIdList(pResultBuf, groupId); - ASSERT_EQ(taosArrayGetSize(list), 1); - ASSERT_EQ(getNumOfResultBufGroupId(pResultBuf), 1); - - releaseResBufPage(pResultBuf, pBufPage); - - tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); - - tFilePage* t = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t == pBufPage1); - - tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t1 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t1 == pBufPage2); - - tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t2 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t2 == pBufPage3); - - tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t3 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t3 == pBufPage4); - - tFilePage* pBufPage5 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t4 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t4 == pBufPage5); - - destroyResultBuf(pResultBuf); -} - -void writeDownTest() { - SDiskbasedResultBuf* pResultBuf = NULL; - int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, 1); - - int32_t pageId = 0; - int32_t writePageId = 0; - int32_t groupId = 0; - int32_t nx = 12345; - - tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); - ASSERT_TRUE(pBufPage != NULL); - - *(int32_t*)(pBufPage->data) = nx; - writePageId = pageId; - releaseResBufPage(pResultBuf, pBufPage); - - tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t1 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t1 == pBufPage1); - ASSERT_TRUE(pageId == 1); - - tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t2 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t2 == pBufPage2); - ASSERT_TRUE(pageId == 2); - - tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t3 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t3 == pBufPage3); - ASSERT_TRUE(pageId == 3); - - tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t4 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t4 == pBufPage4); - ASSERT_TRUE(pageId == 4); - releaseResBufPage(pResultBuf, t4); - - // flush the written page to disk, and read it out again - tFilePage* pBufPagex = getResBufPage(pResultBuf, writePageId); - ASSERT_EQ(*(int32_t*)pBufPagex->data, nx); - - SArray* pa = getDataBufPagesIdList(pResultBuf, groupId); - ASSERT_EQ(taosArrayGetSize(pa), 5); - - destroyResultBuf(pResultBuf); -} - -void recyclePageTest() { - SDiskbasedResultBuf* pResultBuf = NULL; - int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, 1); - - int32_t pageId = 0; - int32_t writePageId = 0; - int32_t groupId = 0; - int32_t nx = 12345; - - tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); - ASSERT_TRUE(pBufPage != NULL); - releaseResBufPage(pResultBuf, pBufPage); - - tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t1 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t1 == pBufPage1); - ASSERT_TRUE(pageId == 1); - - tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t2 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t2 == pBufPage2); - ASSERT_TRUE(pageId == 2); - - tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t3 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t3 == pBufPage3); - ASSERT_TRUE(pageId == 3); - - tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t4 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t4 == pBufPage4); - ASSERT_TRUE(pageId == 4); - releaseResBufPage(pResultBuf, t4); - - tFilePage* pBufPage5 = getNewDataBuf(pResultBuf, groupId, &pageId); - tFilePage* t5 = getResBufPage(pResultBuf, pageId); - ASSERT_TRUE(t5 == pBufPage5); - ASSERT_TRUE(pageId == 5); - - // flush the written page to disk, and read it out again - tFilePage* pBufPagex = getResBufPage(pResultBuf, writePageId); - *(int32_t*)(pBufPagex->data) = nx; - writePageId = pageId; // update the data - releaseResBufPage(pResultBuf, pBufPagex); - - tFilePage* pBufPagex1 = getResBufPage(pResultBuf, 1); - - SArray* pa = getDataBufPagesIdList(pResultBuf, groupId); - ASSERT_EQ(taosArrayGetSize(pa), 6); - - destroyResultBuf(pResultBuf); -} -} // namespace - - -TEST(testCase, resultBufferTest) { - srand(time(NULL)); - simpleTest(); - writeDownTest(); - recyclePageTest(); -} diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp deleted file mode 100644 index 04c5a15252..0000000000 --- a/src/query/tests/tsBufTest.cpp +++ /dev/null @@ -1,515 +0,0 @@ -#include "os.h" -#include -#include -#include - -#include "qTsbuf.h" -#include "taos.h" -#include "tsdb.h" -#include "ttoken.h" -#include "tutil.h" - -#pragma GCC diagnostic ignored "-Wunused-function" -#pragma GCC diagnostic ignored "-Wunused-variable" -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" - -namespace { -/** - * - * @param num total number - * @param step gap between two consecutive ts - * @return - */ -int64_t* createTsList(int32_t num, int64_t start, int32_t step) { - int64_t* pList = (int64_t*)malloc(num * sizeof(int64_t)); - - for (int64_t i = 0; i < num; ++i) { - pList[i] = start + i * step; - } - - return pList; -} - -// simple test -void simpleTest() { - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - // write 10 ts points - int32_t num = 10; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - t.i64 = 1; - - int64_t* list = createTsList(10, 10000000, 30); - tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); - EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); - - EXPECT_EQ(pTSBuf->tsData.len, sizeof(int64_t) * num); - EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0); - EXPECT_EQ(pTSBuf->numOfGroups, 1); - - tsBufFlush(pTSBuf); - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(pTSBuf->block.numOfElem, num); - - tsBufDestroy(pTSBuf); - - free(list); -} - -// one large list of ts, the ts list need to be split into several small blocks -void largeTSTest() { - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - // write 10 ts points - int32_t num = 1000000; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - t.i64 = 1; - - int64_t* list = createTsList(num, 10000000, 30); - tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); - - // the data has been flush to disk, no data in cache - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0); - EXPECT_EQ(pTSBuf->numOfGroups, 1); - EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); - - tsBufFlush(pTSBuf); - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(pTSBuf->block.numOfElem, num); - - tsBufDestroy(pTSBuf); - free(list); -} - -void multiTagsTest() { - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - int32_t num = 10000; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - int64_t start = 10000000; - int32_t numOfTags = 50; - int32_t step = 30; - - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); - free(list); - - start += step * num; - } - - EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); - EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); - - EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); - EXPECT_EQ(pTSBuf->numOfGroups, 1); - - tsBufFlush(pTSBuf); - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(pTSBuf->block.numOfElem, num); - - tsBufDestroy(pTSBuf); -} - -void multiVnodeTagsTest() { - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - int32_t num = 10000; - int64_t start = 10000000; - int32_t numOfTags = 50; - int32_t step = 30; - - // 2000 vnodes - for (int32_t j = 0; j < 20; ++j) { - // vnodeId:0 - start = 10000000; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); - free(list); - - start += step * num; - } - - EXPECT_EQ(pTSBuf->numOfGroups, j + 1); - } - - EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); - EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); - EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); - - EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); - - EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); - - tsBufFlush(pTSBuf); - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(pTSBuf->block.numOfElem, num); - - tsBufDestroy(pTSBuf); -} - -void loadDataTest() { - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - int32_t num = 10000; - int64_t oldStart = 10000000; - int32_t numOfTags = 50; - int32_t step = 30; - int32_t numOfVnode = 200; - - // 10000 vnodes - for (int32_t j = 0; j < numOfVnode; ++j) { - // vnodeId:0 - int64_t start = 10000000; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); - printf("%d - %" PRIu64 "\n", i, list[0]); - - free(list); - start += step * num; - } - - EXPECT_EQ(pTSBuf->numOfGroups, j + 1); - } - - EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); - - EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); - EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); - - EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); - - EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); - - tsBufFlush(pTSBuf); - EXPECT_EQ(pTSBuf->tsData.len, 0); - EXPECT_EQ(pTSBuf->block.numOfElem, num); - - // create from exists file - STSBuf* pNewBuf = tsBufCreateFromFile(pTSBuf->path, false); - EXPECT_EQ(pNewBuf->tsOrder, pTSBuf->tsOrder); - EXPECT_EQ(pNewBuf->numOfGroups, numOfVnode); - EXPECT_EQ(pNewBuf->fileSize, pTSBuf->fileSize); - - EXPECT_EQ(pNewBuf->pData[0].info.offset, pTSBuf->pData[0].info.offset); - EXPECT_EQ(pNewBuf->pData[0].info.numOfBlocks, pTSBuf->pData[0].info.numOfBlocks); - EXPECT_EQ(pNewBuf->pData[0].info.compLen, pTSBuf->pData[0].info.compLen); - - EXPECT_STREQ(pNewBuf->path, pTSBuf->path); - - tsBufResetPos(pNewBuf); - - int64_t s = taosGetTimestampUs(); - printf("start:%" PRIu64 "\n", s); - - int32_t x = 0; - while (tsBufNextPos(pNewBuf)) { - STSElem elem = tsBufGetElem(pNewBuf); - if (++x == 100000000) { - break; - } - - // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); - } - - int64_t e = taosGetTimestampUs(); - printf("end:%" PRIu64 ", elapsed:%" PRIu64 ", total obj:%d\n", e, e - s, x); - tsBufDestroy(pTSBuf); - tsBufDestroy(pNewBuf); -} - -void randomIncTsTest() {} - -void TSTraverse() { - // 10000 vnodes - int32_t num = 200000; - int64_t oldStart = 10000000; - int32_t numOfTags = 3; - int32_t step = 30; - int32_t numOfVnode = 2; - - STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); - - for (int32_t j = 0; j < numOfVnode; ++j) { - // vnodeId:0 - int64_t start = 10000000; - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); - printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); - - free(list); - start += step * num; - - list = createTsList(num, start, step); - tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); - printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); - free(list); - - start += step * num; - } - - EXPECT_EQ(pTSBuf->numOfGroups, j + 1); - } - - tsBufResetPos(pTSBuf); - - //////////////////////////////////////////////////////////////////////////////////////// - // reverse traverse - int64_t s = taosGetTimestampUs(); - printf("start:%" PRIu64 "\n", s); - - pTSBuf->cur.order = TSDB_ORDER_DESC; - - // complete reverse traverse - int32_t x = 0; - while (tsBufNextPos(pTSBuf)) { - STSElem elem = tsBufGetElem(pTSBuf); - // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); - } - - // specify the data block with vnode and tags value - tsBufResetPos(pTSBuf); - pTSBuf->cur.order = TSDB_ORDER_DESC; - - int32_t startVnode = 1; - int32_t startTag = 2; - - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - t.i64 = startTag; - - tsBufGetElemStartPos(pTSBuf, startVnode, &t); - - int32_t totalOutput = 10; - while (1) { - STSElem elem = tsBufGetElem(pTSBuf); - printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); - - if (!tsBufNextPos(pTSBuf)) { - break; - } - - if (--totalOutput <= 0) { - totalOutput = 10; - - startTag -= 1; - t.i64 = startTag; - tsBufGetElemStartPos(pTSBuf, startVnode, &t); - - if (startTag == 0) { - startVnode -= 1; - startTag = 3; - } - - if (startVnode < 0) { - break; - } - } - } - - ///////////////////////////////////////////////////////////////////////////////// - // traverse - pTSBuf->cur.order = TSDB_ORDER_ASC; - tsBufResetPos(pTSBuf); - - // complete forwards traverse - while (tsBufNextPos(pTSBuf)) { - STSElem elem = tsBufGetElem(pTSBuf); - // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); - } - - // specify the data block with vnode and tags value - tsBufResetPos(pTSBuf); - pTSBuf->cur.order = TSDB_ORDER_ASC; - - startVnode = 1; - startTag = 2; - t.i64 = startTag; - - tsBufGetElemStartPos(pTSBuf, startVnode, &t); - - totalOutput = 10; - while (1) { - STSElem elem = tsBufGetElem(pTSBuf); - printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); - - if (!tsBufNextPos(pTSBuf)) { - break; - } - - if (--totalOutput <= 0) { - totalOutput = 10; - - startTag -= 1; - t.i64 = startTag; - tsBufGetElemStartPos(pTSBuf, startVnode, &t); - - if (startTag < 0) { - startVnode -= 1; - startTag = 3; - } - - if (startVnode < 0) { - break; - } - } - } - - tsBufDestroy(pTSBuf); -} - -void performanceTest() {} - -void emptyTagTest() {} - -void invalidFileTest() { - const char* cmd = "touch /tmp/test"; - - // create empty file - system(cmd); - - STSBuf* pNewBuf = tsBufCreateFromFile("/tmp/test", true); - EXPECT_TRUE(pNewBuf == NULL); - tsBufDestroy(pNewBuf); - - pNewBuf = tsBufCreateFromFile("/tmp/911", true); - EXPECT_TRUE(pNewBuf == NULL); - - tsBufDestroy(pNewBuf); -} - -void mergeDiffVnodeBufferTest() { - STSBuf* pTSBuf1 = tsBufCreate(true, TSDB_ORDER_ASC); - STSBuf* pTSBuf2 = tsBufCreate(true, TSDB_ORDER_ASC); - - int32_t step = 30; - int32_t num = 1000; - int32_t numOfTags = 10; - - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - // vnodeId:0 - int64_t start = 10000000; - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf1, 1, &t, (const char*)list, num * sizeof(int64_t)); - tsBufAppend(pTSBuf2, 9, &t, (const char*)list, num * sizeof(int64_t)); - - free(list); - - start += step * num; - } - - tsBufFlush(pTSBuf2); - - tsBufMerge(pTSBuf1, pTSBuf2); - EXPECT_EQ(pTSBuf1->numOfGroups, 2); - EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num); - - tsBufDisplay(pTSBuf1); - - tsBufDestroy(pTSBuf2); - tsBufDestroy(pTSBuf1); -} - -void mergeIdenticalVnodeBufferTest() { - STSBuf* pTSBuf1 = tsBufCreate(true, TSDB_ORDER_ASC); - STSBuf* pTSBuf2 = tsBufCreate(true, TSDB_ORDER_ASC); - - tVariant t = {0}; - t.nType = TSDB_DATA_TYPE_BIGINT; - - int32_t step = 30; - int32_t num = 1000; - int32_t numOfTags = 10; - - // vnodeId:0 - int64_t start = 10000000; - for (int32_t i = 0; i < numOfTags; ++i) { - int64_t* list = createTsList(num, start, step); - t.i64 = i; - - tsBufAppend(pTSBuf1, 12, &t, (const char*)list, num * sizeof(int64_t)); - free(list); - - start += step * num; - } - - for (int32_t i = numOfTags; i < numOfTags * 2; ++i) { - int64_t* list = createTsList(num, start, step); - - t.i64 = i; - tsBufAppend(pTSBuf2, 77, &t, (const char*)list, num * sizeof(int64_t)); - free(list); - - start += step * num; - } - - tsBufFlush(pTSBuf2); - - tsBufMerge(pTSBuf1, pTSBuf2); - EXPECT_EQ(pTSBuf1->numOfGroups, 2); - EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num); - - tsBufResetPos(pTSBuf1); - - int32_t count = 0; - while (tsBufNextPos(pTSBuf1)) { - STSElem elem = tsBufGetElem(pTSBuf1); - - if (count++ < numOfTags * num) { - EXPECT_EQ(elem.id, 12); - } else { - EXPECT_EQ(elem.id, 77); - } - - printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); - } - - tsBufDestroy(pTSBuf1); - tsBufDestroy(pTSBuf2); -} -} // namespace - - -//TODO add binary tag value test case -TEST(testCase, tsBufTest) { - simpleTest(); - largeTSTest(); - multiTagsTest(); - multiVnodeTagsTest(); - loadDataTest(); - invalidFileTest(); -// randomIncTsTest(); - TSTraverse(); - mergeDiffVnodeBufferTest(); - mergeIdenticalVnodeBufferTest(); -} diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 1da93c8761..62d1fc03fa 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -103,6 +103,8 @@ sql_error select * from stb1 where c7 < 'nuLl'; sql_error select * from stb1 where c8 < 'nuLl'; sql_error select * from stb1 where c9 > 'nuLl'; sql_error select * from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b; +sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; +sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); sql select * from stb1 where c2 > 3.0 or c2 < 60; if $rows != 28 then @@ -1487,10 +1489,37 @@ if $data10 != @21-05-05 18:19:21.000@ then return -1 endi -sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; -sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.c1 < 10 or a.c1 > 30) and (b.u1 < 5 or b.u1 > 5); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.c1 < 30 and b.u1 > 1 and a.c1 > 10 and b.u1 < 8 and b.u1<>5; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi -#!!!!!!!!!!!select a.* from (select * from tb1) a, (select * from tb2) b where a.ts = b.ts and a.f1 > 0 and b.f1 > 0; print "ts test" @@ -1639,7 +1668,84 @@ if $data10 != @21-05-05 18:19:03.000@ then return -1 endi +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.ts < '2021-05-05 18:19:03.000' or a.ts >= '2021-05-05 18:19:13.000') and (b.ts >= '2021-05-05 18:19:01.000' and b.ts <= '2021-05-05 18:19:14.000'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select a.ts,c.ts,b.c1,c.u1,c.u2 from (select * from stb1) a, (select * from stb1) b, (select * from stb2) c where a.ts=b.ts and b.ts=c.ts and a.ts <= '2021-05-05 18:19:12.000' and b.ts >= '2021-05-05 18:19:06.000' and c.ts >= '2021-05-05 18:19:08.000' and c.ts <= '2021-05-05 18:19:11.000' and a.ts != '2021-05-05 18:19:10.000'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:06.000' or ts >= '2021-05-05 18:19:13.000') and (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:14.000') and ts != '2021-05-05 18:19:04.000'; +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:14.000@ then + return -1 +endi + print "tbname test" +sql_error select * from stb1 where tbname like '%3' and tbname like '%4'; + +sql select * from stb1 where tbname like 'tb%'; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where tbname like '%2'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi print "tag test" sql select * from stb1 where t1 in (1,2) and t1 in (2,3); @@ -1665,16 +1771,44 @@ if $rows != 0 then endi print "join test" - - +sql_error select * from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts =tb2_1.ts; +sql select tb1.ts from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.ts < '2021-05-05 18:19:06.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi print "column&ts test" sql_error select count(*) from stb1 where ts > 0 or c1 > 0; +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:20.000' and (c1 > 23 or c1 < 14) and c7 in (true) and c8 like '%2'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:17.000@ then + return -1 +endi print "column&tbname test" sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; - +sql select * from stb1 where tbname like '%3' and c6 < 34 and c5 != 33 and c4 > 31; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:13.000@ then + return -1 +endi print "column&tag test" sql_error select * from stb1 where t1 > 0 or c1 > 0 @@ -1687,7 +1821,7 @@ sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 - +sql_error select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.t1=b.t1; sql select * from stb1 where c1 < 63 and t1 > 5 if $rows != 2 then @@ -1726,6 +1860,8 @@ endi print "column&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; + print "ts&tbname test" sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; @@ -1743,9 +1879,29 @@ endi if $data10 != @21-05-05 18:19:12.000@ then return -1 endi + print "ts&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts > 0; +sql select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts and (tb1.ts > '2021-05-05 18:19:05.000' or tb1.ts < '2021-05-05 18:19:03.000' or tb1.ts > 0); + print "tbname&tag test" +sql select * from stb1 where tbname like 'tb%' and (t1=1 or t2=2 or t3=3) and t1 > 2; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi print "tbname&join test" diff --git a/tests/script/test.sh b/tests/script/test.sh index a092a38a2d..d580924c63 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -113,6 +113,7 @@ echo "rpcDebugFlag 143" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG echo "cDebugFlag 143" >> $TAOS_CFG echo "udebugFlag 143" >> $TAOS_CFG +echo "debugFlag 143" >> $TAOS_CFG echo "wal 0" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG From d7a3a975c7eb61ec99c51a8ab7593e510dbc3682 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 30 Jun 2021 13:18:15 +0800 Subject: [PATCH 014/100] restore files --- src/query/tests/CMakeLists.txt | 12 +- src/query/tests/astTest.cpp | 635 +++++++++++++++++++++++++++ src/query/tests/histogramTest.cpp | 142 ++++++ src/query/tests/patternMatchTest.cpp | 86 ++++ src/query/tests/percentileTest.cpp | 257 +++++++++++ src/query/tests/resultBufferTest.cpp | 163 +++++++ src/query/tests/tsBufTest.cpp | 515 ++++++++++++++++++++++ 7 files changed, 1804 insertions(+), 6 deletions(-) create mode 100644 src/query/tests/astTest.cpp create mode 100644 src/query/tests/histogramTest.cpp create mode 100644 src/query/tests/patternMatchTest.cpp create mode 100644 src/query/tests/percentileTest.cpp create mode 100644 src/query/tests/resultBufferTest.cpp create mode 100644 src/query/tests/tsBufTest.cpp diff --git a/src/query/tests/CMakeLists.txt b/src/query/tests/CMakeLists.txt index 475ade5c2f..bb7df70f41 100644 --- a/src/query/tests/CMakeLists.txt +++ b/src/query/tests/CMakeLists.txt @@ -20,10 +20,10 @@ IF (HEADER_GTEST_INCLUDE_DIR AND LIB_GTEST_STATIC_DIR) TARGET_LINK_LIBRARIES(queryTest taos query gtest pthread) ENDIF() -#SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) -#SET_SOURCE_FILES_PROPERTIES(./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w) -#SET_SOURCE_FILES_PROPERTIES(./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w) -#SET_SOURCE_FILES_PROPERTIES(./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w) -#SET_SOURCE_FILES_PROPERTIES(./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w) -#SET_SOURCE_FILES_PROPERTIES(./unitTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./astTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./histogramTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./percentileTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./resultBufferTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./tsBufTest.cpp PROPERTIES COMPILE_FLAGS -w) +SET_SOURCE_FILES_PROPERTIES(./unitTest.cpp PROPERTIES COMPILE_FLAGS -w) SET_SOURCE_FILES_PROPERTIES(./rangeMergeTest.cpp PROPERTIES COMPILE_FLAGS -w) diff --git a/src/query/tests/astTest.cpp b/src/query/tests/astTest.cpp new file mode 100644 index 0000000000..1143d00e8d --- /dev/null +++ b/src/query/tests/astTest.cpp @@ -0,0 +1,635 @@ +#include +#include +#include +#include + +#include "texpr.h" +#include "taosmsg.h" +#include "tsdb.h" +#include "tskiplist.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wwrite-strings" +#pragma GCC diagnostic ignored "-Wunused-function" + +typedef struct ResultObj { + int32_t numOfResult; + char * resultName[64]; +} ResultObj; + +static void initSchema(SSchema *pSchema, int32_t numOfCols); + +static void initSchema_binary(SSchema *schema, int32_t numOfCols); + +static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags); +static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags); + +static void dropMeter(SSkipList *pSkipList); + +static void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); + +static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); + +static void IllegalExprTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); + +static void Left2RightTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); +static void Right2LeftTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList); + +void setValue(ResultObj *pResult, int32_t num, char **val) { + pResult->numOfResult = num; + for (int32_t i = 0; i < num; ++i) { + pResult->resultName[i] = val[i]; + } +} + +static void initSchema_binary(SSchema *schema, int32_t numOfCols) { + schema[0].type = TSDB_DATA_TYPE_BINARY; + schema[0].bytes = 8; + strcpy(schema[0].name, "a"); + + schema[1].type = TSDB_DATA_TYPE_DOUBLE; + schema[1].bytes = 8; + strcpy(schema[1].name, "b"); + + schema[2].type = TSDB_DATA_TYPE_INT; + schema[2].bytes = 20; + strcpy(schema[2].name, "c"); + + schema[3].type = TSDB_DATA_TYPE_BIGINT; + schema[3].bytes = 8; + strcpy(schema[3].name, "d"); + + schema[4].type = TSDB_DATA_TYPE_SMALLINT; + schema[4].bytes = 2; + strcpy(schema[4].name, "e"); + + schema[5].type = TSDB_DATA_TYPE_TINYINT; + schema[5].bytes = 1; + strcpy(schema[5].name, "f"); + + schema[6].type = TSDB_DATA_TYPE_FLOAT; + schema[6].bytes = 4; + strcpy(schema[6].name, "g"); + + schema[7].type = TSDB_DATA_TYPE_BOOL; + schema[7].bytes = 1; + strcpy(schema[7].name, "h"); +} + +static void initSchema(SSchema *schema, int32_t numOfCols) { + schema[0].type = TSDB_DATA_TYPE_INT; + schema[0].bytes = 8; + strcpy(schema[0].name, "a"); + + schema[1].type = TSDB_DATA_TYPE_DOUBLE; + schema[1].bytes = 8; + strcpy(schema[1].name, "b"); + + schema[2].type = TSDB_DATA_TYPE_BINARY; + schema[2].bytes = 20; + strcpy(schema[2].name, "c"); + + schema[3].type = TSDB_DATA_TYPE_BIGINT; + schema[3].bytes = 8; + strcpy(schema[3].name, "d"); + + schema[4].type = TSDB_DATA_TYPE_SMALLINT; + schema[4].bytes = 2; + strcpy(schema[4].name, "e"); + + schema[5].type = TSDB_DATA_TYPE_TINYINT; + schema[5].bytes = 1; + strcpy(schema[5].name, "f"); + + schema[6].type = TSDB_DATA_TYPE_FLOAT; + schema[6].bytes = 4; + strcpy(schema[6].name, "g"); + + schema[7].type = TSDB_DATA_TYPE_BOOL; + schema[7].bytes = 1; + strcpy(schema[7].name, "h"); +} + +// static void addOneNode(SSchema *pSchema, int32_t tagsLen, SSkipList *pSkipList, +// char *meterId, int32_t a, double b, char *c, int64_t d, int16_t e, int8_t f, float g, +// bool h, int32_t numOfTags) { +// STabObj *pMeter = calloc(1, sizeof(STabObj)); +// pMeter->numOfTags = numOfTags; +// pMeter->pTagData = calloc(1, tagsLen + TSDB_METER_ID_LEN); +// strcpy(pMeter->meterId, meterId); +// +// char *tags = pMeter->pTagData + TSDB_METER_ID_LEN; +// int32_t offset = 0; +// +// *(int32_t *) tags = a; +// +// offset += pSchema[0].bytes; +// *(double *) (tags + offset) = b; +// +// offset += pSchema[1].bytes; +// memcpy(tags + offset, c, 3); +// +// offset += pSchema[2].bytes; +// *(int64_t *) (tags + offset) = d; +// +// offset += pSchema[3].bytes; +// *(int16_t *) (tags + offset) = e; +// +// offset += pSchema[4].bytes; +// *(int8_t *) (tags + offset) = f; +// +// offset += pSchema[5].bytes; +// *(float *) (tags + offset) = g; +// +// offset += pSchema[6].bytes; +// *(int8_t *) (tags + offset) = h ? 1 : 0; +// +// SSkipListKey pKey = SSkipListCreateKey(pSchema[0].type, tags, pSchema[0].bytes); +// SSkipListPut(pSkipList, pMeter, &pKey, 1); +//} +// +// static void addOneNode_binary(SSchema *pSchema, int32_t tagsLen, SSkipList *pSkipList, +// char *meterId, int32_t a, double b, char *c, int64_t d, int16_t e, int8_t f, float g, +// bool h, int32_t numOfTags) { +// STabObj *pMeter = calloc(1, sizeof(STabObj)); +// pMeter->numOfTags = numOfTags; +// pMeter->pTagData = calloc(1, tagsLen + TSDB_METER_ID_LEN); +// strcpy(pMeter->meterId, meterId); +// +// char *tags = pMeter->pTagData + TSDB_METER_ID_LEN; +// int32_t offset = 0; +// memcpy(tags, c, pSchema[0].bytes); +// +// offset += pSchema[0].bytes; +// *(double *) (tags + offset) = b; +// +// offset += pSchema[1].bytes; +// *(int32_t *) (tags + offset) = a; +// +// offset += pSchema[2].bytes; +// *(int64_t *) (tags + offset) = d; +// +// offset += pSchema[3].bytes; +// *(int16_t *) (tags + offset) = e; +// +// offset += pSchema[4].bytes; +// *(int8_t *) (tags + offset) = f; +// +// offset += pSchema[5].bytes; +// *(float *) (tags + offset) = g; +// +// offset += pSchema[6].bytes; +// *(int8_t *) (tags + offset) = h ? 1 : 0; +// +// SSkipListKey pKey = SSkipListCreateKey(pSchema[0].type, tags, pSchema[0].bytes); +// SSkipListPut(pSkipList, pMeter, &pKey, 1); +// SSkipListDestroyKey(&pKey); +//} + +// static void dropMeter(SSkipList *pSkipList) { +// SSkipListNode **pRes = NULL; +// int32_t num = SSkipListIterateList(pSkipList, &pRes, NULL, NULL); +// for (int32_t i = 0; i < num; ++i) { +// SSkipListNode *pNode = pRes[i]; +// STabObj *pMeter = (STabObj *) pNode->pData; +// free(pMeter->pTagData); +// free(pMeter); +// pNode->pData = NULL; +// } +// free(pRes); +//} + +// static SSkipList *createSkipList(SSchema *pSchema, int32_t numOfTags) { +// int32_t tagsLen = 0; +// for (int32_t i = 0; i < numOfTags; ++i) { +// tagsLen += pSchema[i].bytes; +// } +// +// SSkipList *pSkipList = SSkipListCreate(10, pSchema[0].type, 4); +// +// addOneNode(pSchema, tagsLen, pSkipList, "tm0\0", 0, 10.5, "abc", 1000, -10000, -20, 1.0, true, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm1\0", 1, 20.5, "def", 1100, -10500, -30, 2.0, false, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm2\0", 2, 30.5, "ghi", 1200, -11000, -40, 3.0, true, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm3\0", 3, 40.5, "jkl", 1300, -11500, -50, 4.0, false, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm4\0", 4, 50.5, "mno", 1400, -12000, -60, 5.0, true, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm5\0", 5, 60.5, "pqr", 1500, -12500, -70, 6.0, false, 8); +// addOneNode(pSchema, tagsLen, pSkipList, "tm6\0", 6, 70.5, "stu", 1600, -13000, -80, 7.0, true, 8); +// +// return pSkipList; +//} +// +// static SSkipList *createSkipList_binary(SSchema *pSchema, int32_t numOfTags) { +// int32_t tagsLen = 0; +// for (int32_t i = 0; i < numOfTags; ++i) { +// tagsLen += pSchema[i].bytes; +// } +// +// SSkipList *pSkipList = SSkipListCreate(10, pSchema[0].type, 4); +// +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm0\0", 0, 10.5, "abc", 1000, -10000, -20, 1.0, true, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm1\0", 1, 20.5, "def", 1100, -10500, -30, 2.0, false, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm2\0", 2, 30.5, "ghi", 1200, -11000, -40, 3.0, true, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm3\0", 3, 40.5, "jkl", 1300, -11500, -50, 4.0, false, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm4\0", 4, 50.5, "mno", 1400, -12000, -60, 5.0, true, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm5\0", 5, 60.5, "pqr", 1500, -12500, -70, 6.0, false, 8); +// addOneNode_binary(pSchema, tagsLen, pSkipList, "tm6\0", 6, 70.5, "stu", 1600, -13000, -80, 7.0, true, 8); +// +// return pSkipList; +//} + +//static void testQueryStr(SSchema *schema, int32_t numOfCols, char *sql, SSkipList *pSkipList, ResultObj *pResult) { +// tExprNode *pExpr = NULL; +// tSQLBinaryExprFromString(&pExpr, schema, numOfCols, sql, strlen(sql)); +// +// char str[512] = {0}; +// int32_t len = 0; +// if (pExpr == NULL) { +// printf("-----error in parse syntax:%s\n\n", sql); +// assert(pResult == NULL); +// return; +// } +// +// tSQLBinaryExprToString(pExpr, str, &len); +// printf("expr is: %s\n", str); +// +// SArray *result = NULL; +// // tExprTreeTraverse(pExpr, pSkipList, result, SSkipListNodeFilterCallback, &result); +// // printf("the result is:%lld\n", result.num); +// // +// // bool findResult = false; +// // for (int32_t i = 0; i < result.num; ++i) { +// // STabObj *pm = (STabObj *)result.pRes[i]; +// // printf("meterid:%s,\t", pm->meterId); +// // +// // for (int32_t j = 0; j < pResult->numOfResult; ++j) { +// // if (strcmp(pm->meterId, pResult->resultName[j]) == 0) { +// // findResult = true; +// // break; +// // } +// // } +// // assert(findResult == true); +// // findResult = false; +// // } +// +// printf("\n\n"); +// tExprTreeDestroy(&pExpr, NULL); +//} + +#if 0 +static void Left2RightTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { + char str[256] = {0}; + + char *t0[1] = {"tm0"}; + char *t1[1] = {"tm1"}; + char *sql = NULL; + + ResultObj res = {1, {"tm1"}}; + testQueryStr(schema, numOfCols, "a=1", pSkipList, &res); + + char *tt[1] = {"tm6"}; + setValue(&res, 1, tt); + testQueryStr(schema, numOfCols, "a>=6", pSkipList, &res); + + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, "b<=10.6", pSkipList, &res); + + strcpy(str, "c<>'pqr'"); + char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; + setValue(&res, 6, t2); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + strcpy(str, "c='abc'"); + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + char *t3[6] = {"tm1", "tm2", "tm3", "tm4", "tm5", "tm6"}; + setValue(&res, 6, t3); + testQueryStr(schema, numOfCols, "d>1050", pSkipList, &res); + + char *t4[3] = {"tm4", "tm5", "tm6"}; + setValue(&res, 3, t4); + testQueryStr(schema, numOfCols, "g>4.5980765", pSkipList, &res); + + char *t5[4] = {"tm0", "tm2", "tm4", "tm6"}; + setValue(&res, 4, t5); + testQueryStr(schema, numOfCols, "h=true", pSkipList, &res); + + char *t6[3] = {"tm1", "tm3", "tm5"}; + setValue(&res, 3, t6); + testQueryStr(schema, numOfCols, "h=0", pSkipList, &res); + + sql = "(((b<40)))\0"; + char *t7[3] = {"tm0", "tm1", "tm2"}; + setValue(&res, 3, t7); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); + + sql = "((a=1) or (a=10)) or ((b=12))"; + setValue(&res, 1, t1); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); + + sql = "((((((a>0 and a<2))) or a=6) or a=3) or (b=50.5)) and h=0"; + char *t8[2] = {"tm1", "tm3"}; + setValue(&res, 2, t8); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); + + char *tf[1] = {"tm6"}; + setValue(&res, 1, tf); + testQueryStr(schema, numOfCols, "e = -13000", pSkipList, &res); + + char *ft[5] = {"tm0", "tm1", "tm2", "tm3", "tm4"}; + setValue(&res, 5, ft); + testQueryStr(schema, numOfCols, "f > -65", pSkipList, &res); +} + +void Right2LeftTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { + ResultObj res = {1, {"tm1"}}; + testQueryStr(schema, numOfCols, "((1=a))", pSkipList, &res); + + char *t9[2] = {"tm0", "tm1"}; + setValue(&res, 2, t9); + testQueryStr(schema, numOfCols, "1>=a", pSkipList, &res); + + char *t0[1] = {"tm0"}; + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, "10.6>=b", pSkipList, &res); + + char *t10[3] = {"tm1", "tm3", "tm5"}; + setValue(&res, 3, t10); + testQueryStr(schema, numOfCols, "0=h", pSkipList, &res); +} + +static void IllegalExprTest(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { + testQueryStr(schema, numOfCols, "h=", pSkipList, NULL); + testQueryStr(schema, numOfCols, "h<", pSkipList, NULL); + testQueryStr(schema, numOfCols, "a=1 and ", pSkipList, NULL); + testQueryStr(schema, numOfCols, "and or", pSkipList, NULL); + testQueryStr(schema, numOfCols, "and a = 1 or", pSkipList, NULL); + testQueryStr(schema, numOfCols, "(())", pSkipList, NULL); + testQueryStr(schema, numOfCols, "(", pSkipList, NULL); + testQueryStr(schema, numOfCols, "(a", pSkipList, NULL); + testQueryStr(schema, numOfCols, "(a)", pSkipList, NULL); + testQueryStr(schema, numOfCols, "())", pSkipList, NULL); + testQueryStr(schema, numOfCols, "a===1", pSkipList, NULL); + testQueryStr(schema, numOfCols, "a=1 and ", pSkipList, NULL); +} + +static void Left2RightTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { + char str[256] = {0}; + char *sql = NULL; + + char *t0[1] = {"tm0"}; + char *t1[1] = {"tm1"}; + + ResultObj res = {1, {"tm0"}}; + strcpy(str, "a='abc'"); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + char *tt[1] = {"tm6"}; + setValue(&res, 1, tt); + testQueryStr(schema, numOfCols, "c>=6", pSkipList, &res); + + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, "b<=10.6", pSkipList, &res); + + strcpy(str, "a<>'pqr'"); + char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; + setValue(&res, 6, t2); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + strcpy(str, "a='abc'"); + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + char *t3[6] = {"tm1", "tm2", "tm3", "tm4", "tm5", "tm6"}; + setValue(&res, 6, t3); + testQueryStr(schema, numOfCols, "d>1050", pSkipList, &res); + + char *t4[3] = {"tm4", "tm5", "tm6"}; + setValue(&res, 3, t4); + testQueryStr(schema, numOfCols, "g>4.5980765", pSkipList, &res); + + char *t5[4] = {"tm0", "tm2", "tm4", "tm6"}; + setValue(&res, 4, t5); + testQueryStr(schema, numOfCols, "h=true", pSkipList, &res); + + char *t6[3] = {"tm1", "tm3", "tm5"}; + setValue(&res, 3, t6); + testQueryStr(schema, numOfCols, "h=0", pSkipList, &res); + + sql = "(((b<40)))\0"; + char *t7[3] = {"tm0", "tm1", "tm2"}; + setValue(&res, 3, t7); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); + + sql = "((c=1) or (c=10)) or ((b=12))\0"; + setValue(&res, 1, t1); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); + + sql = "((((((c>0 and c<2))) or c=6) or c=3) or (b=50.5)) and h=false\0"; + char *t8[2] = {"tm1", "tm3"}; + setValue(&res, 2, t8); + testQueryStr(schema, numOfCols, sql, pSkipList, &res); +} + +static void Right2LeftTest_binary(SSchema *schema, int32_t numOfCols, SSkipList *pSkipList) { + char str[256] = {0}; + char *sql = NULL; + + char *t0[1] = {"tm0"}; + char *t1[1] = {"tm1"}; + + ResultObj res = {1, {"tm0"}}; + strcpy(str, "'abc'=a"); + testQueryStr(schema, numOfCols, str, pSkipList, &res); + + char *tt[1] = {"tm6"}; + setValue(&res, 1, tt); + testQueryStr(schema, numOfCols, "6<=c", pSkipList, &res); + + setValue(&res, 1, t0); + testQueryStr(schema, numOfCols, "10.6>=b", pSkipList, &res); + + strcpy(str, "'pqr'<>a"); + char *t2[6] = {"tm0", "tm1", "tm2", "tm3", "tm4", "tm6"}; + setValue(&res, 6, t2); + testQueryStr(schema, numOfCols, str, pSkipList, &res); +} + +namespace { +// two level expression tree +tExprNode *createExpr1() { + auto *pLeft = (tExprNode*) calloc(1, sizeof(tExprNode)); + pLeft->nodeType = TSQL_NODE_COL; + pLeft->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); + + strcpy(pLeft->pSchema->name, "col_a"); + pLeft->pSchema->type = TSDB_DATA_TYPE_INT; + pLeft->pSchema->bytes = sizeof(int32_t); + pLeft->pSchema->colId = 1; + + auto *pRight = (tExprNode*) calloc(1, sizeof(tExprNode)); + pRight->nodeType = TSQL_NODE_VALUE; + pRight->pVal = (tVariant*) calloc(1, sizeof(tVariant)); + + pRight->pVal->nType = TSDB_DATA_TYPE_INT; + pRight->pVal->i64 = 12; + + auto *pRoot = (tExprNode*) calloc(1, sizeof(tExprNode)); + pRoot->nodeType = TSQL_NODE_EXPR; + + pRoot->_node.optr = TSDB_RELATION_EQUAL; + pRoot->_node.pLeft = pLeft; + pRoot->_node.pRight = pRight; + pRoot->_node.hasPK = true; + + return pRoot; +} + +// thress level expression tree +tExprNode* createExpr2() { + auto *pLeft2 = (tExprNode*) calloc(1, sizeof(tExprNode)); + pLeft2->nodeType = TSQL_NODE_COL; + pLeft2->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); + + strcpy(pLeft2->pSchema->name, "col_a"); + pLeft2->pSchema->type = TSDB_DATA_TYPE_BINARY; + pLeft2->pSchema->bytes = 20; + pLeft2->pSchema->colId = 1; + + auto *pRight2 = (tExprNode*) calloc(1, sizeof(tExprNode)); + pRight2->nodeType = TSQL_NODE_VALUE; + pRight2->pVal = (tVariant*) calloc(1, sizeof(tVariant)); + + pRight2->pVal->nType = TSDB_DATA_TYPE_BINARY; + const char* v = "hello world!"; + pRight2->pVal->pz = strdup(v); + pRight2->pVal->nLen = strlen(v); + + auto *p1 = (tExprNode*) calloc(1, sizeof(tExprNode)); + p1->nodeType = TSQL_NODE_EXPR; + + p1->_node.optr = TSDB_RELATION_LIKE; + p1->_node.pLeft = pLeft2; + p1->_node.pRight = pRight2; + p1->_node.hasPK = false; + + auto *pLeft1 = (tExprNode*) calloc(1, sizeof(tExprNode)); + pLeft1->nodeType = TSQL_NODE_COL; + pLeft1->pSchema = (SSchema*) calloc(1, sizeof(SSchema)); + + strcpy(pLeft1->pSchema->name, "col_b"); + pLeft1->pSchema->type = TSDB_DATA_TYPE_DOUBLE; + pLeft1->pSchema->bytes = 8; + pLeft1->pSchema->colId = 99; + + auto *pRight1 = (tExprNode*) calloc(1, sizeof(tExprNode)); + pRight1->nodeType = TSQL_NODE_VALUE; + pRight1->pVal = (tVariant*) calloc(1, sizeof(tVariant)); + + pRight1->pVal->nType = TSDB_DATA_TYPE_DOUBLE; + pRight1->pVal->dKey = 91.99; + + auto *p2 = (tExprNode*) calloc(1, sizeof(tExprNode)); + p2->nodeType = TSQL_NODE_EXPR; + + p2->_node.optr = TSDB_RELATION_GREATER_EQUAL; + p2->_node.pLeft = pLeft1; + p2->_node.pRight = pRight1; + p2->_node.hasPK = false; + + auto *pRoot = (tExprNode*) calloc(1, sizeof(tExprNode)); + pRoot->nodeType = TSQL_NODE_EXPR; + + pRoot->_node.optr = TSDB_RELATION_OR; + pRoot->_node.pLeft = p1; + pRoot->_node.pRight = p2; + pRoot->_node.hasPK = true; + return pRoot; +} + +void exprSerializeTest1() { + tExprNode* p1 = createExpr1(); + SBufferWriter bw = tbufInitWriter(NULL, false); + exprTreeToBinary(&bw, p1); + + size_t size = tbufTell(&bw); + ASSERT_TRUE(size > 0); + char* b = tbufGetData(&bw, false); + + tExprNode* p2 = exprTreeFromBinary(b, size); + ASSERT_EQ(p1->nodeType, p2->nodeType); + + ASSERT_EQ(p2->_node.optr, p1->_node.optr); + ASSERT_EQ(p2->_node.pLeft->nodeType, p1->_node.pLeft->nodeType); + ASSERT_EQ(p2->_node.pRight->nodeType, p1->_node.pRight->nodeType); + + SSchema* s1 = p1->_node.pLeft->pSchema; + SSchema* s2 = p2->_node.pLeft->pSchema; + + ASSERT_EQ(s2->colId, s1->colId); + ASSERT_EQ(s2->type, s1->type); + ASSERT_EQ(s2->bytes, s1->bytes); + ASSERT_STRCASEEQ(s2->name, s1->name); + + tVariant* v1 = p1->_node.pRight->pVal; + tVariant* v2 = p2->_node.pRight->pVal; + + ASSERT_EQ(v1->nType, v2->nType); + ASSERT_EQ(v1->i64, v2->i64); + ASSERT_EQ(p1->_node.hasPK, p2->_node.hasPK); + + tExprTreeDestroy(&p1, nullptr); + tExprTreeDestroy(&p2, nullptr); + + // tbufClose(&bw); +} + +void exprSerializeTest2() { + tExprNode* p1 = createExpr2(); + SBufferWriter bw = tbufInitWriter(NULL, false); + exprTreeToBinary(&bw, p1); + + size_t size = tbufTell(&bw); + ASSERT_TRUE(size > 0); + char* b = tbufGetData(&bw, false); + + tExprNode* p2 = exprTreeFromBinary(b, size); + ASSERT_EQ(p1->nodeType, p2->nodeType); + + ASSERT_EQ(p2->_node.optr, p1->_node.optr); + ASSERT_EQ(p2->_node.pLeft->nodeType, p1->_node.pLeft->nodeType); + ASSERT_EQ(p2->_node.pRight->nodeType, p1->_node.pRight->nodeType); + + tExprNode* c1Left = p1->_node.pLeft; + tExprNode* c2Left = p2->_node.pLeft; + + ASSERT_EQ(c1Left->nodeType, c2Left->nodeType); + + ASSERT_EQ(c2Left->nodeType, TSQL_NODE_EXPR); + ASSERT_EQ(c2Left->_node.optr, TSDB_RELATION_LIKE); + + ASSERT_STRCASEEQ(c2Left->_node.pLeft->pSchema->name, "col_a"); + ASSERT_EQ(c2Left->_node.pRight->nodeType, TSQL_NODE_VALUE); + + ASSERT_STRCASEEQ(c2Left->_node.pRight->pVal->pz, "hello world!"); + + tExprNode* c1Right = p1->_node.pRight; + tExprNode* c2Right = p2->_node.pRight; + + ASSERT_EQ(c1Right->nodeType, c2Right->nodeType); + ASSERT_EQ(c2Right->nodeType, TSQL_NODE_EXPR); + ASSERT_EQ(c2Right->_node.optr, TSDB_RELATION_GREATER_EQUAL); + ASSERT_EQ(c2Right->_node.pRight->pVal->dKey, 91.99); + + ASSERT_EQ(p2->_node.hasPK, true); + + tExprTreeDestroy(&p1, nullptr); + tExprTreeDestroy(&p2, nullptr); + + // tbufClose(&bw); +} +} // namespace +TEST(testCase, astTest) { +// exprSerializeTest2(); +} +#endif \ No newline at end of file diff --git a/src/query/tests/histogramTest.cpp b/src/query/tests/histogramTest.cpp new file mode 100644 index 0000000000..0266ecffc1 --- /dev/null +++ b/src/query/tests/histogramTest.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +#include + +#include "taos.h" +#include "qHistogram.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace { +void doHistogramAddTest() { + SHistogramInfo* pHisto = NULL; + + /** + * use arrayList, elapsed time is: + * before: + * 10,000,000 45sec, bin:1000 (-O0) / 17sec. bin:1000, (-O3) + * + * after: + * + */ + struct timeval systemTime; + gettimeofday(&systemTime, NULL); + int64_t st = + (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; + for (int32_t i = 0; i < 10000; ++i) { + tHistogramAdd(&pHisto, i); + // tHistogramPrint(pHisto); + } + // + gettimeofday(&systemTime, NULL); + int64_t et = + (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; + printf("total elapsed time: %ld\n", et - st); + + printf("elements: %d, slot:%d \n", pHisto->numOfElems, pHisto->numOfEntries); + tHistogramPrint(pHisto); + + printf("%ld\n", tHistogramSum(pHisto, 1.5)); + printf("%ld\n", tHistogramSum(pHisto, 2)); + printf("%ld\n", tHistogramSum(pHisto, 3)); + printf("%ld\n", tHistogramSum(pHisto, 4)); + printf("%ld\n", tHistogramSum(pHisto, 5)); + printf("%ld\n", tHistogramSum(pHisto, 6)); + + for (int32_t i = 399; i < 400; ++i) { + printf("val:%d, %ld\n", i, tHistogramSum(pHisto, i)); + } + + double ratio[] = {0 / 100, 20.0 / 100, 88.0 / 100, 100 / 100}; + double* res = tHistogramUniform(pHisto, ratio, 4); + for (int32_t i = 0; i < 4; ++i) { + printf("%f\n", res[i]); + } + + SHistogramInfo* pHisto1 = NULL; + for (int32_t i = (90000 - 1); i >= 80000; --i) { + tHistogramAdd(&pHisto1, i); + } + tHistogramPrint(pHisto1); + + SHistogramInfo* pRes = tHistogramMerge(pHisto1, pHisto, MAX_HISTOGRAM_BIN); + assert(pRes->numOfElems == pHisto->numOfElems + pHisto1->numOfElems); + tHistogramPrint(pRes); + + tHistogramDestroy(&pHisto); + tHistogramDestroy(&pHisto1); + tHistogramDestroy(&pRes); + free(res); +} +void doHistogramRepeatTest() { + SHistogramInfo* pHisto = NULL; + struct timeval systemTime; + + gettimeofday(&systemTime, NULL); + int64_t st = + (int64_t)systemTime.tv_sec * 1000L + (uint64_t)systemTime.tv_usec / 1000; + + for (int32_t i = 0; i < 1000; ++i) { + tHistogramAdd(&pHisto, -24 + i); + // tHistogramPrint(pHisto); + } + + tHistogramDestroy(&pHisto); + +} +} + +/* test validate the names for table/database */ +TEST(testCase, histogram_binary_search) { + SHistogramInfo* pHisto = tHistogramCreate(MAX_HISTOGRAM_BIN); + + pHisto->numOfEntries = 10; + for (int32_t i = 0; i < 10; ++i) { + pHisto->elems[i].num = 1; + pHisto->elems[i].val = i; + } + + int32_t idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 1); + assert(idx == 1); + + idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 9); + assert(idx == 9); + + idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 20); + assert(idx == 10); + + idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, -1); + assert(idx == 0); + + idx = histoBinarySearch(pHisto->elems, pHisto->numOfEntries, 3.9); + assert(idx == 4); + + free(pHisto); +} + +TEST(testCase, histogram_add) { + doHistogramAddTest(); + doHistogramRepeatTest(); +} + +TEST(testCase, heapsort) { + // int32_t num = 20; + // + // SHeapEntry* pEntry = tHeapCreate(num); + // + // for(int32_t i=0; i +#include +#include +#include + +#include "qAggMain.h" +#include "tcompare.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" + +TEST(testCase, patternMatchTest) { + SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; + + const char* str = "abcdef"; + int32_t ret = patternMatch("a%b%", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "tm01"; + ret = patternMatch("tm__", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "tkm1"; + ret = patternMatch("t%m1", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "tkm1"; + ret = patternMatch("%m1", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = ""; + ret = patternMatch("%_", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); + + str = "1"; + ret = patternMatch("%__", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); + + str = ""; + ret = patternMatch("%", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = " "; + ret = patternMatch("_", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "!"; + ret = patternMatch("%_", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "abcdefg"; + ret = patternMatch("abc%fg", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("abc%fg", str, 7, &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("abc%f_", str, 6, &info); + EXPECT_EQ(ret, TSDB_PATTERN_NOWILDCARDMATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("abc%f_", str, 1, &info); // pattern string is longe than the size + EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("ab", str, 2, &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("a%", str, 2, &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "abcdefgabcdeju"; + ret = patternMatch("a__", str, 2, &info); + EXPECT_EQ(ret, TSDB_PATTERN_NOMATCH); + + str = "carzero"; + ret = patternMatch("%o", str, strlen(str), &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); + + str = "19"; + ret = patternMatch("%9", str, 2, &info); + EXPECT_EQ(ret, TSDB_PATTERN_MATCH); +} diff --git a/src/query/tests/percentileTest.cpp b/src/query/tests/percentileTest.cpp new file mode 100644 index 0000000000..1b6951201a --- /dev/null +++ b/src/query/tests/percentileTest.cpp @@ -0,0 +1,257 @@ +#include +#include + +#include "qResultbuf.h" +#include "taos.h" +#include "taosdef.h" + +#include "qPercentile.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace { +tMemBucket *createBigIntDataBucket(int32_t start, int32_t end) { + tMemBucket *pBucket = tMemBucketCreate(sizeof(int64_t), TSDB_DATA_TYPE_BIGINT, start, end); + for (int32_t i = start; i <= end; ++i) { + int64_t val = i; + tMemBucketPut(pBucket, &val, 1); + } + + return pBucket; +} + +tMemBucket *createIntDataBucket(int32_t start, int32_t end) { + tMemBucket *pBucket = tMemBucketCreate(sizeof(int32_t), TSDB_DATA_TYPE_INT, start, end); + + for (int32_t i = start; i <= end; ++i) { + int32_t val = i; + tMemBucketPut(pBucket, &val, 1); + } + + return pBucket; +} + +tMemBucket *createDoubleDataBucket(int32_t start, int32_t end) { + tMemBucket *pBucket = tMemBucketCreate(sizeof(double), TSDB_DATA_TYPE_DOUBLE, start, end); + for (int32_t i = start; i <= end; ++i) { + double val = i; + int32_t ret = tMemBucketPut(pBucket, &val, 1); + if (ret != 0) { + printf("value out of range:%f", val); + } + } + + return pBucket; +} + +tMemBucket *createUnsignedDataBucket(int32_t start, int32_t end, int32_t type) { + tMemBucket *pBucket = tMemBucketCreate(tDataTypes[type].bytes, type, start, end); + for (int32_t i = start; i <= end; ++i) { + uint64_t k = i; + int32_t ret = tMemBucketPut(pBucket, &k, 1); + if (ret != 0) { + printf("value out of range:%" PRId64, k); + } + } + + return pBucket; +} + +void intDataTest() { + printf("running %s\n", __FUNCTION__); + + tMemBucket *pBucket = NULL; + double result = 0.; + + pBucket = createIntDataBucket(0, 0); + result = getPercentile(pBucket, 0); + ASSERT_DOUBLE_EQ(result, 0); + tMemBucketDestroy(pBucket); + + pBucket = createIntDataBucket(0, 1); + result = getPercentile(pBucket, 100); + ASSERT_DOUBLE_EQ(result, 1); + + result = getPercentile(pBucket, 0); + ASSERT_DOUBLE_EQ(result, 0); + tMemBucketDestroy(pBucket); + + pBucket = createIntDataBucket(-1, 1); + + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 0); + + result = getPercentile(pBucket, 0); + ASSERT_DOUBLE_EQ(result, -1); + + result = getPercentile(pBucket, 75); + ASSERT_DOUBLE_EQ(result, 0.5); + + result = getPercentile(pBucket, 100); + ASSERT_DOUBLE_EQ(result, 1); + tMemBucketDestroy(pBucket); + + pBucket = createIntDataBucket(0, 99999); + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 49999.5); + + tMemBucketDestroy(pBucket); +} + +void bigintDataTest() { + printf("running %s\n", __FUNCTION__); + + tMemBucket *pBucket = NULL; + double result = 0.0; + + pBucket = createBigIntDataBucket(-1000, 1000); + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 0.); + tMemBucketDestroy(pBucket); + + pBucket = createBigIntDataBucket(-10000, 10000); + result = getPercentile(pBucket, 100); + ASSERT_DOUBLE_EQ(result, 10000.0); + tMemBucketDestroy(pBucket); + + pBucket = createBigIntDataBucket(-10000, 10000); + result = getPercentile(pBucket, 75); + ASSERT_DOUBLE_EQ(result, 5000.0); + + tMemBucketDestroy(pBucket); +} + +void doubleDataTest() { + printf("running %s\n", __FUNCTION__); + + tMemBucket *pBucket = NULL; + double result = 0; + + pBucket = createDoubleDataBucket(-10, 10); + result = getPercentile(pBucket, 0); + ASSERT_DOUBLE_EQ(result, -10.0); + + printf("result is: %lf\n", result); + tMemBucketDestroy(pBucket); + + pBucket = createDoubleDataBucket(-100000, 100000); + result = getPercentile(pBucket, 25); + ASSERT_DOUBLE_EQ(result, -50000); + + printf("result is: %lf\n", result); + + tMemBucketDestroy(pBucket); + + pBucket = createDoubleDataBucket(-100000, 100000); + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 0); + + tMemBucketDestroy(pBucket); + + pBucket = createDoubleDataBucket(-100000, 100000); + result = getPercentile(pBucket, 75); + ASSERT_DOUBLE_EQ(result, 50000); + tMemBucketDestroy(pBucket); + + pBucket = createDoubleDataBucket(-100000, 100000); + + result = getPercentile(pBucket, 100); + ASSERT_DOUBLE_EQ(result, 100000.0); + + printf("result is: %lf\n", result); + tMemBucketDestroy(pBucket); +} + +/* + * large data test, we employ 0.1billion double data to calculated the percentile + * which is 800MB data + */ +void largeDataTest() { + printf("running : %s\n", __FUNCTION__); + + tMemBucket *pBucket = NULL; + double result = 0; + + struct timeval tv; + gettimeofday(&tv, NULL); + + int64_t start = tv.tv_sec; + printf("start time: %" PRId64 "\n", tv.tv_sec); + pBucket = createDoubleDataBucket(0, 100000000); + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 50000000); + + gettimeofday(&tv, NULL); + + printf("total elapsed time: %" PRId64 " sec.", -start + tv.tv_sec); + printf("the result of %d is: %lf\n", 50, result); + tMemBucketDestroy(pBucket); +} + +void qsortTest() { + printf("running : %s\n", __FUNCTION__); + + SSchema field[1] = { + {TSDB_DATA_TYPE_INT, "k", sizeof(int32_t)}, + }; + + const int32_t num = 2000; + + int32_t *d = (int32_t *)malloc(sizeof(int32_t) * num); + for (int32_t i = 0; i < num; ++i) { + d[i] = i % 4; + } + + const int32_t numOfOrderCols = 1; + int32_t orderColIdx = 0; + SColumnModel * pModel = createColumnModel(field, 1, 1000); + tOrderDescriptor *pDesc = tOrderDesCreate(&orderColIdx, numOfOrderCols, pModel, 1); + + tColDataQSort(pDesc, num, 0, num - 1, (char *)d, 1); + + for (int32_t i = 0; i < num; ++i) { + printf("%d\t", d[i]); + } + printf("\n"); + + destroyColumnModel(pModel); +} + +void unsignedDataTest() { + printf("running %s\n", __FUNCTION__); + + tMemBucket *pBucket = NULL; + double result = 0.0; + + pBucket = createUnsignedDataBucket(0, 1000, TSDB_DATA_TYPE_UINT); + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 500.0); + tMemBucketDestroy(pBucket); + + pBucket = createUnsignedDataBucket(0, 10000, TSDB_DATA_TYPE_UBIGINT); + result = getPercentile(pBucket, 100); + ASSERT_DOUBLE_EQ(result, 10000.0); + + result = getPercentile(pBucket, 0); + ASSERT_DOUBLE_EQ(result, 0.0); + + result = getPercentile(pBucket, 50); + ASSERT_DOUBLE_EQ(result, 5000); + + result = getPercentile(pBucket, 75); + ASSERT_DOUBLE_EQ(result, 7500); + tMemBucketDestroy(pBucket); + +} + +} // namespace + +TEST(testCase, percentileTest) { +// qsortTest(); + intDataTest(); + bigintDataTest(); + doubleDataTest(); + unsignedDataTest(); + largeDataTest(); +} diff --git a/src/query/tests/resultBufferTest.cpp b/src/query/tests/resultBufferTest.cpp new file mode 100644 index 0000000000..54ac0bf4e5 --- /dev/null +++ b/src/query/tests/resultBufferTest.cpp @@ -0,0 +1,163 @@ +#include +#include +#include + +#include "qResultbuf.h" +#include "taos.h" +#include "tsdb.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" + +namespace { +// simple test +void simpleTest() { + SDiskbasedResultBuf* pResultBuf = NULL; + int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4096, 1); + + int32_t pageId = 0; + int32_t groupId = 0; + + tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); + ASSERT_TRUE(pBufPage != NULL); + + ASSERT_EQ(getResBufSize(pResultBuf), 1024); + + SIDList list = getDataBufPagesIdList(pResultBuf, groupId); + ASSERT_EQ(taosArrayGetSize(list), 1); + ASSERT_EQ(getNumOfResultBufGroupId(pResultBuf), 1); + + releaseResBufPage(pResultBuf, pBufPage); + + tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); + + tFilePage* t = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t == pBufPage1); + + tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t1 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t1 == pBufPage2); + + tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t2 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t2 == pBufPage3); + + tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t3 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t3 == pBufPage4); + + tFilePage* pBufPage5 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t4 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t4 == pBufPage5); + + destroyResultBuf(pResultBuf); +} + +void writeDownTest() { + SDiskbasedResultBuf* pResultBuf = NULL; + int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, 1); + + int32_t pageId = 0; + int32_t writePageId = 0; + int32_t groupId = 0; + int32_t nx = 12345; + + tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); + ASSERT_TRUE(pBufPage != NULL); + + *(int32_t*)(pBufPage->data) = nx; + writePageId = pageId; + releaseResBufPage(pResultBuf, pBufPage); + + tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t1 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t1 == pBufPage1); + ASSERT_TRUE(pageId == 1); + + tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t2 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t2 == pBufPage2); + ASSERT_TRUE(pageId == 2); + + tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t3 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t3 == pBufPage3); + ASSERT_TRUE(pageId == 3); + + tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t4 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t4 == pBufPage4); + ASSERT_TRUE(pageId == 4); + releaseResBufPage(pResultBuf, t4); + + // flush the written page to disk, and read it out again + tFilePage* pBufPagex = getResBufPage(pResultBuf, writePageId); + ASSERT_EQ(*(int32_t*)pBufPagex->data, nx); + + SArray* pa = getDataBufPagesIdList(pResultBuf, groupId); + ASSERT_EQ(taosArrayGetSize(pa), 5); + + destroyResultBuf(pResultBuf); +} + +void recyclePageTest() { + SDiskbasedResultBuf* pResultBuf = NULL; + int32_t ret = createDiskbasedResultBuffer(&pResultBuf, 1024, 4*1024, 1); + + int32_t pageId = 0; + int32_t writePageId = 0; + int32_t groupId = 0; + int32_t nx = 12345; + + tFilePage* pBufPage = getNewDataBuf(pResultBuf, groupId, &pageId); + ASSERT_TRUE(pBufPage != NULL); + releaseResBufPage(pResultBuf, pBufPage); + + tFilePage* pBufPage1 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t1 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t1 == pBufPage1); + ASSERT_TRUE(pageId == 1); + + tFilePage* pBufPage2 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t2 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t2 == pBufPage2); + ASSERT_TRUE(pageId == 2); + + tFilePage* pBufPage3 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t3 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t3 == pBufPage3); + ASSERT_TRUE(pageId == 3); + + tFilePage* pBufPage4 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t4 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t4 == pBufPage4); + ASSERT_TRUE(pageId == 4); + releaseResBufPage(pResultBuf, t4); + + tFilePage* pBufPage5 = getNewDataBuf(pResultBuf, groupId, &pageId); + tFilePage* t5 = getResBufPage(pResultBuf, pageId); + ASSERT_TRUE(t5 == pBufPage5); + ASSERT_TRUE(pageId == 5); + + // flush the written page to disk, and read it out again + tFilePage* pBufPagex = getResBufPage(pResultBuf, writePageId); + *(int32_t*)(pBufPagex->data) = nx; + writePageId = pageId; // update the data + releaseResBufPage(pResultBuf, pBufPagex); + + tFilePage* pBufPagex1 = getResBufPage(pResultBuf, 1); + + SArray* pa = getDataBufPagesIdList(pResultBuf, groupId); + ASSERT_EQ(taosArrayGetSize(pa), 6); + + destroyResultBuf(pResultBuf); +} +} // namespace + + +TEST(testCase, resultBufferTest) { + srand(time(NULL)); + simpleTest(); + writeDownTest(); + recyclePageTest(); +} diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp new file mode 100644 index 0000000000..04c5a15252 --- /dev/null +++ b/src/query/tests/tsBufTest.cpp @@ -0,0 +1,515 @@ +#include "os.h" +#include +#include +#include + +#include "qTsbuf.h" +#include "taos.h" +#include "tsdb.h" +#include "ttoken.h" +#include "tutil.h" + +#pragma GCC diagnostic ignored "-Wunused-function" +#pragma GCC diagnostic ignored "-Wunused-variable" +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" + +namespace { +/** + * + * @param num total number + * @param step gap between two consecutive ts + * @return + */ +int64_t* createTsList(int32_t num, int64_t start, int32_t step) { + int64_t* pList = (int64_t*)malloc(num * sizeof(int64_t)); + + for (int64_t i = 0; i < num; ++i) { + pList[i] = start + i * step; + } + + return pList; +} + +// simple test +void simpleTest() { + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + // write 10 ts points + int32_t num = 10; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + t.i64 = 1; + + int64_t* list = createTsList(10, 10000000, 30); + tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); + EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); + + EXPECT_EQ(pTSBuf->tsData.len, sizeof(int64_t) * num); + EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0); + EXPECT_EQ(pTSBuf->numOfGroups, 1); + + tsBufFlush(pTSBuf); + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(pTSBuf->block.numOfElem, num); + + tsBufDestroy(pTSBuf); + + free(list); +} + +// one large list of ts, the ts list need to be split into several small blocks +void largeTSTest() { + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + // write 10 ts points + int32_t num = 1000000; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + t.i64 = 1; + + int64_t* list = createTsList(num, 10000000, 30); + tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); + + // the data has been flush to disk, no data in cache + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(tVariantCompare(&pTSBuf->block.tag, &t), 0); + EXPECT_EQ(pTSBuf->numOfGroups, 1); + EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); + + tsBufFlush(pTSBuf); + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(pTSBuf->block.numOfElem, num); + + tsBufDestroy(pTSBuf); + free(list); +} + +void multiTagsTest() { + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + int32_t num = 10000; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + int64_t start = 10000000; + int32_t numOfTags = 50; + int32_t step = 30; + + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf, 0, &t, (const char*)list, num * sizeof(int64_t)); + free(list); + + start += step * num; + } + + EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); + EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); + + EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); + EXPECT_EQ(pTSBuf->numOfGroups, 1); + + tsBufFlush(pTSBuf); + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(pTSBuf->block.numOfElem, num); + + tsBufDestroy(pTSBuf); +} + +void multiVnodeTagsTest() { + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + int32_t num = 10000; + int64_t start = 10000000; + int32_t numOfTags = 50; + int32_t step = 30; + + // 2000 vnodes + for (int32_t j = 0; j < 20; ++j) { + // vnodeId:0 + start = 10000000; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); + free(list); + + start += step * num; + } + + EXPECT_EQ(pTSBuf->numOfGroups, j + 1); + } + + EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); + EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); + EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); + + EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); + + EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); + + tsBufFlush(pTSBuf); + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(pTSBuf->block.numOfElem, num); + + tsBufDestroy(pTSBuf); +} + +void loadDataTest() { + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + int32_t num = 10000; + int64_t oldStart = 10000000; + int32_t numOfTags = 50; + int32_t step = 30; + int32_t numOfVnode = 200; + + // 10000 vnodes + for (int32_t j = 0; j < numOfVnode; ++j) { + // vnodeId:0 + int64_t start = 10000000; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); + printf("%d - %" PRIu64 "\n", i, list[0]); + + free(list); + start += step * num; + } + + EXPECT_EQ(pTSBuf->numOfGroups, j + 1); + } + + EXPECT_EQ(pTSBuf->tsOrder, TSDB_ORDER_ASC); + + EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); + EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); + + EXPECT_EQ(pTSBuf->tsData.len, num * sizeof(int64_t)); + + EXPECT_EQ(pTSBuf->block.tag.i64, numOfTags - 1); + + tsBufFlush(pTSBuf); + EXPECT_EQ(pTSBuf->tsData.len, 0); + EXPECT_EQ(pTSBuf->block.numOfElem, num); + + // create from exists file + STSBuf* pNewBuf = tsBufCreateFromFile(pTSBuf->path, false); + EXPECT_EQ(pNewBuf->tsOrder, pTSBuf->tsOrder); + EXPECT_EQ(pNewBuf->numOfGroups, numOfVnode); + EXPECT_EQ(pNewBuf->fileSize, pTSBuf->fileSize); + + EXPECT_EQ(pNewBuf->pData[0].info.offset, pTSBuf->pData[0].info.offset); + EXPECT_EQ(pNewBuf->pData[0].info.numOfBlocks, pTSBuf->pData[0].info.numOfBlocks); + EXPECT_EQ(pNewBuf->pData[0].info.compLen, pTSBuf->pData[0].info.compLen); + + EXPECT_STREQ(pNewBuf->path, pTSBuf->path); + + tsBufResetPos(pNewBuf); + + int64_t s = taosGetTimestampUs(); + printf("start:%" PRIu64 "\n", s); + + int32_t x = 0; + while (tsBufNextPos(pNewBuf)) { + STSElem elem = tsBufGetElem(pNewBuf); + if (++x == 100000000) { + break; + } + + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); + } + + int64_t e = taosGetTimestampUs(); + printf("end:%" PRIu64 ", elapsed:%" PRIu64 ", total obj:%d\n", e, e - s, x); + tsBufDestroy(pTSBuf); + tsBufDestroy(pNewBuf); +} + +void randomIncTsTest() {} + +void TSTraverse() { + // 10000 vnodes + int32_t num = 200000; + int64_t oldStart = 10000000; + int32_t numOfTags = 3; + int32_t step = 30; + int32_t numOfVnode = 2; + + STSBuf* pTSBuf = tsBufCreate(true, TSDB_ORDER_ASC); + + for (int32_t j = 0; j < numOfVnode; ++j) { + // vnodeId:0 + int64_t start = 10000000; + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); + printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); + + free(list); + start += step * num; + + list = createTsList(num, start, step); + tsBufAppend(pTSBuf, j, &t, (const char*)list, num * sizeof(int64_t)); + printf("%d - %d - %" PRIu64 ", %" PRIu64 "\n", j, i, list[0], list[num - 1]); + free(list); + + start += step * num; + } + + EXPECT_EQ(pTSBuf->numOfGroups, j + 1); + } + + tsBufResetPos(pTSBuf); + + //////////////////////////////////////////////////////////////////////////////////////// + // reverse traverse + int64_t s = taosGetTimestampUs(); + printf("start:%" PRIu64 "\n", s); + + pTSBuf->cur.order = TSDB_ORDER_DESC; + + // complete reverse traverse + int32_t x = 0; + while (tsBufNextPos(pTSBuf)) { + STSElem elem = tsBufGetElem(pTSBuf); + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); + } + + // specify the data block with vnode and tags value + tsBufResetPos(pTSBuf); + pTSBuf->cur.order = TSDB_ORDER_DESC; + + int32_t startVnode = 1; + int32_t startTag = 2; + + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + t.i64 = startTag; + + tsBufGetElemStartPos(pTSBuf, startVnode, &t); + + int32_t totalOutput = 10; + while (1) { + STSElem elem = tsBufGetElem(pTSBuf); + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); + + if (!tsBufNextPos(pTSBuf)) { + break; + } + + if (--totalOutput <= 0) { + totalOutput = 10; + + startTag -= 1; + t.i64 = startTag; + tsBufGetElemStartPos(pTSBuf, startVnode, &t); + + if (startTag == 0) { + startVnode -= 1; + startTag = 3; + } + + if (startVnode < 0) { + break; + } + } + } + + ///////////////////////////////////////////////////////////////////////////////// + // traverse + pTSBuf->cur.order = TSDB_ORDER_ASC; + tsBufResetPos(pTSBuf); + + // complete forwards traverse + while (tsBufNextPos(pTSBuf)) { + STSElem elem = tsBufGetElem(pTSBuf); + // printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.vnode, elem.tag, elem.ts); + } + + // specify the data block with vnode and tags value + tsBufResetPos(pTSBuf); + pTSBuf->cur.order = TSDB_ORDER_ASC; + + startVnode = 1; + startTag = 2; + t.i64 = startTag; + + tsBufGetElemStartPos(pTSBuf, startVnode, &t); + + totalOutput = 10; + while (1) { + STSElem elem = tsBufGetElem(pTSBuf); + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); + + if (!tsBufNextPos(pTSBuf)) { + break; + } + + if (--totalOutput <= 0) { + totalOutput = 10; + + startTag -= 1; + t.i64 = startTag; + tsBufGetElemStartPos(pTSBuf, startVnode, &t); + + if (startTag < 0) { + startVnode -= 1; + startTag = 3; + } + + if (startVnode < 0) { + break; + } + } + } + + tsBufDestroy(pTSBuf); +} + +void performanceTest() {} + +void emptyTagTest() {} + +void invalidFileTest() { + const char* cmd = "touch /tmp/test"; + + // create empty file + system(cmd); + + STSBuf* pNewBuf = tsBufCreateFromFile("/tmp/test", true); + EXPECT_TRUE(pNewBuf == NULL); + tsBufDestroy(pNewBuf); + + pNewBuf = tsBufCreateFromFile("/tmp/911", true); + EXPECT_TRUE(pNewBuf == NULL); + + tsBufDestroy(pNewBuf); +} + +void mergeDiffVnodeBufferTest() { + STSBuf* pTSBuf1 = tsBufCreate(true, TSDB_ORDER_ASC); + STSBuf* pTSBuf2 = tsBufCreate(true, TSDB_ORDER_ASC); + + int32_t step = 30; + int32_t num = 1000; + int32_t numOfTags = 10; + + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + // vnodeId:0 + int64_t start = 10000000; + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf1, 1, &t, (const char*)list, num * sizeof(int64_t)); + tsBufAppend(pTSBuf2, 9, &t, (const char*)list, num * sizeof(int64_t)); + + free(list); + + start += step * num; + } + + tsBufFlush(pTSBuf2); + + tsBufMerge(pTSBuf1, pTSBuf2); + EXPECT_EQ(pTSBuf1->numOfGroups, 2); + EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num); + + tsBufDisplay(pTSBuf1); + + tsBufDestroy(pTSBuf2); + tsBufDestroy(pTSBuf1); +} + +void mergeIdenticalVnodeBufferTest() { + STSBuf* pTSBuf1 = tsBufCreate(true, TSDB_ORDER_ASC); + STSBuf* pTSBuf2 = tsBufCreate(true, TSDB_ORDER_ASC); + + tVariant t = {0}; + t.nType = TSDB_DATA_TYPE_BIGINT; + + int32_t step = 30; + int32_t num = 1000; + int32_t numOfTags = 10; + + // vnodeId:0 + int64_t start = 10000000; + for (int32_t i = 0; i < numOfTags; ++i) { + int64_t* list = createTsList(num, start, step); + t.i64 = i; + + tsBufAppend(pTSBuf1, 12, &t, (const char*)list, num * sizeof(int64_t)); + free(list); + + start += step * num; + } + + for (int32_t i = numOfTags; i < numOfTags * 2; ++i) { + int64_t* list = createTsList(num, start, step); + + t.i64 = i; + tsBufAppend(pTSBuf2, 77, &t, (const char*)list, num * sizeof(int64_t)); + free(list); + + start += step * num; + } + + tsBufFlush(pTSBuf2); + + tsBufMerge(pTSBuf1, pTSBuf2); + EXPECT_EQ(pTSBuf1->numOfGroups, 2); + EXPECT_EQ(pTSBuf1->numOfTotal, numOfTags * 2 * num); + + tsBufResetPos(pTSBuf1); + + int32_t count = 0; + while (tsBufNextPos(pTSBuf1)) { + STSElem elem = tsBufGetElem(pTSBuf1); + + if (count++ < numOfTags * num) { + EXPECT_EQ(elem.id, 12); + } else { + EXPECT_EQ(elem.id, 77); + } + + printf("%d-%" PRIu64 "-%" PRIu64 "\n", elem.id, elem.tag->i64, elem.ts); + } + + tsBufDestroy(pTSBuf1); + tsBufDestroy(pTSBuf2); +} +} // namespace + + +//TODO add binary tag value test case +TEST(testCase, tsBufTest) { + simpleTest(); + largeTSTest(); + multiTagsTest(); + multiVnodeTagsTest(); + loadDataTest(); + invalidFileTest(); +// randomIncTsTest(); + TSTraverse(); + mergeDiffVnodeBufferTest(); + mergeIdenticalVnodeBufferTest(); +} From f1a9b5890ff29b0c1d408e8f6ba81eca8ead57e5 Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 2 Jul 2021 18:18:33 +0800 Subject: [PATCH 015/100] support ts range --- src/client/src/tscSQLParser.c | 125 ++++-- src/common/src/texpr.c | 4 +- src/common/src/ttypes.c | 133 +++--- src/common/src/tvariant.c | 18 +- src/inc/taoserror.h | 1 + src/inc/ttype.h | 6 +- src/query/inc/qFilter.h | 56 ++- src/query/src/qExecutor.c | 9 +- src/query/src/qFilter.c | 474 +++++++++++++++++++--- src/query/src/qSqlParser.c | 3 + src/query/src/queryMain.c | 2 + src/query/tests/rangeMergeTest.cpp | 206 +++++++--- src/util/src/terror.c | 1 + tests/script/general/parser/condition.sim | 115 +++++- 14 files changed, 914 insertions(+), 239 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index dc441dd280..061ba7653b 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4123,6 +4123,19 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t return TSDB_CODE_SUCCESS; } +int32_t handleNeOptr(tSqlExpr** rexpr, tSqlExpr* expr) { + tSqlExpr* left = tSqlExprClone(expr); + tSqlExpr* right = expr; + + left->tokenId = TK_LT; + right->tokenId = TK_GT; + + *rexpr = tSqlExprCreate(left, right, TK_OR); + + return TSDB_CODE_SUCCESS; +} + + static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SCondExpr* pCondExpr, int32_t* type, int32_t* tbIdx, int32_t parentOptr, tSqlExpr** columnExpr, tSqlExpr** tsExpr) { const char* msg1 = "table query cannot use tags filter"; @@ -4221,7 +4234,14 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql *type |= TSQL_EXPR_JOIN; } } else { - ret = setNormalExprToCond(tsExpr, *pExpr, parentOptr); + tSqlExpr *rexpr = NULL; + if ((*pExpr)->tokenId == TK_NE) { + handleNeOptr(&rexpr, *pExpr); + } else { + rexpr = *pExpr; + } + + ret = setNormalExprToCond(tsExpr, rexpr, parentOptr); if (type) { *type |= TSQL_EXPR_TS; } @@ -4272,6 +4292,12 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql // do nothing // ret = setExprToCond(pCmd, &pCondExpr->pTagCond, // *pExpr, NULL, parentOptr); + tSqlExpr *rexpr = NULL; + if ((*pExpr)->tokenId == TK_NE && (pSchema->type != TSDB_DATA_TYPE_BINARY && pSchema->type != TSDB_DATA_TYPE_NCHAR && pSchema->type != TSDB_DATA_TYPE_BOOL)) { + handleNeOptr(&rexpr, *pExpr); + *pExpr = rexpr; + } + if (type) { *type |= TSQL_EXPR_TAG; } @@ -4286,7 +4312,14 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg5); } - ret = setNormalExprToCond(columnExpr, *pExpr, parentOptr); + tSqlExpr *rexpr = NULL; + if ((*pExpr)->tokenId == TK_NE && (pSchema->type != TSDB_DATA_TYPE_BINARY && pSchema->type != TSDB_DATA_TYPE_NCHAR && pSchema->type != TSDB_DATA_TYPE_BOOL)) { + handleNeOptr(&rexpr, *pExpr); + } else { + rexpr = *pExpr; + } + + ret = setNormalExprToCond(columnExpr, rexpr, parentOptr); *pExpr = NULL; // remove it from expr tree } @@ -4575,37 +4608,40 @@ int32_t mergeTimeRange(SSqlCmd* pCmd, STimeWindow* res, STimeWindow* win, int32_ return TSDB_CODE_SUCCESS; } +static int32_t createTimeRangeExpr(tSqlExpr** pExpr, STimeWindow* win, uint32_t tokenId) { + *pExpr = calloc(1, sizeof(tSqlExpr)); + + (*pExpr)->type = SQL_NODE_VALUE; + (*pExpr)->tokenId = tokenId; + (*pExpr)->value.nType = TSDB_DATA_TYPE_VALUE_ARRAY; + (*pExpr)->value.nLen = 2; + (*pExpr)->value.arr = taosArrayInit(2, sizeof(int64_t)); -static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr, STimeWindow* win) { + taosArrayPush((*pExpr)->value.arr, &win->skey); + taosArrayPush((*pExpr)->value.arr, &win->ekey); + + return TSDB_CODE_SUCCESS; +} + +static int32_t convertTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr* pExpr) { const char* msg0 = "invalid timestamp or operator for timestamp"; int32_t code = 0; - STimeWindow win2 = {.skey = INT64_MIN, .ekey = INT64_MAX}; + STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; if (pExpr == NULL) { return TSDB_CODE_SUCCESS; } if (!tSqlExprIsParentOfLeaf(pExpr)) { - if (pExpr->tokenId == TK_OR) { - code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft, win); + code = convertTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft); if (code) { return code; } - code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight, &win2); + code = convertTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight); if (code) { return code; } - - return mergeTimeRange(pCmd, win, &win2, TSDB_RELATION_OR); - } - - code = getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pLeft, win); - if (code) { - return code; - } - - return getTimeRangeFromExpr(pCmd, pQueryInfo, pExpr->pRight, win); } else { SColumnIndex index = COLUMN_INDEX_INITIALIZER; if (getColumnIndexByName(pCmd, &pExpr->pLeft->colInfo, pQueryInfo, &index) != TSDB_CODE_SUCCESS) { @@ -4617,11 +4653,13 @@ static int32_t getTimeRangeFromExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlE tSqlExpr* pRight = pExpr->pRight; - if (getTimeRange(&win2, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) { + if (getTimeRange(&win, pRight, pExpr->tokenId, tinfo.precision) != TSDB_CODE_SUCCESS) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg0); } - return mergeTimeRange(pCmd, win, &win2, TSDB_RELATION_AND); + createTimeRangeExpr(&pExpr->pRight, &win, pRight->tokenId); + + tSqlExprDestroy(pRight); } return TSDB_CODE_SUCCESS; @@ -4950,6 +4988,42 @@ int32_t mergeJoinNodes(SQueryInfo* pQueryInfo, SSqlObj* pSql) { return TSDB_CODE_SUCCESS; } +static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr) { + int32_t ret = TSDB_CODE_SUCCESS; + + if (*pExpr == NULL) { + return ret; + } + + //multiple tables's query time range mixed together + + tExprNode* p = NULL; + SFilterInfo *filter = NULL; + + SArray* colList = taosArrayInit(10, sizeof(SColIndex)); + ret = exprTreeFromSqlExpr(pCmd, &p, *pExpr, pQueryInfo, colList, NULL); + if (ret != TSDB_CODE_SUCCESS) { + goto _ret; + } + + ret = filterInitFromTree(p, &filter); + if (ret != TSDB_CODE_SUCCESS) { + goto _ret; + } + + ret = filterGetTimeRange(filter, &pQueryInfo->window); + +_ret: + tExprTreeDestroy(p, NULL); + + if (ret) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), tstrerror(ret)); + } + + return ret; +} + + int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql) { if (pExpr == NULL) { @@ -5000,12 +5074,11 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } // 2. get the query time range - STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; - if ((ret = getTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow, &win)) != TSDB_CODE_SUCCESS) { + if ((ret = convertTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { return ret; } - if ((ret = mergeTimeRange(&pSql->cmd, &pQueryInfo->window,&win, TSDB_RELATION_AND)) != TSDB_CODE_SUCCESS) { + if ((ret = getQueryTimeRange(&pSql->cmd, pQueryInfo, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { return ret; } @@ -5024,14 +5097,6 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq goto PARSE_WHERE_EXIT; } -/* - if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 ) { - if ((ret = getColumnQueryCondInfo(&pSql->cmd, pQueryInfo, condExpr.pTimewindow, TK_AND)) != TSDB_CODE_SUCCESS) { - goto PARSE_WHERE_EXIT; - } - } -*/ - if ((ret = getColQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr.pColumnCond)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 285ebfcf31..4ba2b35f3e 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -118,7 +118,7 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) { } else if (pNode->nodeType == TSQL_NODE_VALUE) { tVariantDestroy(pNode->pVal); } else if (pNode->nodeType == TSQL_NODE_COL) { - free(pNode->pSchema); + tfree(pNode->pSchema); } free(pNode); @@ -435,7 +435,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) { expr->_node.optr = TSDB_RELATION_IN; tVariant* pVal = exception_calloc(1, sizeof(tVariant)); right->pVal = pVal; - pVal->nType = TSDB_DATA_TYPE_ARRAY; + pVal->nType = TSDB_DATA_TYPE_POINTER_ARRAY; pVal->arr = taosArrayInit(2, POINTER_BYTES); const char* cond = tbnameCond + QUERY_COND_REL_PREFIX_IN_LEN; diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index ffbdbd1bbe..057697fab2 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -368,21 +368,21 @@ static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, i } tDataTypeDescriptor tDataTypes[15] = { - {TSDB_DATA_TYPE_NULL, 6,1, "NOTYPE", NULL, NULL, NULL}, - {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", tsCompressBool, tsDecompressBool, getStatics_bool}, - {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", tsCompressTinyint, tsDecompressTinyint, getStatics_i8}, - {TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", tsCompressSmallint, tsDecompressSmallint, getStatics_i16}, - {TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", tsCompressInt, tsDecompressInt, getStatics_i32}, - {TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", tsCompressBigint, tsDecompressBigint, getStatics_i64}, - {TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", tsCompressFloat, tsDecompressFloat, getStatics_f}, - {TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", tsCompressDouble, tsDecompressDouble, getStatics_d}, - {TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", tsCompressString, tsDecompressString, getStatics_bin}, - {TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", tsCompressTimestamp, tsDecompressTimestamp, getStatics_i64}, - {TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", tsCompressString, tsDecompressString, getStatics_nchr}, - {TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", tsCompressTinyint, tsDecompressTinyint, getStatics_u8}, - {TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", tsCompressSmallint, tsDecompressSmallint, getStatics_u16}, - {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", tsCompressInt, tsDecompressInt, getStatics_u32}, - {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", tsCompressBigint, tsDecompressBigint, getStatics_u64}, + {TSDB_DATA_TYPE_NULL, 6, 1, "NOTYPE", 0, 0, NULL, NULL, NULL}, + {TSDB_DATA_TYPE_BOOL, 4, CHAR_BYTES, "BOOL", false, true, tsCompressBool, tsDecompressBool, getStatics_bool}, + {TSDB_DATA_TYPE_TINYINT, 7, CHAR_BYTES, "TINYINT", INT8_MIN, INT8_MAX, tsCompressTinyint, tsDecompressTinyint, getStatics_i8}, + {TSDB_DATA_TYPE_SMALLINT, 8, SHORT_BYTES, "SMALLINT", INT16_MIN, INT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_i16}, + {TSDB_DATA_TYPE_INT, 3, INT_BYTES, "INT", INT32_MIN, INT32_MAX, tsCompressInt, tsDecompressInt, getStatics_i32}, + {TSDB_DATA_TYPE_BIGINT, 6, LONG_BYTES, "BIGINT", INT64_MIN, INT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_i64}, + {TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f}, + {TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d}, + {TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", 0, 0, tsCompressString, tsDecompressString, getStatics_bin}, + {TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp, tsDecompressTimestamp, getStatics_i64}, + {TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr}, + {TSDB_DATA_TYPE_UTINYINT, 16, CHAR_BYTES, "TINYINT UNSIGNED", 0, UINT8_MAX, tsCompressTinyint, tsDecompressTinyint, getStatics_u8}, + {TSDB_DATA_TYPE_USMALLINT, 17, SHORT_BYTES, "SMALLINT UNSIGNED", 0, UINT16_MAX, tsCompressSmallint, tsDecompressSmallint, getStatics_u16}, + {TSDB_DATA_TYPE_UINT, 12, INT_BYTES, "INT UNSIGNED", 0, UINT32_MAX, tsCompressInt, tsDecompressInt, getStatics_u32}, + {TSDB_DATA_TYPE_UBIGINT, 15, LONG_BYTES, "BIGINT UNSIGNED", 0, UINT64_MAX, tsCompressBigint, tsDecompressBigint, getStatics_u64}, }; char tTokenTypeSwitcher[13] = { @@ -560,65 +560,50 @@ void assignVal(char *val, const char *src, int32_t len, int32_t type) { } } -int8_t getInt8Val(void *s) { - return (int8_t)GET_INT8_VAL(s); -} -uint8_t getUint8Val(void *s) { - return (uint8_t)GET_INT8_VAL(s); -} -int16_t getInt16Val(void *s) { - return (int16_t)GET_INT16_VAL(s); -} -uint16_t getUint16Val(void *s) { - return (uint16_t)GET_INT16_VAL(s); -} -int32_t getInt32Val(void *s) { - return (int32_t)GET_INT32_VAL(s); -} -uint32_t getUint32Val(void *s) { - return (uint32_t)GET_INT32_VAL(s); -} -int64_t getInt64Val(void *s) { - return (int64_t)GET_INT64_VAL(s); -} -uint64_t getUint64Val(void *s) { - return (uint64_t)GET_INT64_VAL(s); -} -float getFloatVal(void *s) { - return GET_FLOAT_VAL(s); -} -double getDoubleVal(void *s) { - return GET_DOUBLE_VAL(s); -} -void setInt8Val(void *d, void *s) { - *((int8_t *)d) = (int8_t)GET_INT8_VAL(s); -} -void setUint8Val(void *d, void *s) { - *((uint8_t *)d) = GET_INT8_VAL(s); -} -void setInt16Val(void *d, void *s) { - *((int16_t *)d) = (int16_t)GET_INT16_VAL(s); -} -void setUint16Val(void *d, void *s) { - *((uint16_t *)d) = GET_INT16_VAL(s); -} -void setInt32Val(void *d, void *s) { - *((int32_t *)d) = GET_INT32_VAL(s); -} -void setUint32Val(void *d, void *s) { - *((uint32_t *)d) = GET_INT32_VAL(s); -} -void setInt64Val(void *d, void *s) { - *((int64_t *)d) = GET_INT64_VAL(s); -} -void setUint64Val(void *d, void *s) { - *((uint64_t *)d) = GET_INT64_VAL(s); -} -void setFloatVal(void *d, void *s) { - SET_FLOAT_VAL(d, GET_FLOAT_VAL(s)); -} -void setDoubleVal(void *d, void *s) { - SET_DOUBLE_VAL(d, GET_DOUBLE_VAL(s)); +void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) { + if (optr == TSDB_BINARY_OP_ADD) { + switch (type) { + case TSDB_DATA_TYPE_TINYINT: + *((int8_t *)dst) = GET_INT8_VAL(s1) + GET_INT8_VAL(s2); + break; + case TSDB_DATA_TYPE_UTINYINT: + *((uint8_t *)dst) = GET_UINT8_VAL(s1) + GET_UINT8_VAL(s2); + break; + case TSDB_DATA_TYPE_SMALLINT: + *((int16_t *)dst) = GET_INT16_VAL(s1) + GET_INT16_VAL(s2); + break; + case TSDB_DATA_TYPE_USMALLINT: + *((uint16_t *)dst) = GET_UINT16_VAL(s1) + GET_UINT16_VAL(s2); + break; + case TSDB_DATA_TYPE_INT: + *((int32_t *)dst) = GET_INT32_VAL(s1) + GET_INT32_VAL(s2); + break; + case TSDB_DATA_TYPE_UINT: + *((uint32_t *)dst) = GET_UINT32_VAL(s1) + GET_UINT32_VAL(s2); + break; + case TSDB_DATA_TYPE_BIGINT: + *((int64_t *)dst) = GET_INT64_VAL(s1) + GET_INT64_VAL(s2); + break; + case TSDB_DATA_TYPE_UBIGINT: + *((uint64_t *)dst) = GET_UINT64_VAL(s1) + GET_UINT64_VAL(s2); + break; + case TSDB_DATA_TYPE_TIMESTAMP: + *((int64_t *)dst) = GET_INT64_VAL(s1) + GET_INT64_VAL(s2); + break; + case TSDB_DATA_TYPE_FLOAT: + SET_FLOAT_VAL(dst, GET_FLOAT_VAL(s1) + GET_FLOAT_VAL(s2)); + break; + case TSDB_DATA_TYPE_DOUBLE: + SET_DOUBLE_VAL(dst, GET_DOUBLE_VAL(s1) + GET_DOUBLE_VAL(s2)); + break; + default: { + assert(0); + break; + } + } + } else { + assert(0); + } } diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 1168eeb231..1a5bbdf28c 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -184,7 +184,7 @@ void tVariantDestroy(tVariant *pVar) { } // NOTE: this is only for string array - if (pVar->nType == TSDB_DATA_TYPE_ARRAY) { + if (pVar->nType == TSDB_DATA_TYPE_POINTER_ARRAY) { size_t num = taosArrayGetSize(pVar->arr); for(size_t i = 0; i < num; i++) { void* p = taosArrayGetP(pVar->arr, i); @@ -192,6 +192,9 @@ void tVariantDestroy(tVariant *pVar) { } taosArrayDestroy(pVar->arr); pVar->arr = NULL; + } else if (pVar->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + taosArrayDestroy(pVar->arr); + pVar->arr = NULL; } } @@ -220,7 +223,7 @@ void tVariantAssign(tVariant *pDst, const tVariant *pSrc) { if (IS_NUMERIC_TYPE(pSrc->nType) || (pSrc->nType == TSDB_DATA_TYPE_BOOL)) { pDst->i64 = pSrc->i64; - } else if (pSrc->nType == TSDB_DATA_TYPE_ARRAY) { // this is only for string array + } else if (pSrc->nType == TSDB_DATA_TYPE_POINTER_ARRAY) { // this is only for string array size_t num = taosArrayGetSize(pSrc->arr); pDst->arr = taosArrayInit(num, sizeof(char*)); for(size_t i = 0; i < num; i++) { @@ -228,9 +231,18 @@ void tVariantAssign(tVariant *pDst, const tVariant *pSrc) { char* n = strdup(p); taosArrayPush(pDst->arr, &n); } + } else if (pSrc->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + size_t num = taosArrayGetSize(pSrc->arr); + pDst->arr = taosArrayInit(num, sizeof(int64_t)); + pDst->nLen = pSrc->nLen; + assert(pSrc->nLen == num); + for(size_t i = 0; i < num; i++) { + int64_t *p = taosArrayGet(pSrc->arr, i); + taosArrayPush(pDst->arr, p); + } } - if (pDst->nType != TSDB_DATA_TYPE_ARRAY) { + if (pDst->nType != TSDB_DATA_TYPE_POINTER_ARRAY && pDst->nType != TSDB_DATA_TYPE_VALUE_ARRAY) { pDst->nLen = tDataTypes[pDst->nType].bytes; } } diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index 431c9116cc..f73ae9e543 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -260,6 +260,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW TAOS_DEF_ERROR_CODE(0, 0x070A) //"Too many time window in query") #define TSDB_CODE_QRY_NOT_ENOUGH_BUFFER TAOS_DEF_ERROR_CODE(0, 0x070B) //"Query buffer limit has reached") #define TSDB_CODE_QRY_INCONSISTAN TAOS_DEF_ERROR_CODE(0, 0x070C) //"File inconsistency in replica") +#define TSDB_CODE_QRY_INVALID_TIME_CONDITION TAOS_DEF_ERROR_CODE(0, 0x070D) //"invalid time condition") // grant diff --git a/src/inc/ttype.h b/src/inc/ttype.h index 9949f31c59..fe19076252 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -29,7 +29,8 @@ typedef struct tstr { #define IS_VAR_DATA_TYPE(t) (((t) == TSDB_DATA_TYPE_BINARY) || ((t) == TSDB_DATA_TYPE_NCHAR)) // this data type is internally used only in 'in' query to hold the values -#define TSDB_DATA_TYPE_ARRAY (1000) +#define TSDB_DATA_TYPE_POINTER_ARRAY (1000) +#define TSDB_DATA_TYPE_VALUE_ARRAY (1001) #define GET_TYPED_DATA(_v, _finalType, _type, _data) \ do { \ @@ -161,6 +162,8 @@ typedef struct tDataTypeDescriptor { int16_t nameLen; int32_t bytes; char * name; + int64_t minValue; + int64_t maxValue; int (*compFunc)(const char *const input, int inputSize, const int nelements, char *const output, int outputSize, char algorithm, char *const buffer, int bufferSize); int (*decompFunc)(const char *const input, int compressedSize, const int nelements, char *const output, @@ -180,6 +183,7 @@ void *getNullValue(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* buf); +void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type); int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned); diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index afa8423244..78c1c1d9db 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -41,30 +41,50 @@ enum { MR_OPT_TS = 1, }; +enum { + RA_EXCLUDE = 1, + RA_NULL = 2, +}; + typedef struct OptrStr { uint16_t optr; char *str; } OptrStr; +typedef struct SFilterColRange { + uint16_t idx; //column field idx + int64_t s; + int64_t e; +} SFilterColRange; + typedef struct SFilterRange { - struct SFilterRange* prev; - struct SFilterRange* next; + char sflag; + char eflag; int64_t s; int64_t e; } SFilterRange; + +typedef struct SFilterRangeNode { + struct SFilterRangeNode* prev; + struct SFilterRangeNode* next; + SFilterRange ra; +} SFilterRangeNode; + typedef struct SFilterRMCtx { int32_t type; int32_t options; int8_t status; __compar_fn_t pCompareFunc; - SFilterRange *rs; + SFilterRangeNode *rf; //freed + SFilterRangeNode *rs; } SFilterRMCtx ; typedef struct SFilterField { uint16_t type; void* desc; void* data; + int64_t range[]; } SFilterField; typedef struct SFilterFields { @@ -106,14 +126,23 @@ typedef struct SFilterInfo { uint8_t *unitFlags; // got result } SFilterInfo; +#define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) + +#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR) +#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL) + +#define MR_EMPTY_RES(ctx) (ctx->rs == NULL) + #define MR_GET_FLAG(st, f) (st & f) #define MR_SET_FLAG(st, f) st |= (f) -#define GEN_RANGE(r, t, s, e) do { r = calloc(1, sizeof(SFilterRange)); assignVal((char*)&(r)->s, s, 0, t); assignVal((char*)&(r)->e, e, 0, t); } while (0) -#define FREE_RANGE(rs, r) do { if (r->prev) { r->prev->next = r->next; } else { rs = r->next;} if (r->next) { r->next->prev = r->prev; } free(r); } while (0) -#define FREE_FROM_RANGE(rs, r) do { if (r->prev) { r->prev->next = NULL; } else { rs = NULL;} while (r) {SFilterRange *n = r->next; free(r); r = n; } } while (0) -#define INSERT_RANGE(rs, r, t, s, e) do { SFilterRange *n = calloc(1, sizeof(SFilterRange)); assignVal((char*)&n->s, s, 0, t); assignVal((char*)&n->e, e, 0, t); n->prev = r->prev; r->prev = n; if (r->prev) { r->prev->next = n; } else { rs->next = n; } n->next = r; } while (0) -#define APPEND_RANGE(r, t, s, e) do { SFilterRange *n = calloc(1, sizeof(SFilterRange)); assignVal((char*)&n->s, s, 0, t); assignVal((char*)&n->e, e, 0, t); n->prev = r; r->next = n; } while (0) +#define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) + +#define RESET_RANGE(ctx, r) do { r->next = ctx->rf; ctx->rf = r; } while (0) +#define FREE_RANGE(ctx, r) do { if (r->prev) { r->prev->next = r->next; } else { ctx->rs = r->next;} if (r->next) { r->next->prev = r->prev; } RESET_RANGE(ctx, r); } while (0) +#define FREE_FROM_RANGE(ctx, r) do { if (r->prev) { r->prev->next = NULL; } else { ctx->rs = NULL;} while (r) {SFilterRangeNode *n = r->next; RESET_RANGE(ctx, r); r = n; } } while (0) +#define INSERT_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r->prev; if (r->prev) { r->prev->next = n; } else { ctx->rs = n; } r->prev = n; n->next = r; } while (0) +#define APPEND_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r; if (r) { r->next = n; } else { ctx->rs = n; } } while (0) #define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0) #define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0) @@ -121,6 +150,7 @@ typedef struct SFilterInfo { #define CHK_RETV(c) do { if (c) { return; } } while (0) #define CHK_RET(c, r) do { if (c) { return r; } } while (0) +#define CHK_JMP(c) do { if (c) { goto _err_return; } } while (0) #define CHK_LRETV(c,...) do { if (c) { qError(__VA_ARGS__); return; } } while (0) #define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) @@ -130,7 +160,13 @@ typedef struct SFilterInfo { #define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) #define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) - +#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units[(g)->unitIdxs[uid]]) +#define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) +#define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) +#define FILTER_UNIT_DATA_TYPE(i, u) FILTER_GET_COL_FIELD_TYPE(FILTER_UNIT_LEFT_FIELD(i, u)) +#define FILTER_UNIT_VAL(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) +#define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) +#define FILTER_UNIT_OPTR(u) ((u)->compare.optr) #define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) #define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 @@ -149,7 +185,7 @@ extern int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr); extern int32_t filterGetMergeRangeNum(void* h, int32_t* num); extern int32_t filterGetMergeRangeRes(void* h, void *s, void* e); extern int32_t filterFreeMergeRange(void* h); - +extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); #ifdef __cplusplus } #endif diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index afc9eab0b0..63e5c50c50 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6966,7 +6966,10 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { return TSDB_CODE_QRY_APP_ERROR; } - return filterInitFromTree(expr, pFilters); + int32_t ret = filterInitFromTree(expr, pFilters); + tExprTreeDestroy(expr, NULL); + + return ret; } @@ -7284,10 +7287,6 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S } doUpdateExprColumnIndex(pQueryAttr); - int32_t ret = createFilterInfo(pQueryAttr, pQInfo->qId); - if (ret != TSDB_CODE_SUCCESS) { - goto _cleanup; - } if (pQueryAttr->fillType != TSDB_FILL_NONE) { pQueryAttr->fillVal = malloc(sizeof(int64_t) * pQueryAttr->numOfOutput); diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 06f85d4af1..56a53ebd50 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -54,6 +54,24 @@ filter_desc_compare_func gDescCompare [F_FIELD_MAX] = { filterFieldValDescCompare }; +static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, int32_t t, void *s, void *e) { + SFilterRangeNode *r = NULL; + + if (ctx->rf) { + r = ctx->rf; + ctx->rf = ctx->rf->next; + r->prev = NULL; + r->next = NULL; + } else { + r = calloc(1, sizeof(SFilterRangeNode)); + } + + SIMPLE_COPY_VALUES((char*)&r->s, s); + SIMPLE_COPY_VALUES((char*)&r->e, e); + + return r; +} + void* filterInitMergeRange(int32_t type, int32_t options) { if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { qError("not supported range type:%d", type); @@ -63,46 +81,97 @@ void* filterInitMergeRange(int32_t type, int32_t options) { SFilterRMCtx *ctx = calloc(1, sizeof(SFilterRMCtx)); ctx->type = type; + ctx->options = options; ctx->pCompareFunc = getComparFunc(type, 0); return ctx; } -int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { +int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { + SFilterRMCtx *dctx = (SFilterRMCtx *)dst; + SFilterRMCtx *sctx = (SFilterRMCtx *)src; + + if (sctx->rs == NULL) { + return TSDB_CODE_SUCCESS; + } + + SFilterRangeNode *r = sctx->rs; + + while (r) { + filterAddMergeRange(dctx, &r->s, &r->e, optr); + r = r->next; + } + + return TSDB_CODE_SUCCESS; +} + +int32_t filterResetMergeRangeCtx(SFilterRMCtx *ctx) { + ctx->status = 0; + + if (ctx->rf == NULL) { + ctx->rf = ctx->rs; + ctx->rs = NULL; + return TSDB_CODE_SUCCESS; + } + + SFilterRangeNode *r = ctx->rf; + + while (r && r->next) { + r = r->next; + } + + r->next = ctx->rs; + ctx->rs = NULL; + return TSDB_CODE_SUCCESS; +} + +int32_t filterReuseMergeRangeCtx(SFilterRMCtx *ctx, int32_t type, int32_t options) { + filterResetMergeRangeCtx(ctx); + + ctx->type = type; + ctx->options = options; + ctx->pCompareFunc = getComparFunc(type, 0); + + return TSDB_CODE_SUCCESS; +} + + + +int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char eflag, int32_t optr) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; if (ctx->rs == NULL) { if (MR_GET_FLAG(ctx->status, MR_ST_START) == 0 || optr == TSDB_RELATION_OR) { - GEN_RANGE(ctx->rs, ctx->type, s, e); + APPEND_RANGE(ctx, ctx->rs, ctx->type, s, e); MR_SET_FLAG(ctx->status, MR_ST_START); } return TSDB_CODE_SUCCESS; } - SFilterRange *r = ctx->rs; - SFilterRange *rn = NULL; + SFilterRangeNode *r = ctx->rs; + SFilterRangeNode *rn = NULL; if (optr == TSDB_RELATION_AND) { while (r != NULL) { if (ctx->pCompareFunc(&r->s, e) > 0) { - FREE_FROM_RANGE(ctx->rs, r); + FREE_FROM_RANGE(ctx, r); break; } if (ctx->pCompareFunc(s, &r->e) > 0) { rn = r->next; - FREE_RANGE(ctx->rs, r); + FREE_RANGE(ctx, r); r = rn; continue; } if (ctx->pCompareFunc(s, &r->s) > 0) { - assignVal((char *)&r->s, s, 0, ctx->type); + SIMPLE_COPY_VALUES((char *)&r->s, s); } if (ctx->pCompareFunc(&r->e, e) > 0) { - assignVal((char *)&r->e, e, 0, ctx->type); + SIMPLE_COPY_VALUES((char *)&r->e, e); break; } @@ -120,7 +189,7 @@ int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { while (r != NULL) { if (ctx->pCompareFunc(&r->s, e) > 0) { if (emerged == false) { - INSERT_RANGE(ctx->rs, r, ctx->type, s, e); + INSERT_RANGE(ctx, r, ctx->type, s, e); } break; @@ -132,13 +201,13 @@ int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { continue; } - APPEND_RANGE(r, ctx->type, s, e); + APPEND_RANGE(ctx, r, ctx->type, s, e); break; } if (smerged == false) { if (ctx->pCompareFunc(&r->s, s) > 0) { - assignVal((char *)&r->s, s, 0, ctx->type); + SIMPLE_COPY_VALUES((char *)&r->s, s); } smerged = true; @@ -146,7 +215,7 @@ int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { if (emerged == false) { if (ctx->pCompareFunc(e, &r->e) > 0) { - assignVal((char *)&r->e, e, 0, ctx->type); + SIMPLE_COPY_VALUES((char *)&r->e, e); emerged = true; e = &r->e; r = r->next; @@ -158,13 +227,13 @@ int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { if (ctx->pCompareFunc(e, &r->e) > 0) { rn = r->next; - FREE_RANGE(ctx->rs, r); + FREE_RANGE(ctx, r); r = rn; continue; } else { - assignVal(e, (char *)&r->e, 0, ctx->type); - FREE_RANGE(ctx->rs, r); + SIMPLE_COPY_VALUES(e, (char *)&r->e); + FREE_RANGE(ctx, r); break; } @@ -173,6 +242,29 @@ int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr) { return TSDB_CODE_SUCCESS; } +int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + int64_t sv, ev; + void *s, *e; + char sflag = 0, eflag = 0; + + if (MR_GET_FLAG(ra->sflag, RA_NULL)) { + SIMPLE_COPY_VALUES(&sv, &tDataTypes[ctx->type].minValue); + s = &sv; + } else { + s = &ra.s; + } + + if (MR_GET_FLAG(ra->eflag, RA_NULL)) { + SIMPLE_COPY_VALUES(&ev, &tDataTypes[ctx->type].maxValue); + e = &ev; + } else { + e = &ra.e; + } + + return filterAddMergeRangeImpl(h, s, e, ra.sflag, ra.eflag, optr); +} + int32_t filterFinMergeRange(void* h) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; @@ -181,7 +273,23 @@ int32_t filterFinMergeRange(void* h) { } if (MR_GET_FLAG(ctx->options, MR_OPT_TS)) { - + SFilterRangeNode *r = ctx->rs; + SFilterRangeNode *rn = NULL; + + while (r && r->next) { + int64_t tmp = 1; + operateVal(&tmp, &r->e, &tmp, TSDB_BINARY_OP_ADD, ctx->type); + if (ctx->pCompareFunc(&tmp, &r->next->s) == 0) { + rn = r->next; + SIMPLE_COPY_VALUES((char *)&r->next->s, (char *)&r->s); + FREE_RANGE(ctx, r); + r = rn; + + continue; + } + + r = r->next; + } } MR_SET_FLAG(ctx->status, MR_ST_FIN); @@ -196,7 +304,7 @@ int32_t filterGetMergeRangeNum(void* h, int32_t* num) { *num = 0; - SFilterRange *r = ctx->rs; + SFilterRangeNode *r = ctx->rs; while (r) { ++(*num); @@ -212,7 +320,7 @@ int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; uint32_t num = 0; - SFilterRange* r = ctx->rs; + SFilterRangeNode* r = ctx->rs; while (r) { assignVal(s + num * tDataTypes[ctx->type].bytes, (char *)&r->s, 0, ctx->type); @@ -231,9 +339,13 @@ int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { } int32_t filterFreeMergeRange(void* h) { + if (h == NULL) { + return TSDB_CODE_SUCCESS; + } + SFilterRMCtx *ctx = (SFilterRMCtx *)h; - SFilterRange *r = ctx->rs; - SFilterRange *rn = NULL; + SFilterRangeNode *r = ctx->rs; + SFilterRangeNode *rn = NULL; while (r) { rn = r->next; @@ -299,7 +411,7 @@ int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) { CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node"); - CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType"); + CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType:%d", node->nodeType); int32_t type, idx = -1; uint16_t *num; @@ -308,9 +420,11 @@ int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) if (node->nodeType == TSQL_NODE_COL) { type = F_FIELD_COLUMN; v = node->pSchema; + node->pSchema = NULL; } else { type = F_FIELD_VALUE; v = node->pVal; + node->pVal = NULL; } num = &info->fields[type].num; @@ -422,7 +536,7 @@ _err_return: int32_t filterInitUnitFunc(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; - SFilterField *left = FILTER_GET_FIELD(info, unit->left); + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); unit->compare.pCompareFunc = getComparFunc(FILTER_GET_COL_FIELD_TYPE(left), unit->compare.optr); } @@ -432,18 +546,18 @@ int32_t filterInitUnitFunc(SFilterInfo *info) { -void filterDumpInfoToString(SFilterInfo *info) { - CHK_LRETV(info == NULL, "FilterInfo: empty"); +void filterDumpInfoToString(SFilterInfo *info, const char *msg) { + CHK_LRETV(info == NULL, "%s - FilterInfo: empty", msg); - qDebug("FilterInfo:"); - qDebug("Field Col Num:%u", info->fields[F_FIELD_COLUMN].num); + qDebug("%s - FilterInfo:", msg); + qDebug("COLUMN Field Num:%u", info->fields[F_FIELD_COLUMN].num); for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { SFilterField *field = &info->fields[F_FIELD_COLUMN].fields[i]; SSchema *sch = field->desc; qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); } - qDebug("Field Val Num:%u", info->fields[F_FIELD_VALUE].num); + qDebug("VALUE Field Num:%u", info->fields[F_FIELD_VALUE].num); for (uint16_t i = 0; i < info->fields[F_FIELD_VALUE].num; ++i) { SFilterField *field = &info->fields[F_FIELD_VALUE].fields[i]; tVariant *var = field->desc; @@ -453,8 +567,8 @@ void filterDumpInfoToString(SFilterInfo *info) { qDebug("Unit Num:%u", info->unitNum); for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; - SFilterField *left = FILTER_GET_FIELD(info, unit->left); - SFilterField *right = FILTER_GET_FIELD(info, unit->right); + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info); + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); SSchema *sch = left->desc; tVariant *var = right->desc; @@ -478,27 +592,13 @@ void filterFreeInfo(SFilterInfo *info) { //TODO } -int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { - CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); - CHK_LRET(info->fields[F_FIELD_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); - for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { - SFilterField* fi = &info->fields[F_FIELD_COLUMN].fields[i]; - SSchema* sch = fi->desc; - if (sch->colId == colId) { - fi->data = data; - break; - } - } - - return TSDB_CODE_SUCCESS; -} int32_t filterInitValFieldData(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; - SFilterField* left = FILTER_GET_FIELD(info, unit->left); - SFilterField* right = FILTER_GET_FIELD(info, unit->right); + SFilterField* left = FILTER_UNIT_LEFT_FIELD(info, unit); + SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); if (left->type != F_FIELD_VALUE && right->type != F_FIELD_VALUE) { continue; @@ -531,7 +631,17 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } else if (type == TSDB_DATA_TYPE_NCHAR) { fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); } else { - fi->data = calloc(1, sizeof(int64_t)); + if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + fi->data = calloc(var->nLen, tDataTypes[type].bytes); + for (int32_t a = 0; a < var->nLen; ++a) { + int64_t *v = taosArrayGet(var->arr, a); + assignVal(fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); + } + + continue; + } else { + fi->data = calloc(1, sizeof(int64_t)); + } } ERR_LRET(tVariantDump(var, (char*)fi->data, type, true), "dump type[%d] failed", type); @@ -579,6 +689,197 @@ bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { } +#if 0 +int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, int32_t optr) { + int32_t type = FILTER_UNIT_DATA_TYPE(info, u); + uint8_t uoptr = FILTER_UNIT_OPTR(u); + void *val = FILTER_UNIT_VAL(info, u); + int64_t s = 0, e = 0; + + switch (uoptr) { + case TSDB_RELATION_GREATER: + + break; + case TSDB_RELATION_GREATER_EQUAL: + case TSDB_RELATION_LESS: + case TSDB_RELATION_LESS_EQUAL: + case TSDB_RELATION_NOT_EQUAL: + case TSDB_RELATION_EQUAL: + case TSDB_RELATION_IN: + default: + assert(0); + } + + filterAddMergeRange(ctx, &s, &e, optr); + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterMergeSingleGroupUnits(SFilterInfo *info, SFilterGroup* g, uint16_t id1, uint16_t id2, SArray* res) { + bool isnull = false, notnull = false; + int32_t num = 0; + + SFilterRMCtx *cur = filterInitMergeRange(type, 0); + + SFilterUnit* u1 = FILTER_GROUP_UNIT(info, g, id1); + SFilterUnit* u2 = FILTER_GROUP_UNIT(info, g, id2); + uint8_t optr1 = FILTER_UNIT_OPTR(u1); + uint8_t optr2 = FILTER_UNIT_OPTR(u2); + uint16_t cidx = FILTER_UNIT_COL_IDX(u1); + + int32_t type = FILTER_UNIT_DATA_TYPE(info, u1); + +#define SET_OPTR(o) ((o == TSDB_RELATION_ISNULL) ? isnull = true : notnull = true) +#define CHK_OPTR() (isnull == true && notnull == true) + + SET_OPTR(optr1); + SET_OPTR(optr2); + + CHK_JMP(CHK_OPTR()); + + if (!FILTER_NO_MERGE_OPTR(optr1)) { + filterAddUnitRange(info, u1, cur, TSDB_RELATION_AND); + } + + if (!FILTER_NO_MERGE_OPTR(optr2)) { + filterAddUnitRange(info, u2, cur, TSDB_RELATION_AND); + CHK_JMP(MR_EMPTY_RES(cur)); + } + + + for (int32_t i = id2 + 1; i < g->unitNum; ++i) { + SFilterUnit* u = FILTER_GROUP_UNIT(info, g, i); + if (cidx != FILTER_UNIT_COL_IDX(u)) { + continue; + } + + optr2 = FILTER_UNIT_OPTR(u); + SET_OPTR(optr2); + CHK_JMP(CHK_OPTR()); + + if (!FILTER_NO_MERGE_OPTR(optr2)) { + filterAddUnitRange(info, u2, cur, TSDB_RELATION_AND); + CHK_JMP(MR_EMPTY_RES(cur)); + } + } + + SFilterColRange ra; + ra.idx = cidx; + + filterGetMergeRangeNum(cur, &num); + assert(num == 1); + + filterGetMergeRangeRes(cur, &ra.s, &ra.e); + + taosArrayPush(res, &ra); + + filterFreeMergeRange(cur); + + return TSDB_CODE_SUCCESS; + +_err_return: + + g->unitNum = 0; + + filterFreeMergeRange(cur); + + return TSDB_CODE_SUCCESS; + +} + +int32_t filterMergeGroupUnits(SFilterInfo *info, SArray** res) { + uint16_t *f = malloc(1, info->fields[F_FIELD_COLUMN].num * sizeof(uint16_t)); + SArray *gres = NULL; + bool gresUsed = false; + + for (uint16_t i = 0; i < info->groupNum; ++i) { + SFilterGroup* g = info->groups + i; + + memet(f, -1, info->fields[F_FIELD_COLUMN].num); + + gresUsed = false; + + for (uint16_t j = 0; j < g->unitNum; ++j) { + SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); + int32_t type = FILTER_UNIT_DATA_TYPE(info, u); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + continue; + } + + uint16_t cidx = FILTER_UNIT_COL_IDX(u); + + if (f[cidx] == -1) { + f[u->left.idx] = j; + } else if (cidx] == -2) { + continue; + } else { + f[cidx] = -2; + + if (gres == NULL) { + gres = taosArrayInit(4, sizeof(SFilterColRange)); + } + + filterMergeSingleGroupUnits(info, g, f[cidx], j, gres); + if (g->unitNum == 0) { + break; + } else { + gresUsed = true; + } + } + } + + if (g->unitNum == 0) { + if (gresUsed) { + taosArrayClear(gres); + } + + continue; + } + + if (res == NULL) { + res = calloc(info->groupNum, sizeof(SArray *)); + res[i] = gres; + gres = NULL; + } + } + + free(f); + if (gres) { + taosArrayDestroy(gres); + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterPreprocess(SFilterInfo *info) { + SArray* res = NULL; + + filterMergeGroupUnits(info, &res); + + +} + +#endif + +int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { + CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); + CHK_LRET(info->fields[F_FIELD_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); + + for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[F_FIELD_COLUMN].fields[i]; + SSchema* sch = fi->desc; + if (sch->colId == colId) { + fi->data = data; + break; + } + } + + return TSDB_CODE_SUCCESS; +} + + bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { bool all = true; @@ -599,8 +900,8 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { ures = FILTER_UNIT_GET_R(info, uidx); } else { SFilterUnit *unit = &info->units[uidx]; - SFilterField *left = FILTER_GET_FIELD(info, unit->left); - SFilterField *right = FILTER_GET_FIELD(info, unit->right); + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info); + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); if (isNull(FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_COL_FIELD_TYPE(left))) { ures = unit->compare.optr == TSDB_RELATION_ISNULL ? true : false; @@ -659,7 +960,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { info->fields[F_FIELD_COLUMN].num = 0; info->fields[F_FIELD_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, sizeof(SFilterField)); + info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, COL_FIELD_SIZE); info->fields[F_FIELD_VALUE].num = 0; info->fields[F_FIELD_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; info->fields[F_FIELD_VALUE].fields = calloc(info->fields[F_FIELD_VALUE].size, sizeof(SFilterField)); @@ -678,17 +979,22 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { for (size_t i = 0; i < groupSize; ++i) { SFilterGroup *pg = taosArrayGet(group, i); + pg->unitFlags = calloc(pg->unitNum, sizeof(*pg->unitFlags)); info->groups[i] = *pg; } - ERR_JRET(filterInitUnitFunc(info)); - ERR_JRET(filterInitValFieldData(info)); + filterDumpInfoToString(info, "Before preprocess"); + + //ERR_JRET(filterPreprocess(info)); + + ERR_JRET(filterInitUnitFunc(info)); + info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); - filterDumpInfoToString(info); + filterDumpInfoToString(info, "Final"); _err_return: @@ -697,4 +1003,68 @@ _err_return: return code; } +int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { + SFilterRange ra = {0}; + SFilterRMCtx *prev = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, MR_OPT_TS); + SFilterRMCtx *tmpc = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, MR_OPT_TS); + SFilterRMCtx *cur = NULL; + int32_t num = 0; + int32_t optr = 0; + int32_t code = 0; + + for (int32_t i = 0; i < info->groupNum; ++i) { + SFilterGroup *group = &info->groups[i]; + if (group->unitNum > 1) { + cur = tmpc; + optr = TSDB_RELATION_AND; + } else { + cur = prev; + optr = TSDB_RELATION_OR; + } + + for (int32_t u = 0; u < group->unitNum; ++u) { + uint16_t uidx = group->unitIdxs[u]; + SFilterUnit *unit = &info->units[uidx]; + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); + void *s = FILTER_GET_VAL_FIELD_DATA(right); + void *e = FILTER_GET_VAL_FIELD_DATA(right) + tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; + + SIMPLE_COPY_VALUES(&ra.s, s); + SIMPLE_COPY_VALUES(&ra.e, e); + + code = filterAddMergeRange(cur, &ra, optr); + if (code) { + break; + } + } + + if (code != TSDB_CODE_SUCCESS) { + break; + } + + if (group->unitNum > 1) { + filterAddMergeRangeCtx(prev, cur, TSDB_RELATION_OR); + filterResetMergeRangeCtx(cur); + } + } + + if (code == TSDB_CODE_SUCCESS) { + filterGetMergeRangeNum(prev, &num); + if (num != 1) { + qError("only one time range accepted, num:%d", num); + ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); + } + + filterGetMergeRangeRes(prev, &win->skey, &win->ekey); + } + +_err_return: + + filterFreeMergeRange(prev); + filterFreeMergeRange(tmpc); + + return code; +} + + diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index a2cb7aee00..7052e8e38b 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -401,6 +401,9 @@ tSqlExpr *tSqlExprClone(tSqlExpr *pSrc) { pExpr->pRight = tSqlExprClone(pSrc->pRight); } + memset(&pExpr->value, 0, sizeof(pExpr->value)); + tVariantAssign(&pExpr->value, &pSrc->value); + //we don't clone pParam now because clone is only used for between/and assert(pSrc->pParam == NULL); return pExpr; diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index ef18575371..6726cf7055 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -188,6 +188,8 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi taosArrayDestroy(param.pGroupbyExpr->columnInfo); } + tfree(param.colCond); + taosArrayDestroy(param.pTableIdList); param.pTableIdList = NULL; diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index b64c1a7494..100afd4705 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -14,81 +14,100 @@ namespace { void intDataTest() { printf("running %s\n", __FUNCTION__); - int32_t s0[3] = {-100, 1, 3}; - int32_t e0[3] = {0 , 2, 4}; + int32_t asize = 0; + int64_t *s =NULL; + int64_t *e =NULL; + int64_t s0[3] = {-100, 1, 3}; + int64_t e0[3] = {0 , 2, 4}; int64_t s1[3] = {INT64_MIN, 0 , 3}; int64_t e1[3] = {100 , 50, 4}; int64_t s2[5] = {1 , 3 , 10,30,70}; int64_t e2[5] = {10, 100, 20,50,120}; int64_t s3[3] = {1 , 20 , 5}; int64_t e3[3] = {10, 100, 25}; + int64_t s4[2] = {10, 0}; + int64_t e4[2] = {20, 5}; + int64_t s5[3] = {0, 6 ,7}; + int64_t e5[5] = {4, 10,20}; - int32_t rs0[3]; - int32_t re0[3]; - int64_t rs1[3]; - int64_t re1[3]; - int64_t rs2[5]; - int64_t re2[5]; - int64_t rs3[5]; - int64_t re3[5]; + int64_t rs[10]; + int64_t re[10]; int32_t num = 0; - - void *h = filterInitMergeRange(TSDB_DATA_TYPE_INT, 0); - for (int32_t i = 0; i < sizeof(s0)/sizeof(s0[0]); ++i) { - filterAddMergeRange(h, s0 + i, e0 + i, TSDB_RELATION_AND); + + s = s0; + e = e0; + asize = sizeof(s0)/sizeof(s[0]); + void *h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); - - h = filterInitMergeRange(TSDB_DATA_TYPE_INT, 0); - for (int32_t i = 0; i < sizeof(s0)/sizeof(s0[0]); ++i) { - filterAddMergeRange(h, s0 + i, e0 + i, TSDB_RELATION_OR); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 3); - filterGetMergeRangeRes(h, rs0, re0); - ASSERT_EQ(rs0[0], -100); - ASSERT_EQ(re0[0], 0); - ASSERT_EQ(rs0[1], 1); - ASSERT_EQ(re0[1], 2); - ASSERT_EQ(rs0[2], 3); - ASSERT_EQ(re0[2], 4); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], -100); + ASSERT_EQ(re[0], 0); + ASSERT_EQ(rs[1], 1); + ASSERT_EQ(re[1], 2); + ASSERT_EQ(rs[2], 3); + ASSERT_EQ(re[2], 4); filterFreeMergeRange(h); - - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s1)/sizeof(s1[0]); ++i) { - filterAddMergeRange(h, s1 + i, e1 + i, TSDB_RELATION_AND); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, MR_OPT_TS); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs1, re1); - ASSERT_EQ(rs1[0], 3); - ASSERT_EQ(re1[0], 4); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], -100); + ASSERT_EQ(re[0], 4); filterFreeMergeRange(h); + s = s1; + e = e1; + asize = sizeof(s1)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s1)/sizeof(s1[0]); ++i) { - filterAddMergeRange(h, s1 + i, e1 + i, TSDB_RELATION_OR); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs1, re1); - ASSERT_EQ(rs1[0], INT64_MIN); - ASSERT_EQ(re1[0], 100); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 3); + ASSERT_EQ(re[0], 4); filterFreeMergeRange(h); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { - filterAddMergeRange(h, s2 + i, e2 + i, TSDB_RELATION_AND); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], INT64_MIN); + ASSERT_EQ(re[0], 100); + filterFreeMergeRange(h); + + + s = s2; + e = e2; + asize = sizeof(s2)/sizeof(s[0]); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -96,21 +115,21 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { - filterAddMergeRange(h, s2 + i, e2 + i, TSDB_RELATION_OR); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs2, re2); - ASSERT_EQ(rs2[0], 1); - ASSERT_EQ(re2[0], 120); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 1); + ASSERT_EQ(re[0], 120); filterFreeMergeRange(h); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { - filterAddMergeRange(h, s2 + i, e2 + i, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -118,21 +137,23 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s2)/sizeof(s2[0]); ++i) { - filterAddMergeRange(h, s2 + i, e2 + i, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs2, re2); - ASSERT_EQ(rs2[0], 70); - ASSERT_EQ(re2[0], 120); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 70); + ASSERT_EQ(re[0], 120); filterFreeMergeRange(h); - + s = s3; + e = e3; + asize = sizeof(s3)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s3)/sizeof(s3[0]); ++i) { - filterAddMergeRange(h, s3 + i, e3 + i, TSDB_RELATION_AND); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -140,18 +161,83 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); - for (int32_t i = 0; i < sizeof(s3)/sizeof(s3[0]); ++i) { - filterAddMergeRange(h, s3 + i, e3 + i, TSDB_RELATION_OR); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs3, re3); - ASSERT_EQ(rs3[0], 1); - ASSERT_EQ(re3[0], 100); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 1); + ASSERT_EQ(re[0], 100); filterFreeMergeRange(h); + + s = s4; + e = e4; + asize = sizeof(s4)/sizeof(s[0]); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 2); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 0); + ASSERT_EQ(re[0], 5); + ASSERT_EQ(rs[1], 10); + ASSERT_EQ(re[1], 20); + filterFreeMergeRange(h); + + + s = s5; + e = e5; + asize = sizeof(s5)/sizeof(s[0]); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 2); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 0); + ASSERT_EQ(re[0], 4); + ASSERT_EQ(rs[1], 6); + ASSERT_EQ(re[1], 20); + filterFreeMergeRange(h); + + + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + filterAddMergeRange(h, s + i, e + i, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 1); + filterGetMergeRangeRes(h, rs, re); + ASSERT_EQ(rs[0], 7); + ASSERT_EQ(re[0], 10); + filterFreeMergeRange(h); + + } diff --git a/src/util/src/terror.c b/src/util/src/terror.c index 1d37a6e9a4..4705110ca6 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -268,6 +268,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_IN_EXEC, "Multiple retrieval of TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW, "Too many time window in query") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NOT_ENOUGH_BUFFER, "Query buffer limit has reached") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, "File inconsistance in replica") +TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_TIME_CONDITION, "One valid time range condition expected") // grant diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 62d1fc03fa..52918a8658 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1527,12 +1527,109 @@ sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; sql_error select * from stb1 where ts2 like '2021-05-05%'; +sql_error select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; +sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); +sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; +sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; -if $rows != 0 then +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; +if $rows != 29 then return -1 endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:28.000'; +if $rows != 29 then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts > '2021-05-05 18:19:27.000'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000' or ts != '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts <> '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.999') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.999')); +if $rows != 16 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:12.000' and ts <= '2021-05-05 18:19:14.000') or (ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:17.000'); +if $rows != 13 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:01.000' and ts <= '2021-05-05 18:19:08.000'); +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:06.000') or (ts >= '2021-05-05 18:19:03.000' and ts <= '2021-05-05 18:19:12.000')) and (ts >= '2021-05-05 18:19:10.000'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + +sql select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:25.000' and ts != '2021-05-05 18:19:18'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + + sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; if $rows != 3 then return -1 @@ -1858,6 +1955,20 @@ if $data00 != @21-05-05 18:19:21.000@ then return -1 endi +sql select * from stb1 where c1!=31 and c1 !=32 and c1 <> 63 and c1 <>1 and c1 <> 21 and c1 <> 2 and c7 <> true and c8 <> '3' and c9 <> '4' and c2<>13 and c3 <> 23 and c4 <> 33 and c5 <> 34 and c6 <> 43 and c2 <> 53 and t1 <> 5 and t2 <>4; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + print "column&join test" sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; From 014740decf449e43de4f18fe00752bd73bdb29d9 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 5 Jul 2021 08:52:34 +0800 Subject: [PATCH 016/100] add unit test --- src/common/src/ttypes.c | 26 ++++++++ src/inc/ttype.h | 2 + src/query/inc/qFilter.h | 1 - src/query/src/qFilter.c | 95 +++++++++++++++--------------- src/query/tests/rangeMergeTest.cpp | 85 +++++++++++++++++++++----- 5 files changed, 145 insertions(+), 64 deletions(-) diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 057697fab2..991f2fc67b 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -401,6 +401,32 @@ char tTokenTypeSwitcher[13] = { TSDB_DATA_TYPE_NCHAR, // TK_NCHAR }; +float floatMin = -FLT_MAX, floatMax = FLT_MAX; +double doubleMin = -DBL_MAX, doubleMax = DBL_MAX; + +FORCE_INLINE void* getDataMin(int32_t type) { + switch (type) { + case TSDB_DATA_TYPE_FLOAT: + return &floatMin; + case TSDB_DATA_TYPE_DOUBLE: + return &doubleMin; + default: + return &tDataTypes[type].minValue; + } +} + +FORCE_INLINE void* getDataMax(int32_t type) { + switch (type) { + case TSDB_DATA_TYPE_FLOAT: + return &floatMax; + case TSDB_DATA_TYPE_DOUBLE: + return &doubleMax; + default: + return &tDataTypes[type].maxValue; + } +} + + bool isValidDataType(int32_t type) { return type >= TSDB_DATA_TYPE_NULL && type <= TSDB_DATA_TYPE_UBIGINT; } diff --git a/src/inc/ttype.h b/src/inc/ttype.h index fe19076252..32fd5ca7df 100644 --- a/src/inc/ttype.h +++ b/src/inc/ttype.h @@ -184,6 +184,8 @@ void *getNullValue(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* buf); void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type); +void* getDataMin(int32_t type); +void* getDataMax(int32_t type); int32_t tStrToInteger(const char* z, int16_t type, int32_t n, int64_t* value, bool issigned); diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 78c1c1d9db..e570623ba1 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -181,7 +181,6 @@ extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); extern void* filterInitMergeRange(int32_t type, int32_t options); -extern int32_t filterAddMergeRange(void* h, void* s, void* e, int32_t optr); extern int32_t filterGetMergeRangeNum(void* h, int32_t* num); extern int32_t filterGetMergeRangeRes(void* h, void *s, void* e); extern int32_t filterFreeMergeRange(void* h); diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 56a53ebd50..f5a04b46e0 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -66,8 +66,8 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, int32_t r = calloc(1, sizeof(SFilterRangeNode)); } - SIMPLE_COPY_VALUES((char*)&r->s, s); - SIMPLE_COPY_VALUES((char*)&r->e, e); + SIMPLE_COPY_VALUES((char*)&r->ra.s, s); + SIMPLE_COPY_VALUES((char*)&r->ra.e, e); return r; } @@ -87,23 +87,6 @@ void* filterInitMergeRange(int32_t type, int32_t options) { return ctx; } -int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { - SFilterRMCtx *dctx = (SFilterRMCtx *)dst; - SFilterRMCtx *sctx = (SFilterRMCtx *)src; - - if (sctx->rs == NULL) { - return TSDB_CODE_SUCCESS; - } - - SFilterRangeNode *r = sctx->rs; - - while (r) { - filterAddMergeRange(dctx, &r->s, &r->e, optr); - r = r->next; - } - - return TSDB_CODE_SUCCESS; -} int32_t filterResetMergeRangeCtx(SFilterRMCtx *ctx) { ctx->status = 0; @@ -154,24 +137,24 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla if (optr == TSDB_RELATION_AND) { while (r != NULL) { - if (ctx->pCompareFunc(&r->s, e) > 0) { + if (ctx->pCompareFunc(&r->ra.s, e) > 0) { FREE_FROM_RANGE(ctx, r); break; } - if (ctx->pCompareFunc(s, &r->e) > 0) { + if (ctx->pCompareFunc(s, &r->ra.e) > 0) { rn = r->next; FREE_RANGE(ctx, r); r = rn; continue; } - if (ctx->pCompareFunc(s, &r->s) > 0) { - SIMPLE_COPY_VALUES((char *)&r->s, s); + if (ctx->pCompareFunc(s, &r->ra.s) > 0) { + SIMPLE_COPY_VALUES((char *)&r->ra.s, s); } - if (ctx->pCompareFunc(&r->e, e) > 0) { - SIMPLE_COPY_VALUES((char *)&r->e, e); + if (ctx->pCompareFunc(&r->ra.e, e) > 0) { + SIMPLE_COPY_VALUES((char *)&r->ra.e, e); break; } @@ -187,7 +170,7 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla bool emerged = false; while (r != NULL) { - if (ctx->pCompareFunc(&r->s, e) > 0) { + if (ctx->pCompareFunc(&r->ra.s, e) > 0) { if (emerged == false) { INSERT_RANGE(ctx, r, ctx->type, s, e); } @@ -195,7 +178,7 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla break; } - if (ctx->pCompareFunc(s, &r->e) > 0) { + if (ctx->pCompareFunc(s, &r->ra.e) > 0) { if (r->next) { r= r->next; continue; @@ -206,18 +189,18 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla } if (smerged == false) { - if (ctx->pCompareFunc(&r->s, s) > 0) { - SIMPLE_COPY_VALUES((char *)&r->s, s); + if (ctx->pCompareFunc(&r->ra.s, s) > 0) { + SIMPLE_COPY_VALUES((char *)&r->ra.s, s); } smerged = true; } if (emerged == false) { - if (ctx->pCompareFunc(e, &r->e) > 0) { - SIMPLE_COPY_VALUES((char *)&r->e, e); + if (ctx->pCompareFunc(e, &r->ra.e) > 0) { + SIMPLE_COPY_VALUES((char *)&r->ra.e, e); emerged = true; - e = &r->e; + e = &r->ra.e; r = r->next; continue; } @@ -225,14 +208,14 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla break; } - if (ctx->pCompareFunc(e, &r->e) > 0) { + if (ctx->pCompareFunc(e, &r->ra.e) > 0) { rn = r->next; FREE_RANGE(ctx, r); r = rn; continue; } else { - SIMPLE_COPY_VALUES(e, (char *)&r->e); + SIMPLE_COPY_VALUES(e, (char *)&r->ra.e); FREE_RANGE(ctx, r); break; @@ -246,25 +229,43 @@ int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; int64_t sv, ev; void *s, *e; - char sflag = 0, eflag = 0; if (MR_GET_FLAG(ra->sflag, RA_NULL)) { - SIMPLE_COPY_VALUES(&sv, &tDataTypes[ctx->type].minValue); + SIMPLE_COPY_VALUES(&sv, getDataMin(ctx->type)); s = &sv; } else { - s = &ra.s; + s = &ra->s; } if (MR_GET_FLAG(ra->eflag, RA_NULL)) { - SIMPLE_COPY_VALUES(&ev, &tDataTypes[ctx->type].maxValue); + SIMPLE_COPY_VALUES(&ev, getDataMax(ctx->type)); e = &ev; } else { - e = &ra.e; + e = &ra->e; } - return filterAddMergeRangeImpl(h, s, e, ra.sflag, ra.eflag, optr); + return filterAddMergeRangeImpl(h, s, e, ra->sflag, ra->eflag, optr); } +int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { + SFilterRMCtx *dctx = (SFilterRMCtx *)dst; + SFilterRMCtx *sctx = (SFilterRMCtx *)src; + + if (sctx->rs == NULL) { + return TSDB_CODE_SUCCESS; + } + + SFilterRangeNode *r = sctx->rs; + + while (r) { + filterAddMergeRange(dctx, &r->ra, optr); + r = r->next; + } + + return TSDB_CODE_SUCCESS; +} + + int32_t filterFinMergeRange(void* h) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; @@ -278,10 +279,10 @@ int32_t filterFinMergeRange(void* h) { while (r && r->next) { int64_t tmp = 1; - operateVal(&tmp, &r->e, &tmp, TSDB_BINARY_OP_ADD, ctx->type); - if (ctx->pCompareFunc(&tmp, &r->next->s) == 0) { + operateVal(&tmp, &r->ra.e, &tmp, TSDB_BINARY_OP_ADD, ctx->type); + if (ctx->pCompareFunc(&tmp, &r->next->ra.s) == 0) { rn = r->next; - SIMPLE_COPY_VALUES((char *)&r->next->s, (char *)&r->s); + SIMPLE_COPY_VALUES((char *)&r->next->ra.s, (char *)&r->ra.s); FREE_RANGE(ctx, r); r = rn; @@ -323,8 +324,8 @@ int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { SFilterRangeNode* r = ctx->rs; while (r) { - assignVal(s + num * tDataTypes[ctx->type].bytes, (char *)&r->s, 0, ctx->type); - assignVal(e + num * tDataTypes[ctx->type].bytes, (char *)&r->e, 0, ctx->type); + assignVal(s + num * tDataTypes[ctx->type].bytes, (char *)&r->ra.s, 0, ctx->type); + assignVal(e + num * tDataTypes[ctx->type].bytes, (char *)&r->ra.e, 0, ctx->type); ++num; r = r->next; @@ -567,7 +568,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { qDebug("Unit Num:%u", info->unitNum); for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; - SFilterField *left = FILTER_UNIT_LEFT_FIELD(info); + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); SSchema *sch = left->desc; @@ -900,7 +901,7 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { ures = FILTER_UNIT_GET_R(info, uidx); } else { SFilterUnit *unit = &info->units[uidx]; - SFilterField *left = FILTER_UNIT_LEFT_FIELD(info); + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); if (isNull(FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_COL_FIELD_TYPE(left))) { diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index 100afd4705..202394e943 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -10,11 +10,17 @@ #pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-variable" +extern "C" { + extern int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr); +} + namespace { + void intDataTest() { printf("running %s\n", __FUNCTION__); int32_t asize = 0; + SFilterRange ra = {0}; int64_t *s =NULL; int64_t *e =NULL; int64_t s0[3] = {-100, 1, 3}; @@ -40,7 +46,9 @@ void intDataTest() { asize = sizeof(s0)/sizeof(s[0]); void *h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -49,7 +57,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 3); @@ -65,7 +76,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, MR_OPT_TS); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -80,7 +94,10 @@ void intDataTest() { asize = sizeof(s1)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -92,7 +109,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -107,7 +127,10 @@ void intDataTest() { asize = sizeof(s2)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -116,7 +139,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -129,7 +155,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -138,7 +167,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -153,7 +185,10 @@ void intDataTest() { asize = sizeof(s3)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -162,7 +197,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); @@ -179,7 +217,10 @@ void intDataTest() { asize = sizeof(s4)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -188,7 +229,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 2); @@ -205,7 +249,10 @@ void intDataTest() { asize = sizeof(s5)/sizeof(s[0]); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_AND); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); @@ -214,7 +261,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 2); @@ -228,7 +278,10 @@ void intDataTest() { h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - filterAddMergeRange(h, s + i, e + i, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); + ra.s = s[i]; + ra.e = e[i]; + + filterAddMergeRange(h, &ra, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); From 69f25dbfc1c223d6f1ea21e01d360a780f30f896 Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 9 Jul 2021 11:35:24 +0800 Subject: [PATCH 017/100] support condition rewrite --- src/client/src/tscSQLParser.c | 2 +- src/client/src/tscUtil.c | 16 + src/query/inc/qFilter.h | 80 ++- src/query/src/qExecutor.c | 2 +- src/query/src/qFilter.c | 1061 ++++++++++++++++++++++------ src/query/tests/rangeMergeTest.cpp | 243 ++++--- src/util/inc/hash.h | 4 +- src/util/src/hash.c | 4 + src/util/src/tcompare.c | 6 +- 9 files changed, 1091 insertions(+), 327 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 061ba7653b..92ebc8fbaa 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5006,7 +5006,7 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr goto _ret; } - ret = filterInitFromTree(p, &filter); + ret = filterInitFromTree(p, &filter, FILTER_NO_REWRITE); if (ret != TSDB_CODE_SUCCESS) { goto _ret; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index a6a25269fc..f7bb4fa1bf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -81,7 +81,23 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le *(str + bufSize + 1) = '"'; n = bufSize + 2; break; + + case TSDB_DATA_TYPE_UTINYINT: + n = sprintf(str, "%d", *(uint8_t*)buf); + break; + case TSDB_DATA_TYPE_USMALLINT: + n = sprintf(str, "%d", *(uint16_t*)buf); + break; + + case TSDB_DATA_TYPE_UINT: + n = sprintf(str, "%u", *(uint32_t*)buf); + break; + + case TSDB_DATA_TYPE_UBIGINT: + n = sprintf(str, "%" PRIu64, *(uint64_t*)buf); + break; + default: tscError("unsupported type:%d", type); return TSDB_CODE_TSC_INVALID_VALUE; diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index e570623ba1..092d244e24 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -22,19 +22,24 @@ extern "C" { #include "texpr.h" +#define FILTER_DEFAULT_GROUP_SIZE 4 #define FILTER_DEFAULT_UNIT_SIZE 4 #define FILTER_DEFAULT_FIELD_SIZE 4 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 enum { - F_FIELD_COLUMN = 0, - F_FIELD_VALUE, - F_FIELD_MAX + FLD_TYPE_COLUMN = 1, + FLD_TYPE_VALUE = 2, + FLD_TYPE_MAX = 3, + FLD_DESC_NO_FREE = 4, + FLD_DATA_NO_FREE = 8, }; enum { MR_ST_START = 1, MR_ST_FIN = 2, + MR_ALL = 4, + MR_NONE = 8, }; enum { @@ -46,17 +51,17 @@ enum { RA_NULL = 2, }; +enum { + FILTER_ALL = 1, + FILTER_NONE = 2, + FILTER_NO_REWRITE = 4, +}; + typedef struct OptrStr { uint16_t optr; char *str; } OptrStr; -typedef struct SFilterColRange { - uint16_t idx; //column field idx - int64_t s; - int64_t e; -} SFilterColRange; - typedef struct SFilterRange { char sflag; char eflag; @@ -64,6 +69,13 @@ typedef struct SFilterRange { int64_t e; } SFilterRange; +typedef struct SFilterColRange { + uint16_t idx; //column field idx + bool isNull; + bool notNull; + SFilterRange ra; +} SFilterColRange; + typedef struct SFilterRangeNode { struct SFilterRangeNode* prev; @@ -81,7 +93,7 @@ typedef struct SFilterRMCtx { } SFilterRMCtx ; typedef struct SFilterField { - uint16_t type; + uint16_t flag; void* desc; void* data; int64_t range[]; @@ -99,13 +111,21 @@ typedef struct SFilterFieldId { } SFilterFieldId; typedef struct SFilterGroup { + uint16_t unitSize; uint16_t unitNum; uint16_t *unitIdxs; uint8_t *unitFlags; // !unit result } SFilterGroup; +typedef struct SFilterGroupCtx { + uint16_t num; + int32_t *col; + SArray *colRange; +} SFilterGroupCtx; + typedef struct SFilterCompare { __compar_fn_t pCompareFunc; + int32_t type; uint8_t optr; } SFilterCompare; @@ -116,10 +136,11 @@ typedef struct SFilterUnit { } SFilterUnit; typedef struct SFilterInfo { + uint32_t flags; uint16_t unitSize; uint16_t unitNum; uint16_t groupNum; - SFilterFields fields[F_FIELD_MAX]; + SFilterFields fields[FLD_TYPE_MAX]; SFilterGroup *groups; SFilterUnit *units; uint8_t *unitRes; // result @@ -133,16 +154,24 @@ typedef struct SFilterInfo { #define MR_EMPTY_RES(ctx) (ctx->rs == NULL) -#define MR_GET_FLAG(st, f) (st & f) -#define MR_SET_FLAG(st, f) st |= (f) +#define SET_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { notnull = true; } } while (0) +#define CHK_OPTR() (isnull == true && notnull == true) + + +#define FILTER_GET_FLAG(st, f) (st & f) +#define FILTER_SET_FLAG(st, f) st |= (f) +#define FILTER_CLR_FLAG(st, f) st &= (~f) #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) -#define RESET_RANGE(ctx, r) do { r->next = ctx->rf; ctx->rf = r; } while (0) -#define FREE_RANGE(ctx, r) do { if (r->prev) { r->prev->next = r->next; } else { ctx->rs = r->next;} if (r->next) { r->next->prev = r->prev; } RESET_RANGE(ctx, r); } while (0) -#define FREE_FROM_RANGE(ctx, r) do { if (r->prev) { r->prev->next = NULL; } else { ctx->rs = NULL;} while (r) {SFilterRangeNode *n = r->next; RESET_RANGE(ctx, r); r = n; } } while (0) -#define INSERT_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r->prev; if (r->prev) { r->prev->next = n; } else { ctx->rs = n; } r->prev = n; n->next = r; } while (0) -#define APPEND_RANGE(ctx, r, t, s, e) do { SFilterRangeNode *n = filterNewRange(ctx, t, s, e); n->prev = r; if (r) { r->next = n; } else { ctx->rs = n; } } while (0) +#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RA_EXCLUDE) || FILTER_GET_FLAG(eflag,RA_EXCLUDE)))) +#define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) + +#define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) +#define FREE_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = (r)->next; } else { (ctx)->rs = (r)->next;} if ((r)->next) { (r)->next->prev = (r)->prev; } RESET_RANGE(ctx, r); } while (0) +#define FREE_FROM_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (r) {SFilterRangeNode *n = (r)->next; RESET_RANGE(ctx, r); r = n; } } while (0) +#define INSERT_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r)->prev; if ((r)->prev) { (r)->prev->next = n; } else { (ctx)->rs = n; } (r)->prev = n; n->next = r; } while (0) +#define APPEND_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r); if (r) { (r)->next = n; } else { (ctx)->rs = n; } } while (0) #define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0) #define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0) @@ -155,16 +184,21 @@ typedef struct SFilterInfo { #define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) #define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) +#define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) #define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type) +#define FILTER_GET_COL_FIELD_DESC(fi) ((SSchema *)((fi)->desc)) #define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) #define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) +#define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) -#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units[(g)->unitIdxs[uid]]) +#define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) #define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) #define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) -#define FILTER_UNIT_DATA_TYPE(i, u) FILTER_GET_COL_FIELD_TYPE(FILTER_UNIT_LEFT_FIELD(i, u)) -#define FILTER_UNIT_VAL(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) +#define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type) +#define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u)) +#define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri) +#define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) #define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) #define FILTER_UNIT_OPTR(u) ((u)->compare.optr) @@ -177,12 +211,12 @@ typedef struct SFilterInfo { typedef int32_t(*filter_desc_compare_func)(const void *, const void *); -extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo); +extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); extern void* filterInitMergeRange(int32_t type, int32_t options); extern int32_t filterGetMergeRangeNum(void* h, int32_t* num); -extern int32_t filterGetMergeRangeRes(void* h, void *s, void* e); +extern int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra); extern int32_t filterFreeMergeRange(void* h); extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); #ifdef __cplusplus diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 63e5c50c50..f6a5d22287 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6966,7 +6966,7 @@ int32_t createQueryFilter(char *data, uint16_t len, SFilterInfo** pFilters) { return TSDB_CODE_QRY_APP_ERROR; } - int32_t ret = filterInitFromTree(expr, pFilters); + int32_t ret = filterInitFromTree(expr, pFilters, 0); tExprTreeDestroy(expr, NULL); return ret; diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index f5a04b46e0..aeab5c995b 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -16,6 +16,8 @@ #include "queryLog.h" #include "qFilter.h" #include "tcompare.h" +#include "hash.h" +#include "tscUtil.h" OptrStr gOptrStr[] = { {TSDB_RELATION_INVALID, "invalid"}, @@ -49,12 +51,28 @@ static FORCE_INLINE int32_t filterFieldValDescCompare(const void *desc1, const v } -filter_desc_compare_func gDescCompare [F_FIELD_MAX] = { +filter_desc_compare_func gDescCompare [FLD_TYPE_MAX] = { + NULL, filterFieldColDescCompare, filterFieldValDescCompare }; -static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, int32_t t, void *s, void *e) { + +int32_t filterInitUnitsFields(SFilterInfo *info) { + info->unitSize = FILTER_DEFAULT_UNIT_SIZE; + info->units = calloc(info->unitSize, sizeof(SFilterUnit)); + + info->fields[FLD_TYPE_COLUMN].num = 0; + info->fields[FLD_TYPE_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[FLD_TYPE_COLUMN].fields = calloc(info->fields[FLD_TYPE_COLUMN].size, COL_FIELD_SIZE); + info->fields[FLD_TYPE_VALUE].num = 0; + info->fields[FLD_TYPE_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; + info->fields[FLD_TYPE_VALUE].fields = calloc(info->fields[FLD_TYPE_VALUE].size, sizeof(SFilterField)); + + return TSDB_CODE_SUCCESS; +} + +static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, SFilterRange* ra) { SFilterRangeNode *r = NULL; if (ctx->rf) { @@ -65,9 +83,8 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, int32_t } else { r = calloc(1, sizeof(SFilterRangeNode)); } - - SIMPLE_COPY_VALUES((char*)&r->ra.s, s); - SIMPLE_COPY_VALUES((char*)&r->ra.e, e); + + FILTER_COPY_RA(&r->ra, ra); return r; } @@ -119,14 +136,41 @@ int32_t filterReuseMergeRangeCtx(SFilterRMCtx *ctx, int32_t type, int32_t option } +int32_t filterPostProcessRange(SFilterRMCtx *cur, SFilterRange *ra, bool *notNull) { + if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { + int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type)); + if (sr == 0) { + FILTER_SET_FLAG(ra->sflag, RA_NULL); + } + } -int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char eflag, int32_t optr) { + if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + int32_t er = cur->pCompareFunc(&ra->e, getDataMax(cur->type)); + if (er == 0) { + FILTER_SET_FLAG(ra->eflag, RA_NULL); + } + } + + + if (FILTER_GET_FLAG(ra->sflag, RA_NULL) && FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + *notNull = true; + } else { + *notNull = false; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; if (ctx->rs == NULL) { - if (MR_GET_FLAG(ctx->status, MR_ST_START) == 0 || optr == TSDB_RELATION_OR) { - APPEND_RANGE(ctx, ctx->rs, ctx->type, s, e); - MR_SET_FLAG(ctx->status, MR_ST_START); + if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) + || (FILTER_GET_FLAG(ctx->status, MR_ALL) && (optr == TSDB_RELATION_AND)) + || ((!FILTER_GET_FLAG(ctx->status, MR_ALL)) && (optr == TSDB_RELATION_OR))) { + APPEND_RANGE(ctx, ctx->rs, ra); + FILTER_SET_FLAG(ctx->status, MR_ST_START); } return TSDB_CODE_SUCCESS; @@ -134,27 +178,34 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; + int32_t cr = 0; if (optr == TSDB_RELATION_AND) { while (r != NULL) { - if (ctx->pCompareFunc(&r->ra.s, e) > 0) { + cr = ctx->pCompareFunc(&r->ra.s, &ra->e); + if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) { FREE_FROM_RANGE(ctx, r); break; } - if (ctx->pCompareFunc(s, &r->ra.e) > 0) { + cr = ctx->pCompareFunc(&ra->s, &r->ra.e); + if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { rn = r->next; FREE_RANGE(ctx, r); r = rn; continue; } - if (ctx->pCompareFunc(s, &r->ra.s) > 0) { - SIMPLE_COPY_VALUES((char *)&r->ra.s, s); + cr = ctx->pCompareFunc(&ra->s, &r->ra.s); + if (FILTER_GREATER(cr, ra->sflag, r->ra.sflag)) { + SIMPLE_COPY_VALUES((char *)&r->ra.s, &ra->s); + cr == 0 ? (r->ra.sflag = 0) : (r->ra.sflag = ra->sflag); } - if (ctx->pCompareFunc(&r->ra.e, e) > 0) { - SIMPLE_COPY_VALUES((char *)&r->ra.e, e); + cr = ctx->pCompareFunc(&r->ra.e, &ra->e); + if (FILTER_GREATER(cr, r->ra.eflag, ra->eflag)) { + SIMPLE_COPY_VALUES((char *)&r->ra.e, &ra->e); + cr == 0 ? (r->ra.eflag = 0) : (r->ra.eflag = ra->eflag); break; } @@ -166,41 +217,52 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla //TSDB_RELATION_OR + bool smerged = false; bool emerged = false; while (r != NULL) { - if (ctx->pCompareFunc(&r->ra.s, e) > 0) { + cr = ctx->pCompareFunc(&r->ra.s, &ra->e); + if (FILTER_GREATER(cr, r->ra.sflag, ra->eflag)) { if (emerged == false) { - INSERT_RANGE(ctx, r, ctx->type, s, e); + INSERT_RANGE(ctx, r, ra); } break; } - if (ctx->pCompareFunc(s, &r->ra.e) > 0) { - if (r->next) { - r= r->next; - continue; + if (smerged == false) { + cr = ctx->pCompareFunc(&ra->s, &r->ra.e); + if (FILTER_GREATER(cr, ra->sflag, r->ra.eflag)) { + if (r->next) { + r= r->next; + continue; + } + + APPEND_RANGE(ctx, r, ra); + break; } - APPEND_RANGE(ctx, r, ctx->type, s, e); - break; - } - - if (smerged == false) { - if (ctx->pCompareFunc(&r->ra.s, s) > 0) { - SIMPLE_COPY_VALUES((char *)&r->ra.s, s); + cr = ctx->pCompareFunc(&r->ra.s, &ra->s); + if (FILTER_GREATER(cr, r->ra.sflag, ra->sflag)) { + SIMPLE_COPY_VALUES((char *)&r->ra.s, &ra->s); + cr == 0 ? (r->ra.sflag &= ra->sflag) : (r->ra.sflag = ra->sflag); } smerged = true; } if (emerged == false) { - if (ctx->pCompareFunc(e, &r->ra.e) > 0) { - SIMPLE_COPY_VALUES((char *)&r->ra.e, e); + cr = ctx->pCompareFunc(&ra->e, &r->ra.e); + if (FILTER_GREATER(cr, ra->eflag, r->ra.eflag)) { + SIMPLE_COPY_VALUES((char *)&r->ra.e, &ra->e); + if (cr == 0) { + r->ra.eflag &= ra->eflag; + break; + } + + r->ra.eflag = ra->eflag; emerged = true; - e = &r->ra.e; r = r->next; continue; } @@ -208,43 +270,48 @@ int32_t filterAddMergeRangeImpl(void* h, void* s, void* e, char sflag, char efla break; } - if (ctx->pCompareFunc(e, &r->ra.e) > 0) { + cr = ctx->pCompareFunc(&ra->e, &r->ra.e); + if (FILTER_GREATER(cr, ra->eflag, r->ra.eflag)) { rn = r->next; FREE_RANGE(ctx, r); r = rn; continue; } else { - SIMPLE_COPY_VALUES(e, (char *)&r->ra.e); + SIMPLE_COPY_VALUES(&r->prev->ra.e, (char *)&r->ra.e); + cr == 0 ? (r->prev->ra.eflag &= r->ra.eflag) : (r->prev->ra.eflag = r->ra.eflag); FREE_RANGE(ctx, r); break; } } + if (ctx->rs && ctx->rs->next == NULL) { + bool notnull; + filterPostProcessRange(ctx, &ctx->rs->ra, ¬null); + if (notnull) { + FREE_FROM_RANGE(ctx, ctx->rs); + FILTER_SET_FLAG(ctx->status, MR_ALL); + } + } + return TSDB_CODE_SUCCESS; } int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; - int64_t sv, ev; - void *s, *e; - if (MR_GET_FLAG(ra->sflag, RA_NULL)) { - SIMPLE_COPY_VALUES(&sv, getDataMin(ctx->type)); - s = &sv; - } else { - s = &ra->s; + if (FILTER_GET_FLAG(ra->sflag, RA_NULL)) { + SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); + //FILTER_CLR_FLAG(ra->sflag, RA_NULL); } - if (MR_GET_FLAG(ra->eflag, RA_NULL)) { - SIMPLE_COPY_VALUES(&ev, getDataMax(ctx->type)); - e = &ev; - } else { - e = &ra->e; + if (FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type)); + //FILTER_CLR_FLAG(ra->eflag, RA_NULL); } - return filterAddMergeRangeImpl(h, s, e, ra->sflag, ra->eflag, optr); + return filterAddMergeRangeImpl(h, ra, optr); } int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { @@ -269,11 +336,11 @@ int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { int32_t filterFinMergeRange(void* h) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; - if (MR_GET_FLAG(ctx->status, MR_ST_FIN)) { + if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) { return TSDB_CODE_SUCCESS; } - if (MR_GET_FLAG(ctx->options, MR_OPT_TS)) { + if (FILTER_GET_FLAG(ctx->options, MR_OPT_TS)) { SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; @@ -293,7 +360,7 @@ int32_t filterFinMergeRange(void* h) { } } - MR_SET_FLAG(ctx->status, MR_ST_FIN); + FILTER_SET_FLAG(ctx->status, MR_ST_FIN); return TSDB_CODE_SUCCESS; } @@ -316,7 +383,7 @@ int32_t filterGetMergeRangeNum(void* h, int32_t* num) { } -int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { +int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra) { filterFinMergeRange(h); SFilterRMCtx *ctx = (SFilterRMCtx *)h; @@ -324,11 +391,11 @@ int32_t filterGetMergeRangeRes(void* h, void *s, void* e) { SFilterRangeNode* r = ctx->rs; while (r) { - assignVal(s + num * tDataTypes[ctx->type].bytes, (char *)&r->ra.s, 0, ctx->type); - assignVal(e + num * tDataTypes[ctx->type].bytes, (char *)&r->ra.e, 0, ctx->type); + FILTER_COPY_RA(ra, &r->ra); ++num; r = r->next; + ++ra; } if (num == 0) { @@ -409,29 +476,14 @@ int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { return -1; } - -int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) { - CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node"); - CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType:%d", node->nodeType); - - int32_t type, idx = -1; +int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, SFilterFieldId *fid) { + int32_t idx = -1; uint16_t *num; - void *v; - - if (node->nodeType == TSQL_NODE_COL) { - type = F_FIELD_COLUMN; - v = node->pSchema; - node->pSchema = NULL; - } else { - type = F_FIELD_VALUE; - v = node->pVal; - node->pVal = NULL; - } num = &info->fields[type].num; - if (*num > 0 && type != F_FIELD_VALUE) { - idx = filterGetFiled(&info->fields[type], type, v); + if (*num > 0 && type != FLD_TYPE_VALUE) { + idx = filterGetFiled(&info->fields[type], type, desc); } if (idx < 0) { @@ -441,8 +493,9 @@ int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) info->fields[type].fields = realloc(info->fields[type].fields, info->fields[type].size * sizeof(SFilterField)); } - info->fields[type].fields[idx].type = type; - info->fields[type].fields[idx].desc = v; + info->fields[type].fields[idx].flag = type; + info->fields[type].fields[idx].desc = desc; + info->fields[type].fields[idx].data = data; ++(*num); } @@ -452,29 +505,186 @@ int32_t filterAddField(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) return TSDB_CODE_SUCCESS; } +static FORCE_INLINE int32_t filterAddFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { + filterAddField(info, field->desc, field->data, FILTER_GET_TYPE(field->flag), fid); + + FILTER_SET_FLAG(field->flag, FLD_DESC_NO_FREE); + FILTER_SET_FLAG(field->flag, FLD_DATA_NO_FREE); + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) { + CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node"); + CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType:%d", node->nodeType); + + int32_t type; + void *v; + + if (node->nodeType == TSQL_NODE_COL) { + type = FLD_TYPE_COLUMN; + v = node->pSchema; + node->pSchema = NULL; + } else { + type = FLD_TYPE_VALUE; + v = node->pVal; + node->pVal = NULL; + } + + filterAddField(info, v, NULL, type, fid); + + return TSDB_CODE_SUCCESS; +} + int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right) { if (info->unitNum >= info->unitSize) { + uint16_t psize = info->unitSize; info->unitSize += FILTER_DEFAULT_UNIT_SIZE; info->units = realloc(info->units, info->unitSize * sizeof(SFilterUnit)); + memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); + } + + SFilterUnit *u = &info->units[info->unitNum]; + + u->compare.optr = optr; + u->left = *left; + if (right) { + u->right = *right; + } + + if (u->right.type == FLD_TYPE_VALUE) { + SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); + assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); + } else { + assert(optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL); } - info->units[info->unitNum].compare.optr = optr; - info->units[info->unitNum].left = *left; - info->units[info->unitNum].right = *right; - + SFilterField *col = FILTER_UNIT_LEFT_FIELD(info, u); + assert(FILTER_GET_FLAG(col->flag, FLD_TYPE_COLUMN)); + + info->units[info->unitNum].compare.type = FILTER_GET_COL_FIELD_TYPE(col); + ++info->unitNum; return TSDB_CODE_SUCCESS; } -int32_t filterAddGroup(SFilterGroup *group, uint16_t unitIdx) { - group->unitNum = 1; - group->unitIdxs= calloc(group->unitNum, sizeof(*group->unitIdxs)); - group->unitIdxs[0] = unitIdx; + + +int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { + if (group->unitNum >= group->unitSize) { + group->unitSize += FILTER_DEFAULT_UNIT_SIZE; + group->unitIdxs = realloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); + } + + group->unitIdxs[group->unitNum++] = unitIdx; return TSDB_CODE_SUCCESS; } + + +int32_t filterAddUnitFromNode(SFilterInfo *info, tExprNode* tree) { + SFilterFieldId left = {0}, right = {0}; + + filterAddFieldFromNode(info, tree->_node.pLeft, &left); + filterAddFieldFromNode(info, tree->_node.pRight, &right); + + filterAddUnit(info, tree->_node.optr, &left, &right); + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u) { + SFilterFieldId left, right; + + filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left); + filterAddField(dst, NULL, FILTER_UNIT_VAL_DATA(src, u), FLD_TYPE_VALUE, &right); + + SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); + FILTER_SET_FLAG(t->flag, FLD_DESC_NO_FREE); + t = FILTER_UNIT_RIGHT_FIELD(src, u); + FILTER_SET_FLAG(t->flag, FLD_DATA_NO_FREE); + + return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, &right); +} + +int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterColRange *cra, SFilterGroup *g, int32_t optr, SArray *res) { + SFilterFieldId left, right; + + SFilterField *col = FILTER_GET_COL_FIELD(src, cra->idx); + + filterAddFieldFromField(dst, col, &left); + + if (optr == TSDB_RELATION_AND) { + if (cra->isNull) { + assert(cra->notNull == false); + filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); + return filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (cra->notNull) { + assert(cra->isNull == false); + filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); + return filterAddUnitToGroup(g, dst->unitNum - 1); + } + + assert(!((FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) && (FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)))); + + if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + } else { + SFilterGroup ng = {0}; + g = &ng; + + if (cra->isNull) { + filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); + filterAddUnitToGroup(g, dst->unitNum - 1); + taosArrayPush(res, g); + } + + if (cra->notNull) { + memset(g, 0, sizeof(*g)); + + filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); + filterAddUnitToGroup(g, dst->unitNum - 1); + taosArrayPush(res, g); + } + + memset(g, 0, sizeof(*g)); + + if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (g->unitNum > 0) { + taosArrayPush(res, g); + } + } + + return TSDB_CODE_SUCCESS; +} + + static void filterFreeGroup(void *pItem) { SFilterGroup* p = (SFilterGroup*) pItem; if (p) { @@ -515,14 +725,10 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } - SFilterFieldId left, right; - filterAddField(info, tree->_node.pLeft, &left); - filterAddField(info, tree->_node.pRight, &right); - - filterAddUnit(info, tree->_node.optr, &left, &right); + filterAddUnitFromNode(info, tree); SFilterGroup fgroup = {0}; - filterAddGroup(&fgroup, info->unitNum - 1); + filterAddUnitToGroup(&fgroup, info->unitNum - 1); taosArrayPush(group, &fgroup); @@ -537,9 +743,7 @@ _err_return: int32_t filterInitUnitFunc(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; - SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); - - unit->compare.pCompareFunc = getComparFunc(FILTER_GET_COL_FIELD_TYPE(left), unit->compare.optr); + unit->compare.pCompareFunc = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); } return TSDB_CODE_SUCCESS; @@ -551,29 +755,44 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { CHK_LRETV(info == NULL, "%s - FilterInfo: empty", msg); qDebug("%s - FilterInfo:", msg); - qDebug("COLUMN Field Num:%u", info->fields[F_FIELD_COLUMN].num); - for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { - SFilterField *field = &info->fields[F_FIELD_COLUMN].fields[i]; + qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema *sch = field->desc; qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); } - qDebug("VALUE Field Num:%u", info->fields[F_FIELD_VALUE].num); - for (uint16_t i = 0; i < info->fields[F_FIELD_VALUE].num; ++i) { - SFilterField *field = &info->fields[F_FIELD_VALUE].fields[i]; - tVariant *var = field->desc; - qDebug("VAL%d => [type:%d][val:%" PRIu64"]", i, var->nType, var->u64); //TODO + qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num); + for (uint16_t i = 0; i < info->fields[FLD_TYPE_VALUE].num; ++i) { + SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; + if (field->desc) { + tVariant *var = field->desc; + qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + } else { + qDebug("VAL%d => [type:NIL][val:%" PRIi64" or %f]", i, *(int64_t *)field->data, *(double *)field->data); //TODO + } } qDebug("Unit Num:%u", info->unitNum); for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; + int32_t type = FILTER_UNIT_DATA_TYPE(unit); + int32_t len = 0; + char str[128]; + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); - SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); - SSchema *sch = left->desc; - tVariant *var = right->desc; - qDebug("UNIT%d => [%d][%s] %s %" PRId64, i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str, IS_NUMERIC_TYPE(var->nType) ? var->i64 : -1); //TODO + len = sprintf(str, "UNIT[%d] => [%d][%s] %s [", i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str); + + if (unit->right.type== FLD_TYPE_VALUE) { + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); + converToStr(str + len, type, right->data, 0, &len); + } else { + strcat(str, "NULL"); + } + strcat(str, "]"); + + qDebug("%s", str); //TODO } qDebug("Group Num:%u", info->groupNum); @@ -598,25 +817,17 @@ void filterFreeInfo(SFilterInfo *info) { int32_t filterInitValFieldData(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; - SFilterField* left = FILTER_UNIT_LEFT_FIELD(info, unit); - SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); - - if (left->type != F_FIELD_VALUE && right->type != F_FIELD_VALUE) { + if (unit->right.type != FLD_TYPE_VALUE) { + assert(unit->compare.optr == TSDB_RELATION_ISNULL || unit->compare.optr == TSDB_RELATION_NOTNULL); continue; } + + SFilterField* right = FILTER_UNIT_RIGHT_FIELD(info, unit); - uint32_t type = 0; - SFilterField* fi = NULL; - if (left->type == F_FIELD_COLUMN) { - type = FILTER_GET_COL_FIELD_TYPE(left); - fi = right; - } else if (right->type == F_FIELD_COLUMN) { - type = FILTER_GET_COL_FIELD_TYPE(right); - fi = left; - } else { - type = FILTER_GET_VAL_FIELD_TYPE(left); - fi = right; - } + assert(FILTER_GET_FLAG(right->flag, FLD_TYPE_VALUE)); + + uint32_t type = FILTER_UNIT_DATA_TYPE(unit); + SFilterField* fi = right; tVariant* var = fi->desc; @@ -632,7 +843,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } else if (type == TSDB_DATA_TYPE_NCHAR) { fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); } else { - if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE fi->data = calloc(var->nLen, tDataTypes[type].bytes); for (int32_t a = 0; a < var->nLen; ++a) { int64_t *v = taosArrayGet(var->arr, a); @@ -690,38 +901,73 @@ bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { } -#if 0 int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, int32_t optr) { - int32_t type = FILTER_UNIT_DATA_TYPE(info, u); + int32_t type = FILTER_UNIT_DATA_TYPE(u); uint8_t uoptr = FILTER_UNIT_OPTR(u); - void *val = FILTER_UNIT_VAL(info, u); - int64_t s = 0, e = 0; + void *val = FILTER_UNIT_VAL_DATA(info, u); + SFilterRange ra = {0}; + int64_t tmp = 0; switch (uoptr) { case TSDB_RELATION_GREATER: - + SIMPLE_COPY_VALUES(&ra.s, val); + FILTER_SET_FLAG(ra.sflag, RA_EXCLUDE); + FILTER_SET_FLAG(ra.eflag, RA_NULL); break; case TSDB_RELATION_GREATER_EQUAL: + SIMPLE_COPY_VALUES(&ra.s, val); + FILTER_SET_FLAG(ra.eflag, RA_NULL); + break; case TSDB_RELATION_LESS: + SIMPLE_COPY_VALUES(&ra.e, val); + FILTER_SET_FLAG(ra.eflag, RA_EXCLUDE); + FILTER_SET_FLAG(ra.sflag, RA_NULL); + break; case TSDB_RELATION_LESS_EQUAL: + SIMPLE_COPY_VALUES(&ra.e, val); + FILTER_SET_FLAG(ra.sflag, RA_NULL); + break; case TSDB_RELATION_NOT_EQUAL: + assert(type == TSDB_DATA_TYPE_BOOL); + if (GET_INT8_VAL(val)) { + SIMPLE_COPY_VALUES(&ra.s, &tmp); + SIMPLE_COPY_VALUES(&ra.e, &tmp); + } else { + *(bool *)&tmp = true; + SIMPLE_COPY_VALUES(&ra.s, &tmp); + SIMPLE_COPY_VALUES(&ra.e, &tmp); + } + break; case TSDB_RELATION_EQUAL: - case TSDB_RELATION_IN: + SIMPLE_COPY_VALUES(&ra.s, val); + SIMPLE_COPY_VALUES(&ra.e, val); + break; + case TSDB_RELATION_IN: { + void *p = taosHashIterate((SHashObj *)val, NULL); + while(p) { + void *key = taosHashGetDataKey((SHashObj *)val, p); + SIMPLE_COPY_VALUES(&ra.s, key); + SIMPLE_COPY_VALUES(&ra.e, key); + filterAddMergeRange(ctx, &ra, optr); + p = taosHashIterate((SHashObj *)val, p); + } + + return TSDB_CODE_SUCCESS; + } default: assert(0); } - filterAddMergeRange(ctx, &s, &e, optr); + filterAddMergeRange(ctx, &ra, optr); return TSDB_CODE_SUCCESS; } -int32_t filterMergeSingleGroupUnits(SFilterInfo *info, SFilterGroup* g, uint16_t id1, uint16_t id2, SArray* res) { + +int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum) { bool isnull = false, notnull = false; int32_t num = 0; - - SFilterRMCtx *cur = filterInitMergeRange(type, 0); SFilterUnit* u1 = FILTER_GROUP_UNIT(info, g, id1); SFilterUnit* u2 = FILTER_GROUP_UNIT(info, g, id2); @@ -729,10 +975,8 @@ int32_t filterMergeSingleGroupUnits(SFilterInfo *info, SFilterGroup* g, uint16_t uint8_t optr2 = FILTER_UNIT_OPTR(u2); uint16_t cidx = FILTER_UNIT_COL_IDX(u1); - int32_t type = FILTER_UNIT_DATA_TYPE(info, u1); - -#define SET_OPTR(o) ((o == TSDB_RELATION_ISNULL) ? isnull = true : notnull = true) -#define CHK_OPTR() (isnull == true && notnull == true) + int32_t type = FILTER_UNIT_DATA_TYPE(u1); + SFilterRMCtx *cur = filterInitMergeRange(type, 0); SET_OPTR(optr1); SET_OPTR(optr2); @@ -755,25 +999,37 @@ int32_t filterMergeSingleGroupUnits(SFilterInfo *info, SFilterGroup* g, uint16_t continue; } + ++(*removedNum); optr2 = FILTER_UNIT_OPTR(u); SET_OPTR(optr2); CHK_JMP(CHK_OPTR()); if (!FILTER_NO_MERGE_OPTR(optr2)) { - filterAddUnitRange(info, u2, cur, TSDB_RELATION_AND); + filterAddUnitRange(info, u, cur, TSDB_RELATION_AND); CHK_JMP(MR_EMPTY_RES(cur)); } } - SFilterColRange ra; - ra.idx = cidx; + SFilterColRange cra = {0}; + cra.idx = cidx; filterGetMergeRangeNum(cur, &num); - assert(num == 1); - - filterGetMergeRangeRes(cur, &ra.s, &ra.e); + assert(num == 1 || num == 0); - taosArrayPush(res, &ra); + if (num == 1) { + filterGetMergeRangeRes(cur, &cra.ra); + filterPostProcessRange(cur, &cra.ra, &cra.notNull); + } else { + if (isnull) { + cra.isNull = true; + } + + if (notnull) { + cra.notNull = true; + } + } + + taosArrayPush(res, &cra); filterFreeMergeRange(cur); @@ -782,6 +1038,8 @@ int32_t filterMergeSingleGroupUnits(SFilterInfo *info, SFilterGroup* g, uint16_t _err_return: g->unitNum = 0; + + *removedNum = g->unitNum; filterFreeMergeRange(cur); @@ -789,39 +1047,50 @@ _err_return: } -int32_t filterMergeGroupUnits(SFilterInfo *info, SArray** res) { - uint16_t *f = malloc(1, info->fields[F_FIELD_COLUMN].num * sizeof(uint16_t)); - SArray *gres = NULL; + +int32_t filterProcessUnits(SFilterInfo *info, SFilterGroupCtx*** res) { + int32_t *col = NULL; + SFilterGroupCtx *gctx = NULL; + SArray *colRange = NULL; bool gresUsed = false; + uint16_t removedNum = 0; for (uint16_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; - - memet(f, -1, info->fields[F_FIELD_COLUMN].num); + if (col == NULL) { + col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); + } else { + memset(col, 0, info->fields[FLD_TYPE_COLUMN].num * sizeof(int32_t)); + } gresUsed = false; + + removedNum = 0; for (uint16_t j = 0; j < g->unitNum; ++j) { SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); - int32_t type = FILTER_UNIT_DATA_TYPE(info, u); + int32_t type = FILTER_UNIT_DATA_TYPE(u); if (FILTER_NO_MERGE_DATA_TYPE(type)) { continue; } uint16_t cidx = FILTER_UNIT_COL_IDX(u); - if (f[cidx] == -1) { - f[u->left.idx] = j; - } else if (cidx] == -2) { + if (col[cidx] == 0) { + col[cidx] = j + 1; + } else if (col[cidx] == -1) { continue; } else { - f[cidx] = -2; - - if (gres == NULL) { - gres = taosArrayInit(4, sizeof(SFilterColRange)); + if (colRange == NULL) { + colRange = taosArrayInit(4, sizeof(SFilterColRange)); } - filterMergeSingleGroupUnits(info, g, f[cidx], j, gres); + removedNum += 2; + + filterProcessUnitsInOneGroup(info, g, col[cidx] - 1, j, colRange, &removedNum); + + col[cidx] = -1; + if (g->unitNum == 0) { break; } else { @@ -832,44 +1101,409 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SArray** res) { if (g->unitNum == 0) { if (gresUsed) { - taosArrayClear(gres); + taosArrayClear(colRange); } continue; } - if (res == NULL) { - res = calloc(info->groupNum, sizeof(SArray *)); - res[i] = gres; - gres = NULL; + if (gresUsed) { + gctx = malloc(sizeof(*gctx)); + gctx->num = g->unitNum - removedNum + 1; + gctx->col = col; + gctx->colRange = colRange; + + col = NULL; + colRange = NULL; + + if (*res == NULL) { + *res = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); + } + + (*res)[i] = gctx; } } - free(f); - if (gres) { - taosArrayDestroy(gres); + tfree(col); + if (colRange) { + taosArrayDestroy(colRange); } return TSDB_CODE_SUCCESS; } -int32_t filterPreprocess(SFilterInfo *info) { - SArray* res = NULL; - - filterMergeGroupUnits(info, &res); +int32_t filterProcessGroupsSameColumn(SFilterInfo *info, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum, SFilterGroupCtx** unitRes) { + bool isnull = false, notnull = false; + int32_t num = 0; + SFilterColRange *cra = NULL; + SFilterGroup *g = NULL; + + SFilterUnit* u1 = FILTER_GROUP_UNIT(info, info->groups + id1, 0); + uint8_t optr = FILTER_UNIT_OPTR(u1); + uint16_t cidx = FILTER_UNIT_COL_IDX(u1); + uint16_t cidx2 = 0; + + int32_t type = FILTER_UNIT_DATA_TYPE(u1); + SFilterRMCtx *cur = filterInitMergeRange(type, 0); + + for (int32_t i = 0; i < info->groupNum; ++i) { + g = info->groups + i; + uint16_t unitNum = (unitRes && unitRes[i]) ? unitRes[i]->num : g->unitNum; + + if (unitNum == 0) { + continue; + } + + if (unitNum > 1) { + continue; + } + + if (unitRes && unitRes[i]) { + assert(taosArrayGetSize(unitRes[i]->colRange) == 1); + if (notnull) { + continue; + } + + cra = taosArrayGet(unitRes[i]->colRange, 0); + + if (cra->notNull) { + notnull = true; + CHK_JMP(CHK_OPTR()); + } + + cidx2 = cra->idx; + } else { + u1 = FILTER_GROUP_UNIT(info, g, 0); + int32_t type = FILTER_UNIT_DATA_TYPE(u1); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + continue; + } + + optr = FILTER_UNIT_OPTR(u1); + + cidx2 = FILTER_UNIT_COL_IDX(u1); + } + + if (cidx != cidx2) { + continue; + } + + g->unitNum = 0; + + if (unitRes && unitRes[i]) { + unitRes[i]->num = 0; + if (notnull) { + continue; + } + + filterAddMergeRange(cur, &cra->ra, TSDB_RELATION_OR); + if (MR_EMPTY_RES(cur)) { + notnull = true; + CHK_JMP(CHK_OPTR()); + } + + continue; + } + + optr = FILTER_UNIT_OPTR(u1); + SET_OPTR(optr); + CHK_JMP(CHK_OPTR()); + + if (!FILTER_NO_MERGE_OPTR(optr) && notnull == false) { + filterAddUnitRange(info, u1, cur, TSDB_RELATION_OR); + if (MR_EMPTY_RES(cur)) { + notnull = true; + CHK_JMP(CHK_OPTR()); + } + } + } + + SFilterColRange ncra; + SFilterRange *ra; + ncra.idx = cidx; + + ncra.isNull = isnull; + ncra.notNull = notnull; + + if (isnull) { + --removedNum; + } + + if (!notnull) { + filterGetMergeRangeNum(cur, &num); + if (num > 1) { + ra = calloc(num, sizeof(*ra)); + } else { + assert(num == 1); + ra = &ncra.ra; + } + + filterGetMergeRangeRes(cur, ra); + + SFilterRange *tra = ra; + for (int32_t i = 0; i < num; ++i) { + filterPostProcessRange(cur, tra, &ncra.notNull); + assert(ncra.notNull == false); + ++tra; + } + + if (num > 1) { + for (int32_t i = 0; i < num; ++i) { + FILTER_COPY_RA(&ncra.ra, ra); + + taosArrayPush(res, &ncra); + + ++ra; + } + } else { + FILTER_COPY_RA(&ncra.ra, ra); + + taosArrayPush(res, &ncra); + } + } else { + taosArrayPush(res, &ncra); + } + + filterFreeMergeRange(cur); + + return TSDB_CODE_SUCCESS; + +_err_return: + + FILTER_SET_FLAG(info->flags, FILTER_ALL); + + filterFreeMergeRange(cur); + + return TSDB_CODE_SUCCESS; + +} + + +int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilterGroupCtx* groupRes) { + int32_t *col = NULL; + uint16_t cidx; + uint16_t removedNum = 0; + SArray *colRange = NULL; + + for (uint16_t i = 0; i < info->groupNum; ++i) { + SFilterGroup* g = info->groups + i; + uint16_t unitNum = (unitRes && unitRes[i]) ? unitRes[i]->num : g->unitNum; + + if (unitNum == 0) { + ++removedNum; + continue; + } + + if (unitNum > 1) { + continue; + } + + if (unitRes && unitRes[i]) { + assert(taosArrayGetSize(unitRes[i]->colRange) == 1); + SFilterColRange *ra = taosArrayGet(unitRes[i]->colRange, 0); + + cidx = ra->idx; + } else { + SFilterUnit* u = FILTER_GROUP_UNIT(info, g, 0); + int32_t type = FILTER_UNIT_DATA_TYPE(u); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + continue; + } + + cidx = FILTER_UNIT_COL_IDX(u); + } + + if (col == NULL) { + col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); + } + + if (col[cidx] == 0) { + col[cidx] = i + 1; + continue; + } else if (col[cidx] == -1) { + continue; + } else { + if (colRange == NULL) { + colRange = taosArrayInit(4, sizeof(SFilterColRange)); + } + + removedNum += 2; + filterProcessGroupsSameColumn(info, col[cidx] - 1, i, colRange, &removedNum, unitRes); + + CHK_JMP(FILTER_GET_FLAG(info->flags, FILTER_ALL)); + + col[cidx] = -1; + } + } + + uint16_t num = info->groupNum - removedNum; + assert(num >= 0); + + if (colRange) { + num += taosArrayGetSize(colRange); + } + + if (num == 0) { + FILTER_SET_FLAG(info->flags, FILTER_NONE); + goto _err_return; + } + + if (colRange || removedNum > 0) { + groupRes->num = num; + groupRes->col = col; + groupRes->colRange = colRange; + } else { + tfree(col); + } + + return TSDB_CODE_SUCCESS; + +_err_return: + tfree(col); + if (colRange) { + taosArrayDestroy(colRange); + } + + return TSDB_CODE_SUCCESS; +} + +int32_t filterGenerateGroupFromArray(SFilterInfo *info, SArray* group) { + size_t groupSize = taosArrayGetSize(group); + + info->groupNum = (uint16_t)groupSize; + + if (info->groupNum > 0) { + info->groups = calloc(info->groupNum, sizeof(*info->groups)); + } + + for (size_t i = 0; i < groupSize; ++i) { + SFilterGroup *pg = taosArrayGet(group, i); + pg->unitFlags = calloc(pg->unitNum, sizeof(*pg->unitFlags)); + info->groups[i] = *pg; + } + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { + if (gctx->num == 0) { + return TSDB_CODE_SUCCESS; + } + + SFilterInfo oinfo = *info; + uint16_t gNum = 0; + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + + memset(info, 0, sizeof(*info)); + + filterInitUnitsFields(info); + + for (uint16_t i = 0; i < oinfo.groupNum; ++i) { + SFilterGroup* g = oinfo.groups + i; + SFilterGroup ng = {0}; + uint16_t unitNum = (uctx && uctx[i]) ? uctx[i]->num : g->unitNum; + + if (unitNum == 0) { + continue; + } + + ++gNum; + + if ((uctx == NULL) || (uctx[i] == NULL)) { + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + + taosArrayPush(group, &ng); + + continue; + } + + SFilterGroupCtx* ctx = uctx[i]; + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + int32_t type = FILTER_UNIT_DATA_TYPE(u); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + continue; + } + + uint16_t cidx = FILTER_UNIT_COL_IDX(u); + + assert(ctx->col[cidx] > 0 || ctx->col[cidx] == -1); + + if (ctx->col[cidx] != -1) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + } + + if (ctx->colRange && taosArrayGetSize(ctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(ctx->colRange); + for (int32_t i = 0; i < size; ++i) { + SFilterColRange *cra = taosArrayGet(ctx->colRange, i); + filterAddGroupUnitFromRange(info, &oinfo, cra, &ng, TSDB_RELATION_AND, NULL); + } + } + + taosArrayPush(group, &ng); + } + + if (gctx->colRange && taosArrayGetSize(gctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(gctx->colRange); + for (int32_t i = 0; i < size; ++i) { + SFilterColRange *cra = taosArrayGet(gctx->colRange, i); + filterAddGroupUnitFromRange(info, &oinfo, cra, NULL, TSDB_RELATION_OR, group); + } + } + + filterGenerateGroupFromArray(info, group); + + taosArrayDestroy(group); + + return TSDB_CODE_SUCCESS; +} + + +int32_t filterPreprocess(SFilterInfo *info) { + SFilterGroupCtx** unitsRes = NULL; + SFilterGroupCtx groupRes = {0}; + + filterProcessUnits(info, &unitsRes); + + filterProcessGroups(info, unitsRes, &groupRes); + + if (FILTER_GET_FLAG(info->flags, FILTER_ALL)) { + qInfo("Final - FilterInfo: [ALL]"); + return TSDB_CODE_SUCCESS; + } + + if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { + qInfo("Final - FilterInfo: [NONE]"); + return TSDB_CODE_SUCCESS; + } + + //TODO GET COLUMN RANGE + + filterRewrite(info, &groupRes, unitsRes); + + return TSDB_CODE_SUCCESS; } -#endif int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); - CHK_LRET(info->fields[F_FIELD_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); + CHK_LRET(info->fields[FLD_TYPE_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); - for (uint16_t i = 0; i < info->fields[F_FIELD_COLUMN].num; ++i) { - SFilterField* fi = &info->fields[F_FIELD_COLUMN].fields[i]; + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema* sch = fi->desc; if (sch->colId == colId) { fi->data = data; @@ -884,6 +1518,10 @@ int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { bool all = true; + if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { + return false; + } + for (int32_t i = 0; i < numOfRows; ++i) { FILTER_UNIT_CLR_F(info); @@ -901,10 +1539,8 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { ures = FILTER_UNIT_GET_R(info, uidx); } else { SFilterUnit *unit = &info->units[uidx]; - SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); - SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); - if (isNull(FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_COL_FIELD_TYPE(left))) { + if (isNull(FILTER_UNIT_COL_DATA(info, unit, i), FILTER_UNIT_DATA_TYPE(unit))) { ures = unit->compare.optr == TSDB_RELATION_ISNULL ? true : false; } else { if (unit->compare.optr == TSDB_RELATION_NOTNULL) { @@ -912,7 +1548,7 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { } else if (unit->compare.optr == TSDB_RELATION_ISNULL) { ures = false; } else { - ures = filterDoCompare(unit, FILTER_GET_COL_FIELD_DATA(left, i), FILTER_GET_VAL_FIELD_DATA(right)); + ures = filterDoCompare(unit, FILTER_UNIT_COL_DATA(info, unit, i), FILTER_UNIT_VAL_DATA(info, unit)); } } @@ -941,8 +1577,7 @@ bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { } - -int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { +int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options) { int32_t code = TSDB_CODE_SUCCESS; SFilterInfo *info = NULL; @@ -954,42 +1589,33 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { info = *pinfo; - SArray* group = taosArrayInit(4, sizeof(SFilterGroup)); - - info->unitSize = FILTER_DEFAULT_UNIT_SIZE; - info->units = calloc(info->unitSize, sizeof(SFilterUnit)); + info->flags = options; - info->fields[F_FIELD_COLUMN].num = 0; - info->fields[F_FIELD_COLUMN].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[F_FIELD_COLUMN].fields = calloc(info->fields[F_FIELD_COLUMN].size, COL_FIELD_SIZE); - info->fields[F_FIELD_VALUE].num = 0; - info->fields[F_FIELD_VALUE].size = FILTER_DEFAULT_FIELD_SIZE; - info->fields[F_FIELD_VALUE].fields = calloc(info->fields[F_FIELD_VALUE].size, sizeof(SFilterField)); + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + + filterInitUnitsFields(info); code = filterTreeToGroup(tree, info, group); ERR_JRET(code); - size_t groupSize = taosArrayGetSize(group); - - info->groupNum = (uint16_t)groupSize; - - if (info->groupNum > 0) { - info->groups = calloc(info->groupNum, sizeof(*info->groups)); - } - - for (size_t i = 0; i < groupSize; ++i) { - SFilterGroup *pg = taosArrayGet(group, i); - pg->unitFlags = calloc(pg->unitNum, sizeof(*pg->unitFlags)); - info->groups[i] = *pg; - } + filterGenerateGroupFromArray(info, group); ERR_JRET(filterInitValFieldData(info)); - filterDumpInfoToString(info, "Before preprocess"); + if (!FILTER_GET_FLAG(info->flags, FILTER_NO_REWRITE)) { + filterDumpInfoToString(info, "Before preprocess"); - //ERR_JRET(filterPreprocess(info)); + ERR_JRET(filterPreprocess(info)); + + CHK_JMP(FILTER_GET_FLAG(info->flags, FILTER_ALL)); + if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { + taosArrayDestroy(group); + return code; + } + } + ERR_JRET(filterInitUnitFunc(info)); info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); @@ -997,10 +1623,19 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo) { filterDumpInfoToString(info, "Final"); + taosArrayDestroy(group); + + return code; + _err_return: + qInfo("No filter, code:%d", code); taosArrayDestroy(group); + filterFreeInfo(*pinfo); + + *pinfo = NULL; + return code; } @@ -1043,6 +1678,11 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { break; } + if (FILTER_GET_FLAG(cur->status, MR_ALL)) { + FILTER_SET_FLAG(prev->status, MR_ALL); + break; + } + if (group->unitNum > 1) { filterAddMergeRangeCtx(prev, cur, TSDB_RELATION_OR); filterResetMergeRangeCtx(cur); @@ -1050,13 +1690,20 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { } if (code == TSDB_CODE_SUCCESS) { - filterGetMergeRangeNum(prev, &num); - if (num != 1) { - qError("only one time range accepted, num:%d", num); - ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); - } + if (FILTER_GET_FLAG(prev->status, MR_ALL)) { + *win = TSWINDOW_INITIALIZER; + } else { + filterGetMergeRangeNum(prev, &num); + if (num != 1) { + qError("only one time range accepted, num:%d", num); + ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); + } - filterGetMergeRangeRes(prev, &win->skey, &win->ekey); + SFilterRange ra; + filterGetMergeRangeRes(prev, &ra); + win->skey = ra.s; + win->ekey = ra.e; + } } _err_return: diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index 202394e943..1f4626e364 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -20,7 +20,7 @@ namespace { void intDataTest() { printf("running %s\n", __FUNCTION__); int32_t asize = 0; - SFilterRange ra = {0}; + SFilterRange ra[10] = {0}; int64_t *s =NULL; int64_t *e =NULL; int64_t s0[3] = {-100, 1, 3}; @@ -34,179 +34,191 @@ void intDataTest() { int64_t s4[2] = {10, 0}; int64_t e4[2] = {20, 5}; int64_t s5[3] = {0, 6 ,7}; - int64_t e5[5] = {4, 10,20}; + int64_t e5[3] = {4, 10,20}; int64_t rs[10]; int64_t re[10]; int32_t num = 0; + void *h = NULL; s = s0; e = e0; - asize = sizeof(s0)/sizeof(s[0]); - void *h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + asize = sizeof(s0)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + ra[0].s = s[i]; + ra[0].e = e[i]; + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 3); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], -100); - ASSERT_EQ(re[0], 0); - ASSERT_EQ(rs[1], 1); - ASSERT_EQ(re[1], 2); - ASSERT_EQ(rs[2], 3); - ASSERT_EQ(re[2], 4); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, -100); + ASSERT_EQ(ra[0].e, 0); + ASSERT_EQ(ra[1].s, 1); + ASSERT_EQ(ra[1].e, 2); + ASSERT_EQ(ra[2].s, 3); + ASSERT_EQ(ra[2].e, 4); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, MR_OPT_TS); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], -100); - ASSERT_EQ(re[0], 4); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, -100); + ASSERT_EQ(ra[0].e, 4); filterFreeMergeRange(h); s = s1; e = e1; asize = sizeof(s1)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 3); - ASSERT_EQ(re[0], 4); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 3); + ASSERT_EQ(ra[0].e, 4); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], INT64_MIN); - ASSERT_EQ(re[0], 100); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, INT64_MIN); + ASSERT_EQ(ra[0].e, 100); filterFreeMergeRange(h); + s = s2; e = e2; asize = sizeof(s2)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 1); - ASSERT_EQ(re[0], 120); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 1); + ASSERT_EQ(ra[0].e, 120); filterFreeMergeRange(h); - + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); + filterAddMergeRange(h, ra, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); + filterAddMergeRange(h, ra, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 70); - ASSERT_EQ(re[0], 120); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 70); + ASSERT_EQ(ra[0].e, 120); filterFreeMergeRange(h); s = s3; e = e3; asize = sizeof(s3)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 1); - ASSERT_EQ(re[0], 100); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 1); + ASSERT_EQ(ra[0].e, 100); filterFreeMergeRange(h); @@ -215,82 +227,131 @@ void intDataTest() { s = s4; e = e4; asize = sizeof(s4)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 2); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 0); - ASSERT_EQ(re[0], 5); - ASSERT_EQ(rs[1], 10); - ASSERT_EQ(re[1], 20); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 0); + ASSERT_EQ(ra[0].e, 5); + ASSERT_EQ(ra[1].s, 10); + ASSERT_EQ(ra[1].e, 20); filterFreeMergeRange(h); s = s5; e = e5; asize = sizeof(s5)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_AND); + filterAddMergeRange(h, ra, TSDB_RELATION_AND); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 0); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, TSDB_RELATION_OR); + filterAddMergeRange(h, ra, TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 2); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 0); - ASSERT_EQ(re[0], 4); - ASSERT_EQ(rs[1], 6); - ASSERT_EQ(re[1], 20); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 0); + ASSERT_EQ(ra[0].e, 4); + ASSERT_EQ(ra[1].s, 6); + ASSERT_EQ(ra[1].e, 20); filterFreeMergeRange(h); + memset(ra, 0, sizeof(ra)); h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { - ra.s = s[i]; - ra.e = e[i]; + ra[0].s = s[i]; + ra[0].e = e[i]; - filterAddMergeRange(h, &ra, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); + filterAddMergeRange(h, ra, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); } filterGetMergeRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, rs, re); - ASSERT_EQ(rs[0], 7); - ASSERT_EQ(re[0], 10); + filterGetMergeRangeRes(h, ra); + ASSERT_EQ(ra[0].s, 7); + ASSERT_EQ(ra[0].e, 10); filterFreeMergeRange(h); + + int64_t s6[2] = {0, 4}; + int64_t e6[2] = {4, 6}; + s = s6; + e = e6; + asize = sizeof(s6)/sizeof(s[0]); + memset(ra, 0, sizeof(ra)); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + ra[0].eflag = 1; + ra[1].sflag = 4; + + ra[i].s = s[i]; + ra[i].e = e[i]; + + filterAddMergeRange(h, ra + i, TSDB_RELATION_AND); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 0); + filterFreeMergeRange(h); + + + + memset(ra, 0, sizeof(ra)); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + for (int32_t i = 0; i < asize; ++i) { + ra[0].eflag = 1; + ra[1].sflag = 1; + + ra[i].s = s[i]; + ra[i].e = e[i]; + + filterAddMergeRange(h, ra + i, TSDB_RELATION_OR); + } + filterGetMergeRangeNum(h, &num); + ASSERT_EQ(num, 2); + ASSERT_EQ(ra[0].s, 0); + ASSERT_EQ(ra[0].e, 4); + ASSERT_EQ(ra[0].eflag, 1); + ASSERT_EQ(ra[1].s, 4); + ASSERT_EQ(ra[1].e, 6); + ASSERT_EQ(ra[1].sflag, 1); + filterFreeMergeRange(h); + } diff --git a/src/util/inc/hash.h b/src/util/inc/hash.h index c37426069c..79eda33e74 100644 --- a/src/util/inc/hash.h +++ b/src/util/inc/hash.h @@ -42,7 +42,7 @@ typedef struct SHashNode { #define GET_HASH_NODE_KEY(_n) ((char*)(_n) + sizeof(SHashNode) + (_n)->dataLen) #define GET_HASH_NODE_DATA(_n) ((char*)(_n) + sizeof(SHashNode)) -#define GET_HASH_PNODE(_n) ((char*)(_n) - sizeof(SHashNode)); +#define GET_HASH_PNODE(_n) ((SHashNode *)((char*)(_n) - sizeof(SHashNode))) typedef enum SHashLockTypeE { HASH_NO_LOCK = 0, @@ -161,6 +161,8 @@ void *taosHashIterate(SHashObj *pHashObj, void *p); void taosHashCancelIterate(SHashObj *pHashObj, void *p); +void *taosHashGetDataKey(SHashObj *pHashObj, void *data); + #ifdef __cplusplus } #endif diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 5b3218382f..a3501d47da 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -695,6 +695,10 @@ size_t taosHashGetMemSize(const SHashObj *pHashObj) { return (pHashObj->capacity * (sizeof(SHashEntry) + POINTER_BYTES)) + sizeof(SHashNode) * taosHashGetSize(pHashObj) + sizeof(SHashObj); } +FORCE_INLINE void *taosHashGetDataKey(SHashObj *pHashObj, void *data) { + return GET_HASH_NODE_KEY(GET_HASH_PNODE(data)); +} + // release the pNode, return next pNode, and lock the current entry static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 4cc8eeece6..6d4d6dc0b8 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -64,21 +64,21 @@ int32_t compareInt8Val(const void *pLeft, const void *pRight) { } int32_t compareUint32Val(const void *pLeft, const void *pRight) { - int32_t left = GET_UINT32_VAL(pLeft), right = GET_UINT32_VAL(pRight); + uint32_t left = GET_UINT32_VAL(pLeft), right = GET_UINT32_VAL(pRight); if (left > right) return 1; if (left < right) return -1; return 0; } int32_t compareUint64Val(const void *pLeft, const void *pRight) { - int64_t left = GET_UINT64_VAL(pLeft), right = GET_UINT64_VAL(pRight); + uint64_t left = GET_UINT64_VAL(pLeft), right = GET_UINT64_VAL(pRight); if (left > right) return 1; if (left < right) return -1; return 0; } int32_t compareUint16Val(const void *pLeft, const void *pRight) { - int16_t left = GET_UINT16_VAL(pLeft), right = GET_UINT16_VAL(pRight); + uint16_t left = GET_UINT16_VAL(pLeft), right = GET_UINT16_VAL(pRight); if (left > right) return 1; if (left < right) return -1; return 0; From 8faa80d6a7176553ac52247aa6c6be5953aedcdc Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 13 Jul 2021 08:33:39 +0800 Subject: [PATCH 018/100] fix range issue --- src/query/inc/qFilter.h | 6 +- src/query/src/qFilter.c | 115 ++++++++----- tests/script/general/parser/condition.sim | 200 ++++++++++++++++++++++ 3 files changed, 275 insertions(+), 46 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 092d244e24..1a618c62fa 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -154,8 +154,10 @@ typedef struct SFilterInfo { #define MR_EMPTY_RES(ctx) (ctx->rs == NULL) -#define SET_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { notnull = true; } } while (0) -#define CHK_OPTR() (isnull == true && notnull == true) +#define SET_AND_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!isrange) { notnull = true; } } else { isrange = true; notnull = false; } } while (0) +#define SET_OR_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { notnull = true; } } while (0) +#define CHK_OR_OPTR() (isnull == true && notnull == true) +#define CHK_AND_OPTR() (isnull == true && ((notnull == true) || (isrange == true))) #define FILTER_GET_FLAG(st, f) (st & f) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index aeab5c995b..95bbdc5677 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -199,13 +199,13 @@ int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { cr = ctx->pCompareFunc(&ra->s, &r->ra.s); if (FILTER_GREATER(cr, ra->sflag, r->ra.sflag)) { SIMPLE_COPY_VALUES((char *)&r->ra.s, &ra->s); - cr == 0 ? (r->ra.sflag = 0) : (r->ra.sflag = ra->sflag); + cr == 0 ? (r->ra.sflag |= ra->sflag) : (r->ra.sflag = ra->sflag); } cr = ctx->pCompareFunc(&r->ra.e, &ra->e); if (FILTER_GREATER(cr, r->ra.eflag, ra->eflag)) { SIMPLE_COPY_VALUES((char *)&r->ra.e, &ra->e); - cr == 0 ? (r->ra.eflag = 0) : (r->ra.eflag = ra->eflag); + cr == 0 ? (r->ra.eflag |= ra->eflag) : (r->ra.eflag = ra->eflag); break; } @@ -677,7 +677,7 @@ int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterC } if (g->unitNum > 0) { - taosArrayPush(res, g); + taosArrayPush(res, g); } } @@ -966,9 +966,9 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum) { - bool isnull = false, notnull = false; + bool isnull = false, notnull = false, isrange = false; int32_t num = 0; - + SFilterRMCtx *cur = NULL; SFilterUnit* u1 = FILTER_GROUP_UNIT(info, g, id1); SFilterUnit* u2 = FILTER_GROUP_UNIT(info, g, id2); uint8_t optr1 = FILTER_UNIT_OPTR(u1); @@ -976,12 +976,13 @@ int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_ uint16_t cidx = FILTER_UNIT_COL_IDX(u1); int32_t type = FILTER_UNIT_DATA_TYPE(u1); - SFilterRMCtx *cur = filterInitMergeRange(type, 0); - SET_OPTR(optr1); - SET_OPTR(optr2); + SET_AND_OPTR(optr1); + SET_AND_OPTR(optr2); - CHK_JMP(CHK_OPTR()); + CHK_JMP(CHK_AND_OPTR()); + + cur = filterInitMergeRange(type, 0); if (!FILTER_NO_MERGE_OPTR(optr1)) { filterAddUnitRange(info, u1, cur, TSDB_RELATION_AND); @@ -1001,8 +1002,8 @@ int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_ ++(*removedNum); optr2 = FILTER_UNIT_OPTR(u); - SET_OPTR(optr2); - CHK_JMP(CHK_OPTR()); + SET_AND_OPTR(optr2); + CHK_JMP(CHK_AND_OPTR()); if (!FILTER_NO_MERGE_OPTR(optr2)) { filterAddUnitRange(info, u, cur, TSDB_RELATION_AND); @@ -1053,17 +1054,18 @@ int32_t filterProcessUnits(SFilterInfo *info, SFilterGroupCtx*** res) { SFilterGroupCtx *gctx = NULL; SArray *colRange = NULL; bool gresUsed = false; + bool colInit = false; uint16_t removedNum = 0; for (uint16_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; - if (col == NULL) { - col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); - } else { - memset(col, 0, info->fields[FLD_TYPE_COLUMN].num * sizeof(int32_t)); + if (g->unitNum <= 1) { + continue; } + gresUsed = false; + colInit = false; removedNum = 0; @@ -1073,6 +1075,16 @@ int32_t filterProcessUnits(SFilterInfo *info, SFilterGroupCtx*** res) { if (FILTER_NO_MERGE_DATA_TYPE(type)) { continue; } + + if (colInit == false) { + if (col == NULL) { + col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); + } else { + memset(col, 0, info->fields[FLD_TYPE_COLUMN].num * sizeof(int32_t)); + } + + colInit = true; + } uint16_t cidx = FILTER_UNIT_COL_IDX(u); @@ -1171,7 +1183,7 @@ int32_t filterProcessGroupsSameColumn(SFilterInfo *info, uint16_t id1, uint16_t if (cra->notNull) { notnull = true; - CHK_JMP(CHK_OPTR()); + CHK_JMP(CHK_OR_OPTR()); } cidx2 = cra->idx; @@ -1202,21 +1214,21 @@ int32_t filterProcessGroupsSameColumn(SFilterInfo *info, uint16_t id1, uint16_t filterAddMergeRange(cur, &cra->ra, TSDB_RELATION_OR); if (MR_EMPTY_RES(cur)) { notnull = true; - CHK_JMP(CHK_OPTR()); + CHK_JMP(CHK_OR_OPTR()); } continue; } optr = FILTER_UNIT_OPTR(u1); - SET_OPTR(optr); - CHK_JMP(CHK_OPTR()); + SET_OR_OPTR(optr); + CHK_JMP(CHK_OR_OPTR()); if (!FILTER_NO_MERGE_OPTR(optr) && notnull == false) { filterAddUnitRange(info, u1, cur, TSDB_RELATION_OR); if (MR_EMPTY_RES(cur)) { notnull = true; - CHK_JMP(CHK_OPTR()); + CHK_JMP(CHK_OR_OPTR()); } } } @@ -1234,36 +1246,41 @@ int32_t filterProcessGroupsSameColumn(SFilterInfo *info, uint16_t id1, uint16_t if (!notnull) { filterGetMergeRangeNum(cur, &num); - if (num > 1) { - ra = calloc(num, sizeof(*ra)); - } else { - assert(num == 1); - ra = &ncra.ra; - } + if (num > 0) { + if (num > 1) { + ra = calloc(num, sizeof(*ra)); + } else { + ra = &ncra.ra; + } - filterGetMergeRangeRes(cur, ra); + filterGetMergeRangeRes(cur, ra); - SFilterRange *tra = ra; - for (int32_t i = 0; i < num; ++i) { - filterPostProcessRange(cur, tra, &ncra.notNull); - assert(ncra.notNull == false); - ++tra; - } - - if (num > 1) { + SFilterRange *tra = ra; for (int32_t i = 0; i < num; ++i) { - FILTER_COPY_RA(&ncra.ra, ra); - - taosArrayPush(res, &ncra); + filterPostProcessRange(cur, tra, &ncra.notNull); + assert(ncra.notNull == false); + ++tra; + } - ++ra; + if (num > 1) { + for (int32_t i = 0; i < num; ++i) { + FILTER_COPY_RA(&ncra.ra, ra); + + taosArrayPush(res, &ncra); + + ++ra; + } + } else { + taosArrayPush(res, &ncra); } } else { - FILTER_COPY_RA(&ncra.ra, ra); - + ncra.ra.sflag = RA_NULL; + ncra.ra.eflag = RA_NULL; taosArrayPush(res, &ncra); } } else { + ncra.ra.sflag = RA_NULL; + ncra.ra.eflag = RA_NULL; taosArrayPush(res, &ncra); } @@ -1286,11 +1303,17 @@ int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilte int32_t *col = NULL; uint16_t cidx; uint16_t removedNum = 0; + bool merged = false; SArray *colRange = NULL; for (uint16_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; - uint16_t unitNum = (unitRes && unitRes[i]) ? unitRes[i]->num : g->unitNum; + uint16_t unitNum = g->unitNum; + + if (unitRes && unitRes[i]) { + unitNum = unitRes[i]->num; + merged = true; + } if (unitNum == 0) { ++removedNum; @@ -1317,7 +1340,11 @@ int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilte } if (col == NULL) { - col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); + if (i < (info->groupNum - 1)) { + col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); + } else { + break; + } } if (col[cidx] == 0) { @@ -1351,7 +1378,7 @@ int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilte goto _err_return; } - if (colRange || removedNum > 0) { + if (colRange || removedNum > 0 || merged) { groupRes->num = num; groupRes->col = col; groupRes->colRange = colRange; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 52918a8658..b6f0e76db1 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1520,6 +1520,206 @@ if $data20 != @21-05-05 18:19:10.000@ then return -1 endi +sql select * from stb1 where c1 is null and c1 is not null; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is not null; +if $rows != 29 then + return -1 +endi +sql select * from stb1 where c1 is null or c1 > 20 or c1 < 25; +if $rows != 29 then + return -1 +endi +sql select * from stb1 where (c1 > 20 or c1 < 25) and c1 is null; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where (c1 > 20 or c1 < 25) and (c1 > 62 or c1 < 3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 11 and c1 != 11 and c1 != 14 and c1 < 14; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 or c1 >= 62; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 >= 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 >= 62 and c1 != 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 >= 62 or c1 != 62; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 >= 62 and c1 = 62; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 != 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 = 62; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is not null and c1 is not null; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 is not null or c1 is not null; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 is null and c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where c2 > 3 and c2 < 3; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c2 = 3; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where c2 > 3 and c2 <= 3; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c2 >= 3 and c2 <= 3; +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) and (c1 != 51 and c1 <= 54 and c1 != 54 and c1 >=1 and c1 != 1) and (c1 >= 11 and c1 <=52 and c1 != 52 and c1 != 11); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 1 and c1 is not null and c1 < 5; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi print "ts test" From 2f87a6ee443800fe015cedad2fd87e9ecef6a445 Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 15 Jul 2021 13:23:34 +0800 Subject: [PATCH 019/100] support in --- src/query/src/qFilter.c | 185 +++++++++++++++------- src/util/inc/hash.h | 2 + src/util/src/hash.c | 6 + tests/script/general/parser/condition.sim | 17 ++ 4 files changed, 154 insertions(+), 56 deletions(-) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 95bbdc5677..627f7eb13f 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -585,13 +585,55 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { -int32_t filterAddUnitFromNode(SFilterInfo *info, tExprNode* tree) { +int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *group) { SFilterFieldId left = {0}, right = {0}; - + filterAddFieldFromNode(info, tree->_node.pLeft, &left); - filterAddFieldFromNode(info, tree->_node.pRight, &right); - - filterAddUnit(info, tree->_node.optr, &left, &right); + + tVariant* var = tree->_node.pRight->pVal; + int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); + + if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { + void *data = NULL; + convertFilterSetFromBinary((void **)&data, var->pz, var->nLen, type); + CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); + + void *p = taosHashIterate((SHashObj *)data, NULL); + while(p) { + void *key = taosHashGetDataKey((SHashObj *)data, p); + void *fdata = NULL; + + if (IS_VAR_DATA_TYPE(type)) { + uint32_t len = taosHashGetDataKeyLen((SHashObj *)data, p); + fdata = malloc(len + VARSTR_HEADER_SIZE); + varDataLen(fdata) = len; + memcpy(varDataVal(fdata), key, len); + } else { + fdata = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(fdata, key); + } + + filterAddField(info, NULL, fdata, FLD_TYPE_VALUE, &right); + + filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right); + + SFilterGroup fgroup = {0}; + filterAddUnitToGroup(&fgroup, info->unitNum - 1); + + taosArrayPush(group, &fgroup); + + p = taosHashIterate((SHashObj *)data, p); + } + } else { + filterAddFieldFromNode(info, tree->_node.pRight, &right); + + filterAddUnit(info, tree->_node.optr, &left, &right); + + SFilterGroup fgroup = {0}; + filterAddUnitToGroup(&fgroup, info->unitNum - 1); + + taosArrayPush(group, &fgroup); + } return TSDB_CODE_SUCCESS; } @@ -611,6 +653,7 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, &right); } + int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterColRange *cra, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right; @@ -633,53 +676,88 @@ int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterC assert(!((FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) && (FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)))); + if ((!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL))) { + int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); + __compar_fn_t func = getComparFunc(type, 0); + if (func(&cra->ra.s, &cra->ra.e) == 0) { + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &cra->ra.s); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); + return filterAddUnitToGroup(g, dst->unitNum - 1); + } + } + if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &cra->ra.s); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); filterAddUnitToGroup(g, dst->unitNum - 1); } if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &cra->ra.e); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); filterAddUnitToGroup(g, dst->unitNum - 1); } - } else { - SFilterGroup ng = {0}; - g = &ng; - - if (cra->isNull) { - filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); - taosArrayPush(res, g); - } - - if (cra->notNull) { - memset(g, 0, sizeof(*g)); - - filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); - taosArrayPush(res, g); - } + return TSDB_CODE_SUCCESS; + } + + // OR PROCESS + + SFilterGroup ng = {0}; + g = &ng; + + if (cra->isNull) { + filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); + filterAddUnitToGroup(g, dst->unitNum - 1); + taosArrayPush(res, g); + } + + if (cra->notNull) { memset(g, 0, sizeof(*g)); - if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); - } - - if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); - } + filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); + filterAddUnitToGroup(g, dst->unitNum - 1); + taosArrayPush(res, g); + } - if (g->unitNum > 0) { + memset(g, 0, sizeof(*g)); + + if ((!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL))) { + int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); + __compar_fn_t func = getComparFunc(type, 0); + if (func(&cra->ra.s, &cra->ra.e) == 0) { + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &cra->ra.s); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + taosArrayPush(res, g); + return TSDB_CODE_SUCCESS; } } + + if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { + filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (g->unitNum > 0) { + taosArrayPush(res, g); + } return TSDB_CODE_SUCCESS; } @@ -725,12 +803,8 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } - filterAddUnitFromNode(info, tree); + filterAddGroupUnitFromNode(info, tree, group); - SFilterGroup fgroup = {0}; - filterAddUnitToGroup(&fgroup, info->unitNum - 1); - - taosArrayPush(group, &fgroup); _err_return: @@ -778,15 +852,21 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { SFilterUnit *unit = &info->units[i]; int32_t type = FILTER_UNIT_DATA_TYPE(unit); int32_t len = 0; - char str[128]; + int32_t tlen = 0; + char str[128] = {0}; SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SSchema *sch = left->desc; len = sprintf(str, "UNIT[%d] => [%d][%s] %s [", i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str); - if (unit->right.type== FLD_TYPE_VALUE) { + if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != TSDB_RELATION_IN) { SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); - converToStr(str + len, type, right->data, 0, &len); + char *data = right->data; + if (IS_VAR_DATA_TYPE(type)) { + tlen = varDataLen(data); + data += VARSTR_HEADER_SIZE; + } + converToStr(str + len, type, data, tlen, &tlen); } else { strcat(str, "NULL"); } @@ -831,6 +911,11 @@ int32_t filterInitValFieldData(SFilterInfo *info) { tVariant* var = fi->desc; + if (var == NULL) { + assert(fi->data != NULL); + continue; + } + if (unit->compare.optr == TSDB_RELATION_IN) { convertFilterSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); @@ -942,18 +1027,6 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, SIMPLE_COPY_VALUES(&ra.s, val); SIMPLE_COPY_VALUES(&ra.e, val); break; - case TSDB_RELATION_IN: { - void *p = taosHashIterate((SHashObj *)val, NULL); - while(p) { - void *key = taosHashGetDataKey((SHashObj *)val, p); - SIMPLE_COPY_VALUES(&ra.s, key); - SIMPLE_COPY_VALUES(&ra.e, key); - filterAddMergeRange(ctx, &ra, optr); - p = taosHashIterate((SHashObj *)val, p); - } - - return TSDB_CODE_SUCCESS; - } default: assert(0); } diff --git a/src/util/inc/hash.h b/src/util/inc/hash.h index 79eda33e74..57c69f7beb 100644 --- a/src/util/inc/hash.h +++ b/src/util/inc/hash.h @@ -163,6 +163,8 @@ void taosHashCancelIterate(SHashObj *pHashObj, void *p); void *taosHashGetDataKey(SHashObj *pHashObj, void *data); +uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data); + #ifdef __cplusplus } #endif diff --git a/src/util/src/hash.c b/src/util/src/hash.c index a3501d47da..27091b1fe8 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -699,6 +699,12 @@ FORCE_INLINE void *taosHashGetDataKey(SHashObj *pHashObj, void *data) { return GET_HASH_NODE_KEY(GET_HASH_PNODE(data)); } +FORCE_INLINE uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data) { + SHashNode * node = GET_HASH_PNODE(data); + return node->keyLen; +} + + // release the pNode, return next pNode, and lock the current entry static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index b6f0e76db1..54e64c01dc 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1696,6 +1696,23 @@ if $data00 != @21-05-05 18:19:02.000@ then return -1 endi +sql select * from stb1 where (c2 in (1,2,3,4) or c2 in (11,12,13,14)) and c2 != 11 and c2 >2 and c2 != 14; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:06.000@ then + return -1 +endi + sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) and (c1 != 51 and c1 <= 54 and c1 != 54 and c1 >=1 and c1 != 1) and (c1 >= 11 and c1 <=52 and c1 != 52 and c1 != 11); if $rows != 2 then return -1 From 8756467972177f35730be8240d65bd9e7b1ba1cc Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 15 Jul 2021 16:11:21 +0800 Subject: [PATCH 020/100] support nchar filter in parent --- src/query/inc/qFilter.h | 1 + src/query/src/qFilter.c | 37 +++++++++++++- tests/script/general/parser/condition.sim | 59 +++++++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 73f86f3ff3..33a526fec5 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -188,6 +188,7 @@ typedef struct SFilterInfo { #define FILTER_GET_FIELD(i, id) (&((i)->fields[(id).type].fields[(id).idx])) #define FILTER_GET_COL_FIELD(i, idx) (&((i)->fields[FLD_TYPE_COLUMN].fields[idx])) #define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type) +#define FILTER_GET_COL_FIELD_SIZE(fi) (((SSchema *)((fi)->desc))->bytes) #define FILTER_GET_COL_FIELD_DESC(fi) ((SSchema *)((fi)->desc)) #define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 8c55b7fd94..8f1530551c 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1815,7 +1815,31 @@ _err_return: } -int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar) { +int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar) { + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + if (type == TSDB_DATA_TYPE_NCHAR) { + SFilterField nfi = {0}; + nfi.desc = fi->desc; + int32_t bytes = FILTER_GET_COL_FIELD_SIZE(fi); + nfi.data = malloc(rows * bytes); + int32_t bufSize = bytes - VARSTR_HEADER_SIZE; + for (int32_t j = 0; j < rows; ++j) { + char *src = FILTER_GET_COL_FIELD_DATA(fi, j); + char *dst = FILTER_GET_COL_FIELD_DATA(&nfi, j); + int32_t len = 0; + taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len); + varDataLen(dst) = len; + } + + fi->data = nfi.data; + + *gotNchar = true; + } + } + + #if 0 for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { @@ -1837,7 +1861,7 @@ int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *g return TSDB_CODE_SUCCESS; } -int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo) { +int32_t filterFreeNcharColumns(SFilterInfo* info) { #if 0 for (int32_t i = 0; i < numOfFilterCols; ++i) { if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { @@ -1850,6 +1874,15 @@ int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo) { } #endif + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + if (type == TSDB_DATA_TYPE_NCHAR) { + tfree(fi->data); + } + } + + return TSDB_CODE_SUCCESS; } diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 54e64c01dc..d414cb1554 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1200,6 +1200,31 @@ sql select * from stb1 where c1 is null and c2 is null and ts > '2021-05-05 18:1 if $rows != 0 then return -1 endi + +sql select * from stb1 where c1 is null and c1 > 0; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is not null or c1 > 1; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 is null or c1 > 40) and c1 < 44; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:18.000@ then + return -1 +endi + sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; if $rows != 4 then return -1 @@ -1738,6 +1763,20 @@ if $data20 != @21-05-05 18:19:03.000@ then return -1 endi +sql select * from (select * from stb1 where c2 > 10 and c6 < 40) where c9 in ('11','21','31'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' @@ -2036,6 +2075,26 @@ if $data50 != @21-05-05 18:19:14.000@ then return -1 endi +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + print "tbname test" sql_error select * from stb1 where tbname like '%3' and tbname like '%4'; From 375847cad65c8db0216da94ff0084f093052226e Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 16 Jul 2021 08:13:06 +0800 Subject: [PATCH 021/100] support nchar filter --- src/query/src/qFilter.c | 91 ++++++++++++++++++++++- tests/script/general/parser/condition.sim | 39 ++++++++++ 2 files changed, 127 insertions(+), 3 deletions(-) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 8f1530551c..fa26d652fe 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1470,7 +1470,7 @@ _err_return: return TSDB_CODE_SUCCESS; } -int32_t filterGenerateGroupFromArray(SFilterInfo *info, SArray* group) { +int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { size_t groupSize = taosArrayGetSize(group); info->groupNum = (uint16_t)groupSize; @@ -1488,6 +1488,89 @@ int32_t filterGenerateGroupFromArray(SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } +int32_t filterCheckRangeCoverage(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { + if (gctx->num == 0) { + return TSDB_CODE_SUCCESS; + } + + SFilterInfo oinfo = *info; + uint16_t gNum = 0; + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + + memset(info, 0, sizeof(*info)); + + filterInitUnitsFields(info); + + for (uint16_t i = 0; i < oinfo.groupNum; ++i) { + SFilterGroup* g = oinfo.groups + i; + SFilterGroup ng = {0}; + uint16_t unitNum = (uctx && uctx[i]) ? uctx[i]->num : g->unitNum; + + if (unitNum == 0) { + continue; + } + + ++gNum; + + if ((uctx == NULL) || (uctx[i] == NULL)) { + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + + taosArrayPush(group, &ng); + + continue; + } + + SFilterGroupCtx* ctx = uctx[i]; + for (uint16_t n = 0; n < g->unitNum; ++n) { + SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); + int32_t type = FILTER_UNIT_DATA_TYPE(u); + if (FILTER_NO_MERGE_DATA_TYPE(type)) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + continue; + } + + uint16_t cidx = FILTER_UNIT_COL_IDX(u); + + assert(ctx->col[cidx] > 0 || ctx->col[cidx] == -1); + + if (ctx->col[cidx] != -1) { + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + } + + if (ctx->colRange && taosArrayGetSize(ctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(ctx->colRange); + for (int32_t m = 0; m < size; ++m) { + SFilterColRange *cra = taosArrayGet(ctx->colRange, m); + filterAddGroupUnitFromRange(info, &oinfo, cra, &ng, TSDB_RELATION_AND, NULL); + } + } + + taosArrayPush(group, &ng); + } + + if (gctx->colRange && taosArrayGetSize(gctx->colRange) > 0) { + int32_t size = (int32_t)taosArrayGetSize(gctx->colRange); + for (int32_t i = 0; i < size; ++i) { + SFilterColRange *cra = taosArrayGet(gctx->colRange, i); + filterAddGroupUnitFromRange(info, &oinfo, cra, NULL, TSDB_RELATION_OR, group); + } + } + + filterConvertGroupFromArray(info, group); + + taosArrayDestroy(group); + + return TSDB_CODE_SUCCESS; +} + + int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { if (gctx->num == 0) { @@ -1564,7 +1647,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx* } } - filterGenerateGroupFromArray(info, group); + filterConvertGroupFromArray(info, group); taosArrayDestroy(group); @@ -1590,6 +1673,8 @@ int32_t filterPreprocess(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } + filterCheckRangeCoverage(info, &groupRes, unitsRes); + //TODO GET COLUMN RANGE filterRewrite(info, &groupRes, unitsRes); @@ -1699,7 +1784,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option ERR_JRET(code); - filterGenerateGroupFromArray(info, group); + filterConvertGroupFromArray(info, group); ERR_JRET(filterInitValFieldData(info)); diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index d414cb1554..8048ccc192 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -93,6 +93,12 @@ sql_error select ts,c1,c7 from stb1 where c7 > false sql_error select * from stb1 where c1 > NULL; sql_error select * from stb1 where c1 = NULL; sql_error select * from stb1 where c1 LIKE '%1'; +sql_error select * from stb1 where c2 LIKE '%1'; +sql_error select * from stb1 where c3 LIKE '%1'; +sql_error select * from stb1 where c4 LIKE '%1'; +sql_error select * from stb1 where c5 LIKE '%1'; +sql_error select * from stb1 where c6 LIKE '%1'; +sql_error select * from stb1 where c7 LIKE '%1'; sql_error select * from stb1 where c1 = 'NULL'; sql_error select * from stb1 where c2 > 'NULL'; sql_error select * from stb1 where c3 <> 'NULL'; @@ -1225,6 +1231,39 @@ if $data20 != @21-05-05 18:19:18.000@ then return -1 endi +sql select * from stb1 where c1 in (11,21,31,41) and c1 in (11,42); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c8 in ('11','21','31','41') and c8 in ('11','42'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; if $rows != 4 then return -1 From d5a8aedb34e770a7d1ef47b889124d6a13f4257b Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 16 Jul 2021 14:24:12 +0800 Subject: [PATCH 022/100] refact code --- src/query/inc/qFilter.h | 22 +- src/query/src/qFilter.c | 285 ++++++++++++---------- tests/script/general/parser/condition.sim | 2 +- 3 files changed, 179 insertions(+), 130 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 33a526fec5..ad4e5bba1a 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -57,6 +57,11 @@ enum { FILTER_NO_REWRITE = 4, }; +enum { + RANGE_TYPE_UNIT = 1, + RANGE_TYPE_COL_RANGE, +}; + typedef struct OptrStr { uint16_t optr; char *str; @@ -117,12 +122,18 @@ typedef struct SFilterGroup { uint8_t *unitFlags; // !unit result } SFilterGroup; +typedef struct SFilterColInfo { + uint8_t type; + void *info; +} SFilterColInfo; + typedef struct SFilterGroupCtx { - uint16_t num; - int32_t *col; - SArray *colRange; + uint16_t colNum; + uint16_t *colIdx; + SArray **colInfo; } SFilterGroupCtx; + typedef struct SFilterCompare { __compar_fn_t pCompareFunc; int32_t type; @@ -195,6 +206,11 @@ typedef struct SFilterInfo { #define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) #define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) + +#define FILTER_PUSH_UNIT(colInfo, u) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_UNIT; _info->info = u; taosArrayPush((SArray *)(colInfo), &_info);} while (0) +#define FILTER_PUSH_RANGE(colInfo, cra) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_COL_RANGE; _info->info = cra; taosArrayPush((SArray *)(colInfo), &_info);} while (0) +#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint16_t) * n); memcpy(*(dst), src, sizeof(uint16_t) * n);} while (0) + #define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) #define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) #define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index fa26d652fe..986d0672fb 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -58,6 +58,14 @@ filter_desc_compare_func gDescCompare [FLD_TYPE_MAX] = { }; +static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { + SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); + if (left->colNum > right->colNum) return 1; + if (left->colNum < right->colNum) return -1; + return 0; +} + + int32_t filterInitUnitsFields(SFilterInfo *info) { info->unitSize = FILTER_DEFAULT_UNIT_SIZE; info->units = calloc(info->unitSize, sizeof(SFilterUnit)); @@ -886,6 +894,28 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { } } +void filterFreeGroupCtx(SFilterGroupCtx* gRes) { + if (gRes == NULL) { + return; + } + + tfree(gRes->colIdx); + + int16_t i = 0, j = 0; + + while (i < gRes->colNum) { + if (gRes->colInfo[j]) { + taosArrayDestroy(gRes->colInfo[j]); + ++i; + } + + ++j; + } + + tfree(gRes->colInfo); + tfree(gRes); +} + void filterFreeInfo(SFilterInfo *info) { CHK_RETV(info == NULL); @@ -1038,72 +1068,50 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, -int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum) { +int32_t filterMergeBetweenColumns(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colIdx) { bool isnull = false, notnull = false, isrange = false; int32_t num = 0; - SFilterRMCtx *cur = NULL; - SFilterUnit* u1 = FILTER_GROUP_UNIT(info, g, id1); - SFilterUnit* u2 = FILTER_GROUP_UNIT(info, g, id2); - uint8_t optr1 = FILTER_UNIT_OPTR(u1); - uint8_t optr2 = FILTER_UNIT_OPTR(u2); - uint16_t cidx = FILTER_UNIT_COL_IDX(u1); - - int32_t type = FILTER_UNIT_DATA_TYPE(u1); - - SET_AND_OPTR(optr1); - SET_AND_OPTR(optr2); + SArray* colArray = gRes->colInfo[colIdx]; + int32_t size = (int32_t)taosArrayGetSize(colArray); + SFilterRMCtx* cur = filterInitMergeRange(type, 0); - CHK_JMP(CHK_AND_OPTR()); + for (uint32_t i = 0; i < size; ++i) { + SFilterColInfo* colInfo = taosArrayGet(colArray, i); + SFilterUnit* u = colInfo->info; + int32_t type = FILTER_UNIT_DATA_TYPE(u); + uint8_t optr = FILTER_UNIT_OPTR(u); - cur = filterInitMergeRange(type, 0); - - if (!FILTER_NO_MERGE_OPTR(optr1)) { - filterAddUnitRange(info, u1, cur, TSDB_RELATION_AND); - } - - if (!FILTER_NO_MERGE_OPTR(optr2)) { - filterAddUnitRange(info, u2, cur, TSDB_RELATION_AND); - CHK_JMP(MR_EMPTY_RES(cur)); - } - - - for (int32_t i = id2 + 1; i < g->unitNum; ++i) { - SFilterUnit* u = FILTER_GROUP_UNIT(info, g, i); - if (cidx != FILTER_UNIT_COL_IDX(u)) { - continue; - } - - ++(*removedNum); - optr2 = FILTER_UNIT_OPTR(u); - SET_AND_OPTR(optr2); + SET_AND_OPTR(optr); CHK_JMP(CHK_AND_OPTR()); - - if (!FILTER_NO_MERGE_OPTR(optr2)) { + + if (!FILTER_NO_MERGE_OPTR(optr)) { filterAddUnitRange(info, u, cur, TSDB_RELATION_AND); CHK_JMP(MR_EMPTY_RES(cur)); } } - SFilterColRange cra = {0}; - cra.idx = cidx; + SFilterColRange *cra = calloc(1, sizeof(*cra)); + cra->idx = colIdx; filterGetMergeRangeNum(cur, &num); assert(num == 1 || num == 0); if (num == 1) { - filterGetMergeRangeRes(cur, &cra.ra); - filterPostProcessRange(cur, &cra.ra, &cra.notNull); + filterGetMergeRangeRes(cur, &cra->ra); + filterPostProcessRange(cur, &cra->ra, &cra->notNull); } else { if (isnull) { - cra.isNull = true; + cra->isNull = true; } if (notnull) { - cra.notNull = true; + cra->notNull = true; } } - taosArrayPush(res, &cra); + taosArrayClear(colArray); + + FILTER_PUSH_RANGE(colArray, cra); filterFreeMergeRange(cur); @@ -1111,9 +1119,8 @@ int32_t filterProcessUnitsInOneGroup(SFilterInfo *info, SFilterGroup* g, uint16_ _err_return: - g->unitNum = 0; - - *removedNum = g->unitNum; + taosArrayDestroy(colArray); + gRes->colInfo[colIdx] = NULL; filterFreeMergeRange(cur); @@ -1122,97 +1129,76 @@ _err_return: } -int32_t filterProcessUnits(SFilterInfo *info, SFilterGroupCtx*** res) { - int32_t *col = NULL; - SFilterGroupCtx *gctx = NULL; - SArray *colRange = NULL; - bool gresUsed = false; - bool colInit = false; - uint16_t removedNum = 0; +int32_t filterMergeBetweenUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { + bool emptyGroup = false; + uint16_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint16_t)); + uint16_t colIdxi = 0; + uint16_t gResIdx = 0; for (uint16_t i = 0; i < info->groupNum; ++i) { SFilterGroup* g = info->groups + i; - if (g->unitNum <= 1) { - continue; - } - - gresUsed = false; - colInit = false; - - removedNum = 0; + gRes[gResIdx] = calloc(1, sizeof(SFilterGroupCtx)); + gRes[gResIdx]->colInfo = calloc(info->fields[FLD_TYPE_COLUMN].num, POINTER_BYTES); + colIdxi = 0; + emptyGroup = false; for (uint16_t j = 0; j < g->unitNum; ++j) { SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); - int32_t type = FILTER_UNIT_DATA_TYPE(u); - if (FILTER_NO_MERGE_DATA_TYPE(type)) { - continue; - } + uint16_t cidx = FILTER_UNIT_COL_IDX(u); - if (colInit == false) { - if (col == NULL) { - col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); - } else { - memset(col, 0, info->fields[FLD_TYPE_COLUMN].num * sizeof(int32_t)); - } - - colInit = true; + if (gRes[gResIdx]->colInfo[cidx] == NULL) { + gRes[gResIdx]->colInfo[cidx] = (SArray *)taosArrayInit(4, POINTER_BYTES); + colIdx[colIdxi++] = cidx; + ++gRes[gResIdx]->colNum; } - uint16_t cidx = FILTER_UNIT_COL_IDX(u); - - if (col[cidx] == 0) { - col[cidx] = j + 1; - } else if (col[cidx] == -1) { + FILTER_PUSH_UNIT(gRes[gResIdx]->colInfo[cidx], u); + } + + if (colIdxi > 1) { + qsort(colIdx, colIdxi, sizeof(uint16_t), compareUint16Val); + } + + for (uint16_t l = 0; l < colIdxi; ++l) { + SArray* colArray = gRes[gResIdx]->colInfo[colIdx[l]]; + int32_t size = (int32_t)taosArrayGetSize(colArray); + + if (size <= 1) { continue; - } else { - if (colRange == NULL) { - colRange = taosArrayInit(4, sizeof(SFilterColRange)); - } + } - removedNum += 2; + SFilterColInfo* colInfo = taosArrayGet(colArray, 0); + SFilterUnit* u = colInfo->info; + int32_t type = FILTER_UNIT_DATA_TYPE(u); - filterProcessUnitsInOneGroup(info, g, col[cidx] - 1, j, colRange, &removedNum); + if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + continue; + } - col[cidx] = -1; + filterMergeBetweenColumns(info, gRes[gResIdx], colIdx[l]); - if (g->unitNum == 0) { - break; - } else { - gresUsed = true; - } + if (gRes[gResIdx]->colInfo[colIdx[l]] == NULL) { + emptyGroup = true; + break; } } - if (g->unitNum == 0) { - if (gresUsed) { - taosArrayClear(colRange); - } - + if (emptyGroup) { + filterFreeGroupCtx(gRes[gResIdx]); + gRes[gResIdx] = NULL; + continue; } - - if (gresUsed) { - gctx = malloc(sizeof(*gctx)); - gctx->num = g->unitNum - removedNum + 1; - gctx->col = col; - gctx->colRange = colRange; - - col = NULL; - colRange = NULL; - - if (*res == NULL) { - *res = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); - } - - (*res)[i] = gctx; - } + + gRes[gResIdx]->colNum = colIdxi; + FILTER_COPY_IDX(&gRes[gResIdx]->colIdx, colIdx, colIdxi); + ++gResIdx; } - tfree(col); - if (colRange) { - taosArrayDestroy(colRange); - } + tfree(colIdx); + + *gResNum = gResIdx; return TSDB_CODE_SUCCESS; } @@ -1220,7 +1206,7 @@ int32_t filterProcessUnits(SFilterInfo *info, SFilterGroupCtx*** res) { -int32_t filterProcessGroupsSameColumn(SFilterInfo *info, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum, SFilterGroupCtx** unitRes) { +int32_t filterMergeTwoGroups(SFilterInfo *info, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum, SFilterGroupCtx** unitRes) { bool isnull = false, notnull = false; int32_t num = 0; SFilterColRange *cra = NULL; @@ -1372,7 +1358,58 @@ _err_return: } -int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilterGroupCtx* groupRes) { +int32_t filterMergeBetweenGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gResNum) { + if (*gResNum <= 1) { + return TSDB_CODE_SUCCESS; + } + + qsort(gRes, *gResNum, POINTER_BYTES, filterCompareGroupCtx); + + int32_t pEnd = 0, cStart = 0, cEnd = 0; + uint16_t pColNum = 0, cColNum = 0; + int32_t movedNum = 0; + + cColNum = gRes[0]->colNum; + + for (int32_t i = 1; i < *gResNum; ++i) { + if (gRes[i]->colNum == cColNum) { + continue; + } + + cEnd = i - 1; + + movedNum = 0; + if (pColNum > 0) { + for (int32_t m = 0; m <= pEnd; ++m) { + for (int32_t n = cStart; n <= cEnd; ++n) { + filterMergeTwoGroups(&gRes[m], &gRes[n]); + + if (gRes[n] == NULL) { + memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + --cEnd; + --(*gResNum); + ++movedNum; + } + } + } + } + + for (int32_t m = cStart; m <= cEnd; ++m) { + for (int32_t n = cStart + 1; n <= cEnd; ++n) { + filterMergeTwoGroups(&gRes[m], &gRes[n]); + } + } + + pColNum = cColNum; + pEnd = cEnd; + + i -= movedNum; + cStart = i; + cEnd = i; + cColNum = gRes[i]->colNum; + } + + int32_t *col = NULL; uint16_t cidx; uint16_t removedNum = 0; @@ -1462,10 +1499,7 @@ int32_t filterProcessGroups(SFilterInfo *info, SFilterGroupCtx** unitRes, SFilte return TSDB_CODE_SUCCESS; _err_return: - tfree(col); - if (colRange) { - taosArrayDestroy(colRange); - } + tfree(gColNum); return TSDB_CODE_SUCCESS; } @@ -1656,12 +1690,13 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx* int32_t filterPreprocess(SFilterInfo *info) { - SFilterGroupCtx** unitsRes = NULL; + SFilterGroupCtx** gRes = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); + int32_t gResNum = 0; SFilterGroupCtx groupRes = {0}; - filterProcessUnits(info, &unitsRes); + filterMergeBetweenUnits(info, gRes, &gResNum); - filterProcessGroups(info, unitsRes, &groupRes); + filterMergeBetweenGroups(info, gRes, gResNum); if (FILTER_GET_FLAG(info->flags, FILTER_ALL)) { qInfo("Final - FilterInfo: [ALL]"); @@ -1673,8 +1708,6 @@ int32_t filterPreprocess(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - filterCheckRangeCoverage(info, &groupRes, unitsRes); - //TODO GET COLUMN RANGE filterRewrite(info, &groupRes, unitsRes); diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index 8048ccc192..c2b0f2e0f6 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -1247,7 +1247,7 @@ if $data00 != @21-05-05 18:19:04.000@ then return -1 endi -sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); +xxx sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); if $rows != 4 then return -1 endi From e270cf3742f6744188cd47bfb818c06967283898 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 21 Jul 2021 17:56:44 +0800 Subject: [PATCH 023/100] code refact --- src/client/src/tscSQLParser.c | 2 +- src/query/inc/qFilter.h | 71 +- src/query/src/qFilter.c | 1104 +++++++++++---------- src/query/tests/rangeMergeTest.cpp | 2 +- tests/script/general/parser/condition.sim | 14 +- 5 files changed, 632 insertions(+), 561 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 6380850188..919dc392ed 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5051,7 +5051,7 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr goto _ret; } - ret = filterInitFromTree(p, &filter, FILTER_NO_REWRITE); + ret = filterInitFromTree(p, &filter, FI_OPTION_NO_REWRITE|FI_OPTION_TIMESTAMP); if (ret != TSDB_CODE_SUCCESS) { goto _ret; } diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index ad4e5bba1a..ebf0fda55b 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -38,12 +38,8 @@ enum { enum { MR_ST_START = 1, MR_ST_FIN = 2, - MR_ALL = 4, - MR_NONE = 8, -}; - -enum { - MR_OPT_TS = 1, + MR_ST_ALL = 4, + MR_ST_EMPTY = 8, }; enum { @@ -52,14 +48,21 @@ enum { }; enum { - FILTER_ALL = 1, - FILTER_NONE = 2, - FILTER_NO_REWRITE = 4, + FI_OPTION_NO_REWRITE = 1, + FI_OPTION_TIMESTAMP = 2, + FI_OPTION_NEED_UNIQE = 4, +}; + +enum { + FI_STATUS_ALL = 1, + FI_STATUS_EMPTY = 2, + FI_STATUS_REWRITE = 4, }; enum { RANGE_TYPE_UNIT = 1, - RANGE_TYPE_COL_RANGE, + RANGE_TYPE_COL_RANGE = 2, + RANGE_TYPE_MR_CTX = 3, }; typedef struct OptrStr { @@ -78,6 +81,7 @@ typedef struct SFilterColRange { uint16_t idx; //column field idx bool isNull; bool notNull; + bool isRange; SFilterRange ra; } SFilterColRange; @@ -91,7 +95,10 @@ typedef struct SFilterRangeNode { typedef struct SFilterRMCtx { int32_t type; int32_t options; - int8_t status; + int8_t status; + bool isnull; + bool notnull; + bool isrange; __compar_fn_t pCompareFunc; SFilterRangeNode *rf; //freed SFilterRangeNode *rs; @@ -124,15 +131,20 @@ typedef struct SFilterGroup { typedef struct SFilterColInfo { uint8_t type; + int32_t dataType; void *info; } SFilterColInfo; typedef struct SFilterGroupCtx { - uint16_t colNum; - uint16_t *colIdx; - SArray **colInfo; + uint16_t colNum; + uint16_t *colIdx; + SFilterColInfo *colInfo; } SFilterGroupCtx; +typedef struct SFilterColCtx { + uint16_t colIdx; + void* ctx; +} SFilterColCtx; typedef struct SFilterCompare { __compar_fn_t pCompareFunc; @@ -146,8 +158,15 @@ typedef struct SFilterUnit { SFilterFieldId right; } SFilterUnit; +typedef struct SFilterPCtx { + SHashObj *colHash; + SHashObj *valHash; + SHashObj *unitHash; +} SFilterPCtx; + typedef struct SFilterInfo { - uint32_t flags; + uint32_t options; + uint32_t status; uint16_t unitSize; uint16_t unitNum; uint16_t groupNum; @@ -156,6 +175,7 @@ typedef struct SFilterInfo { SFilterUnit *units; uint8_t *unitRes; // result uint8_t *unitFlags; // got result + SFilterPCtx *pctx; } SFilterInfo; #define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) @@ -165,10 +185,10 @@ typedef struct SFilterInfo { #define MR_EMPTY_RES(ctx) (ctx->rs == NULL) -#define SET_AND_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!isrange) { notnull = true; } } else { isrange = true; notnull = false; } } while (0) -#define SET_OR_OPTR(o) do {if (o == TSDB_RELATION_ISNULL) { isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { notnull = true; } } while (0) -#define CHK_OR_OPTR() (isnull == true && notnull == true) -#define CHK_AND_OPTR() (isnull == true && ((notnull == true) || (isrange == true))) +#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0) +#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0) +#define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true) +#define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true))) #define FILTER_GET_FLAG(st, f) (st & f) @@ -206,11 +226,6 @@ typedef struct SFilterInfo { #define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) #define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) - -#define FILTER_PUSH_UNIT(colInfo, u) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_UNIT; _info->info = u; taosArrayPush((SArray *)(colInfo), &_info);} while (0) -#define FILTER_PUSH_RANGE(colInfo, cra) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_COL_RANGE; _info->info = cra; taosArrayPush((SArray *)(colInfo), &_info);} while (0) -#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint16_t) * n); memcpy(*(dst), src, sizeof(uint16_t) * n);} while (0) - #define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) #define FILTER_UNIT_LEFT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->left) #define FILTER_UNIT_RIGHT_FIELD(i, u) FILTER_GET_FIELD(i, (u)->right) @@ -227,6 +242,14 @@ typedef struct SFilterInfo { #define FILTER_UNIT_GET_R(i, idx) ((i)->unitRes[idx]) #define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v) +#define FILTER_PUSH_UNIT(colInfo, u) do { (colInfo).type = RANGE_TYPE_UNIT; (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u);taosArrayPush((SArray *)((colInfo).info), &u);} while (0) +#define FILTER_PUSH_RANGE(colInfo, cra) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_COL_RANGE; _info->info = cra; taosArrayPush((SArray *)(colInfo), &_info);} while (0) +#define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) + +#define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint16_t) * n); memcpy(*(dst), src, sizeof(uint16_t) * n);} while (0) + +#define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) + typedef int32_t(*filter_desc_compare_func)(const void *, const void *); diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 986d0672fb..99355103b9 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -122,6 +122,10 @@ int32_t filterResetMergeRangeCtx(SFilterRMCtx *ctx) { return TSDB_CODE_SUCCESS; } + ctx->isnull = false; + ctx->notnull = false; + ctx->isrange = false; + SFilterRangeNode *r = ctx->rf; while (r && r->next) { @@ -169,14 +173,35 @@ int32_t filterPostProcessRange(SFilterRMCtx *cur, SFilterRange *ra, bool *notNul return TSDB_CODE_SUCCESS; } +int32_t filterAddMergeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { + SFilterRMCtx *ctx = (SFilterRMCtx *)h; + + if (optr == TSDB_RELATION_AND) { + SET_AND_OPTR(ctx, raOptr); + if (CHK_AND_OPTR(ctx)) { + FILTER_SET_FLAG(ctx->status, MR_ST_EMPTY); + *empty = true; + } + } else { + SET_OR_OPTR(ctx, raOptr); + if (CHK_OR_OPTR(ctx)) { + FILTER_SET_FLAG(ctx->status, MR_ST_ALL); + *all = true; + } + } + + return TSDB_CODE_SUCCESS; +} + + int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; if (ctx->rs == NULL) { if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) - || (FILTER_GET_FLAG(ctx->status, MR_ALL) && (optr == TSDB_RELATION_AND)) - || ((!FILTER_GET_FLAG(ctx->status, MR_ALL)) && (optr == TSDB_RELATION_OR))) { + || (FILTER_GET_FLAG(ctx->status, MR_ST_ALL) && (optr == TSDB_RELATION_AND)) + || ((!FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) && (optr == TSDB_RELATION_OR))) { APPEND_RANGE(ctx, ctx->rs, ra); FILTER_SET_FLAG(ctx->status, MR_ST_START); } @@ -298,8 +323,12 @@ int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { bool notnull; filterPostProcessRange(ctx, &ctx->rs->ra, ¬null); if (notnull) { + bool all = false; FREE_FROM_RANGE(ctx, ctx->rs); - FILTER_SET_FLAG(ctx->status, MR_ALL); + filterAddMergeOptr(h, TSDB_RELATION_NOTNULL, optr, NULL, &all); + if (all) { + FILTER_SET_FLAG(ctx->status, MR_ST_ALL); + } } } @@ -322,10 +351,21 @@ int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { return filterAddMergeRangeImpl(h, ra, optr); } + int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { SFilterRMCtx *dctx = (SFilterRMCtx *)dst; SFilterRMCtx *sctx = (SFilterRMCtx *)src; + if (optr == TSDB_RELATION_AND) { + dctx->isnull &= sctx->isnull; + dctx->notnull &= sctx->notnull; + dctx->isrange &= sctx->isrange; + } else { + dctx->isnull |= sctx->isnull; + dctx->notnull |= sctx->notnull; + dctx->isrange |= sctx->isrange; + } + if (sctx->rs == NULL) { return TSDB_CODE_SUCCESS; } @@ -340,6 +380,33 @@ int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { return TSDB_CODE_SUCCESS; } +int32_t filterCopyMergeRangeCtx(void *dst, void *src) { + SFilterRMCtx *dctx = (SFilterRMCtx *)dst; + SFilterRMCtx *sctx = (SFilterRMCtx *)src; + + dctx->status = sctx->status; + + dctx->isnull = sctx->isnull; + dctx->notnull = sctx->notnull; + dctx->isrange = sctx->isrange; + + SFilterRangeNode *r = sctx->rs; + SFilterRangeNode *dr = dctx->rs; + + while (r) { + APPEND_RANGE(dctx, dr, &r->ra); + if (dr == NULL) { + dr = dctx->rs; + } else { + dr = dr->next; + } + r = r->next; + } + + return TSDB_CODE_SUCCESS; +} + + int32_t filterFinMergeRange(void* h) { SFilterRMCtx *ctx = (SFilterRMCtx *)h; @@ -348,7 +415,7 @@ int32_t filterFinMergeRange(void* h) { return TSDB_CODE_SUCCESS; } - if (FILTER_GET_FLAG(ctx->options, MR_OPT_TS)) { + if (FILTER_GET_FLAG(ctx->options, FI_OPTION_TIMESTAMP)) { SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; @@ -414,6 +481,41 @@ int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra) { return TSDB_CODE_SUCCESS; } + +int32_t filterSourceRangeFromCtx(SFilterRMCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) { + SFilterRMCtx *src = (SFilterRMCtx *)sctx; + + if (src->isnull){ + filterAddMergeOptr(ctx, TSDB_RELATION_ISNULL, optr, empty, all); + if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { + *all = true; + } + } + + if (src->notnull) { + filterAddMergeOptr(ctx, TSDB_RELATION_NOTNULL, optr, empty, all); + if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { + *all = true; + } + } + + if (src->isrange) { + filterAddMergeOptr(ctx, 0, optr, empty, all); + + if (!(optr == TSDB_RELATION_OR && ctx->notnull)) { + filterAddMergeRangeCtx(ctx, src, optr); + } + + if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { + *all = true; + } + } + + return TSDB_CODE_SUCCESS; +} + + + int32_t filterFreeMergeRange(void* h) { if (h == NULL) { return TSDB_CODE_SUCCESS; @@ -435,7 +537,7 @@ int32_t filterFreeMergeRange(void* h) { } -int32_t filterMergeGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { +int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { SFilterGroup gp = {0}; //TODO CHECK DUP @@ -453,7 +555,7 @@ int32_t filterMergeGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { } -int32_t filterMergeGroups(SArray* group, SArray* left, SArray* right) { +int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { int32_t leftSize = (int32_t)taosArrayGetSize(left); int32_t rightSize = (int32_t)taosArrayGetSize(right); @@ -466,7 +568,7 @@ int32_t filterMergeGroups(SArray* group, SArray* left, SArray* right) { for (int32_t r = 0; r < rightSize; ++r) { SFilterGroup *gp2 = taosArrayGet(right, r); - filterMergeGroup(gp1, gp2, group); + filterDetachCnfGroup(gp1, gp2, group); } } @@ -513,7 +615,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, return TSDB_CODE_SUCCESS; } -static FORCE_INLINE int32_t filterAddFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { +static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { filterAddField(info, field->desc, field->data, FILTER_GET_TYPE(field->flag), fid); FILTER_SET_FLAG(field->flag, FLD_DESC_NO_FREE); @@ -648,85 +750,105 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u) { - SFilterFieldId left, right; + SFilterFieldId left, right, *pright = &right; filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left); - filterAddField(dst, NULL, FILTER_UNIT_VAL_DATA(src, u), FLD_TYPE_VALUE, &right); - SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); FILTER_SET_FLAG(t->flag, FLD_DESC_NO_FREE); - t = FILTER_UNIT_RIGHT_FIELD(src, u); - FILTER_SET_FLAG(t->flag, FLD_DATA_NO_FREE); - return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, &right); + if (u->right.type == FLD_TYPE_VALUE) { + filterAddField(dst, NULL, FILTER_UNIT_VAL_DATA(src, u), FLD_TYPE_VALUE, &right); + t = FILTER_UNIT_RIGHT_FIELD(src, u); + FILTER_SET_FLAG(t->flag, FLD_DATA_NO_FREE); + } else { + pright = NULL; + } + + + return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright); } -int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterColRange *cra, SFilterGroup *g, int32_t optr, SArray *res) { +int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right; - SFilterField *col = FILTER_GET_COL_FIELD(src, cra->idx); + SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); - filterAddFieldFromField(dst, col, &left); + filterAddColFieldFromField(dst, col, &left); if (optr == TSDB_RELATION_AND) { - if (cra->isNull) { - assert(cra->notNull == false); + if (ctx->isnull) { + assert(ctx->notnull == false && ctx->isrange == false); filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); - return filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnitToGroup(g, dst->unitNum - 1); + return TSDB_CODE_SUCCESS; } - if (cra->notNull) { - assert(cra->isNull == false); + if (ctx->notnull) { + assert(ctx->isnull == false && ctx->isrange == false); filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); - return filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnitToGroup(g, dst->unitNum - 1); + return TSDB_CODE_SUCCESS; } - assert(!((FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) && (FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)))); + if (!ctx->isrange) { + assert(ctx->isnull || ctx->notnull); + return TSDB_CODE_SUCCESS; + } - if ((!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL))) { + assert(ctx->rs && ctx->rs->next == NULL); + + SFilterRange *ra = &ctx->rs->ra; + + assert(!((FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (FILTER_GET_FLAG(ra->eflag, RA_NULL)))); + + if ((!FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RA_NULL))) { int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); __compar_fn_t func = getComparFunc(type, 0); - if (func(&cra->ra.s, &cra->ra.e) == 0) { + if (func(&ra->s, &ra->e) == 0) { void *data = malloc(sizeof(int64_t)); - SIMPLE_COPY_VALUES(data, &cra->ra.s); + SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); - return filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnitToGroup(g, dst->unitNum - 1); + return TSDB_CODE_SUCCESS; } } - if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); - SIMPLE_COPY_VALUES(data, &cra->ra.s); + SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); filterAddUnitToGroup(g, dst->unitNum - 1); } - if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); - SIMPLE_COPY_VALUES(data, &cra->ra.e); + SIMPLE_COPY_VALUES(data, &ra->e); filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); + filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); filterAddUnitToGroup(g, dst->unitNum - 1); } - return TSDB_CODE_SUCCESS; + return TSDB_CODE_SUCCESS; } // OR PROCESS SFilterGroup ng = {0}; g = &ng; + + assert(ctx->isnull || ctx->notnull || ctx->isrange); - if (cra->isNull) { + if (ctx->isnull) { filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); filterAddUnitToGroup(g, dst->unitNum - 1); taosArrayPush(res, g); } - if (cra->notNull) { + if (ctx->notnull) { + assert(!ctx->isrange); memset(g, 0, sizeof(*g)); filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); @@ -734,38 +856,54 @@ int32_t filterAddGroupUnitFromRange(SFilterInfo *dst, SFilterInfo *src, SFilterC taosArrayPush(res, g); } - memset(g, 0, sizeof(*g)); + if (!ctx->isrange) { + assert(ctx->isnull || ctx->notnull); + g->unitNum = 0; + return TSDB_CODE_SUCCESS; + } - if ((!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL))) { - int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); - __compar_fn_t func = getComparFunc(type, 0); - if (func(&cra->ra.s, &cra->ra.e) == 0) { - void *data = malloc(sizeof(int64_t)); - SIMPLE_COPY_VALUES(data, &cra->ra.s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); - - taosArrayPush(res, g); - return TSDB_CODE_SUCCESS; + SFilterRangeNode *r = ctx->rs; + + while (r) { + memset(g, 0, sizeof(*g)); + + if ((!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RA_NULL))) { + int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); + __compar_fn_t func = getComparFunc(type, 0); + if (func(&r->ra.s, &r->ra.e) == 0) { + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &r->ra.s); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + + taosArrayPush(res, g); + + r = r->next; + continue; + } } - } - - if (!FILTER_GET_FLAG(cra->ra.sflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.s, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); - } - - if (!FILTER_GET_FLAG(cra->ra.eflag, RA_NULL)) { - filterAddField(dst, NULL, &cra->ra.e, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(cra->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + + if (!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { + filterAddField(dst, NULL, &r->ra.s, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + if (!FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { + filterAddField(dst, NULL, &r->ra.e, FLD_TYPE_VALUE, &right); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); + filterAddUnitToGroup(g, dst->unitNum - 1); + } + + assert (g->unitNum > 0); + + taosArrayPush(res, g); + + r = r->next; } - if (g->unitNum > 0) { - taosArrayPush(res, g); - } + g->unitNum = 0; return TSDB_CODE_SUCCESS; } @@ -796,7 +934,7 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { ERR_JRET(filterTreeToGroup(tree->_node.pLeft, info, leftGroup)); ERR_JRET(filterTreeToGroup(tree->_node.pRight, info, rightGroup)); - ERR_JRET(filterMergeGroups(group, leftGroup, rightGroup)); + ERR_JRET(filterDetachCnfGroups(group, leftGroup, rightGroup)); taosArrayDestroyEx(leftGroup, filterFreeGroup); taosArrayDestroyEx(rightGroup, filterFreeGroup); @@ -849,9 +987,13 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; if (field->desc) { tVariant *var = field->desc; - qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); + } else { + qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + } } else { - qDebug("VAL%d => [type:NIL][val:%" PRIi64" or %f]", i, *(int64_t *)field->data, *(double *)field->data); //TODO + qDebug("VAL%d => [type:NIL][val:0x%" PRIx64"]", i, *(int64_t *)field->data); //TODO } } @@ -894,6 +1036,36 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg) { } } +void filterFreeColInfo(void *data) { + SFilterColInfo* info = (SFilterColInfo *)data; + + if (info->info == NULL) { + return; + } + + if (info->type == RANGE_TYPE_COL_RANGE) { + tfree(info->info); + } else if (info->type == RANGE_TYPE_MR_CTX) { + filterFreeMergeRange(info->info); + } else if (info->type == RANGE_TYPE_UNIT) { + taosArrayDestroy((SArray *)info->info); + } + + //NO NEED TO FREE UNIT + + info->type = 0; + info->info = NULL; +} + +void filterFreeColCtx(void *data) { + SFilterColCtx* ctx = (SFilterColCtx *)data; + + if (ctx->ctx) { + filterFreeMergeRange(ctx->ctx); + } +} + + void filterFreeGroupCtx(SFilterGroupCtx* gRes) { if (gRes == NULL) { return; @@ -904,8 +1076,8 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { int16_t i = 0, j = 0; while (i < gRes->colNum) { - if (gRes->colInfo[j]) { - taosArrayDestroy(gRes->colInfo[j]); + if (gRes->colInfo[j].info) { + filterFreeColInfo(&gRes->colInfo[j]); ++i; } @@ -1066,71 +1238,75 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, return TSDB_CODE_SUCCESS; } +int32_t filterCompareRMCtx(SFilterRMCtx *ctx1, SFilterRMCtx *ctx2, bool *equal) { + CHK_JMP(ctx1->status != ctx2->status); + CHK_JMP(ctx1->isnull != ctx2->isnull); + CHK_JMP(ctx1->notnull != ctx2->notnull); + CHK_JMP(ctx1->isrange != ctx2->isrange); + + SFilterRangeNode *r1 = ctx1->rs; + SFilterRangeNode *r2 = ctx2->rs; + + while (r1 && r2) { + CHK_JMP(r1->ra.sflag != r2->ra.sflag); + CHK_JMP(r1->ra.eflag != r2->ra.eflag); + CHK_JMP(r1->ra.s != r2->ra.s); + CHK_JMP(r1->ra.e != r2->ra.e); + + r1 = r1->next; + r2 = r2->next; + } + + CHK_JMP(r1 != r2); + + *equal = true; + + return TSDB_CODE_SUCCESS; + +_err_return: + *equal = false; + return TSDB_CODE_SUCCESS; +} -int32_t filterMergeBetweenColumns(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colIdx) { - bool isnull = false, notnull = false, isrange = false; - int32_t num = 0; - SArray* colArray = gRes->colInfo[colIdx]; +int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colIdx, bool *empty) { + SArray* colArray = (SArray *)gRes->colInfo[colIdx].info; int32_t size = (int32_t)taosArrayGetSize(colArray); - SFilterRMCtx* cur = filterInitMergeRange(type, 0); + int32_t type = gRes->colInfo[colIdx].dataType; + SFilterRMCtx* ctx = filterInitMergeRange(type, 0); for (uint32_t i = 0; i < size; ++i) { - SFilterColInfo* colInfo = taosArrayGet(colArray, i); - SFilterUnit* u = colInfo->info; - int32_t type = FILTER_UNIT_DATA_TYPE(u); + SFilterUnit* u = taosArrayGetP(colArray, i); uint8_t optr = FILTER_UNIT_OPTR(u); - SET_AND_OPTR(optr); - CHK_JMP(CHK_AND_OPTR()); + filterAddMergeOptr(ctx, optr, TSDB_RELATION_AND, empty, NULL); + CHK_JMP(*empty); if (!FILTER_NO_MERGE_OPTR(optr)) { - filterAddUnitRange(info, u, cur, TSDB_RELATION_AND); - CHK_JMP(MR_EMPTY_RES(cur)); + filterAddUnitRange(info, u, ctx, TSDB_RELATION_AND); + CHK_JMP(MR_EMPTY_RES(ctx)); } } - SFilterColRange *cra = calloc(1, sizeof(*cra)); - cra->idx = colIdx; + taosArrayDestroy(colArray); - filterGetMergeRangeNum(cur, &num); - assert(num == 1 || num == 0); - - if (num == 1) { - filterGetMergeRangeRes(cur, &cra->ra); - filterPostProcessRange(cur, &cra->ra, &cra->notNull); - } else { - if (isnull) { - cra->isNull = true; - } - - if (notnull) { - cra->notNull = true; - } - } - - taosArrayClear(colArray); - - FILTER_PUSH_RANGE(colArray, cra); - - filterFreeMergeRange(cur); + FILTER_PUSH_CTX(gRes->colInfo[colIdx], ctx); return TSDB_CODE_SUCCESS; _err_return: - taosArrayDestroy(colArray); - gRes->colInfo[colIdx] = NULL; + *empty = true; - filterFreeMergeRange(cur); + filterFreeMergeRange(ctx); return TSDB_CODE_SUCCESS; } -int32_t filterMergeBetweenUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { - bool emptyGroup = false; +int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t* gResNum) { + bool empty = false; uint16_t *colIdx = malloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint16_t)); uint16_t colIdxi = 0; uint16_t gResIdx = 0; @@ -1139,52 +1315,44 @@ int32_t filterMergeBetweenUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32 SFilterGroup* g = info->groups + i; gRes[gResIdx] = calloc(1, sizeof(SFilterGroupCtx)); - gRes[gResIdx]->colInfo = calloc(info->fields[FLD_TYPE_COLUMN].num, POINTER_BYTES); + gRes[gResIdx]->colInfo = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(SFilterColInfo)); colIdxi = 0; - emptyGroup = false; + empty = false; for (uint16_t j = 0; j < g->unitNum; ++j) { SFilterUnit* u = FILTER_GROUP_UNIT(info, g, j); uint16_t cidx = FILTER_UNIT_COL_IDX(u); - if (gRes[gResIdx]->colInfo[cidx] == NULL) { - gRes[gResIdx]->colInfo[cidx] = (SArray *)taosArrayInit(4, POINTER_BYTES); + if (gRes[gResIdx]->colInfo[cidx].info == NULL) { + gRes[gResIdx]->colInfo[cidx].info = (SArray *)taosArrayInit(4, POINTER_BYTES); colIdx[colIdxi++] = cidx; ++gRes[gResIdx]->colNum; + } else { + FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); } FILTER_PUSH_UNIT(gRes[gResIdx]->colInfo[cidx], u); } if (colIdxi > 1) { - qsort(colIdx, colIdxi, sizeof(uint16_t), compareUint16Val); + qsort(colIdx, colIdxi, sizeof(uint16_t), getComparFunc(TSDB_DATA_TYPE_USMALLINT, 0)); } for (uint16_t l = 0; l < colIdxi; ++l) { - SArray* colArray = gRes[gResIdx]->colInfo[colIdx[l]]; - int32_t size = (int32_t)taosArrayGetSize(colArray); - - if (size <= 1) { - continue; - } - - SFilterColInfo* colInfo = taosArrayGet(colArray, 0); - SFilterUnit* u = colInfo->info; - int32_t type = FILTER_UNIT_DATA_TYPE(u); + int32_t type = gRes[gResIdx]->colInfo[colIdx[l]].dataType; if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { continue; } - filterMergeBetweenColumns(info, gRes[gResIdx], colIdx[l]); + filterMergeUnits(info, gRes[gResIdx], colIdx[l], &empty); - if (gRes[gResIdx]->colInfo[colIdx[l]] == NULL) { - emptyGroup = true; + if (empty) { break; } } - if (emptyGroup) { + if (empty) { filterFreeGroupCtx(gRes[gResIdx]); gRes[gResIdx] = NULL; @@ -1199,166 +1367,191 @@ int32_t filterMergeBetweenUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32 tfree(colIdx); *gResNum = gResIdx; + + if (gResIdx == 0) { + FILTER_SET_FLAG(info->status, FI_STATUS_EMPTY); + } + + return TSDB_CODE_SUCCESS; +} + +void filterCheckColumns(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { + uint16_t idx1 = 0, idx2 = 0, m = 0, n = 0; + bool equal = false; + + for (; m < gRes1->colNum; ++m) { + idx1 = gRes1->colIdx[m]; + + equal = false; + + for (; n < gRes2->colNum; ++n) { + idx2 = gRes2->colIdx[n]; + if (idx1 < idx2) { + *conflict = true; + return; + } + + if (idx1 > idx2) { + continue; + } + + if (FILTER_NO_MERGE_DATA_TYPE(gRes1->colInfo[idx1].dataType)) { + *conflict = true; + return; + } + + ++n; + equal = true; + break; + } + + if (!equal) { + *conflict = true; + return; + } + } + + *conflict = false; + return; +} + + +int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRMCtx **ctx, int32_t optr, uint16_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { + SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx); + int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); + + if ((*ctx) == NULL) { + *ctx = filterInitMergeRange(type, 0); + } else { + filterReuseMergeRangeCtx(*ctx, type, 0); + } + + assert(gRes2->colInfo[cidx].type == RANGE_TYPE_MR_CTX); + assert(gRes1->colInfo[cidx].type == RANGE_TYPE_MR_CTX); + + filterCopyMergeRangeCtx(*ctx, gRes2->colInfo[cidx].info); + filterSourceRangeFromCtx(*ctx, gRes1->colInfo[cidx].info, optr, empty, all); return TSDB_CODE_SUCCESS; } - - -int32_t filterMergeTwoGroups(SFilterInfo *info, uint16_t id1, uint16_t id2, SArray* res, uint16_t *removedNum, SFilterGroupCtx** unitRes) { - bool isnull = false, notnull = false; - int32_t num = 0; - SFilterColRange *cra = NULL; - SFilterGroup *g = NULL; +int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilterGroupCtx** gRes2, bool *all) { + bool conflict = false; - SFilterUnit* u1 = FILTER_GROUP_UNIT(info, info->groups + id1, 0); - uint8_t optr = FILTER_UNIT_OPTR(u1); - uint16_t cidx = FILTER_UNIT_COL_IDX(u1); - uint16_t cidx2 = 0; - - int32_t type = FILTER_UNIT_DATA_TYPE(u1); - SFilterRMCtx *cur = filterInitMergeRange(type, 0); - - for (int32_t i = 0; i < info->groupNum; ++i) { - g = info->groups + i; - uint16_t unitNum = (unitRes && unitRes[i]) ? unitRes[i]->num : g->unitNum; - - if (unitNum == 0) { - continue; - } - - if (unitNum > 1) { - continue; - } - - if (unitRes && unitRes[i]) { - assert(taosArrayGetSize(unitRes[i]->colRange) == 1); - if (notnull) { - continue; - } - - cra = taosArrayGet(unitRes[i]->colRange, 0); - - if (cra->notNull) { - notnull = true; - CHK_JMP(CHK_OR_OPTR()); - } - - cidx2 = cra->idx; - } else { - u1 = FILTER_GROUP_UNIT(info, g, 0); - type = FILTER_UNIT_DATA_TYPE(u1); - if (FILTER_NO_MERGE_DATA_TYPE(type)) { - continue; - } - - optr = FILTER_UNIT_OPTR(u1); - - cidx2 = FILTER_UNIT_COL_IDX(u1); - } - - if (cidx != cidx2) { - continue; - } - - g->unitNum = 0; - - if (unitRes && unitRes[i]) { - unitRes[i]->num = 0; - if (notnull) { - continue; - } - - filterAddMergeRange(cur, &cra->ra, TSDB_RELATION_OR); - if (MR_EMPTY_RES(cur)) { - notnull = true; - CHK_JMP(CHK_OR_OPTR()); - } - - continue; - } - - optr = FILTER_UNIT_OPTR(u1); - SET_OR_OPTR(optr); - CHK_JMP(CHK_OR_OPTR()); - - if (!FILTER_NO_MERGE_OPTR(optr) && notnull == false) { - filterAddUnitRange(info, u1, cur, TSDB_RELATION_OR); - if (MR_EMPTY_RES(cur)) { - notnull = true; - CHK_JMP(CHK_OR_OPTR()); - } - } + filterCheckColumns(*gRes1, *gRes2, &conflict); + if (conflict) { + return TSDB_CODE_SUCCESS; } - SFilterColRange ncra; - SFilterRange *ra; - ncra.idx = cidx; + FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); - ncra.isNull = isnull; - ncra.notNull = notnull; + uint16_t idx1 = 0, idx2 = 0, m = 0, n = 0; + bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; + bool equal = false; + uint16_t equal1 = 0, equal2 = 0, merNum = 0; + SFilterRMCtx *ctx = NULL; + SFilterColCtx colCtx = {0}; + SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); - if (isnull) { - --removedNum; - } + for (; m < (*gRes1)->colNum; ++m) { + idx1 = (*gRes1)->colIdx[m]; + + for (; n < (*gRes2)->colNum; ++n) { + idx2 = (*gRes2)->colIdx[n]; - if (!notnull) { - filterGetMergeRangeNum(cur, &num); - if (num > 0) { - if (num > 1) { - ra = calloc(num, sizeof(*ra)); - } else { - ra = &ncra.ra; + if (idx1 > idx2) { + continue; } - filterGetMergeRangeRes(cur, ra); + assert(idx1 == idx2); + + ++merNum; + + filterMergeTwoGroupsImpl(info, &ctx, TSDB_RELATION_OR, idx1, *gRes1, *gRes2, NULL, all); - SFilterRange *tra = ra; - for (int32_t i = 0; i < num; ++i) { - filterPostProcessRange(cur, tra, &ncra.notNull); - assert(ncra.notNull == false); - ++tra; - } + CHK_JMP(*all); - if (num > 1) { - for (int32_t i = 0; i < num; ++i) { - FILTER_COPY_RA(&ncra.ra, ra); + if (numEqual) { + if ((*gRes1)->colNum == 1) { + ++equal1; + colCtx.colIdx = idx1; + colCtx.ctx = ctx; + taosArrayPush(colCtxs, &colCtx); + break; + } else { + filterCompareRMCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); + if (equal) { + ++equal1; + } - taosArrayPush(res, &ncra); + filterCompareRMCtx(ctx, (*gRes2)->colInfo[idx2].info, &equal); + if (equal) { + ++equal2; + } - ++ra; + CHK_JMP(equal1 != merNum && equal2 != merNum); + colCtx.colIdx = idx1; + colCtx.ctx = ctx; + ctx = NULL; + taosArrayPush(colCtxs, &colCtx); } } else { - taosArrayPush(res, &ncra); + filterCompareRMCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); + if (equal) { + ++equal1; + } + + CHK_JMP(equal1 != merNum); + colCtx.colIdx = idx1; + colCtx.ctx = ctx; + ctx = NULL; + taosArrayPush(colCtxs, &colCtx); } - } else { - ncra.ra.sflag = RA_NULL; - ncra.ra.eflag = RA_NULL; - taosArrayPush(res, &ncra); + + ++n; + break; } - } else { - ncra.ra.sflag = RA_NULL; - ncra.ra.eflag = RA_NULL; - taosArrayPush(res, &ncra); } - filterFreeMergeRange(cur); + assert(merNum > 0); + SFilterColInfo *colInfo = NULL; + assert (merNum == equal1 || merNum == equal2); + + filterFreeGroupCtx(*gRes2); + *gRes2 = NULL; + + assert(colCtxs && taosArrayGetSize(colCtxs) > 0); + + int32_t ctxSize = (int32_t)taosArrayGetSize(colCtxs); + SFilterColCtx *pctx = NULL; + + for (int32_t i = 0; i < ctxSize; ++i) { + pctx = taosArrayGet(colCtxs, i); + colInfo = &(*gRes1)->colInfo[pctx->colIdx]; + + filterFreeColInfo(colInfo); + FILTER_PUSH_CTX((*gRes1)->colInfo[pctx->colIdx], pctx->ctx); + } + + taosArrayDestroy(colCtxs); + return TSDB_CODE_SUCCESS; _err_return: - FILTER_SET_FLAG(info->flags, FILTER_ALL); - - filterFreeMergeRange(cur); + if (colCtxs && taosArrayGetSize(colCtxs) > 0) { + taosArrayDestroyEx(colCtxs, filterFreeColCtx); + } + + filterFreeMergeRange(ctx); return TSDB_CODE_SUCCESS; - } -int32_t filterMergeBetweenGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gResNum) { +int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gResNum) { if (*gResNum <= 1) { return TSDB_CODE_SUCCESS; } @@ -1368,11 +1561,12 @@ int32_t filterMergeBetweenGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int3 int32_t pEnd = 0, cStart = 0, cEnd = 0; uint16_t pColNum = 0, cColNum = 0; int32_t movedNum = 0; + bool all = false; cColNum = gRes[0]->colNum; - for (int32_t i = 1; i < *gResNum; ++i) { - if (gRes[i]->colNum == cColNum) { + for (int32_t i = 1; i <= *gResNum; ++i) { + if (i < (*gResNum) && gRes[i]->colNum == cColNum) { continue; } @@ -1382,21 +1576,42 @@ int32_t filterMergeBetweenGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int3 if (pColNum > 0) { for (int32_t m = 0; m <= pEnd; ++m) { for (int32_t n = cStart; n <= cEnd; ++n) { - filterMergeTwoGroups(&gRes[m], &gRes[n]); + assert(m < n); + filterMergeTwoGroups(info, &gRes[m], &gRes[n], &all); + + CHK_JMP(all); if (gRes[n] == NULL) { - memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + if (n < ((*gResNum) - 1)) { + memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + } + --cEnd; --(*gResNum); ++movedNum; + --n; } } } } - for (int32_t m = cStart; m <= cEnd; ++m) { - for (int32_t n = cStart + 1; n <= cEnd; ++n) { - filterMergeTwoGroups(&gRes[m], &gRes[n]); + for (int32_t m = cStart; m < cEnd; ++m) { + for (int32_t n = m + 1; n <= cEnd; ++n) { + assert(m < n); + filterMergeTwoGroups(info, &gRes[m], &gRes[n], &all); + + CHK_JMP(all); + + if (gRes[n] == NULL) { + if (n < ((*gResNum) - 1)) { + memmove(&gRes[n], &gRes[n+1], (*gResNum-n-1) * POINTER_BYTES); + } + + --cEnd; + --(*gResNum); + ++movedNum; + --n; + } } } @@ -1404,102 +1619,21 @@ int32_t filterMergeBetweenGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int3 pEnd = cEnd; i -= movedNum; - cStart = i; - cEnd = i; - cColNum = gRes[i]->colNum; - } - - int32_t *col = NULL; - uint16_t cidx; - uint16_t removedNum = 0; - bool merged = false; - SArray *colRange = NULL; - - for (uint16_t i = 0; i < info->groupNum; ++i) { - SFilterGroup* g = info->groups + i; - uint16_t unitNum = g->unitNum; - - if (unitRes && unitRes[i]) { - unitNum = unitRes[i]->num; - merged = true; - } - - if (unitNum == 0) { - ++removedNum; - continue; - } - - if (unitNum > 1) { - continue; - } - - if (unitRes && unitRes[i]) { - assert(taosArrayGetSize(unitRes[i]->colRange) == 1); - SFilterColRange *ra = taosArrayGet(unitRes[i]->colRange, 0); - - cidx = ra->idx; - } else { - SFilterUnit* u = FILTER_GROUP_UNIT(info, g, 0); - int32_t type = FILTER_UNIT_DATA_TYPE(u); - if (FILTER_NO_MERGE_DATA_TYPE(type)) { - continue; - } - - cidx = FILTER_UNIT_COL_IDX(u); - } - - if (col == NULL) { - if (i < (info->groupNum - 1)) { - col = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(int32_t)); - } else { - break; - } + if (i >= (*gResNum)) { + break; } - if (col[cidx] == 0) { - col[cidx] = i + 1; - continue; - } else if (col[cidx] == -1) { - continue; - } else { - if (colRange == NULL) { - colRange = taosArrayInit(4, sizeof(SFilterColRange)); - } - - removedNum += 2; - filterProcessGroupsSameColumn(info, col[cidx] - 1, i, colRange, &removedNum, unitRes); - - CHK_JMP(FILTER_GET_FLAG(info->flags, FILTER_ALL)); - - col[cidx] = -1; - } + cStart = i; + cEnd = i; + cColNum = gRes[i]->colNum; } - uint16_t num = info->groupNum - removedNum; - assert(num >= 0); - - if (colRange) { - num += taosArrayGetSize(colRange); - } - - if (num == 0) { - FILTER_SET_FLAG(info->flags, FILTER_NONE); - goto _err_return; - } - - if (colRange || removedNum > 0 || merged) { - groupRes->num = num; - groupRes->col = col; - groupRes->colRange = colRange; - } else { - tfree(col); - } - return TSDB_CODE_SUCCESS; - + _err_return: - tfree(gColNum); + + FILTER_SET_FLAG(info->status, FI_STATUS_ALL); return TSDB_CODE_SUCCESS; } @@ -1522,162 +1656,54 @@ int32_t filterConvertGroupFromArray(SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } -int32_t filterCheckRangeCoverage(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { - if (gctx->num == 0) { +int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { + if (!FILTER_GET_FLAG(info->status, FI_STATUS_REWRITE)) { + qDebug("no need rewrite"); return TSDB_CODE_SUCCESS; } - + SFilterInfo oinfo = *info; - uint16_t gNum = 0; SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); + SFilterGroupCtx *res = NULL; + SFilterColInfo *colInfo = NULL; + int32_t optr = 0; memset(info, 0, sizeof(*info)); - filterInitUnitsFields(info); - - for (uint16_t i = 0; i < oinfo.groupNum; ++i) { - SFilterGroup* g = oinfo.groups + i; - SFilterGroup ng = {0}; - uint16_t unitNum = (uctx && uctx[i]) ? uctx[i]->num : g->unitNum; - - if (unitNum == 0) { - continue; - } - - ++gNum; - - if ((uctx == NULL) || (uctx[i] == NULL)) { - for (uint16_t n = 0; n < g->unitNum; ++n) { - SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); - } - - taosArrayPush(group, &ng); - - continue; - } - - SFilterGroupCtx* ctx = uctx[i]; - for (uint16_t n = 0; n < g->unitNum; ++n) { - SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); - int32_t type = FILTER_UNIT_DATA_TYPE(u); - if (FILTER_NO_MERGE_DATA_TYPE(type)) { - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); - continue; - } - - uint16_t cidx = FILTER_UNIT_COL_IDX(u); - - assert(ctx->col[cidx] > 0 || ctx->col[cidx] == -1); - - if (ctx->col[cidx] != -1) { - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); - } - } - - if (ctx->colRange && taosArrayGetSize(ctx->colRange) > 0) { - int32_t size = (int32_t)taosArrayGetSize(ctx->colRange); - for (int32_t m = 0; m < size; ++m) { - SFilterColRange *cra = taosArrayGet(ctx->colRange, m); - filterAddGroupUnitFromRange(info, &oinfo, cra, &ng, TSDB_RELATION_AND, NULL); - } - } - - taosArrayPush(group, &ng); - } - - if (gctx->colRange && taosArrayGetSize(gctx->colRange) > 0) { - int32_t size = (int32_t)taosArrayGetSize(gctx->colRange); - for (int32_t i = 0; i < size; ++i) { - SFilterColRange *cra = taosArrayGet(gctx->colRange, i); - filterAddGroupUnitFromRange(info, &oinfo, cra, NULL, TSDB_RELATION_OR, group); - } - } - - filterConvertGroupFromArray(info, group); - - taosArrayDestroy(group); - - return TSDB_CODE_SUCCESS; -} - - - -int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx** uctx) { - if (gctx->num == 0) { - return TSDB_CODE_SUCCESS; - } - - SFilterInfo oinfo = *info; - uint16_t gNum = 0; - SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); - - memset(info, 0, sizeof(*info)); + FILTER_SET_FLAG(info->options, FI_OPTION_NEED_UNIQE); filterInitUnitsFields(info); - - for (uint16_t i = 0; i < oinfo.groupNum; ++i) { - SFilterGroup* g = oinfo.groups + i; + + for (int32_t i = 0; i < gResNum; ++i) { + res = gRes[i]; + + optr = (res->colNum > 1) ? TSDB_RELATION_AND : TSDB_RELATION_OR; + SFilterGroup ng = {0}; - uint16_t unitNum = (uctx && uctx[i]) ? uctx[i]->num : g->unitNum; - - if (unitNum == 0) { - continue; - } - - ++gNum; - - if ((uctx == NULL) || (uctx[i] == NULL)) { - for (uint16_t n = 0; n < g->unitNum; ++n) { - SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); - } - - taosArrayPush(group, &ng); - - continue; - } - SFilterGroupCtx* ctx = uctx[i]; - for (uint16_t n = 0; n < g->unitNum; ++n) { - SFilterUnit* u = FILTER_GROUP_UNIT(&oinfo, g, n); - int32_t type = FILTER_UNIT_DATA_TYPE(u); - if (FILTER_NO_MERGE_DATA_TYPE(type)) { - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); + for (uint16_t m = 0; m < res->colNum; ++m) { + colInfo = &res->colInfo[res->colIdx[m]]; + if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { + assert(colInfo->type == RANGE_TYPE_UNIT); + int32_t usize = (int32_t)taosArrayGetSize((SArray *)colInfo->info); + + for (int32_t n = 0; n < usize; ++n) { + SFilterUnit* u = taosArrayGetP((SArray *)colInfo->info, n); + + filterAddUnitFromUnit(info, &oinfo, u); + filterAddUnitToGroup(&ng, info->unitNum - 1); + } + continue; } - - uint16_t cidx = FILTER_UNIT_COL_IDX(u); - - assert(ctx->col[cidx] > 0 || ctx->col[cidx] == -1); - if (ctx->col[cidx] != -1) { - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); - } + assert(colInfo->type == RANGE_TYPE_MR_CTX); + + filterAddGroupUnitFromCtx(info, &oinfo, colInfo->info, res->colIdx[m], &ng, optr, group); } - if (ctx->colRange && taosArrayGetSize(ctx->colRange) > 0) { - int32_t size = (int32_t)taosArrayGetSize(ctx->colRange); - for (int32_t m = 0; m < size; ++m) { - SFilterColRange *cra = taosArrayGet(ctx->colRange, m); - filterAddGroupUnitFromRange(info, &oinfo, cra, &ng, TSDB_RELATION_AND, NULL); - } - } - - taosArrayPush(group, &ng); - } - - if (gctx->colRange && taosArrayGetSize(gctx->colRange) > 0) { - int32_t size = (int32_t)taosArrayGetSize(gctx->colRange); - for (int32_t i = 0; i < size; ++i) { - SFilterColRange *cra = taosArrayGet(gctx->colRange, i); - filterAddGroupUnitFromRange(info, &oinfo, cra, NULL, TSDB_RELATION_OR, group); + if (ng.unitNum > 0) { + taosArrayPush(group, &ng); } } @@ -1692,25 +1718,24 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx* gctx, SFilterGroupCtx* int32_t filterPreprocess(SFilterInfo *info) { SFilterGroupCtx** gRes = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); int32_t gResNum = 0; - SFilterGroupCtx groupRes = {0}; - filterMergeBetweenUnits(info, gRes, &gResNum); + filterMergeGroupUnits(info, gRes, &gResNum); - filterMergeBetweenGroups(info, gRes, gResNum); + filterMergeGroups(info, gRes, &gResNum); - if (FILTER_GET_FLAG(info->flags, FILTER_ALL)) { + if (FILTER_GET_FLAG(info->status, FI_STATUS_ALL)) { qInfo("Final - FilterInfo: [ALL]"); return TSDB_CODE_SUCCESS; } - if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { - qInfo("Final - FilterInfo: [NONE]"); + if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { + qInfo("Final - FilterInfo: [EMPTY]"); return TSDB_CODE_SUCCESS; } //TODO GET COLUMN RANGE - filterRewrite(info, &groupRes, unitsRes); + filterRewrite(info, gRes, gResNum); return TSDB_CODE_SUCCESS; } @@ -1736,7 +1761,7 @@ int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { bool all = true; - if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { + if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { return false; } @@ -1807,7 +1832,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option info = *pinfo; - info->flags = options; + info->options = options; SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); @@ -1821,14 +1846,14 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option ERR_JRET(filterInitValFieldData(info)); - if (!FILTER_GET_FLAG(info->flags, FILTER_NO_REWRITE)) { + if (!FILTER_GET_FLAG(info->options, FI_OPTION_NO_REWRITE)) { filterDumpInfoToString(info, "Before preprocess"); ERR_JRET(filterPreprocess(info)); - CHK_JMP(FILTER_GET_FLAG(info->flags, FILTER_ALL)); + CHK_JMP(FILTER_GET_FLAG(info->status, FI_STATUS_ALL)); - if (FILTER_GET_FLAG(info->flags, FILTER_NONE)) { + if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { taosArrayDestroy(group); return code; } @@ -1859,12 +1884,13 @@ _err_return: int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { SFilterRange ra = {0}; - SFilterRMCtx *prev = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, MR_OPT_TS); - SFilterRMCtx *tmpc = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, MR_OPT_TS); + SFilterRMCtx *prev = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); + SFilterRMCtx *tmpc = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); SFilterRMCtx *cur = NULL; int32_t num = 0; int32_t optr = 0; - int32_t code = 0; + int32_t code = TSDB_CODE_QRY_INVALID_TIME_CONDITION; + bool empty = false; for (int32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *group = &info->groups[i]; @@ -1879,6 +1905,16 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { for (int32_t u = 0; u < group->unitNum; ++u) { uint16_t uidx = group->unitIdxs[u]; SFilterUnit *unit = &info->units[uidx]; + + uint8_t raOptr = FILTER_UNIT_OPTR(unit); + + filterAddMergeOptr(cur, raOptr, TSDB_RELATION_AND, &empty, NULL); + CHK_JMP(empty); + + if (FILTER_NO_MERGE_OPTR(raOptr)) { + continue; + } + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); void *s = FILTER_GET_VAL_FIELD_DATA(right); void *e = FILTER_GET_VAL_FIELD_DATA(right) + tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes; @@ -1886,18 +1922,11 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { SIMPLE_COPY_VALUES(&ra.s, s); SIMPLE_COPY_VALUES(&ra.e, e); - code = filterAddMergeRange(cur, &ra, optr); - if (code) { - break; - } + filterAddMergeRange(cur, &ra, optr); } - if (code != TSDB_CODE_SUCCESS) { - break; - } - - if (FILTER_GET_FLAG(cur->status, MR_ALL)) { - FILTER_SET_FLAG(prev->status, MR_ALL); + if (cur->notnull) { + prev->notnull = true; break; } @@ -1907,28 +1936,36 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { } } - if (code == TSDB_CODE_SUCCESS) { - if (FILTER_GET_FLAG(prev->status, MR_ALL)) { - *win = TSWINDOW_INITIALIZER; - } else { - filterGetMergeRangeNum(prev, &num); - if (num != 1) { - qError("only one time range accepted, num:%d", num); - ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); - } - - SFilterRange tra; - filterGetMergeRangeRes(prev, &tra); - win->skey = tra.s; - win->ekey = tra.e; + if (prev->notnull) { + *win = TSWINDOW_INITIALIZER; + } else { + filterGetMergeRangeNum(prev, &num); + if (num != 1) { + qError("only one time range accepted, num:%d", num); + ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); } - } -_err_return: + SFilterRange tra; + filterGetMergeRangeRes(prev, &tra); + win->skey = tra.s; + win->ekey = tra.e; + } filterFreeMergeRange(prev); filterFreeMergeRange(tmpc); + qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); + return TSDB_CODE_SUCCESS; + +_err_return: + + *win = TSWINDOW_DESC_INITIALIZER; + + filterFreeMergeRange(prev); + filterFreeMergeRange(tmpc); + + qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); + return code; } @@ -2000,7 +2037,6 @@ int32_t filterFreeNcharColumns(SFilterInfo* info) { } } - return TSDB_CODE_SUCCESS; } diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index 1f4626e364..64f7fdddae 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -78,7 +78,7 @@ void intDataTest() { memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, MR_OPT_TS); + h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, FI_OPTION_TIMESTAMP); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index c2b0f2e0f6..d11d7ab6da 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -168,6 +168,7 @@ if $rows != 27 then return -1 endi +#xxx sql select * from stb1 where c8 = '51' and c8 != '51'; if $rows != 0 then return -1 @@ -1247,7 +1248,7 @@ if $data00 != @21-05-05 18:19:04.000@ then return -1 endi -xxx sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); +sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); if $rows != 4 then return -1 endi @@ -1828,6 +1829,17 @@ sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; +sql_error select * from stb1 where ts is null; +sql_error select * from stb1 where ts is not null and ts is null; +sql select * from stb1 where ts is not null; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where ts is not null or ts is null; +if $rows != 29 then + return -1 +endi sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; if $rows != 29 then From d77c190ec6c906f02391c46e8af0a930b18ed834 Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 22 Jul 2021 09:44:15 +0800 Subject: [PATCH 024/100] support filter duplicated unit --- src/query/inc/qFilter.h | 6 +- src/query/src/qFilter.c | 168 ++++++++++++++++++++++++++++------------ 2 files changed, 124 insertions(+), 50 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index ebf0fda55b..a383b15473 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -21,10 +21,12 @@ extern "C" { #endif #include "texpr.h" +#include "hash.h" #define FILTER_DEFAULT_GROUP_SIZE 4 #define FILTER_DEFAULT_UNIT_SIZE 4 #define FILTER_DEFAULT_FIELD_SIZE 4 +#define FILTER_DEFAULT_VALUE_SIZE 4 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 enum { @@ -175,7 +177,7 @@ typedef struct SFilterInfo { SFilterUnit *units; uint8_t *unitRes; // result uint8_t *unitFlags; // got result - SFilterPCtx *pctx; + SFilterPCtx pctx; } SFilterInfo; #define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) @@ -196,7 +198,7 @@ typedef struct SFilterInfo { #define FILTER_CLR_FLAG(st, f) st &= (~f) #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) - +#define FILTER_PACKAGE_UNIT_HASH_KEY(v, optr, idx1, idx2) do { char *_t = (char *)v; _t[0] = optr; *(uint16_t *)(_t + 1) = idx1; *(uint16_t *)(_t + 3) = idx2; } while (0) #define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RA_EXCLUDE) || FILTER_GET_FLAG(eflag,RA_EXCLUDE)))) #define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 99355103b9..26ecfa0ac7 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -576,7 +576,7 @@ int32_t filterDetachCnfGroups(SArray* group, SArray* left, SArray* right) { return TSDB_CODE_SUCCESS; } -int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { +int32_t filterGetFiledByDesc(SFilterFields* fields, int32_t type, void *v) { for (uint16_t i = 0; i < fields->num; ++i) { if (0 == gDescCompare[type](fields->fields[i].desc, v)) { return i; @@ -586,14 +586,36 @@ int32_t filterGetFiled(SFilterFields* fields, int32_t type, void *v) { return -1; } -int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, SFilterFieldId *fid) { + +int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t dataLen) { + if (type == FLD_TYPE_VALUE) { + if (info->pctx.valHash == false) { + qError("value hash is empty"); + return -1; + } + + void *hv = taosHashGet(info->pctx.valHash, v, dataLen); + if (hv) { + return *(int32_t *)hv; + } + } + + return -1; +} + + +int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, SFilterFieldId *fid, int32_t dataLen) { int32_t idx = -1; uint16_t *num; num = &info->fields[type].num; - if (*num > 0 && type != FLD_TYPE_VALUE) { - idx = filterGetFiled(&info->fields[type], type, desc); + if (*num > 0) { + if (type == FLD_TYPE_COLUMN) { + idx = filterGetFiledByDesc(&info->fields[type], type, desc); + } else if (dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + idx = filterGetFiledByData(info, type, data, dataLen); + } } if (idx < 0) { @@ -607,6 +629,14 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, info->fields[type].fields[idx].desc = desc; info->fields[type].fields[idx].data = data; ++(*num); + + if (data && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + if (info->pctx.valHash == NULL) { + info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); + } + + taosHashPut(info->pctx.valHash, data, dataLen, &idx, sizeof(idx)); + } } fid->type = type; @@ -616,7 +646,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, } static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { - filterAddField(info, field->desc, field->data, FILTER_GET_TYPE(field->flag), fid); + filterAddField(info, field->desc, field->data, FILTER_GET_TYPE(field->flag), fid, 0); FILTER_SET_FLAG(field->flag, FLD_DESC_NO_FREE); FILTER_SET_FLAG(field->flag, FLD_DATA_NO_FREE); @@ -642,12 +672,26 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldI node->pVal = NULL; } - filterAddField(info, v, NULL, type, fid); + filterAddField(info, v, NULL, type, fid, 0); return TSDB_CODE_SUCCESS; } -int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right) { +int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFilterFieldId *right, uint16_t *uidx) { + if (FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + if (info->pctx.unitHash == NULL) { + info->pctx.unitHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); + } else { + int64_t v = 0; + FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); + void *hu = taosHashGet(info->pctx.unitHash, &v, sizeof(v)); + if (hu) { + *uidx = *(uint16_t *)hu; + return TSDB_CODE_SUCCESS; + } + } + } + if (info->unitNum >= info->unitSize) { uint16_t psize = info->unitSize; info->unitSize += FILTER_DEFAULT_UNIT_SIZE; @@ -674,6 +718,14 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi assert(FILTER_GET_FLAG(col->flag, FLD_TYPE_COLUMN)); info->units[info->unitNum].compare.type = FILTER_GET_COL_FIELD_TYPE(col); + + *uidx = info->unitNum; + + if (FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + int64_t v = 0; + FILTER_PACKAGE_UNIT_HASH_KEY(&v, optr, left->idx, right ? right->idx : -1); + taosHashPut(info->pctx.unitHash, &v, sizeof(v), uidx, sizeof(*uidx)); + } ++info->unitNum; @@ -702,8 +754,10 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g tVariant* var = tree->_node.pRight->pVal; int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left)); + int32_t len = 0; + uint16_t uidx = 0; - if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { + if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { void *data = NULL; convertFilterSetFromBinary((void **)&data, var->pz, var->nLen, type); CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); @@ -714,21 +768,23 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g void *fdata = NULL; if (IS_VAR_DATA_TYPE(type)) { - uint32_t len = taosHashGetDataKeyLen((SHashObj *)data, p); + len = (int32_t)taosHashGetDataKeyLen((SHashObj *)data, p); fdata = malloc(len + VARSTR_HEADER_SIZE); varDataLen(fdata) = len; memcpy(varDataVal(fdata), key, len); + len += VARSTR_HEADER_SIZE; } else { fdata = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(fdata, key); + len = tDataTypes[type].bytes; } - filterAddField(info, NULL, fdata, FLD_TYPE_VALUE, &right); + filterAddField(info, NULL, fdata, FLD_TYPE_VALUE, &right, len); - filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right); + filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right, &uidx); SFilterGroup fgroup = {0}; - filterAddUnitToGroup(&fgroup, info->unitNum - 1); + filterAddUnitToGroup(&fgroup, uidx); taosArrayPush(group, &fgroup); @@ -737,10 +793,10 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g } else { filterAddFieldFromNode(info, tree->_node.pRight, &right); - filterAddUnit(info, tree->_node.optr, &left, &right); + filterAddUnit(info, tree->_node.optr, &left, &right, &uidx); SFilterGroup fgroup = {0}; - filterAddUnitToGroup(&fgroup, info->unitNum - 1); + filterAddUnitToGroup(&fgroup, uidx); taosArrayPush(group, &fgroup); } @@ -749,15 +805,25 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g } -int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u) { +int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint16_t *uidx) { SFilterFieldId left, right, *pright = &right; + int32_t type = FILTER_UNIT_DATA_TYPE(u); - filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left); + filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); FILTER_SET_FLAG(t->flag, FLD_DESC_NO_FREE); if (u->right.type == FLD_TYPE_VALUE) { - filterAddField(dst, NULL, FILTER_UNIT_VAL_DATA(src, u), FLD_TYPE_VALUE, &right); + void *data = FILTER_UNIT_VAL_DATA(src, u); + if (IS_VAR_DATA_TYPE(type)) { + if (FILTER_UNIT_OPTR(u) == TSDB_RELATION_IN) { + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, 0); + } else { + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, varDataTLen(data)); + } + } else { + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + } t = FILTER_UNIT_RIGHT_FIELD(src, u); FILTER_SET_FLAG(t->flag, FLD_DATA_NO_FREE); } else { @@ -765,29 +831,32 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u } - return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright); + return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright, uidx); } int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right; + uint16_t uidx = 0; SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); filterAddColFieldFromField(dst, col, &left); + int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); + if (optr == TSDB_RELATION_AND) { if (ctx->isnull) { assert(ctx->notnull == false && ctx->isrange == false); - filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL, &uidx); + filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; } if (ctx->notnull) { assert(ctx->isnull == false && ctx->isrange == false); - filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL, &uidx); + filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; } @@ -803,14 +872,13 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC assert(!((FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (FILTER_GET_FLAG(ra->eflag, RA_NULL)))); if ((!FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RA_NULL))) { - int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); __compar_fn_t func = getComparFunc(type, 0); if (func(&ra->s, &ra->e) == 0) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; } } @@ -818,17 +886,17 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); } if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->e); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); } return TSDB_CODE_SUCCESS; @@ -842,8 +910,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC assert(ctx->isnull || ctx->notnull || ctx->isrange); if (ctx->isnull) { - filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnit(dst, TSDB_RELATION_ISNULL, &left, NULL, &uidx); + filterAddUnitToGroup(g, uidx); taosArrayPush(res, g); } @@ -851,8 +919,8 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC assert(!ctx->isrange); memset(g, 0, sizeof(*g)); - filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddUnit(dst, TSDB_RELATION_NOTNULL, &left, NULL, &uidx); + filterAddUnitToGroup(g, uidx); taosArrayPush(res, g); } @@ -868,14 +936,13 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC memset(g, 0, sizeof(*g)); if ((!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RA_NULL))) { - int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(dst, left)); __compar_fn_t func = getComparFunc(type, 0); if (func(&r->ra.s, &r->ra.e) == 0) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); taosArrayPush(res, g); @@ -885,15 +952,19 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMC } if (!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { - filterAddField(dst, NULL, &r->ra.s, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &r->ra.s); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); } if (!FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { - filterAddField(dst, NULL, &r->ra.e, FLD_TYPE_VALUE, &right); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right); - filterAddUnitToGroup(g, dst->unitNum - 1); + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &r->ra.e); + filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); + filterAddUnitToGroup(g, uidx); } assert (g->unitNum > 0); @@ -1667,6 +1738,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum SFilterGroupCtx *res = NULL; SFilterColInfo *colInfo = NULL; int32_t optr = 0; + uint16_t uidx = 0; memset(info, 0, sizeof(*info)); @@ -1690,8 +1762,8 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum for (int32_t n = 0; n < usize; ++n) { SFilterUnit* u = taosArrayGetP((SArray *)colInfo->info, n); - filterAddUnitFromUnit(info, &oinfo, u); - filterAddUnitToGroup(&ng, info->unitNum - 1); + filterAddUnitFromUnit(info, &oinfo, u, &uidx); + filterAddUnitToGroup(&ng, uidx); } continue; From 8ed28fd81a8c998809dd412b3fde7cc0a0470c8f Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 23 Jul 2021 18:32:35 +0800 Subject: [PATCH 025/100] support range filter --- src/query/inc/qFilter.h | 54 ++- src/query/src/qExecutor.c | 69 +-- src/query/src/qFilter.c | 561 ++++++++++++++++------ src/query/tests/rangeMergeTest.cpp | 166 +++---- tests/script/general/parser/condition.sim | 71 +++ 5 files changed, 616 insertions(+), 305 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index a383b15473..3f34173d24 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -46,9 +46,13 @@ enum { enum { RA_EXCLUDE = 1, - RA_NULL = 2, + RA_INCLUDE = 2, + RA_NULL = 4, }; +#define RA_EMPTY (RA_EXCLUDE|RA_INCLUDE) +#define RA_ALL (RA_EXCLUDE|RA_INCLUDE) + enum { FI_OPTION_NO_REWRITE = 1, FI_OPTION_TIMESTAMP = 2, @@ -63,7 +67,7 @@ enum { enum { RANGE_TYPE_UNIT = 1, - RANGE_TYPE_COL_RANGE = 2, + RANGE_TYPE_VAR_HASH = 2, RANGE_TYPE_MR_CTX = 3, }; @@ -73,10 +77,10 @@ typedef struct OptrStr { } OptrStr; typedef struct SFilterRange { - char sflag; - char eflag; int64_t s; int64_t e; + char sflag; + char eflag; } SFilterRange; typedef struct SFilterColRange { @@ -87,30 +91,51 @@ typedef struct SFilterColRange { SFilterRange ra; } SFilterColRange; +typedef struct SFilterRangeCompare { + int64_t s; + int64_t e; + rangeCompFunc func; +} SFilterRangeCompare; + +typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); typedef struct SFilterRangeNode { struct SFilterRangeNode* prev; struct SFilterRangeNode* next; - SFilterRange ra; + union { + SFilterRange ra; + SFilterRangeCompare rc; + }; } SFilterRangeNode; -typedef struct SFilterRMCtx { +typedef struct SFilterRangeCtx { int32_t type; int32_t options; int8_t status; bool isnull; bool notnull; bool isrange; + int16_t colId; __compar_fn_t pCompareFunc; SFilterRangeNode *rf; //freed SFilterRangeNode *rs; -} SFilterRMCtx ; +} SFilterRangeCtx ; + +typedef struct SFilterVarCtx { + int32_t type; + int32_t options; + int8_t status; + bool isnull; + bool notnull; + bool isrange; + SHashObj *wild; + SHashObj *value; +} SFilterVarCtx; typedef struct SFilterField { uint16_t flag; void* desc; void* data; - int64_t range[]; } SFilterField; typedef struct SFilterFields { @@ -172,11 +197,13 @@ typedef struct SFilterInfo { uint16_t unitSize; uint16_t unitNum; uint16_t groupNum; + uint16_t colRangeNum; SFilterFields fields[FLD_TYPE_MAX]; SFilterGroup *groups; SFilterUnit *units; uint8_t *unitRes; // result uint8_t *unitFlags; // got result + SFilterRangeCtx **colRange; SFilterPCtx pctx; } SFilterInfo; @@ -245,7 +272,7 @@ typedef struct SFilterInfo { #define FILTER_UNIT_SET_R(i, idx, v) (i)->unitRes[idx] = (v) #define FILTER_PUSH_UNIT(colInfo, u) do { (colInfo).type = RANGE_TYPE_UNIT; (colInfo).dataType = FILTER_UNIT_DATA_TYPE(u);taosArrayPush((SArray *)((colInfo).info), &u);} while (0) -#define FILTER_PUSH_RANGE(colInfo, cra) do { SFilterColInfo* _info = malloc(sizeof(SFilterColInfo)); _info->type = RANGE_TYPE_COL_RANGE; _info->info = cra; taosArrayPush((SArray *)(colInfo), &_info);} while (0) +#define FILTER_PUSH_VAR_HASH(colInfo, ha) do { (colInfo).type = RANGE_TYPE_VAR_HASH; (colInfo).info = ha;} while (0) #define FILTER_PUSH_CTX(colInfo, ctx) do { (colInfo).type = RANGE_TYPE_MR_CTX; (colInfo).info = ctx;} while (0) #define FILTER_COPY_IDX(dst, src, n) do { *(dst) = malloc(sizeof(uint16_t) * n); memcpy(*(dst), src, sizeof(uint16_t) * n);} while (0) @@ -258,14 +285,15 @@ typedef int32_t(*filter_desc_compare_func)(const void *, const void *); extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); -extern void* filterInitMergeRange(int32_t type, int32_t options); -extern int32_t filterGetMergeRangeNum(void* h, int32_t* num); -extern int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra); -extern int32_t filterFreeMergeRange(void* h); +extern void* filterInitRangeCtx(int32_t type, int32_t options); +extern int32_t filterGetRangeNum(void* h, int32_t* num); +extern int32_t filterGetRangeRes(void* h, SFilterRange *ra); +extern int32_t filterFreeRangeCtx(void* h); extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); extern void filterFreeInfo(SFilterInfo *info); +extern bool filterIsEmptyRes(SFilterInfo *info); #ifdef __cplusplus } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 01f43778f9..7d7dd85814 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2395,77 +2395,14 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i #define IS_PREFILTER_TYPE(_t) ((_t) != TSDB_DATA_TYPE_BINARY && (_t) != TSDB_DATA_TYPE_NCHAR) -static bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, int32_t numOfRows) { +static FORCE_INLINE bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv, SDataStatis *pDataStatis, SQLFunctionCtx *pCtx, int32_t numOfRows) { SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - if (pDataStatis == NULL || pQueryAttr->numOfFilterCols == 0) { + if (pDataStatis == NULL || pQueryAttr->pFilters == NULL) { return true; } - bool ret = true; - for (int32_t k = 0; k < pQueryAttr->numOfFilterCols; ++k) { - SSingleColumnFilterInfo *pFilterInfo = &pQueryAttr->pFilterInfo[k]; - int32_t index = -1; - for(int32_t i = 0; i < pQueryAttr->numOfCols; ++i) { - if (pDataStatis[i].colId == pFilterInfo->info.colId) { - index = i; - break; - } - } - - // no statistics data, load the true data block - if (index == -1) { - return true; - } - - // not support pre-filter operation on binary/nchar data type - if (!IS_PREFILTER_TYPE(pFilterInfo->info.type)) { - return true; - } - - // all data in current column are NULL, no need to check its boundary value - if (pDataStatis[index].numOfNull == numOfRows) { - - // if isNULL query exists, load the null data column - for (int32_t j = 0; j < pFilterInfo->numOfFilters; ++j) { - SColumnFilterElem *pFilterElem = &pFilterInfo->pFilters[j]; - if (pFilterElem->fp == isNullOperator) { - return true; - } - } - - continue; - } - - SDataStatis* pDataBlockst = &pDataStatis[index]; - - if (pFilterInfo->info.type == TSDB_DATA_TYPE_FLOAT) { - float minval = (float)(*(double *)(&pDataBlockst->min)); - float maxval = (float)(*(double *)(&pDataBlockst->max)); - - for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { - if (pFilterInfo->pFilters[i].filterInfo.lowerRelOptr == TSDB_RELATION_IN) { - continue; - } - ret &= pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&minval, (char *)&maxval, TSDB_DATA_TYPE_FLOAT); - if (ret == false) { - return false; - } - } - } else { - for (int32_t i = 0; i < pFilterInfo->numOfFilters; ++i) { - if (pFilterInfo->pFilters[i].filterInfo.lowerRelOptr == TSDB_RELATION_IN) { - continue; - } - ret &= pFilterInfo->pFilters[i].fp(&pFilterInfo->pFilters[i], (char *)&pDataBlockst->min, (char *)&pDataBlockst->max, pFilterInfo->info.type); - if (ret == false) { - return false; - } - } - } - } - - return ret; + return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, numOfRows); } static bool overlapWithTimeWindow(SQueryAttr* pQueryAttr, SDataBlockInfo* pBlockInfo) { diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 26ecfa0ac7..a02f284b88 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -57,6 +57,64 @@ filter_desc_compare_func gDescCompare [FLD_TYPE_MAX] = { filterFieldValDescCompare }; +bool filterRangeCompGi (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) >= 0; +} +bool filterRangeCompGe (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) > 0; +} +bool filterRangeCompLi (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(minv, maxr) <= 0; +} +bool filterRangeCompLe (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(minv, maxr) < 0; +} +bool filterRangeCompii (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) <= 0; +} +bool filterRangeCompee (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) < 0; +} +bool filterRangeCompei (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) <= 0; +} +bool filterRangeCompie (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { + return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) < 0; +} + +rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { + if (FILTER_GET_FLAG(sflag, RA_NULL)) { + if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + return filterRangeCompLe; + } + + return filterRangeCompLi; + } + + if (FILTER_GET_FLAG(eflag, RA_NULL)) { + if (FILTER_GET_FLAG(sflag, RA_EXCLUDE)) { + return filterRangeCompGe; + } + + return filterRangeCompGi; + } + + if (FILTER_GET_FLAG(sflag, RA_EXCLUDE)) { + if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + return filterRangeCompee; + } + + return filterRangeCompei; + } + + if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + return filterRangeCompie; + } + + return filterRangeCompii; +} + + static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); @@ -80,7 +138,7 @@ int32_t filterInitUnitsFields(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } -static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, SFilterRange* ra) { +static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilterRange* ra) { SFilterRangeNode *r = NULL; if (ctx->rf) { @@ -97,13 +155,13 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRMCtx *ctx, SFilterR return r; } -void* filterInitMergeRange(int32_t type, int32_t options) { +void* filterInitRangeCtx(int32_t type, int32_t options) { if (type > TSDB_DATA_TYPE_UBIGINT || type < TSDB_DATA_TYPE_BOOL || type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { qError("not supported range type:%d", type); return NULL; } - SFilterRMCtx *ctx = calloc(1, sizeof(SFilterRMCtx)); + SFilterRangeCtx *ctx = calloc(1, sizeof(SFilterRangeCtx)); ctx->type = type; ctx->options = options; @@ -113,7 +171,7 @@ void* filterInitMergeRange(int32_t type, int32_t options) { } -int32_t filterResetMergeRangeCtx(SFilterRMCtx *ctx) { +int32_t filterResetRangeCtx(SFilterRangeCtx *ctx) { ctx->status = 0; if (ctx->rf == NULL) { @@ -137,8 +195,8 @@ int32_t filterResetMergeRangeCtx(SFilterRMCtx *ctx) { return TSDB_CODE_SUCCESS; } -int32_t filterReuseMergeRangeCtx(SFilterRMCtx *ctx, int32_t type, int32_t options) { - filterResetMergeRangeCtx(ctx); +int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options) { + filterResetRangeCtx(ctx); ctx->type = type; ctx->options = options; @@ -148,7 +206,7 @@ int32_t filterReuseMergeRangeCtx(SFilterRMCtx *ctx, int32_t type, int32_t option } -int32_t filterPostProcessRange(SFilterRMCtx *cur, SFilterRange *ra, bool *notNull) { +int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) { if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type)); if (sr == 0) { @@ -173,8 +231,8 @@ int32_t filterPostProcessRange(SFilterRMCtx *cur, SFilterRange *ra, bool *notNul return TSDB_CODE_SUCCESS; } -int32_t filterAddMergeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { - SFilterRMCtx *ctx = (SFilterRMCtx *)h; +int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, bool *all) { + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (optr == TSDB_RELATION_AND) { SET_AND_OPTR(ctx, raOptr); @@ -195,8 +253,8 @@ int32_t filterAddMergeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b -int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { - SFilterRMCtx *ctx = (SFilterRMCtx *)h; +int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (ctx->rs == NULL) { if ((FILTER_GET_FLAG(ctx->status, MR_ST_START) == 0) @@ -321,11 +379,11 @@ int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { if (ctx->rs && ctx->rs->next == NULL) { bool notnull; - filterPostProcessRange(ctx, &ctx->rs->ra, ¬null); + filterConvertRange(ctx, &ctx->rs->ra, ¬null); if (notnull) { bool all = false; FREE_FROM_RANGE(ctx, ctx->rs); - filterAddMergeOptr(h, TSDB_RELATION_NOTNULL, optr, NULL, &all); + filterAddRangeOptr(h, TSDB_RELATION_NOTNULL, optr, NULL, &all); if (all) { FILTER_SET_FLAG(ctx->status, MR_ST_ALL); } @@ -335,8 +393,8 @@ int32_t filterAddMergeRangeImpl(void* h, SFilterRange* ra, int32_t optr) { return TSDB_CODE_SUCCESS; } -int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { - SFilterRMCtx *ctx = (SFilterRMCtx *)h; +int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) { + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (FILTER_GET_FLAG(ra->sflag, RA_NULL)) { SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); @@ -348,23 +406,15 @@ int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr) { //FILTER_CLR_FLAG(ra->eflag, RA_NULL); } - return filterAddMergeRangeImpl(h, ra, optr); + return filterAddRangeImpl(h, ra, optr); } -int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { - SFilterRMCtx *dctx = (SFilterRMCtx *)dst; - SFilterRMCtx *sctx = (SFilterRMCtx *)src; +int32_t filterAddRangeCtx(void *dst, void *src, int32_t optr) { + SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst; + SFilterRangeCtx *sctx = (SFilterRangeCtx *)src; - if (optr == TSDB_RELATION_AND) { - dctx->isnull &= sctx->isnull; - dctx->notnull &= sctx->notnull; - dctx->isrange &= sctx->isrange; - } else { - dctx->isnull |= sctx->isnull; - dctx->notnull |= sctx->notnull; - dctx->isrange |= sctx->isrange; - } + assert(optr == TSDB_RELATION_OR); if (sctx->rs == NULL) { return TSDB_CODE_SUCCESS; @@ -373,16 +423,16 @@ int32_t filterAddMergeRangeCtx(void *dst, void *src, int32_t optr) { SFilterRangeNode *r = sctx->rs; while (r) { - filterAddMergeRange(dctx, &r->ra, optr); + filterAddRange(dctx, &r->ra, optr); r = r->next; } return TSDB_CODE_SUCCESS; } -int32_t filterCopyMergeRangeCtx(void *dst, void *src) { - SFilterRMCtx *dctx = (SFilterRMCtx *)dst; - SFilterRMCtx *sctx = (SFilterRMCtx *)src; +int32_t filterCopyRangeCtx(void *dst, void *src) { + SFilterRangeCtx *dctx = (SFilterRangeCtx *)dst; + SFilterRangeCtx *sctx = (SFilterRangeCtx *)src; dctx->status = sctx->status; @@ -408,8 +458,8 @@ int32_t filterCopyMergeRangeCtx(void *dst, void *src) { -int32_t filterFinMergeRange(void* h) { - SFilterRMCtx *ctx = (SFilterRMCtx *)h; +int32_t filterFinishRange(void* h) { + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; if (FILTER_GET_FLAG(ctx->status, MR_ST_FIN)) { return TSDB_CODE_SUCCESS; @@ -440,10 +490,10 @@ int32_t filterFinMergeRange(void* h) { return TSDB_CODE_SUCCESS; } -int32_t filterGetMergeRangeNum(void* h, int32_t* num) { - filterFinMergeRange(h); +int32_t filterGetRangeNum(void* h, int32_t* num) { + filterFinishRange(h); - SFilterRMCtx *ctx = (SFilterRMCtx *)h; + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; *num = 0; @@ -458,10 +508,10 @@ int32_t filterGetMergeRangeNum(void* h, int32_t* num) { } -int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra) { - filterFinMergeRange(h); +int32_t filterGetRangeRes(void* h, SFilterRange *ra) { + filterFinishRange(h); - SFilterRMCtx *ctx = (SFilterRMCtx *)h; + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; uint32_t num = 0; SFilterRangeNode* r = ctx->rs; @@ -482,28 +532,28 @@ int32_t filterGetMergeRangeRes(void* h, SFilterRange *ra) { } -int32_t filterSourceRangeFromCtx(SFilterRMCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) { - SFilterRMCtx *src = (SFilterRMCtx *)sctx; +int32_t filterSourceRangeFromCtx(SFilterRangeCtx *ctx, void *sctx, int32_t optr, bool *empty, bool *all) { + SFilterRangeCtx *src = (SFilterRangeCtx *)sctx; if (src->isnull){ - filterAddMergeOptr(ctx, TSDB_RELATION_ISNULL, optr, empty, all); + filterAddRangeOptr(ctx, TSDB_RELATION_ISNULL, optr, empty, all); if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { *all = true; } } if (src->notnull) { - filterAddMergeOptr(ctx, TSDB_RELATION_NOTNULL, optr, empty, all); + filterAddRangeOptr(ctx, TSDB_RELATION_NOTNULL, optr, empty, all); if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { *all = true; } } if (src->isrange) { - filterAddMergeOptr(ctx, 0, optr, empty, all); + filterAddRangeOptr(ctx, 0, optr, empty, all); if (!(optr == TSDB_RELATION_OR && ctx->notnull)) { - filterAddMergeRangeCtx(ctx, src, optr); + filterAddRangeCtx(ctx, src, optr); } if (FILTER_GET_FLAG(ctx->status, MR_ST_ALL)) { @@ -516,12 +566,12 @@ int32_t filterSourceRangeFromCtx(SFilterRMCtx *ctx, void *sctx, int32_t optr, bo -int32_t filterFreeMergeRange(void* h) { +int32_t filterFreeRangeCtx(void* h) { if (h == NULL) { return TSDB_CODE_SUCCESS; } - SFilterRMCtx *ctx = (SFilterRMCtx *)h; + SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; SFilterRangeNode *r = ctx->rs; SFilterRangeNode *rn = NULL; @@ -657,7 +707,7 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldId *fid) { CHK_LRET(node == NULL, TSDB_CODE_QRY_APP_ERROR, "empty node"); - CHK_LRET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR, "invalid nodeType:%d", node->nodeType); + CHK_RET(node->nodeType != TSQL_NODE_COL && node->nodeType != TSQL_NODE_VALUE, TSDB_CODE_QRY_APP_ERROR); int32_t type; void *v; @@ -835,7 +885,7 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u } -int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRMCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { +int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right; uint16_t uidx = 0; @@ -1042,67 +1092,106 @@ int32_t filterInitUnitFunc(SFilterInfo *info) { -void filterDumpInfoToString(SFilterInfo *info, const char *msg) { - CHK_LRETV(info == NULL, "%s - FilterInfo: empty", msg); +void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) { + if (qDebugFlag & DEBUG_DEBUG) { + CHK_LRETV(info == NULL, "%s - FilterInfo: EMPTY", msg); - qDebug("%s - FilterInfo:", msg); - qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { - SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; - SSchema *sch = field->desc; - qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); - } - - qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num); - for (uint16_t i = 0; i < info->fields[FLD_TYPE_VALUE].num; ++i) { - SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; - if (field->desc) { - tVariant *var = field->desc; - if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { - qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); - } else { - qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + if (options == 0) { + qDebug("%s - FilterInfo:", msg); + qDebug("COLUMN Field Num:%u", info->fields[FLD_TYPE_COLUMN].num); + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + SFilterField *field = &info->fields[FLD_TYPE_COLUMN].fields[i]; + SSchema *sch = field->desc; + qDebug("COL%d => [%d][%s]", i, sch->colId, sch->name); } - } else { - qDebug("VAL%d => [type:NIL][val:0x%" PRIx64"]", i, *(int64_t *)field->data); //TODO - } - } - qDebug("Unit Num:%u", info->unitNum); - for (uint16_t i = 0; i < info->unitNum; ++i) { - SFilterUnit *unit = &info->units[i]; - int32_t type = FILTER_UNIT_DATA_TYPE(unit); - int32_t len = 0; - int32_t tlen = 0; - char str[128] = {0}; - - SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); - SSchema *sch = left->desc; - len = sprintf(str, "UNIT[%d] => [%d][%s] %s [", i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str); - - if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != TSDB_RELATION_IN) { - SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); - char *data = right->data; - if (IS_VAR_DATA_TYPE(type)) { - tlen = varDataLen(data); - data += VARSTR_HEADER_SIZE; + qDebug("VALUE Field Num:%u", info->fields[FLD_TYPE_VALUE].num); + for (uint16_t i = 0; i < info->fields[FLD_TYPE_VALUE].num; ++i) { + SFilterField *field = &info->fields[FLD_TYPE_VALUE].fields[i]; + if (field->desc) { + tVariant *var = field->desc; + if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { + qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); + } else { + qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + } + } else { + qDebug("VAL%d => [type:NIL][val:0x%" PRIx64"]", i, *(int64_t *)field->data); //TODO + } } - converToStr(str + len, type, data, tlen, &tlen); - } else { - strcat(str, "NULL"); + + qDebug("UNIT Num:%u", info->unitNum); + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit *unit = &info->units[i]; + int32_t type = FILTER_UNIT_DATA_TYPE(unit); + int32_t len = 0; + int32_t tlen = 0; + char str[128] = {0}; + + SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); + SSchema *sch = left->desc; + len = sprintf(str, "UNIT[%d] => [%d][%s] %s [", i, sch->colId, sch->name, gOptrStr[unit->compare.optr].str); + + if (unit->right.type == FLD_TYPE_VALUE && FILTER_UNIT_OPTR(unit) != TSDB_RELATION_IN) { + SFilterField *right = FILTER_UNIT_RIGHT_FIELD(info, unit); + char *data = right->data; + if (IS_VAR_DATA_TYPE(type)) { + tlen = varDataLen(data); + data += VARSTR_HEADER_SIZE; + } + converToStr(str + len, type, data, tlen, &tlen); + } else { + strcat(str, "NULL"); + } + strcat(str, "]"); + + qDebug("%s", str); //TODO + } + + qDebug("GROUP Num:%u", info->groupNum); + for (uint16_t i = 0; i < info->groupNum; ++i) { + SFilterGroup *group = &info->groups[i]; + qDebug("Group%d : unit num[%u]", i, group->unitNum); + + for (uint16_t u = 0; u < group->unitNum; ++u) { + qDebug("unit id:%u", group->unitIdxs[u]); + } + } + + return; } - strcat(str, "]"); - - qDebug("%s", str); //TODO - } - qDebug("Group Num:%u", info->groupNum); - for (uint16_t i = 0; i < info->groupNum; ++i) { - SFilterGroup *group = &info->groups[i]; - qDebug("Group%d : unit num[%u]", i, group->unitNum); + qDebug("%s - RANGE info:", msg); - for (uint16_t u = 0; u < group->unitNum; ++u) { - qDebug("unit id:%u", group->unitIdxs[u]); + qDebug("RANGE Num:%u", info->colRangeNum); + for (uint16_t i = 0; i < info->colRangeNum; ++i) { + SFilterRangeCtx *ctx = info->colRange[i]; + qDebug("Column ID[%d] RANGE: isnull[%d],notnull[%d],range[%d]", ctx->colId, ctx->isnull, ctx->notnull, ctx->isrange); + if (ctx->isrange) { + SFilterRangeNode *r = ctx->rs; + while (r) { + char str[128] = {0}; + int32_t tlen = 0; + if (FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { + strcat(str,"(NULL)"); + } else { + FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + converToStr(str + strlen(str), ctx->type, &r->ra.s, tlen, &tlen); + FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + } + strcat(str, " - "); + if (FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { + strcat(str, "(NULL)"); + } else { + FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + converToStr(str + strlen(str), ctx->type, &r->ra.e, tlen, &tlen); + FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + } + qDebug("range: %s", str); + + r = r->next; + } + } } } } @@ -1114,10 +1203,10 @@ void filterFreeColInfo(void *data) { return; } - if (info->type == RANGE_TYPE_COL_RANGE) { - tfree(info->info); + if (info->type == RANGE_TYPE_VAR_HASH) { + //TODO } else if (info->type == RANGE_TYPE_MR_CTX) { - filterFreeMergeRange(info->info); + filterFreeRangeCtx(info->info); } else if (info->type == RANGE_TYPE_UNIT) { taosArrayDestroy((SArray *)info->info); } @@ -1132,7 +1221,7 @@ void filterFreeColCtx(void *data) { SFilterColCtx* ctx = (SFilterColCtx *)data; if (ctx->ctx) { - filterFreeMergeRange(ctx->ctx); + filterFreeRangeCtx(ctx->ctx); } } @@ -1259,7 +1348,7 @@ bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { } -int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, int32_t optr) { +int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *ctx, int32_t optr) { int32_t type = FILTER_UNIT_DATA_TYPE(u); uint8_t uoptr = FILTER_UNIT_OPTR(u); void *val = FILTER_UNIT_VAL_DATA(info, u); @@ -1304,12 +1393,12 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRMCtx *ctx, assert(0); } - filterAddMergeRange(ctx, &ra, optr); + filterAddRange(ctx, &ra, optr); return TSDB_CODE_SUCCESS; } -int32_t filterCompareRMCtx(SFilterRMCtx *ctx1, SFilterRMCtx *ctx2, bool *equal) { +int32_t filterCompareRangeCtx(SFilterRangeCtx *ctx1, SFilterRangeCtx *ctx2, bool *equal) { CHK_JMP(ctx1->status != ctx2->status); CHK_JMP(ctx1->isnull != ctx2->isnull); CHK_JMP(ctx1->notnull != ctx2->notnull); @@ -1344,13 +1433,13 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colI SArray* colArray = (SArray *)gRes->colInfo[colIdx].info; int32_t size = (int32_t)taosArrayGetSize(colArray); int32_t type = gRes->colInfo[colIdx].dataType; - SFilterRMCtx* ctx = filterInitMergeRange(type, 0); + SFilterRangeCtx* ctx = filterInitRangeCtx(type, 0); for (uint32_t i = 0; i < size; ++i) { SFilterUnit* u = taosArrayGetP(colArray, i); uint8_t optr = FILTER_UNIT_OPTR(u); - filterAddMergeOptr(ctx, optr, TSDB_RELATION_AND, empty, NULL); + filterAddRangeOptr(ctx, optr, TSDB_RELATION_AND, empty, NULL); CHK_JMP(*empty); if (!FILTER_NO_MERGE_OPTR(optr)) { @@ -1369,7 +1458,7 @@ _err_return: *empty = true; - filterFreeMergeRange(ctx); + filterFreeRangeCtx(ctx); return TSDB_CODE_SUCCESS; @@ -1446,7 +1535,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t return TSDB_CODE_SUCCESS; } -void filterCheckColumns(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { +void filterCheckColConflict(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *conflict) { uint16_t idx1 = 0, idx2 = 0, m = 0, n = 0; bool equal = false; @@ -1487,20 +1576,20 @@ void filterCheckColumns(SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *co } -int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRMCtx **ctx, int32_t optr, uint16_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { +int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRangeCtx **ctx, int32_t optr, uint16_t cidx, SFilterGroupCtx* gRes1, SFilterGroupCtx* gRes2, bool *empty, bool *all) { SFilterField *fi = FILTER_GET_COL_FIELD(info, cidx); int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); if ((*ctx) == NULL) { - *ctx = filterInitMergeRange(type, 0); + *ctx = filterInitRangeCtx(type, 0); } else { - filterReuseMergeRangeCtx(*ctx, type, 0); + filterReuseRangeCtx(*ctx, type, 0); } assert(gRes2->colInfo[cidx].type == RANGE_TYPE_MR_CTX); assert(gRes1->colInfo[cidx].type == RANGE_TYPE_MR_CTX); - filterCopyMergeRangeCtx(*ctx, gRes2->colInfo[cidx].info); + filterCopyRangeCtx(*ctx, gRes2->colInfo[cidx].info); filterSourceRangeFromCtx(*ctx, gRes1->colInfo[cidx].info, optr, empty, all); return TSDB_CODE_SUCCESS; @@ -1510,7 +1599,7 @@ int32_t filterMergeTwoGroupsImpl(SFilterInfo *info, SFilterRMCtx **ctx, int32_t int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilterGroupCtx** gRes2, bool *all) { bool conflict = false; - filterCheckColumns(*gRes1, *gRes2, &conflict); + filterCheckColConflict(*gRes1, *gRes2, &conflict); if (conflict) { return TSDB_CODE_SUCCESS; } @@ -1521,7 +1610,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter bool numEqual = (*gRes1)->colNum == (*gRes2)->colNum; bool equal = false; uint16_t equal1 = 0, equal2 = 0, merNum = 0; - SFilterRMCtx *ctx = NULL; + SFilterRangeCtx *ctx = NULL; SFilterColCtx colCtx = {0}; SArray* colCtxs = taosArrayInit((*gRes2)->colNum, sizeof(SFilterColCtx)); @@ -1551,12 +1640,12 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter taosArrayPush(colCtxs, &colCtx); break; } else { - filterCompareRMCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); + filterCompareRangeCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); if (equal) { ++equal1; } - filterCompareRMCtx(ctx, (*gRes2)->colInfo[idx2].info, &equal); + filterCompareRangeCtx(ctx, (*gRes2)->colInfo[idx2].info, &equal); if (equal) { ++equal2; } @@ -1568,7 +1657,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter taosArrayPush(colCtxs, &colCtx); } } else { - filterCompareRMCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); + filterCompareRangeCtx(ctx, (*gRes1)->colInfo[idx1].info, &equal); if (equal) { ++equal1; } @@ -1616,7 +1705,7 @@ _err_return: taosArrayDestroyEx(colCtxs, filterFreeColCtx); } - filterFreeMergeRange(ctx); + filterFreeRangeCtx(ctx); return TSDB_CODE_SUCCESS; } @@ -1786,6 +1875,105 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum return TSDB_CODE_SUCCESS; } +int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum) { + uint16_t *idxs = NULL; + uint16_t colNum = 0; + SFilterGroupCtx *res = NULL; + uint16_t *idxNum = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxNum)); + + for (int32_t i = 0; i < gResNum; ++i) { + for (uint16_t m = 0; m < gRes[i]->colNum; ++m) { + SFilterColInfo *colInfo = &gRes[i]->colInfo[gRes[i]->colIdx[m]]; + if (FILTER_NO_MERGE_DATA_TYPE(colInfo->dataType)) { + continue; + } + + ++idxNum[gRes[i]->colIdx[m]]; + } + } + + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { + if (idxNum[i] < gResNum) { + continue; + } + + assert(idxNum[i] == gResNum); + + if (idxs == NULL) { + idxs = calloc(info->fields[FLD_TYPE_COLUMN].num, sizeof(*idxs)); + } + + idxs[colNum++] = i; + } + + CHK_JMP(colNum <= 0); + + info->colRangeNum = colNum; + info->colRange = calloc(colNum, POINTER_BYTES); + + for (int32_t i = 0; i < gResNum; ++i) { + res = gRes[i]; + uint16_t n = 0; + + for (uint16_t m = 0; m < info->colRangeNum; ++m) { + for (; n < res->colNum; ++n) { + if (res->colIdx[n] < idxs[m]) { + continue; + } + + assert(res->colIdx[n] == idxs[m]); + + SFilterColInfo * colInfo = &res->colInfo[res->colIdx[n]]; + if (info->colRange[m] == NULL) { + info->colRange[m] = filterInitRangeCtx(colInfo->dataType, 0); + SFilterField* fi = FILTER_GET_COL_FIELD(info, res->colIdx[n]); + info->colRange[m]->colId = ((SSchema*)fi->desc)->colId; + } + + assert(colInfo->type == RANGE_TYPE_MR_CTX); + + bool all = false; + filterSourceRangeFromCtx(info->colRange[m], colInfo->info, TSDB_RELATION_OR, NULL, &all); + if (all) { + filterFreeRangeCtx(info->colRange[m]); + info->colRange[m] = NULL; + + if (m < (info->colRangeNum - 1)) { + memmove(&info->colRange[m], &info->colRange[m + 1], (info->colRangeNum - m - 1) * POINTER_BYTES); + memmove(&idxs[m], &idxs[m + 1], (info->colRangeNum - m - 1) * sizeof(*idxs)); + } + + --info->colRangeNum; + --m; + + CHK_JMP(info->colRangeNum <= 0); + } + + ++n; + break; + } + } + } + +_err_return: + tfree(idxs); + + return TSDB_CODE_SUCCESS; +} + +int32_t filterPostProcessRange(SFilterInfo *info) { + for (uint16_t i = 0; i < info->colRangeNum; ++i) { + SFilterRangeCtx* ctx = info->colRange[i]; + SFilterRangeNode *r = ctx->rs; + while (r) { + r->rc.func = filterGetRangeCompFunc(r->ra.sflag, r->ra.eflag); + r = r->next; + } + } + + return TSDB_CODE_SUCCESS; +} + int32_t filterPreprocess(SFilterInfo *info) { SFilterGroupCtx** gRes = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); @@ -1805,9 +1993,13 @@ int32_t filterPreprocess(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - //TODO GET COLUMN RANGE - filterRewrite(info, gRes, gResNum); + + filterGenerateColRange(info, gRes, gResNum); + + filterDumpInfoToString(info, "Final", 1); + + filterPostProcessRange(info); return TSDB_CODE_SUCCESS; } @@ -1919,7 +2111,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option ERR_JRET(filterInitValFieldData(info)); if (!FILTER_GET_FLAG(info->options, FI_OPTION_NO_REWRITE)) { - filterDumpInfoToString(info, "Before preprocess"); + filterDumpInfoToString(info, "Before preprocess", 0); ERR_JRET(filterPreprocess(info)); @@ -1936,7 +2128,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); - filterDumpInfoToString(info, "Final"); + filterDumpInfoToString(info, "Final", 0); taosArrayDestroy(group); @@ -1954,15 +2146,95 @@ _err_return: return code; } +FORCE_INLINE bool filterIsEmptyRes(SFilterInfo *info) { + if (info == NULL) { + return false; + } + + return FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY); +} + + +bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t numOfCols, int32_t numOfRows) { + if (filterIsEmptyRes(info)) { + return false; + } + + bool ret = true; + void *minVal, *maxVal; + + for (int32_t k = 0; k < info->colRangeNum; ++k) { + int32_t index = -1; + SFilterRangeCtx *ctx = info->colRange[k]; + for(int32_t i = 0; i < numOfCols; ++i) { + if (pDataStatis[i].colId == ctx->colId) { + index = i; + break; + } + } + + // no statistics data, load the true data block + if (index == -1) { + return true; + } + + // not support pre-filter operation on binary/nchar data type + if (!IS_PREFILTER_TYPE(ctx->type)) { + return true; + } + + if ((pDataStatis[index].numOfNull <= 0) && (ctx->isnull && !ctx->notnull && !ctx->isrange)) { + return false; + } + + // all data in current column are NULL, no need to check its boundary value + if (pDataStatis[index].numOfNull == numOfRows) { + + // if isNULL query exists, load the null data column + if ((ctx->notnull || ctx->isrange) && (!ctx->isnull)) { + return false; + } + + continue; + } + + SDataStatis* pDataBlockst = &pDataStatis[index]; + + SFilterRangeNode r = ctx->rs; + + if (ctx->type == TSDB_DATA_TYPE_FLOAT) { + float minv = (float)(*(double *)(&pDataBlockst->min)); + float maxv = (float)(*(double *)(&pDataBlockst->max)); + + minVal = &minv; + maxVal = &maxv; + } else { + minVal = &pDataBlockst->min; + maxVal = &pDataBlockst->max; + } + + while (r) { + ret = r->rc.func(minVal, maxVal, &r->rc.s, &r->rc.e, ctx->pCompareFunc); + CHK_RET(!ret, ret); + + r = r->next; + } + } + + return ret; +} + + + int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { SFilterRange ra = {0}; - SFilterRMCtx *prev = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); - SFilterRMCtx *tmpc = filterInitMergeRange(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); - SFilterRMCtx *cur = NULL; + SFilterRangeCtx *prev = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); + SFilterRangeCtx *tmpc = filterInitRangeCtx(TSDB_DATA_TYPE_TIMESTAMP, FI_OPTION_TIMESTAMP); + SFilterRangeCtx *cur = NULL; int32_t num = 0; int32_t optr = 0; int32_t code = TSDB_CODE_QRY_INVALID_TIME_CONDITION; - bool empty = false; + bool empty = false, all = false; for (int32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *group = &info->groups[i]; @@ -1980,7 +2252,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { uint8_t raOptr = FILTER_UNIT_OPTR(unit); - filterAddMergeOptr(cur, raOptr, TSDB_RELATION_AND, &empty, NULL); + filterAddRangeOptr(cur, raOptr, TSDB_RELATION_AND, &empty, NULL); CHK_JMP(empty); if (FILTER_NO_MERGE_OPTR(raOptr)) { @@ -1994,7 +2266,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { SIMPLE_COPY_VALUES(&ra.s, s); SIMPLE_COPY_VALUES(&ra.e, e); - filterAddMergeRange(cur, &ra, optr); + filterAddRange(cur, &ra, optr); } if (cur->notnull) { @@ -2003,28 +2275,31 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { } if (group->unitNum > 1) { - filterAddMergeRangeCtx(prev, cur, TSDB_RELATION_OR); - filterResetMergeRangeCtx(cur); + filterSourceRangeFromCtx(prev, cur, TSDB_RELATION_OR, &empty, &all); + filterResetRangeCtx(cur); + if (all) { + break; + } } } if (prev->notnull) { *win = TSWINDOW_INITIALIZER; } else { - filterGetMergeRangeNum(prev, &num); + filterGetRangeNum(prev, &num); if (num != 1) { qError("only one time range accepted, num:%d", num); ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); } SFilterRange tra; - filterGetMergeRangeRes(prev, &tra); + filterGetRangeRes(prev, &tra); win->skey = tra.s; win->ekey = tra.e; } - filterFreeMergeRange(prev); - filterFreeMergeRange(tmpc); + filterFreeRangeCtx(prev); + filterFreeRangeCtx(tmpc); qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); return TSDB_CODE_SUCCESS; @@ -2033,8 +2308,8 @@ _err_return: *win = TSWINDOW_DESC_INITIALIZER; - filterFreeMergeRange(prev); - filterFreeMergeRange(tmpc); + filterFreeRangeCtx(prev); + filterFreeRangeCtx(tmpc); qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index 64f7fdddae..bf6971b9dc 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -11,7 +11,7 @@ #pragma GCC diagnostic ignored "-Wunused-variable" extern "C" { - extern int32_t filterAddMergeRange(void* h, SFilterRange* ra, int32_t optr); + extern int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr); } namespace { @@ -46,86 +46,86 @@ void intDataTest() { e = e0; asize = sizeof(s0)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 3); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, -100); ASSERT_EQ(ra[0].e, 0); ASSERT_EQ(ra[1].s, 1); ASSERT_EQ(ra[1].e, 2); ASSERT_EQ(ra[2].s, 3); ASSERT_EQ(ra[2].e, 4); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, FI_OPTION_TIMESTAMP); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, FI_OPTION_TIMESTAMP); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, -100); ASSERT_EQ(ra[0].e, 4); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); s = s1; e = e1; asize = sizeof(s1)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 3); ASSERT_EQ(ra[0].e, 4); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, INT64_MIN); ASSERT_EQ(ra[0].e, 100); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); @@ -133,93 +133,93 @@ void intDataTest() { e = e2; asize = sizeof(s2)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 1); ASSERT_EQ(ra[0].e, 120); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); + filterAddRange(h, ra, i % 2 ? TSDB_RELATION_OR : TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); + filterAddRange(h, ra, i % 2 ? TSDB_RELATION_AND : TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 70); ASSERT_EQ(ra[0].e, 120); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); s = s3; e = e3; asize = sizeof(s3)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 1); ASSERT_EQ(ra[0].e, 100); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); @@ -228,84 +228,84 @@ void intDataTest() { e = e4; asize = sizeof(s4)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 2); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 0); ASSERT_EQ(ra[0].e, 5); ASSERT_EQ(ra[1].s, 10); ASSERT_EQ(ra[1].e, 20); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); s = s5; e = e5; asize = sizeof(s5)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_AND); + filterAddRange(h, ra, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, TSDB_RELATION_OR); + filterAddRange(h, ra, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 2); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 0); ASSERT_EQ(ra[0].e, 4); ASSERT_EQ(ra[1].s, 6); ASSERT_EQ(ra[1].e, 20); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].s = s[i]; ra[0].e = e[i]; - filterAddMergeRange(h, ra, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); + filterAddRange(h, ra, (i == (asize -1)) ? TSDB_RELATION_AND : TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 1); - filterGetMergeRangeRes(h, ra); + filterGetRangeRes(h, ra); ASSERT_EQ(ra[0].s, 7); ASSERT_EQ(ra[0].e, 10); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); @@ -315,7 +315,7 @@ void intDataTest() { e = e6; asize = sizeof(s6)/sizeof(s[0]); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].eflag = 1; ra[1].sflag = 4; @@ -323,16 +323,16 @@ void intDataTest() { ra[i].s = s[i]; ra[i].e = e[i]; - filterAddMergeRange(h, ra + i, TSDB_RELATION_AND); + filterAddRange(h, ra + i, TSDB_RELATION_AND); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 0); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); memset(ra, 0, sizeof(ra)); - h = filterInitMergeRange(TSDB_DATA_TYPE_BIGINT, 0); + h = filterInitRangeCtx(TSDB_DATA_TYPE_BIGINT, 0); for (int32_t i = 0; i < asize; ++i) { ra[0].eflag = 1; ra[1].sflag = 1; @@ -340,9 +340,9 @@ void intDataTest() { ra[i].s = s[i]; ra[i].e = e[i]; - filterAddMergeRange(h, ra + i, TSDB_RELATION_OR); + filterAddRange(h, ra + i, TSDB_RELATION_OR); } - filterGetMergeRangeNum(h, &num); + filterGetRangeNum(h, &num); ASSERT_EQ(num, 2); ASSERT_EQ(ra[0].s, 0); ASSERT_EQ(ra[0].e, 4); @@ -350,7 +350,7 @@ void intDataTest() { ASSERT_EQ(ra[1].s, 4); ASSERT_EQ(ra[1].e, 6); ASSERT_EQ(ra[1].sflag, 1); - filterFreeMergeRange(h); + filterFreeRangeCtx(h); } diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index d11d7ab6da..a512cf4028 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -174,6 +174,7 @@ if $rows != 0 then return -1 endi +#xxx sql select * from stb1 where c8 = '51' or c8 != '51'; if $rows != 28 then return -1 @@ -1072,6 +1073,34 @@ endi if $data01 != NULL then return -1 endi + +#xxx +sql select * from stb1 where c8 like '1'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi + +#xxx +sql select * from stb1 where c8 like '1%' and c8 like '%1'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi + +#xxx +sql select * from stb1 where c8 like '1' and c8 like '2'; +if $rows != 0 then + return -1 +endi + sql select * from stb1 where c9 is null; if $rows != 1 then return -1 @@ -1817,6 +1846,48 @@ if $data20 != @21-05-05 18:19:12.000@ then return -1 endi +sql select * from stb1 where c1 > 40 and c2 > 50 and c3 > 62 or c1 < 2 and c2 < 3; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30); +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30) or (c1 is null and c2 is null); +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c3 < 30) or (c1 is null and c2 is null); +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 > 60 and c2 < 63) or (c1 >62 and c3 < 30) or (c1 is null and c2 is null); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' From cfa925dd17be2e7c36e8f4763beaae12f5308603 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 26 Jul 2021 09:54:24 +0800 Subject: [PATCH 026/100] support range filter --- src/query/inc/qFilter.h | 6 +- src/query/src/qExecutor.c | 2 +- src/query/src/qFilter.c | 36 +- tests/script/general/parser/condition.sim | 2426 +-------------------- 4 files changed, 58 insertions(+), 2412 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 3f34173d24..4ed30853e8 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -22,6 +22,7 @@ extern "C" { #include "texpr.h" #include "hash.h" +#include "tname.h" #define FILTER_DEFAULT_GROUP_SIZE 4 #define FILTER_DEFAULT_UNIT_SIZE 4 @@ -91,14 +92,14 @@ typedef struct SFilterColRange { SFilterRange ra; } SFilterColRange; +typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); + typedef struct SFilterRangeCompare { int64_t s; int64_t e; rangeCompFunc func; } SFilterRangeCompare; -typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); - typedef struct SFilterRangeNode { struct SFilterRangeNode* prev; struct SFilterRangeNode* next; @@ -294,6 +295,7 @@ extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); extern void filterFreeInfo(SFilterInfo *info); extern bool filterIsEmptyRes(SFilterInfo *info); +extern bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t numOfCols, int32_t numOfRows); #ifdef __cplusplus } diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 7d7dd85814..34896babe9 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2402,7 +2402,7 @@ static FORCE_INLINE bool doFilterByBlockStatistics(SQueryRuntimeEnv* pRuntimeEnv return true; } - return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, numOfRows); + return filterRangeExecute(pQueryAttr->pFilters, pDataStatis, pQueryAttr->numOfCols, numOfRows); } static bool overlapWithTimeWindow(SQueryAttr* pQueryAttr, SDataBlockInfo* pBlockInfo) { diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index a02f284b88..7ee19e88b3 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -57,28 +57,28 @@ filter_desc_compare_func gDescCompare [FLD_TYPE_MAX] = { filterFieldValDescCompare }; -bool filterRangeCompGi (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompGi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) >= 0; } -bool filterRangeCompGe (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompGe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) > 0; } -bool filterRangeCompLi (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompLi (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(minv, maxr) <= 0; } -bool filterRangeCompLe (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompLe (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(minv, maxr) < 0; } -bool filterRangeCompii (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompii (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) <= 0; } -bool filterRangeCompee (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompee (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) < 0; } -bool filterRangeCompei (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompei (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) > 0 && cfunc(minv, maxr) <= 0; } -bool filterRangeCompie (const char *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { +bool filterRangeCompie (const void *minv, const void *maxv, const void *minr, const void *maxr, __compar_fn_t cfunc) { return cfunc(maxv, minr) >= 0 && cfunc(minv, maxr) < 0; } @@ -1823,6 +1823,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum } SFilterInfo oinfo = *info; + SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SFilterGroupCtx *res = NULL; SFilterColInfo *colInfo = NULL; @@ -1830,6 +1831,10 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum uint16_t uidx = 0; memset(info, 0, sizeof(*info)); + info->colRangeNum = oinfo.colRangeNum; + info->colRange = oinfo.colRange; + oinfo.colRangeNum = 0; + oinfo.colRange = NULL; FILTER_SET_FLAG(info->options, FI_OPTION_NEED_UNIQE); @@ -1993,13 +1998,13 @@ int32_t filterPreprocess(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - filterRewrite(info, gRes, gResNum); - filterGenerateColRange(info, gRes, gResNum); filterDumpInfoToString(info, "Final", 1); filterPostProcessRange(info); + + filterRewrite(info, gRes, gResNum); return TSDB_CODE_SUCCESS; } @@ -2179,7 +2184,7 @@ bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t num } // not support pre-filter operation on binary/nchar data type - if (!IS_PREFILTER_TYPE(ctx->type)) { + if (FILTER_NO_MERGE_DATA_TYPE(ctx->type)) { return true; } @@ -2200,7 +2205,7 @@ bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t num SDataStatis* pDataBlockst = &pDataStatis[index]; - SFilterRangeNode r = ctx->rs; + SFilterRangeNode *r = ctx->rs; if (ctx->type == TSDB_DATA_TYPE_FLOAT) { float minv = (float)(*(double *)(&pDataBlockst->min)); @@ -2215,10 +2220,13 @@ bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t num while (r) { ret = r->rc.func(minVal, maxVal, &r->rc.s, &r->rc.e, ctx->pCompareFunc); - CHK_RET(!ret, ret); - + if (ret) { + break; + } r = r->next; } + + CHK_RET(!ret, ret); } return ret; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index a512cf4028..e29f154d44 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -72,2404 +72,40 @@ sql insert into tb2_2 values ('2021-05-05 18:19:13',5,6,7,8,'2021-05-05 18:28:14 sql insert into tb2_2 values ('2021-05-05 18:19:14',8,2,3,4,'2021-05-05 18:28:15') sql insert into tb2_2 values ('2021-05-05 18:19:15',5,6,7,8,'2021-05-05 18:28:16') +sql create table stb3 (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 binary(10), c9 nchar(9)) TAGS(t1 int, t2 binary(10), t3 double) + +sql create table tb3_1 using stb3 tags(1,'1',1.0) +sql create table tb3_2 using stb3 tags(2,'2',2.0) + +sql insert into tb3_1 values ('2021-01-05 18:19:00',1,1.0,1,1,1,1.0,true ,'1','1') +sql insert into tb3_1 values ('2021-02-05 18:19:01',2,2.0,2,2,2,2.0,true ,'2','2') +sql insert into tb3_1 values ('2021-03-05 18:19:02',3,3.0,3,3,3,3.0,false,'3','3') +sql insert into tb3_1 values ('2021-04-05 18:19:03',4,4.0,4,4,4,4.0,false,'4','4') +sql insert into tb3_1 values ('2021-05-05 18:19:28',5,NULL,5,NULL,5,NULL,true,NULL,'5') +sql insert into tb3_1 values ('2021-06-05 18:19:28',NULL,6.0,NULL,6,NULL,6.0,NULL,'6',NULL) +sql insert into tb3_1 values ('2021-07-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) + +sql insert into tb3_2 values ('2021-01-06 18:19:00',11,11.0,11,11,11,11.0,true ,'11','11') +sql insert into tb3_2 values ('2021-02-06 18:19:01',12,12.0,12,12,12,12.0,true ,'12','12') +sql insert into tb3_2 values ('2021-03-06 18:19:02',13,13.0,13,13,13,13.0,false,'13','13') +sql insert into tb3_2 values ('2021-04-06 18:19:03',14,14.0,14,14,14,14.0,false,'14','14') +sql insert into tb3_2 values ('2021-05-06 18:19:28',15,NULL,15,NULL,15,NULL,true,NULL,'15') +sql insert into tb3_2 values ('2021-06-06 18:19:28',NULL,16.0,NULL,16,NULL,16.0,NULL,'16',NULL) +sql insert into tb3_2 values ('2021-07-06 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) + sleep 100 -print "column test" -sql select * from stb1 -if $rows != 29 then - return -1 -endi -sql select * from stb1 where c1 > 0 -if $rows != 28 then - return -1 -endi +sql connect -sql_error select * from stb1 where c8 > 0 -sql_error select * from stb1 where c7 in (0,2,3,1); -sql_error select * from stb1 where c8 in (true); -sql_error select * from stb1 where c8 in (1,2); -sql_error select * from stb1 where t2 in (3.0); -sql_error select ts,c1,c7 from stb1 where c7 > false -sql_error select * from stb1 where c1 > NULL; -sql_error select * from stb1 where c1 = NULL; -sql_error select * from stb1 where c1 LIKE '%1'; -sql_error select * from stb1 where c2 LIKE '%1'; -sql_error select * from stb1 where c3 LIKE '%1'; -sql_error select * from stb1 where c4 LIKE '%1'; -sql_error select * from stb1 where c5 LIKE '%1'; -sql_error select * from stb1 where c6 LIKE '%1'; -sql_error select * from stb1 where c7 LIKE '%1'; -sql_error select * from stb1 where c1 = 'NULL'; -sql_error select * from stb1 where c2 > 'NULL'; -sql_error select * from stb1 where c3 <> 'NULL'; -sql_error select * from stb1 where c4 != 'null'; -sql_error select * from stb1 where c5 >= 'null'; -sql_error select * from stb1 where c6 <= 'null'; -sql_error select * from stb1 where c7 < 'nuLl'; -sql_error select * from stb1 where c8 < 'nuLl'; -sql_error select * from stb1 where c9 > 'nuLl'; -sql_error select * from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b; -sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; -sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); +run general/parser/condition_query.sim -sql select * from stb1 where c2 > 3.0 or c2 < 60; -if $rows != 28 then - return -1 -endi -sql select * from stb1 where c2 > 3.0 or c2 < 60 and c2 > 50; -if $rows != 25 then - return -1 -endi -sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50; -if $rows != 8 then - return -1 -endi +print ================== restart server to commit data into disk +system sh/exec.sh -n dnode1 -s stop -x SIGINT +sleep 100 +system sh/exec.sh -n dnode1 -s start +print ================== server restart completed +sql connect +sleep 100 -sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 and c2 != 63); -if $rows != 6 then - return -1 -endi +run general/parser/condition_query.sim -sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 or c2 != 63); -if $rows != 8 then - return -1 -endi - -sql select * from stb1 where (c3 > 3.0 or c3 < 60) and c3 > 50 and (c3 != 53 or c3 != 63); -if $rows != 8 then - return -1 -endi - -sql select * from stb1 where (c4 > 3.0 or c4 < 60) and c4 > 50 and (c4 != 53 or c4 != 63); -if $rows != 8 then - return -1 -endi - -sql select * from stb1 where (c5 > 3.0 or c5 < 60) and c5 > 50 and (c5 != 53 or c5 != 63); -if $rows != 8 then - return -1 -endi - -sql select * from stb1 where (c6 > 3.0 or c6 < 60) and c6 > 50 and (c6 != 53 or c6 != 63); -if $rows != 8 then - return -1 -endi - -sql select * from stb1 where c8 = '51'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi - -sql select * from stb1 where c8 != '51'; -if $rows != 27 then - return -1 -endi - -#xxx -sql select * from stb1 where c8 = '51' and c8 != '51'; -if $rows != 0 then - return -1 -endi - -#xxx -sql select * from stb1 where c8 = '51' or c8 != '51'; -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where c9 = '51'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi - -sql select * from stb1 where c9 != '51'; -if $rows != 27 then - return -1 -endi - -sql select * from stb1 where c9 = '51' and c9 != '51'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c9 = '51' or c9 != '51'; -if $rows != 28 then - return -1 -endi - -sql select ts,c1,c7 from stb1 where c7 = false -if $rows != 14 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data01 != 3 then - return -1 -endi -if $data02 != 0 then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data11 != 4 then - return -1 -endi -if $data12 != 0 then - return -1 -endi -if $data20 != @21-05-05 18:19:06.000@ then - return -1 -endi -if $data21 != 13 then - return -1 -endi -if $data22 != 0 then - return -1 -endi -if $data30 != @21-05-05 18:19:07.000@ then - return -1 -endi -if $data31 != 14 then - return -1 -endi -if $data32 != 0 then - return -1 -endi - - -sql select ts,c1,c7 from stb1 where c7 = true -if $rows != 14 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -if $data02 != 1 then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data11 != 2 then - return -1 -endi -if $data12 != 1 then - return -1 -endi -if $data20 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data21 != 11 then - return -1 -endi -if $data22 != 1 then - return -1 -endi -if $data30 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data31 != 12 then - return -1 -endi -if $data32 != 1 then - return -1 -endi - - -sql select * from stb1 where c8 = '51' or c8 = '4' -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data01 != 4 then - return -1 -endi -if $data10 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data11 != 51 then - return -1 -endi - - -sql select * from stb1 where c1 > 50 and c1 > 53 -if $rows != 5 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 52 -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 -if $rows != 28 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 -if $rows != 25 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 and c1 > 54 -if $rows != 4 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 or c1 > 54 -if $rows != 5 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 51 or c1 > 54 -if $rows != 4 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 and c1 > 54 -if $rows != 5 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 or c1 > 51 and c1 < 54 -if $rows != 7 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 and c1 > 54 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 or c1 > 54 -if $rows != 25 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 or c1 > 54 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 and c1 > 54 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 or c1 > 51 and c1 > 54 -if $rows != 8 then - return -1 -endi -sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 or c1 > 54 -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where (c1 > 50 and c1 > 53) and c1 < 52 -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 52) -if $rows != 0 then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) or c1 < 51 -if $rows != 28 then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) -if $rows != 28 then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53) or c1 < 51 -if $rows != 25 then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) -if $rows != 5 then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) and c1 < 51 -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) -if $rows != 8 then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53) and (c1 < 51 and c1 > 54) -if $rows != 0 then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53 and c1 < 51) and c1 > 54 -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51) and c1 > 54 -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51 or c1 > 54) -if $rows != 4 then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 and c1 > 54) -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) and c1 > 54 -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) and c1 > 54 -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 and c1 > 54) -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 and c1 > 54) -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 and c1 > 54) -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) and c1 > 54 -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) and c1 > 54 -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 or c1 > 54) -if $rows != 25 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 or c1 > 54) -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) or c1 > 54 -if $rows != 25 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) or c1 > 54 -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 or c1 > 54) -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 or c1 > 54) -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) or c1 > 54 -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) or c1 > 54 -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 and c1 > 54) -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) and c1 > 54 -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 and c1 > 54) -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) and c1 > 54 -if $rows != 8 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where c1 > 62 or (c1 > 53 or c1 < 51) and c1 > 54 -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 or c1 > 54) -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 or c1 > 54) -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) or c1 > 54 -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) or c1 > 54 -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:04.000@ then - return -1 -endi -sql select ts,c1 from stb1 where (c1 > 60 or c1 < 10 or (c1 > 20 and c1 < 30)) and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:25.000' and c1 != 21 and c1 != 22 -if $rows != 6 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data11 != 3 then - return -1 -endi -if $data20 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data21 != 4 then - return -1 -endi -if $data30 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data31 != 23 then - return -1 -endi -if $data40 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data41 != 24 then - return -1 -endi -if $data50 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data51 != 61 then - return -1 -endi - - -sql select * from stb1 where (c1 > 40 or c1 < 20) and (c2 < 53 or c2 >= 63) and c3 > 1 and c3 < 5 -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data11 != 3 then - return -1 -endi -if $data20 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data21 != 4 then - return -1 -endi - -sql select * from stb1 where (c1 > 52 or c1 < 10) and (c2 > 1 and c2 < 61) -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data11 != 3 then - return -1 -endi -if $data20 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data21 != 4 then - return -1 -endi -if $data30 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data31 != 53 then - return -1 -endi -if $data40 != @21-05-05 18:19:23.000@ then - return -1 -endi -if $data41 != 54 then - return -1 -endi - -sql select * from stb1 where (c3 > 52 or c3 < 10) and (c4 > 1 and c4 < 61) and (c5 = 2 or c6 = 3.0 or c6 = 4.0 or c6 = 53); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data01 != 2 then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data11 != 3 then - return -1 -endi -if $data20 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data21 != 4 then - return -1 -endi -if $data30 != @21-05-05 18:19:22.000@ then - return -1 -endi -if $data31 != 53 then - return -1 -endi - -sql select * from stb1 where c1 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c2 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c3 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c4 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c5 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c6 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c7 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c8 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi - -#xxx -sql select * from stb1 where c8 like '1'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi - -#xxx -sql select * from stb1 where c8 like '1%' and c8 like '%1'; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:04.000@ then - return -1 -endi - -#xxx -sql select * from stb1 where c8 like '1' and c8 like '2'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c9 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi - -sql select * from stb1 where c1 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c2 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c3 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c4 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c5 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c6 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c7 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c8 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c9 is not null; -if $rows != 28 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 1 then - return -1 -endi -sql select * from stb1 where c1 > 63 or c1 is null; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data01 != 64 then - return -1 -endi -if $data10 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data11 != NULL then - return -1 -endi -sql select * from stb1 where c1 is null and c2 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi -if $data01 != NULL then - return -1 -endi -sql select * from stb1 where c1 is null and c2 is null and c3 is not null; -if $rows != 0 then - return -1 -endi -sql select * from stb1 where c1 is null and c2 is null and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:28.000'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c1 is null and c1 > 0; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c1 is null or c1 is not null or c1 > 1; -if $rows != 29 then - return -1 -endi - -sql select * from stb1 where (c1 is null or c1 > 40) and c1 < 44; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:16.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:17.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:18.000@ then - return -1 -endi - -sql select * from stb1 where c1 in (11,21,31,41) and c1 in (11,42); -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi - -sql select * from stb1 where c8 in ('11','21','31','41') and c8 in ('11','42'); -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi - -sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:19.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:21.000@ then - return -1 -endi - -sql select * from stb1 where c8 LIKE '%1'; -if $rows != 7 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:16.000@ then - return -1 -endi -if $data50 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data60 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where c9 LIKE '%1'; -if $rows != 7 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:16.000@ then - return -1 -endi -if $data50 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data60 != @21-05-05 18:19:24.000@ then - return -1 -endi -sql select * from stb1 where (c8 LIKE '%1' or c9 like '_2') and (c5 > 50 or c6 > 30) and ( c8 like '3_' or c9 like '4_') and (c4 <= 31 or c4 >= 42); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:17.000@ then - return -1 -endi - -sql select * from stb1 where c1 in (1,3); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where c3 in (11,22); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi - -sql select * from stb1 where c4 in (3,33); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c5 in (3,33) and c8 in ('33','54'); -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select * from stb1 where c5 in (3,33) or c8 in ('22','54'); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:14.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:23.000@ then - return -1 -endi - -sql select * from stb1 where (c9 in ('3','1','2','4','5') or c9 in ('33','11','22','44','55')) and c9 in ('1','3','11','13'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:04.000@ then - return -1 -endi - -sql select * from stb2 where (u1 in (1) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) and ts2 in ('2021-05-05 18:28:02.000','2021-05-05 18:28:15.000','2021-05-05 18:28:01.000'); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi - -sql select * from stb2 where u2 in (2) and u3 in (1,2,3) and u4 in (1,2,4,5) and u1 > 3 and u1 < 6 and u1 != 4; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi - -sql select avg(c1) from tb1 where (c1 > 12 or c2 > 10) and (c3 < 12 or c3 > 13); -if $rows != 1 then - return -1 -endi -if $data00 != 12.500000000 then - return -1 -endi - -sql select count(c1),sum(c3) from tb1 where ((c7 = true and c6 > 2) or (c1 > 10 or c3 < 3)) and ((c8 like '1%') or (c9 like '%2' or c9 like '%3')) interval(5s); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data01 != 3 then - return -1 -endi -if $data02 != 14 then - return -1 -endi -if $data10 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data11 != 3 then - return -1 -endi -if $data12 != 39 then - return -1 -endi - -sql select * from stb1 where c8 = 'null'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c8 = 'NULL'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c9 = 'null'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c9 = 'NULL'; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c2 in (0,1); -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -sql select * from stb1 where c6 in (0,2,3,1); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -sql select ts,c1 from (select * from stb1 where (c1 > 60 or c1 < 10) and (c7 = true or c5 > 2 and c5 < 63)) where (c3 > 61 or c3 < 3); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:25.000@ then - return -1 -endi - -#sql select a.* from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50; -sql select a.ts from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:25.000@ then - return -1 -endi - -#sql select a.ts,a.c1,a.c8,a.c9 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 and b.c1 < 60; -sql select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 and b.c1 < 60; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:20.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:21.000@ then - return -1 -endi - -sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.c1 < 10 or a.c1 > 30) and (b.u1 < 5 or b.u1 > 5); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.c1 < 30 and b.u1 > 1 and a.c1 > 10 and b.u1 < 8 and b.u1<>5; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:06.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:10.000@ then - return -1 -endi - -sql select * from stb1 where c1 is null and c1 is not null; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c1 is null or c1 is not null; -if $rows != 29 then - return -1 -endi -sql select * from stb1 where c1 is null or c1 > 20 or c1 < 25; -if $rows != 29 then - return -1 -endi -sql select * from stb1 where (c1 > 20 or c1 < 25) and c1 is null; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where (c1 > 20 or c1 < 25) and (c1 > 62 or c1 < 3); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 11 and c1 != 11 and c1 != 14 and c1 < 14; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:06.000@ then - return -1 -endi -sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) -if $rows != 14 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:04.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 62 or c1 >= 62; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 62 and c1 >= 62; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 >= 62 and c1 != 62; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 >= 62 or c1 != 62; -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where c1 >= 62 and c1 = 62; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 62 and c1 != 62; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 62 and c1 = 62; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c1 is not null and c1 is not null; -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where c1 is not null or c1 is not null; -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where c1 is null and c1 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi - -sql select * from stb1 where c1 is null or c1 is null; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:28.000@ then - return -1 -endi - -sql select * from stb1 where c2 > 3 and c2 < 3; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c2 = 3; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where c2 > 3 and c2 <= 3; -if $rows != 0 then - return -1 -endi - -sql select * from stb1 where c2 >= 3 and c2 <= 3; -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where (c2 in (1,2,3,4) or c2 in (11,12,13,14)) and c2 != 11 and c2 >2 and c2 != 14; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:06.000@ then - return -1 -endi - -sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) and (c1 != 51 and c1 <= 54 and c1 != 54 and c1 >=1 and c1 != 1) and (c1 >= 11 and c1 <=52 and c1 != 52 and c1 != 11); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:07.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 1 and c1 is not null and c1 < 5; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:03.000@ then - return -1 -endi - -sql select * from (select * from stb1 where c2 > 10 and c6 < 40) where c9 in ('11','21','31'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:12.000@ then - return -1 -endi - -sql select * from stb1 where c1 > 40 and c2 > 50 and c3 > 62 or c1 < 2 and c2 < 3; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:27.000@ then - return -1 -endi - -sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30); -if $rows != 28 then - return -1 -endi - -sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30) or (c1 is null and c2 is null); -if $rows != 29 then - return -1 -endi - -sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c3 < 30) or (c1 is null and c2 is null); -if $rows != 29 then - return -1 -endi - -sql select * from stb1 where (c1 > 60 and c2 < 63) or (c1 >62 and c3 < 30) or (c1 is null and c2 is null); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:28.000@ then - return -1 -endi - -print "ts test" -sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; -sql_error select * from stb1 where ts2 like '2021-05-05%'; -sql_error select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; -sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; -sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; -sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); -sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; -sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; -sql_error select * from stb1 where ts is null; -sql_error select * from stb1 where ts is not null and ts is null; -sql select * from stb1 where ts is not null; -if $rows != 29 then - return -1 -endi - -sql select * from stb1 where ts is not null or ts is null; -if $rows != 29 then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; -if $rows != 29 then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:26.000'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:28.000'; -if $rows != 29 then - return -1 -endi -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts > '2021-05-05 18:19:27.000'; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:28.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000' or ts != '2021-05-05 18:19:25.000'; -if $rows != 29 then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts <> '2021-05-05 18:19:25.000'; -if $rows != 29 then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.999') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.999')); -if $rows != 16 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:12.000' and ts <= '2021-05-05 18:19:14.000') or (ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:17.000'); -if $rows != 13 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:01.000' and ts <= '2021-05-05 18:19:08.000'); -if $rows != 10 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi - -sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:06.000') or (ts >= '2021-05-05 18:19:03.000' and ts <= '2021-05-05 18:19:12.000')) and (ts >= '2021-05-05 18:19:10.000'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:12.000@ then - return -1 -endi - -sql select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:25.000' and ts != '2021-05-05 18:19:18'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:28.000@ then - return -1 -endi - - -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:28.000@ then - return -1 -endi - -sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; -if $rows != 25 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:06.000@ then - return -1 -endi - -sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; -if $rows != 25 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; -if $rows != 29 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi - -sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi - -sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:26.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:28.000@ then - return -1 -endi - - -sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:07.000@ then - return -1 -endi - -sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi - -sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.ts < '2021-05-05 18:19:03.000' or a.ts >= '2021-05-05 18:19:13.000') and (b.ts >= '2021-05-05 18:19:01.000' and b.ts <= '2021-05-05 18:19:14.000'); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select a.ts,c.ts,b.c1,c.u1,c.u2 from (select * from stb1) a, (select * from stb1) b, (select * from stb2) c where a.ts=b.ts and b.ts=c.ts and a.ts <= '2021-05-05 18:19:12.000' and b.ts >= '2021-05-05 18:19:06.000' and c.ts >= '2021-05-05 18:19:08.000' and c.ts <= '2021-05-05 18:19:11.000' and a.ts != '2021-05-05 18:19:10.000'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:11.000@ then - return -1 -endi - -sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:06.000' or ts >= '2021-05-05 18:19:13.000') and (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:14.000') and ts != '2021-05-05 18:19:04.000'; -if $rows != 6 then - return -1 -endi -if $data00 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:03.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:06.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data50 != @21-05-05 18:19:14.000@ then - return -1 -endi - -sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; -if $rows != 5 then - return -1 -endi -if $data00 != @21-05-05 18:19:00.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:01.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:02.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:27.000@ then - return -1 -endi -if $data40 != @21-05-05 18:19:28.000@ then - return -1 -endi - -print "tbname test" -sql_error select * from stb1 where tbname like '%3' and tbname like '%4'; - -sql select * from stb1 where tbname like 'tb%'; -if $rows != 29 then - return -1 -endi - -sql select * from stb1 where tbname like '%2'; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:11.000@ then - return -1 -endi - -print "tag test" -sql select * from stb1 where t1 in (1,2) and t1 in (2,3); -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:08.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:09.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:10.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:11.000@ then - return -1 -endi - -sql select * from stb2 where t1 in (1,2) and t2 in (2) and t3 in ('2021-05-05 18:58:57.000'); -if $rows != 0 then - return -1 -endi - -print "join test" -sql_error select * from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts =tb2_1.ts; -sql select tb1.ts from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.ts < '2021-05-05 18:19:06.000'; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:04.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:05.000@ then - return -1 -endi - - -print "column&ts test" -sql_error select count(*) from stb1 where ts > 0 or c1 > 0; -sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:20.000' and (c1 > 23 or c1 < 14) and c7 in (true) and c8 like '%2'; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:05.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:17.000@ then - return -1 -endi - -print "column&tbname test" -sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; -sql select * from stb1 where tbname like '%3' and c6 < 34 and c5 != 33 and c4 > 31; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:13.000@ then - return -1 -endi - -print "column&tag test" -sql_error select * from stb1 where t1 > 0 or c1 > 0 -sql_error select * from stb1 where c1 > 0 or t1 > 0 -sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 -sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 -sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) -sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 -sql_error select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.t1=b.t1; - -sql select * from stb1 where c1 < 63 and t1 > 5 -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:24.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:25.000@ then - return -1 -endi -sql select * from stb1 where t1 > 3 and t1 < 5 and c1 != 42 and c1 != 44; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:16.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:18.000@ then - return -1 -endi -sql select * from stb1 where t1 > 1 and c1 > 21 and t1 < 3 and c1 < 24 and t1 != 3 and c1 != 23; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:09.000@ then - return -1 -endi -sql select * from stb1 where c1 > 1 and (t1 > 3 or t1 < 2) and (c2 > 2 and c2 < 62 and t1 != 4) and (t1 > 2 and t1 < 6) and c7 = true and c8 like '%2'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:21.000@ then - return -1 -endi - -sql select * from stb1 where c1!=31 and c1 !=32 and c1 <> 63 and c1 <>1 and c1 <> 21 and c1 <> 2 and c7 <> true and c8 <> '3' and c9 <> '4' and c2<>13 and c3 <> 23 and c4 <> 33 and c5 <> 34 and c6 <> 43 and c2 <> 53 and t1 <> 5 and t2 <>4; -if $rows != 3 then - return -1 -endi -if $data00 != @21-05-05 18:19:07.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:27.000@ then - return -1 -endi - - -print "column&join test" -sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; - - -print "ts&tbname test" -sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; - -print "ts&tag test" -sql_error select count(*) from stb1 where ts > 0 or t1 > 0; - -sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; -if $rows != 2 then - return -1 -endi -if $data00 != @21-05-05 18:19:11.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:12.000@ then - return -1 -endi - -print "ts&join test" -sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts > 0; -sql select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts and (tb1.ts > '2021-05-05 18:19:05.000' or tb1.ts < '2021-05-05 18:19:03.000' or tb1.ts > 0); - - -print "tbname&tag test" -sql select * from stb1 where tbname like 'tb%' and (t1=1 or t2=2 or t3=3) and t1 > 2; -if $rows != 4 then - return -1 -endi -if $data00 != @21-05-05 18:19:12.000@ then - return -1 -endi -if $data10 != @21-05-05 18:19:13.000@ then - return -1 -endi -if $data20 != @21-05-05 18:19:14.000@ then - return -1 -endi -if $data30 != @21-05-05 18:19:15.000@ then - return -1 -endi - -print "tbname&join test" - -print "tag&join test" - - - - - -print "column&ts&tbname test" -sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0 or ts > 0; - -print "column&ts&tag test" -sql_error select count(*) from stb1 where t1 > 0 or c1 > 0 or ts > 0; -sql_error select count(*) from stb1 where c1 > 0 or t1 > 0 or ts > 0; - -sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:26.000@ then - return -1 -endi -sql select * from stb1 where ts > '2021-05-05 18:19:00.000' and c1 > 2 and t1 != 1 and c2 >= 23 and t2 >= 3 and c3 < 63 and c7 = false and t3 > 3 and t3 < 6 and c8 like '4%' and ts < '2021-05-05 18:19:19.000' and c2 > 40 and c3 != 42; -if $rows != 1 then - return -1 -endi -if $data00 != @21-05-05 18:19:18.000@ then - return -1 -endi -print "column&ts&join test" - -print "column&tbname&tag test" -sql_error select count(*) from stb1 where c1 > 0 or tbname in ('tb1') or t1 > 0; - -print "column&tbname&join test" -print "column&tag&join test" -print "ts&tbname&tag test" -sql_error select count(*) from stb1 where ts > 0 or tbname in ('tb1') or t1 > 0; - -print "ts&tbname&join test" -print "ts&tag&join test" -print "tbname&tag&join test" - - - - -print "column&ts&tbname&tag test" -sql_error select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; -sql_error select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; -sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col > 0 and t1 > 0; - - -print "column&ts&tbname&join test" -print "column&ts&tag&join test" -print "column&tbname&tag&join test" -print "ts&tbname&tag&join test" - - -print "column&ts&tbname&tag&join test" - -#system sh/exec.sh -n dnode1 -s stop -x SIGINT From 82a7d7b9e365a563c61c7f21bbc2426cf8d57363 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 26 Jul 2021 09:55:50 +0800 Subject: [PATCH 027/100] add test case --- .../script/general/parser/condition_query.sim | 2477 +++++++++++++++++ 1 file changed, 2477 insertions(+) create mode 100644 tests/script/general/parser/condition_query.sim diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim new file mode 100644 index 0000000000..45c20a0ce1 --- /dev/null +++ b/tests/script/general/parser/condition_query.sim @@ -0,0 +1,2477 @@ + +sql use cdb; + +print "column test" +sql select * from stb1 +if $rows != 29 then + return -1 +endi +sql select * from stb1 where c1 > 0 +if $rows != 28 then + return -1 +endi + +sql_error select * from stb1 where c8 > 0 +sql_error select * from stb1 where c7 in (0,2,3,1); +sql_error select * from stb1 where c8 in (true); +sql_error select * from stb1 where c8 in (1,2); +sql_error select * from stb1 where t2 in (3.0); +sql_error select ts,c1,c7 from stb1 where c7 > false +sql_error select * from stb1 where c1 > NULL; +sql_error select * from stb1 where c1 = NULL; +sql_error select * from stb1 where c1 LIKE '%1'; +sql_error select * from stb1 where c2 LIKE '%1'; +sql_error select * from stb1 where c3 LIKE '%1'; +sql_error select * from stb1 where c4 LIKE '%1'; +sql_error select * from stb1 where c5 LIKE '%1'; +sql_error select * from stb1 where c6 LIKE '%1'; +sql_error select * from stb1 where c7 LIKE '%1'; +sql_error select * from stb1 where c1 = 'NULL'; +sql_error select * from stb1 where c2 > 'NULL'; +sql_error select * from stb1 where c3 <> 'NULL'; +sql_error select * from stb1 where c4 != 'null'; +sql_error select * from stb1 where c5 >= 'null'; +sql_error select * from stb1 where c6 <= 'null'; +sql_error select * from stb1 where c7 < 'nuLl'; +sql_error select * from stb1 where c8 < 'nuLl'; +sql_error select * from stb1 where c9 > 'nuLl'; +sql_error select * from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b; +sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; +sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); + +sql select * from stb1 where c2 > 3.0 or c2 < 60; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c2 > 3.0 or c2 < 60 and c2 > 50; +if $rows != 25 then + return -1 +endi +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50; +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 and c2 != 63); +if $rows != 6 then + return -1 +endi + +sql select * from stb1 where (c2 > 3.0 or c2 < 60) and c2 > 50 and (c2 != 53 or c2 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c3 > 3.0 or c3 < 60) and c3 > 50 and (c3 != 53 or c3 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c4 > 3.0 or c4 < 60) and c4 > 50 and (c4 != 53 or c4 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c5 > 3.0 or c5 < 60) and c5 > 50 and (c5 != 53 or c5 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where (c6 > 3.0 or c6 < 60) and c6 > 50 and (c6 != 53 or c6 != 63); +if $rows != 8 then + return -1 +endi + +sql select * from stb1 where c8 = '51'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi + +sql select * from stb1 where c8 != '51'; +if $rows != 27 then + return -1 +endi + +#xxx +sql select * from stb1 where c8 = '51' and c8 != '51'; +if $rows != 0 then + return -1 +endi + +#xxx +sql select * from stb1 where c8 = '51' or c8 != '51'; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c9 = '51'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi + +sql select * from stb1 where c9 != '51'; +if $rows != 27 then + return -1 +endi + +sql select * from stb1 where c9 = '51' and c9 != '51'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = '51' or c9 != '51'; +if $rows != 28 then + return -1 +endi + +sql select ts,c1,c7 from stb1 where c7 = false +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data02 != 0 then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data11 != 4 then + return -1 +endi +if $data12 != 0 then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data21 != 13 then + return -1 +endi +if $data22 != 0 then + return -1 +endi +if $data30 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data32 != 0 then + return -1 +endi + + +sql select ts,c1,c7 from stb1 where c7 = true +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +if $data02 != 1 then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data11 != 2 then + return -1 +endi +if $data12 != 1 then + return -1 +endi +if $data20 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data21 != 11 then + return -1 +endi +if $data22 != 1 then + return -1 +endi +if $data30 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data31 != 12 then + return -1 +endi +if $data32 != 1 then + return -1 +endi + + +sql select * from stb1 where c8 = '51' or c8 = '4' +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data01 != 4 then + return -1 +endi +if $data10 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data11 != 51 then + return -1 +endi + + +sql select * from stb1 where c1 > 50 and c1 > 53 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 52 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 and c1 > 54 +if $rows != 4 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 > 51 or c1 > 54 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 and c1 < 51 or c1 > 54 +if $rows != 4 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 and c1 > 54 +if $rows != 5 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 > 51 and c1 < 54 +if $rows != 7 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 and c1 > 53 or c1 < 51 or c1 > 54 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 and c1 < 51 or c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 > 51 and c1 > 54 +if $rows != 8 then + return -1 +endi +sql select * from stb1 where c1 > 50 or c1 > 53 or c1 < 51 or c1 > 54 +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where (c1 > 50 and c1 > 53) and c1 < 52 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 52) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or c1 < 51 +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) +if $rows != 28 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or c1 < 51 +if $rows != 25 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) +if $rows != 5 then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and c1 < 51 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) +if $rows != 8 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) and (c1 < 51 and c1 > 54) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 and c1 < 51 or c1 > 54) +if $rows != 4 then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 and c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 and c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 and c1 > 54) +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) and c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53) or (c1 < 51 or c1 > 54) +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51 or c1 > 54) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 and c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 and (c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) and (c1 < 51 or c1 > 54) +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51 or c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 and c1 < 51) or c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 and c1 < 51) or c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 and c1 > 54) +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 8 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c1 > 62 or (c1 > 53 or c1 < 51) and c1 > 54 +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53) or (c1 < 51 or c1 > 54) +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51 or c1 > 54) +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 50 or c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select * from stb1 where c1 > 50 or (c1 > 53 or c1 < 51) or c1 > 54 +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +sql select ts,c1 from stb1 where (c1 > 60 or c1 < 10 or (c1 > 20 and c1 < 30)) and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:25.000' and c1 != 21 and c1 != 22 +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data31 != 23 then + return -1 +endi +if $data40 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data41 != 24 then + return -1 +endi +if $data50 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data51 != 61 then + return -1 +endi + + +sql select * from stb1 where (c1 > 40 or c1 < 20) and (c2 < 53 or c2 >= 63) and c3 > 1 and c3 < 5 +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi + +sql select * from stb1 where (c1 > 52 or c1 < 10) and (c2 > 1 and c2 < 61) +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data31 != 53 then + return -1 +endi +if $data40 != @21-05-05 18:19:23.000@ then + return -1 +endi +if $data41 != 54 then + return -1 +endi + +sql select * from stb1 where (c3 > 52 or c3 < 10) and (c4 > 1 and c4 < 61) and (c5 = 2 or c6 = 3.0 or c6 = 4.0 or c6 = 53); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data01 != 2 then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data21 != 4 then + return -1 +endi +if $data30 != @21-05-05 18:19:22.000@ then + return -1 +endi +if $data31 != 53 then + return -1 +endi + +sql select * from stb1 where c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c2 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c3 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c4 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c5 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c6 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c7 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c8 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +#xxx +sql select * from stb1 where c8 like '1'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi + +#xxx +sql select * from stb1 where c8 like '1%' and c8 like '%1'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi + +#xxx +sql select * from stb1 where c8 like '1' and c8 like '2'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi + +sql select * from stb1 where c1 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c2 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c3 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c4 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c5 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c6 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c7 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c8 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c9 is not null; +if $rows != 28 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from stb1 where c1 > 63 or c1 is null; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data01 != 64 then + return -1 +endi +if $data10 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null and c3 is not null; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 is null and c2 is null and ts > '2021-05-05 18:19:00.000' and ts < '2021-05-05 18:19:28.000'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null and c1 > 0; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is not null or c1 > 1; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 is null or c1 > 40) and c1 < 44; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:18.000@ then + return -1 +endi + +sql select * from stb1 where c1 in (11,21,31,41) and c1 in (11,42); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c8 in ('11','21','31','41') and c8 in ('11','42'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 60 and c2 > 40) or (c1 > 62 and c2 > 50); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 = 3 or c1 = 5 or c1 >= 44 and c1 <= 52; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:19.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:21.000@ then + return -1 +endi + +sql select * from stb1 where c8 LIKE '%1'; +if $rows != 7 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where c9 LIKE '%1'; +if $rows != 7 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:24.000@ then + return -1 +endi +sql select * from stb1 where (c8 LIKE '%1' or c9 like '_2') and (c5 > 50 or c6 > 30) and ( c8 like '3_' or c9 like '4_') and (c4 <= 31 or c4 >= 42); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:17.000@ then + return -1 +endi + +sql select * from stb1 where c1 in (1,3); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where c3 in (11,22); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi + +sql select * from stb1 where c4 in (3,33); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) and c8 in ('22','55'); +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) and c8 in ('33','54'); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select * from stb1 where c5 in (3,33) or c8 in ('22','54'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:23.000@ then + return -1 +endi + +sql select * from stb1 where (c9 in ('3','1','2','4','5') or c9 in ('33','11','22','44','55')) and c9 in ('1','3','11','13'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb2 where (u1 in (1) or u2 in (5,6)) and (u3 in (3,6) or u4 in (7,8)) and ts2 in ('2021-05-05 18:28:02.000','2021-05-05 18:28:15.000','2021-05-05 18:28:01.000'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi + +sql select * from stb2 where u2 in (2) and u3 in (1,2,3) and u4 in (1,2,4,5) and u1 > 3 and u1 < 6 and u1 != 4; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi + +sql select avg(c1) from tb1 where (c1 > 12 or c2 > 10) and (c3 < 12 or c3 > 13); +if $rows != 1 then + return -1 +endi +if $data00 != 12.500000000 then + return -1 +endi + +sql select count(c1),sum(c3) from tb1 where ((c7 = true and c6 > 2) or (c1 > 10 or c3 < 3)) and ((c8 like '1%') or (c9 like '%2' or c9 like '%3')) interval(5s); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data01 != 3 then + return -1 +endi +if $data02 != 14 then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data11 != 3 then + return -1 +endi +if $data12 != 39 then + return -1 +endi + +sql select * from stb1 where c8 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c8 = 'NULL'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'null'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c9 = 'NULL'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c2 in (0,1); +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +sql select * from stb1 where c6 in (0,2,3,1); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +sql select ts,c1 from (select * from stb1 where (c1 > 60 or c1 < 10) and (c7 = true or c5 > 2 and c5 < 63)) where (c3 > 61 or c3 < 3); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:25.000@ then + return -1 +endi + +#sql select a.* from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50; +sql select a.ts from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:25.000@ then + return -1 +endi + +#sql select a.ts,a.c1,a.c8,a.c9 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 and b.c1 < 60; +sql select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 and b.c1 < 60; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:20.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:21.000@ then + return -1 +endi + +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.c1 < 10 or a.c1 > 30) and (b.u1 < 5 or b.u1 > 5); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.c1 < 30 and b.u1 > 1 and a.c1 > 10 and b.u1 < 8 and b.u1<>5; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi + +sql select * from stb1 where c1 is null and c1 is not null; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is not null; +if $rows != 29 then + return -1 +endi +sql select * from stb1 where c1 is null or c1 > 20 or c1 < 25; +if $rows != 29 then + return -1 +endi +sql select * from stb1 where (c1 > 20 or c1 < 25) and c1 is null; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where (c1 > 20 or c1 < 25) and (c1 > 62 or c1 < 3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 11 and c1 != 11 and c1 != 14 and c1 < 14; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) +if $rows != 14 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:04.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 or c1 >= 62; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 >= 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 >= 62 and c1 != 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 >= 62 or c1 != 62; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 >= 62 and c1 = 62; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 != 62; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 62 and c1 = 62; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c1 is not null and c1 is not null; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 is not null or c1 is not null; +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where c1 is null and c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where c1 is null or c1 is null; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where c2 > 3 and c2 < 3; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c2 = 3; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where c2 > 3 and c2 <= 3; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where c2 >= 3 and c2 <= 3; +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (c2 in (1,2,3,4) or c2 in (11,12,13,14)) and c2 != 11 and c2 >2 and c2 != 14; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 60 or c1 < 4 or c1 > 10 and c1 < 20 and c1 != 13 or c1 < 2 or c1 > 50) and (c1 != 51 and c1 <= 54 and c1 != 54 and c1 >=1 and c1 != 1) and (c1 >= 11 and c1 <=52 and c1 != 52 and c1 != 11); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 1 and c1 is not null and c1 < 5; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:03.000@ then + return -1 +endi + +sql select * from (select * from stb1 where c2 > 10 and c6 < 40) where c9 in ('11','21','31'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + +sql select * from stb1 where c1 > 40 and c2 > 50 and c3 > 62 or c1 < 2 and c2 < 3; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30); +if $rows != 28 then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c2 < 30) or (c1 is null and c2 is null); +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 > 3 and c2 > 4) or (c1 < 60 and c3 < 30) or (c1 is null and c2 is null); +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where (c1 > 60 and c2 < 63) or (c1 >62 and c3 < 30) or (c1 is null and c2 is null); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb3 where c1 > 3 and c1 < 2; +if $rows != 0 then + return -1 +endi + +sql select * from stb3 where c1 is null order by ts; +if $rows != 4 then + return -1 +endi +if $data00 != @21-06-05 18:19:28.000@ then + return -1 +endi +if $data10 != @21-06-06 18:19:28.000@ then + return -1 +endi +if $data20 != @21-07-05 18:19:28.000@ then + return -1 +endi +if $data30 != @21-07-06 18:19:28.000@ then + return -1 +endi + +sql select * from stb3 where c1 is not null order by ts; +if $rows != 10 then + return -1 +endi +if $data00 != @21-01-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-01-06 18:19:00.000@ then + return -1 +endi +if $data20 != @21-02-05 18:19:01.000@ then + return -1 +endi +if $data30 != @21-02-06 18:19:01.000@ then + return -1 +endi +if $data40 != @21-03-05 18:19:02.000@ then + return -1 +endi +if $data50 != @21-03-06 18:19:02.000@ then + return -1 +endi +if $data60 != @21-04-05 18:19:03.000@ then + return -1 +endi +if $data70 != @21-04-06 18:19:03.000@ then + return -1 +endi + + +sql select * from stb3 where c1 > 11; +if $rows != 4 then + return -1 +endi +if $data00 != @21-02-06 18:19:01.000@ then + return -1 +endi +if $data10 != @21-03-06 18:19:02.000@ then + return -1 +endi +if $data20 != @21-04-06 18:19:03.000@ then + return -1 +endi +if $data30 != @21-05-06 18:19:28.000@ then + return -1 +endi + +sql select * from stb3 where c1 is not null or c1 is null; +if $rows != 14 then + return -1 +endi + + +print "ts test" +sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; +sql_error select * from stb1 where ts2 like '2021-05-05%'; +sql_error select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; +sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; +sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); +sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; +sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; +sql_error select * from stb1 where ts is null; +sql_error select * from stb1 where ts is not null and ts is null; +sql select * from stb1 where ts is not null; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where ts is not null or ts is null; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:28.000'; +if $rows != 29 then + return -1 +endi +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts > '2021-05-05 18:19:27.000'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000' or ts != '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts <> '2021-05-05 18:19:25.000'; +if $rows != 29 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.999') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.999')); +if $rows != 16 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:12.000' and ts <= '2021-05-05 18:19:14.000') or (ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:17.000'); +if $rows != 13 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:01.000' and ts <= '2021-05-05 18:19:08.000'); +if $rows != 10 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:08.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:03.000') or (ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:06.000') or (ts >= '2021-05-05 18:19:03.000' and ts <= '2021-05-05 18:19:12.000')) and (ts >= '2021-05-05 18:19:10.000'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:12.000@ then + return -1 +endi + +sql select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:25.000' and ts != '2021-05-05 18:19:18'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:28.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:25'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:25'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi + +sql select * from stb1 where ts < '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:25'; +if $rows != 25 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25'; +if $rows != 29 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' and ts < '2021-05-05 18:19:26'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi + +sql select * from stb1 where (ts > '2021-05-05 18:19:23.000' or ts < '2021-05-05 18:19:25') and (ts > '2021-05-05 18:19:23.000' or ts > '2021-05-05 18:19:26'); +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + + +sql select * from stb2 where ts2 in ('2021-05-05 18:28:03','2021-05-05 18:28:05','2021-05-05 18:28:08'); +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select * from stb2 where t3 in ('2021-05-05 18:38:38','2021-05-05 18:38:28','2021-05-05 18:38:08') and ts2 in ('2021-05-05 18:28:04','2021-05-05 18:28:04','2021-05-05 18:28:03'); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi + +sql select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and (a.ts < '2021-05-05 18:19:03.000' or a.ts >= '2021-05-05 18:19:13.000') and (b.ts >= '2021-05-05 18:19:01.000' and b.ts <= '2021-05-05 18:19:14.000'); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select a.ts,c.ts,b.c1,c.u1,c.u2 from (select * from stb1) a, (select * from stb1) b, (select * from stb2) c where a.ts=b.ts and b.ts=c.ts and a.ts <= '2021-05-05 18:19:12.000' and b.ts >= '2021-05-05 18:19:06.000' and c.ts >= '2021-05-05 18:19:08.000' and c.ts <= '2021-05-05 18:19:11.000' and a.ts != '2021-05-05 18:19:10.000'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:06.000' or ts >= '2021-05-05 18:19:13.000') and (ts >= '2021-05-05 18:19:02.000' and ts <= '2021-05-05 18:19:14.000') and ts != '2021-05-05 18:19:04.000'; +if $rows != 6 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:14.000@ then + return -1 +endi + +sql select ts,c1,c2,c8 from (select * from stb1) where (ts <= '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:26.000' or ts = '2021-05-05 18:19:26.000') and ts != '2021-05-05 18:19:03.000' and ts != '2021-05-05 18:19:26.000'; +if $rows != 5 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:28.000@ then + return -1 +endi + +print "tbname test" +sql_error select * from stb1 where tbname like '%3' and tbname like '%4'; + +sql select * from stb1 where tbname like 'tb%'; +if $rows != 29 then + return -1 +endi + +sql select * from stb1 where tbname like '%2'; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi + +print "tag test" +sql select * from stb1 where t1 in (1,2) and t1 in (2,3); +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:08.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:09.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:10.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select * from stb2 where t1 in (1,2) and t2 in (2) and t3 in ('2021-05-05 18:58:57.000'); +if $rows != 0 then + return -1 +endi + +print "join test" +sql_error select * from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts =tb2_1.ts; +sql select tb1.ts from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.ts < '2021-05-05 18:19:06.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:05.000@ then + return -1 +endi + + +print "column&ts test" +sql_error select count(*) from stb1 where ts > 0 or c1 > 0; +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:20.000' and (c1 > 23 or c1 < 14) and c7 in (true) and c8 like '%2'; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:17.000@ then + return -1 +endi + +print "column&tbname test" +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0; +sql select * from stb1 where tbname like '%3' and c6 < 34 and c5 != 33 and c4 > 31; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:13.000@ then + return -1 +endi + +print "column&tag test" +sql_error select * from stb1 where t1 > 0 or c1 > 0 +sql_error select * from stb1 where c1 > 0 or t1 > 0 +sql_error select * from stb1 where t1 > 0 or c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 or c1 > 1 +sql_error select * from stb1 where t1 > 0 and c1 > 0 or t1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where c1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where t1 > 0 or t1 > 0 and c1 > 1 +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or (t1 > 1 and c1 > 3) +sql_error select * from stb1 where (c1 > 0 and t1 > 0 ) or t1 > 1 +sql_error select a.ts,b.ts,a.c1,b.u1,b.u2 from (select * from stb1) a, (select * from stb2) b where a.ts=b.ts and a.t1=b.t1; + +sql select * from stb1 where c1 < 63 and t1 > 5 +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +sql select * from stb1 where t1 > 3 and t1 < 5 and c1 != 42 and c1 != 44; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:16.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:18.000@ then + return -1 +endi +sql select * from stb1 where t1 > 1 and c1 > 21 and t1 < 3 and c1 < 24 and t1 != 3 and c1 != 23; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:09.000@ then + return -1 +endi +sql select * from stb1 where c1 > 1 and (t1 > 3 or t1 < 2) and (c2 > 2 and c2 < 62 and t1 != 4) and (t1 > 2 and t1 < 6) and c7 = true and c8 like '%2'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:21.000@ then + return -1 +endi + +sql select * from stb1 where c1!=31 and c1 !=32 and c1 <> 63 and c1 <>1 and c1 <> 21 and c1 <> 2 and c7 <> true and c8 <> '3' and c9 <> '4' and c2<>13 and c3 <> 23 and c4 <> 33 and c5 <> 34 and c6 <> 43 and c2 <> 53 and t1 <> 5 and t2 <>4; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:27.000@ then + return -1 +endi + + +print "column&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.c1 > 0; + + +print "ts&tbname test" +sql_error select count(*) from stb1 where ts > 0 or tbname like 'tb%'; + +print "ts&tag test" +sql_error select count(*) from stb1 where ts > 0 or t1 > 0; + +sql select * from stb2 where t1!=1 and t2=2 and t3 in ('2021-05-05 18:58:58.000') and ts < '2021-05-05 18:19:13.000'; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:11.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:12.000@ then + return -1 +endi + +print "ts&join test" +sql_error select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts or tb1.ts > 0; +sql select tb1.ts,tb1.c1,tb2_1.u1 from tb1, tb2_1 where tb1.ts=tb2_1.ts and (tb1.ts > '2021-05-05 18:19:05.000' or tb1.ts < '2021-05-05 18:19:03.000' or tb1.ts > 0); + + +print "tbname&tag test" +sql select * from stb1 where tbname like 'tb%' and (t1=1 or t2=2 or t3=3) and t1 > 2; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:12.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:13.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:14.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:15.000@ then + return -1 +endi + +print "tbname&join test" + +print "tag&join test" + + + + + +print "column&ts&tbname test" +sql_error select count(*) from stb1 where tbname like 'tb%' or c1 > 0 or ts > 0; + +print "column&ts&tag test" +sql_error select count(*) from stb1 where t1 > 0 or c1 > 0 or ts > 0; +sql_error select count(*) from stb1 where c1 > 0 or t1 > 0 or ts > 0; + +sql select * from stb1 where (t1 > 0 or t1 > 2 ) and ts > '2021-05-05 18:19:10.000' and (c1 > 1 or c1 > 3) and (c6 > 40 or c6 < 30) and (c8 like '%3' or c8 like '_4') and (c9 like '1%' or c9 like '6%' or (c9 like '%3' and c9 != '23')) and ts > '2021-05-05 18:19:22.000' and ts <= '2021-05-05 18:19:26.000'; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:26.000@ then + return -1 +endi +sql select * from stb1 where ts > '2021-05-05 18:19:00.000' and c1 > 2 and t1 != 1 and c2 >= 23 and t2 >= 3 and c3 < 63 and c7 = false and t3 > 3 and t3 < 6 and c8 like '4%' and ts < '2021-05-05 18:19:19.000' and c2 > 40 and c3 != 42; +if $rows != 1 then + return -1 +endi +if $data00 != @21-05-05 18:19:18.000@ then + return -1 +endi +print "column&ts&join test" + +print "column&tbname&tag test" +sql_error select count(*) from stb1 where c1 > 0 or tbname in ('tb1') or t1 > 0; + +print "column&tbname&join test" +print "column&tag&join test" +print "ts&tbname&tag test" +sql_error select count(*) from stb1 where ts > 0 or tbname in ('tb1') or t1 > 0; + +print "ts&tbname&join test" +print "ts&tag&join test" +print "tbname&tag&join test" + + + + +print "column&ts&tbname&tag test" +sql_error select * from stb1 where (tbname like 'tb%' or ts > '2021-05-05 18:19:01.000') and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select * from stb1 where (ts > '2021-05-05 18:19:01.000') and (ts > '2021-05-05 18:19:02.000' or t1 > 3) and (t1 > 5 or t1 < 4) and c1 > 0; +sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts > '2021-05-05 18:19:20.000' and col > 0 and t1 > 0; + + +print "column&ts&tbname&join test" +print "column&ts&tag&join test" +print "column&tbname&tag&join test" +print "ts&tbname&tag&join test" + + +print "column&ts&tbname&tag&join test" + +#system sh/exec.sh -n dnode1 -s stop -x SIGINT From 56177e18493dd4fea0a55b665489ffaa3930a2aa Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 27 Jul 2021 10:55:44 +0800 Subject: [PATCH 028/100] fix mem leak --- src/client/src/tscSQLParser.c | 45 ++++---- src/common/src/texpr.c | 30 +++--- src/query/inc/qFilter.h | 5 +- src/query/src/qExecutor.c | 9 +- src/query/src/qFilter.c | 188 +++++++++++++++++++++++++++------- src/query/src/qSqlParser.c | 4 +- src/query/src/queryMain.c | 3 + src/util/src/hash.c | 3 +- 8 files changed, 203 insertions(+), 84 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 919dc392ed..da7f4d5750 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3424,8 +3424,8 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, retVal = tVariantDump(&pRight->value, (char*)pColumnFilter->pz, colType, false); } else if (colType == TSDB_DATA_TYPE_NCHAR) { - // pRight->value.nLen + 1 is larger than the actual nchar string length - pColumnFilter->pz = (int64_t)calloc(1, bufLen * TSDB_NCHAR_SIZE); + // bufLen + 1 is larger than the actual nchar string length + pColumnFilter->pz = (int64_t)calloc(1, (bufLen + 1) * TSDB_NCHAR_SIZE); retVal = tVariantDump(&pRight->value, (char*)pColumnFilter->pz, colType, false); size_t len = twcslen((wchar_t*)pColumnFilter->pz); pColumnFilter->len = len * TSDB_NCHAR_SIZE; @@ -3652,14 +3652,10 @@ static int32_t getColQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlEx } tExprNode* p = NULL; - //SFilterInfo colFilter = {0}; - - SArray* colList = taosArrayInit(10, sizeof(SColIndex)); - ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL); - //if (ret == TSDB_CODE_SUCCESS) { - // ret = filterInitFromTree(p, &colFilter, (int32_t)taosArrayGetSize(colList)); - //} + SArray* colList = taosArrayInit(10, sizeof(SColIndex)); + ret = exprTreeFromSqlExpr(pCmd, &p, p1, pQueryInfo, colList, NULL); + taosArrayDestroy(colList); SBufferWriter bw = tbufInitWriter(NULL, false); @@ -5045,8 +5041,10 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr tExprNode* p = NULL; SFilterInfo *filter = NULL; - SArray* colList = taosArrayInit(10, sizeof(SColIndex)); + SArray* colList = taosArrayInit(10, sizeof(SColIndex)); ret = exprTreeFromSqlExpr(pCmd, &p, *pExpr, pQueryInfo, colList, NULL); + taosArrayDestroy(colList); + if (ret != TSDB_CODE_SUCCESS) { goto _ret; } @@ -5058,6 +5056,8 @@ static int32_t getQueryTimeRange(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr ret = filterGetTimeRange(filter, &pQueryInfo->window); + filterFreeInfo(filter); + _ret: tExprTreeDestroy(p, NULL); @@ -5100,7 +5100,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq #endif if ((ret = getQueryCondExpr(&pSql->cmd, pQueryInfo, pExpr, &condExpr, etype, &tbIdx, (*pExpr)->tokenId, &condExpr.pColumnCond, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } if (taosArrayGetSize(pQueryInfo->pUpstream) > 0 && condExpr.pTimewindow != NULL) { @@ -5115,21 +5115,21 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 2. get the query time range if ((ret = convertTimeRangeFromExpr(&pSql->cmd, pQueryInfo, condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } if ((ret = getQueryTimeRange(&pSql->cmd, pQueryInfo, &condExpr.pTimewindow)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 3. get the tag query condition if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { - return ret; + goto PARSE_WHERE_EXIT; } // 4. get the table name query condition @@ -8613,12 +8613,15 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS } else if (pSqlExpr->tokenId == TK_SET) { int32_t colType = -1; STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, pQueryInfo->curTableIdx)->pTableMeta; - size_t colSize = taosArrayGetSize(pCols); - if (pCols != NULL && colSize > 0) { - SColIndex* idx = taosArrayGet(pCols, colSize - 1); - SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); - if (pSchema != NULL) { - colType = pSchema->type; + if (pCols != NULL) { + size_t colSize = taosArrayGetSize(pCols); + + if (colSize > 0) { + SColIndex* idx = taosArrayGet(pCols, colSize - 1); + SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, idx->colIndex); + if (pSchema != NULL) { + colType = pSchema->type; + } } } tVariant *pVal; diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 4ba2b35f3e..8414314301 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -513,7 +513,8 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tVariant tmpVar = {0}; size_t t = 0; int32_t sz = tbufReadInt32(&br); - void *pvar = NULL; + void *pvar = NULL; + int64_t val = 0; int32_t bufLen = 0; if (IS_NUMERIC_TYPE(sType)) { bufLen = 60; // The maximum length of string that a number is converted to. @@ -528,21 +529,21 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { - uint8_t val = (uint8_t)tbufReadInt64(&br); + *(uint8_t *)&val = (uint8_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { - uint16_t val = (uint16_t)tbufReadInt64(&br); + *(uint16_t *)&val = (uint16_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { - uint32_t val = (uint32_t)tbufReadInt64(&br); + *(uint32_t *)&val = (uint32_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; @@ -550,31 +551,29 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { - uint64_t val = (uint64_t)tbufReadInt64(&br); + *(uint64_t *)&val = (uint64_t)tbufReadInt64(&br); t = sizeof(val); pvar = &val; break; } case TSDB_DATA_TYPE_DOUBLE: { - double val = tbufReadDouble(&br); + *(double *)&val = tbufReadDouble(&br); t = sizeof(val); pvar = &val; break; } case TSDB_DATA_TYPE_FLOAT: { - float val = (float)tbufReadDouble(&br); + *(float *)&val = (float)tbufReadDouble(&br); t = sizeof(val); pvar = &val; break; } case TSDB_DATA_TYPE_BINARY: { - char *val = (char *)tbufReadBinary(&br, &t); - pvar = val; + pvar = (char *)tbufReadBinary(&br, &t); break; } case TSDB_DATA_TYPE_NCHAR: { - char *val = (char *)tbufReadBinary(&br, &t); - pvar = val; + pvar = (char *)tbufReadBinary(&br, &t); break; } default: @@ -594,7 +593,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_TINYINT: { - int8_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -604,7 +602,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t } case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_SMALLINT: { - int16_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -614,7 +611,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t } case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_INT: { - int32_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -625,7 +621,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { - int64_t val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -634,7 +629,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t break; } case TSDB_DATA_TYPE_DOUBLE: { - double val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -643,7 +637,6 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t break; } case TSDB_DATA_TYPE_FLOAT: { - float val = 0; if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { goto err_ret; } @@ -672,12 +665,15 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t } taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy)); + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); } *q = (void *)pObj; pObj = NULL; err_ret: + tVariantDestroy(&tmpVar); taosHashCleanup(pObj); tfree(tmp); } diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 4ed30853e8..d7edefd9cd 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -36,6 +36,7 @@ enum { FLD_TYPE_MAX = 3, FLD_DESC_NO_FREE = 4, FLD_DATA_NO_FREE = 8, + FLD_DATA_IS_HASH = 16, }; enum { @@ -64,6 +65,7 @@ enum { FI_STATUS_ALL = 1, FI_STATUS_EMPTY = 2, FI_STATUS_REWRITE = 4, + FI_STATUS_CLONED = 8, }; enum { @@ -187,7 +189,6 @@ typedef struct SFilterUnit { } SFilterUnit; typedef struct SFilterPCtx { - SHashObj *colHash; SHashObj *valHash; SHashObj *unitHash; } SFilterPCtx; @@ -232,7 +233,7 @@ typedef struct SFilterInfo { #define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) #define FREE_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = (r)->next; } else { (ctx)->rs = (r)->next;} if ((r)->next) { (r)->next->prev = (r)->prev; } RESET_RANGE(ctx, r); } while (0) -#define FREE_FROM_RANGE(ctx, r) do { if ((r)->prev) { (r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (r) {SFilterRangeNode *n = (r)->next; RESET_RANGE(ctx, r); r = n; } } while (0) +#define FREE_FROM_RANGE(ctx, r) do { SFilterRangeNode *_r = r; if ((_r)->prev) { (_r)->prev->next = NULL; } else { (ctx)->rs = NULL;} while (_r) {SFilterRangeNode *n = (_r)->next; RESET_RANGE(ctx, _r); _r = n; } } while (0) #define INSERT_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r)->prev; if ((r)->prev) { (r)->prev->next = n; } else { (ctx)->rs = n; } (r)->prev = n; n->next = r; } while (0) #define APPEND_RANGE(ctx, r, ra) do { SFilterRangeNode *n = filterNewRange(ctx, ra); n->prev = (r); if (r) { (r)->next = n; } else { (ctx)->rs = n; } } while (0) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 34896babe9..3e8f683008 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2847,7 +2847,10 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa return terrno; } - doSetFilterColInfo(pQueryAttr->pFilters, pBlock); + if (pQueryAttr->pFilters != NULL) { + doSetFilterColInfo(pQueryAttr->pFilters, pBlock); + } + if (pQueryAttr->pFilters != NULL || pRuntimeEnv->pTsBuf != NULL) { filterColRowsInDataBlock(pRuntimeEnv, pBlock, ascQuery); } @@ -7575,6 +7578,8 @@ _cleanup_qinfo: tfree(pExprs); + filterFreeInfo(pFilters); + _cleanup: freeQInfo(pQInfo); return NULL; @@ -7930,6 +7935,8 @@ void freeQueryAttr(SQueryAttr* pQueryAttr) { taosArrayDestroy(pQueryAttr->pGroupbyExpr->columnInfo); tfree(pQueryAttr->pGroupbyExpr); } + + filterFreeInfo(pQueryAttr->pFilters); } } diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 7ee19e88b3..0a7d7ac8e3 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -581,6 +581,13 @@ int32_t filterFreeRangeCtx(void* h) { r = rn; } + r = ctx->rf; + while (r) { + rn = r->next; + free(r); + r = rn; + } + free(ctx); return TSDB_CODE_SUCCESS; @@ -654,7 +661,7 @@ int32_t filterGetFiledByData(SFilterInfo *info, int32_t type, void *v, int32_t d } -int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, SFilterFieldId *fid, int32_t dataLen) { +int32_t filterAddField(SFilterInfo *info, void *desc, void **data, int32_t type, SFilterFieldId *fid, int32_t dataLen, bool freeIfExists) { int32_t idx = -1; uint16_t *num; @@ -663,8 +670,8 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, if (*num > 0) { if (type == FLD_TYPE_COLUMN) { idx = filterGetFiledByDesc(&info->fields[type], type, desc); - } else if (dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { - idx = filterGetFiledByData(info, type, data, dataLen); + } else if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + idx = filterGetFiledByData(info, type, *data, dataLen); } } @@ -677,15 +684,28 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, info->fields[type].fields[idx].flag = type; info->fields[type].fields[idx].desc = desc; - info->fields[type].fields[idx].data = data; + info->fields[type].fields[idx].data = data ? *data : NULL; + + if (type == FLD_TYPE_COLUMN) { + FILTER_SET_FLAG(info->fields[type].fields[idx].flag, FLD_DATA_NO_FREE); + } + ++(*num); - if (data && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { + if (data && (*data) && dataLen > 0 && FILTER_GET_FLAG(info->options, FI_OPTION_NEED_UNIQE)) { if (info->pctx.valHash == NULL) { info->pctx.valHash = taosHashInit(FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_VALUE_SIZE, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); } - taosHashPut(info->pctx.valHash, data, dataLen, &idx, sizeof(idx)); + taosHashPut(info->pctx.valHash, *data, dataLen, &idx, sizeof(idx)); + } + } else { + if (freeIfExists) { + tfree(desc); + } + + if (data && freeIfExists) { + tfree(*data); } } @@ -696,7 +716,7 @@ int32_t filterAddField(SFilterInfo *info, void *desc, void *data, int32_t type, } static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilterField *field, SFilterFieldId *fid) { - filterAddField(info, field->desc, field->data, FILTER_GET_TYPE(field->flag), fid, 0); + filterAddField(info, field->desc, &field->data, FILTER_GET_TYPE(field->flag), fid, 0, false); FILTER_SET_FLAG(field->flag, FLD_DESC_NO_FREE); FILTER_SET_FLAG(field->flag, FLD_DATA_NO_FREE); @@ -722,7 +742,7 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldI node->pVal = NULL; } - filterAddField(info, v, NULL, type, fid, 0); + filterAddField(info, v, NULL, type, fid, 0, true); return TSDB_CODE_SUCCESS; } @@ -829,7 +849,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g len = tDataTypes[type].bytes; } - filterAddField(info, NULL, fdata, FLD_TYPE_VALUE, &right, len); + filterAddField(info, NULL, &fdata, FLD_TYPE_VALUE, &right, len, true); filterAddUnit(info, TSDB_RELATION_EQUAL, &left, &right, &uidx); @@ -840,6 +860,8 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g p = taosHashIterate((SHashObj *)data, p); } + + taosHashCleanup(data); } else { filterAddFieldFromNode(info, tree->_node.pRight, &right); @@ -858,28 +880,34 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u, uint16_t *uidx) { SFilterFieldId left, right, *pright = &right; int32_t type = FILTER_UNIT_DATA_TYPE(u); + uint16_t flag = FLD_DESC_NO_FREE; - filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0); + filterAddField(dst, FILTER_UNIT_COL_DESC(src, u), NULL, FLD_TYPE_COLUMN, &left, 0, false); SFilterField *t = FILTER_UNIT_LEFT_FIELD(src, u); - FILTER_SET_FLAG(t->flag, FLD_DESC_NO_FREE); - + FILTER_SET_FLAG(t->flag, flag); + if (u->right.type == FLD_TYPE_VALUE) { void *data = FILTER_UNIT_VAL_DATA(src, u); if (IS_VAR_DATA_TYPE(type)) { if (FILTER_UNIT_OPTR(u) == TSDB_RELATION_IN) { - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, 0); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, 0, false); + + t = FILTER_GET_FIELD(dst, right); + + FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH); } else { - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, varDataTLen(data)); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, varDataTLen(data), false); } } else { - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, false); } + + flag = FLD_DATA_NO_FREE; t = FILTER_UNIT_RIGHT_FIELD(src, u); - FILTER_SET_FLAG(t->flag, FLD_DATA_NO_FREE); + FILTER_SET_FLAG(t->flag, flag); } else { pright = NULL; } - return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright, uidx); } @@ -926,7 +954,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (func(&ra->s, &ra->e) == 0) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; @@ -936,7 +964,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -944,7 +972,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->e); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -990,7 +1018,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (func(&r->ra.s, &r->ra.e) == 0) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); @@ -1004,7 +1032,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1012,7 +1040,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.e); - filterAddField(dst, NULL, data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1031,11 +1059,13 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan static void filterFreeGroup(void *pItem) { - SFilterGroup* p = (SFilterGroup*) pItem; - if (p) { - tfree(p->unitIdxs); - tfree(p->unitFlags); + if (pItem == NULL) { + return; } + + SFilterGroup* p = (SFilterGroup*) pItem; + tfree(p->unitIdxs); + tfree(p->unitFlags); } @@ -1113,10 +1143,10 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { qDebug("VAL%d => [type:TS][val:[%" PRIi64"] - [%" PRId64 "]]", i, *(int64_t *)field->data, *(((int64_t *)field->data) + 1)); } else { - qDebug("VAL%d => [type:%d][val:%" PRIi64"]", i, var->nType, var->i64); //TODO + qDebug("VAL%d => [type:%d][val:%" PRIx64"]", i, var->nType, var->i64); //TODO } - } else { - qDebug("VAL%d => [type:NIL][val:0x%" PRIx64"]", i, *(int64_t *)field->data); //TODO + } else if (field->data) { + qDebug("VAL%d => [type:NIL][val:NIL]", i); //TODO } } @@ -1248,10 +1278,67 @@ void filterFreeGroupCtx(SFilterGroupCtx* gRes) { tfree(gRes); } +void filterFreeField(SFilterField* field, int32_t type) { + if (field == NULL) { + return; + } + + if (!FILTER_GET_FLAG(field->flag, FLD_DESC_NO_FREE)) { + if (type == FLD_TYPE_VALUE) { + tVariantDestroy(field->desc); + } + + tfree(field->desc); + } + + if (!FILTER_GET_FLAG(field->flag, FLD_DATA_NO_FREE)) { + if (FILTER_GET_FLAG(field->flag, FLD_DATA_IS_HASH)) { + taosHashCleanup(field->data); + } else { + tfree(field->data); + } + } +} + +void filterFreePCtx(SFilterPCtx *pctx) { + taosHashCleanup(pctx->valHash); + taosHashCleanup(pctx->unitHash); +} + void filterFreeInfo(SFilterInfo *info) { CHK_RETV(info == NULL); - //TODO + for (int32_t i = 0; i < FLD_TYPE_MAX; ++i) { + for (uint16_t f = 0; f < info->fields[i].num; ++f) { + filterFreeField(&info->fields[i].fields[f], i); + } + + tfree(info->fields[i].fields); + } + + for (int32_t i = 0; i < info->groupNum; ++i) { + filterFreeGroup(&info->groups[i]); + } + + tfree(info->groups); + + tfree(info->units); + + tfree(info->unitRes); + + tfree(info->unitFlags); + + for (uint16_t i = 0; i < info->colRangeNum; ++i) { + filterFreeRangeCtx(info->colRange[i]); + } + + tfree(info->colRange); + + filterFreePCtx(&info->pctx); + + if (!FILTER_GET_FLAG(info->status, FI_STATUS_CLONED)) { + tfree(info); + } } @@ -1281,14 +1368,16 @@ int32_t filterInitValFieldData(SFilterInfo *info) { if (unit->compare.optr == TSDB_RELATION_IN) { convertFilterSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); - + + FILTER_SET_FLAG(fi->flag, FLD_DATA_IS_HASH); + continue; } if (type == TSDB_DATA_TYPE_BINARY) { - fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); + fi->data = calloc(1, var->nLen + VARSTR_HEADER_SIZE); } else if (type == TSDB_DATA_TYPE_NCHAR) { - fi->data = calloc(1, (var->nLen + 1) * TSDB_NCHAR_SIZE); + fi->data = calloc(1, (var->nLen + VARSTR_HEADER_SIZE) * TSDB_NCHAR_SIZE); } else { if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE fi->data = calloc(var->nLen, tDataTypes[type].bytes); @@ -1488,7 +1577,9 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t colIdx[colIdxi++] = cidx; ++gRes[gResIdx]->colNum; } else { - FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); + if (!FILTER_NO_MERGE_DATA_TYPE(FILTER_UNIT_DATA_TYPE(u))) { + FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); + } } FILTER_PUSH_UNIT(gRes[gResIdx]->colInfo[cidx], u); @@ -1701,8 +1792,12 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter _err_return: - if (colCtxs && taosArrayGetSize(colCtxs) > 0) { - taosArrayDestroyEx(colCtxs, filterFreeColCtx); + if (colCtxs) { + if (taosArrayGetSize(colCtxs) > 0) { + taosArrayDestroyEx(colCtxs, filterFreeColCtx); + } else { + taosArrayDestroy(colCtxs); + } } filterFreeRangeCtx(ctx); @@ -1823,6 +1918,8 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum } SFilterInfo oinfo = *info; + + FILTER_SET_FLAG(oinfo.status, FI_STATUS_CLONED); SArray* group = taosArrayInit(FILTER_DEFAULT_GROUP_SIZE, sizeof(SFilterGroup)); SFilterGroupCtx *res = NULL; @@ -1831,6 +1928,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum uint16_t uidx = 0; memset(info, 0, sizeof(*info)); + info->colRangeNum = oinfo.colRangeNum; info->colRange = oinfo.colRange; oinfo.colRangeNum = 0; @@ -1877,6 +1975,8 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t gResNum taosArrayDestroy(group); + filterFreeInfo(&oinfo); + return TSDB_CODE_SUCCESS; } @@ -1961,6 +2061,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ } _err_return: + tfree(idxNum); tfree(idxs); return TSDB_CODE_SUCCESS; @@ -1990,12 +2091,13 @@ int32_t filterPreprocess(SFilterInfo *info) { if (FILTER_GET_FLAG(info->status, FI_STATUS_ALL)) { qInfo("Final - FilterInfo: [ALL]"); - return TSDB_CODE_SUCCESS; + goto _return; } + if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { qInfo("Final - FilterInfo: [EMPTY]"); - return TSDB_CODE_SUCCESS; + goto _return; } filterGenerateColRange(info, gRes, gResNum); @@ -2005,6 +2107,14 @@ int32_t filterPreprocess(SFilterInfo *info) { filterPostProcessRange(info); filterRewrite(info, gRes, gResNum); + +_return: + + for (int32_t i = 0; i < gResNum; ++i) { + filterFreeGroupCtx(gRes[i]); + } + + tfree(gRes); return TSDB_CODE_SUCCESS; } diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 919ecdade8..bb5efdb123 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -459,9 +459,7 @@ static void doDestroySqlExprNode(tSqlExpr *pExpr) { return; } - if (pExpr->tokenId == TK_STRING) { - tVariantDestroy(&pExpr->value); - } + tVariantDestroy(&pExpr->value); tSqlExprListDestroy(pExpr->Expr.paramList); free(pExpr); diff --git a/src/query/src/queryMain.c b/src/query/src/queryMain.c index dd20716388..0bdf4d2ead 100644 --- a/src/query/src/queryMain.c +++ b/src/query/src/queryMain.c @@ -175,6 +175,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi param.pSecExprs = NULL; param.pGroupbyExpr = NULL; param.pTagColumnInfo = NULL; + param.pFilters = NULL; if ((*pQInfo) == NULL) { code = TSDB_CODE_QRY_OUT_OF_MEMORY; @@ -200,6 +201,8 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi freeColumnFilterInfo(column->flist.filterInfo, column->flist.numOfFilters); } + filterFreeInfo(param.pFilters); + //pQInfo already freed in initQInfo, but *pQInfo may not pointer to null; if (code != TSDB_CODE_SUCCESS) { *pQInfo = NULL; diff --git a/src/util/src/hash.c b/src/util/src/hash.c index c8bd79f118..c8e04a37b1 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -713,7 +713,8 @@ size_t taosHashGetMemSize(const SHashObj *pHashObj) { } FORCE_INLINE void *taosHashGetDataKey(SHashObj *pHashObj, void *data) { - return GET_HASH_NODE_KEY(GET_HASH_PNODE(data)); + SHashNode * node = GET_HASH_PNODE(data); + return GET_HASH_NODE_KEY(node); } FORCE_INLINE uint32_t taosHashGetDataKeyLen(SHashObj *pHashObj, void *data) { From deb9a7cfbc78391d044be61e255c24f7b74ad2a0 Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 27 Jul 2021 11:35:53 +0800 Subject: [PATCH 029/100] fix bool in issue --- src/client/src/tscSQLParser.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 8037e36a37..4ccfdbaf59 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -186,6 +186,9 @@ bool serializeExprListToVariant(SArray* pList, tVariant **dst, int16_t colType, if (var->nType != TSDB_DATA_TYPE_BOOL && !IS_SIGNED_NUMERIC_TYPE(var->nType)) { break; } + if (colType == TSDB_DATA_TYPE_BOOL && (var->i64 > 1 ||var->i64 < 0)) { + break; + } tbufWriteInt64(&bw, var->i64); } else if (IS_UNSIGNED_NUMERIC_TYPE(colType)) { if (IS_SIGNED_NUMERIC_TYPE(var->nType) || IS_UNSIGNED_NUMERIC_TYPE(var->nType)) { From 4336659e9c89d52b4c46396b84817b8d0806a1ed Mon Sep 17 00:00:00 2001 From: dapan <89396746@qq.com> Date: Tue, 27 Jul 2021 11:40:16 +0800 Subject: [PATCH 030/100] fix issue --- src/client/src/tscSQLParser.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4ccfdbaf59..79a7c52777 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -9197,4 +9197,3 @@ void normalizeSqlNode(SSqlNode* pSqlNode, const char* dbName) { #endif - \ No newline at end of file From 83d1283390797824c766008e6268b9ade769763d Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 27 Jul 2021 18:17:14 +0800 Subject: [PATCH 031/100] fix bug and case issue --- src/client/inc/tscUtil.h | 2 +- src/client/src/tscSQLParser.c | 15 ++-- src/client/src/tscSubquery.c | 2 +- src/client/src/tscUtil.c | 19 ++-- src/query/src/qFilter.c | 6 +- tests/script/general/parser/condition.sim | 6 +- .../script/general/parser/condition_query.sim | 89 ++++++++++++++++++- tests/script/general/parser/set_tag_vals.sim | 7 +- 8 files changed, 118 insertions(+), 28 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 527ca24335..e52b0958ae 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -245,7 +245,7 @@ SCond* tsGetSTableQueryCond(STagCond* pCond, uint64_t uid); void tsSetSTableQueryCond(STagCond* pTagCond, uint64_t uid, SBufferWriter* bw); int32_t tscTagCondCopy(STagCond* dest, const STagCond* src); -int32_t tscColCondCopy(SArray** dest, const SArray* src); +int32_t tscColCondCopy(SArray** dest, const SArray* src, uint64_t uid, int16_t tidx); void tscTagCondRelease(STagCond* pCond); void tscColCondRelease(SArray** pCond); void tscGetSrcColumnInfo(SSrcColumnInfo* pColInfo, SQueryInfo* pQueryInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4ccfdbaf59..bc5ef6fa39 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4805,6 +4805,8 @@ err_ret: tSqlExprDestroy(columnLeft); tSqlExprDestroy(columnRight); + tSqlExprDestroy(tsLeft); + tSqlExprDestroy(tsRight); return ret; } @@ -5198,7 +5200,7 @@ static int32_t validateTagCondExpr(SSqlCmd* pCmd, tExprNode *p) { return TSDB_CODE_SUCCESS; } -static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr, tSqlExpr** pExpr) { +static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondExpr* pCondExpr) { int32_t ret = TSDB_CODE_SUCCESS; if (pCondExpr->pTagCond == NULL) { @@ -5206,7 +5208,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE } for (int32_t i = 0; i < pQueryInfo->numOfTables; ++i) { - tSqlExpr* p1 = extractExprForSTable(pCmd, pExpr, pQueryInfo, i); + tSqlExpr* p1 = extractExprForSTable(pCmd, &pCondExpr->pTagCond, pQueryInfo, i); if (p1 == NULL) { // no query condition on this table continue; } @@ -5245,7 +5247,7 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE } tsSetSTableQueryCond(&pQueryInfo->tagCond, uid, &bw); - tSqlExprCompact(pExpr); + tSqlExprCompact(&pCondExpr->pTagCond); if (ret == TSDB_CODE_SUCCESS) { ret = validateTagCondExpr(pCmd, p); @@ -5264,7 +5266,6 @@ static int32_t getTagQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SCondE } } - pCondExpr->pTagCond = NULL; return ret; } @@ -5446,6 +5447,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq // after expression compact, the expression tree is only include tag query condition condExpr.pTagCond = (*pExpr); + *pExpr = NULL; // 1. check if it is a join query if ((ret = validateJoinExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { @@ -5462,7 +5464,7 @@ int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSq } // 3. get the tag query condition - if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr, pExpr)) != TSDB_CODE_SUCCESS) { + if ((ret = getTagQueryCondExpr(&pSql->cmd, pQueryInfo, &condExpr)) != TSDB_CODE_SUCCESS) { goto PARSE_WHERE_EXIT; } @@ -9141,7 +9143,7 @@ int32_t exprTreeFromSqlExpr(SSqlCmd* pCmd, tExprNode **pExpr, const tSqlExpr* pS // NOTE: binary|nchar data allows the >|< type filter if ((*pExpr)->_node.optr != TSDB_RELATION_EQUAL && (*pExpr)->_node.optr != TSDB_RELATION_NOT_EQUAL) { if (pRight != NULL && pRight->nodeType == TSQL_NODE_VALUE) { - if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL) { + if (pRight->pVal->nType == TSDB_DATA_TYPE_BOOL && pLeft->pSchema->type == TSDB_DATA_TYPE_BOOL) { return TSDB_CODE_TSC_INVALID_OPERATION; } } @@ -9197,4 +9199,3 @@ void normalizeSqlNode(SSqlNode* pSqlNode, const char* dbName) { #endif - \ No newline at end of file diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index de8b907539..e75bbb7f98 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2321,7 +2321,7 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) { goto _error; } - if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond) != 0) { + if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond, pTableMetaInfo->pTableMeta->id.uid, 0) != 0) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 4e1c0c0028..86c28f7a2f 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2999,7 +2999,7 @@ int32_t tscTagCondCopy(STagCond* dest, const STagCond* src) { return 0; } -int32_t tscColCondCopy(SArray** dest, const SArray* src) { +int32_t tscColCondCopy(SArray** dest, const SArray* src, uint64_t uid, int16_t tidx) { if (src == NULL) { return 0; } @@ -3009,11 +3009,20 @@ int32_t tscColCondCopy(SArray** dest, const SArray* src) { for (int32_t i = 0; i < s; ++i) { STblCond* pCond = taosArrayGet(src, i); - STblCond c = {0}; + + if (tidx > 0) { + if (!(pCond->uid == uid && pCond->idx == tidx)) { + continue; + } + + c.idx = 0; + } else { + c.idx = pCond->idx; + } + c.len = pCond->len; c.uid = pCond->uid; - c.idx = pCond->idx; if (pCond->len > 0) { assert(pCond->cond != NULL); @@ -3329,7 +3338,7 @@ int32_t tscQueryInfoCopy(SQueryInfo* pQueryInfo, const SQueryInfo* pSrc) { goto _error; } - if (tscColCondCopy(&pQueryInfo->colCond, pSrc->colCond) != 0) { + if (tscColCondCopy(&pQueryInfo->colCond, pSrc->colCond, 0, -1) != 0) { code = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } @@ -3729,7 +3738,7 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t goto _error; } - if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond) != 0) { + if (tscColCondCopy(&pNewQueryInfo->colCond, pQueryInfo->colCond, pTableMetaInfo->pTableMeta->id.uid, tableIndex) != 0) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; goto _error; } diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 0a7d7ac8e3..605fdd64ce 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -2351,7 +2351,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { SFilterRangeCtx *cur = NULL; int32_t num = 0; int32_t optr = 0; - int32_t code = TSDB_CODE_QRY_INVALID_TIME_CONDITION; + int32_t code = 0; bool empty = false, all = false; for (int32_t i = 0; i < info->groupNum; ++i) { @@ -2405,11 +2405,13 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { *win = TSWINDOW_INITIALIZER; } else { filterGetRangeNum(prev, &num); - if (num != 1) { + if (num > 1) { qError("only one time range accepted, num:%d", num); ERR_JRET(TSDB_CODE_QRY_INVALID_TIME_CONDITION); } + CHK_JMP(num < 1); + SFilterRange tra; filterGetRangeRes(prev, &tra); win->skey = tra.s; diff --git a/tests/script/general/parser/condition.sim b/tests/script/general/parser/condition.sim index e29f154d44..56706467f1 100644 --- a/tests/script/general/parser/condition.sim +++ b/tests/script/general/parser/condition.sim @@ -50,10 +50,10 @@ sql insert into tb6 values ('2021-05-05 18:19:26',63,63.0,63,63,63,63.0,false,'6 sql insert into tb6 values ('2021-05-05 18:19:27',64,64.0,64,64,64,64.0,false,'64','64') sql insert into tb6 values ('2021-05-05 18:19:28',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL) -sql create table stb2 (ts timestamp, u1 int unsigned, u2 bigint unsigned, u3 smallint unsigned, u4 tinyint unsigned, ts2 timestamp) TAGS(t1 int unsigned, t2 bigint unsigned, t3 timestamp) +sql create table stb2 (ts timestamp, u1 int unsigned, u2 bigint unsigned, u3 smallint unsigned, u4 tinyint unsigned, ts2 timestamp) TAGS(t1 int unsigned, t2 bigint unsigned, t3 timestamp, t4 int) -sql create table tb2_1 using stb2 tags(1,1,'2021-05-05 18:38:38') -sql create table tb2_2 using stb2 tags(2,2,'2021-05-05 18:58:58') +sql create table tb2_1 using stb2 tags(1,1,'2021-05-05 18:38:38',1) +sql create table tb2_2 using stb2 tags(2,2,'2021-05-05 18:58:58',2) sql insert into tb2_1 values ('2021-05-05 18:19:00',1,2,3,4,'2021-05-05 18:28:01') sql insert into tb2_1 values ('2021-05-05 18:19:01',5,6,7,8,'2021-05-05 18:28:02') diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim index 45c20a0ce1..25e29eeca7 100644 --- a/tests/script/general/parser/condition_query.sim +++ b/tests/script/general/parser/condition_query.sim @@ -1896,14 +1896,29 @@ sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' and ts > '2021-05-05 18:19:20.000' and ts != '2021-05-05 18:19:22.000'; sql_error select * from stb1 where ts2 like '2021-05-05%'; -sql_error select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:05.000') and ts > '2021-05-05 18:19:01.000' and ts < '2021-05-05 18:19:27.000'; sql_error select ts,c1,c2 from stb1 where (ts > '2021-05-05 18:19:20.000' or ts < '2021-05-05 18:19:05.000') and ts != '2021-05-05 18:19:25.000'; sql_error select ts,c1,c2 from stb1 where ((ts >= '2021-05-05 18:19:05.000' and ts <= '2021-05-05 18:19:10.000') or (ts >= '2021-05-05 18:19:15.000' and ts <= '2021-05-05 18:19:20.000') or (ts >= '2021-05-05 18:19:11.000' and ts <= '2021-05-05 18:19:14.000')); sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' or ts < '2021-05-05 18:19:24.000'; -sql_error select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; -sql_error select * from stb1 where ts is null; -sql_error select * from stb1 where ts is not null and ts is null; +sql select * from stb1 where ts is null; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where ts is not null and ts is null; +if $rows != 0 then + return -1 +endi + +sql select ts,c1,c2 from stb1 where ts >= '2021-05-05 18:19:25.000' and ts < '2021-05-05 18:19:10.000'; +if $rows != 0 then + return -1 +endi + +sql select * from stb1 where ts > '2021-05-05 18:19:03.000' and ts < '2021-05-05 18:19:02'; +if $rows != 0 then + return -1 +endi + sql select * from stb1 where ts is not null; if $rows != 29 then return -1 @@ -2279,7 +2294,73 @@ endi if $data10 != @21-05-05 18:19:05.000@ then return -1 endi +sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts > '2021-05-05 18:19:03.000' and tb2_1.u1 < 5; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:06.000@ then + return -1 +endi +sql select tb1.ts,tb1.*,tb2_1.* from tb1, tb2_1 where tb1.ts=tb2_1.ts and tb1.ts >= '2021-05-05 18:19:03.000' and tb1.c7=false and tb2_1.u3>4; +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:07.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4; +if $rows != 9 then + return -1 +endi +if $data00 != @21-05-05 18:19:00.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:01.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:03.000@ then + return -1 +endi +if $data40 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data50 != @21-05-05 18:19:05.000@ then + return -1 +endi +if $data60 != @21-05-05 18:19:06.000@ then + return -1 +endi +if $data70 != @21-05-05 18:19:07.000@ then + return -1 +endi +if $data80 != @21-05-05 18:19:11.000@ then + return -1 +endi + +sql select stb1.ts,stb1.c1,stb1.t1,stb2.ts,stb2.u1,stb2.t4 from stb1, stb2 where stb1.ts=stb2.ts and stb1.t1 = stb2.t4 and stb1.c1 > 2 and stb2.u1 <=4; +if $rows != 3 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:04.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:06.000@ then + return -1 +endi print "column&ts test" sql_error select count(*) from stb1 where ts > 0 or c1 > 0; diff --git a/tests/script/general/parser/set_tag_vals.sim b/tests/script/general/parser/set_tag_vals.sim index 74184f94d4..4a63f9c6f1 100644 --- a/tests/script/general/parser/set_tag_vals.sim +++ b/tests/script/general/parser/set_tag_vals.sim @@ -83,10 +83,7 @@ while $i < $tbNum endw print ================== all tags have been changed! -sql select tbname from $stb where t3 = 'NULL' -if $rows != 0 then - return -1 -endi +sql_error select tbname from $stb where t3 = 'NULL' print ================== set tag to NULL sql create table stb1_tg (ts timestamp, c1 int) tags(t1 int,t2 bigint,t3 double,t4 float,t5 smallint,t6 tinyint) @@ -227,4 +224,4 @@ if $data04 != NULL then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT From 63532d0038c460b235e96a40a93751c679ab3dc8 Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 29 Jul 2021 09:30:20 +0800 Subject: [PATCH 032/100] fix bug --- src/client/src/tscServer.c | 1 + src/query/inc/qFilter.h | 2 ++ src/query/src/qFilter.c | 6 ++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7b2cc5d298..b7a6ee6e75 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -3105,3 +3105,4 @@ void tscInitMsgsFp() { tscKeepConn[TSDB_SQL_HB] = 1; } + \ No newline at end of file diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index d7edefd9cd..75d6f0b745 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -30,6 +30,8 @@ extern "C" { #define FILTER_DEFAULT_VALUE_SIZE 4 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 +#define MAX_NUM_STR_SIZE 40 + enum { FLD_TYPE_COLUMN = 1, FLD_TYPE_VALUE = 2, diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 605fdd64ce..1aa5ab8437 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1375,9 +1375,11 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } if (type == TSDB_DATA_TYPE_BINARY) { - fi->data = calloc(1, var->nLen + VARSTR_HEADER_SIZE); + size_t len = (var->nType == TSDB_DATA_TYPE_BINARY || var->nType == TSDB_DATA_TYPE_NCHAR) ? var->nLen : MAX_NUM_STR_SIZE; + fi->data = calloc(1, len + 1 + VARSTR_HEADER_SIZE); } else if (type == TSDB_DATA_TYPE_NCHAR) { - fi->data = calloc(1, (var->nLen + VARSTR_HEADER_SIZE) * TSDB_NCHAR_SIZE); + size_t len = (var->nType == TSDB_DATA_TYPE_BINARY || var->nType == TSDB_DATA_TYPE_NCHAR) ? var->nLen : MAX_NUM_STR_SIZE; + fi->data = calloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE); } else { if (var->nType == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE fi->data = calloc(var->nLen, tDataTypes[type].bytes); From 4cf5f99ce7e2799abb0ef2457efbe30b45e7096a Mon Sep 17 00:00:00 2001 From: dapan <89396746@qq.com> Date: Thu, 29 Jul 2021 09:33:10 +0800 Subject: [PATCH 033/100] remove string --- src/client/src/tscServer.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index b7a6ee6e75..7b2cc5d298 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -3105,4 +3105,3 @@ void tscInitMsgsFp() { tscKeepConn[TSDB_SQL_HB] = 1; } - \ No newline at end of file From 1b5a4492106f1aab2c6c8c12f2cdb23d6da45003 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 29 Jul 2021 09:41:47 +0800 Subject: [PATCH 034/100] add support for parsing timestamp with both letter 'T' and whitespace as timezone indicator --- src/os/src/detail/osTime.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 847d484d9e..8db3fed701 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -82,7 +82,7 @@ void deltaToUtcInitOnce() { } static int64_t parseFraction(char* str, char** end, int32_t timePrec); -static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec); +static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char delim); static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec); static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec); @@ -96,7 +96,9 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ if (strnchr(timestr, 'T', len, false) != NULL) { - return parseTimeWithTz(timestr, time, timePrec); + return parseTimeWithTz(timestr, time, timePrec, 'T'); + } else if (strnchr(timestr, ' ', len, false) != NULL) { + return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); } @@ -213,14 +215,23 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { * 2013-04-12T15:52:01+0800 * 2013-04-12T15:52:01.123+0800 */ -int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec) { +int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char delim) { int64_t factor = (timePrec == TSDB_TIME_PRECISION_MILLI) ? 1000 : (timePrec == TSDB_TIME_PRECISION_MICRO ? 1000000 : 1000000000); int64_t tzOffset = 0; struct tm tm = {0}; - char* str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); + + char* str; + if (delim == 'T') { + str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); + } else if (delim == ' ') { + str = strptime(timestr, "%Y-%m-%d%n%H:%M:%S", &tm); + } else { + str = NULL; + } + if (str == NULL) { return -1; } From 02f88d54098ee3648d740e906a86c247539c344e Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 29 Jul 2021 13:03:18 +0800 Subject: [PATCH 035/100] [TD-5505]: add support for parsing timestamp with both letter 'T' and whitespace as timezone indicator --- src/os/src/detail/osTime.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 8db3fed701..c7a249c2e3 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -85,6 +85,7 @@ static int64_t parseFraction(char* str, char** end, int32_t timePrec); static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char delim); static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec); static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec); +static char* forwardToTimeStringEnd(char* str); static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { parseLocaltime, @@ -95,9 +96,12 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ + char *seg = forwardToTimeStringEnd(timestr); if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); - } else if (strnchr(timestr, ' ', len, false) != NULL) { + } else if (strnchr(timestr, ' ', len, false) != NULL && + (strnchr(seg, 'Z', len, false) != NULL || strnchr(seg, 'z', len, false) != NULL || + strnchr(seg, '+', len, false) != NULL || strnchr(seg, '-', len, false) != NULL)) { return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); From f56027daddeda1716b0940806a460ff37e3be41f Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 29 Jul 2021 13:03:18 +0800 Subject: [PATCH 036/100] [TD-5505]: add test cases --- src/os/src/detail/osTime.c | 4 ++-- src/query/tests/unitTest.cpp | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index c7a249c2e3..85970a4790 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -100,8 +100,8 @@ int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePre if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); } else if (strnchr(timestr, ' ', len, false) != NULL && - (strnchr(seg, 'Z', len, false) != NULL || strnchr(seg, 'z', len, false) != NULL || - strnchr(seg, '+', len, false) != NULL || strnchr(seg, '-', len, false) != NULL)) { + (strnchr(seg, 'Z', strlen(seg), false) != NULL || strnchr(seg, 'z', strlen(seg), false) != NULL || + strnchr(seg, '+', strlen(seg), false) != NULL || strnchr(seg, '-', strlen(seg), false) != NULL)) { return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index e5487a061d..51afca9532 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -407,11 +407,33 @@ TEST(testCase, parse_time) { taosParseTime(t41, &time, strlen(t41), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999); - int64_t k = timezone; char t42[] = "1997-1-1T0:0:0.999999999Z"; taosParseTime(t42, &time, strlen(t42), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, 852048000999 - timezone * MILLISECOND_PER_SECOND); + // "%Y-%m-%d %H:%M:%S" format with TimeZone appendix is also treated as legal + // and TimeZone will be processed + char t60[] = "2017-4-3 1:1:2.980"; + char t61[] = "2017-4-3 2:1:2.98+9:00"; + taosParseTime(t60, &time, strlen(t60), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t61, &time1, strlen(t61), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t62[] = "2017-4-3 2:1:2.98+09:00"; + taosParseTime(t62, &time, strlen(t62), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t61, &time1, strlen(t61), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t63[] = "2017-4-3 2:1:2.98+0900"; + taosParseTime(t63, &time, strlen(t63), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t62, &time1, strlen(t62), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t64[] = "2017-4-2 17:1:2.98Z"; + taosParseTime(t63, &time, strlen(t63), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t64, &time1, strlen(t64), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + //////////////////////////////////////////////////////////////////// // illegal timestamp format char t15[] = "2017-12-33 0:0:0"; @@ -430,8 +452,7 @@ TEST(testCase, parse_time) { EXPECT_EQ(taosParseTime(t19, &time, strlen(t19), TSDB_TIME_PRECISION_MILLI, 0), -1); char t20[] = "2017-12-31 9:0:0.1+12:99"; - EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI, 0), 0); - EXPECT_EQ(time, 1514682000100); + EXPECT_EQ(taosParseTime(t20, &time, strlen(t20), TSDB_TIME_PRECISION_MILLI, 0), -1); char t21[] = "2017-12-31T9:0:0.1+12:99"; EXPECT_EQ(taosParseTime(t21, &time, strlen(t21), TSDB_TIME_PRECISION_MILLI, 0), -1); From 20b79cb24ff923523600ac06246894cbbf65b616 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 29 Jul 2021 19:01:50 +0800 Subject: [PATCH 037/100] [TD-5505]:windows build error --- src/os/src/detail/osTime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 85970a4790..2a74ef131b 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -100,8 +100,8 @@ int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePre if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); } else if (strnchr(timestr, ' ', len, false) != NULL && - (strnchr(seg, 'Z', strlen(seg), false) != NULL || strnchr(seg, 'z', strlen(seg), false) != NULL || - strnchr(seg, '+', strlen(seg), false) != NULL || strnchr(seg, '-', strlen(seg), false) != NULL)) { + (strnchr(seg, 'Z', (int32_t)strlen(seg), false) != NULL || strnchr(seg, 'z', (int32_t)strlen(seg), false) != NULL || + strnchr(seg, '+', (int32_t)strlen(seg), false) != NULL || strnchr(seg, '-', (int32_t)strlen(seg), false) != NULL)) { return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); From 07f7b9acb5a0394c3e4ef5e0d27b4f326db35a2d Mon Sep 17 00:00:00 2001 From: wpan Date: Fri, 30 Jul 2021 08:33:36 +0800 Subject: [PATCH 038/100] fix bug --- src/client/src/tscServer.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 7b2cc5d298..20eba96603 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -640,7 +640,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd); int32_t srcColListSize = (int32_t)(taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo)); - int32_t srcColFilterSize = tscGetColFilterSerializeLen(pQueryInfo); + int32_t srcColFilterSize = 0; size_t numOfExprs = tscNumOfExprs(pQueryInfo); int32_t exprSize = (int32_t)(sizeof(SSqlExpr) * numOfExprs * 2); @@ -649,6 +649,7 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { int32_t tableSerialize = 0; STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; if (pTableMetaInfo->pVgroupTables != NULL) { size_t numOfGroups = taosArrayGetSize(pTableMetaInfo->pVgroupTables); @@ -661,6 +662,13 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { tableSerialize = totalTables * sizeof(STableIdInfo); } + if (pQueryInfo->colCond && taosArrayGetSize(pQueryInfo->colCond) > 0) { + STblCond *pCond = tsGetTableFilter(pQueryInfo->colCond, pTableMeta->id.uid, 0); + if (pCond != NULL && pCond->cond != NULL) { + srcColFilterSize = pCond->len; + } + } + return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; } From db88b17c61d769a72fbb0cfd7b95bb258c9eac85 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 30 Jul 2021 10:42:33 +0800 Subject: [PATCH 039/100] [TD-5505]:fix timezone string part length issue --- src/os/src/detail/osTime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 2a74ef131b..7ae9f58bc4 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -97,11 +97,12 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ char *seg = forwardToTimeStringEnd(timestr); + int32_t seg_len = len - (seg - timestr); if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); } else if (strnchr(timestr, ' ', len, false) != NULL && - (strnchr(seg, 'Z', (int32_t)strlen(seg), false) != NULL || strnchr(seg, 'z', (int32_t)strlen(seg), false) != NULL || - strnchr(seg, '+', (int32_t)strlen(seg), false) != NULL || strnchr(seg, '-', (int32_t)strlen(seg), false) != NULL)) { + (strnchr(seg, 'Z', seg_len, false) != NULL || strnchr(seg, 'z', seg_len, false) != NULL || + strnchr(seg, '+', seg_len, false) != NULL || strnchr(seg, '-', seg_len, false) != NULL)) { return parseTimeWithTz(timestr, time, timePrec, ' '); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); From a81f2bd1e58c3c08986a25fb88cf89a55bdf3ede Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 30 Jul 2021 11:12:04 +0800 Subject: [PATCH 040/100] [TD-5659]:start taos processing with subprocess instead of internal function --- tests/pytest/insert/metadataUpdate.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/tests/pytest/insert/metadataUpdate.py b/tests/pytest/insert/metadataUpdate.py index 1a960a20e6..f996a707ff 100644 --- a/tests/pytest/insert/metadataUpdate.py +++ b/tests/pytest/insert/metadataUpdate.py @@ -16,7 +16,6 @@ from util.log import tdLog from util.cases import tdCases from util.sql import tdSql from util.dnodes import tdDnodes -from multiprocessing import Process import subprocess class TDTestCase: @@ -28,16 +27,6 @@ class TDTestCase: self.tables = 10 self.rows = 1000 - def updateMetadata(self): - self.host = "127.0.0.1" - self.user = "root" - self.password = "taosdata" - self.config = tdDnodes.getSimCfgPath() - - self.conn = taos.connect(host = self.host, user = self.user, password = self.password, config = self.config) - self.cursor = self.conn.cursor() - self.cursor.execute("alter table db.tb add column col2 int") - print("alter table done") def deleteTableAndRecreate(self): self.config = tdDnodes.getSimCfgPath() @@ -68,11 +57,15 @@ class TDTestCase: tdSql.query("select * from tb") tdSql.checkRows(1) - p = Process(target=self.updateMetadata, args=()) - p.start() - p.join() - p.terminate() - + self.config = tdDnodes.getSimCfgPath() + command = ["taos", "-c", self.config, "-s", "alter table db.tb add column col2 int;"] + print("alter table db.tb add column col2 int;") + result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf-8") + if result.returncode == 0: + print("success:", result) + else: + print("error:", result) + tdSql.execute("insert into tb(ts, col1, col2) values(%d, 1, 2)" % (self.ts + 2)) print("==============step2") From 83b5c2a6a7141c7965bd71fbb9495db534b11377 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 30 Jul 2021 11:42:56 +0800 Subject: [PATCH 041/100] [TD-5505]: windows compilation error --- src/os/src/detail/osTime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 7ae9f58bc4..696867e586 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -97,7 +97,7 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ char *seg = forwardToTimeStringEnd(timestr); - int32_t seg_len = len - (seg - timestr); + int32_t seg_len = len - (int32_t)(seg - timestr); if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); } else if (strnchr(timestr, ' ', len, false) != NULL && From 1643b5e4c6e4a957a6638f8d06e7490e7d69d951 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 2 Aug 2021 14:16:17 +0800 Subject: [PATCH 042/100] fix bug and case issue --- src/client/src/tscUtil.c | 4 +- src/common/inc/texpr.h | 1 - src/common/inc/tvariant.h | 2 + src/common/src/tvariant.c | 78 +++++- src/query/inc/qFilter.h | 8 +- src/query/src/qFilter.c | 257 +++++++++++++++++- tests/pytest/query/queryBetweenAnd.py | 4 +- .../script/general/parser/condition_query.sim | 54 ++++ 8 files changed, 382 insertions(+), 26 deletions(-) diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 714e77b35f..f39b7d3ec2 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -62,11 +62,11 @@ int32_t converToStr(char *str, int type, void *buf, int32_t bufSize, int32_t *le break; case TSDB_DATA_TYPE_FLOAT: - n = sprintf(str, "%f", GET_FLOAT_VAL(buf)); + n = sprintf(str, "%e", GET_FLOAT_VAL(buf)); break; case TSDB_DATA_TYPE_DOUBLE: - n = sprintf(str, "%f", GET_DOUBLE_VAL(buf)); + n = sprintf(str, "%e", GET_DOUBLE_VAL(buf)); break; case TSDB_DATA_TYPE_BINARY: diff --git a/src/common/inc/texpr.h b/src/common/inc/texpr.h index 65ff05ad3e..2e49a69366 100644 --- a/src/common/inc/texpr.h +++ b/src/common/inc/texpr.h @@ -95,7 +95,6 @@ void arithmeticTreeTraverse(tExprNode *pExprs, int32_t numOfRows, char *pOutput, char *(*cb)(void *, const char*, int32_t)); void buildFilterSetFromBinary(void **q, const char *buf, int32_t len); -void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType); #ifdef __cplusplus } diff --git a/src/common/inc/tvariant.h b/src/common/inc/tvariant.h index 21b7fd8223..c69a662846 100644 --- a/src/common/inc/tvariant.h +++ b/src/common/inc/tvariant.h @@ -53,6 +53,8 @@ int32_t tVariantToString(tVariant *pVar, char *dst); int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix); +int32_t tVariantDumpEx(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo); + int32_t tVariantTypeSetType(tVariant *pVariant, char type); #ifdef __cplusplus diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 8ae611cb07..a491df6f98 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -23,6 +23,13 @@ #include "tutil.h" #include "tvariant.h" +#define SET_EXT_INFO(converted, res, minv, maxv, exti) do { \ + if (converted == NULL || exti == NULL || *converted == false) { break; } \ + if ((res) < (minv)) { *exti = -1; break; } \ + if ((res) > (maxv)) { *exti = 1; break; } \ + assert(0); \ + } while (0) + void tVariantCreate(tVariant *pVar, SStrToken *token) { int32_t ret = 0; int32_t type = token->type; @@ -462,7 +469,7 @@ static FORCE_INLINE int32_t convertToDouble(char *pStr, int32_t len, double *val return 0; } -static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, bool issigned, bool releaseVariantPtr) { +static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result, int32_t type, bool issigned, bool releaseVariantPtr, bool *converted) { if (pVariant->nType == TSDB_DATA_TYPE_NULL) { setNull((char *)result, type, tDataTypes[type].bytes); return 0; @@ -552,6 +559,10 @@ static FORCE_INLINE int32_t convertToInteger(tVariant *pVariant, int64_t *result } } + if (converted) { + *converted = true; + } + bool code = false; uint64_t ui = 0; @@ -614,6 +625,18 @@ static int32_t convertToBool(tVariant *pVariant, int64_t *pDest) { * to column type defined in schema */ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix) { + return tVariantDumpEx(pVariant, payload, type, includeLengthPrefix, NULL, NULL); +} + +/* + * transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType + * to column type defined in schema + */ +int32_t tVariantDumpEx(tVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo) { + if (converted) { + *converted = false; + } + if (pVariant == NULL || (pVariant->nType != 0 && !isValidDataType(pVariant->nType))) { return -1; } @@ -632,7 +655,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_TINYINT: { - if (convertToInteger(pVariant, &result, type, true, false) < 0) { + if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { + SET_EXT_INFO(converted, result, INT8_MIN + 1, INT8_MAX, extInfo); return -1; } *((int8_t *)payload) = (int8_t) result; @@ -640,7 +664,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_UTINYINT: { - if (convertToInteger(pVariant, &result, type, false, false) < 0) { + if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { + SET_EXT_INFO(converted, result, 0, UINT8_MAX - 1, extInfo); return -1; } *((uint8_t *)payload) = (uint8_t) result; @@ -648,7 +673,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_SMALLINT: { - if (convertToInteger(pVariant, &result, type, true, false) < 0) { + if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { + SET_EXT_INFO(converted, result, INT16_MIN + 1, INT16_MAX, extInfo); return -1; } *((int16_t *)payload) = (int16_t)result; @@ -656,7 +682,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_USMALLINT: { - if (convertToInteger(pVariant, &result, type, false, false) < 0) { + if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { + SET_EXT_INFO(converted, result, 0, UINT16_MAX - 1, extInfo); return -1; } *((uint16_t *)payload) = (uint16_t)result; @@ -664,7 +691,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_INT: { - if (convertToInteger(pVariant, &result, type, true, false) < 0) { + if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { + SET_EXT_INFO(converted, result, INT32_MIN + 1, INT32_MAX, extInfo); return -1; } *((int32_t *)payload) = (int32_t)result; @@ -672,7 +700,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_UINT: { - if (convertToInteger(pVariant, &result, type, false, false) < 0) { + if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { + SET_EXT_INFO(converted, result, 0, UINT32_MAX - 1, extInfo); return -1; } *((uint32_t *)payload) = (uint32_t)result; @@ -680,7 +709,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_BIGINT: { - if (convertToInteger(pVariant, &result, type, true, false) < 0) { + if (convertToInteger(pVariant, &result, type, true, false, converted) < 0) { + SET_EXT_INFO(converted, (int64_t)result, INT64_MIN + 1, INT64_MAX, extInfo); return -1; } *((int64_t *)payload) = (int64_t)result; @@ -688,7 +718,8 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu } case TSDB_DATA_TYPE_UBIGINT: { - if (convertToInteger(pVariant, &result, type, false, false) < 0) { + if (convertToInteger(pVariant, &result, type, false, false, converted) < 0) { + SET_EXT_INFO(converted, (uint64_t)result, 0, UINT64_MAX - 1, extInfo); return -1; } *((uint64_t *)payload) = (uint64_t)result; @@ -708,11 +739,37 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu return -1; } + if (converted) { + *converted = true; + } + + if (value > FLT_MAX || value < -FLT_MAX) { + SET_EXT_INFO(converted, value, -FLT_MAX, FLT_MAX, extInfo); + return -1; + } SET_FLOAT_VAL(payload, value); } } else if (pVariant->nType == TSDB_DATA_TYPE_BOOL || IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) { + if (converted) { + *converted = true; + } + + if (pVariant->i64 > FLT_MAX || pVariant->i64 < -FLT_MAX) { + SET_EXT_INFO(converted, pVariant->i64, -FLT_MAX, FLT_MAX, extInfo); + return -1; + } + SET_FLOAT_VAL(payload, pVariant->i64); } else if (IS_FLOAT_TYPE(pVariant->nType)) { + if (converted) { + *converted = true; + } + + if (pVariant->dKey > FLT_MAX || pVariant->dKey < -FLT_MAX) { + SET_EXT_INFO(converted, pVariant->dKey, -FLT_MAX, FLT_MAX, extInfo); + return -1; + } + SET_FLOAT_VAL(payload, pVariant->dKey); } else if (pVariant->nType == TSDB_DATA_TYPE_NULL) { *((uint32_t *)payload) = TSDB_DATA_FLOAT_NULL; @@ -836,6 +893,7 @@ int32_t tVariantDump(tVariant *pVariant, char *payload, int16_t type, bool inclu return 0; } + /* * In variant, bool/smallint/tinyint/int/bigint share the same attribution of * structure, also ignore the convert the type required @@ -860,7 +918,7 @@ int32_t tVariantTypeSetType(tVariant *pVariant, char type) { case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_SMALLINT: { - convertToInteger(pVariant, &(pVariant->i64), type, true, true); + convertToInteger(pVariant, &(pVariant->i64), type, true, true, NULL); pVariant->nType = TSDB_DATA_TYPE_BIGINT; break; } diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 75d6f0b745..acd6c703c9 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -30,6 +30,8 @@ extern "C" { #define FILTER_DEFAULT_VALUE_SIZE 4 #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 +#define FILTER_DUMMY_EMPTY_OPTR 127 + #define MAX_NUM_STR_SIZE 40 enum { @@ -214,12 +216,12 @@ typedef struct SFilterInfo { #define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) #define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR) -#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL) +#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL || (o) == FILTER_DUMMY_EMPTY_OPTR) #define MR_EMPTY_RES(ctx) (ctx->rs == NULL) -#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0) -#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0) +#define SET_AND_OPTR(ctx, o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { if (!(ctx)->isrange) { (ctx)->notnull = true; } } else if (o != FILTER_DUMMY_EMPTY_OPTR) { (ctx)->isrange = true; (ctx)->notnull = false; } } while (0) +#define SET_OR_OPTR(ctx,o) do {if (o == TSDB_RELATION_ISNULL) { (ctx)->isnull = true; } else if (o == TSDB_RELATION_NOTNULL) { (ctx)->notnull = true; (ctx)->isrange = false; } else if (o != FILTER_DUMMY_EMPTY_OPTR) { if (!(ctx)->notnull) { (ctx)->isrange = true; } } } while (0) #define CHK_OR_OPTR(ctx) ((ctx)->isnull == true && (ctx)->notnull == true) #define CHK_AND_OPTR(ctx) ((ctx)->isnull == true && (((ctx)->notnull == true) || ((ctx)->isrange == true))) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 1aa5ab8437..7b69b6fb06 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -236,7 +236,7 @@ int32_t filterAddRangeOptr(void* h, uint8_t raOptr, int32_t optr, bool *empty, b if (optr == TSDB_RELATION_AND) { SET_AND_OPTR(ctx, raOptr); - if (CHK_AND_OPTR(ctx)) { + if (CHK_AND_OPTR(ctx) || (raOptr == FILTER_DUMMY_EMPTY_OPTR)) { FILTER_SET_FLAG(ctx->status, MR_ST_EMPTY); *empty = true; } @@ -815,6 +815,214 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint16_t unitIdx) { return TSDB_CODE_SUCCESS; } +int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint32_t tType) { + SBufferReader br = tbufInitReader(buf, len, false); + uint32_t sType = tbufReadUint32(&br); + SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(tType), true, false); + int32_t code = 0; + + taosHashSetEqualFp(pObj, taosGetDefaultEqualFunction(tType)); + + int dummy = -1; + tVariant tmpVar = {0}; + size_t t = 0; + int32_t sz = tbufReadInt32(&br); + void *pvar = NULL; + int64_t val = 0; + int32_t bufLen = 0; + if (IS_NUMERIC_TYPE(sType)) { + bufLen = 60; // The maximum length of string that a number is converted to. + } else { + bufLen = 128; + } + + char *tmp = calloc(1, bufLen * TSDB_NCHAR_SIZE); + + for (int32_t i = 0; i < sz; i++) { + switch (sType) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: { + *(uint8_t *)&val = (uint8_t)tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_USMALLINT: + case TSDB_DATA_TYPE_SMALLINT: { + *(uint16_t *)&val = (uint16_t)tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_INT: { + *(uint32_t *)&val = (uint32_t)tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_BIGINT: { + *(uint64_t *)&val = (uint64_t)tbufReadInt64(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + *(double *)&val = tbufReadDouble(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_FLOAT: { + *(float *)&val = (float)tbufReadDouble(&br); + t = sizeof(val); + pvar = &val; + break; + } + case TSDB_DATA_TYPE_BINARY: { + pvar = (char *)tbufReadBinary(&br, &t); + break; + } + case TSDB_DATA_TYPE_NCHAR: { + pvar = (char *)tbufReadBinary(&br, &t); + break; + } + default: + taosHashCleanup(pObj); + *q = NULL; + assert(0); + } + + tVariantCreateFromBinary(&tmpVar, (char *)pvar, t, sType); + + if (bufLen < t) { + tmp = realloc(tmp, t * TSDB_NCHAR_SIZE); + bufLen = t; + } + + bool converted = false; + char extInfo = 0; + + switch (tType) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_UTINYINT: + case TSDB_DATA_TYPE_TINYINT: { + if (tVariantDumpEx(&tmpVar, (char *)&val, tType, false, &converted, &extInfo)) { + if (converted) { + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); + continue; + } + + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_USMALLINT: + case TSDB_DATA_TYPE_SMALLINT: { + if (tVariantDumpEx(&tmpVar, (char *)&val, tType, false, &converted, &extInfo)) { + if (converted) { + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); + continue; + } + + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_INT: { + if (tVariantDumpEx(&tmpVar, (char *)&val, tType, false, &converted, &extInfo)) { + if (converted) { + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); + continue; + } + + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_BIGINT: { + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_DOUBLE: { + if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_FLOAT: { + if (tVariantDumpEx(&tmpVar, (char *)&val, tType, false, &converted, &extInfo)) { + if (converted) { + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); + continue; + } + + goto _err_return; + } + pvar = &val; + t = sizeof(val); + break; + } + case TSDB_DATA_TYPE_BINARY: { + if (tVariantDump(&tmpVar, tmp, tType, true)) { + goto _err_return; + } + t = varDataLen(tmp); + pvar = varDataVal(tmp); + break; + } + case TSDB_DATA_TYPE_NCHAR: { + if (tVariantDump(&tmpVar, tmp, tType, true)) { + goto _err_return; + } + t = varDataLen(tmp); + pvar = varDataVal(tmp); + break; + } + default: + goto _err_return; + } + + taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy)); + tVariantDestroy(&tmpVar); + memset(&tmpVar, 0, sizeof(tmpVar)); + } + + CHK_JMP(taosHashGetSize(pObj) <= 0); + + *q = (void *)pObj; + pObj = NULL; + +_err_return: + tVariantDestroy(&tmpVar); + taosHashCleanup(pObj); + tfree(tmp); + + return code; +} + int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *group) { @@ -829,7 +1037,7 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g if (tree->_node.optr == TSDB_RELATION_IN && (!IS_VAR_DATA_TYPE(type))) { void *data = NULL; - convertFilterSetFromBinary((void **)&data, var->pz, var->nLen, type); + filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type); CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); void *p = taosHashIterate((SHashObj *)data, NULL); @@ -1100,7 +1308,7 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { return TSDB_CODE_SUCCESS; } - filterAddGroupUnitFromNode(info, tree, group); + code = filterAddGroupUnitFromNode(info, tree, group); _err_return: @@ -1156,7 +1364,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) int32_t type = FILTER_UNIT_DATA_TYPE(unit); int32_t len = 0; int32_t tlen = 0; - char str[128] = {0}; + char str[256] = {0}; SFilterField *left = FILTER_UNIT_LEFT_FIELD(info, unit); SSchema *sch = left->desc; @@ -1169,7 +1377,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) tlen = varDataLen(data); data += VARSTR_HEADER_SIZE; } - converToStr(str + len, type, data, tlen, &tlen); + converToStr(str + len, type, data, tlen > 32 ? 32 : tlen, &tlen); } else { strcat(str, "NULL"); } @@ -1341,6 +1549,28 @@ void filterFreeInfo(SFilterInfo *info) { } } +int32_t filterHandleValueExtInfo(SFilterUnit* unit, char extInfo) { + assert(extInfo > 0 || extInfo < 0); + + uint8_t optr = FILTER_UNIT_OPTR(unit); + switch (optr) { + case TSDB_RELATION_GREATER: + case TSDB_RELATION_GREATER_EQUAL: + unit->compare.optr = (extInfo > 0) ? FILTER_DUMMY_EMPTY_OPTR : TSDB_RELATION_NOTNULL; + break; + case TSDB_RELATION_LESS: + case TSDB_RELATION_LESS_EQUAL: + unit->compare.optr = (extInfo > 0) ? TSDB_RELATION_NOTNULL : FILTER_DUMMY_EMPTY_OPTR; + break; + case TSDB_RELATION_EQUAL: + unit->compare.optr = FILTER_DUMMY_EMPTY_OPTR; + break; + default: + assert(0); + } + + return TSDB_CODE_SUCCESS; +} int32_t filterInitValFieldData(SFilterInfo *info) { @@ -1366,7 +1596,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } if (unit->compare.optr == TSDB_RELATION_IN) { - convertFilterSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); + filterConvertSetFromBinary((void **)&fi->data, var->pz, var->nLen, type); CHK_LRET(fi->data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); FILTER_SET_FLAG(fi->flag, FLD_DATA_IS_HASH); @@ -1394,7 +1624,17 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } } - ERR_LRET(tVariantDump(var, (char*)fi->data, type, true), "dump type[%d] failed", type); + bool converted = false; + char extInfo = 0; + if (tVariantDumpEx(var, (char*)fi->data, type, true, &converted, &extInfo)) { + if (converted) { + filterHandleValueExtInfo(unit, extInfo); + + continue; + } + qError("dump value to type[%d] failed", type); + return TSDB_CODE_TSC_INVALID_OPERATION; + } } return TSDB_CODE_SUCCESS; @@ -1594,7 +1834,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t for (uint16_t l = 0; l < colIdxi; ++l) { int32_t type = gRes[gResIdx]->colInfo[colIdx[l]].dataType; - if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + if (FILTER_NO_MERGE_DATA_TYPE(type)) { continue; } @@ -1606,6 +1846,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t } if (empty) { + FILTER_SET_FLAG(info->status, FI_STATUS_REWRITE); filterFreeGroupCtx(gRes[gResIdx]); gRes[gResIdx] = NULL; diff --git a/tests/pytest/query/queryBetweenAnd.py b/tests/pytest/query/queryBetweenAnd.py index cd4320f523..3d038b3d2f 100644 --- a/tests/pytest/query/queryBetweenAnd.py +++ b/tests/pytest/query/queryBetweenAnd.py @@ -101,7 +101,7 @@ class TDTestCase: # tdSql.query(f"select * from t1 where c2 between {pow(10,38)*3.4} and {pow(10,38)*3.4+1}") # tdSql.checkRows(1) tdSql.query(f"select * from t2 where c2 between {-3.4*10**38-1} and {-3.4*10**38}") - tdSql.checkRows(0) + tdSql.checkRows(2) tdSql.error(f"select * from t2 where c2 between null and {-3.4*10**38}") # tdSql.checkRows(3) @@ -203,4 +203,4 @@ class TDTestCase: tdLog.success(f"{__file__} successfully executed") tdCases.addLinux(__file__, TDTestCase()) -tdCases.addWindows(__file__, TDTestCase()) \ No newline at end of file +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim index 25e29eeca7..78c98bbbd0 100644 --- a/tests/script/general/parser/condition_query.sim +++ b/tests/script/general/parser/condition_query.sim @@ -1816,6 +1816,59 @@ if $data20 != @21-05-05 18:19:28.000@ then return -1 endi +sql select * from stb1 where c1 between 60 and 9999999999; +if $rows != 4 then + return -1 +endi +if $data00 != @21-05-05 18:19:24.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:25.000@ then + return -1 +endi +if $data20 != @21-05-05 18:19:26.000@ then + return -1 +endi +if $data30 != @21-05-05 18:19:27.000@ then + return -1 +endi +sql select * from stb1 where c1 > 9999999999; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 < 9999999999; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c1 = 9999999999; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c1 <> 9999999999; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c4 < -9999999999; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c4 > -9999999999; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c4 = -9999999999; +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c4 <> -9999999999; +if $rows != 28 then + return -1 +endi +sql select * from stb1 where c5 in (-9999999999); +#sql select * from stb1 where c5 in (9999999999); +#sql select * from stb1 where c5 in (-9999999999,3,4,9999999999); + + sql select * from stb3 where c1 > 3 and c1 < 2; if $rows != 0 then return -1 @@ -1891,6 +1944,7 @@ if $rows != 14 then endi + print "ts test" sql_error select ts,c1,c7 from stb1 where ts != '2021-05-05 18:19:27' sql_error select ts,c1,c7 from stb1 where ts > '2021-05-05 18:19:03.000' or ts < '2021-05-05 18:19:02.000'; From 1d9c079d2317dfe3725972b2b3724afad5be60e4 Mon Sep 17 00:00:00 2001 From: wenzhouwww Date: Mon, 2 Aug 2021 15:47:41 +0800 Subject: [PATCH 043/100] this is a test case for date formate about TDengine --- tests/pytest/ZoneTimeTest.py | 174 +++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 tests/pytest/ZoneTimeTest.py diff --git a/tests/pytest/ZoneTimeTest.py b/tests/pytest/ZoneTimeTest.py new file mode 100644 index 0000000000..0e33f1887d --- /dev/null +++ b/tests/pytest/ZoneTimeTest.py @@ -0,0 +1,174 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import os +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import datetime + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def checkCommunity(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + if ("community" in selfPath): + return False + else: + return True + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosdump" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + + + def run(self): + + # clear envs + + tdSql.execute(" create database ZoneTime precision 'us' ") + tdSql.execute(" use ZoneTime ") + tdSql.execute(" create stable st (ts timestamp , id int , val float) tags (tag1 timestamp ,tag2 int) ") + + # standard case for Timestamp + + tdSql.execute(" insert into tb1 using st tags (\"2021-07-01 00:00:00.000\" , 2) values( \"2021-07-01 00:00:00.000\" , 1 , 1.0 ) ") + case1 = (tdSql.getResult("select * from tb1")) + print(case1) + if case1 == [(datetime.datetime(2021, 7, 1, 0, 0), 1, 1.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01 00:00:00.000' ") + + # RCF-3339 : it allows "T" is replaced by " " + + tdSql.execute(" insert into tb2 using st tags (\"2021-07-01T00:00:00.000+07:50\" , 2) values( \"2021-07-01T00:00:00.000+07:50\" , 2 , 2.0 ) ") + case2 = (tdSql.getResult("select * from tb2")) + print(case2) + if case2 == [(datetime.datetime(2021, 7, 1, 0, 10), 2, 2.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01T00:00:00.000+07:50'! ") + + tdSql.execute(" insert into tb3 using st tags (\"2021-07-01T00:00:00.000+08:00\" , 3) values( \"2021-07-01T00:00:00.000+08:00\" , 3 , 3.0 ) ") + case3 = (tdSql.getResult("select * from tb3")) + print(case3) + if case3 == [(datetime.datetime(2021, 7, 1, 0, 0), 3, 3.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01T00:00:00.000+08:00'! ") + + tdSql.execute(" insert into tb4 using st tags (\"2021-07-01T00:00:00.000Z\" , 4) values( \"2021-07-01T00:00:00.000Z\" , 4 , 4.0 ) ") + case4 = (tdSql.getResult("select * from tb4")) + print(case4) + if case4 == [(datetime.datetime(2021, 7, 1, 8, 0), 4, 4.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01T00:00:00.000Z'! ") + + tdSql.execute(" insert into tb5 using st tags (\"2021-07-01 00:00:00.000+07:50\" , 5) values( \"2021-07-01 00:00:00.000+07:50\" , 5 , 5.0 ) ") + case5 = (tdSql.getResult("select * from tb5")) + print(case5) + if case5 == [(datetime.datetime(2021, 7, 1, 0, 10), 5, 5.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01 00:00:00.000+08:00 ") + + tdSql.execute(" insert into tb6 using st tags (\"2021-07-01 00:00:00.000Z\" , 6) values( \"2021-07-01 00:00:00.000Z\" , 6 , 6.0 ) ") + case6 = (tdSql.getResult("select * from tb6")) + print(case6) + if case6 == [(datetime.datetime(2021, 7, 1, 8, 0), 6, 6.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01 00:00:00.000Z'! ") + + # ISO 8610 timestamp format , time days and hours must be split by "T" + + tdSql.execute(" insert into tb7 using st tags (\"2021-07-01T00:00:00.000+0800\" , 7) values( \"2021-07-01T00:00:00.000+0800\" , 7 , 7.0 ) ") + case7 = (tdSql.getResult("select * from tb7")) + print(case7) + if case7 == [(datetime.datetime(2021, 7, 1, 0, 0), 7, 7.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01T00:00:00.000+0800'! ") + + tdSql.execute(" insert into tb8 using st tags (\"2021-07-01T00:00:00.000+08\" , 8) values( \"2021-07-01T00:00:00.000+08\" , 8 , 8.0 ) ") + case8 = (tdSql.getResult("select * from tb8")) + print(case8) + if case8 == [(datetime.datetime(2021, 7, 1, 0, 0), 8, 8.0)]: + print ("check pass! ") + else: + print ("check failed about timestamp '2021-07-01T00:00:00.000+08'! ") + + # Non-standard case for Timestamp + + tdSql.execute(" insert into tb9 using st tags (\"2021-07-01 00:00:00.000+0800\" , 9) values( \"2021-07-01 00:00:00.000+0800\" , 9 , 9.0 ) ") + case9 = (tdSql.getResult("select * from tb9")) + print(case9) + + tdSql.execute(" insert into tb10 using st tags (\"2021-07-0100:00:00.000\" , 10) values( \"2021-07-0100:00:00.000\" , 10 , 10.0 ) ") + case10 = (tdSql.getResult("select * from tb10")) + print(case10) + + tdSql.execute(" insert into tb11 using st tags (\"2021-07-0100:00:00.000+0800\" , 11) values( \"2021-07-0100:00:00.000+0800\" , 11 , 11.0 ) ") + case11 = (tdSql.getResult("select * from tb11")) + print(case11) + + tdSql.execute(" insert into tb12 using st tags (\"2021-07-0100:00:00.000+08:00\" , 12) values( \"2021-07-0100:00:00.000+08:00\" , 12 , 12.0 ) ") + case12 = (tdSql.getResult("select * from tb12")) + print(case12) + + tdSql.execute(" insert into tb13 using st tags (\"2021-07-0100:00:00.000Z\" , 13) values( \"2021-07-0100:00:00.000Z\" , 13 , 13.0 ) ") + case13 = (tdSql.getResult("select * from tb13")) + print(case13) + + tdSql.execute(" insert into tb14 using st tags (\"2021-07-0100:00:00.000Z\" , 14) values( \"2021-07-0100:00:00.000Z\" , 14 , 14.0 ) ") + case14 = (tdSql.getResult("select * from tb14")) + print(case14) + + tdSql.execute(" insert into tb15 using st tags (\"2021-07-0100:00:00.000+08\" , 15) values( \"2021-07-0100:00:00.000+08\" , 15 , 15.0 ) ") + case15 = (tdSql.getResult("select * from tb15")) + print(case15) + + tdSql.execute(" insert into tb16 using st tags (\"2021-07-0100:00:00.000+07:50\" , 16) values( \"2021-07-0100:00:00.000+07:50\" , 16 , 16.0 ) ") + case16 = (tdSql.getResult("select * from tb16")) + print(case16) + + os.system("rm -rf *.py.sql") + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From 3ce28c06792e0473a9764d714d0dd415e5b3e404 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Mon, 2 Aug 2021 16:08:05 +0800 Subject: [PATCH 044/100] [TD-5505]: return error if there're additional illegal characters after timezeone str --- src/os/src/detail/osTime.c | 19 ++++++++++++++----- src/query/tests/unitTest.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 696867e586..9b5a86cbbb 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -72,12 +72,12 @@ int64_t user_mktime64(const unsigned int year0, const unsigned int mon0, // ==== mktime() kernel code =================// static int64_t m_deltaUtc = 0; -void deltaToUtcInitOnce() { +void deltaToUtcInitOnce() { struct tm tm = {0}; - + (void)strptime("1970-01-01 00:00:00", (const char *)("%Y-%m-%d %H:%M:%S"), &tm); m_deltaUtc = (int64_t)mktime(&tm); - //printf("====delta:%lld\n\n", seconds); + //printf("====delta:%lld\n\n", seconds); return; } @@ -90,7 +90,7 @@ static char* forwardToTimeStringEnd(char* str); static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { parseLocaltime, parseLocaltimeWithDst -}; +}; int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } @@ -194,6 +194,13 @@ int32_t parseTimezone(char* str, int64_t* tzOffset) { i += 2; } + //return error if there're illegal charaters after min(2 Digits) + char *minStr = &str[i]; + if (minStr[1] != '\0' && minStr[2] != '\0') { + return -1; + } + + int64_t minute = strnatoi(&str[i], 2); if (minute > 59) { return -1; @@ -252,7 +259,7 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del int64_t fraction = 0; str = forwardToTimeStringEnd(timestr); - if (str[0] == 'Z' || str[0] == 'z') { + if ((str[0] == 'Z' || str[0] == 'z') && str[1] == '\0') { /* utc time, no millisecond, return directly*/ *time = seconds * factor; } else if (str[0] == '.') { @@ -266,6 +273,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del char seg = str[0]; if (seg != 'Z' && seg != 'z' && seg != '+' && seg != '-') { return -1; + } else if ((seg == 'Z' || seg == 'z') && str[1] != '\0') { + return -1; } else if (seg == '+' || seg == '-') { // parse the timezone if (parseTimezone(str, &tzOffset) == -1) { diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index 51afca9532..e898992a40 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -462,6 +462,42 @@ TEST(testCase, parse_time) { char t23[] = "2017-12-31T9:0:0.1+13:1"; EXPECT_EQ(taosParseTime(t23, &time, strlen(t23), TSDB_TIME_PRECISION_MILLI, 0), 0); + + char t24[] = "2017-12-31T9:0:0.1+13:001"; + EXPECT_EQ(taosParseTime(t24, &time, strlen(t24), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t25[] = "2017-12-31T9:0:0.1+13:00abc"; + EXPECT_EQ(taosParseTime(t25, &time, strlen(t25), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t26[] = "2017-12-31T9:0:0.1+13001"; + EXPECT_EQ(taosParseTime(t26, &time, strlen(t26), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t27[] = "2017-12-31T9:0:0.1+1300abc"; + EXPECT_EQ(taosParseTime(t27, &time, strlen(t27), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t28[] = "2017-12-31T9:0:0Z+12:00"; + EXPECT_EQ(taosParseTime(t28, &time, strlen(t28), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t29[] = "2017-12-31T9:0:0.123Z+12:00"; + EXPECT_EQ(taosParseTime(t29, &time, strlen(t29), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t65[] = "2017-12-31 9:0:0.1+13:001"; + EXPECT_EQ(taosParseTime(t65, &time, strlen(t65), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t66[] = "2017-12-31 9:0:0.1+13:00abc"; + EXPECT_EQ(taosParseTime(t66, &time, strlen(t66), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t67[] = "2017-12-31 9:0:0.1+13001"; + EXPECT_EQ(taosParseTime(t67, &time, strlen(t67), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t68[] = "2017-12-31 9:0:0.1+1300abc"; + EXPECT_EQ(taosParseTime(t68, &time, strlen(t68), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t69[] = "2017-12-31 9:0:0Z+12:00"; + EXPECT_EQ(taosParseTime(t69, &time, strlen(t69), TSDB_TIME_PRECISION_MILLI, 0), -1); + + char t70[] = "2017-12-31 9:0:0.123Z+12:00"; + EXPECT_EQ(taosParseTime(t70, &time, strlen(t70), TSDB_TIME_PRECISION_MILLI, 0), -1); } TEST(testCase, tvariant_convert) { From 5bc82ffc3f96179921550c531b5290df5ce06413 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 2 Aug 2021 17:01:52 +0800 Subject: [PATCH 045/100] [TD-5578] the max length of like condition can be configured --- src/client/src/tscSQLParser.c | 2 +- src/common/inc/tglobal.h | 1 + src/common/src/tglobal.c | 13 +++++++++++++ src/util/inc/tcompare.h | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 819f1af4f0..c953b753a2 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4401,7 +4401,7 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t tSqlExpr* pRight = pExpr->pRight; if (pExpr->tokenId == TK_LIKE) { - if (pRight->value.nLen > TSDB_PATTERN_STRING_MAX_LEN) { + if (pRight->value.nLen > tsMaxLikeStringLen) { return invalidOperationMsg(msgBuf, msg1); } diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 7290db6ec9..544482fd14 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -70,6 +70,7 @@ extern int8_t tsKeepOriginalColumnName; // client extern int32_t tsMaxSQLStringLen; +extern int32_t tsMaxLikeStringLen; extern int8_t tsTscEnableRecordSql; extern int32_t tsMaxNumOfOrderedResults; extern int32_t tsMinSlidingTime; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index a58303e9fc..98d524179d 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -25,6 +25,7 @@ #include "tutil.h" #include "tlocale.h" #include "ttimezone.h" +#include "tcompare.h" // cluster char tsFirst[TSDB_EP_LEN] = {0}; @@ -75,6 +76,7 @@ int32_t tsCompressMsgSize = -1; // client int32_t tsMaxSQLStringLen = TSDB_MAX_ALLOWED_SQL_LEN; +int32_t tsMaxLikeStringLen = TSDB_PATTERN_STRING_MAX_LEN; int8_t tsTscEnableRecordSql = 0; // the maximum number of results for projection query on super table that are returned from @@ -984,6 +986,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_BYTE; taosInitConfigOption(cfg); + cfg.option = "maxLikeLength"; + cfg.ptr = &tsMaxLikeStringLen; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_BYTE; + taosInitConfigOption(cfg); + cfg.option = "maxNumOfOrderedRes"; cfg.ptr = &tsMaxNumOfOrderedResults; cfg.valType = TAOS_CFG_VTYPE_INT32; @@ -1531,6 +1543,7 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + assert(tsGlobalConfigNum <= TSDB_CFG_MAX_NUM); #ifdef TD_TSZ // lossy compress cfg.option = "lossyColumns"; diff --git a/src/util/inc/tcompare.h b/src/util/inc/tcompare.h index 612ce7ede0..fe46f00086 100644 --- a/src/util/inc/tcompare.h +++ b/src/util/inc/tcompare.h @@ -25,7 +25,7 @@ extern "C" { #define TSDB_PATTERN_MATCH 0 #define TSDB_PATTERN_NOMATCH 1 #define TSDB_PATTERN_NOWILDCARDMATCH 2 -#define TSDB_PATTERN_STRING_MAX_LEN 20 +#define TSDB_PATTERN_STRING_MAX_LEN 100 #define FLT_COMPAR_TOL_FACTOR 4 #define FLT_EQUAL(_x, _y) (fabs((_x) - (_y)) <= (FLT_COMPAR_TOL_FACTOR * FLT_EPSILON)) From 1c0cc17ea6d14e5006228741c4fe2a9415018236 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 2 Aug 2021 17:24:28 +0800 Subject: [PATCH 046/100] [TD-5578] the max length of like condition can be configured --- packaging/cfg/taos.cfg | 3 +++ src/client/inc/tscUtil.h | 1 - src/client/src/tscSQLParser.c | 6 ++++-- src/client/src/tscServer.c | 8 +++----- src/client/src/tscUtil.c | 15 --------------- src/inc/taosmsg.h | 2 +- src/query/src/qExecutor.c | 2 +- 7 files changed, 12 insertions(+), 25 deletions(-) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index bbe6eae419..0e28d8b43c 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -144,6 +144,9 @@ keepColumnName 1 # max length of an SQL # maxSQLLength 65480 +# max length of like +# maxLikeLength 100 + # the maximum number of records allowed for super table time sorting # maxNumOfOrderedRes 100000 diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 687d182bb6..a7c2862f51 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -344,7 +344,6 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta* pChild, const char* name, v STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); -int32_t tscGetTagFilterSerializeLen(SQueryInfo* pQueryInfo); int32_t tscGetColFilterSerializeLen(SQueryInfo* pQueryInfo); int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr); void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c953b753a2..8bab4225b8 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4394,7 +4394,7 @@ static int32_t validateNullExpr(tSqlExpr* pExpr, char* msgBuf) { // check for like expression static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t index, char* msgBuf) { - const char* msg1 = "wildcard string should be less than 20 characters"; + const char* msg1 = "wildcard string should be less than %d characters"; const char* msg2 = "illegal column name"; tSqlExpr* pLeft = pExpr->pLeft; @@ -4402,7 +4402,9 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t if (pExpr->tokenId == TK_LIKE) { if (pRight->value.nLen > tsMaxLikeStringLen) { - return invalidOperationMsg(msgBuf, msg1); + char tmp[64] = {0}; + sprintf(tmp, msg1, tsMaxLikeStringLen); + return invalidOperationMsg(msgBuf, tmp); } SSchema* pSchema = tscGetTableSchema(pTableMeta); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index c951f24ae9..fdb1be9f4e 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -678,8 +678,6 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { int32_t srcColListSize = (int32_t)(taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo)); int32_t srcColFilterSize = tscGetColFilterSerializeLen(pQueryInfo); - int32_t srcTagFilterSize = tscGetTagFilterSerializeLen(pQueryInfo); - size_t numOfExprs = tscNumOfExprs(pQueryInfo); int32_t exprSize = (int32_t)(sizeof(SSqlExpr) * numOfExprs * 2); @@ -700,8 +698,8 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { tableSerialize = totalTables * sizeof(STableIdInfo); } - return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize + - exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; + return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + exprSize + tsBufSize + + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; } static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, char *pMsg, @@ -1037,7 +1035,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->tagCondLen = htonl(pCond->len); + pQueryMsg->tagCondLen = htons(pCond->len); memcpy(pMsg, pCond->cond, pCond->len); pMsg += pCond->len; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 741b82e124..1736fa3259 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -4684,21 +4684,6 @@ int32_t tscGetColFilterSerializeLen(SQueryInfo* pQueryInfo) { return len; } -int32_t tscGetTagFilterSerializeLen(SQueryInfo* pQueryInfo) { - // serialize tag column query condition - if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0) { - STagCond* pTagCond = &pQueryInfo->tagCond; - - STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); - STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; - SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); - if (pCond != NULL && pCond->cond != NULL) { - return pCond->len; - } - } - return 0; -} - int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr) { memset(pQueryAttr, 0, sizeof(SQueryAttr)); diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 54ea17657a..fb5bbe6c2d 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -489,7 +489,7 @@ typedef struct { int16_t numOfCols; // the number of columns will be load from vnode SInterval interval; SSessionWindow sw; // session window - uint32_t tagCondLen; // tag length in current query + uint16_t tagCondLen; // tag length in current query uint32_t tbnameCondLen; // table name filter condition string length int16_t numOfGroupCols; // num of group by columns int16_t orderByIdx; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 36bfb1d442..3f6df2ec07 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6898,7 +6898,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols); pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput); pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols); - pQueryMsg->tagCondLen = htonl(pQueryMsg->tagCondLen); + pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen); pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset); pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen); pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks); From f4974fd827a7f9a170526b7773edd73efeb2e7af Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 3 Aug 2021 09:20:17 +0800 Subject: [PATCH 047/100] fix dump issue --- src/query/src/qFilter.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 7b69b6fb06..c64cf1e88b 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -1408,13 +1408,13 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) if (ctx->isrange) { SFilterRangeNode *r = ctx->rs; while (r) { - char str[128] = {0}; + char str[256] = {0}; int32_t tlen = 0; if (FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { strcat(str,"(NULL)"); } else { FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); - converToStr(str + strlen(str), ctx->type, &r->ra.s, tlen, &tlen); + converToStr(str + strlen(str), ctx->type, &r->ra.s, tlen > 32 ? 32 : tlen, &tlen); FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); } strcat(str, " - "); @@ -1422,7 +1422,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) strcat(str, "(NULL)"); } else { FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); - converToStr(str + strlen(str), ctx->type, &r->ra.e, tlen, &tlen); + converToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen); FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); } qDebug("range: %s", str); From 079e063b59720bd8cac9e366ae2aa544f6b319e8 Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 3 Aug 2021 10:51:20 +0800 Subject: [PATCH 048/100] add test case --- src/common/src/texpr.c | 2 +- src/query/inc/qFilter.h | 20 +-- src/query/src/qFilter.c | 163 ++++++++---------- src/query/tests/rangeMergeTest.cpp | 4 + .../script/general/parser/condition_query.sim | 20 ++- 5 files changed, 97 insertions(+), 112 deletions(-) diff --git a/src/common/src/texpr.c b/src/common/src/texpr.c index 8414314301..ebdb33fd5b 100644 --- a/src/common/src/texpr.c +++ b/src/common/src/texpr.c @@ -586,7 +586,7 @@ void convertFilterSetFromBinary(void **q, const char *buf, int32_t len, uint32_t if (bufLen < t) { tmp = realloc(tmp, t * TSDB_NCHAR_SIZE); - bufLen = t; + bufLen = (int32_t)t; } switch (tType) { diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index acd6c703c9..a46ec0efa3 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -51,14 +51,11 @@ enum { }; enum { - RA_EXCLUDE = 1, - RA_INCLUDE = 2, - RA_NULL = 4, + RANGE_FLG_EXCLUDE = 1, + RANGE_FLG_INCLUDE = 2, + RANGE_FLG_NULL = 4, }; -#define RA_EMPTY (RA_EXCLUDE|RA_INCLUDE) -#define RA_ALL (RA_EXCLUDE|RA_INCLUDE) - enum { FI_OPTION_NO_REWRITE = 1, FI_OPTION_TIMESTAMP = 2, @@ -232,7 +229,7 @@ typedef struct SFilterInfo { #define SIMPLE_COPY_VALUES(dst, src) *((int64_t *)dst) = *((int64_t *)src) #define FILTER_PACKAGE_UNIT_HASH_KEY(v, optr, idx1, idx2) do { char *_t = (char *)v; _t[0] = optr; *(uint16_t *)(_t + 1) = idx1; *(uint16_t *)(_t + 3) = idx2; } while (0) -#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RA_EXCLUDE) || FILTER_GET_FLAG(eflag,RA_EXCLUDE)))) +#define FILTER_GREATER(cr,sflag,eflag) ((cr > 0) || ((cr == 0) && (FILTER_GET_FLAG(sflag,RANGE_FLG_EXCLUDE) || FILTER_GET_FLAG(eflag,RANGE_FLG_EXCLUDE)))) #define FILTER_COPY_RA(dst, src) do { (dst)->sflag = (src)->sflag; (dst)->eflag = (src)->eflag; (dst)->s = (src)->s; (dst)->e = (src)->e; } while (0) #define RESET_RANGE(ctx, r) do { (r)->next = (ctx)->rf; (ctx)->rf = r; } while (0) @@ -243,11 +240,11 @@ typedef struct SFilterInfo { #define ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { return _code; } } while (0) #define ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); return _code; } } while (0) -#define ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _err_return; } } while (0) +#define ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { goto _return; } } while (0) #define CHK_RETV(c) do { if (c) { return; } } while (0) #define CHK_RET(c, r) do { if (c) { return r; } } while (0) -#define CHK_JMP(c) do { if (c) { goto _err_return; } } while (0) +#define CHK_JMP(c) do { if (c) { goto _return; } } while (0) #define CHK_LRETV(c,...) do { if (c) { qError(__VA_ARGS__); return; } } while (0) #define CHK_LRET(c, r,...) do { if (c) { qError(__VA_ARGS__); return r; } } while (0) @@ -291,15 +288,10 @@ typedef int32_t(*filter_desc_compare_func)(const void *, const void *); extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options); extern bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p); extern int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data); -extern void* filterInitRangeCtx(int32_t type, int32_t options); -extern int32_t filterGetRangeNum(void* h, int32_t* num); -extern int32_t filterGetRangeRes(void* h, SFilterRange *ra); -extern int32_t filterFreeRangeCtx(void* h); extern int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win); extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar); extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo); extern void filterFreeInfo(SFilterInfo *info); -extern bool filterIsEmptyRes(SFilterInfo *info); extern bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t numOfCols, int32_t numOfRows); #ifdef __cplusplus diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index c64cf1e88b..1a0eb9796a 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -83,31 +83,31 @@ bool filterRangeCompie (const void *minv, const void *maxv, const void *minr, co } rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { - if (FILTER_GET_FLAG(sflag, RA_NULL)) { - if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + if (FILTER_GET_FLAG(sflag, RANGE_FLG_NULL)) { + if (FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompLe; } return filterRangeCompLi; } - if (FILTER_GET_FLAG(eflag, RA_NULL)) { - if (FILTER_GET_FLAG(sflag, RA_EXCLUDE)) { + if (FILTER_GET_FLAG(eflag, RANGE_FLG_NULL)) { + if (FILTER_GET_FLAG(sflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompGe; } return filterRangeCompGi; } - if (FILTER_GET_FLAG(sflag, RA_EXCLUDE)) { - if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + if (FILTER_GET_FLAG(sflag, RANGE_FLG_EXCLUDE)) { + if (FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompee; } return filterRangeCompei; } - if (FILTER_GET_FLAG(eflag, RA_EXCLUDE)) { + if (FILTER_GET_FLAG(eflag, RANGE_FLG_EXCLUDE)) { return filterRangeCompie; } @@ -207,22 +207,22 @@ int32_t filterReuseRangeCtx(SFilterRangeCtx *ctx, int32_t type, int32_t options) int32_t filterConvertRange(SFilterRangeCtx *cur, SFilterRange *ra, bool *notNull) { - if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { int32_t sr = cur->pCompareFunc(&ra->s, getDataMin(cur->type)); if (sr == 0) { - FILTER_SET_FLAG(ra->sflag, RA_NULL); + FILTER_SET_FLAG(ra->sflag, RANGE_FLG_NULL); } } - if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { int32_t er = cur->pCompareFunc(&ra->e, getDataMax(cur->type)); if (er == 0) { - FILTER_SET_FLAG(ra->eflag, RA_NULL); + FILTER_SET_FLAG(ra->eflag, RANGE_FLG_NULL); } } - if (FILTER_GET_FLAG(ra->sflag, RA_NULL) && FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL) && FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { *notNull = true; } else { *notNull = false; @@ -396,12 +396,12 @@ int32_t filterAddRangeImpl(void* h, SFilterRange* ra, int32_t optr) { int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr) { SFilterRangeCtx *ctx = (SFilterRangeCtx *)h; - if (FILTER_GET_FLAG(ra->sflag, RA_NULL)) { + if (FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { SIMPLE_COPY_VALUES(&ra->s, getDataMin(ctx->type)); //FILTER_CLR_FLAG(ra->sflag, RA_NULL); } - if (FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + if (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { SIMPLE_COPY_VALUES(&ra->e, getDataMax(ctx->type)); //FILTER_CLR_FLAG(ra->eflag, RA_NULL); } @@ -597,8 +597,6 @@ int32_t filterFreeRangeCtx(void* h) { int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray* group) { SFilterGroup gp = {0}; - //TODO CHECK DUP - gp.unitNum = gp1->unitNum + gp2->unitNum; gp.unitIdxs = calloc(gp.unitNum, sizeof(*gp.unitIdxs)); memcpy(gp.unitIdxs, gp1->unitIdxs, gp1->unitNum * sizeof(*gp.unitIdxs)); @@ -781,7 +779,7 @@ int32_t filterAddUnit(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, SFi SFilterField *val = FILTER_UNIT_RIGHT_FIELD(info, u); assert(FILTER_GET_FLAG(val->flag, FLD_TYPE_VALUE)); } else { - assert(optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL); + assert(optr == TSDB_RELATION_ISNULL || optr == TSDB_RELATION_NOTNULL || optr == FILTER_DUMMY_EMPTY_OPTR); } SFilterField *col = FILTER_UNIT_LEFT_FIELD(info, u); @@ -917,7 +915,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 continue; } - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -932,7 +930,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 continue; } - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -947,7 +945,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 continue; } - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -957,7 +955,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 case TSDB_DATA_TYPE_UBIGINT: case TSDB_DATA_TYPE_BIGINT: { if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -965,7 +963,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 } case TSDB_DATA_TYPE_DOUBLE: { if (tVariantDump(&tmpVar, (char *)&val, tType, false)) { - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -979,7 +977,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 continue; } - goto _err_return; + goto _return; } pvar = &val; t = sizeof(val); @@ -987,7 +985,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 } case TSDB_DATA_TYPE_BINARY: { if (tVariantDump(&tmpVar, tmp, tType, true)) { - goto _err_return; + goto _return; } t = varDataLen(tmp); pvar = varDataVal(tmp); @@ -995,14 +993,14 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 } case TSDB_DATA_TYPE_NCHAR: { if (tVariantDump(&tmpVar, tmp, tType, true)) { - goto _err_return; + goto _return; } t = varDataLen(tmp); pvar = varDataVal(tmp); break; } default: - goto _err_return; + goto _return; } taosHashPut(pObj, (char *)pvar, t, &dummy, sizeof(dummy)); @@ -1010,12 +1008,10 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 memset(&tmpVar, 0, sizeof(tmpVar)); } - CHK_JMP(taosHashGetSize(pObj) <= 0); - *q = (void *)pObj; pObj = NULL; -_err_return: +_return: tVariantDestroy(&tmpVar); taosHashCleanup(pObj); tfree(tmp); @@ -1040,6 +1036,18 @@ int32_t filterAddGroupUnitFromNode(SFilterInfo *info, tExprNode* tree, SArray *g filterConvertSetFromBinary((void **)&data, var->pz, var->nLen, type); CHK_LRET(data == NULL, TSDB_CODE_QRY_APP_ERROR, "failed to convert in param"); + if (taosHashGetSize((SHashObj *)data) <= 0) { + filterAddUnit(info, FILTER_DUMMY_EMPTY_OPTR, &left, NULL, &uidx); + + SFilterGroup fgroup = {0}; + filterAddUnitToGroup(&fgroup, uidx); + + taosArrayPush(group, &fgroup); + taosHashCleanup(data); + + return TSDB_CODE_SUCCESS; + } + void *p = taosHashIterate((SHashObj *)data, NULL); while(p) { void *key = taosHashGetDataKey((SHashObj *)data, p); @@ -1155,9 +1163,9 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan SFilterRange *ra = &ctx->rs->ra; - assert(!((FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (FILTER_GET_FLAG(ra->eflag, RA_NULL)))); + assert(!((FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) && (FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)))); - if ((!FILTER_GET_FLAG(ra->sflag, RA_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RA_NULL))) { + if ((!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) && (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL))) { __compar_fn_t func = getComparFunc(type, 0); if (func(&ra->s, &ra->e) == 0) { void *data = malloc(sizeof(int64_t)); @@ -1169,19 +1177,19 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } } - if (!FILTER_GET_FLAG(ra->sflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } - if (!FILTER_GET_FLAG(ra->eflag, RA_NULL)) { + if (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &ra->e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1221,7 +1229,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan while (r) { memset(g, 0, sizeof(*g)); - if ((!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RA_NULL))) { + if ((!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) &&(!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL))) { __compar_fn_t func = getComparFunc(type, 0); if (func(&r->ra.s, &r->ra.e) == 0) { void *data = malloc(sizeof(int64_t)); @@ -1237,19 +1245,19 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } } - if (!FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { + if (!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.s); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } - if (!FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { + if (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { void *data = malloc(sizeof(int64_t)); SIMPLE_COPY_VALUES(data, &r->ra.e); filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); - filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); } @@ -1311,7 +1319,7 @@ int32_t filterTreeToGroup(tExprNode* tree, SFilterInfo *info, SArray* group) { code = filterAddGroupUnitFromNode(info, tree, group); -_err_return: +_return: taosArrayDestroyEx(leftGroup, filterFreeGroup); taosArrayDestroyEx(rightGroup, filterFreeGroup); @@ -1410,20 +1418,20 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) while (r) { char str[256] = {0}; int32_t tlen = 0; - if (FILTER_GET_FLAG(r->ra.sflag, RA_NULL)) { + if (FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { strcat(str,"(NULL)"); } else { - FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); converToStr(str + strlen(str), ctx->type, &r->ra.s, tlen > 32 ? 32 : tlen, &tlen); - FILTER_GET_FLAG(r->ra.sflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); } strcat(str, " - "); - if (FILTER_GET_FLAG(r->ra.eflag, RA_NULL)) { + if (FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { strcat(str, "(NULL)"); } else { - FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); + FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,"(") : strcat(str,"["); converToStr(str + strlen(str), ctx->type, &r->ra.e, tlen > 32 ? 32 : tlen, &tlen); - FILTER_GET_FLAG(r->ra.eflag, RA_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); + FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? strcat(str,")") : strcat(str,"]"); } qDebug("range: %s", str); @@ -1577,7 +1585,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; if (unit->right.type != FLD_TYPE_VALUE) { - assert(unit->compare.optr == TSDB_RELATION_ISNULL || unit->compare.optr == TSDB_RELATION_NOTNULL); + assert(unit->compare.optr == TSDB_RELATION_ISNULL || unit->compare.optr == TSDB_RELATION_NOTNULL || unit->compare.optr == FILTER_DUMMY_EMPTY_OPTR); continue; } @@ -1641,7 +1649,6 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } - bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { int32_t ret = unit->compare.pCompareFunc(left, right); @@ -1689,21 +1696,21 @@ int32_t filterAddUnitRange(SFilterInfo *info, SFilterUnit* u, SFilterRangeCtx *c switch (uoptr) { case TSDB_RELATION_GREATER: SIMPLE_COPY_VALUES(&ra.s, val); - FILTER_SET_FLAG(ra.sflag, RA_EXCLUDE); - FILTER_SET_FLAG(ra.eflag, RA_NULL); + FILTER_SET_FLAG(ra.sflag, RANGE_FLG_EXCLUDE); + FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL); break; case TSDB_RELATION_GREATER_EQUAL: SIMPLE_COPY_VALUES(&ra.s, val); - FILTER_SET_FLAG(ra.eflag, RA_NULL); + FILTER_SET_FLAG(ra.eflag, RANGE_FLG_NULL); break; case TSDB_RELATION_LESS: SIMPLE_COPY_VALUES(&ra.e, val); - FILTER_SET_FLAG(ra.eflag, RA_EXCLUDE); - FILTER_SET_FLAG(ra.sflag, RA_NULL); + FILTER_SET_FLAG(ra.eflag, RANGE_FLG_EXCLUDE); + FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL); break; case TSDB_RELATION_LESS_EQUAL: SIMPLE_COPY_VALUES(&ra.e, val); - FILTER_SET_FLAG(ra.sflag, RA_NULL); + FILTER_SET_FLAG(ra.sflag, RANGE_FLG_NULL); break; case TSDB_RELATION_NOT_EQUAL: assert(type == TSDB_DATA_TYPE_BOOL); @@ -1754,7 +1761,7 @@ int32_t filterCompareRangeCtx(SFilterRangeCtx *ctx1, SFilterRangeCtx *ctx2, bool return TSDB_CODE_SUCCESS; -_err_return: +_return: *equal = false; return TSDB_CODE_SUCCESS; } @@ -1785,14 +1792,13 @@ int32_t filterMergeUnits(SFilterInfo *info, SFilterGroupCtx* gRes, uint16_t colI return TSDB_CODE_SUCCESS; -_err_return: +_return: *empty = true; filterFreeRangeCtx(ctx); return TSDB_CODE_SUCCESS; - } @@ -2033,7 +2039,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx** gRes1, SFilter return TSDB_CODE_SUCCESS; -_err_return: +_return: if (colCtxs) { if (taosArrayGetSize(colCtxs) > 0) { @@ -2129,7 +2135,7 @@ int32_t filterMergeGroups(SFilterInfo *info, SFilterGroupCtx** gRes, int32_t *gR return TSDB_CODE_SUCCESS; -_err_return: +_return: FILTER_SET_FLAG(info->status, FI_STATUS_ALL); @@ -2303,7 +2309,7 @@ int32_t filterGenerateColRange(SFilterInfo *info, SFilterGroupCtx** gRes, int32_ } } -_err_return: +_return: tfree(idxNum); tfree(idxs); @@ -2492,7 +2498,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option return code; -_err_return: +_return: qInfo("No filter, code:%d", code); taosArrayDestroy(group); @@ -2667,7 +2673,7 @@ int32_t filterGetTimeRange(SFilterInfo *info, STimeWindow *win) { qDebug("qFilter time range:[%"PRId64 "]-[%"PRId64 "]", win->skey, win->ekey); return TSDB_CODE_SUCCESS; -_err_return: +_return: *win = TSWINDOW_DESC_INITIALIZER; @@ -2704,41 +2710,10 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar } } - -#if 0 - for (int32_t i = 0; i < numOfFilterCols; ++i) { - if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { - pFilterInfo[i].pData2 = pFilterInfo[i].pData; - pFilterInfo[i].pData = malloc(rows * pFilterInfo[i].info.bytes); - int32_t bufSize = pFilterInfo[i].info.bytes - VARSTR_HEADER_SIZE; - for (int32_t j = 0; j < rows; ++j) { - char* dst = (char *)pFilterInfo[i].pData + j * pFilterInfo[i].info.bytes; - char* src = (char *)pFilterInfo[i].pData2 + j * pFilterInfo[i].info.bytes; - int32_t len = 0; - taosMbsToUcs4(varDataVal(src), varDataLen(src), varDataVal(dst), bufSize, &len); - varDataLen(dst) = len; - } - *gotNchar = true; - } - } -#endif - return TSDB_CODE_SUCCESS; } int32_t filterFreeNcharColumns(SFilterInfo* info) { -#if 0 - for (int32_t i = 0; i < numOfFilterCols; ++i) { - if (pFilterInfo[i].info.type == TSDB_DATA_TYPE_NCHAR) { - if (pFilterInfo[i].pData2) { - tfree(pFilterInfo[i].pData); - pFilterInfo[i].pData = pFilterInfo[i].pData2; - pFilterInfo[i].pData2 = NULL; - } - } - } -#endif - for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; int32_t type = FILTER_GET_COL_FIELD_TYPE(fi); diff --git a/src/query/tests/rangeMergeTest.cpp b/src/query/tests/rangeMergeTest.cpp index bf6971b9dc..e65508a300 100644 --- a/src/query/tests/rangeMergeTest.cpp +++ b/src/query/tests/rangeMergeTest.cpp @@ -11,6 +11,10 @@ #pragma GCC diagnostic ignored "-Wunused-variable" extern "C" { + extern void* filterInitRangeCtx(int32_t type, int32_t options); + extern int32_t filterGetRangeNum(void* h, int32_t* num); + extern int32_t filterGetRangeRes(void* h, SFilterRange *ra); + extern int32_t filterFreeRangeCtx(void* h); extern int32_t filterAddRange(void* h, SFilterRange* ra, int32_t optr); } diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim index 78c98bbbd0..5ea707311a 100644 --- a/tests/script/general/parser/condition_query.sim +++ b/tests/script/general/parser/condition_query.sim @@ -1865,9 +1865,23 @@ if $rows != 28 then return -1 endi sql select * from stb1 where c5 in (-9999999999); -#sql select * from stb1 where c5 in (9999999999); -#sql select * from stb1 where c5 in (-9999999999,3,4,9999999999); - +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c5 in (9999999999); +if $rows != 0 then + return -1 +endi +sql select * from stb1 where c5 in (-9999999999,3,4,9999999999); +if $rows != 2 then + return -1 +endi +if $data00 != @21-05-05 18:19:02.000@ then + return -1 +endi +if $data10 != @21-05-05 18:19:03.000@ then + return -1 +endi sql select * from stb3 where c1 > 3 and c1 < 2; if $rows != 0 then From 9a64c0ee8fcbdd17ec0cd92401c01190f16f73f6 Mon Sep 17 00:00:00 2001 From: wpan Date: Tue, 3 Aug 2021 11:20:45 +0800 Subject: [PATCH 049/100] fix windows compile error --- src/query/inc/qFilter.h | 4 ++-- src/query/src/qFilter.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index a46ec0efa3..3e1109a730 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -253,9 +253,9 @@ typedef struct SFilterInfo { #define FILTER_GET_COL_FIELD_TYPE(fi) (((SSchema *)((fi)->desc))->type) #define FILTER_GET_COL_FIELD_SIZE(fi) (((SSchema *)((fi)->desc))->bytes) #define FILTER_GET_COL_FIELD_DESC(fi) ((SSchema *)((fi)->desc)) -#define FILTER_GET_COL_FIELD_DATA(fi, ri) ((fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) +#define FILTER_GET_COL_FIELD_DATA(fi, ri) ((char *)(fi)->data + ((SSchema *)((fi)->desc))->bytes * (ri)) #define FILTER_GET_VAL_FIELD_TYPE(fi) (((tVariant *)((fi)->desc))->nType) -#define FILTER_GET_VAL_FIELD_DATA(fi) ((fi)->data) +#define FILTER_GET_VAL_FIELD_DATA(fi) ((char *)(fi)->data) #define FILTER_GET_TYPE(fl) ((fl) & FLD_TYPE_MAX) #define FILTER_GROUP_UNIT(i, g, uid) ((i)->units + (g)->unitIdxs[uid]) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 1a0eb9796a..4bbc9eba15 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -898,7 +898,7 @@ int32_t filterConvertSetFromBinary(void **q, const char *buf, int32_t len, uint3 if (bufLen < t) { tmp = realloc(tmp, t * TSDB_NCHAR_SIZE); - bufLen = t; + bufLen = (int32_t)t; } bool converted = false; @@ -1623,7 +1623,7 @@ int32_t filterInitValFieldData(SFilterInfo *info) { fi->data = calloc(var->nLen, tDataTypes[type].bytes); for (int32_t a = 0; a < var->nLen; ++a) { int64_t *v = taosArrayGet(var->arr, a); - assignVal(fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); + assignVal((char *)fi->data + a * tDataTypes[type].bytes, (char *)v, 0, type); } continue; From 472dc1336580dfe8b35ffdb97139c26ad7b19c71 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 3 Aug 2021 16:34:39 +0800 Subject: [PATCH 050/100] [TD-5650] fix test case --- tests/pytest/functions/showOfflineThresholdIs864000.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/functions/showOfflineThresholdIs864000.py b/tests/pytest/functions/showOfflineThresholdIs864000.py index a7a1c2bf3f..57d0b1921b 100644 --- a/tests/pytest/functions/showOfflineThresholdIs864000.py +++ b/tests/pytest/functions/showOfflineThresholdIs864000.py @@ -25,7 +25,7 @@ class TDTestCase: def run(self): tdSql.query("show variables") - tdSql.checkData(53, 1, 864000) + tdSql.checkData(54, 1, 864000) def stop(self): tdSql.close() From 0b80e979adc5a5ad870e1acc234c53ba9f6080ec Mon Sep 17 00:00:00 2001 From: Jun Li Date: Tue, 3 Aug 2021 20:00:43 -0700 Subject: [PATCH 051/100] Fix dirname bug on MacOS --- src/tfs/src/tfs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index 9dc68dcdfd..61fbc61448 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -261,11 +261,20 @@ int tfsMkdirRecurAt(const char *rname, int level, int id) { // Try to create upper char *s = strdup(rname); - if (tfsMkdirRecurAt(dirname(s), level, id) < 0) { - tfree(s); + // Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms. + // Some platform may modify the contents of the string passed into dirname(). Others may return a pointer to + // internal static storage space that will be overwritten by next call. For case like that, we should not use + // the pointer directly in this recursion. + // See https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dirname.3.html + char *dir = strdup(dirname(s)); + + if (tfsMkdirRecurAt(dir, level, id) < 0) { + free(s); + free(dir); return -1; } - tfree(s); + free(s); + free(dir); if (tfsMkdirAt(rname, level, id) < 0) { return -1; From 13e6a9faf7a97298bbbd7dd916cd014e89c1cff3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Aug 2021 12:07:02 +0800 Subject: [PATCH 052/100] enhance --- src/client/inc/tscUtil.h | 2 +- src/client/src/tscSQLParser.c | 10 ++-------- src/client/src/tscServer.c | 10 ++++++---- src/client/src/tscUtil.c | 16 ++++++++-------- src/util/src/hash.c | 2 +- 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 577ce2a0fd..3e2556c0e7 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -340,7 +340,7 @@ STableMeta* createSuperTableMeta(STableMetaMsg* pChild); uint32_t tscGetTableMetaSize(STableMeta* pTableMeta); CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta); uint32_t tscGetTableMetaMaxSize(); -int32_t tscCreateTableMetaFromSTableMeta(STableMeta** pChild, const char* name, size_t *tableMetaCapacity); +int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta **ppStable); STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 90d0865258..7aa4d5d0bd 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8122,19 +8122,13 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { char name[TSDB_TABLE_FNAME_LEN] = {0}; - //if (!pSql->pBuf) { - // if (NULL == (pSql->pBuf = tcalloc(1, 80 * TSDB_MAX_COLUMNS))) { - // code = TSDB_CODE_TSC_OUT_OF_MEMORY; - // goto _end; - // } - //} - plist = taosArrayInit(4, POINTER_BYTES); pVgroupList = taosArrayInit(4, POINTER_BYTES); taosArraySort(tableNameList, tnameComparFn); taosArrayRemoveDuplicate(tableNameList, tnameComparFn, NULL); + STableMeta* pSTMeta = (STableMeta *)(pSql->pBuf); size_t numOfTables = taosArrayGetSize(tableNameList); for (int32_t i = 0; i < numOfTables; ++i) { SName* pname = taosArrayGet(tableNameList, i); @@ -8150,7 +8144,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { // avoid mem leak, may should update pTableMeta void* pVgroupIdList = NULL; if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity); + code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity, (STableMeta **)(&pSTMeta)); // create the child table meta from super table failed, try load it from mnode if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6773b00576..6b5094df89 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2844,18 +2844,20 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool tNameExtractFullName(&pTableMetaInfo->name, name); size_t len = strlen(name); + // just make runtime happy if (pTableMetaInfo->tableMetaCapacity != 0) { if (pTableMetaInfo->pTableMeta != NULL) { memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity); - } + } } taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity); - - STableMeta* pMeta = pTableMetaInfo->pTableMeta; + + STableMeta* pMeta = pTableMetaInfo->pTableMeta; + STableMeta* pSTMeta = (STableMeta *)(pSql->pBuf); if (pMeta && pMeta->id.uid > 0) { // in case of child table, here only get the if (pMeta->tableType == TSDB_CHILD_TABLE) { - int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity); + int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta)); if (code != TSDB_CODE_SUCCESS) { return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 8a2fafe3e3..48f061f789 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -4448,14 +4448,16 @@ CChildTableMeta* tscCreateChildMeta(STableMeta* pTableMeta) { return cMeta; } -int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity) { +int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, size_t *tableMetaCapacity, STableMeta**ppSTable) { assert(*ppChild != NULL); - - STableMeta* p = NULL; - size_t sz = 0; + STableMeta* p = *ppSTable; STableMeta* pChild = *ppChild; - - taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz); + size_t sz = (p != NULL) ? tscGetTableMetaSize(p) : 0; //ppSTableBuf actually capacity may larger than sz, dont care + if (p != NULL && sz != 0) { + memset((char *)p, 0, sz); + } + taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)ppSTable, &sz); + p = *ppSTable; // tableMeta exists, build child table meta according to the super table meta // the uid need to be checked in addition to the general name of the super table. @@ -4474,10 +4476,8 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, memcpy(pChild->schema, p->schema, totalBytes); *ppChild = pChild; - tfree(p); return TSDB_CODE_SUCCESS; } else { // super table has been removed, current tableMeta is also expired. remove it here - tfree(p); taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN)); return -1; } diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 6118aa7bef..e2ad447933 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -18,7 +18,7 @@ #include "tulog.h" #include "taosdef.h" -#define EXT_SIZE 1024 +#define EXT_SIZE 0 #define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR) From 1dc7859b620cd4a591a56d3f3a738867e32d7833 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Aug 2021 13:06:52 +0800 Subject: [PATCH 053/100] [TD-4199] enhance performance --- src/client/src/tscServer.c | 6 ++---- src/util/src/hash.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6b5094df89..326dc14ecb 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2845,10 +2845,8 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool size_t len = strlen(name); // just make runtime happy - if (pTableMetaInfo->tableMetaCapacity != 0) { - if (pTableMetaInfo->pTableMeta != NULL) { - memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity); - } + if (pTableMetaInfo->tableMetaCapacity != 0 && pTableMetaInfo->pTableMeta != NULL) { + memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity); } taosHashGetCloneExt(tscTableMetaMap, name, len, NULL, (void **)&(pTableMetaInfo->pTableMeta), &pTableMetaInfo->tableMetaCapacity); diff --git a/src/util/src/hash.c b/src/util/src/hash.c index e2ad447933..6118aa7bef 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -18,7 +18,7 @@ #include "tulog.h" #include "taosdef.h" -#define EXT_SIZE 0 +#define EXT_SIZE 1024 #define HASH_NEED_RESIZE(_h) ((_h)->size >= (_h)->capacity * HASH_DEFAULT_LOAD_FACTOR) From 6ed3b785e00abe17d6c5263584a79019f7a6bd0a Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Aug 2021 16:54:38 +0800 Subject: [PATCH 054/100] [TD-4199] enhance performance --- src/client/src/tscSQLParser.c | 1 + src/client/src/tscServer.c | 1 + src/client/src/tscUtil.c | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 7aa4d5d0bd..294cbbf51d 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -8145,6 +8145,7 @@ int32_t loadAllTableMeta(SSqlObj* pSql, struct SSqlInfo* pInfo) { void* pVgroupIdList = NULL; if (pTableMeta->tableType == TSDB_CHILD_TABLE) { code = tscCreateTableMetaFromSTableMeta((STableMeta **)(&pTableMeta), name, &tableMetaCapacity, (STableMeta **)(&pSTMeta)); + pSql->pBuf = (void *)pSTMeta; // create the child table meta from super table failed, try load it from mnode if (code != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 326dc14ecb..6f1d0baee8 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2856,6 +2856,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool // in case of child table, here only get the if (pMeta->tableType == TSDB_CHILD_TABLE) { int32_t code = tscCreateTableMetaFromSTableMeta(&pTableMetaInfo->pTableMeta, name, &pTableMetaInfo->tableMetaCapacity, (STableMeta **)(&pSTMeta)); + pSql->pBuf = (void *)(pSTMeta); if (code != TSDB_CODE_SUCCESS) { return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 48f061f789..611384f4a7 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -4456,8 +4456,8 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** ppChild, const char* name, if (p != NULL && sz != 0) { memset((char *)p, 0, sz); } - taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)ppSTable, &sz); - p = *ppSTable; + taosHashGetCloneExt(tscTableMetaMap, pChild->sTableName, strnlen(pChild->sTableName, TSDB_TABLE_FNAME_LEN), NULL, (void **)&p, &sz); + *ppSTable = p; // tableMeta exists, build child table meta according to the super table meta // the uid need to be checked in addition to the general name of the super table. From d60212302b784dd5d8f1aa7b2ccef55742e56175 Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 4 Aug 2021 18:04:32 +0800 Subject: [PATCH 055/100] improve performance --- src/query/inc/qFilter.h | 51 +++-- src/query/src/qFilter.c | 421 ++++++++++++++++++++++++++++++++-------- 2 files changed, 374 insertions(+), 98 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index 3e1109a730..ba65360624 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -31,6 +31,7 @@ extern "C" { #define FILTER_DEFAULT_GROUP_UNIT_SIZE 2 #define FILTER_DUMMY_EMPTY_OPTR 127 +#define FILTER_DUMMY_RANGE_OPTR 126 #define MAX_NUM_STR_SIZE 40 @@ -96,6 +97,8 @@ typedef struct SFilterColRange { } SFilterColRange; typedef bool (*rangeCompFunc) (const void *, const void *, const void *, const void *, __compar_fn_t); +typedef int32_t(*filter_desc_compare_func)(const void *, const void *); +typedef bool(*filter_exec_func)(void *, int32_t, int8_t*); typedef struct SFilterRangeCompare { int64_t s; @@ -178,36 +181,52 @@ typedef struct SFilterColCtx { } SFilterColCtx; typedef struct SFilterCompare { - __compar_fn_t pCompareFunc; int32_t type; uint8_t optr; + uint8_t optr2; } SFilterCompare; typedef struct SFilterUnit { SFilterCompare compare; SFilterFieldId left; SFilterFieldId right; + SFilterFieldId right2; } SFilterUnit; +typedef struct SFilterComUnit { + __compar_fn_t func; + rangeCompFunc rfunc; + void *colData; + void *valData; + void *valData2; + int32_t dataType; + uint16_t dataSize; + uint16_t optr; +} SFilterComUnit; + typedef struct SFilterPCtx { SHashObj *valHash; SHashObj *unitHash; } SFilterPCtx; typedef struct SFilterInfo { - uint32_t options; - uint32_t status; - uint16_t unitSize; - uint16_t unitNum; - uint16_t groupNum; - uint16_t colRangeNum; - SFilterFields fields[FLD_TYPE_MAX]; - SFilterGroup *groups; - SFilterUnit *units; - uint8_t *unitRes; // result - uint8_t *unitFlags; // got result + uint32_t options; + uint32_t status; + uint16_t unitSize; + uint16_t unitNum; + uint16_t groupNum; + uint16_t colRangeNum; + SFilterFields fields[FLD_TYPE_MAX]; + SFilterGroup *groups; + uint16_t *cgroups; + SFilterUnit *units; + SFilterComUnit *cunits; + uint8_t *unitRes; // result + uint8_t *unitFlags; // got result SFilterRangeCtx **colRange; - SFilterPCtx pctx; + filter_exec_func func; + + SFilterPCtx pctx; } SFilterInfo; #define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t)) @@ -264,9 +283,11 @@ typedef struct SFilterInfo { #define FILTER_UNIT_DATA_TYPE(u) ((u)->compare.type) #define FILTER_UNIT_COL_DESC(i, u) FILTER_GET_COL_FIELD_DESC(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_COL_DATA(i, u, ri) FILTER_GET_COL_FIELD_DATA(FILTER_UNIT_LEFT_FIELD(i, u), ri) +#define FILTER_UNIT_COL_SIZE(i, u) FILTER_GET_COL_FIELD_SIZE(FILTER_UNIT_LEFT_FIELD(i, u)) #define FILTER_UNIT_VAL_DATA(i, u) FILTER_GET_VAL_FIELD_DATA(FILTER_UNIT_RIGHT_FIELD(i, u)) #define FILTER_UNIT_COL_IDX(u) ((u)->left.idx) #define FILTER_UNIT_OPTR(u) ((u)->compare.optr) +#define FILTER_UNIT_COMP_FUNC(u) ((u)->compare.func) #define FILTER_UNIT_CLR_F(i) memset((i)->unitFlags, 0, (i)->unitNum * sizeof(*info->unitFlags)) #define FILTER_UNIT_SET_F(i, idx) (i)->unitFlags[idx] = 1 @@ -282,7 +303,9 @@ typedef struct SFilterInfo { #define FILTER_ADD_CTX_TO_GRES(gres, idx, ctx) do { if ((gres)->colCtxs == NULL) { (gres)->colCtxs = taosArrayInit(gres->colNum, sizeof(SFilterColCtx)); } SFilterColCtx cCtx = {idx, ctx}; taosArrayPush((gres)->colCtxs, &cCtx); } while (0) -typedef int32_t(*filter_desc_compare_func)(const void *, const void *); + +#define FILTER_ALL_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_ALL) +#define FILTER_EMPTY_RES(i) FILTER_GET_FLAG((i)->status, FI_STATUS_EMPTY) extern int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options); diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 4bbc9eba15..1625ff5aab 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -114,7 +114,40 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { return filterRangeCompii; } +rangeCompFunc filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { + if (optr2) { + assert(optr2 == TSDB_RELATION_LESS || optr2 == TSDB_RELATION_LESS_EQUAL); + if (optr == TSDB_RELATION_GREATER) { + if (optr2 == TSDB_RELATION_LESS) { + return filterRangeCompee; + } + + return filterRangeCompei; + } + + if (optr2 == TSDB_RELATION_LESS) { + return filterRangeCompie; + } + + return filterRangeCompii; + } else { + switch (optr) { + case TSDB_RELATION_GREATER: + return filterRangeCompGe; + case TSDB_RELATION_GREATER_EQUAL: + return filterRangeCompGi; + case TSDB_RELATION_LESS: + return filterRangeCompLe; + case TSDB_RELATION_LESS_EQUAL: + return filterRangeCompLi; + default: + break; + } + } + + return NULL; +} static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); @@ -123,7 +156,6 @@ static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void return 0; } - int32_t filterInitUnitsFields(SFilterInfo *info) { info->unitSize = FILTER_DEFAULT_UNIT_SIZE; info->units = calloc(info->unitSize, sizeof(SFilterUnit)); @@ -1128,9 +1160,18 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u return filterAddUnit(dst, FILTER_UNIT_OPTR(u), &left, pright, uidx); } +int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *right, uint16_t uidx) { + SFilterUnit *u = &info->units[uidx]; + + u->compare.optr2 = optr; + u->right2 = *right; + + return TSDB_CODE_SUCCESS; +} + int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint16_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { - SFilterFieldId left, right; + SFilterFieldId left, right, right2; uint16_t uidx = 0; SFilterField *col = FILTER_GET_COL_FIELD(src, cidx); @@ -1174,6 +1215,18 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); return TSDB_CODE_SUCCESS; + } else { + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &ra->s); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); + void *data2 = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data2, &ra->e); + filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); + + filterAddUnit(dst, FILTER_GET_FLAG(ra->sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnitRight(dst, FILTER_GET_FLAG(ra->eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &right2, uidx); + filterAddUnitToGroup(g, uidx); + return TSDB_CODE_SUCCESS; } } @@ -1237,12 +1290,24 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); filterAddUnit(dst, TSDB_RELATION_EQUAL, &left, &right, &uidx); filterAddUnitToGroup(g, uidx); + } else { + void *data = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data, &r->ra.s); + filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true); + void *data2 = malloc(sizeof(int64_t)); + SIMPLE_COPY_VALUES(data2, &r->ra.e); + filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true); - taosArrayPush(res, g); - - r = r->next; - continue; + filterAddUnit(dst, FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_GREATER : TSDB_RELATION_GREATER_EQUAL, &left, &right, &uidx); + filterAddUnitRight(dst, FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_EXCLUDE) ? TSDB_RELATION_LESS : TSDB_RELATION_LESS_EQUAL, &right2, uidx); + filterAddUnitToGroup(g, uidx); } + + taosArrayPush(res, g); + + r = r->next; + + continue; } if (!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { @@ -1330,7 +1395,8 @@ _return: int32_t filterInitUnitFunc(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; - unit->compare.pCompareFunc = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); + + info->cunits[i].func = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); } return TSDB_CODE_SUCCESS; @@ -1524,6 +1590,8 @@ void filterFreePCtx(SFilterPCtx *pctx) { void filterFreeInfo(SFilterInfo *info) { CHK_RETV(info == NULL); + tfree(info->cunits); + for (int32_t i = 0; i < FLD_TYPE_MAX; ++i) { for (uint16_t f = 0; f < info->fields[i].num; ++f) { filterFreeField(&info->fields[i].fields[f], i); @@ -1649,10 +1717,10 @@ int32_t filterInitValFieldData(SFilterInfo *info) { } -bool filterDoCompare(SFilterUnit *unit, void *left, void *right) { - int32_t ret = unit->compare.pCompareFunc(left, right); +bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right) { + int32_t ret = func(left, right); - switch (unit->compare.optr) { + switch (optr) { case TSDB_RELATION_EQUAL: { return ret == 0; } @@ -2330,6 +2398,241 @@ int32_t filterPostProcessRange(SFilterInfo *info) { } +int32_t filterGenerateComInfo(SFilterInfo *info) { + uint16_t n = 0; + + info->cunits = malloc(info->unitNum * sizeof(*info->cunits)); + + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit *unit = &info->units[i]; + + info->cunits[i].func = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); + info->cunits[i].rfunc = filterGetRangeCompFuncFromOptrs(unit->compare.optr, unit->compare.optr2); + info->cunits[i].optr = FILTER_UNIT_OPTR(unit); + info->cunits[i].colData = NULL; + + if (unit->right.type == FLD_TYPE_VALUE) { + info->cunits[i].valData = FILTER_UNIT_VAL_DATA(info, unit); + } else { + info->cunits[i].valData = NULL; + } + if (unit->right2.type == FLD_TYPE_VALUE) { + info->cunits[i].valData2 = FILTER_GET_VAL_FIELD_DATA(FILTER_GET_FIELD(info, unit->right2)); + } else { + info->cunits[i].valData2 = info->cunits[i].valData; + } + + info->cunits[i].dataSize = FILTER_UNIT_COL_SIZE(info, unit); + info->cunits[i].dataType = FILTER_UNIT_DATA_TYPE(unit); + } + + uint16_t cgroupNum = info->groupNum + 1; + + for (uint16_t i = 0; i < info->groupNum; ++i) { + cgroupNum += info->groups[i].unitNum; + } + + info->cgroups = malloc(cgroupNum * sizeof(*info->cgroups)); + + for (uint16_t i = 0; i < info->groupNum; ++i) { + info->cgroups[n++] = info->groups[i].unitNum; + + for (uint16_t m = 0; m < info->groups[i].unitNum; ++m) { + info->cgroups[n++] = info->groups[i].unitIdxs[m]; + } + } + + info->cgroups[n] = 0; + + return TSDB_CODE_SUCCESS; +} + +int32_t filterUpdateComUnits(SFilterInfo *info) { + for (uint16_t i = 0; i < info->unitNum; ++i) { + SFilterUnit *unit = &info->units[i]; + + info->cunits[i].colData = FILTER_UNIT_COL_DATA(info, unit, 0); + } + + return TSDB_CODE_SUCCESS; +} + + +static FORCE_INLINE bool filterExecuteImplAll(void *info, int32_t numOfRows, int8_t* p) { + return true; +} +static FORCE_INLINE bool filterExecuteImplEmpty(void *info, int32_t numOfRows, int8_t* p) { + return false; +} +static FORCE_INLINE bool filterExecuteImplIsNull(void *pinfo, int32_t numOfRows, int8_t* p) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + uint16_t uidx = info->groups[0].unitIdxs[0]; + void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + p[i] = isNull(colData, info->cunits[uidx].dataType); + if (p[i] == 0) { + all = false; + } + } + + return all; +} +static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows, int8_t* p) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + uint16_t uidx = info->groups[0].unitIdxs[0]; + void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + p[i] = !isNull(colData, info->cunits[uidx].dataType); + if (p[i] == 0) { + all = false; + } + } + + return all; +} + +bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t* p) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + uint16_t uidx = info->groups[0].unitIdxs[0]; + void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + if (isNull(colData, info->cunits[uidx].dataType)) { + all = false; + continue; + } + + p[i] = (*info->cunits[uidx].rfunc)(colData, colData, info->cunits[uidx].valData, info->cunits[uidx].valData2, info->cunits[uidx].func); + + if (p[i] == 0) { + all = false; + } + } + + return all; +} + +bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t* p) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + uint16_t uidx = info->groups[0].unitIdxs[0]; + void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + if (isNull(colData, info->cunits[uidx].dataType)) { + all = false; + continue; + } + + p[i] = filterDoCompare(info->cunits[uidx].func, info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + + if (p[i] == 0) { + all = false; + } + } + + return all; +} + + +bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t* p) { + SFilterInfo *info = (SFilterInfo *)pinfo; + bool all = true; + + for (int32_t i = 0; i < numOfRows; ++i) { + //FILTER_UNIT_CLR_F(info); + + for (uint32_t g = 0; g < info->groupNum; ++g) { + for (uint32_t u = 0; u < info->groups[g].unitNum; ++u) { + uint16_t uidx = info->groups[g].unitIdxs[u]; + void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + + //if (FILTER_UNIT_GET_F(info, uidx)) { + // p[i] = FILTER_UNIT_GET_R(info, uidx); + //} else { + uint8_t optr = info->cunits[uidx].optr; + + if (isNull(colData, info->cunits[uidx].dataType)) { + p[i] = optr == TSDB_RELATION_ISNULL ? true : false; + } else { + if (optr == TSDB_RELATION_NOTNULL) { + p[i] = 1; + } else if (optr == TSDB_RELATION_ISNULL) { + p[i] = 0; + } else if (info->cunits[uidx].rfunc) { + p[i] = (*info->cunits[uidx].rfunc)(colData, colData, info->cunits[uidx].valData, info->cunits[uidx].valData2, info->cunits[uidx].func); + } else { + p[i] = filterDoCompare(info->cunits[uidx].func, info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + } + + //FILTER_UNIT_SET_R(info, uidx, p[i]); + //FILTER_UNIT_SET_F(info, uidx); + } + + if (p[i] == 0) { + break; + } + } + + if (p[i]) { + break; + } + } + + if (p[i] == 0) { + all = false; + } + } + + return all; +} + +FORCE_INLINE bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { + return (*info->func)(info, numOfRows, p); +} + +int32_t filterSetExecFunc(SFilterInfo *info) { + if (FILTER_ALL_RES(info)) { + info->func = filterExecuteImplAll; + return TSDB_CODE_SUCCESS; + } + + if (FILTER_EMPTY_RES(info)) { + info->func = filterExecuteImplEmpty; + return TSDB_CODE_SUCCESS; + } + + if (info->unitNum > 1) { + info->func = filterExecuteImpl; + return TSDB_CODE_SUCCESS; + } + + if (info->units[0].compare.optr == TSDB_RELATION_ISNULL) { + info->func = filterExecuteImplIsNull; + return TSDB_CODE_SUCCESS; + } + + if (info->units[0].compare.optr == TSDB_RELATION_NOTNULL) { + info->func = filterExecuteImplNotNull; + return TSDB_CODE_SUCCESS; + } + + if (info->cunits[0].rfunc) { + info->func = filterExecuteImplRange; + return TSDB_CODE_SUCCESS; + } + + info->func = filterExecuteImplMisc; + return TSDB_CODE_SUCCESS; +} + + + int32_t filterPreprocess(SFilterInfo *info) { SFilterGroupCtx** gRes = calloc(info->groupNum, sizeof(SFilterGroupCtx *)); int32_t gResNum = 0; @@ -2357,8 +2660,12 @@ int32_t filterPreprocess(SFilterInfo *info) { filterRewrite(info, gRes, gResNum); + filterGenerateComInfo(info); + _return: + filterSetExecFunc(info); + for (int32_t i = 0; i < gResNum; ++i) { filterFreeGroupCtx(gRes[i]); } @@ -2368,86 +2675,30 @@ _return: return TSDB_CODE_SUCCESS; } - int32_t filterSetColFieldData(SFilterInfo *info, int16_t colId, void *data) { CHK_LRET(info == NULL, TSDB_CODE_QRY_APP_ERROR, "info NULL"); CHK_LRET(info->fields[FLD_TYPE_COLUMN].num <= 0, TSDB_CODE_QRY_APP_ERROR, "no column fileds"); + if (FILTER_ALL_RES(info) || FILTER_EMPTY_RES(info)) { + return TSDB_CODE_SUCCESS; + } + for (uint16_t i = 0; i < info->fields[FLD_TYPE_COLUMN].num; ++i) { SFilterField* fi = &info->fields[FLD_TYPE_COLUMN].fields[i]; SSchema* sch = fi->desc; if (sch->colId == colId) { fi->data = data; + break; } } + filterUpdateComUnits(info); + return TSDB_CODE_SUCCESS; } -bool filterExecute(SFilterInfo *info, int32_t numOfRows, int8_t* p) { - bool all = true; - - if (FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY)) { - return false; - } - - for (int32_t i = 0; i < numOfRows; ++i) { - FILTER_UNIT_CLR_F(info); - - p[i] = 0; - - for (uint16_t g = 0; g < info->groupNum; ++g) { - SFilterGroup* group = &info->groups[g]; - bool qualified = true; - - for (uint16_t u = 0; u < group->unitNum; ++u) { - uint16_t uidx = group->unitIdxs[u]; - uint8_t ures = 0; - - if (FILTER_UNIT_GET_F(info, uidx)) { - ures = FILTER_UNIT_GET_R(info, uidx); - } else { - SFilterUnit *unit = &info->units[uidx]; - - if (isNull(FILTER_UNIT_COL_DATA(info, unit, i), FILTER_UNIT_DATA_TYPE(unit))) { - ures = unit->compare.optr == TSDB_RELATION_ISNULL ? true : false; - } else { - if (unit->compare.optr == TSDB_RELATION_NOTNULL) { - ures = true; - } else if (unit->compare.optr == TSDB_RELATION_ISNULL) { - ures = false; - } else { - ures = filterDoCompare(unit, FILTER_UNIT_COL_DATA(info, unit, i), FILTER_UNIT_VAL_DATA(info, unit)); - } - } - - FILTER_UNIT_SET_R(info, uidx, ures); - FILTER_UNIT_SET_F(info, uidx); - } - - if (!ures) { - qualified = ures; - break; - } - } - - if (qualified) { - p[i] = 1; - break; - } - } - - if (p[i] != 1) { - all = false; - } - } - - return all; -} - - int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t options) { int32_t code = TSDB_CODE_SUCCESS; SFilterInfo *info = NULL; @@ -2485,9 +2736,9 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option taosArrayDestroy(group); return code; } - } - - ERR_JRET(filterInitUnitFunc(info)); + + ERR_JRET(filterInitUnitFunc(info)); + } info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); info->unitFlags = malloc(info->unitNum * sizeof(*info->unitFlags)); @@ -2510,19 +2761,17 @@ _return: return code; } -FORCE_INLINE bool filterIsEmptyRes(SFilterInfo *info) { - if (info == NULL) { - return false; - } - - return FILTER_GET_FLAG(info->status, FI_STATUS_EMPTY); -} + bool filterRangeExecute(SFilterInfo *info, SDataStatis *pDataStatis, int32_t numOfCols, int32_t numOfRows) { - if (filterIsEmptyRes(info)) { + if (FILTER_EMPTY_RES(info)) { return false; } + + if (FILTER_ALL_RES(info)) { + return true; + } bool ret = true; void *minVal, *maxVal; @@ -2710,6 +2959,10 @@ int32_t filterConverNcharColumns(SFilterInfo* info, int32_t rows, bool *gotNchar } } + if (*gotNchar) { + filterUpdateComUnits(info); + } + return TSDB_CODE_SUCCESS; } From 79a0050c636a48ac49e8a37ff2a15f71a45f7450 Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 4 Aug 2021 18:04:35 +0800 Subject: [PATCH 056/100] [TD-5784]: fixed potential memory leak bugs --- src/plugins/http/src/httpParser.c | 42 +++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/plugins/http/src/httpParser.c b/src/plugins/http/src/httpParser.c index ba88a2b9cd..02f21037b8 100644 --- a/src/plugins/http/src/httpParser.c +++ b/src/plugins/http/src/httpParser.c @@ -101,13 +101,17 @@ char *httpGetStatusDesc(int32_t statusCode) { } static void httpCleanupString(HttpString *str) { - free(str->str); - str->str = NULL; - str->pos = 0; - str->size = 0; + if (str->str) { + free(str->str); + str->str = NULL; + str->pos = 0; + str->size = 0; + } } static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) { + char *new_str = NULL; + if (str->size == 0) { str->pos = 0; str->size = len + 1; @@ -115,7 +119,16 @@ static int32_t httpAppendString(HttpString *str, const char *s, int32_t len) { } else if (str->pos + len + 1 >= str->size) { str->size += len; str->size *= 4; - str->str = realloc(str->str, str->size); + + new_str = realloc(str->str, str->size); + if (new_str == NULL && str->str) { + // if str->str was not NULL originally, + // the old allocated memory was left unchanged, + // see man 3 realloc + free(str->str); + } + + str->str = new_str; } else { } @@ -317,7 +330,7 @@ static int32_t httpOnParseHeaderField(HttpParser *parser, const char *key, const static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) { HttpContext *pContext = parser->pContext; - HttpString * buf = &parser->body; + HttpString *buf = &parser->body; if (parser->parseCode != TSDB_CODE_SUCCESS) return -1; if (buf->size <= 0) { @@ -326,6 +339,7 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) { } int32_t newSize = buf->pos + len + 1; + char *newStr = NULL; if (newSize >= buf->size) { if (buf->size >= HTTP_BUFFER_SIZE) { httpError("context:%p, fd:%d, failed parse body, exceeding buffer size %d", pContext, pContext->fd, buf->size); @@ -336,7 +350,12 @@ static int32_t httpOnBody(HttpParser *parser, const char *chunk, int32_t len) { newSize = MAX(newSize, HTTP_BUFFER_INIT); newSize *= 4; newSize = MIN(newSize, HTTP_BUFFER_SIZE); - buf->str = realloc(buf->str, newSize); + newStr = realloc(buf->str, newSize); + if (newStr == NULL && buf->str) { + free(buf->str); + } + + buf->str = newStr; buf->size = newSize; if (buf->str == NULL) { @@ -374,13 +393,20 @@ static HTTP_PARSER_STATE httpTopStack(HttpParser *parser) { static int32_t httpPushStack(HttpParser *parser, HTTP_PARSER_STATE state) { HttpStack *stack = &parser->stacks; + int8_t *newStacks = NULL; if (stack->size == 0) { stack->pos = 0; stack->size = 32; stack->stacks = malloc(stack->size * sizeof(int8_t)); } else if (stack->pos + 1 > stack->size) { stack->size *= 2; - stack->stacks = realloc(stack->stacks, stack->size * sizeof(int8_t)); + + newStacks = realloc(stack->stacks, stack->size * sizeof(int8_t)); + if (newStacks == NULL && stack->stacks) { + free(stack->stacks); + } + + stack->stacks = newStacks; } else { } From 349818c9b18ffb99f7253c43b5cd4cb927c95b25 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 4 Aug 2021 18:16:25 +0800 Subject: [PATCH 057/100] [TD-5578] the max length of wild cards can be configured --- packaging/cfg/taos.cfg | 4 ++-- src/client/src/tscSQLParser.c | 4 ++-- src/common/inc/tglobal.h | 2 +- src/common/src/tglobal.c | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 0e28d8b43c..3ae4e9941e 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -144,8 +144,8 @@ keepColumnName 1 # max length of an SQL # maxSQLLength 65480 -# max length of like -# maxLikeLength 100 +# max length of WildCards +# maxWildCardsLength 100 # the maximum number of records allowed for super table time sorting # maxNumOfOrderedRes 100000 diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 8bab4225b8..573e8b8782 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4401,9 +4401,9 @@ static int32_t validateLikeExpr(tSqlExpr* pExpr, STableMeta* pTableMeta, int32_t tSqlExpr* pRight = pExpr->pRight; if (pExpr->tokenId == TK_LIKE) { - if (pRight->value.nLen > tsMaxLikeStringLen) { + if (pRight->value.nLen > tsMaxWildCardsLen) { char tmp[64] = {0}; - sprintf(tmp, msg1, tsMaxLikeStringLen); + sprintf(tmp, msg1, tsMaxWildCardsLen); return invalidOperationMsg(msgBuf, tmp); } diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 544482fd14..25d1c90ec5 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -70,7 +70,7 @@ extern int8_t tsKeepOriginalColumnName; // client extern int32_t tsMaxSQLStringLen; -extern int32_t tsMaxLikeStringLen; +extern int32_t tsMaxWildCardsLen; extern int8_t tsTscEnableRecordSql; extern int32_t tsMaxNumOfOrderedResults; extern int32_t tsMinSlidingTime; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 98d524179d..3c904dc034 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -76,7 +76,7 @@ int32_t tsCompressMsgSize = -1; // client int32_t tsMaxSQLStringLen = TSDB_MAX_ALLOWED_SQL_LEN; -int32_t tsMaxLikeStringLen = TSDB_PATTERN_STRING_MAX_LEN; +int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_MAX_LEN; int8_t tsTscEnableRecordSql = 0; // the maximum number of results for projection query on super table that are returned from @@ -986,8 +986,8 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_BYTE; taosInitConfigOption(cfg); - cfg.option = "maxLikeLength"; - cfg.ptr = &tsMaxLikeStringLen; + cfg.option = "maxWildCardsLength"; + cfg.ptr = &tsMaxWildCardsLen; cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; From a0a50458176ad75dda276d245b066e690b9d9814 Mon Sep 17 00:00:00 2001 From: xywang Date: Wed, 4 Aug 2021 19:39:35 +0800 Subject: [PATCH 058/100] [TD-5784]: fixed potential memory leak bugs --- src/plugins/http/src/httpUtil.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index a8031d3fd8..27b95a4934 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -188,13 +188,17 @@ bool httpMallocMultiCmds(HttpContext *pContext, int32_t cmdSize, int32_t bufferS bool httpReMallocMultiCmdsSize(HttpContext *pContext, int32_t cmdSize) { HttpSqlCmds *multiCmds = pContext->multiCmds; - if (cmdSize > HTTP_MAX_CMD_SIZE) { + if (cmdSize <= 0 && cmdSize > HTTP_MAX_CMD_SIZE) { httpError("context:%p, fd:%d, user:%s, mulitcmd size:%d large then %d", pContext, pContext->fd, pContext->user, cmdSize, HTTP_MAX_CMD_SIZE); return false; } - multiCmds->cmds = (HttpSqlCmd *)realloc(multiCmds->cmds, (size_t)cmdSize * sizeof(HttpSqlCmd)); + HttpSqlCmd *new_cmds = (HttpSqlCmd *)realloc(multiCmds->cmds, (size_t)cmdSize * sizeof(HttpSqlCmd)); + if (new_cmds == NULL && multiCmds->cmds) { + free(multiCmds->cmds); + } + multiCmds->cmds = new_cmds; if (multiCmds->cmds == NULL) { httpError("context:%p, fd:%d, user:%s, malloc cmds:%d error", pContext, pContext->fd, pContext->user, cmdSize); return false; @@ -208,13 +212,17 @@ bool httpReMallocMultiCmdsSize(HttpContext *pContext, int32_t cmdSize) { bool httpReMallocMultiCmdsBuffer(HttpContext *pContext, int32_t bufferSize) { HttpSqlCmds *multiCmds = pContext->multiCmds; - if (bufferSize > HTTP_MAX_BUFFER_SIZE) { + if (bufferSize <= 0 || bufferSize > HTTP_MAX_BUFFER_SIZE) { httpError("context:%p, fd:%d, user:%s, mulitcmd buffer size:%d large then %d", pContext, pContext->fd, pContext->user, bufferSize, HTTP_MAX_BUFFER_SIZE); return false; } - multiCmds->buffer = (char *)realloc(multiCmds->buffer, (size_t)bufferSize); + char *new_buffer = (char *)realloc(multiCmds->buffer, (size_t)bufferSize); + if (new_buffer == NULL && multiCmds->buffer) { + free(multiCmds->buffer); + } + multiCmds->buffer = new_buffer; if (multiCmds->buffer == NULL) { httpError("context:%p, fd:%d, user:%s, malloc buffer:%d error", pContext, pContext->fd, pContext->user, bufferSize); return false; From 0f6be76c0ecaa4c9951462a801d1615c7dd699c4 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 4 Aug 2021 21:51:32 +0800 Subject: [PATCH 059/100] [TD-4199] enhance performance --- src/client/src/tscServer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 6f1d0baee8..5c9c89639a 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2844,7 +2844,7 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool tNameExtractFullName(&pTableMetaInfo->name, name); size_t len = strlen(name); - // just make runtime happy + // just make runtime happy if (pTableMetaInfo->tableMetaCapacity != 0 && pTableMetaInfo->pTableMeta != NULL) { memset(pTableMetaInfo->pTableMeta, 0, pTableMetaInfo->tableMetaCapacity); } From 3cfb2ea995c06f39d0e466a1dae01d5d3870d10d Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 4 Aug 2021 23:48:45 +0800 Subject: [PATCH 060/100] [TD-5505]: if there's no space or 'T' delimiter timezone will also be parsed --- src/os/src/detail/osTime.c | 23 +++++++++++++++-------- src/query/tests/unitTest.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 9b5a86cbbb..078b9c62d0 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -86,6 +86,7 @@ static int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, c static int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec); static int32_t parseLocaltimeWithDst(char* timestr, int64_t* time, int32_t timePrec); static char* forwardToTimeStringEnd(char* str); +static bool checkTzPresent(char *str, int32_t len); static int32_t (*parseLocaltimeFp[]) (char* timestr, int64_t* time, int32_t timePrec) = { parseLocaltime, @@ -96,19 +97,25 @@ int32_t taosGetTimestampSec() { return (int32_t)time(NULL); } int32_t taosParseTime(char* timestr, int64_t* time, int32_t len, int32_t timePrec, int8_t day_light) { /* parse datatime string in with tz */ - char *seg = forwardToTimeStringEnd(timestr); - int32_t seg_len = len - (int32_t)(seg - timestr); if (strnchr(timestr, 'T', len, false) != NULL) { return parseTimeWithTz(timestr, time, timePrec, 'T'); - } else if (strnchr(timestr, ' ', len, false) != NULL && - (strnchr(seg, 'Z', seg_len, false) != NULL || strnchr(seg, 'z', seg_len, false) != NULL || - strnchr(seg, '+', seg_len, false) != NULL || strnchr(seg, '-', seg_len, false) != NULL)) { - return parseTimeWithTz(timestr, time, timePrec, ' '); + } else if (checkTzPresent(timestr, len)) { + return parseTimeWithTz(timestr, time, timePrec, 0); } else { return (*parseLocaltimeFp[day_light])(timestr, time, timePrec); } } +bool checkTzPresent(char *str, int32_t len) { + char *seg = forwardToTimeStringEnd(str); + int32_t seg_len = len - (int32_t)(seg - str); + + return (strnchr(seg, 'Z', seg_len, false) != NULL || + strnchr(seg, 'z', seg_len, false) != NULL || + strnchr(seg, '+', seg_len, false) != NULL || + strnchr(seg, '-', seg_len, false) != NULL); +} + char* forwardToTimeStringEnd(char* str) { int32_t i = 0; int32_t numOfSep = 0; @@ -238,8 +245,8 @@ int32_t parseTimeWithTz(char* timestr, int64_t* time, int32_t timePrec, char del char* str; if (delim == 'T') { str = strptime(timestr, "%Y-%m-%dT%H:%M:%S", &tm); - } else if (delim == ' ') { - str = strptime(timestr, "%Y-%m-%d%n%H:%M:%S", &tm); + } else if (delim == 0) { + str = strptime(timestr, "%Y-%m-%d %H:%M:%S", &tm); } else { str = NULL; } diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index e898992a40..740a783ca0 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -434,6 +434,29 @@ TEST(testCase, parse_time) { taosParseTime(t64, &time1, strlen(t64), TSDB_TIME_PRECISION_MILLI, 0); EXPECT_EQ(time, time1); + // "%Y-%m-%d%H:%M:%S" format with TimeZone appendix is also treated as legal + // and TimeZone will be processed + char t80[] = "2017-4-51:1:2.980"; + char t81[] = "2017-4-52:1:2.98+9:00"; + taosParseTime(t80, &time, strlen(t80), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t81, &time1, strlen(t81), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t82[] = "2017-4-52:1:2.98+09:00"; + taosParseTime(t82, &time, strlen(t82), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t81, &time1, strlen(t81), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t83[] = "2017-4-52:1:2.98+0900"; + taosParseTime(t83, &time, strlen(t83), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t82, &time1, strlen(t82), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + + char t84[] = "2017-4-417:1:2.98Z"; + taosParseTime(t83, &time, strlen(t83), TSDB_TIME_PRECISION_MILLI, 0); + taosParseTime(t84, &time1, strlen(t84), TSDB_TIME_PRECISION_MILLI, 0); + EXPECT_EQ(time, time1); + //////////////////////////////////////////////////////////////////// // illegal timestamp format char t15[] = "2017-12-33 0:0:0"; @@ -498,6 +521,7 @@ TEST(testCase, parse_time) { char t70[] = "2017-12-31 9:0:0.123Z+12:00"; EXPECT_EQ(taosParseTime(t70, &time, strlen(t70), TSDB_TIME_PRECISION_MILLI, 0), -1); + } TEST(testCase, tvariant_convert) { From d86f582a25a8e7a0f6471672828314768a4cab8d Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 5 Aug 2021 08:52:36 +0800 Subject: [PATCH 061/100] improve performance --- src/query/src/qFilter.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index 1625ff5aab..d6e69bb480 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -2498,20 +2498,27 @@ static FORCE_INLINE bool filterExecuteImplNotNull(void *pinfo, int32_t numOfRows bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t* p) { SFilterInfo *info = (SFilterInfo *)pinfo; bool all = true; + uint16_t dataSize = info->cunits[0].dataSize; + char *colData = (char *)info->cunits[0].colData; + rangeCompFunc rfunc = info->cunits[0].rfunc; + void *valData = info->cunits[0].valData; + void *valData2 = info->cunits[0].valData2; + __compar_fn_t func = info->cunits[0].func; for (int32_t i = 0; i < numOfRows; ++i) { - uint16_t uidx = info->groups[0].unitIdxs[0]; - void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; - if (isNull(colData, info->cunits[uidx].dataType)) { + if (isNull(colData, info->cunits[0].dataType)) { all = false; + colData += dataSize; continue; } - p[i] = (*info->cunits[uidx].rfunc)(colData, colData, info->cunits[uidx].valData, info->cunits[uidx].valData2, info->cunits[uidx].func); + p[i] = (*rfunc)(colData, colData, valData, valData2, func); if (p[i] == 0) { all = false; } + + colData += dataSize; } return all; @@ -2548,26 +2555,28 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t* p) { //FILTER_UNIT_CLR_F(info); for (uint32_t g = 0; g < info->groupNum; ++g) { - for (uint32_t u = 0; u < info->groups[g].unitNum; ++u) { - uint16_t uidx = info->groups[g].unitIdxs[u]; - void *colData = (char *)info->cunits[uidx].colData + info->cunits[uidx].dataSize * i; + SFilterGroup *group = &info->groups[g]; + for (uint32_t u = 0; u < group->unitNum; ++u) { + uint16_t uidx = group->unitIdxs[u]; + SFilterComUnit *cunit = &info->cunits[uidx]; + void *colData = (char *)cunit->colData + cunit->dataSize * i; //if (FILTER_UNIT_GET_F(info, uidx)) { // p[i] = FILTER_UNIT_GET_R(info, uidx); //} else { - uint8_t optr = info->cunits[uidx].optr; + uint8_t optr = cunit->optr; - if (isNull(colData, info->cunits[uidx].dataType)) { + if (isNull(colData, cunit->dataType)) { p[i] = optr == TSDB_RELATION_ISNULL ? true : false; } else { if (optr == TSDB_RELATION_NOTNULL) { p[i] = 1; } else if (optr == TSDB_RELATION_ISNULL) { p[i] = 0; - } else if (info->cunits[uidx].rfunc) { - p[i] = (*info->cunits[uidx].rfunc)(colData, colData, info->cunits[uidx].valData, info->cunits[uidx].valData2, info->cunits[uidx].func); + } else if (cunit->rfunc) { + p[i] = (*cunit->rfunc)(colData, colData, cunit->valData, cunit->valData2, cunit->func); } else { - p[i] = filterDoCompare(info->cunits[uidx].func, info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + p[i] = filterDoCompare(cunit->func, cunit->optr, colData, cunit->valData); } //FILTER_UNIT_SET_R(info, uidx, p[i]); From 84d15a7e9765fd8d6e91769ccdc4636be719792a Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Wed, 4 Aug 2021 17:28:56 +0800 Subject: [PATCH 062/100] fix bug on show vnodes with dnode ep --- src/client/src/tscSQLParser.c | 24 +- src/inc/ttokendef.h | 250 +-- src/mnode/src/mnodeDnode.c | 6 +- src/query/inc/sql.y | 2 +- src/query/src/sql.c | 3095 +++++++++++++++++++++------------ tests/pytest/client/client.py | 15 +- 6 files changed, 2094 insertions(+), 1298 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 7adc0812ae..cf9ab51676 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -87,7 +87,6 @@ static uint8_t convertRelationalOperator(SStrToken *pToken); static int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelNodeList, bool isSTable, bool joinQuery, bool timeWindowQuery); -static bool validateIpAddress(const char* ip, size_t size); static bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo); static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool twQuery); @@ -3220,7 +3219,6 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { const char* msg1 = "invalid name"; const char* msg2 = "pattern filter string too long"; const char* msg3 = "database name too long"; - const char* msg4 = "invalid ip address"; const char* msg5 = "database name is empty"; const char* msg6 = "pattern string is empty"; @@ -3268,17 +3266,11 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } } else if (showType == TSDB_MGMT_TABLE_VNODES) { if (pShowInfo->prefix.type == 0) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "No specified ip of dnode"); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), "No specified dnode ep"); } - // show vnodes may be ip addr of dnode in payload - SStrToken* pDnodeIp = &pShowInfo->prefix; - if (pDnodeIp->n >= TSDB_IPv4ADDR_LEN) { // ip addr is too long - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3); - } - - if (!validateIpAddress(pDnodeIp->z, pDnodeIp->n)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg4); + if (pShowInfo->prefix.type == TK_STRING) { + pShowInfo->prefix.n = strdequote(pShowInfo->prefix.z); } } return TSDB_CODE_SUCCESS; @@ -3331,16 +3323,6 @@ static int32_t setCompactVnodeInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_SUCCESS; } -bool validateIpAddress(const char* ip, size_t size) { - char tmp[128] = {0}; // buffer to build null-terminated string - assert(size < 128); - - strncpy(tmp, ip, size); - - in_addr_t epAddr = taosInetAddr(tmp); - - return epAddr != INADDR_NONE; -} int32_t tscTansformFuncForSTableQuery(SQueryInfo* pQueryInfo) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); diff --git a/src/inc/ttokendef.h b/src/inc/ttokendef.h index e89fed6282..a97de15e93 100644 --- a/src/inc/ttokendef.h +++ b/src/inc/ttokendef.h @@ -75,131 +75,131 @@ #define TK_SCORES 57 #define TK_GRANTS 58 #define TK_VNODES 59 -#define TK_IPTOKEN 60 -#define TK_DOT 61 -#define TK_CREATE 62 -#define TK_TABLE 63 -#define TK_STABLE 64 -#define TK_DATABASE 65 -#define TK_TABLES 66 -#define TK_STABLES 67 -#define TK_VGROUPS 68 -#define TK_DROP 69 -#define TK_TOPIC 70 -#define TK_FUNCTION 71 -#define TK_DNODE 72 -#define TK_USER 73 -#define TK_ACCOUNT 74 -#define TK_USE 75 -#define TK_DESCRIBE 76 -#define TK_ALTER 77 -#define TK_PASS 78 -#define TK_PRIVILEGE 79 -#define TK_LOCAL 80 -#define TK_COMPACT 81 -#define TK_LP 82 -#define TK_RP 83 -#define TK_IF 84 -#define TK_EXISTS 85 -#define TK_AS 86 -#define TK_OUTPUTTYPE 87 -#define TK_AGGREGATE 88 -#define TK_BUFSIZE 89 -#define TK_PPS 90 -#define TK_TSERIES 91 -#define TK_DBS 92 -#define TK_STORAGE 93 -#define TK_QTIME 94 -#define TK_CONNS 95 -#define TK_STATE 96 -#define TK_COMMA 97 -#define TK_KEEP 98 -#define TK_CACHE 99 -#define TK_REPLICA 100 -#define TK_QUORUM 101 -#define TK_DAYS 102 -#define TK_MINROWS 103 -#define TK_MAXROWS 104 -#define TK_BLOCKS 105 -#define TK_CTIME 106 -#define TK_WAL 107 -#define TK_FSYNC 108 -#define TK_COMP 109 -#define TK_PRECISION 110 -#define TK_UPDATE 111 -#define TK_CACHELAST 112 -#define TK_PARTITIONS 113 -#define TK_UNSIGNED 114 -#define TK_TAGS 115 -#define TK_USING 116 -#define TK_NULL 117 -#define TK_NOW 118 -#define TK_SELECT 119 -#define TK_UNION 120 -#define TK_ALL 121 -#define TK_DISTINCT 122 -#define TK_FROM 123 -#define TK_VARIABLE 124 -#define TK_INTERVAL 125 -#define TK_SESSION 126 -#define TK_STATE_WINDOW 127 -#define TK_FILL 128 -#define TK_SLIDING 129 -#define TK_ORDER 130 -#define TK_BY 131 -#define TK_ASC 132 -#define TK_DESC 133 -#define TK_GROUP 134 -#define TK_HAVING 135 -#define TK_LIMIT 136 -#define TK_OFFSET 137 -#define TK_SLIMIT 138 -#define TK_SOFFSET 139 -#define TK_WHERE 140 -#define TK_RESET 141 -#define TK_QUERY 142 -#define TK_SYNCDB 143 -#define TK_ADD 144 -#define TK_COLUMN 145 -#define TK_MODIFY 146 -#define TK_TAG 147 -#define TK_CHANGE 148 -#define TK_SET 149 -#define TK_KILL 150 -#define TK_CONNECTION 151 -#define TK_STREAM 152 -#define TK_COLON 153 -#define TK_ABORT 154 -#define TK_AFTER 155 -#define TK_ATTACH 156 -#define TK_BEFORE 157 -#define TK_BEGIN 158 -#define TK_CASCADE 159 -#define TK_CLUSTER 160 -#define TK_CONFLICT 161 -#define TK_COPY 162 -#define TK_DEFERRED 163 -#define TK_DELIMITERS 164 -#define TK_DETACH 165 -#define TK_EACH 166 -#define TK_END 167 -#define TK_EXPLAIN 168 -#define TK_FAIL 169 -#define TK_FOR 170 -#define TK_IGNORE 171 -#define TK_IMMEDIATE 172 -#define TK_INITIALLY 173 -#define TK_INSTEAD 174 -#define TK_MATCH 175 -#define TK_KEY 176 -#define TK_OF 177 -#define TK_RAISE 178 -#define TK_REPLACE 179 -#define TK_RESTRICT 180 -#define TK_ROW 181 -#define TK_STATEMENT 182 -#define TK_TRIGGER 183 -#define TK_VIEW 184 +#define TK_DOT 60 +#define TK_CREATE 61 +#define TK_TABLE 62 +#define TK_STABLE 63 +#define TK_DATABASE 64 +#define TK_TABLES 65 +#define TK_STABLES 66 +#define TK_VGROUPS 67 +#define TK_DROP 68 +#define TK_TOPIC 69 +#define TK_FUNCTION 70 +#define TK_DNODE 71 +#define TK_USER 72 +#define TK_ACCOUNT 73 +#define TK_USE 74 +#define TK_DESCRIBE 75 +#define TK_ALTER 76 +#define TK_PASS 77 +#define TK_PRIVILEGE 78 +#define TK_LOCAL 79 +#define TK_COMPACT 80 +#define TK_LP 81 +#define TK_RP 82 +#define TK_IF 83 +#define TK_EXISTS 84 +#define TK_AS 85 +#define TK_OUTPUTTYPE 86 +#define TK_AGGREGATE 87 +#define TK_BUFSIZE 88 +#define TK_PPS 89 +#define TK_TSERIES 90 +#define TK_DBS 91 +#define TK_STORAGE 92 +#define TK_QTIME 93 +#define TK_CONNS 94 +#define TK_STATE 95 +#define TK_COMMA 96 +#define TK_KEEP 97 +#define TK_CACHE 98 +#define TK_REPLICA 99 +#define TK_QUORUM 100 +#define TK_DAYS 101 +#define TK_MINROWS 102 +#define TK_MAXROWS 103 +#define TK_BLOCKS 104 +#define TK_CTIME 105 +#define TK_WAL 106 +#define TK_FSYNC 107 +#define TK_COMP 108 +#define TK_PRECISION 109 +#define TK_UPDATE 110 +#define TK_CACHELAST 111 +#define TK_PARTITIONS 112 +#define TK_UNSIGNED 113 +#define TK_TAGS 114 +#define TK_USING 115 +#define TK_NULL 116 +#define TK_NOW 117 +#define TK_SELECT 118 +#define TK_UNION 119 +#define TK_ALL 120 +#define TK_DISTINCT 121 +#define TK_FROM 122 +#define TK_VARIABLE 123 +#define TK_INTERVAL 124 +#define TK_SESSION 125 +#define TK_STATE_WINDOW 126 +#define TK_FILL 127 +#define TK_SLIDING 128 +#define TK_ORDER 129 +#define TK_BY 130 +#define TK_ASC 131 +#define TK_DESC 132 +#define TK_GROUP 133 +#define TK_HAVING 134 +#define TK_LIMIT 135 +#define TK_OFFSET 136 +#define TK_SLIMIT 137 +#define TK_SOFFSET 138 +#define TK_WHERE 139 +#define TK_RESET 140 +#define TK_QUERY 141 +#define TK_SYNCDB 142 +#define TK_ADD 143 +#define TK_COLUMN 144 +#define TK_MODIFY 145 +#define TK_TAG 146 +#define TK_CHANGE 147 +#define TK_SET 148 +#define TK_KILL 149 +#define TK_CONNECTION 150 +#define TK_STREAM 151 +#define TK_COLON 152 +#define TK_ABORT 153 +#define TK_AFTER 154 +#define TK_ATTACH 155 +#define TK_BEFORE 156 +#define TK_BEGIN 157 +#define TK_CASCADE 158 +#define TK_CLUSTER 159 +#define TK_CONFLICT 160 +#define TK_COPY 161 +#define TK_DEFERRED 162 +#define TK_DELIMITERS 163 +#define TK_DETACH 164 +#define TK_EACH 165 +#define TK_END 166 +#define TK_EXPLAIN 167 +#define TK_FAIL 168 +#define TK_FOR 169 +#define TK_IGNORE 170 +#define TK_IMMEDIATE 171 +#define TK_INITIALLY 172 +#define TK_INSTEAD 173 +#define TK_MATCH 174 +#define TK_KEY 175 +#define TK_OF 176 +#define TK_RAISE 177 +#define TK_REPLACE 178 +#define TK_RESTRICT 179 +#define TK_ROW 180 +#define TK_STATEMENT 181 +#define TK_TRIGGER 182 +#define TK_VIEW 183 +#define TK_IPTOKEN 184 #define TK_SEMI 185 #define TK_NONE 186 #define TK_PREV 187 diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index 02cf1c782c..73be7ea045 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -1181,7 +1181,7 @@ static int32_t mnodeGetVnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pShow->bytes[cols] = 4; pSchema[cols].type = TSDB_DATA_TYPE_INT; - strcpy(pSchema[cols].name, "vnode"); + strcpy(pSchema[cols].name, "vgId"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -1243,8 +1243,10 @@ static int32_t mnodeRetrieveVnodes(SShowObj *pShow, char *data, int32_t rows, vo cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - strcpy(pWrite, syncRole[pVgid->role]); + STR_TO_VARSTR(pWrite, syncRole[pVgid->role]); cols++; + + numOfRows++; } } diff --git a/src/query/inc/sql.y b/src/query/inc/sql.y index 96f1e680f1..8b43e55693 100644 --- a/src/query/inc/sql.y +++ b/src/query/inc/sql.y @@ -80,7 +80,7 @@ cmd ::= SHOW SCORES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); cmd ::= SHOW GRANTS. { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); } cmd ::= SHOW VNODES. { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); } -cmd ::= SHOW VNODES IPTOKEN(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); } +cmd ::= SHOW VNODES ids(X). { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); } %type dbPrefix {SStrToken} diff --git a/src/query/src/sql.c b/src/query/src/sql.c index dc5123b7fb..09be4c0cf0 100644 --- a/src/query/src/sql.c +++ b/src/query/src/sql.c @@ -23,7 +23,9 @@ ** input grammar file: */ #include +#include /************ Begin %include sections from the grammar ************************/ +#line 23 "sql.y" #include #include @@ -36,6 +38,7 @@ #include "ttokendef.h" #include "tutil.h" #include "tvariant.h" +#line 42 "sql.c" /**************** End of %include directives **********************************/ /* These constants specify the various numeric values for terminal symbols ** in a format understandable to "makeheaders". This section is blank unless @@ -76,8 +79,10 @@ ** zero the stack is dynamically sized using realloc() ** ParseARG_SDECL A static variable declaration for the %extra_argument ** ParseARG_PDECL A parameter declaration for the %extra_argument +** ParseARG_PARAM Code to pass %extra_argument as a subroutine parameter ** ParseARG_STORE Code to store %extra_argument into yypParser ** ParseARG_FETCH Code to extract %extra_argument from yypParser +** ParseCTX_* As ParseARG_ except for %extra_context ** YYERRORSYMBOL is the code number of the error symbol. If not ** defined, then do no error processing. ** YYNSTATE the combined number of states. @@ -97,39 +102,46 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 277 +#define YYNOCODE 275 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SStrToken typedef union { int yyinit; ParseTOKENTYPE yy0; - TAOS_FIELD yy31; - int yy52; - SLimitVal yy126; - SWindowStateVal yy144; - SCreateTableSql* yy158; - SCreateDbInfo yy214; - SSessionWindowVal yy259; - tSqlExpr* yy370; - SRelationInfo* yy412; - SCreatedTableInfo yy432; - SSqlNode* yy464; - int64_t yy501; - tVariant yy506; - SIntervalVal yy520; - SArray* yy525; - SCreateAcctInfo yy547; + SSessionWindowVal yy39; + SCreateDbInfo yy42; + int yy43; + tSqlExpr* yy46; + SCreatedTableInfo yy96; + SArray* yy131; + TAOS_FIELD yy163; + SSqlNode* yy256; + SCreateTableSql* yy272; + SLimitVal yy284; + SCreateAcctInfo yy341; + int64_t yy459; + tVariant yy516; + SIntervalVal yy530; + SWindowStateVal yy538; + SRelationInfo* yy544; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 #endif #define ParseARG_SDECL SSqlInfo* pInfo; #define ParseARG_PDECL ,SSqlInfo* pInfo -#define ParseARG_FETCH SSqlInfo* pInfo = yypParser->pInfo -#define ParseARG_STORE yypParser->pInfo = pInfo +#define ParseARG_PARAM ,pInfo +#define ParseARG_FETCH SSqlInfo* pInfo=yypParser->pInfo; +#define ParseARG_STORE yypParser->pInfo=pInfo; +#define ParseCTX_SDECL +#define ParseCTX_PDECL +#define ParseCTX_PARAM +#define ParseCTX_FETCH +#define ParseCTX_STORE #define YYFALLBACK 1 #define YYNSTATE 362 #define YYNRULE 289 +#define YYNRULE_WITH_ACTION 289 #define YYNTOKEN 195 #define YY_MAX_SHIFT 361 #define YY_MIN_SHIFTREDUCE 567 @@ -140,6 +152,7 @@ typedef union { #define YY_MIN_REDUCE 859 #define YY_MAX_REDUCE 1147 /************* End control #defines *******************************************/ +#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) /* Define the yytestcase() macro to be a no-op if is not already defined ** otherwise. @@ -204,249 +217,249 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (753) +#define YY_ACTTAB_COUNT (754) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 206, 618, 245, 618, 618, 97, 244, 228, 359, 619, - /* 10 */ 1123, 619, 619, 56, 57, 152, 60, 61, 654, 1027, - /* 20 */ 248, 50, 1036, 59, 317, 64, 62, 65, 63, 984, - /* 30 */ 249, 982, 983, 55, 54, 231, 985, 53, 52, 51, - /* 40 */ 986, 1002, 987, 988, 53, 52, 51, 568, 569, 570, + /* 0 */ 207, 618, 246, 618, 618, 245, 360, 229, 160, 619, + /* 10 */ 1123, 619, 619, 56, 57, 1036, 60, 61, 857, 361, + /* 20 */ 249, 50, 618, 59, 318, 64, 62, 65, 63, 984, + /* 30 */ 619, 982, 983, 55, 54, 160, 985, 53, 52, 51, + /* 40 */ 986, 153, 987, 988, 356, 945, 654, 568, 569, 570, /* 50 */ 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, - /* 60 */ 581, 360, 206, 257, 229, 159, 206, 56, 57, 37, - /* 70 */ 60, 61, 1124, 174, 248, 50, 1124, 59, 317, 64, - /* 80 */ 62, 65, 63, 277, 276, 29, 79, 55, 54, 1033, - /* 90 */ 206, 53, 52, 51, 56, 57, 315, 60, 61, 234, - /* 100 */ 1124, 248, 50, 1014, 59, 317, 64, 62, 65, 63, - /* 110 */ 358, 357, 144, 230, 55, 54, 85, 1011, 53, 52, - /* 120 */ 51, 56, 58, 240, 60, 61, 347, 1014, 248, 50, - /* 130 */ 94, 59, 317, 64, 62, 65, 63, 794, 1073, 242, - /* 140 */ 289, 55, 54, 1014, 618, 53, 52, 51, 57, 23, - /* 150 */ 60, 61, 619, 44, 248, 50, 1000, 59, 317, 64, - /* 160 */ 62, 65, 63, 997, 998, 34, 1001, 55, 54, 857, - /* 170 */ 361, 53, 52, 51, 43, 313, 354, 353, 312, 311, - /* 180 */ 310, 352, 309, 308, 307, 351, 306, 350, 349, 976, - /* 190 */ 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, - /* 200 */ 974, 975, 977, 978, 60, 61, 24, 1008, 248, 50, - /* 210 */ 257, 59, 317, 64, 62, 65, 63, 1027, 122, 1027, - /* 220 */ 175, 55, 54, 37, 209, 53, 52, 51, 247, 809, - /* 230 */ 347, 215, 798, 232, 801, 270, 804, 135, 134, 214, - /* 240 */ 315, 247, 809, 322, 85, 798, 14, 801, 37, 804, - /* 250 */ 93, 159, 726, 241, 203, 723, 800, 724, 803, 725, - /* 260 */ 226, 227, 257, 16, 318, 15, 37, 238, 5, 40, - /* 270 */ 178, 1011, 1012, 226, 227, 177, 103, 108, 99, 107, - /* 280 */ 96, 44, 204, 253, 254, 210, 64, 62, 65, 63, - /* 290 */ 355, 945, 159, 302, 55, 54, 1010, 251, 53, 52, - /* 300 */ 51, 1013, 78, 269, 256, 77, 120, 114, 125, 66, - /* 310 */ 239, 702, 222, 124, 1011, 130, 133, 123, 37, 197, - /* 320 */ 195, 193, 66, 127, 1072, 37, 192, 139, 138, 137, - /* 330 */ 136, 799, 159, 802, 37, 43, 999, 354, 353, 337, - /* 340 */ 336, 37, 352, 262, 810, 805, 351, 37, 350, 349, - /* 350 */ 37, 806, 266, 265, 742, 55, 54, 810, 805, 53, - /* 360 */ 52, 51, 326, 291, 806, 90, 1011, 727, 728, 327, - /* 370 */ 37, 37, 252, 1011, 250, 807, 325, 324, 328, 258, - /* 380 */ 82, 255, 1011, 332, 331, 329, 150, 148, 147, 1011, - /* 390 */ 907, 333, 83, 917, 334, 1011, 908, 188, 1011, 271, - /* 400 */ 188, 739, 92, 188, 70, 91, 1, 176, 3, 189, - /* 410 */ 775, 776, 758, 38, 335, 339, 80, 273, 1011, 1011, - /* 420 */ 766, 767, 73, 712, 294, 33, 154, 9, 714, 273, - /* 430 */ 296, 713, 796, 830, 67, 26, 246, 38, 38, 746, - /* 440 */ 811, 319, 67, 76, 95, 67, 71, 25, 1120, 617, - /* 450 */ 808, 132, 131, 113, 25, 112, 1119, 6, 297, 18, - /* 460 */ 1118, 17, 74, 25, 731, 729, 732, 730, 797, 20, - /* 470 */ 1083, 19, 119, 224, 118, 701, 22, 225, 21, 207, - /* 480 */ 208, 211, 205, 212, 213, 217, 218, 219, 216, 202, - /* 490 */ 1143, 1082, 1135, 236, 267, 1079, 1078, 237, 338, 151, - /* 500 */ 1035, 1046, 47, 1065, 1043, 149, 1064, 1025, 1028, 1044, - /* 510 */ 274, 1048, 153, 170, 158, 1009, 278, 285, 171, 1007, - /* 520 */ 172, 233, 166, 280, 161, 757, 160, 173, 162, 922, - /* 530 */ 163, 299, 300, 301, 304, 305, 282, 292, 45, 290, - /* 540 */ 75, 200, 288, 813, 272, 41, 72, 49, 316, 164, - /* 550 */ 916, 323, 1142, 110, 1141, 1138, 286, 179, 330, 1134, - /* 560 */ 284, 116, 1133, 1130, 180, 281, 942, 42, 39, 46, - /* 570 */ 201, 904, 279, 126, 303, 902, 128, 129, 900, 899, - /* 580 */ 259, 191, 897, 896, 895, 894, 893, 892, 891, 194, - /* 590 */ 196, 888, 886, 884, 882, 198, 879, 199, 48, 81, - /* 600 */ 86, 348, 283, 1066, 121, 340, 341, 342, 343, 344, - /* 610 */ 223, 345, 346, 356, 855, 243, 298, 260, 261, 854, - /* 620 */ 263, 220, 221, 264, 853, 836, 104, 921, 920, 105, - /* 630 */ 835, 268, 273, 10, 293, 734, 275, 84, 30, 898, - /* 640 */ 890, 183, 182, 943, 187, 181, 184, 185, 2, 140, - /* 650 */ 186, 141, 142, 889, 4, 143, 980, 881, 87, 944, - /* 660 */ 759, 165, 167, 168, 169, 880, 155, 157, 768, 156, - /* 670 */ 235, 762, 88, 89, 990, 764, 287, 31, 11, 32, - /* 680 */ 12, 13, 27, 295, 28, 96, 98, 101, 35, 100, - /* 690 */ 632, 36, 102, 667, 665, 664, 663, 661, 660, 659, - /* 700 */ 656, 314, 622, 106, 7, 320, 812, 321, 8, 109, - /* 710 */ 814, 111, 68, 69, 115, 704, 703, 38, 117, 700, - /* 720 */ 648, 646, 638, 644, 640, 642, 636, 634, 670, 669, - /* 730 */ 668, 666, 662, 658, 657, 190, 620, 585, 583, 859, + /* 60 */ 581, 151, 207, 230, 907, 207, 56, 57, 1027, 60, + /* 70 */ 61, 189, 1124, 249, 50, 1124, 59, 318, 64, 62, + /* 80 */ 65, 63, 1072, 1033, 271, 79, 55, 54, 3, 190, + /* 90 */ 53, 52, 51, 56, 57, 250, 60, 61, 702, 1027, + /* 100 */ 249, 50, 29, 59, 318, 64, 62, 65, 63, 91, + /* 110 */ 278, 277, 37, 55, 54, 232, 94, 53, 52, 51, + /* 120 */ 235, 120, 114, 125, 1014, 241, 338, 337, 124, 1014, + /* 130 */ 130, 133, 123, 56, 58, 794, 60, 61, 127, 85, + /* 140 */ 249, 50, 92, 59, 318, 64, 62, 65, 63, 997, + /* 150 */ 998, 34, 1001, 55, 54, 207, 80, 53, 52, 51, + /* 160 */ 57, 1010, 60, 61, 316, 1124, 249, 50, 263, 59, + /* 170 */ 318, 64, 62, 65, 63, 37, 44, 267, 266, 55, + /* 180 */ 54, 348, 243, 53, 52, 51, 1014, 160, 43, 314, + /* 190 */ 355, 354, 313, 312, 311, 353, 310, 309, 308, 352, + /* 200 */ 307, 351, 350, 976, 964, 965, 966, 967, 968, 969, + /* 210 */ 970, 971, 972, 973, 974, 975, 977, 978, 60, 61, + /* 220 */ 231, 160, 249, 50, 1011, 59, 318, 64, 62, 65, + /* 230 */ 63, 1008, 1027, 24, 258, 55, 54, 1000, 97, 53, + /* 240 */ 52, 51, 252, 248, 809, 175, 1013, 798, 233, 801, + /* 250 */ 210, 804, 248, 809, 1143, 917, 798, 216, 801, 292, + /* 260 */ 804, 90, 189, 135, 134, 215, 258, 55, 54, 323, + /* 270 */ 85, 53, 52, 51, 1002, 227, 228, 176, 242, 319, + /* 280 */ 5, 40, 179, 258, 227, 228, 23, 178, 103, 108, + /* 290 */ 99, 107, 204, 726, 1012, 1073, 723, 290, 724, 908, + /* 300 */ 725, 64, 62, 65, 63, 303, 189, 44, 257, 55, + /* 310 */ 54, 37, 37, 53, 52, 51, 800, 253, 803, 251, + /* 320 */ 316, 326, 325, 66, 254, 255, 198, 196, 194, 270, + /* 330 */ 37, 77, 66, 193, 139, 138, 137, 136, 223, 742, + /* 340 */ 799, 43, 802, 355, 354, 37, 37, 37, 353, 53, + /* 350 */ 52, 51, 352, 37, 351, 350, 239, 240, 810, 805, + /* 360 */ 1011, 1011, 272, 78, 37, 806, 122, 810, 805, 37, + /* 370 */ 37, 359, 358, 144, 806, 327, 38, 14, 348, 1011, + /* 380 */ 82, 93, 70, 259, 739, 256, 320, 333, 332, 83, + /* 390 */ 328, 329, 330, 73, 1011, 1011, 1011, 999, 334, 150, + /* 400 */ 148, 147, 1011, 1, 177, 775, 776, 727, 728, 335, + /* 410 */ 9, 96, 796, 1011, 336, 340, 758, 274, 1011, 1011, + /* 420 */ 1083, 766, 767, 746, 71, 712, 274, 295, 714, 297, + /* 430 */ 155, 713, 33, 74, 807, 67, 26, 830, 811, 38, + /* 440 */ 247, 38, 67, 95, 76, 67, 617, 16, 797, 15, + /* 450 */ 205, 25, 25, 113, 18, 112, 17, 731, 808, 732, + /* 460 */ 25, 6, 729, 211, 730, 298, 20, 119, 19, 118, + /* 470 */ 22, 1120, 21, 132, 131, 1119, 701, 1118, 225, 226, + /* 480 */ 208, 209, 1135, 212, 206, 213, 214, 813, 218, 219, + /* 490 */ 220, 217, 203, 1082, 237, 1079, 1078, 238, 339, 47, + /* 500 */ 1028, 268, 152, 1065, 1064, 1035, 149, 275, 1009, 279, + /* 510 */ 1046, 1043, 1044, 1048, 154, 159, 286, 171, 172, 273, + /* 520 */ 234, 1007, 173, 162, 174, 922, 300, 301, 302, 305, + /* 530 */ 306, 757, 1025, 45, 281, 201, 161, 283, 41, 317, + /* 540 */ 75, 916, 293, 72, 49, 324, 164, 1142, 291, 110, + /* 550 */ 1141, 1138, 163, 289, 180, 331, 1134, 116, 1133, 1130, + /* 560 */ 287, 285, 181, 942, 42, 39, 46, 202, 282, 904, + /* 570 */ 126, 902, 128, 129, 900, 899, 260, 280, 192, 897, + /* 580 */ 896, 895, 894, 893, 892, 891, 195, 197, 888, 886, + /* 590 */ 884, 882, 199, 48, 879, 200, 875, 304, 349, 81, + /* 600 */ 86, 284, 1066, 121, 341, 342, 343, 344, 345, 346, + /* 610 */ 347, 357, 855, 262, 261, 854, 224, 244, 299, 264, + /* 620 */ 265, 853, 836, 221, 222, 835, 269, 294, 104, 921, + /* 630 */ 920, 274, 105, 10, 276, 87, 84, 898, 734, 140, + /* 640 */ 30, 156, 141, 184, 890, 183, 943, 182, 185, 187, + /* 650 */ 186, 142, 188, 2, 889, 759, 143, 881, 980, 165, + /* 660 */ 880, 166, 167, 944, 168, 169, 170, 4, 990, 768, + /* 670 */ 157, 158, 762, 88, 236, 764, 89, 288, 31, 11, + /* 680 */ 32, 12, 13, 27, 296, 28, 96, 101, 98, 35, + /* 690 */ 100, 632, 36, 667, 102, 665, 664, 663, 661, 660, + /* 700 */ 659, 656, 622, 315, 106, 7, 321, 812, 322, 8, + /* 710 */ 814, 109, 111, 68, 69, 38, 704, 703, 115, 700, + /* 720 */ 117, 648, 646, 638, 644, 640, 642, 636, 634, 670, + /* 730 */ 669, 668, 666, 662, 658, 657, 191, 620, 585, 859, /* 740 */ 858, 858, 858, 858, 858, 858, 858, 858, 858, 858, - /* 750 */ 858, 145, 146, + /* 750 */ 858, 858, 145, 146, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 265, 1, 205, 1, 1, 206, 205, 198, 199, 9, - /* 10 */ 275, 9, 9, 13, 14, 199, 16, 17, 5, 246, - /* 20 */ 20, 21, 199, 23, 24, 25, 26, 27, 28, 222, - /* 30 */ 205, 224, 225, 33, 34, 262, 229, 37, 38, 39, - /* 40 */ 233, 242, 235, 236, 37, 38, 39, 45, 46, 47, + /* 0 */ 264, 1, 204, 1, 1, 204, 197, 198, 197, 9, + /* 10 */ 274, 9, 9, 13, 14, 197, 16, 17, 195, 196, + /* 20 */ 20, 21, 1, 23, 24, 25, 26, 27, 28, 221, + /* 30 */ 9, 223, 224, 33, 34, 197, 228, 37, 38, 39, + /* 40 */ 232, 197, 234, 235, 219, 220, 5, 45, 46, 47, /* 50 */ 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, - /* 60 */ 58, 59, 265, 199, 62, 199, 265, 13, 14, 199, - /* 70 */ 16, 17, 275, 209, 20, 21, 275, 23, 24, 25, - /* 80 */ 26, 27, 28, 267, 268, 82, 86, 33, 34, 266, - /* 90 */ 265, 37, 38, 39, 13, 14, 84, 16, 17, 244, - /* 100 */ 275, 20, 21, 248, 23, 24, 25, 26, 27, 28, - /* 110 */ 66, 67, 68, 243, 33, 34, 82, 247, 37, 38, - /* 120 */ 39, 13, 14, 244, 16, 17, 90, 248, 20, 21, - /* 130 */ 206, 23, 24, 25, 26, 27, 28, 83, 272, 244, - /* 140 */ 274, 33, 34, 248, 1, 37, 38, 39, 14, 265, - /* 150 */ 16, 17, 9, 119, 20, 21, 0, 23, 24, 25, - /* 160 */ 26, 27, 28, 239, 240, 241, 242, 33, 34, 196, - /* 170 */ 197, 37, 38, 39, 98, 99, 100, 101, 102, 103, - /* 180 */ 104, 105, 106, 107, 108, 109, 110, 111, 112, 222, - /* 190 */ 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, - /* 200 */ 233, 234, 235, 236, 16, 17, 44, 199, 20, 21, - /* 210 */ 199, 23, 24, 25, 26, 27, 28, 246, 78, 246, - /* 220 */ 209, 33, 34, 199, 62, 37, 38, 39, 1, 2, - /* 230 */ 90, 69, 5, 262, 7, 262, 9, 75, 76, 77, - /* 240 */ 84, 1, 2, 81, 82, 5, 82, 7, 199, 9, - /* 250 */ 86, 199, 2, 245, 265, 5, 5, 7, 7, 9, - /* 260 */ 33, 34, 199, 145, 37, 147, 199, 243, 63, 64, - /* 270 */ 65, 247, 209, 33, 34, 70, 71, 72, 73, 74, - /* 280 */ 116, 119, 265, 33, 34, 265, 25, 26, 27, 28, - /* 290 */ 220, 221, 199, 88, 33, 34, 247, 69, 37, 38, - /* 300 */ 39, 248, 206, 141, 69, 143, 63, 64, 65, 82, - /* 310 */ 243, 5, 150, 70, 247, 72, 73, 74, 199, 63, - /* 320 */ 64, 65, 82, 80, 272, 199, 70, 71, 72, 73, - /* 330 */ 74, 5, 199, 7, 199, 98, 240, 100, 101, 33, - /* 340 */ 34, 199, 105, 142, 117, 118, 109, 199, 111, 112, - /* 350 */ 199, 124, 151, 152, 37, 33, 34, 117, 118, 37, - /* 360 */ 38, 39, 243, 270, 124, 272, 247, 117, 118, 243, - /* 370 */ 199, 199, 144, 247, 146, 124, 148, 149, 243, 144, - /* 380 */ 83, 146, 247, 148, 149, 243, 63, 64, 65, 247, - /* 390 */ 204, 243, 83, 204, 243, 247, 204, 211, 247, 83, - /* 400 */ 211, 97, 249, 211, 97, 272, 207, 208, 202, 203, - /* 410 */ 132, 133, 83, 97, 243, 243, 263, 120, 247, 247, - /* 420 */ 83, 83, 97, 83, 83, 82, 97, 123, 83, 120, - /* 430 */ 83, 83, 1, 83, 97, 97, 61, 97, 97, 122, - /* 440 */ 83, 15, 97, 82, 97, 97, 139, 97, 265, 83, - /* 450 */ 124, 78, 79, 145, 97, 147, 265, 82, 115, 145, - /* 460 */ 265, 147, 137, 97, 5, 5, 7, 7, 37, 145, - /* 470 */ 238, 147, 145, 265, 147, 114, 145, 265, 147, 265, - /* 480 */ 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, - /* 490 */ 248, 238, 248, 238, 199, 238, 238, 238, 238, 199, - /* 500 */ 199, 199, 264, 273, 199, 61, 273, 261, 246, 199, - /* 510 */ 246, 199, 199, 250, 199, 246, 269, 199, 199, 199, - /* 520 */ 199, 269, 254, 269, 259, 124, 260, 199, 258, 199, - /* 530 */ 257, 199, 199, 199, 199, 199, 269, 130, 199, 134, - /* 540 */ 136, 199, 128, 117, 200, 199, 138, 135, 199, 256, - /* 550 */ 199, 199, 199, 199, 199, 199, 127, 199, 199, 199, - /* 560 */ 126, 199, 199, 199, 199, 129, 199, 199, 199, 199, - /* 570 */ 199, 199, 125, 199, 89, 199, 199, 199, 199, 199, - /* 580 */ 199, 199, 199, 199, 199, 199, 199, 199, 199, 199, - /* 590 */ 199, 199, 199, 199, 199, 199, 199, 199, 140, 200, - /* 600 */ 200, 113, 200, 200, 96, 95, 51, 92, 94, 55, - /* 610 */ 200, 93, 91, 84, 5, 200, 200, 153, 5, 5, - /* 620 */ 153, 200, 200, 5, 5, 100, 206, 210, 210, 206, - /* 630 */ 99, 142, 120, 82, 115, 83, 97, 121, 82, 200, - /* 640 */ 200, 213, 217, 219, 212, 218, 216, 214, 207, 201, - /* 650 */ 215, 201, 201, 200, 202, 201, 237, 200, 97, 221, - /* 660 */ 83, 255, 253, 252, 251, 200, 82, 97, 83, 82, - /* 670 */ 1, 83, 82, 82, 237, 83, 82, 97, 131, 97, - /* 680 */ 131, 82, 82, 115, 82, 116, 78, 71, 87, 86, - /* 690 */ 5, 87, 86, 9, 5, 5, 5, 5, 5, 5, - /* 700 */ 5, 15, 85, 78, 82, 24, 83, 59, 82, 147, - /* 710 */ 117, 147, 16, 16, 147, 5, 5, 97, 147, 83, - /* 720 */ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - /* 730 */ 5, 5, 5, 5, 5, 97, 85, 61, 60, 0, - /* 740 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 750 */ 276, 21, 21, 276, 276, 276, 276, 276, 276, 276, - /* 760 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 770 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 780 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 790 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 800 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 810 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 820 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 830 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 840 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 850 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 860 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 870 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 880 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 890 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 900 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 910 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 920 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 930 */ 276, 276, 276, 276, 276, 276, 276, 276, 276, 276, - /* 940 */ 276, 276, 276, 276, 276, 276, 276, 276, + /* 60 */ 58, 59, 264, 61, 203, 264, 13, 14, 245, 16, + /* 70 */ 17, 210, 274, 20, 21, 274, 23, 24, 25, 26, + /* 80 */ 27, 28, 271, 265, 261, 85, 33, 34, 201, 202, + /* 90 */ 37, 38, 39, 13, 14, 204, 16, 17, 5, 245, + /* 100 */ 20, 21, 81, 23, 24, 25, 26, 27, 28, 271, + /* 110 */ 266, 267, 197, 33, 34, 261, 205, 37, 38, 39, + /* 120 */ 243, 62, 63, 64, 247, 243, 33, 34, 69, 247, + /* 130 */ 71, 72, 73, 13, 14, 82, 16, 17, 79, 81, + /* 140 */ 20, 21, 248, 23, 24, 25, 26, 27, 28, 238, + /* 150 */ 239, 240, 241, 33, 34, 264, 262, 37, 38, 39, + /* 160 */ 14, 246, 16, 17, 83, 274, 20, 21, 141, 23, + /* 170 */ 24, 25, 26, 27, 28, 197, 118, 150, 151, 33, + /* 180 */ 34, 89, 243, 37, 38, 39, 247, 197, 97, 98, + /* 190 */ 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, + /* 200 */ 109, 110, 111, 221, 222, 223, 224, 225, 226, 227, + /* 210 */ 228, 229, 230, 231, 232, 233, 234, 235, 16, 17, + /* 220 */ 242, 197, 20, 21, 246, 23, 24, 25, 26, 27, + /* 230 */ 28, 197, 245, 44, 197, 33, 34, 0, 205, 37, + /* 240 */ 38, 39, 68, 1, 2, 208, 247, 5, 261, 7, + /* 250 */ 61, 9, 1, 2, 247, 203, 5, 68, 7, 269, + /* 260 */ 9, 271, 210, 74, 75, 76, 197, 33, 34, 80, + /* 270 */ 81, 37, 38, 39, 241, 33, 34, 208, 244, 37, + /* 280 */ 62, 63, 64, 197, 33, 34, 264, 69, 70, 71, + /* 290 */ 72, 73, 264, 2, 208, 271, 5, 273, 7, 203, + /* 300 */ 9, 25, 26, 27, 28, 87, 210, 118, 68, 33, + /* 310 */ 34, 197, 197, 37, 38, 39, 5, 143, 7, 145, + /* 320 */ 83, 147, 148, 81, 33, 34, 62, 63, 64, 140, + /* 330 */ 197, 142, 81, 69, 70, 71, 72, 73, 149, 37, + /* 340 */ 5, 97, 7, 99, 100, 197, 197, 197, 104, 37, + /* 350 */ 38, 39, 108, 197, 110, 111, 242, 242, 116, 117, + /* 360 */ 246, 246, 82, 205, 197, 123, 77, 116, 117, 197, + /* 370 */ 197, 65, 66, 67, 123, 242, 96, 81, 89, 246, + /* 380 */ 82, 85, 96, 143, 96, 145, 15, 147, 148, 82, + /* 390 */ 242, 242, 242, 96, 246, 246, 246, 239, 242, 62, + /* 400 */ 63, 64, 246, 206, 207, 131, 132, 116, 117, 242, + /* 410 */ 122, 115, 1, 246, 242, 242, 82, 119, 246, 246, + /* 420 */ 237, 82, 82, 121, 138, 82, 119, 82, 82, 82, + /* 430 */ 96, 82, 81, 136, 123, 96, 96, 82, 82, 96, + /* 440 */ 60, 96, 96, 96, 81, 96, 82, 144, 37, 146, + /* 450 */ 264, 96, 96, 144, 144, 146, 146, 5, 123, 7, + /* 460 */ 96, 81, 5, 264, 7, 114, 144, 144, 146, 146, + /* 470 */ 144, 264, 146, 77, 78, 264, 113, 264, 264, 264, + /* 480 */ 264, 264, 247, 264, 264, 264, 264, 116, 264, 264, + /* 490 */ 264, 264, 264, 237, 237, 237, 237, 237, 237, 263, + /* 500 */ 245, 197, 197, 272, 272, 197, 60, 245, 245, 268, + /* 510 */ 197, 197, 197, 197, 197, 197, 197, 249, 197, 199, + /* 520 */ 268, 197, 197, 258, 197, 197, 197, 197, 197, 197, + /* 530 */ 197, 123, 260, 197, 268, 197, 259, 268, 197, 197, + /* 540 */ 135, 197, 129, 137, 134, 197, 256, 197, 133, 197, + /* 550 */ 197, 197, 257, 127, 197, 197, 197, 197, 197, 197, + /* 560 */ 126, 125, 197, 197, 197, 197, 197, 197, 128, 197, + /* 570 */ 197, 197, 197, 197, 197, 197, 197, 124, 197, 197, + /* 580 */ 197, 197, 197, 197, 197, 197, 197, 197, 197, 197, + /* 590 */ 197, 197, 197, 139, 197, 197, 197, 88, 112, 199, + /* 600 */ 199, 199, 199, 95, 94, 51, 91, 93, 55, 92, + /* 610 */ 90, 83, 5, 5, 152, 5, 199, 199, 199, 152, + /* 620 */ 5, 5, 99, 199, 199, 98, 141, 114, 205, 209, + /* 630 */ 209, 119, 205, 81, 96, 96, 120, 199, 82, 200, + /* 640 */ 81, 81, 200, 212, 199, 216, 218, 217, 215, 214, + /* 650 */ 213, 200, 211, 206, 199, 82, 200, 199, 236, 255, + /* 660 */ 199, 254, 253, 220, 252, 251, 250, 201, 236, 82, + /* 670 */ 81, 96, 82, 81, 1, 82, 81, 81, 96, 130, + /* 680 */ 96, 130, 81, 81, 114, 81, 115, 70, 77, 86, + /* 690 */ 85, 5, 86, 9, 85, 5, 5, 5, 5, 5, + /* 700 */ 5, 5, 84, 15, 77, 81, 24, 82, 59, 81, + /* 710 */ 116, 146, 146, 16, 16, 96, 5, 5, 146, 82, + /* 720 */ 146, 5, 5, 5, 5, 5, 5, 5, 5, 5, + /* 730 */ 5, 5, 5, 5, 5, 5, 96, 84, 60, 0, + /* 740 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 750 */ 275, 275, 21, 21, 275, 275, 275, 275, 275, 275, + /* 760 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 770 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 780 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 790 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 800 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 810 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 820 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 830 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 840 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 850 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 860 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 870 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 880 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 890 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 900 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 910 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 920 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 930 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, 275, + /* 940 */ 275, 275, 275, 275, 275, 275, 275, 275, 275, }; #define YY_SHIFT_COUNT (361) #define YY_SHIFT_MIN (0) #define YY_SHIFT_MAX (739) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 162, 76, 76, 237, 237, 12, 227, 240, 240, 3, - /* 10 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 20 */ 143, 143, 143, 0, 2, 240, 250, 250, 250, 34, - /* 30 */ 34, 143, 143, 143, 156, 143, 143, 143, 143, 140, - /* 40 */ 12, 36, 36, 13, 753, 753, 753, 240, 240, 240, - /* 50 */ 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, - /* 60 */ 240, 240, 240, 240, 240, 240, 240, 250, 250, 250, - /* 70 */ 306, 306, 306, 306, 306, 306, 306, 143, 143, 143, - /* 80 */ 317, 143, 143, 143, 34, 34, 143, 143, 143, 143, - /* 90 */ 278, 278, 304, 34, 143, 143, 143, 143, 143, 143, - /* 100 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 110 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 120 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 130 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 140 */ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143, - /* 150 */ 143, 444, 444, 444, 401, 401, 401, 401, 444, 444, - /* 160 */ 404, 408, 407, 412, 405, 414, 429, 434, 436, 447, - /* 170 */ 458, 444, 444, 444, 485, 485, 488, 12, 12, 444, - /* 180 */ 444, 508, 510, 555, 515, 514, 554, 518, 521, 488, - /* 190 */ 13, 444, 529, 529, 444, 529, 444, 529, 444, 444, - /* 200 */ 753, 753, 54, 81, 81, 108, 81, 134, 188, 205, - /* 210 */ 261, 261, 261, 261, 243, 256, 322, 322, 322, 322, - /* 220 */ 228, 235, 201, 164, 7, 7, 251, 326, 44, 323, - /* 230 */ 316, 297, 309, 329, 337, 338, 307, 325, 340, 341, - /* 240 */ 345, 347, 348, 343, 350, 357, 431, 375, 426, 366, - /* 250 */ 118, 308, 314, 459, 460, 324, 327, 361, 331, 373, - /* 260 */ 609, 464, 613, 614, 467, 618, 619, 525, 531, 489, - /* 270 */ 512, 519, 551, 516, 552, 556, 539, 561, 577, 584, - /* 280 */ 585, 587, 588, 570, 590, 592, 591, 669, 594, 580, - /* 290 */ 547, 582, 549, 599, 519, 600, 568, 602, 569, 608, - /* 300 */ 601, 603, 616, 685, 604, 606, 684, 689, 690, 691, - /* 310 */ 692, 693, 694, 695, 617, 686, 625, 622, 623, 593, - /* 320 */ 626, 681, 648, 696, 562, 564, 620, 620, 620, 620, - /* 330 */ 697, 567, 571, 620, 620, 620, 710, 711, 636, 620, - /* 340 */ 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, - /* 350 */ 725, 726, 727, 728, 729, 638, 651, 730, 731, 676, + /* 0 */ 189, 91, 91, 244, 244, 81, 242, 251, 251, 21, + /* 10 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 20 */ 3, 3, 3, 0, 2, 251, 291, 291, 291, 58, + /* 30 */ 58, 3, 3, 3, 237, 3, 3, 3, 3, 289, + /* 40 */ 81, 92, 92, 41, 754, 754, 754, 251, 251, 251, + /* 50 */ 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, + /* 60 */ 251, 251, 251, 251, 251, 251, 251, 291, 291, 291, + /* 70 */ 93, 93, 93, 93, 93, 93, 93, 3, 3, 3, + /* 80 */ 302, 3, 3, 3, 58, 58, 3, 3, 3, 3, + /* 90 */ 274, 274, 288, 58, 3, 3, 3, 3, 3, 3, + /* 100 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 110 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 120 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 130 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 140 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + /* 150 */ 3, 3, 446, 446, 446, 408, 408, 408, 408, 446, + /* 160 */ 446, 405, 406, 413, 410, 415, 426, 434, 436, 440, + /* 170 */ 453, 454, 446, 446, 446, 509, 509, 486, 81, 81, + /* 180 */ 446, 446, 508, 510, 554, 515, 514, 553, 517, 520, + /* 190 */ 486, 41, 446, 528, 528, 446, 528, 446, 528, 446, + /* 200 */ 446, 754, 754, 53, 80, 80, 120, 80, 146, 202, + /* 210 */ 218, 276, 276, 276, 276, 59, 264, 234, 234, 234, + /* 220 */ 234, 174, 240, 27, 296, 312, 312, 311, 335, 306, + /* 230 */ 337, 280, 298, 307, 334, 339, 340, 286, 297, 343, + /* 240 */ 345, 346, 347, 349, 351, 355, 356, 411, 380, 371, + /* 250 */ 364, 303, 309, 310, 452, 457, 322, 323, 363, 326, + /* 260 */ 396, 607, 462, 608, 610, 467, 615, 616, 523, 527, + /* 270 */ 485, 512, 513, 552, 516, 556, 559, 538, 539, 573, + /* 280 */ 560, 587, 589, 590, 575, 592, 593, 595, 673, 596, + /* 290 */ 582, 549, 584, 551, 601, 513, 602, 570, 604, 571, + /* 300 */ 611, 603, 605, 617, 686, 606, 609, 684, 690, 691, + /* 310 */ 692, 693, 694, 695, 696, 618, 688, 627, 624, 625, + /* 320 */ 594, 628, 682, 649, 697, 565, 566, 619, 619, 619, + /* 330 */ 619, 698, 572, 574, 619, 619, 619, 711, 712, 637, + /* 340 */ 619, 716, 717, 718, 719, 720, 721, 722, 723, 724, + /* 350 */ 725, 726, 727, 728, 729, 730, 640, 653, 731, 732, /* 360 */ 678, 739, }; -#define YY_REDUCE_COUNT (201) -#define YY_REDUCE_MIN (-265) -#define YY_REDUCE_MAX (465) +#define YY_REDUCE_COUNT (202) +#define YY_REDUCE_MIN (-264) +#define YY_REDUCE_MAX (466) static const short yy_reduce_ofst[] = { - /* 0 */ -27, -33, -33, -193, -193, -76, -203, -199, -175, -184, - /* 10 */ -130, -134, 93, 24, 67, 119, 126, 135, 142, 148, - /* 20 */ 151, 171, 172, -177, -191, -265, -145, -121, -105, -227, - /* 30 */ -29, 52, 133, 8, -201, -136, 11, 63, 49, 186, - /* 40 */ 96, 189, 192, 70, 153, 199, 206, -116, -11, 17, - /* 50 */ 20, 183, 191, 195, 208, 212, 214, 215, 216, 217, - /* 60 */ 218, 219, 220, 221, 222, 223, 224, 53, 242, 244, - /* 70 */ 232, 253, 255, 257, 258, 259, 260, 295, 300, 301, - /* 80 */ 238, 302, 305, 310, 262, 264, 312, 313, 315, 318, - /* 90 */ 230, 233, 263, 269, 319, 320, 321, 328, 330, 332, - /* 100 */ 333, 334, 335, 336, 339, 342, 346, 349, 351, 352, - /* 110 */ 353, 354, 355, 356, 358, 359, 360, 362, 363, 364, - /* 120 */ 365, 367, 368, 369, 370, 371, 372, 374, 376, 377, - /* 130 */ 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, - /* 140 */ 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, - /* 150 */ 398, 344, 399, 400, 247, 252, 254, 267, 402, 403, - /* 160 */ 246, 266, 265, 270, 273, 293, 406, 268, 409, 411, - /* 170 */ 413, 410, 415, 416, 417, 418, 419, 420, 423, 421, - /* 180 */ 422, 424, 427, 425, 428, 430, 433, 435, 432, 437, - /* 190 */ 438, 439, 448, 450, 440, 451, 453, 454, 457, 465, - /* 200 */ 441, 452, + /* 0 */ -177, -18, -18, -192, -192, -89, -202, -199, -109, -156, + /* 10 */ -22, 24, -10, 114, 115, 133, 148, 149, 150, 156, + /* 20 */ 167, 172, 173, -182, -191, -264, -123, -118, -61, -146, + /* 30 */ -13, -189, -162, 34, 33, 37, 69, 86, -85, -139, + /* 40 */ 158, 52, 96, -175, -106, 197, -113, 22, 28, 186, + /* 50 */ 199, 207, 211, 213, 214, 215, 216, 217, 219, 220, + /* 60 */ 221, 222, 224, 225, 226, 227, 228, -1, 7, 235, + /* 70 */ 183, 256, 257, 258, 259, 260, 261, 304, 305, 308, + /* 80 */ 236, 313, 314, 315, 255, 262, 316, 317, 318, 319, + /* 90 */ 231, 232, 268, 263, 321, 324, 325, 327, 328, 329, + /* 100 */ 330, 331, 332, 333, 336, 338, 341, 342, 344, 348, + /* 110 */ 350, 352, 353, 354, 357, 358, 359, 360, 361, 362, + /* 120 */ 365, 366, 367, 368, 369, 370, 372, 373, 374, 375, + /* 130 */ 376, 377, 378, 379, 381, 382, 383, 384, 385, 386, + /* 140 */ 387, 388, 389, 390, 391, 392, 393, 394, 395, 397, + /* 150 */ 398, 399, 320, 400, 401, 241, 252, 266, 269, 402, + /* 160 */ 403, 272, 277, 265, 295, 290, 404, 407, 409, 412, + /* 170 */ 414, 416, 417, 418, 419, 420, 421, 422, 423, 427, + /* 180 */ 424, 425, 428, 430, 429, 431, 433, 437, 435, 441, + /* 190 */ 432, 443, 438, 439, 442, 445, 451, 455, 456, 458, + /* 200 */ 461, 447, 466, }; static const YYACTIONTYPE yy_default[] = { /* 0 */ 856, 979, 918, 989, 905, 915, 1126, 1126, 1126, 856, @@ -464,28 +477,28 @@ static const YYACTIONTYPE yy_default[] = { /* 120 */ 856, 856, 856, 856, 856, 856, 903, 856, 901, 856, /* 130 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, /* 140 */ 856, 856, 856, 856, 887, 856, 856, 856, 856, 856, - /* 150 */ 856, 878, 878, 878, 856, 856, 856, 856, 878, 878, - /* 160 */ 1076, 1080, 1062, 1074, 1070, 1057, 1055, 1053, 1061, 1052, - /* 170 */ 1084, 878, 878, 878, 923, 923, 919, 915, 915, 878, - /* 180 */ 878, 941, 939, 937, 929, 935, 931, 933, 927, 906, - /* 190 */ 856, 878, 913, 913, 878, 913, 878, 913, 878, 878, - /* 200 */ 963, 981, 856, 1085, 1075, 856, 1125, 1115, 1114, 856, - /* 210 */ 1121, 1113, 1112, 1111, 856, 856, 1107, 1110, 1109, 1108, - /* 220 */ 856, 856, 856, 856, 1117, 1116, 856, 856, 856, 856, - /* 230 */ 856, 856, 856, 856, 856, 856, 1081, 1077, 856, 856, - /* 240 */ 856, 856, 856, 856, 856, 856, 856, 1087, 856, 856, - /* 250 */ 856, 856, 856, 856, 856, 856, 856, 991, 856, 856, + /* 150 */ 856, 874, 878, 878, 878, 856, 856, 856, 856, 878, + /* 160 */ 878, 1076, 1080, 1062, 1074, 1070, 1057, 1055, 1053, 1061, + /* 170 */ 1052, 1084, 878, 878, 878, 923, 923, 919, 915, 915, + /* 180 */ 878, 878, 941, 939, 937, 929, 935, 931, 933, 927, + /* 190 */ 906, 856, 878, 913, 913, 878, 913, 878, 913, 878, + /* 200 */ 878, 963, 981, 856, 1085, 1075, 856, 1125, 1115, 1114, + /* 210 */ 856, 1121, 1113, 1112, 1111, 856, 856, 1107, 1110, 1109, + /* 220 */ 1108, 856, 856, 856, 856, 1117, 1116, 856, 856, 856, + /* 230 */ 856, 856, 856, 856, 856, 856, 856, 1081, 1077, 856, + /* 240 */ 856, 856, 856, 856, 856, 856, 856, 856, 1087, 856, + /* 250 */ 856, 856, 856, 856, 856, 856, 856, 856, 991, 856, /* 260 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, - /* 270 */ 1029, 856, 856, 856, 856, 856, 1041, 1040, 856, 856, - /* 280 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 1071, - /* 290 */ 856, 1063, 856, 856, 1003, 856, 856, 856, 856, 856, + /* 270 */ 856, 1029, 856, 856, 856, 856, 856, 1041, 1040, 856, + /* 280 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 290 */ 1071, 856, 1063, 856, 856, 1003, 856, 856, 856, 856, /* 300 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, /* 310 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, - /* 320 */ 856, 856, 856, 856, 856, 856, 1144, 1139, 1140, 1137, - /* 330 */ 856, 856, 856, 1136, 1131, 1132, 856, 856, 856, 1129, - /* 340 */ 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, - /* 350 */ 856, 856, 856, 856, 856, 947, 856, 885, 883, 856, - /* 360 */ 874, 856, + /* 320 */ 856, 856, 856, 856, 856, 856, 856, 1144, 1139, 1140, + /* 330 */ 1137, 856, 856, 856, 1136, 1131, 1132, 856, 856, 856, + /* 340 */ 1129, 856, 856, 856, 856, 856, 856, 856, 856, 856, + /* 350 */ 856, 856, 856, 856, 856, 856, 947, 856, 885, 883, + /* 360 */ 856, 856, }; /********** End of lemon-generated parsing tables *****************************/ @@ -565,7 +578,6 @@ static const YYCODETYPE yyFallback[] = { 0, /* SCORES => nothing */ 0, /* GRANTS => nothing */ 0, /* VNODES => nothing */ - 1, /* IPTOKEN => ID */ 0, /* DOT => nothing */ 0, /* CREATE => nothing */ 0, /* TABLE => nothing */ @@ -690,6 +702,7 @@ static const YYCODETYPE yyFallback[] = { 1, /* STATEMENT => ID */ 1, /* TRIGGER => ID */ 1, /* VIEW => ID */ + 1, /* IPTOKEN => ID */ 1, /* SEMI => ID */ 1, /* NONE => ID */ 1, /* PREV => ID */ @@ -739,6 +752,7 @@ struct yyParser { int yyerrcnt; /* Shifts left before out of the error */ #endif ParseARG_SDECL /* A place to hold %extra_argument */ + ParseCTX_SDECL /* A place to hold %extra_context */ #if YYSTACKDEPTH<=0 int yystksz; /* Current side of the stack */ yyStackEntry *yystack; /* The parser's stack */ @@ -846,131 +860,131 @@ static const char *const yyTokenName[] = { /* 57 */ "SCORES", /* 58 */ "GRANTS", /* 59 */ "VNODES", - /* 60 */ "IPTOKEN", - /* 61 */ "DOT", - /* 62 */ "CREATE", - /* 63 */ "TABLE", - /* 64 */ "STABLE", - /* 65 */ "DATABASE", - /* 66 */ "TABLES", - /* 67 */ "STABLES", - /* 68 */ "VGROUPS", - /* 69 */ "DROP", - /* 70 */ "TOPIC", - /* 71 */ "FUNCTION", - /* 72 */ "DNODE", - /* 73 */ "USER", - /* 74 */ "ACCOUNT", - /* 75 */ "USE", - /* 76 */ "DESCRIBE", - /* 77 */ "ALTER", - /* 78 */ "PASS", - /* 79 */ "PRIVILEGE", - /* 80 */ "LOCAL", - /* 81 */ "COMPACT", - /* 82 */ "LP", - /* 83 */ "RP", - /* 84 */ "IF", - /* 85 */ "EXISTS", - /* 86 */ "AS", - /* 87 */ "OUTPUTTYPE", - /* 88 */ "AGGREGATE", - /* 89 */ "BUFSIZE", - /* 90 */ "PPS", - /* 91 */ "TSERIES", - /* 92 */ "DBS", - /* 93 */ "STORAGE", - /* 94 */ "QTIME", - /* 95 */ "CONNS", - /* 96 */ "STATE", - /* 97 */ "COMMA", - /* 98 */ "KEEP", - /* 99 */ "CACHE", - /* 100 */ "REPLICA", - /* 101 */ "QUORUM", - /* 102 */ "DAYS", - /* 103 */ "MINROWS", - /* 104 */ "MAXROWS", - /* 105 */ "BLOCKS", - /* 106 */ "CTIME", - /* 107 */ "WAL", - /* 108 */ "FSYNC", - /* 109 */ "COMP", - /* 110 */ "PRECISION", - /* 111 */ "UPDATE", - /* 112 */ "CACHELAST", - /* 113 */ "PARTITIONS", - /* 114 */ "UNSIGNED", - /* 115 */ "TAGS", - /* 116 */ "USING", - /* 117 */ "NULL", - /* 118 */ "NOW", - /* 119 */ "SELECT", - /* 120 */ "UNION", - /* 121 */ "ALL", - /* 122 */ "DISTINCT", - /* 123 */ "FROM", - /* 124 */ "VARIABLE", - /* 125 */ "INTERVAL", - /* 126 */ "SESSION", - /* 127 */ "STATE_WINDOW", - /* 128 */ "FILL", - /* 129 */ "SLIDING", - /* 130 */ "ORDER", - /* 131 */ "BY", - /* 132 */ "ASC", - /* 133 */ "DESC", - /* 134 */ "GROUP", - /* 135 */ "HAVING", - /* 136 */ "LIMIT", - /* 137 */ "OFFSET", - /* 138 */ "SLIMIT", - /* 139 */ "SOFFSET", - /* 140 */ "WHERE", - /* 141 */ "RESET", - /* 142 */ "QUERY", - /* 143 */ "SYNCDB", - /* 144 */ "ADD", - /* 145 */ "COLUMN", - /* 146 */ "MODIFY", - /* 147 */ "TAG", - /* 148 */ "CHANGE", - /* 149 */ "SET", - /* 150 */ "KILL", - /* 151 */ "CONNECTION", - /* 152 */ "STREAM", - /* 153 */ "COLON", - /* 154 */ "ABORT", - /* 155 */ "AFTER", - /* 156 */ "ATTACH", - /* 157 */ "BEFORE", - /* 158 */ "BEGIN", - /* 159 */ "CASCADE", - /* 160 */ "CLUSTER", - /* 161 */ "CONFLICT", - /* 162 */ "COPY", - /* 163 */ "DEFERRED", - /* 164 */ "DELIMITERS", - /* 165 */ "DETACH", - /* 166 */ "EACH", - /* 167 */ "END", - /* 168 */ "EXPLAIN", - /* 169 */ "FAIL", - /* 170 */ "FOR", - /* 171 */ "IGNORE", - /* 172 */ "IMMEDIATE", - /* 173 */ "INITIALLY", - /* 174 */ "INSTEAD", - /* 175 */ "MATCH", - /* 176 */ "KEY", - /* 177 */ "OF", - /* 178 */ "RAISE", - /* 179 */ "REPLACE", - /* 180 */ "RESTRICT", - /* 181 */ "ROW", - /* 182 */ "STATEMENT", - /* 183 */ "TRIGGER", - /* 184 */ "VIEW", + /* 60 */ "DOT", + /* 61 */ "CREATE", + /* 62 */ "TABLE", + /* 63 */ "STABLE", + /* 64 */ "DATABASE", + /* 65 */ "TABLES", + /* 66 */ "STABLES", + /* 67 */ "VGROUPS", + /* 68 */ "DROP", + /* 69 */ "TOPIC", + /* 70 */ "FUNCTION", + /* 71 */ "DNODE", + /* 72 */ "USER", + /* 73 */ "ACCOUNT", + /* 74 */ "USE", + /* 75 */ "DESCRIBE", + /* 76 */ "ALTER", + /* 77 */ "PASS", + /* 78 */ "PRIVILEGE", + /* 79 */ "LOCAL", + /* 80 */ "COMPACT", + /* 81 */ "LP", + /* 82 */ "RP", + /* 83 */ "IF", + /* 84 */ "EXISTS", + /* 85 */ "AS", + /* 86 */ "OUTPUTTYPE", + /* 87 */ "AGGREGATE", + /* 88 */ "BUFSIZE", + /* 89 */ "PPS", + /* 90 */ "TSERIES", + /* 91 */ "DBS", + /* 92 */ "STORAGE", + /* 93 */ "QTIME", + /* 94 */ "CONNS", + /* 95 */ "STATE", + /* 96 */ "COMMA", + /* 97 */ "KEEP", + /* 98 */ "CACHE", + /* 99 */ "REPLICA", + /* 100 */ "QUORUM", + /* 101 */ "DAYS", + /* 102 */ "MINROWS", + /* 103 */ "MAXROWS", + /* 104 */ "BLOCKS", + /* 105 */ "CTIME", + /* 106 */ "WAL", + /* 107 */ "FSYNC", + /* 108 */ "COMP", + /* 109 */ "PRECISION", + /* 110 */ "UPDATE", + /* 111 */ "CACHELAST", + /* 112 */ "PARTITIONS", + /* 113 */ "UNSIGNED", + /* 114 */ "TAGS", + /* 115 */ "USING", + /* 116 */ "NULL", + /* 117 */ "NOW", + /* 118 */ "SELECT", + /* 119 */ "UNION", + /* 120 */ "ALL", + /* 121 */ "DISTINCT", + /* 122 */ "FROM", + /* 123 */ "VARIABLE", + /* 124 */ "INTERVAL", + /* 125 */ "SESSION", + /* 126 */ "STATE_WINDOW", + /* 127 */ "FILL", + /* 128 */ "SLIDING", + /* 129 */ "ORDER", + /* 130 */ "BY", + /* 131 */ "ASC", + /* 132 */ "DESC", + /* 133 */ "GROUP", + /* 134 */ "HAVING", + /* 135 */ "LIMIT", + /* 136 */ "OFFSET", + /* 137 */ "SLIMIT", + /* 138 */ "SOFFSET", + /* 139 */ "WHERE", + /* 140 */ "RESET", + /* 141 */ "QUERY", + /* 142 */ "SYNCDB", + /* 143 */ "ADD", + /* 144 */ "COLUMN", + /* 145 */ "MODIFY", + /* 146 */ "TAG", + /* 147 */ "CHANGE", + /* 148 */ "SET", + /* 149 */ "KILL", + /* 150 */ "CONNECTION", + /* 151 */ "STREAM", + /* 152 */ "COLON", + /* 153 */ "ABORT", + /* 154 */ "AFTER", + /* 155 */ "ATTACH", + /* 156 */ "BEFORE", + /* 157 */ "BEGIN", + /* 158 */ "CASCADE", + /* 159 */ "CLUSTER", + /* 160 */ "CONFLICT", + /* 161 */ "COPY", + /* 162 */ "DEFERRED", + /* 163 */ "DELIMITERS", + /* 164 */ "DETACH", + /* 165 */ "EACH", + /* 166 */ "END", + /* 167 */ "EXPLAIN", + /* 168 */ "FAIL", + /* 169 */ "FOR", + /* 170 */ "IGNORE", + /* 171 */ "IMMEDIATE", + /* 172 */ "INITIALLY", + /* 173 */ "INSTEAD", + /* 174 */ "MATCH", + /* 175 */ "KEY", + /* 176 */ "OF", + /* 177 */ "RAISE", + /* 178 */ "REPLACE", + /* 179 */ "RESTRICT", + /* 180 */ "ROW", + /* 181 */ "STATEMENT", + /* 182 */ "TRIGGER", + /* 183 */ "VIEW", + /* 184 */ "IPTOKEN", /* 185 */ "SEMI", /* 186 */ "NONE", /* 187 */ "PREV", @@ -981,87 +995,86 @@ static const char *const yyTokenName[] = { /* 192 */ "INSERT", /* 193 */ "INTO", /* 194 */ "VALUES", - /* 195 */ "error", - /* 196 */ "program", - /* 197 */ "cmd", + /* 195 */ "program", + /* 196 */ "cmd", + /* 197 */ "ids", /* 198 */ "dbPrefix", - /* 199 */ "ids", - /* 200 */ "cpxName", - /* 201 */ "ifexists", - /* 202 */ "alter_db_optr", - /* 203 */ "alter_topic_optr", - /* 204 */ "acct_optr", - /* 205 */ "exprlist", - /* 206 */ "ifnotexists", - /* 207 */ "db_optr", - /* 208 */ "topic_optr", - /* 209 */ "typename", - /* 210 */ "bufsize", - /* 211 */ "pps", - /* 212 */ "tseries", - /* 213 */ "dbs", - /* 214 */ "streams", - /* 215 */ "storage", - /* 216 */ "qtime", - /* 217 */ "users", - /* 218 */ "conns", - /* 219 */ "state", - /* 220 */ "intitemlist", - /* 221 */ "intitem", - /* 222 */ "keep", - /* 223 */ "cache", - /* 224 */ "replica", - /* 225 */ "quorum", - /* 226 */ "days", - /* 227 */ "minrows", - /* 228 */ "maxrows", - /* 229 */ "blocks", - /* 230 */ "ctime", - /* 231 */ "wal", - /* 232 */ "fsync", - /* 233 */ "comp", - /* 234 */ "prec", - /* 235 */ "update", - /* 236 */ "cachelast", - /* 237 */ "partitions", - /* 238 */ "signed", - /* 239 */ "create_table_args", - /* 240 */ "create_stable_args", - /* 241 */ "create_table_list", - /* 242 */ "create_from_stable", - /* 243 */ "columnlist", - /* 244 */ "tagitemlist", - /* 245 */ "tagNamelist", - /* 246 */ "select", - /* 247 */ "column", - /* 248 */ "tagitem", - /* 249 */ "selcollist", - /* 250 */ "from", - /* 251 */ "where_opt", - /* 252 */ "interval_opt", - /* 253 */ "sliding_opt", - /* 254 */ "session_option", - /* 255 */ "windowstate_option", - /* 256 */ "fill_opt", - /* 257 */ "groupby_opt", - /* 258 */ "having_opt", - /* 259 */ "orderby_opt", - /* 260 */ "slimit_opt", - /* 261 */ "limit_opt", - /* 262 */ "union", - /* 263 */ "sclp", - /* 264 */ "distinct", - /* 265 */ "expr", - /* 266 */ "as", - /* 267 */ "tablelist", - /* 268 */ "sub", - /* 269 */ "tmvar", - /* 270 */ "sortlist", - /* 271 */ "sortitem", - /* 272 */ "item", - /* 273 */ "sortorder", - /* 274 */ "grouplist", - /* 275 */ "expritem", + /* 199 */ "cpxName", + /* 200 */ "ifexists", + /* 201 */ "alter_db_optr", + /* 202 */ "alter_topic_optr", + /* 203 */ "acct_optr", + /* 204 */ "exprlist", + /* 205 */ "ifnotexists", + /* 206 */ "db_optr", + /* 207 */ "topic_optr", + /* 208 */ "typename", + /* 209 */ "bufsize", + /* 210 */ "pps", + /* 211 */ "tseries", + /* 212 */ "dbs", + /* 213 */ "streams", + /* 214 */ "storage", + /* 215 */ "qtime", + /* 216 */ "users", + /* 217 */ "conns", + /* 218 */ "state", + /* 219 */ "intitemlist", + /* 220 */ "intitem", + /* 221 */ "keep", + /* 222 */ "cache", + /* 223 */ "replica", + /* 224 */ "quorum", + /* 225 */ "days", + /* 226 */ "minrows", + /* 227 */ "maxrows", + /* 228 */ "blocks", + /* 229 */ "ctime", + /* 230 */ "wal", + /* 231 */ "fsync", + /* 232 */ "comp", + /* 233 */ "prec", + /* 234 */ "update", + /* 235 */ "cachelast", + /* 236 */ "partitions", + /* 237 */ "signed", + /* 238 */ "create_table_args", + /* 239 */ "create_stable_args", + /* 240 */ "create_table_list", + /* 241 */ "create_from_stable", + /* 242 */ "columnlist", + /* 243 */ "tagitemlist", + /* 244 */ "tagNamelist", + /* 245 */ "select", + /* 246 */ "column", + /* 247 */ "tagitem", + /* 248 */ "selcollist", + /* 249 */ "from", + /* 250 */ "where_opt", + /* 251 */ "interval_opt", + /* 252 */ "sliding_opt", + /* 253 */ "session_option", + /* 254 */ "windowstate_option", + /* 255 */ "fill_opt", + /* 256 */ "groupby_opt", + /* 257 */ "having_opt", + /* 258 */ "orderby_opt", + /* 259 */ "slimit_opt", + /* 260 */ "limit_opt", + /* 261 */ "union", + /* 262 */ "sclp", + /* 263 */ "distinct", + /* 264 */ "expr", + /* 265 */ "as", + /* 266 */ "tablelist", + /* 267 */ "sub", + /* 268 */ "tmvar", + /* 269 */ "sortlist", + /* 270 */ "sortitem", + /* 271 */ "item", + /* 272 */ "sortorder", + /* 273 */ "grouplist", + /* 274 */ "expritem", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1085,7 +1098,7 @@ static const char *const yyRuleName[] = { /* 13 */ "cmd ::= SHOW SCORES", /* 14 */ "cmd ::= SHOW GRANTS", /* 15 */ "cmd ::= SHOW VNODES", - /* 16 */ "cmd ::= SHOW VNODES IPTOKEN", + /* 16 */ "cmd ::= SHOW VNODES ids", /* 17 */ "dbPrefix ::=", /* 18 */ "dbPrefix ::= ids DOT", /* 19 */ "cpxName ::=", @@ -1406,28 +1419,29 @@ static int yyGrowStack(yyParser *p){ /* Initialize a new parser that has already been allocated. */ -void ParseInit(void *yypParser){ - yyParser *pParser = (yyParser*)yypParser; +void ParseInit(void *yypRawParser ParseCTX_PDECL){ + yyParser *yypParser = (yyParser*)yypRawParser; + ParseCTX_STORE #ifdef YYTRACKMAXSTACKDEPTH - pParser->yyhwm = 0; + yypParser->yyhwm = 0; #endif #if YYSTACKDEPTH<=0 - pParser->yytos = NULL; - pParser->yystack = NULL; - pParser->yystksz = 0; - if( yyGrowStack(pParser) ){ - pParser->yystack = &pParser->yystk0; - pParser->yystksz = 1; + yypParser->yytos = NULL; + yypParser->yystack = NULL; + yypParser->yystksz = 0; + if( yyGrowStack(yypParser) ){ + yypParser->yystack = &yypParser->yystk0; + yypParser->yystksz = 1; } #endif #ifndef YYNOERRORRECOVERY - pParser->yyerrcnt = -1; + yypParser->yyerrcnt = -1; #endif - pParser->yytos = pParser->yystack; - pParser->yystack[0].stateno = 0; - pParser->yystack[0].major = 0; + yypParser->yytos = yypParser->yystack; + yypParser->yystack[0].stateno = 0; + yypParser->yystack[0].major = 0; #if YYSTACKDEPTH>0 - pParser->yystackEnd = &pParser->yystack[YYSTACKDEPTH-1]; + yypParser->yystackEnd = &yypParser->yystack[YYSTACKDEPTH-1]; #endif } @@ -1444,11 +1458,14 @@ void ParseInit(void *yypParser){ ** A pointer to a parser. This pointer is used in subsequent calls ** to Parse and ParseFree. */ -void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE)){ - yyParser *pParser; - pParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); - if( pParser ) ParseInit(pParser); - return pParser; +void *ParseAlloc(void *(*mallocProc)(YYMALLOCARGTYPE) ParseCTX_PDECL){ + yyParser *yypParser; + yypParser = (yyParser*)(*mallocProc)( (YYMALLOCARGTYPE)sizeof(yyParser) ); + if( yypParser ){ + ParseCTX_STORE + ParseInit(yypParser ParseCTX_PARAM); + } + return (void*)yypParser; } #endif /* Parse_ENGINEALWAYSONSTACK */ @@ -1465,7 +1482,8 @@ static void yy_destructor( YYCODETYPE yymajor, /* Type code for object to destroy */ YYMINORTYPE *yypminor /* The object to be destroyed */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH switch( yymajor ){ /* Here is inserted the actions which take place when a ** terminal or non-terminal is destroyed. This can happen @@ -1478,60 +1496,76 @@ static void yy_destructor( ** inside the C code. */ /********* Begin destructor definitions ***************************************/ - case 205: /* exprlist */ - case 249: /* selcollist */ - case 263: /* sclp */ + case 204: /* exprlist */ + case 248: /* selcollist */ + case 262: /* sclp */ { -tSqlExprListDestroy((yypminor->yy525)); +#line 750 "sql.y" +tSqlExprListDestroy((yypminor->yy131)); +#line 1506 "sql.c" } break; - case 220: /* intitemlist */ - case 222: /* keep */ - case 243: /* columnlist */ - case 244: /* tagitemlist */ - case 245: /* tagNamelist */ - case 256: /* fill_opt */ - case 257: /* groupby_opt */ - case 259: /* orderby_opt */ - case 270: /* sortlist */ - case 274: /* grouplist */ + case 219: /* intitemlist */ + case 221: /* keep */ + case 242: /* columnlist */ + case 243: /* tagitemlist */ + case 244: /* tagNamelist */ + case 255: /* fill_opt */ + case 256: /* groupby_opt */ + case 258: /* orderby_opt */ + case 269: /* sortlist */ + case 273: /* grouplist */ { -taosArrayDestroy((yypminor->yy525)); +#line 253 "sql.y" +taosArrayDestroy((yypminor->yy131)); +#line 1522 "sql.c" } break; - case 241: /* create_table_list */ + case 240: /* create_table_list */ { -destroyCreateTableSql((yypminor->yy158)); +#line 361 "sql.y" +destroyCreateTableSql((yypminor->yy272)); +#line 1529 "sql.c" } break; - case 246: /* select */ + case 245: /* select */ { -destroySqlNode((yypminor->yy464)); +#line 481 "sql.y" +destroySqlNode((yypminor->yy256)); +#line 1536 "sql.c" } break; - case 250: /* from */ - case 267: /* tablelist */ - case 268: /* sub */ + case 249: /* from */ + case 266: /* tablelist */ + case 267: /* sub */ { -destroyRelationInfo((yypminor->yy412)); +#line 536 "sql.y" +destroyRelationInfo((yypminor->yy544)); +#line 1545 "sql.c" } break; - case 251: /* where_opt */ - case 258: /* having_opt */ - case 265: /* expr */ - case 275: /* expritem */ + case 250: /* where_opt */ + case 257: /* having_opt */ + case 264: /* expr */ + case 274: /* expritem */ { -tSqlExprDestroy((yypminor->yy370)); +#line 683 "sql.y" +tSqlExprDestroy((yypminor->yy46)); +#line 1555 "sql.c" } break; - case 262: /* union */ + case 261: /* union */ { -destroyAllSqlNode((yypminor->yy525)); +#line 489 "sql.y" +destroyAllSqlNode((yypminor->yy131)); +#line 1562 "sql.c" } break; - case 271: /* sortitem */ + case 270: /* sortitem */ { -tVariantDestroy(&(yypminor->yy506)); +#line 616 "sql.y" +tVariantDestroy(&(yypminor->yy516)); +#line 1569 "sql.c" } break; /********* End destructor definitions *****************************************/ @@ -1643,13 +1677,12 @@ int ParseCoverage(FILE *out){ ** Find the appropriate action for a parser given the terminal ** look-ahead token iLookAhead. */ -static unsigned int yy_find_shift_action( - yyParser *pParser, /* The parser */ - YYCODETYPE iLookAhead /* The look-ahead token */ +static YYACTIONTYPE yy_find_shift_action( + YYCODETYPE iLookAhead, /* The look-ahead token */ + YYACTIONTYPE stateno /* Current state number */ ){ int i; - int stateno = pParser->yytos->stateno; - + if( stateno>YY_MAX_SHIFT ) return stateno; assert( stateno <= YY_SHIFT_COUNT ); #if defined(YYCOVERAGE) @@ -1657,15 +1690,19 @@ static unsigned int yy_find_shift_action( #endif do{ i = yy_shift_ofst[stateno]; - assert( i>=0 && i+YYNTOKEN<=sizeof(yy_lookahead)/sizeof(yy_lookahead[0]) ); + assert( i>=0 ); + assert( i<=YY_ACTTAB_COUNT ); + assert( i+YYNTOKEN<=(int)YY_NLOOKAHEAD ); assert( iLookAhead!=YYNOCODE ); assert( iLookAhead < YYNTOKEN ); i += iLookAhead; + assert( i<(int)YY_NLOOKAHEAD ); if( yy_lookahead[i]!=iLookAhead ){ #ifdef YYFALLBACK YYCODETYPE iFallback; /* Fallback token */ - if( iLookAhead %s\n", @@ -1680,15 +1717,8 @@ static unsigned int yy_find_shift_action( #ifdef YYWILDCARD { int j = i - iLookAhead + YYWILDCARD; - if( -#if YY_SHIFT_MIN+YYWILDCARD<0 - j>=0 && -#endif -#if YY_SHIFT_MAX+YYWILDCARD>=YY_ACTTAB_COUNT - j0 - ){ + assert( j<(int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])) ); + if( yy_lookahead[j]==YYWILDCARD && iLookAhead>0 ){ #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n", @@ -1702,6 +1732,7 @@ static unsigned int yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ + assert( i>=0 && iyytos; - yytos->stateno = (YYACTIONTYPE)yyNewState; - yytos->major = (YYCODETYPE)yyMajor; + yytos->stateno = yyNewState; + yytos->major = yyMajor; yytos->minor.yy0 = yyMinor; yyTraceShift(yypParser, yyNewState, "Shift"); } -/* The following table contains information about every rule that -** is used during the reduce. -*/ -static const struct { - YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ - signed char nrhs; /* Negative of the number of RHS symbols in the rule */ -} yyRuleInfo[] = { - { 196, -1 }, /* (0) program ::= cmd */ - { 197, -2 }, /* (1) cmd ::= SHOW DATABASES */ - { 197, -2 }, /* (2) cmd ::= SHOW TOPICS */ - { 197, -2 }, /* (3) cmd ::= SHOW FUNCTIONS */ - { 197, -2 }, /* (4) cmd ::= SHOW MNODES */ - { 197, -2 }, /* (5) cmd ::= SHOW DNODES */ - { 197, -2 }, /* (6) cmd ::= SHOW ACCOUNTS */ - { 197, -2 }, /* (7) cmd ::= SHOW USERS */ - { 197, -2 }, /* (8) cmd ::= SHOW MODULES */ - { 197, -2 }, /* (9) cmd ::= SHOW QUERIES */ - { 197, -2 }, /* (10) cmd ::= SHOW CONNECTIONS */ - { 197, -2 }, /* (11) cmd ::= SHOW STREAMS */ - { 197, -2 }, /* (12) cmd ::= SHOW VARIABLES */ - { 197, -2 }, /* (13) cmd ::= SHOW SCORES */ - { 197, -2 }, /* (14) cmd ::= SHOW GRANTS */ - { 197, -2 }, /* (15) cmd ::= SHOW VNODES */ - { 197, -3 }, /* (16) cmd ::= SHOW VNODES IPTOKEN */ - { 198, 0 }, /* (17) dbPrefix ::= */ - { 198, -2 }, /* (18) dbPrefix ::= ids DOT */ - { 200, 0 }, /* (19) cpxName ::= */ - { 200, -2 }, /* (20) cpxName ::= DOT ids */ - { 197, -5 }, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ - { 197, -5 }, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ - { 197, -4 }, /* (23) cmd ::= SHOW CREATE DATABASE ids */ - { 197, -3 }, /* (24) cmd ::= SHOW dbPrefix TABLES */ - { 197, -5 }, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ - { 197, -3 }, /* (26) cmd ::= SHOW dbPrefix STABLES */ - { 197, -5 }, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ - { 197, -3 }, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ - { 197, -4 }, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ - { 197, -5 }, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ - { 197, -5 }, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ - { 197, -4 }, /* (32) cmd ::= DROP DATABASE ifexists ids */ - { 197, -4 }, /* (33) cmd ::= DROP TOPIC ifexists ids */ - { 197, -3 }, /* (34) cmd ::= DROP FUNCTION ids */ - { 197, -3 }, /* (35) cmd ::= DROP DNODE ids */ - { 197, -3 }, /* (36) cmd ::= DROP USER ids */ - { 197, -3 }, /* (37) cmd ::= DROP ACCOUNT ids */ - { 197, -2 }, /* (38) cmd ::= USE ids */ - { 197, -3 }, /* (39) cmd ::= DESCRIBE ids cpxName */ - { 197, -5 }, /* (40) cmd ::= ALTER USER ids PASS ids */ - { 197, -5 }, /* (41) cmd ::= ALTER USER ids PRIVILEGE ids */ - { 197, -4 }, /* (42) cmd ::= ALTER DNODE ids ids */ - { 197, -5 }, /* (43) cmd ::= ALTER DNODE ids ids ids */ - { 197, -3 }, /* (44) cmd ::= ALTER LOCAL ids */ - { 197, -4 }, /* (45) cmd ::= ALTER LOCAL ids ids */ - { 197, -4 }, /* (46) cmd ::= ALTER DATABASE ids alter_db_optr */ - { 197, -4 }, /* (47) cmd ::= ALTER TOPIC ids alter_topic_optr */ - { 197, -4 }, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ - { 197, -6 }, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ - { 197, -6 }, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ - { 199, -1 }, /* (51) ids ::= ID */ - { 199, -1 }, /* (52) ids ::= STRING */ - { 201, -2 }, /* (53) ifexists ::= IF EXISTS */ - { 201, 0 }, /* (54) ifexists ::= */ - { 206, -3 }, /* (55) ifnotexists ::= IF NOT EXISTS */ - { 206, 0 }, /* (56) ifnotexists ::= */ - { 197, -3 }, /* (57) cmd ::= CREATE DNODE ids */ - { 197, -6 }, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ - { 197, -5 }, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ - { 197, -5 }, /* (60) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ - { 197, -8 }, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 197, -9 }, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ - { 197, -5 }, /* (63) cmd ::= CREATE USER ids PASS ids */ - { 210, 0 }, /* (64) bufsize ::= */ - { 210, -2 }, /* (65) bufsize ::= BUFSIZE INTEGER */ - { 211, 0 }, /* (66) pps ::= */ - { 211, -2 }, /* (67) pps ::= PPS INTEGER */ - { 212, 0 }, /* (68) tseries ::= */ - { 212, -2 }, /* (69) tseries ::= TSERIES INTEGER */ - { 213, 0 }, /* (70) dbs ::= */ - { 213, -2 }, /* (71) dbs ::= DBS INTEGER */ - { 214, 0 }, /* (72) streams ::= */ - { 214, -2 }, /* (73) streams ::= STREAMS INTEGER */ - { 215, 0 }, /* (74) storage ::= */ - { 215, -2 }, /* (75) storage ::= STORAGE INTEGER */ - { 216, 0 }, /* (76) qtime ::= */ - { 216, -2 }, /* (77) qtime ::= QTIME INTEGER */ - { 217, 0 }, /* (78) users ::= */ - { 217, -2 }, /* (79) users ::= USERS INTEGER */ - { 218, 0 }, /* (80) conns ::= */ - { 218, -2 }, /* (81) conns ::= CONNS INTEGER */ - { 219, 0 }, /* (82) state ::= */ - { 219, -2 }, /* (83) state ::= STATE ids */ - { 204, -9 }, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ - { 220, -3 }, /* (85) intitemlist ::= intitemlist COMMA intitem */ - { 220, -1 }, /* (86) intitemlist ::= intitem */ - { 221, -1 }, /* (87) intitem ::= INTEGER */ - { 222, -2 }, /* (88) keep ::= KEEP intitemlist */ - { 223, -2 }, /* (89) cache ::= CACHE INTEGER */ - { 224, -2 }, /* (90) replica ::= REPLICA INTEGER */ - { 225, -2 }, /* (91) quorum ::= QUORUM INTEGER */ - { 226, -2 }, /* (92) days ::= DAYS INTEGER */ - { 227, -2 }, /* (93) minrows ::= MINROWS INTEGER */ - { 228, -2 }, /* (94) maxrows ::= MAXROWS INTEGER */ - { 229, -2 }, /* (95) blocks ::= BLOCKS INTEGER */ - { 230, -2 }, /* (96) ctime ::= CTIME INTEGER */ - { 231, -2 }, /* (97) wal ::= WAL INTEGER */ - { 232, -2 }, /* (98) fsync ::= FSYNC INTEGER */ - { 233, -2 }, /* (99) comp ::= COMP INTEGER */ - { 234, -2 }, /* (100) prec ::= PRECISION STRING */ - { 235, -2 }, /* (101) update ::= UPDATE INTEGER */ - { 236, -2 }, /* (102) cachelast ::= CACHELAST INTEGER */ - { 237, -2 }, /* (103) partitions ::= PARTITIONS INTEGER */ - { 207, 0 }, /* (104) db_optr ::= */ - { 207, -2 }, /* (105) db_optr ::= db_optr cache */ - { 207, -2 }, /* (106) db_optr ::= db_optr replica */ - { 207, -2 }, /* (107) db_optr ::= db_optr quorum */ - { 207, -2 }, /* (108) db_optr ::= db_optr days */ - { 207, -2 }, /* (109) db_optr ::= db_optr minrows */ - { 207, -2 }, /* (110) db_optr ::= db_optr maxrows */ - { 207, -2 }, /* (111) db_optr ::= db_optr blocks */ - { 207, -2 }, /* (112) db_optr ::= db_optr ctime */ - { 207, -2 }, /* (113) db_optr ::= db_optr wal */ - { 207, -2 }, /* (114) db_optr ::= db_optr fsync */ - { 207, -2 }, /* (115) db_optr ::= db_optr comp */ - { 207, -2 }, /* (116) db_optr ::= db_optr prec */ - { 207, -2 }, /* (117) db_optr ::= db_optr keep */ - { 207, -2 }, /* (118) db_optr ::= db_optr update */ - { 207, -2 }, /* (119) db_optr ::= db_optr cachelast */ - { 208, -1 }, /* (120) topic_optr ::= db_optr */ - { 208, -2 }, /* (121) topic_optr ::= topic_optr partitions */ - { 202, 0 }, /* (122) alter_db_optr ::= */ - { 202, -2 }, /* (123) alter_db_optr ::= alter_db_optr replica */ - { 202, -2 }, /* (124) alter_db_optr ::= alter_db_optr quorum */ - { 202, -2 }, /* (125) alter_db_optr ::= alter_db_optr keep */ - { 202, -2 }, /* (126) alter_db_optr ::= alter_db_optr blocks */ - { 202, -2 }, /* (127) alter_db_optr ::= alter_db_optr comp */ - { 202, -2 }, /* (128) alter_db_optr ::= alter_db_optr update */ - { 202, -2 }, /* (129) alter_db_optr ::= alter_db_optr cachelast */ - { 203, -1 }, /* (130) alter_topic_optr ::= alter_db_optr */ - { 203, -2 }, /* (131) alter_topic_optr ::= alter_topic_optr partitions */ - { 209, -1 }, /* (132) typename ::= ids */ - { 209, -4 }, /* (133) typename ::= ids LP signed RP */ - { 209, -2 }, /* (134) typename ::= ids UNSIGNED */ - { 238, -1 }, /* (135) signed ::= INTEGER */ - { 238, -2 }, /* (136) signed ::= PLUS INTEGER */ - { 238, -2 }, /* (137) signed ::= MINUS INTEGER */ - { 197, -3 }, /* (138) cmd ::= CREATE TABLE create_table_args */ - { 197, -3 }, /* (139) cmd ::= CREATE TABLE create_stable_args */ - { 197, -3 }, /* (140) cmd ::= CREATE STABLE create_stable_args */ - { 197, -3 }, /* (141) cmd ::= CREATE TABLE create_table_list */ - { 241, -1 }, /* (142) create_table_list ::= create_from_stable */ - { 241, -2 }, /* (143) create_table_list ::= create_table_list create_from_stable */ - { 239, -6 }, /* (144) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ - { 240, -10 }, /* (145) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ - { 242, -10 }, /* (146) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ - { 242, -13 }, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ - { 245, -3 }, /* (148) tagNamelist ::= tagNamelist COMMA ids */ - { 245, -1 }, /* (149) tagNamelist ::= ids */ - { 239, -5 }, /* (150) create_table_args ::= ifnotexists ids cpxName AS select */ - { 243, -3 }, /* (151) columnlist ::= columnlist COMMA column */ - { 243, -1 }, /* (152) columnlist ::= column */ - { 247, -2 }, /* (153) column ::= ids typename */ - { 244, -3 }, /* (154) tagitemlist ::= tagitemlist COMMA tagitem */ - { 244, -1 }, /* (155) tagitemlist ::= tagitem */ - { 248, -1 }, /* (156) tagitem ::= INTEGER */ - { 248, -1 }, /* (157) tagitem ::= FLOAT */ - { 248, -1 }, /* (158) tagitem ::= STRING */ - { 248, -1 }, /* (159) tagitem ::= BOOL */ - { 248, -1 }, /* (160) tagitem ::= NULL */ - { 248, -1 }, /* (161) tagitem ::= NOW */ - { 248, -2 }, /* (162) tagitem ::= MINUS INTEGER */ - { 248, -2 }, /* (163) tagitem ::= MINUS FLOAT */ - { 248, -2 }, /* (164) tagitem ::= PLUS INTEGER */ - { 248, -2 }, /* (165) tagitem ::= PLUS FLOAT */ - { 246, -14 }, /* (166) select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ - { 246, -3 }, /* (167) select ::= LP select RP */ - { 262, -1 }, /* (168) union ::= select */ - { 262, -4 }, /* (169) union ::= union UNION ALL select */ - { 197, -1 }, /* (170) cmd ::= union */ - { 246, -2 }, /* (171) select ::= SELECT selcollist */ - { 263, -2 }, /* (172) sclp ::= selcollist COMMA */ - { 263, 0 }, /* (173) sclp ::= */ - { 249, -4 }, /* (174) selcollist ::= sclp distinct expr as */ - { 249, -2 }, /* (175) selcollist ::= sclp STAR */ - { 266, -2 }, /* (176) as ::= AS ids */ - { 266, -1 }, /* (177) as ::= ids */ - { 266, 0 }, /* (178) as ::= */ - { 264, -1 }, /* (179) distinct ::= DISTINCT */ - { 264, 0 }, /* (180) distinct ::= */ - { 250, -2 }, /* (181) from ::= FROM tablelist */ - { 250, -2 }, /* (182) from ::= FROM sub */ - { 268, -3 }, /* (183) sub ::= LP union RP */ - { 268, -4 }, /* (184) sub ::= LP union RP ids */ - { 268, -6 }, /* (185) sub ::= sub COMMA LP union RP ids */ - { 267, -2 }, /* (186) tablelist ::= ids cpxName */ - { 267, -3 }, /* (187) tablelist ::= ids cpxName ids */ - { 267, -4 }, /* (188) tablelist ::= tablelist COMMA ids cpxName */ - { 267, -5 }, /* (189) tablelist ::= tablelist COMMA ids cpxName ids */ - { 269, -1 }, /* (190) tmvar ::= VARIABLE */ - { 252, -4 }, /* (191) interval_opt ::= INTERVAL LP tmvar RP */ - { 252, -6 }, /* (192) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ - { 252, 0 }, /* (193) interval_opt ::= */ - { 254, 0 }, /* (194) session_option ::= */ - { 254, -7 }, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ - { 255, 0 }, /* (196) windowstate_option ::= */ - { 255, -4 }, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */ - { 256, 0 }, /* (198) fill_opt ::= */ - { 256, -6 }, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ - { 256, -4 }, /* (200) fill_opt ::= FILL LP ID RP */ - { 253, -4 }, /* (201) sliding_opt ::= SLIDING LP tmvar RP */ - { 253, 0 }, /* (202) sliding_opt ::= */ - { 259, 0 }, /* (203) orderby_opt ::= */ - { 259, -3 }, /* (204) orderby_opt ::= ORDER BY sortlist */ - { 270, -4 }, /* (205) sortlist ::= sortlist COMMA item sortorder */ - { 270, -2 }, /* (206) sortlist ::= item sortorder */ - { 272, -2 }, /* (207) item ::= ids cpxName */ - { 273, -1 }, /* (208) sortorder ::= ASC */ - { 273, -1 }, /* (209) sortorder ::= DESC */ - { 273, 0 }, /* (210) sortorder ::= */ - { 257, 0 }, /* (211) groupby_opt ::= */ - { 257, -3 }, /* (212) groupby_opt ::= GROUP BY grouplist */ - { 274, -3 }, /* (213) grouplist ::= grouplist COMMA item */ - { 274, -1 }, /* (214) grouplist ::= item */ - { 258, 0 }, /* (215) having_opt ::= */ - { 258, -2 }, /* (216) having_opt ::= HAVING expr */ - { 261, 0 }, /* (217) limit_opt ::= */ - { 261, -2 }, /* (218) limit_opt ::= LIMIT signed */ - { 261, -4 }, /* (219) limit_opt ::= LIMIT signed OFFSET signed */ - { 261, -4 }, /* (220) limit_opt ::= LIMIT signed COMMA signed */ - { 260, 0 }, /* (221) slimit_opt ::= */ - { 260, -2 }, /* (222) slimit_opt ::= SLIMIT signed */ - { 260, -4 }, /* (223) slimit_opt ::= SLIMIT signed SOFFSET signed */ - { 260, -4 }, /* (224) slimit_opt ::= SLIMIT signed COMMA signed */ - { 251, 0 }, /* (225) where_opt ::= */ - { 251, -2 }, /* (226) where_opt ::= WHERE expr */ - { 265, -3 }, /* (227) expr ::= LP expr RP */ - { 265, -1 }, /* (228) expr ::= ID */ - { 265, -3 }, /* (229) expr ::= ID DOT ID */ - { 265, -3 }, /* (230) expr ::= ID DOT STAR */ - { 265, -1 }, /* (231) expr ::= INTEGER */ - { 265, -2 }, /* (232) expr ::= MINUS INTEGER */ - { 265, -2 }, /* (233) expr ::= PLUS INTEGER */ - { 265, -1 }, /* (234) expr ::= FLOAT */ - { 265, -2 }, /* (235) expr ::= MINUS FLOAT */ - { 265, -2 }, /* (236) expr ::= PLUS FLOAT */ - { 265, -1 }, /* (237) expr ::= STRING */ - { 265, -1 }, /* (238) expr ::= NOW */ - { 265, -1 }, /* (239) expr ::= VARIABLE */ - { 265, -2 }, /* (240) expr ::= PLUS VARIABLE */ - { 265, -2 }, /* (241) expr ::= MINUS VARIABLE */ - { 265, -1 }, /* (242) expr ::= BOOL */ - { 265, -1 }, /* (243) expr ::= NULL */ - { 265, -4 }, /* (244) expr ::= ID LP exprlist RP */ - { 265, -4 }, /* (245) expr ::= ID LP STAR RP */ - { 265, -3 }, /* (246) expr ::= expr IS NULL */ - { 265, -4 }, /* (247) expr ::= expr IS NOT NULL */ - { 265, -3 }, /* (248) expr ::= expr LT expr */ - { 265, -3 }, /* (249) expr ::= expr GT expr */ - { 265, -3 }, /* (250) expr ::= expr LE expr */ - { 265, -3 }, /* (251) expr ::= expr GE expr */ - { 265, -3 }, /* (252) expr ::= expr NE expr */ - { 265, -3 }, /* (253) expr ::= expr EQ expr */ - { 265, -5 }, /* (254) expr ::= expr BETWEEN expr AND expr */ - { 265, -3 }, /* (255) expr ::= expr AND expr */ - { 265, -3 }, /* (256) expr ::= expr OR expr */ - { 265, -3 }, /* (257) expr ::= expr PLUS expr */ - { 265, -3 }, /* (258) expr ::= expr MINUS expr */ - { 265, -3 }, /* (259) expr ::= expr STAR expr */ - { 265, -3 }, /* (260) expr ::= expr SLASH expr */ - { 265, -3 }, /* (261) expr ::= expr REM expr */ - { 265, -3 }, /* (262) expr ::= expr LIKE expr */ - { 265, -5 }, /* (263) expr ::= expr IN LP exprlist RP */ - { 205, -3 }, /* (264) exprlist ::= exprlist COMMA expritem */ - { 205, -1 }, /* (265) exprlist ::= expritem */ - { 275, -1 }, /* (266) expritem ::= expr */ - { 275, 0 }, /* (267) expritem ::= */ - { 197, -3 }, /* (268) cmd ::= RESET QUERY CACHE */ - { 197, -3 }, /* (269) cmd ::= SYNCDB ids REPLICA */ - { 197, -7 }, /* (270) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ - { 197, -7 }, /* (271) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ - { 197, -7 }, /* (272) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ - { 197, -7 }, /* (273) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ - { 197, -7 }, /* (274) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ - { 197, -8 }, /* (275) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ - { 197, -9 }, /* (276) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ - { 197, -7 }, /* (277) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ - { 197, -7 }, /* (278) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ - { 197, -7 }, /* (279) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ - { 197, -7 }, /* (280) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ - { 197, -7 }, /* (281) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ - { 197, -7 }, /* (282) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ - { 197, -8 }, /* (283) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ - { 197, -9 }, /* (284) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ - { 197, -7 }, /* (285) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ - { 197, -3 }, /* (286) cmd ::= KILL CONNECTION INTEGER */ - { 197, -5 }, /* (287) cmd ::= KILL STREAM INTEGER COLON INTEGER */ - { 197, -5 }, /* (288) cmd ::= KILL QUERY INTEGER COLON INTEGER */ +/* For rule J, yyRuleInfoLhs[J] contains the symbol on the left-hand side +** of that rule */ +static const YYCODETYPE yyRuleInfoLhs[] = { + 195, /* (0) program ::= cmd */ + 196, /* (1) cmd ::= SHOW DATABASES */ + 196, /* (2) cmd ::= SHOW TOPICS */ + 196, /* (3) cmd ::= SHOW FUNCTIONS */ + 196, /* (4) cmd ::= SHOW MNODES */ + 196, /* (5) cmd ::= SHOW DNODES */ + 196, /* (6) cmd ::= SHOW ACCOUNTS */ + 196, /* (7) cmd ::= SHOW USERS */ + 196, /* (8) cmd ::= SHOW MODULES */ + 196, /* (9) cmd ::= SHOW QUERIES */ + 196, /* (10) cmd ::= SHOW CONNECTIONS */ + 196, /* (11) cmd ::= SHOW STREAMS */ + 196, /* (12) cmd ::= SHOW VARIABLES */ + 196, /* (13) cmd ::= SHOW SCORES */ + 196, /* (14) cmd ::= SHOW GRANTS */ + 196, /* (15) cmd ::= SHOW VNODES */ + 196, /* (16) cmd ::= SHOW VNODES ids */ + 198, /* (17) dbPrefix ::= */ + 198, /* (18) dbPrefix ::= ids DOT */ + 199, /* (19) cpxName ::= */ + 199, /* (20) cpxName ::= DOT ids */ + 196, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + 196, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + 196, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + 196, /* (24) cmd ::= SHOW dbPrefix TABLES */ + 196, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + 196, /* (26) cmd ::= SHOW dbPrefix STABLES */ + 196, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + 196, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + 196, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + 196, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + 196, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + 196, /* (32) cmd ::= DROP DATABASE ifexists ids */ + 196, /* (33) cmd ::= DROP TOPIC ifexists ids */ + 196, /* (34) cmd ::= DROP FUNCTION ids */ + 196, /* (35) cmd ::= DROP DNODE ids */ + 196, /* (36) cmd ::= DROP USER ids */ + 196, /* (37) cmd ::= DROP ACCOUNT ids */ + 196, /* (38) cmd ::= USE ids */ + 196, /* (39) cmd ::= DESCRIBE ids cpxName */ + 196, /* (40) cmd ::= ALTER USER ids PASS ids */ + 196, /* (41) cmd ::= ALTER USER ids PRIVILEGE ids */ + 196, /* (42) cmd ::= ALTER DNODE ids ids */ + 196, /* (43) cmd ::= ALTER DNODE ids ids ids */ + 196, /* (44) cmd ::= ALTER LOCAL ids */ + 196, /* (45) cmd ::= ALTER LOCAL ids ids */ + 196, /* (46) cmd ::= ALTER DATABASE ids alter_db_optr */ + 196, /* (47) cmd ::= ALTER TOPIC ids alter_topic_optr */ + 196, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ + 196, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + 196, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ + 197, /* (51) ids ::= ID */ + 197, /* (52) ids ::= STRING */ + 200, /* (53) ifexists ::= IF EXISTS */ + 200, /* (54) ifexists ::= */ + 205, /* (55) ifnotexists ::= IF NOT EXISTS */ + 205, /* (56) ifnotexists ::= */ + 196, /* (57) cmd ::= CREATE DNODE ids */ + 196, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + 196, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + 196, /* (60) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + 196, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + 196, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + 196, /* (63) cmd ::= CREATE USER ids PASS ids */ + 209, /* (64) bufsize ::= */ + 209, /* (65) bufsize ::= BUFSIZE INTEGER */ + 210, /* (66) pps ::= */ + 210, /* (67) pps ::= PPS INTEGER */ + 211, /* (68) tseries ::= */ + 211, /* (69) tseries ::= TSERIES INTEGER */ + 212, /* (70) dbs ::= */ + 212, /* (71) dbs ::= DBS INTEGER */ + 213, /* (72) streams ::= */ + 213, /* (73) streams ::= STREAMS INTEGER */ + 214, /* (74) storage ::= */ + 214, /* (75) storage ::= STORAGE INTEGER */ + 215, /* (76) qtime ::= */ + 215, /* (77) qtime ::= QTIME INTEGER */ + 216, /* (78) users ::= */ + 216, /* (79) users ::= USERS INTEGER */ + 217, /* (80) conns ::= */ + 217, /* (81) conns ::= CONNS INTEGER */ + 218, /* (82) state ::= */ + 218, /* (83) state ::= STATE ids */ + 203, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + 219, /* (85) intitemlist ::= intitemlist COMMA intitem */ + 219, /* (86) intitemlist ::= intitem */ + 220, /* (87) intitem ::= INTEGER */ + 221, /* (88) keep ::= KEEP intitemlist */ + 222, /* (89) cache ::= CACHE INTEGER */ + 223, /* (90) replica ::= REPLICA INTEGER */ + 224, /* (91) quorum ::= QUORUM INTEGER */ + 225, /* (92) days ::= DAYS INTEGER */ + 226, /* (93) minrows ::= MINROWS INTEGER */ + 227, /* (94) maxrows ::= MAXROWS INTEGER */ + 228, /* (95) blocks ::= BLOCKS INTEGER */ + 229, /* (96) ctime ::= CTIME INTEGER */ + 230, /* (97) wal ::= WAL INTEGER */ + 231, /* (98) fsync ::= FSYNC INTEGER */ + 232, /* (99) comp ::= COMP INTEGER */ + 233, /* (100) prec ::= PRECISION STRING */ + 234, /* (101) update ::= UPDATE INTEGER */ + 235, /* (102) cachelast ::= CACHELAST INTEGER */ + 236, /* (103) partitions ::= PARTITIONS INTEGER */ + 206, /* (104) db_optr ::= */ + 206, /* (105) db_optr ::= db_optr cache */ + 206, /* (106) db_optr ::= db_optr replica */ + 206, /* (107) db_optr ::= db_optr quorum */ + 206, /* (108) db_optr ::= db_optr days */ + 206, /* (109) db_optr ::= db_optr minrows */ + 206, /* (110) db_optr ::= db_optr maxrows */ + 206, /* (111) db_optr ::= db_optr blocks */ + 206, /* (112) db_optr ::= db_optr ctime */ + 206, /* (113) db_optr ::= db_optr wal */ + 206, /* (114) db_optr ::= db_optr fsync */ + 206, /* (115) db_optr ::= db_optr comp */ + 206, /* (116) db_optr ::= db_optr prec */ + 206, /* (117) db_optr ::= db_optr keep */ + 206, /* (118) db_optr ::= db_optr update */ + 206, /* (119) db_optr ::= db_optr cachelast */ + 207, /* (120) topic_optr ::= db_optr */ + 207, /* (121) topic_optr ::= topic_optr partitions */ + 201, /* (122) alter_db_optr ::= */ + 201, /* (123) alter_db_optr ::= alter_db_optr replica */ + 201, /* (124) alter_db_optr ::= alter_db_optr quorum */ + 201, /* (125) alter_db_optr ::= alter_db_optr keep */ + 201, /* (126) alter_db_optr ::= alter_db_optr blocks */ + 201, /* (127) alter_db_optr ::= alter_db_optr comp */ + 201, /* (128) alter_db_optr ::= alter_db_optr update */ + 201, /* (129) alter_db_optr ::= alter_db_optr cachelast */ + 202, /* (130) alter_topic_optr ::= alter_db_optr */ + 202, /* (131) alter_topic_optr ::= alter_topic_optr partitions */ + 208, /* (132) typename ::= ids */ + 208, /* (133) typename ::= ids LP signed RP */ + 208, /* (134) typename ::= ids UNSIGNED */ + 237, /* (135) signed ::= INTEGER */ + 237, /* (136) signed ::= PLUS INTEGER */ + 237, /* (137) signed ::= MINUS INTEGER */ + 196, /* (138) cmd ::= CREATE TABLE create_table_args */ + 196, /* (139) cmd ::= CREATE TABLE create_stable_args */ + 196, /* (140) cmd ::= CREATE STABLE create_stable_args */ + 196, /* (141) cmd ::= CREATE TABLE create_table_list */ + 240, /* (142) create_table_list ::= create_from_stable */ + 240, /* (143) create_table_list ::= create_table_list create_from_stable */ + 238, /* (144) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + 239, /* (145) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + 241, /* (146) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + 241, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + 244, /* (148) tagNamelist ::= tagNamelist COMMA ids */ + 244, /* (149) tagNamelist ::= ids */ + 238, /* (150) create_table_args ::= ifnotexists ids cpxName AS select */ + 242, /* (151) columnlist ::= columnlist COMMA column */ + 242, /* (152) columnlist ::= column */ + 246, /* (153) column ::= ids typename */ + 243, /* (154) tagitemlist ::= tagitemlist COMMA tagitem */ + 243, /* (155) tagitemlist ::= tagitem */ + 247, /* (156) tagitem ::= INTEGER */ + 247, /* (157) tagitem ::= FLOAT */ + 247, /* (158) tagitem ::= STRING */ + 247, /* (159) tagitem ::= BOOL */ + 247, /* (160) tagitem ::= NULL */ + 247, /* (161) tagitem ::= NOW */ + 247, /* (162) tagitem ::= MINUS INTEGER */ + 247, /* (163) tagitem ::= MINUS FLOAT */ + 247, /* (164) tagitem ::= PLUS INTEGER */ + 247, /* (165) tagitem ::= PLUS FLOAT */ + 245, /* (166) select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + 245, /* (167) select ::= LP select RP */ + 261, /* (168) union ::= select */ + 261, /* (169) union ::= union UNION ALL select */ + 196, /* (170) cmd ::= union */ + 245, /* (171) select ::= SELECT selcollist */ + 262, /* (172) sclp ::= selcollist COMMA */ + 262, /* (173) sclp ::= */ + 248, /* (174) selcollist ::= sclp distinct expr as */ + 248, /* (175) selcollist ::= sclp STAR */ + 265, /* (176) as ::= AS ids */ + 265, /* (177) as ::= ids */ + 265, /* (178) as ::= */ + 263, /* (179) distinct ::= DISTINCT */ + 263, /* (180) distinct ::= */ + 249, /* (181) from ::= FROM tablelist */ + 249, /* (182) from ::= FROM sub */ + 267, /* (183) sub ::= LP union RP */ + 267, /* (184) sub ::= LP union RP ids */ + 267, /* (185) sub ::= sub COMMA LP union RP ids */ + 266, /* (186) tablelist ::= ids cpxName */ + 266, /* (187) tablelist ::= ids cpxName ids */ + 266, /* (188) tablelist ::= tablelist COMMA ids cpxName */ + 266, /* (189) tablelist ::= tablelist COMMA ids cpxName ids */ + 268, /* (190) tmvar ::= VARIABLE */ + 251, /* (191) interval_opt ::= INTERVAL LP tmvar RP */ + 251, /* (192) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + 251, /* (193) interval_opt ::= */ + 253, /* (194) session_option ::= */ + 253, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 254, /* (196) windowstate_option ::= */ + 254, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */ + 255, /* (198) fill_opt ::= */ + 255, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + 255, /* (200) fill_opt ::= FILL LP ID RP */ + 252, /* (201) sliding_opt ::= SLIDING LP tmvar RP */ + 252, /* (202) sliding_opt ::= */ + 258, /* (203) orderby_opt ::= */ + 258, /* (204) orderby_opt ::= ORDER BY sortlist */ + 269, /* (205) sortlist ::= sortlist COMMA item sortorder */ + 269, /* (206) sortlist ::= item sortorder */ + 271, /* (207) item ::= ids cpxName */ + 272, /* (208) sortorder ::= ASC */ + 272, /* (209) sortorder ::= DESC */ + 272, /* (210) sortorder ::= */ + 256, /* (211) groupby_opt ::= */ + 256, /* (212) groupby_opt ::= GROUP BY grouplist */ + 273, /* (213) grouplist ::= grouplist COMMA item */ + 273, /* (214) grouplist ::= item */ + 257, /* (215) having_opt ::= */ + 257, /* (216) having_opt ::= HAVING expr */ + 260, /* (217) limit_opt ::= */ + 260, /* (218) limit_opt ::= LIMIT signed */ + 260, /* (219) limit_opt ::= LIMIT signed OFFSET signed */ + 260, /* (220) limit_opt ::= LIMIT signed COMMA signed */ + 259, /* (221) slimit_opt ::= */ + 259, /* (222) slimit_opt ::= SLIMIT signed */ + 259, /* (223) slimit_opt ::= SLIMIT signed SOFFSET signed */ + 259, /* (224) slimit_opt ::= SLIMIT signed COMMA signed */ + 250, /* (225) where_opt ::= */ + 250, /* (226) where_opt ::= WHERE expr */ + 264, /* (227) expr ::= LP expr RP */ + 264, /* (228) expr ::= ID */ + 264, /* (229) expr ::= ID DOT ID */ + 264, /* (230) expr ::= ID DOT STAR */ + 264, /* (231) expr ::= INTEGER */ + 264, /* (232) expr ::= MINUS INTEGER */ + 264, /* (233) expr ::= PLUS INTEGER */ + 264, /* (234) expr ::= FLOAT */ + 264, /* (235) expr ::= MINUS FLOAT */ + 264, /* (236) expr ::= PLUS FLOAT */ + 264, /* (237) expr ::= STRING */ + 264, /* (238) expr ::= NOW */ + 264, /* (239) expr ::= VARIABLE */ + 264, /* (240) expr ::= PLUS VARIABLE */ + 264, /* (241) expr ::= MINUS VARIABLE */ + 264, /* (242) expr ::= BOOL */ + 264, /* (243) expr ::= NULL */ + 264, /* (244) expr ::= ID LP exprlist RP */ + 264, /* (245) expr ::= ID LP STAR RP */ + 264, /* (246) expr ::= expr IS NULL */ + 264, /* (247) expr ::= expr IS NOT NULL */ + 264, /* (248) expr ::= expr LT expr */ + 264, /* (249) expr ::= expr GT expr */ + 264, /* (250) expr ::= expr LE expr */ + 264, /* (251) expr ::= expr GE expr */ + 264, /* (252) expr ::= expr NE expr */ + 264, /* (253) expr ::= expr EQ expr */ + 264, /* (254) expr ::= expr BETWEEN expr AND expr */ + 264, /* (255) expr ::= expr AND expr */ + 264, /* (256) expr ::= expr OR expr */ + 264, /* (257) expr ::= expr PLUS expr */ + 264, /* (258) expr ::= expr MINUS expr */ + 264, /* (259) expr ::= expr STAR expr */ + 264, /* (260) expr ::= expr SLASH expr */ + 264, /* (261) expr ::= expr REM expr */ + 264, /* (262) expr ::= expr LIKE expr */ + 264, /* (263) expr ::= expr IN LP exprlist RP */ + 204, /* (264) exprlist ::= exprlist COMMA expritem */ + 204, /* (265) exprlist ::= expritem */ + 274, /* (266) expritem ::= expr */ + 274, /* (267) expritem ::= */ + 196, /* (268) cmd ::= RESET QUERY CACHE */ + 196, /* (269) cmd ::= SYNCDB ids REPLICA */ + 196, /* (270) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + 196, /* (271) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + 196, /* (272) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + 196, /* (273) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + 196, /* (274) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + 196, /* (275) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + 196, /* (276) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + 196, /* (277) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + 196, /* (278) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + 196, /* (279) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + 196, /* (280) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + 196, /* (281) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + 196, /* (282) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + 196, /* (283) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + 196, /* (284) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + 196, /* (285) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + 196, /* (286) cmd ::= KILL CONNECTION INTEGER */ + 196, /* (287) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + 196, /* (288) cmd ::= KILL QUERY INTEGER COLON INTEGER */ +}; + +/* For rule J, yyRuleInfoNRhs[J] contains the negative of the number +** of symbols on the right-hand side of that rule. */ +static const signed char yyRuleInfoNRhs[] = { + -1, /* (0) program ::= cmd */ + -2, /* (1) cmd ::= SHOW DATABASES */ + -2, /* (2) cmd ::= SHOW TOPICS */ + -2, /* (3) cmd ::= SHOW FUNCTIONS */ + -2, /* (4) cmd ::= SHOW MNODES */ + -2, /* (5) cmd ::= SHOW DNODES */ + -2, /* (6) cmd ::= SHOW ACCOUNTS */ + -2, /* (7) cmd ::= SHOW USERS */ + -2, /* (8) cmd ::= SHOW MODULES */ + -2, /* (9) cmd ::= SHOW QUERIES */ + -2, /* (10) cmd ::= SHOW CONNECTIONS */ + -2, /* (11) cmd ::= SHOW STREAMS */ + -2, /* (12) cmd ::= SHOW VARIABLES */ + -2, /* (13) cmd ::= SHOW SCORES */ + -2, /* (14) cmd ::= SHOW GRANTS */ + -2, /* (15) cmd ::= SHOW VNODES */ + -3, /* (16) cmd ::= SHOW VNODES ids */ + 0, /* (17) dbPrefix ::= */ + -2, /* (18) dbPrefix ::= ids DOT */ + 0, /* (19) cpxName ::= */ + -2, /* (20) cpxName ::= DOT ids */ + -5, /* (21) cmd ::= SHOW CREATE TABLE ids cpxName */ + -5, /* (22) cmd ::= SHOW CREATE STABLE ids cpxName */ + -4, /* (23) cmd ::= SHOW CREATE DATABASE ids */ + -3, /* (24) cmd ::= SHOW dbPrefix TABLES */ + -5, /* (25) cmd ::= SHOW dbPrefix TABLES LIKE ids */ + -3, /* (26) cmd ::= SHOW dbPrefix STABLES */ + -5, /* (27) cmd ::= SHOW dbPrefix STABLES LIKE ids */ + -3, /* (28) cmd ::= SHOW dbPrefix VGROUPS */ + -4, /* (29) cmd ::= SHOW dbPrefix VGROUPS ids */ + -5, /* (30) cmd ::= DROP TABLE ifexists ids cpxName */ + -5, /* (31) cmd ::= DROP STABLE ifexists ids cpxName */ + -4, /* (32) cmd ::= DROP DATABASE ifexists ids */ + -4, /* (33) cmd ::= DROP TOPIC ifexists ids */ + -3, /* (34) cmd ::= DROP FUNCTION ids */ + -3, /* (35) cmd ::= DROP DNODE ids */ + -3, /* (36) cmd ::= DROP USER ids */ + -3, /* (37) cmd ::= DROP ACCOUNT ids */ + -2, /* (38) cmd ::= USE ids */ + -3, /* (39) cmd ::= DESCRIBE ids cpxName */ + -5, /* (40) cmd ::= ALTER USER ids PASS ids */ + -5, /* (41) cmd ::= ALTER USER ids PRIVILEGE ids */ + -4, /* (42) cmd ::= ALTER DNODE ids ids */ + -5, /* (43) cmd ::= ALTER DNODE ids ids ids */ + -3, /* (44) cmd ::= ALTER LOCAL ids */ + -4, /* (45) cmd ::= ALTER LOCAL ids ids */ + -4, /* (46) cmd ::= ALTER DATABASE ids alter_db_optr */ + -4, /* (47) cmd ::= ALTER TOPIC ids alter_topic_optr */ + -4, /* (48) cmd ::= ALTER ACCOUNT ids acct_optr */ + -6, /* (49) cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ + -6, /* (50) cmd ::= COMPACT VNODES IN LP exprlist RP */ + -1, /* (51) ids ::= ID */ + -1, /* (52) ids ::= STRING */ + -2, /* (53) ifexists ::= IF EXISTS */ + 0, /* (54) ifexists ::= */ + -3, /* (55) ifnotexists ::= IF NOT EXISTS */ + 0, /* (56) ifnotexists ::= */ + -3, /* (57) cmd ::= CREATE DNODE ids */ + -6, /* (58) cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ + -5, /* (59) cmd ::= CREATE DATABASE ifnotexists ids db_optr */ + -5, /* (60) cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ + -8, /* (61) cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + -9, /* (62) cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ + -5, /* (63) cmd ::= CREATE USER ids PASS ids */ + 0, /* (64) bufsize ::= */ + -2, /* (65) bufsize ::= BUFSIZE INTEGER */ + 0, /* (66) pps ::= */ + -2, /* (67) pps ::= PPS INTEGER */ + 0, /* (68) tseries ::= */ + -2, /* (69) tseries ::= TSERIES INTEGER */ + 0, /* (70) dbs ::= */ + -2, /* (71) dbs ::= DBS INTEGER */ + 0, /* (72) streams ::= */ + -2, /* (73) streams ::= STREAMS INTEGER */ + 0, /* (74) storage ::= */ + -2, /* (75) storage ::= STORAGE INTEGER */ + 0, /* (76) qtime ::= */ + -2, /* (77) qtime ::= QTIME INTEGER */ + 0, /* (78) users ::= */ + -2, /* (79) users ::= USERS INTEGER */ + 0, /* (80) conns ::= */ + -2, /* (81) conns ::= CONNS INTEGER */ + 0, /* (82) state ::= */ + -2, /* (83) state ::= STATE ids */ + -9, /* (84) acct_optr ::= pps tseries storage streams qtime dbs users conns state */ + -3, /* (85) intitemlist ::= intitemlist COMMA intitem */ + -1, /* (86) intitemlist ::= intitem */ + -1, /* (87) intitem ::= INTEGER */ + -2, /* (88) keep ::= KEEP intitemlist */ + -2, /* (89) cache ::= CACHE INTEGER */ + -2, /* (90) replica ::= REPLICA INTEGER */ + -2, /* (91) quorum ::= QUORUM INTEGER */ + -2, /* (92) days ::= DAYS INTEGER */ + -2, /* (93) minrows ::= MINROWS INTEGER */ + -2, /* (94) maxrows ::= MAXROWS INTEGER */ + -2, /* (95) blocks ::= BLOCKS INTEGER */ + -2, /* (96) ctime ::= CTIME INTEGER */ + -2, /* (97) wal ::= WAL INTEGER */ + -2, /* (98) fsync ::= FSYNC INTEGER */ + -2, /* (99) comp ::= COMP INTEGER */ + -2, /* (100) prec ::= PRECISION STRING */ + -2, /* (101) update ::= UPDATE INTEGER */ + -2, /* (102) cachelast ::= CACHELAST INTEGER */ + -2, /* (103) partitions ::= PARTITIONS INTEGER */ + 0, /* (104) db_optr ::= */ + -2, /* (105) db_optr ::= db_optr cache */ + -2, /* (106) db_optr ::= db_optr replica */ + -2, /* (107) db_optr ::= db_optr quorum */ + -2, /* (108) db_optr ::= db_optr days */ + -2, /* (109) db_optr ::= db_optr minrows */ + -2, /* (110) db_optr ::= db_optr maxrows */ + -2, /* (111) db_optr ::= db_optr blocks */ + -2, /* (112) db_optr ::= db_optr ctime */ + -2, /* (113) db_optr ::= db_optr wal */ + -2, /* (114) db_optr ::= db_optr fsync */ + -2, /* (115) db_optr ::= db_optr comp */ + -2, /* (116) db_optr ::= db_optr prec */ + -2, /* (117) db_optr ::= db_optr keep */ + -2, /* (118) db_optr ::= db_optr update */ + -2, /* (119) db_optr ::= db_optr cachelast */ + -1, /* (120) topic_optr ::= db_optr */ + -2, /* (121) topic_optr ::= topic_optr partitions */ + 0, /* (122) alter_db_optr ::= */ + -2, /* (123) alter_db_optr ::= alter_db_optr replica */ + -2, /* (124) alter_db_optr ::= alter_db_optr quorum */ + -2, /* (125) alter_db_optr ::= alter_db_optr keep */ + -2, /* (126) alter_db_optr ::= alter_db_optr blocks */ + -2, /* (127) alter_db_optr ::= alter_db_optr comp */ + -2, /* (128) alter_db_optr ::= alter_db_optr update */ + -2, /* (129) alter_db_optr ::= alter_db_optr cachelast */ + -1, /* (130) alter_topic_optr ::= alter_db_optr */ + -2, /* (131) alter_topic_optr ::= alter_topic_optr partitions */ + -1, /* (132) typename ::= ids */ + -4, /* (133) typename ::= ids LP signed RP */ + -2, /* (134) typename ::= ids UNSIGNED */ + -1, /* (135) signed ::= INTEGER */ + -2, /* (136) signed ::= PLUS INTEGER */ + -2, /* (137) signed ::= MINUS INTEGER */ + -3, /* (138) cmd ::= CREATE TABLE create_table_args */ + -3, /* (139) cmd ::= CREATE TABLE create_stable_args */ + -3, /* (140) cmd ::= CREATE STABLE create_stable_args */ + -3, /* (141) cmd ::= CREATE TABLE create_table_list */ + -1, /* (142) create_table_list ::= create_from_stable */ + -2, /* (143) create_table_list ::= create_table_list create_from_stable */ + -6, /* (144) create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ + -10, /* (145) create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ + -10, /* (146) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ + -13, /* (147) create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ + -3, /* (148) tagNamelist ::= tagNamelist COMMA ids */ + -1, /* (149) tagNamelist ::= ids */ + -5, /* (150) create_table_args ::= ifnotexists ids cpxName AS select */ + -3, /* (151) columnlist ::= columnlist COMMA column */ + -1, /* (152) columnlist ::= column */ + -2, /* (153) column ::= ids typename */ + -3, /* (154) tagitemlist ::= tagitemlist COMMA tagitem */ + -1, /* (155) tagitemlist ::= tagitem */ + -1, /* (156) tagitem ::= INTEGER */ + -1, /* (157) tagitem ::= FLOAT */ + -1, /* (158) tagitem ::= STRING */ + -1, /* (159) tagitem ::= BOOL */ + -1, /* (160) tagitem ::= NULL */ + -1, /* (161) tagitem ::= NOW */ + -2, /* (162) tagitem ::= MINUS INTEGER */ + -2, /* (163) tagitem ::= MINUS FLOAT */ + -2, /* (164) tagitem ::= PLUS INTEGER */ + -2, /* (165) tagitem ::= PLUS FLOAT */ + -14, /* (166) select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ + -3, /* (167) select ::= LP select RP */ + -1, /* (168) union ::= select */ + -4, /* (169) union ::= union UNION ALL select */ + -1, /* (170) cmd ::= union */ + -2, /* (171) select ::= SELECT selcollist */ + -2, /* (172) sclp ::= selcollist COMMA */ + 0, /* (173) sclp ::= */ + -4, /* (174) selcollist ::= sclp distinct expr as */ + -2, /* (175) selcollist ::= sclp STAR */ + -2, /* (176) as ::= AS ids */ + -1, /* (177) as ::= ids */ + 0, /* (178) as ::= */ + -1, /* (179) distinct ::= DISTINCT */ + 0, /* (180) distinct ::= */ + -2, /* (181) from ::= FROM tablelist */ + -2, /* (182) from ::= FROM sub */ + -3, /* (183) sub ::= LP union RP */ + -4, /* (184) sub ::= LP union RP ids */ + -6, /* (185) sub ::= sub COMMA LP union RP ids */ + -2, /* (186) tablelist ::= ids cpxName */ + -3, /* (187) tablelist ::= ids cpxName ids */ + -4, /* (188) tablelist ::= tablelist COMMA ids cpxName */ + -5, /* (189) tablelist ::= tablelist COMMA ids cpxName ids */ + -1, /* (190) tmvar ::= VARIABLE */ + -4, /* (191) interval_opt ::= INTERVAL LP tmvar RP */ + -6, /* (192) interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ + 0, /* (193) interval_opt ::= */ + 0, /* (194) session_option ::= */ + -7, /* (195) session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ + 0, /* (196) windowstate_option ::= */ + -4, /* (197) windowstate_option ::= STATE_WINDOW LP ids RP */ + 0, /* (198) fill_opt ::= */ + -6, /* (199) fill_opt ::= FILL LP ID COMMA tagitemlist RP */ + -4, /* (200) fill_opt ::= FILL LP ID RP */ + -4, /* (201) sliding_opt ::= SLIDING LP tmvar RP */ + 0, /* (202) sliding_opt ::= */ + 0, /* (203) orderby_opt ::= */ + -3, /* (204) orderby_opt ::= ORDER BY sortlist */ + -4, /* (205) sortlist ::= sortlist COMMA item sortorder */ + -2, /* (206) sortlist ::= item sortorder */ + -2, /* (207) item ::= ids cpxName */ + -1, /* (208) sortorder ::= ASC */ + -1, /* (209) sortorder ::= DESC */ + 0, /* (210) sortorder ::= */ + 0, /* (211) groupby_opt ::= */ + -3, /* (212) groupby_opt ::= GROUP BY grouplist */ + -3, /* (213) grouplist ::= grouplist COMMA item */ + -1, /* (214) grouplist ::= item */ + 0, /* (215) having_opt ::= */ + -2, /* (216) having_opt ::= HAVING expr */ + 0, /* (217) limit_opt ::= */ + -2, /* (218) limit_opt ::= LIMIT signed */ + -4, /* (219) limit_opt ::= LIMIT signed OFFSET signed */ + -4, /* (220) limit_opt ::= LIMIT signed COMMA signed */ + 0, /* (221) slimit_opt ::= */ + -2, /* (222) slimit_opt ::= SLIMIT signed */ + -4, /* (223) slimit_opt ::= SLIMIT signed SOFFSET signed */ + -4, /* (224) slimit_opt ::= SLIMIT signed COMMA signed */ + 0, /* (225) where_opt ::= */ + -2, /* (226) where_opt ::= WHERE expr */ + -3, /* (227) expr ::= LP expr RP */ + -1, /* (228) expr ::= ID */ + -3, /* (229) expr ::= ID DOT ID */ + -3, /* (230) expr ::= ID DOT STAR */ + -1, /* (231) expr ::= INTEGER */ + -2, /* (232) expr ::= MINUS INTEGER */ + -2, /* (233) expr ::= PLUS INTEGER */ + -1, /* (234) expr ::= FLOAT */ + -2, /* (235) expr ::= MINUS FLOAT */ + -2, /* (236) expr ::= PLUS FLOAT */ + -1, /* (237) expr ::= STRING */ + -1, /* (238) expr ::= NOW */ + -1, /* (239) expr ::= VARIABLE */ + -2, /* (240) expr ::= PLUS VARIABLE */ + -2, /* (241) expr ::= MINUS VARIABLE */ + -1, /* (242) expr ::= BOOL */ + -1, /* (243) expr ::= NULL */ + -4, /* (244) expr ::= ID LP exprlist RP */ + -4, /* (245) expr ::= ID LP STAR RP */ + -3, /* (246) expr ::= expr IS NULL */ + -4, /* (247) expr ::= expr IS NOT NULL */ + -3, /* (248) expr ::= expr LT expr */ + -3, /* (249) expr ::= expr GT expr */ + -3, /* (250) expr ::= expr LE expr */ + -3, /* (251) expr ::= expr GE expr */ + -3, /* (252) expr ::= expr NE expr */ + -3, /* (253) expr ::= expr EQ expr */ + -5, /* (254) expr ::= expr BETWEEN expr AND expr */ + -3, /* (255) expr ::= expr AND expr */ + -3, /* (256) expr ::= expr OR expr */ + -3, /* (257) expr ::= expr PLUS expr */ + -3, /* (258) expr ::= expr MINUS expr */ + -3, /* (259) expr ::= expr STAR expr */ + -3, /* (260) expr ::= expr SLASH expr */ + -3, /* (261) expr ::= expr REM expr */ + -3, /* (262) expr ::= expr LIKE expr */ + -5, /* (263) expr ::= expr IN LP exprlist RP */ + -3, /* (264) exprlist ::= exprlist COMMA expritem */ + -1, /* (265) exprlist ::= expritem */ + -1, /* (266) expritem ::= expr */ + 0, /* (267) expritem ::= */ + -3, /* (268) cmd ::= RESET QUERY CACHE */ + -3, /* (269) cmd ::= SYNCDB ids REPLICA */ + -7, /* (270) cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (271) cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ + -7, /* (272) cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ + -7, /* (273) cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ + -7, /* (274) cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ + -8, /* (275) cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ + -9, /* (276) cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ + -7, /* (277) cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ + -7, /* (278) cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ + -7, /* (279) cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ + -7, /* (280) cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ + -7, /* (281) cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ + -7, /* (282) cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ + -8, /* (283) cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ + -9, /* (284) cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ + -7, /* (285) cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ + -3, /* (286) cmd ::= KILL CONNECTION INTEGER */ + -5, /* (287) cmd ::= KILL STREAM INTEGER COLON INTEGER */ + -5, /* (288) cmd ::= KILL QUERY INTEGER COLON INTEGER */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -2128,30 +2451,34 @@ static void yy_accept(yyParser*); /* Forward Declaration */ ** only called from one place, optimizing compilers will in-line it, which ** means that the extra parameters have no performance impact. */ -static void yy_reduce( +static YYACTIONTYPE yy_reduce( yyParser *yypParser, /* The parser */ unsigned int yyruleno, /* Number of the rule by which to reduce */ int yyLookahead, /* Lookahead token, or YYNOCODE if none */ ParseTOKENTYPE yyLookaheadToken /* Value of the lookahead token */ + ParseCTX_PDECL /* %extra_context */ ){ int yygoto; /* The next state */ - int yyact; /* The next action */ + YYACTIONTYPE yyact; /* The next action */ yyStackEntry *yymsp; /* The top of the parser's stack */ int yysize; /* Amount to pop the stack */ - ParseARG_FETCH; + ParseARG_FETCH (void)yyLookahead; (void)yyLookaheadToken; yymsp = yypParser->yytos; #ifndef NDEBUG if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ - yysize = yyRuleInfo[yyruleno].nrhs; + yysize = yyRuleInfoNRhs[yyruleno]; if( yysize ){ - fprintf(yyTraceFILE, "%sReduce %d [%s], go to state %d.\n", + fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", yyTracePrompt, - yyruleno, yyRuleName[yyruleno], yymsp[yysize].stateno); + yyruleno, yyRuleName[yyruleno], + yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ yypParser->yyhwm++; @@ -2169,13 +2496,19 @@ static void yy_reduce( #if YYSTACKDEPTH>0 if( yypParser->yytos>=yypParser->yystackEnd ){ yyStackOverflow(yypParser); - return; + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; } #else if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ if( yyGrowStack(yypParser) ){ yyStackOverflow(yypParser); - return; + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; } yymsp = yypParser->yytos; } @@ -2197,226 +2530,346 @@ static void yy_reduce( case 138: /* cmd ::= CREATE TABLE create_table_args */ yytestcase(yyruleno==138); case 139: /* cmd ::= CREATE TABLE create_stable_args */ yytestcase(yyruleno==139); case 140: /* cmd ::= CREATE STABLE create_stable_args */ yytestcase(yyruleno==140); +#line 63 "sql.y" {} +#line 2536 "sql.c" break; case 1: /* cmd ::= SHOW DATABASES */ +#line 66 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);} +#line 2541 "sql.c" break; case 2: /* cmd ::= SHOW TOPICS */ +#line 67 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_TP, 0, 0);} +#line 2546 "sql.c" break; case 3: /* cmd ::= SHOW FUNCTIONS */ +#line 68 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_FUNCTION, 0, 0);} +#line 2551 "sql.c" break; case 4: /* cmd ::= SHOW MNODES */ +#line 69 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);} +#line 2556 "sql.c" break; case 5: /* cmd ::= SHOW DNODES */ +#line 70 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);} +#line 2561 "sql.c" break; case 6: /* cmd ::= SHOW ACCOUNTS */ +#line 71 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);} +#line 2566 "sql.c" break; case 7: /* cmd ::= SHOW USERS */ +#line 72 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);} +#line 2571 "sql.c" break; case 8: /* cmd ::= SHOW MODULES */ +#line 74 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0); } +#line 2576 "sql.c" break; case 9: /* cmd ::= SHOW QUERIES */ +#line 75 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0); } +#line 2581 "sql.c" break; case 10: /* cmd ::= SHOW CONNECTIONS */ +#line 76 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);} +#line 2586 "sql.c" break; case 11: /* cmd ::= SHOW STREAMS */ +#line 77 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0); } +#line 2591 "sql.c" break; case 12: /* cmd ::= SHOW VARIABLES */ +#line 78 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0); } +#line 2596 "sql.c" break; case 13: /* cmd ::= SHOW SCORES */ +#line 79 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0); } +#line 2601 "sql.c" break; case 14: /* cmd ::= SHOW GRANTS */ +#line 80 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0); } +#line 2606 "sql.c" break; case 15: /* cmd ::= SHOW VNODES */ +#line 82 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); } +#line 2611 "sql.c" break; - case 16: /* cmd ::= SHOW VNODES IPTOKEN */ + case 16: /* cmd ::= SHOW VNODES ids */ +#line 83 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &yymsp[0].minor.yy0, 0); } +#line 2616 "sql.c" break; case 17: /* dbPrefix ::= */ +#line 87 "sql.y" {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.type = 0;} +#line 2621 "sql.c" break; case 18: /* dbPrefix ::= ids DOT */ +#line 88 "sql.y" {yylhsminor.yy0 = yymsp[-1].minor.yy0; } +#line 2626 "sql.c" yymsp[-1].minor.yy0 = yylhsminor.yy0; break; case 19: /* cpxName ::= */ +#line 91 "sql.y" {yymsp[1].minor.yy0.n = 0; } +#line 2632 "sql.c" break; case 20: /* cpxName ::= DOT ids */ +#line 92 "sql.y" {yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; yymsp[-1].minor.yy0.n += 1; } +#line 2637 "sql.c" break; case 21: /* cmd ::= SHOW CREATE TABLE ids cpxName */ +#line 94 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &yymsp[-1].minor.yy0); } +#line 2645 "sql.c" break; case 22: /* cmd ::= SHOW CREATE STABLE ids cpxName */ +#line 98 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &yymsp[-1].minor.yy0); } +#line 2653 "sql.c" break; case 23: /* cmd ::= SHOW CREATE DATABASE ids */ +#line 103 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &yymsp[0].minor.yy0); } +#line 2660 "sql.c" break; case 24: /* cmd ::= SHOW dbPrefix TABLES */ +#line 107 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-1].minor.yy0, 0); } +#line 2667 "sql.c" break; case 25: /* cmd ::= SHOW dbPrefix TABLES LIKE ids */ +#line 111 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0); } +#line 2674 "sql.c" break; case 26: /* cmd ::= SHOW dbPrefix STABLES */ +#line 115 "sql.y" { setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &yymsp[-1].minor.yy0, 0); } +#line 2681 "sql.c" break; case 27: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */ +#line 119 "sql.y" { SStrToken token; tSetDbName(&token, &yymsp[-3].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &yymsp[0].minor.yy0); } +#line 2690 "sql.c" break; case 28: /* cmd ::= SHOW dbPrefix VGROUPS */ +#line 125 "sql.y" { SStrToken token; tSetDbName(&token, &yymsp[-1].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0); } +#line 2699 "sql.c" break; case 29: /* cmd ::= SHOW dbPrefix VGROUPS ids */ +#line 131 "sql.y" { SStrToken token; tSetDbName(&token, &yymsp[-2].minor.yy0); setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, &yymsp[0].minor.yy0); } +#line 2708 "sql.c" break; case 30: /* cmd ::= DROP TABLE ifexists ids cpxName */ +#line 138 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0, -1, -1); } +#line 2716 "sql.c" break; case 31: /* cmd ::= DROP STABLE ifexists ids cpxName */ +#line 144 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &yymsp[-1].minor.yy0, &yymsp[-2].minor.yy0, -1, TSDB_SUPER_TABLE); } +#line 2724 "sql.c" break; case 32: /* cmd ::= DROP DATABASE ifexists ids */ +#line 149 "sql.y" { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0, TSDB_DB_TYPE_DEFAULT, -1); } +#line 2729 "sql.c" break; case 33: /* cmd ::= DROP TOPIC ifexists ids */ +#line 150 "sql.y" { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &yymsp[0].minor.yy0, &yymsp[-1].minor.yy0, TSDB_DB_TYPE_TOPIC, -1); } +#line 2734 "sql.c" break; case 34: /* cmd ::= DROP FUNCTION ids */ +#line 151 "sql.y" { setDropFuncInfo(pInfo, TSDB_SQL_DROP_FUNCTION, &yymsp[0].minor.yy0); } +#line 2739 "sql.c" break; case 35: /* cmd ::= DROP DNODE ids */ +#line 153 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &yymsp[0].minor.yy0); } +#line 2744 "sql.c" break; case 36: /* cmd ::= DROP USER ids */ +#line 154 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &yymsp[0].minor.yy0); } +#line 2749 "sql.c" break; case 37: /* cmd ::= DROP ACCOUNT ids */ +#line 155 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &yymsp[0].minor.yy0); } +#line 2754 "sql.c" break; case 38: /* cmd ::= USE ids */ +#line 158 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &yymsp[0].minor.yy0);} +#line 2759 "sql.c" break; case 39: /* cmd ::= DESCRIBE ids cpxName */ +#line 161 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &yymsp[-1].minor.yy0); } +#line 2767 "sql.c" break; case 40: /* cmd ::= ALTER USER ids PASS ids */ +#line 167 "sql.y" { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, NULL); } +#line 2772 "sql.c" break; case 41: /* cmd ::= ALTER USER ids PRIVILEGE ids */ +#line 168 "sql.y" { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &yymsp[-2].minor.yy0, NULL, &yymsp[0].minor.yy0);} +#line 2777 "sql.c" break; case 42: /* cmd ::= ALTER DNODE ids ids */ +#line 169 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +#line 2782 "sql.c" break; case 43: /* cmd ::= ALTER DNODE ids ids ids */ +#line 170 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &yymsp[-2].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +#line 2787 "sql.c" break; case 44: /* cmd ::= ALTER LOCAL ids */ +#line 171 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &yymsp[0].minor.yy0); } +#line 2792 "sql.c" break; case 45: /* cmd ::= ALTER LOCAL ids ids */ +#line 172 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } +#line 2797 "sql.c" break; case 46: /* cmd ::= ALTER DATABASE ids alter_db_optr */ case 47: /* cmd ::= ALTER TOPIC ids alter_topic_optr */ yytestcase(yyruleno==47); -{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy214, &t);} +#line 173 "sql.y" +{ SStrToken t = {0}; setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &t);} +#line 2803 "sql.c" break; case 48: /* cmd ::= ALTER ACCOUNT ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy547);} +#line 176 "sql.y" +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-1].minor.yy0, NULL, &yymsp[0].minor.yy341);} +#line 2808 "sql.c" break; case 49: /* cmd ::= ALTER ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy547);} +#line 177 "sql.y" +{ setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy341);} +#line 2813 "sql.c" break; case 50: /* cmd ::= COMPACT VNODES IN LP exprlist RP */ -{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy525);} +#line 181 "sql.y" +{ setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, yymsp[-1].minor.yy131);} +#line 2818 "sql.c" break; case 51: /* ids ::= ID */ case 52: /* ids ::= STRING */ yytestcase(yyruleno==52); +#line 187 "sql.y" {yylhsminor.yy0 = yymsp[0].minor.yy0; } +#line 2824 "sql.c" yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 53: /* ifexists ::= IF EXISTS */ +#line 191 "sql.y" { yymsp[-1].minor.yy0.n = 1;} +#line 2830 "sql.c" break; case 54: /* ifexists ::= */ case 56: /* ifnotexists ::= */ yytestcase(yyruleno==56); case 180: /* distinct ::= */ yytestcase(yyruleno==180); +#line 192 "sql.y" { yymsp[1].minor.yy0.n = 0;} +#line 2837 "sql.c" break; case 55: /* ifnotexists ::= IF NOT EXISTS */ +#line 195 "sql.y" { yymsp[-2].minor.yy0.n = 1;} +#line 2842 "sql.c" break; case 57: /* cmd ::= CREATE DNODE ids */ +#line 200 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &yymsp[0].minor.yy0);} +#line 2847 "sql.c" break; case 58: /* cmd ::= CREATE ACCOUNT ids PASS ids acct_optr */ -{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy547);} +#line 202 "sql.y" +{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy341);} +#line 2852 "sql.c" break; case 59: /* cmd ::= CREATE DATABASE ifnotexists ids db_optr */ case 60: /* cmd ::= CREATE TOPIC ifnotexists ids topic_optr */ yytestcase(yyruleno==60); -{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy214, &yymsp[-2].minor.yy0);} +#line 203 "sql.y" +{ setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy42, &yymsp[-2].minor.yy0);} +#line 2858 "sql.c" break; case 61: /* cmd ::= CREATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy31, &yymsp[0].minor.yy0, 1);} +#line 205 "sql.y" +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy163, &yymsp[0].minor.yy0, 1);} +#line 2863 "sql.c" break; case 62: /* cmd ::= CREATE AGGREGATE FUNCTION ids AS ids OUTPUTTYPE typename bufsize */ -{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy31, &yymsp[0].minor.yy0, 2);} +#line 206 "sql.y" +{ setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &yymsp[-5].minor.yy0, &yymsp[-3].minor.yy0, &yymsp[-1].minor.yy163, &yymsp[0].minor.yy0, 2);} +#line 2868 "sql.c" break; case 63: /* cmd ::= CREATE USER ids PASS ids */ +#line 207 "sql.y" { setCreateUserSql(pInfo, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0);} +#line 2873 "sql.c" break; case 64: /* bufsize ::= */ case 66: /* pps ::= */ yytestcase(yyruleno==66); @@ -2428,7 +2881,9 @@ static void yy_reduce( case 78: /* users ::= */ yytestcase(yyruleno==78); case 80: /* conns ::= */ yytestcase(yyruleno==80); case 82: /* state ::= */ yytestcase(yyruleno==82); +#line 209 "sql.y" { yymsp[1].minor.yy0.n = 0; } +#line 2887 "sql.c" break; case 65: /* bufsize ::= BUFSIZE INTEGER */ case 67: /* pps ::= PPS INTEGER */ yytestcase(yyruleno==67); @@ -2440,42 +2895,54 @@ static void yy_reduce( case 79: /* users ::= USERS INTEGER */ yytestcase(yyruleno==79); case 81: /* conns ::= CONNS INTEGER */ yytestcase(yyruleno==81); case 83: /* state ::= STATE ids */ yytestcase(yyruleno==83); +#line 210 "sql.y" { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } +#line 2901 "sql.c" break; case 84: /* acct_optr ::= pps tseries storage streams qtime dbs users conns state */ +#line 240 "sql.y" { - yylhsminor.yy547.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; - yylhsminor.yy547.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; - yylhsminor.yy547.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; - yylhsminor.yy547.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; - yylhsminor.yy547.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; - yylhsminor.yy547.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy547.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; - yylhsminor.yy547.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; - yylhsminor.yy547.stat = yymsp[0].minor.yy0; + yylhsminor.yy341.maxUsers = (yymsp[-2].minor.yy0.n>0)?atoi(yymsp[-2].minor.yy0.z):-1; + yylhsminor.yy341.maxDbs = (yymsp[-3].minor.yy0.n>0)?atoi(yymsp[-3].minor.yy0.z):-1; + yylhsminor.yy341.maxTimeSeries = (yymsp[-7].minor.yy0.n>0)?atoi(yymsp[-7].minor.yy0.z):-1; + yylhsminor.yy341.maxStreams = (yymsp[-5].minor.yy0.n>0)?atoi(yymsp[-5].minor.yy0.z):-1; + yylhsminor.yy341.maxPointsPerSecond = (yymsp[-8].minor.yy0.n>0)?atoi(yymsp[-8].minor.yy0.z):-1; + yylhsminor.yy341.maxStorage = (yymsp[-6].minor.yy0.n>0)?strtoll(yymsp[-6].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy341.maxQueryTime = (yymsp[-4].minor.yy0.n>0)?strtoll(yymsp[-4].minor.yy0.z, NULL, 10):-1; + yylhsminor.yy341.maxConnections = (yymsp[-1].minor.yy0.n>0)?atoi(yymsp[-1].minor.yy0.z):-1; + yylhsminor.yy341.stat = yymsp[0].minor.yy0; } - yymsp[-8].minor.yy547 = yylhsminor.yy547; +#line 2916 "sql.c" + yymsp[-8].minor.yy341 = yylhsminor.yy341; break; case 85: /* intitemlist ::= intitemlist COMMA intitem */ case 154: /* tagitemlist ::= tagitemlist COMMA tagitem */ yytestcase(yyruleno==154); -{ yylhsminor.yy525 = tVariantListAppend(yymsp[-2].minor.yy525, &yymsp[0].minor.yy506, -1); } - yymsp[-2].minor.yy525 = yylhsminor.yy525; +#line 256 "sql.y" +{ yylhsminor.yy131 = tVariantListAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy516, -1); } +#line 2923 "sql.c" + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; case 86: /* intitemlist ::= intitem */ case 155: /* tagitemlist ::= tagitem */ yytestcase(yyruleno==155); -{ yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); } - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 257 "sql.y" +{ yylhsminor.yy131 = tVariantListAppend(NULL, &yymsp[0].minor.yy516, -1); } +#line 2930 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 87: /* intitem ::= INTEGER */ case 156: /* tagitem ::= INTEGER */ yytestcase(yyruleno==156); case 157: /* tagitem ::= FLOAT */ yytestcase(yyruleno==157); case 158: /* tagitem ::= STRING */ yytestcase(yyruleno==158); case 159: /* tagitem ::= BOOL */ yytestcase(yyruleno==159); -{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy506 = yylhsminor.yy506; +#line 259 "sql.y" +{ toTSDBType(yymsp[0].minor.yy0.type); tVariantCreate(&yylhsminor.yy516, &yymsp[0].minor.yy0); } +#line 2940 "sql.c" + yymsp[0].minor.yy516 = yylhsminor.yy516; break; case 88: /* keep ::= KEEP intitemlist */ -{ yymsp[-1].minor.yy525 = yymsp[0].minor.yy525; } +#line 263 "sql.y" +{ yymsp[-1].minor.yy131 = yymsp[0].minor.yy131; } +#line 2946 "sql.c" break; case 89: /* cache ::= CACHE INTEGER */ case 90: /* replica ::= REPLICA INTEGER */ yytestcase(yyruleno==90); @@ -2492,639 +2959,912 @@ static void yy_reduce( case 101: /* update ::= UPDATE INTEGER */ yytestcase(yyruleno==101); case 102: /* cachelast ::= CACHELAST INTEGER */ yytestcase(yyruleno==102); case 103: /* partitions ::= PARTITIONS INTEGER */ yytestcase(yyruleno==103); +#line 265 "sql.y" { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } +#line 2965 "sql.c" break; case 104: /* db_optr ::= */ -{setDefaultCreateDbOption(&yymsp[1].minor.yy214); yymsp[1].minor.yy214.dbType = TSDB_DB_TYPE_DEFAULT;} +#line 282 "sql.y" +{setDefaultCreateDbOption(&yymsp[1].minor.yy42); yymsp[1].minor.yy42.dbType = TSDB_DB_TYPE_DEFAULT;} +#line 2970 "sql.c" break; case 105: /* db_optr ::= db_optr cache */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 284 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 2975 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 106: /* db_optr ::= db_optr replica */ case 123: /* alter_db_optr ::= alter_db_optr replica */ yytestcase(yyruleno==123); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 285 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.replica = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 2982 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 107: /* db_optr ::= db_optr quorum */ case 124: /* alter_db_optr ::= alter_db_optr quorum */ yytestcase(yyruleno==124); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 286 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.quorum = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 2989 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 108: /* db_optr ::= db_optr days */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 287 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.daysPerFile = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 2995 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 109: /* db_optr ::= db_optr minrows */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 288 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.minRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } +#line 3001 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 110: /* db_optr ::= db_optr maxrows */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 289 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.maxRowsPerBlock = strtod(yymsp[0].minor.yy0.z, NULL); } +#line 3007 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 111: /* db_optr ::= db_optr blocks */ case 126: /* alter_db_optr ::= alter_db_optr blocks */ yytestcase(yyruleno==126); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 290 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.numOfBlocks = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3014 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 112: /* db_optr ::= db_optr ctime */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 291 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.commitTime = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3020 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 113: /* db_optr ::= db_optr wal */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 292 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.walLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3026 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 114: /* db_optr ::= db_optr fsync */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 293 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.fsyncPeriod = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3032 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 115: /* db_optr ::= db_optr comp */ case 127: /* alter_db_optr ::= alter_db_optr comp */ yytestcase(yyruleno==127); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 294 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.compressionLevel = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3039 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 116: /* db_optr ::= db_optr prec */ -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.precision = yymsp[0].minor.yy0; } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 295 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.precision = yymsp[0].minor.yy0; } +#line 3045 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 117: /* db_optr ::= db_optr keep */ case 125: /* alter_db_optr ::= alter_db_optr keep */ yytestcase(yyruleno==125); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.keep = yymsp[0].minor.yy525; } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 296 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.keep = yymsp[0].minor.yy131; } +#line 3052 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 118: /* db_optr ::= db_optr update */ case 128: /* alter_db_optr ::= alter_db_optr update */ yytestcase(yyruleno==128); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 297 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.update = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3059 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 119: /* db_optr ::= db_optr cachelast */ case 129: /* alter_db_optr ::= alter_db_optr cachelast */ yytestcase(yyruleno==129); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 298 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.cachelast = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3066 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 120: /* topic_optr ::= db_optr */ case 130: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==130); -{ yylhsminor.yy214 = yymsp[0].minor.yy214; yylhsminor.yy214.dbType = TSDB_DB_TYPE_TOPIC; } - yymsp[0].minor.yy214 = yylhsminor.yy214; +#line 302 "sql.y" +{ yylhsminor.yy42 = yymsp[0].minor.yy42; yylhsminor.yy42.dbType = TSDB_DB_TYPE_TOPIC; } +#line 3073 "sql.c" + yymsp[0].minor.yy42 = yylhsminor.yy42; break; case 121: /* topic_optr ::= topic_optr partitions */ case 131: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==131); -{ yylhsminor.yy214 = yymsp[-1].minor.yy214; yylhsminor.yy214.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[-1].minor.yy214 = yylhsminor.yy214; +#line 303 "sql.y" +{ yylhsminor.yy42 = yymsp[-1].minor.yy42; yylhsminor.yy42.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3080 "sql.c" + yymsp[-1].minor.yy42 = yylhsminor.yy42; break; case 122: /* alter_db_optr ::= */ -{ setDefaultCreateDbOption(&yymsp[1].minor.yy214); yymsp[1].minor.yy214.dbType = TSDB_DB_TYPE_DEFAULT;} +#line 306 "sql.y" +{ setDefaultCreateDbOption(&yymsp[1].minor.yy42); yymsp[1].minor.yy42.dbType = TSDB_DB_TYPE_DEFAULT;} +#line 3086 "sql.c" break; case 132: /* typename ::= ids */ +#line 326 "sql.y" { yymsp[0].minor.yy0.type = 0; - tSetColumnType (&yylhsminor.yy31, &yymsp[0].minor.yy0); + tSetColumnType (&yylhsminor.yy163, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy31 = yylhsminor.yy31; +#line 3094 "sql.c" + yymsp[0].minor.yy163 = yylhsminor.yy163; break; case 133: /* typename ::= ids LP signed RP */ +#line 332 "sql.y" { - if (yymsp[-1].minor.yy501 <= 0) { + if (yymsp[-1].minor.yy459 <= 0) { yymsp[-3].minor.yy0.type = 0; - tSetColumnType(&yylhsminor.yy31, &yymsp[-3].minor.yy0); + tSetColumnType(&yylhsminor.yy163, &yymsp[-3].minor.yy0); } else { - yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy501; // negative value of name length - tSetColumnType(&yylhsminor.yy31, &yymsp[-3].minor.yy0); + yymsp[-3].minor.yy0.type = -yymsp[-1].minor.yy459; // negative value of name length + tSetColumnType(&yylhsminor.yy163, &yymsp[-3].minor.yy0); } } - yymsp[-3].minor.yy31 = yylhsminor.yy31; +#line 3108 "sql.c" + yymsp[-3].minor.yy163 = yylhsminor.yy163; break; case 134: /* typename ::= ids UNSIGNED */ +#line 343 "sql.y" { yymsp[-1].minor.yy0.type = 0; yymsp[-1].minor.yy0.n = ((yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z); - tSetColumnType (&yylhsminor.yy31, &yymsp[-1].minor.yy0); + tSetColumnType (&yylhsminor.yy163, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy31 = yylhsminor.yy31; +#line 3118 "sql.c" + yymsp[-1].minor.yy163 = yylhsminor.yy163; break; case 135: /* signed ::= INTEGER */ -{ yylhsminor.yy501 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } - yymsp[0].minor.yy501 = yylhsminor.yy501; +#line 350 "sql.y" +{ yylhsminor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3124 "sql.c" + yymsp[0].minor.yy459 = yylhsminor.yy459; break; case 136: /* signed ::= PLUS INTEGER */ -{ yymsp[-1].minor.yy501 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 351 "sql.y" +{ yymsp[-1].minor.yy459 = strtol(yymsp[0].minor.yy0.z, NULL, 10); } +#line 3130 "sql.c" break; case 137: /* signed ::= MINUS INTEGER */ -{ yymsp[-1].minor.yy501 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +#line 352 "sql.y" +{ yymsp[-1].minor.yy459 = -strtol(yymsp[0].minor.yy0.z, NULL, 10);} +#line 3135 "sql.c" break; case 141: /* cmd ::= CREATE TABLE create_table_list */ -{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy158;} +#line 358 "sql.y" +{ pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = yymsp[0].minor.yy272;} +#line 3140 "sql.c" break; case 142: /* create_table_list ::= create_from_stable */ +#line 362 "sql.y" { SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql)); pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo)); - taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy432); + taosArrayPush(pCreateTable->childTableInfo, &yymsp[0].minor.yy96); pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE; - yylhsminor.yy158 = pCreateTable; + yylhsminor.yy272 = pCreateTable; } - yymsp[0].minor.yy158 = yylhsminor.yy158; +#line 3152 "sql.c" + yymsp[0].minor.yy272 = yylhsminor.yy272; break; case 143: /* create_table_list ::= create_table_list create_from_stable */ +#line 371 "sql.y" { - taosArrayPush(yymsp[-1].minor.yy158->childTableInfo, &yymsp[0].minor.yy432); - yylhsminor.yy158 = yymsp[-1].minor.yy158; + taosArrayPush(yymsp[-1].minor.yy272->childTableInfo, &yymsp[0].minor.yy96); + yylhsminor.yy272 = yymsp[-1].minor.yy272; } - yymsp[-1].minor.yy158 = yylhsminor.yy158; +#line 3161 "sql.c" + yymsp[-1].minor.yy272 = yylhsminor.yy272; break; case 144: /* create_table_args ::= ifnotexists ids cpxName LP columnlist RP */ +#line 377 "sql.y" { - yylhsminor.yy158 = tSetCreateTableInfo(yymsp[-1].minor.yy525, NULL, NULL, TSQL_CREATE_TABLE); - setSqlInfo(pInfo, yylhsminor.yy158, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-1].minor.yy131, NULL, NULL, TSQL_CREATE_TABLE); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-4].minor.yy0, &yymsp[-5].minor.yy0); } - yymsp[-5].minor.yy158 = yylhsminor.yy158; +#line 3173 "sql.c" + yymsp[-5].minor.yy272 = yylhsminor.yy272; break; case 145: /* create_stable_args ::= ifnotexists ids cpxName LP columnlist RP TAGS LP columnlist RP */ +#line 387 "sql.y" { - yylhsminor.yy158 = tSetCreateTableInfo(yymsp[-5].minor.yy525, yymsp[-1].minor.yy525, NULL, TSQL_CREATE_STABLE); - setSqlInfo(pInfo, yylhsminor.yy158, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, NULL, TSQL_CREATE_STABLE); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy158 = yylhsminor.yy158; +#line 3185 "sql.c" + yymsp[-9].minor.yy272 = yylhsminor.yy272; break; case 146: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName TAGS LP tagitemlist RP */ +#line 398 "sql.y" { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; - yylhsminor.yy432 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy525, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); + yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-5].minor.yy0, NULL, yymsp[-1].minor.yy131, &yymsp[-8].minor.yy0, &yymsp[-9].minor.yy0); } - yymsp[-9].minor.yy432 = yylhsminor.yy432; +#line 3195 "sql.c" + yymsp[-9].minor.yy96 = yylhsminor.yy96; break; case 147: /* create_from_stable ::= ifnotexists ids cpxName USING ids cpxName LP tagNamelist RP TAGS LP tagitemlist RP */ +#line 404 "sql.y" { yymsp[-8].minor.yy0.n += yymsp[-7].minor.yy0.n; yymsp[-11].minor.yy0.n += yymsp[-10].minor.yy0.n; - yylhsminor.yy432 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy525, yymsp[-1].minor.yy525, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); + yylhsminor.yy96 = createNewChildTableInfo(&yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, yymsp[-1].minor.yy131, &yymsp[-11].minor.yy0, &yymsp[-12].minor.yy0); } - yymsp[-12].minor.yy432 = yylhsminor.yy432; +#line 3205 "sql.c" + yymsp[-12].minor.yy96 = yylhsminor.yy96; break; case 148: /* tagNamelist ::= tagNamelist COMMA ids */ -{taosArrayPush(yymsp[-2].minor.yy525, &yymsp[0].minor.yy0); yylhsminor.yy525 = yymsp[-2].minor.yy525; } - yymsp[-2].minor.yy525 = yylhsminor.yy525; +#line 412 "sql.y" +{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy0); yylhsminor.yy131 = yymsp[-2].minor.yy131; } +#line 3211 "sql.c" + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; case 149: /* tagNamelist ::= ids */ -{yylhsminor.yy525 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy525, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 413 "sql.y" +{yylhsminor.yy131 = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy0);} +#line 3217 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 150: /* create_table_args ::= ifnotexists ids cpxName AS select */ +#line 417 "sql.y" { - yylhsminor.yy158 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy464, TSQL_CREATE_STREAM); - setSqlInfo(pInfo, yylhsminor.yy158, NULL, TSDB_SQL_CREATE_TABLE); + yylhsminor.yy272 = tSetCreateTableInfo(NULL, NULL, yymsp[0].minor.yy256, TSQL_CREATE_STREAM); + setSqlInfo(pInfo, yylhsminor.yy272, NULL, TSDB_SQL_CREATE_TABLE); yymsp[-3].minor.yy0.n += yymsp[-2].minor.yy0.n; setCreatedTableName(pInfo, &yymsp[-3].minor.yy0, &yymsp[-4].minor.yy0); } - yymsp[-4].minor.yy158 = yylhsminor.yy158; +#line 3229 "sql.c" + yymsp[-4].minor.yy272 = yylhsminor.yy272; break; case 151: /* columnlist ::= columnlist COMMA column */ -{taosArrayPush(yymsp[-2].minor.yy525, &yymsp[0].minor.yy31); yylhsminor.yy525 = yymsp[-2].minor.yy525; } - yymsp[-2].minor.yy525 = yylhsminor.yy525; +#line 428 "sql.y" +{taosArrayPush(yymsp[-2].minor.yy131, &yymsp[0].minor.yy163); yylhsminor.yy131 = yymsp[-2].minor.yy131; } +#line 3235 "sql.c" + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; case 152: /* columnlist ::= column */ -{yylhsminor.yy525 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy525, &yymsp[0].minor.yy31);} - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 429 "sql.y" +{yylhsminor.yy131 = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(yylhsminor.yy131, &yymsp[0].minor.yy163);} +#line 3241 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 153: /* column ::= ids typename */ +#line 433 "sql.y" { - tSetColumnInfo(&yylhsminor.yy31, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy31); + tSetColumnInfo(&yylhsminor.yy163, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy163); } - yymsp[-1].minor.yy31 = yylhsminor.yy31; +#line 3249 "sql.c" + yymsp[-1].minor.yy163 = yylhsminor.yy163; break; case 160: /* tagitem ::= NULL */ -{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy506 = yylhsminor.yy506; +#line 448 "sql.y" +{ yymsp[0].minor.yy0.type = 0; tVariantCreate(&yylhsminor.yy516, &yymsp[0].minor.yy0); } +#line 3255 "sql.c" + yymsp[0].minor.yy516 = yylhsminor.yy516; break; case 161: /* tagitem ::= NOW */ -{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&yylhsminor.yy506, &yymsp[0].minor.yy0);} - yymsp[0].minor.yy506 = yylhsminor.yy506; +#line 449 "sql.y" +{ yymsp[0].minor.yy0.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreate(&yylhsminor.yy516, &yymsp[0].minor.yy0);} +#line 3261 "sql.c" + yymsp[0].minor.yy516 = yylhsminor.yy516; break; case 162: /* tagitem ::= MINUS INTEGER */ case 163: /* tagitem ::= MINUS FLOAT */ yytestcase(yyruleno==163); case 164: /* tagitem ::= PLUS INTEGER */ yytestcase(yyruleno==164); case 165: /* tagitem ::= PLUS FLOAT */ yytestcase(yyruleno==165); +#line 451 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = yymsp[0].minor.yy0.type; toTSDBType(yymsp[-1].minor.yy0.type); - tVariantCreate(&yylhsminor.yy506, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy516, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy506 = yylhsminor.yy506; +#line 3275 "sql.c" + yymsp[-1].minor.yy516 = yylhsminor.yy516; break; case 166: /* select ::= SELECT selcollist from where_opt interval_opt sliding_opt session_option windowstate_option fill_opt groupby_opt having_opt orderby_opt slimit_opt limit_opt */ +#line 482 "sql.y" { - yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy525, yymsp[-11].minor.yy412, yymsp[-10].minor.yy370, yymsp[-4].minor.yy525, yymsp[-2].minor.yy525, &yymsp[-9].minor.yy520, &yymsp[-7].minor.yy259, &yymsp[-6].minor.yy144, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy525, &yymsp[0].minor.yy126, &yymsp[-1].minor.yy126, yymsp[-3].minor.yy370); + yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-13].minor.yy0, yymsp[-12].minor.yy131, yymsp[-11].minor.yy544, yymsp[-10].minor.yy46, yymsp[-4].minor.yy131, yymsp[-2].minor.yy131, &yymsp[-9].minor.yy530, &yymsp[-7].minor.yy39, &yymsp[-6].minor.yy538, &yymsp[-8].minor.yy0, yymsp[-5].minor.yy131, &yymsp[0].minor.yy284, &yymsp[-1].minor.yy284, yymsp[-3].minor.yy46); } - yymsp[-13].minor.yy464 = yylhsminor.yy464; +#line 3283 "sql.c" + yymsp[-13].minor.yy256 = yylhsminor.yy256; break; case 167: /* select ::= LP select RP */ -{yymsp[-2].minor.yy464 = yymsp[-1].minor.yy464;} +#line 486 "sql.y" +{yymsp[-2].minor.yy256 = yymsp[-1].minor.yy256;} +#line 3289 "sql.c" break; case 168: /* union ::= select */ -{ yylhsminor.yy525 = setSubclause(NULL, yymsp[0].minor.yy464); } - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 490 "sql.y" +{ yylhsminor.yy131 = setSubclause(NULL, yymsp[0].minor.yy256); } +#line 3294 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 169: /* union ::= union UNION ALL select */ -{ yylhsminor.yy525 = appendSelectClause(yymsp[-3].minor.yy525, yymsp[0].minor.yy464); } - yymsp[-3].minor.yy525 = yylhsminor.yy525; +#line 491 "sql.y" +{ yylhsminor.yy131 = appendSelectClause(yymsp[-3].minor.yy131, yymsp[0].minor.yy256); } +#line 3300 "sql.c" + yymsp[-3].minor.yy131 = yylhsminor.yy131; break; case 170: /* cmd ::= union */ -{ setSqlInfo(pInfo, yymsp[0].minor.yy525, NULL, TSDB_SQL_SELECT); } +#line 493 "sql.y" +{ setSqlInfo(pInfo, yymsp[0].minor.yy131, NULL, TSDB_SQL_SELECT); } +#line 3306 "sql.c" break; case 171: /* select ::= SELECT selcollist */ +#line 500 "sql.y" { - yylhsminor.yy464 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy525, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + yylhsminor.yy256 = tSetQuerySqlNode(&yymsp[-1].minor.yy0, yymsp[0].minor.yy131, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); } - yymsp[-1].minor.yy464 = yylhsminor.yy464; +#line 3313 "sql.c" + yymsp[-1].minor.yy256 = yylhsminor.yy256; break; case 172: /* sclp ::= selcollist COMMA */ -{yylhsminor.yy525 = yymsp[-1].minor.yy525;} - yymsp[-1].minor.yy525 = yylhsminor.yy525; +#line 512 "sql.y" +{yylhsminor.yy131 = yymsp[-1].minor.yy131;} +#line 3319 "sql.c" + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; case 173: /* sclp ::= */ case 203: /* orderby_opt ::= */ yytestcase(yyruleno==203); -{yymsp[1].minor.yy525 = 0;} +#line 513 "sql.y" +{yymsp[1].minor.yy131 = 0;} +#line 3326 "sql.c" break; case 174: /* selcollist ::= sclp distinct expr as */ +#line 514 "sql.y" { - yylhsminor.yy525 = tSqlExprListAppend(yymsp[-3].minor.yy525, yymsp[-1].minor.yy370, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); + yylhsminor.yy131 = tSqlExprListAppend(yymsp[-3].minor.yy131, yymsp[-1].minor.yy46, yymsp[-2].minor.yy0.n? &yymsp[-2].minor.yy0:0, yymsp[0].minor.yy0.n?&yymsp[0].minor.yy0:0); } - yymsp[-3].minor.yy525 = yylhsminor.yy525; +#line 3333 "sql.c" + yymsp[-3].minor.yy131 = yylhsminor.yy131; break; case 175: /* selcollist ::= sclp STAR */ +#line 518 "sql.y" { tSqlExpr *pNode = tSqlExprCreateIdValue(NULL, TK_ALL); - yylhsminor.yy525 = tSqlExprListAppend(yymsp[-1].minor.yy525, pNode, 0, 0); + yylhsminor.yy131 = tSqlExprListAppend(yymsp[-1].minor.yy131, pNode, 0, 0); } - yymsp[-1].minor.yy525 = yylhsminor.yy525; +#line 3342 "sql.c" + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; case 176: /* as ::= AS ids */ +#line 526 "sql.y" { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } +#line 3348 "sql.c" break; case 177: /* as ::= ids */ +#line 527 "sql.y" { yylhsminor.yy0 = yymsp[0].minor.yy0; } +#line 3353 "sql.c" yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 178: /* as ::= */ +#line 528 "sql.y" { yymsp[1].minor.yy0.n = 0; } +#line 3359 "sql.c" break; case 179: /* distinct ::= DISTINCT */ +#line 531 "sql.y" { yylhsminor.yy0 = yymsp[0].minor.yy0; } +#line 3364 "sql.c" yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 181: /* from ::= FROM tablelist */ case 182: /* from ::= FROM sub */ yytestcase(yyruleno==182); -{yymsp[-1].minor.yy412 = yymsp[0].minor.yy412;} +#line 537 "sql.y" +{yymsp[-1].minor.yy544 = yymsp[0].minor.yy544;} +#line 3371 "sql.c" break; case 183: /* sub ::= LP union RP */ -{yymsp[-2].minor.yy412 = addSubqueryElem(NULL, yymsp[-1].minor.yy525, NULL);} +#line 542 "sql.y" +{yymsp[-2].minor.yy544 = addSubqueryElem(NULL, yymsp[-1].minor.yy131, NULL);} +#line 3376 "sql.c" break; case 184: /* sub ::= LP union RP ids */ -{yymsp[-3].minor.yy412 = addSubqueryElem(NULL, yymsp[-2].minor.yy525, &yymsp[0].minor.yy0);} +#line 543 "sql.y" +{yymsp[-3].minor.yy544 = addSubqueryElem(NULL, yymsp[-2].minor.yy131, &yymsp[0].minor.yy0);} +#line 3381 "sql.c" break; case 185: /* sub ::= sub COMMA LP union RP ids */ -{yylhsminor.yy412 = addSubqueryElem(yymsp[-5].minor.yy412, yymsp[-2].minor.yy525, &yymsp[0].minor.yy0);} - yymsp[-5].minor.yy412 = yylhsminor.yy412; +#line 544 "sql.y" +{yylhsminor.yy544 = addSubqueryElem(yymsp[-5].minor.yy544, yymsp[-2].minor.yy131, &yymsp[0].minor.yy0);} +#line 3386 "sql.c" + yymsp[-5].minor.yy544 = yylhsminor.yy544; break; case 186: /* tablelist ::= ids cpxName */ +#line 548 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy412 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-1].minor.yy0, NULL); } - yymsp[-1].minor.yy412 = yylhsminor.yy412; +#line 3395 "sql.c" + yymsp[-1].minor.yy544 = yylhsminor.yy544; break; case 187: /* tablelist ::= ids cpxName ids */ +#line 553 "sql.y" { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy412 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy544 = setTableNameList(NULL, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy412 = yylhsminor.yy412; +#line 3404 "sql.c" + yymsp[-2].minor.yy544 = yylhsminor.yy544; break; case 188: /* tablelist ::= tablelist COMMA ids cpxName */ +#line 558 "sql.y" { yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - yylhsminor.yy412 = setTableNameList(yymsp[-3].minor.yy412, &yymsp[-1].minor.yy0, NULL); + yylhsminor.yy544 = setTableNameList(yymsp[-3].minor.yy544, &yymsp[-1].minor.yy0, NULL); } - yymsp[-3].minor.yy412 = yylhsminor.yy412; +#line 3413 "sql.c" + yymsp[-3].minor.yy544 = yylhsminor.yy544; break; case 189: /* tablelist ::= tablelist COMMA ids cpxName ids */ +#line 563 "sql.y" { yymsp[-2].minor.yy0.n += yymsp[-1].minor.yy0.n; - yylhsminor.yy412 = setTableNameList(yymsp[-4].minor.yy412, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); + yylhsminor.yy544 = setTableNameList(yymsp[-4].minor.yy544, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } - yymsp[-4].minor.yy412 = yylhsminor.yy412; +#line 3422 "sql.c" + yymsp[-4].minor.yy544 = yylhsminor.yy544; break; case 190: /* tmvar ::= VARIABLE */ +#line 570 "sql.y" {yylhsminor.yy0 = yymsp[0].minor.yy0;} +#line 3428 "sql.c" yymsp[0].minor.yy0 = yylhsminor.yy0; break; case 191: /* interval_opt ::= INTERVAL LP tmvar RP */ -{yymsp[-3].minor.yy520.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy520.offset.n = 0;} +#line 573 "sql.y" +{yymsp[-3].minor.yy530.interval = yymsp[-1].minor.yy0; yymsp[-3].minor.yy530.offset.n = 0;} +#line 3434 "sql.c" break; case 192: /* interval_opt ::= INTERVAL LP tmvar COMMA tmvar RP */ -{yymsp[-5].minor.yy520.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy520.offset = yymsp[-1].minor.yy0;} +#line 574 "sql.y" +{yymsp[-5].minor.yy530.interval = yymsp[-3].minor.yy0; yymsp[-5].minor.yy530.offset = yymsp[-1].minor.yy0;} +#line 3439 "sql.c" break; case 193: /* interval_opt ::= */ -{memset(&yymsp[1].minor.yy520, 0, sizeof(yymsp[1].minor.yy520));} +#line 575 "sql.y" +{memset(&yymsp[1].minor.yy530, 0, sizeof(yymsp[1].minor.yy530));} +#line 3444 "sql.c" break; case 194: /* session_option ::= */ -{yymsp[1].minor.yy259.col.n = 0; yymsp[1].minor.yy259.gap.n = 0;} +#line 578 "sql.y" +{yymsp[1].minor.yy39.col.n = 0; yymsp[1].minor.yy39.gap.n = 0;} +#line 3449 "sql.c" break; case 195: /* session_option ::= SESSION LP ids cpxName COMMA tmvar RP */ +#line 579 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - yymsp[-6].minor.yy259.col = yymsp[-4].minor.yy0; - yymsp[-6].minor.yy259.gap = yymsp[-1].minor.yy0; + yymsp[-6].minor.yy39.col = yymsp[-4].minor.yy0; + yymsp[-6].minor.yy39.gap = yymsp[-1].minor.yy0; } +#line 3458 "sql.c" break; case 196: /* windowstate_option ::= */ -{ yymsp[1].minor.yy144.col.n = 0; yymsp[1].minor.yy144.col.z = NULL;} +#line 585 "sql.y" +{ yymsp[1].minor.yy538.col.n = 0; yymsp[1].minor.yy538.col.z = NULL;} +#line 3463 "sql.c" break; case 197: /* windowstate_option ::= STATE_WINDOW LP ids RP */ -{ yymsp[-3].minor.yy144.col = yymsp[-1].minor.yy0; } +#line 586 "sql.y" +{ yymsp[-3].minor.yy538.col = yymsp[-1].minor.yy0; } +#line 3468 "sql.c" break; case 198: /* fill_opt ::= */ -{ yymsp[1].minor.yy525 = 0; } +#line 590 "sql.y" +{ yymsp[1].minor.yy131 = 0; } +#line 3473 "sql.c" break; case 199: /* fill_opt ::= FILL LP ID COMMA tagitemlist RP */ +#line 591 "sql.y" { tVariant A = {0}; toTSDBType(yymsp[-3].minor.yy0.type); tVariantCreate(&A, &yymsp[-3].minor.yy0); - tVariantListInsert(yymsp[-1].minor.yy525, &A, -1, 0); - yymsp[-5].minor.yy525 = yymsp[-1].minor.yy525; + tVariantListInsert(yymsp[-1].minor.yy131, &A, -1, 0); + yymsp[-5].minor.yy131 = yymsp[-1].minor.yy131; } +#line 3485 "sql.c" break; case 200: /* fill_opt ::= FILL LP ID RP */ +#line 600 "sql.y" { toTSDBType(yymsp[-1].minor.yy0.type); - yymsp[-3].minor.yy525 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); + yymsp[-3].minor.yy131 = tVariantListAppendToken(NULL, &yymsp[-1].minor.yy0, -1); } +#line 3493 "sql.c" break; case 201: /* sliding_opt ::= SLIDING LP tmvar RP */ +#line 606 "sql.y" {yymsp[-3].minor.yy0 = yymsp[-1].minor.yy0; } +#line 3498 "sql.c" break; case 202: /* sliding_opt ::= */ +#line 607 "sql.y" {yymsp[1].minor.yy0.n = 0; yymsp[1].minor.yy0.z = NULL; yymsp[1].minor.yy0.type = 0; } +#line 3503 "sql.c" break; case 204: /* orderby_opt ::= ORDER BY sortlist */ -{yymsp[-2].minor.yy525 = yymsp[0].minor.yy525;} +#line 619 "sql.y" +{yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} +#line 3508 "sql.c" break; case 205: /* sortlist ::= sortlist COMMA item sortorder */ +#line 621 "sql.y" { - yylhsminor.yy525 = tVariantListAppend(yymsp[-3].minor.yy525, &yymsp[-1].minor.yy506, yymsp[0].minor.yy52); + yylhsminor.yy131 = tVariantListAppend(yymsp[-3].minor.yy131, &yymsp[-1].minor.yy516, yymsp[0].minor.yy43); } - yymsp[-3].minor.yy525 = yylhsminor.yy525; +#line 3515 "sql.c" + yymsp[-3].minor.yy131 = yylhsminor.yy131; break; case 206: /* sortlist ::= item sortorder */ +#line 625 "sql.y" { - yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[-1].minor.yy506, yymsp[0].minor.yy52); + yylhsminor.yy131 = tVariantListAppend(NULL, &yymsp[-1].minor.yy516, yymsp[0].minor.yy43); } - yymsp[-1].minor.yy525 = yylhsminor.yy525; +#line 3523 "sql.c" + yymsp[-1].minor.yy131 = yylhsminor.yy131; break; case 207: /* item ::= ids cpxName */ +#line 630 "sql.y" { toTSDBType(yymsp[-1].minor.yy0.type); yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; - tVariantCreate(&yylhsminor.yy506, &yymsp[-1].minor.yy0); + tVariantCreate(&yylhsminor.yy516, &yymsp[-1].minor.yy0); } - yymsp[-1].minor.yy506 = yylhsminor.yy506; +#line 3534 "sql.c" + yymsp[-1].minor.yy516 = yylhsminor.yy516; break; case 208: /* sortorder ::= ASC */ -{ yymsp[0].minor.yy52 = TSDB_ORDER_ASC; } +#line 638 "sql.y" +{ yymsp[0].minor.yy43 = TSDB_ORDER_ASC; } +#line 3540 "sql.c" break; case 209: /* sortorder ::= DESC */ -{ yymsp[0].minor.yy52 = TSDB_ORDER_DESC;} +#line 639 "sql.y" +{ yymsp[0].minor.yy43 = TSDB_ORDER_DESC;} +#line 3545 "sql.c" break; case 210: /* sortorder ::= */ -{ yymsp[1].minor.yy52 = TSDB_ORDER_ASC; } +#line 640 "sql.y" +{ yymsp[1].minor.yy43 = TSDB_ORDER_ASC; } +#line 3550 "sql.c" break; case 211: /* groupby_opt ::= */ -{ yymsp[1].minor.yy525 = 0;} +#line 648 "sql.y" +{ yymsp[1].minor.yy131 = 0;} +#line 3555 "sql.c" break; case 212: /* groupby_opt ::= GROUP BY grouplist */ -{ yymsp[-2].minor.yy525 = yymsp[0].minor.yy525;} +#line 649 "sql.y" +{ yymsp[-2].minor.yy131 = yymsp[0].minor.yy131;} +#line 3560 "sql.c" break; case 213: /* grouplist ::= grouplist COMMA item */ +#line 651 "sql.y" { - yylhsminor.yy525 = tVariantListAppend(yymsp[-2].minor.yy525, &yymsp[0].minor.yy506, -1); + yylhsminor.yy131 = tVariantListAppend(yymsp[-2].minor.yy131, &yymsp[0].minor.yy516, -1); } - yymsp[-2].minor.yy525 = yylhsminor.yy525; +#line 3567 "sql.c" + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; case 214: /* grouplist ::= item */ +#line 655 "sql.y" { - yylhsminor.yy525 = tVariantListAppend(NULL, &yymsp[0].minor.yy506, -1); + yylhsminor.yy131 = tVariantListAppend(NULL, &yymsp[0].minor.yy516, -1); } - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 3575 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 215: /* having_opt ::= */ case 225: /* where_opt ::= */ yytestcase(yyruleno==225); case 267: /* expritem ::= */ yytestcase(yyruleno==267); -{yymsp[1].minor.yy370 = 0;} +#line 662 "sql.y" +{yymsp[1].minor.yy46 = 0;} +#line 3583 "sql.c" break; case 216: /* having_opt ::= HAVING expr */ case 226: /* where_opt ::= WHERE expr */ yytestcase(yyruleno==226); -{yymsp[-1].minor.yy370 = yymsp[0].minor.yy370;} +#line 663 "sql.y" +{yymsp[-1].minor.yy46 = yymsp[0].minor.yy46;} +#line 3589 "sql.c" break; case 217: /* limit_opt ::= */ case 221: /* slimit_opt ::= */ yytestcase(yyruleno==221); -{yymsp[1].minor.yy126.limit = -1; yymsp[1].minor.yy126.offset = 0;} +#line 667 "sql.y" +{yymsp[1].minor.yy284.limit = -1; yymsp[1].minor.yy284.offset = 0;} +#line 3595 "sql.c" break; case 218: /* limit_opt ::= LIMIT signed */ case 222: /* slimit_opt ::= SLIMIT signed */ yytestcase(yyruleno==222); -{yymsp[-1].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-1].minor.yy126.offset = 0;} +#line 668 "sql.y" +{yymsp[-1].minor.yy284.limit = yymsp[0].minor.yy459; yymsp[-1].minor.yy284.offset = 0;} +#line 3601 "sql.c" break; case 219: /* limit_opt ::= LIMIT signed OFFSET signed */ -{ yymsp[-3].minor.yy126.limit = yymsp[-2].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[0].minor.yy501;} +#line 670 "sql.y" +{ yymsp[-3].minor.yy284.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy284.offset = yymsp[0].minor.yy459;} +#line 3606 "sql.c" break; case 220: /* limit_opt ::= LIMIT signed COMMA signed */ -{ yymsp[-3].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[-2].minor.yy501;} +#line 672 "sql.y" +{ yymsp[-3].minor.yy284.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy284.offset = yymsp[-2].minor.yy459;} +#line 3611 "sql.c" break; case 223: /* slimit_opt ::= SLIMIT signed SOFFSET signed */ -{yymsp[-3].minor.yy126.limit = yymsp[-2].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[0].minor.yy501;} +#line 678 "sql.y" +{yymsp[-3].minor.yy284.limit = yymsp[-2].minor.yy459; yymsp[-3].minor.yy284.offset = yymsp[0].minor.yy459;} +#line 3616 "sql.c" break; case 224: /* slimit_opt ::= SLIMIT signed COMMA signed */ -{yymsp[-3].minor.yy126.limit = yymsp[0].minor.yy501; yymsp[-3].minor.yy126.offset = yymsp[-2].minor.yy501;} +#line 680 "sql.y" +{yymsp[-3].minor.yy284.limit = yymsp[0].minor.yy459; yymsp[-3].minor.yy284.offset = yymsp[-2].minor.yy459;} +#line 3621 "sql.c" break; case 227: /* expr ::= LP expr RP */ -{yylhsminor.yy370 = yymsp[-1].minor.yy370; yylhsminor.yy370->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy370->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 693 "sql.y" +{yylhsminor.yy46 = yymsp[-1].minor.yy46; yylhsminor.yy46->exprToken.z = yymsp[-2].minor.yy0.z; yylhsminor.yy46->exprToken.n = (yymsp[0].minor.yy0.z - yymsp[-2].minor.yy0.z + 1);} +#line 3626 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 228: /* expr ::= ID */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 695 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_ID);} +#line 3632 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 229: /* expr ::= ID DOT ID */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 696 "sql.y" +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ID);} +#line 3638 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 230: /* expr ::= ID DOT STAR */ -{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 697 "sql.y" +{ yymsp[-2].minor.yy0.n += (1+yymsp[0].minor.yy0.n); yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-2].minor.yy0, TK_ALL);} +#line 3644 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 231: /* expr ::= INTEGER */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 699 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_INTEGER);} +#line 3650 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 232: /* expr ::= MINUS INTEGER */ case 233: /* expr ::= PLUS INTEGER */ yytestcase(yyruleno==233); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} - yymsp[-1].minor.yy370 = yylhsminor.yy370; +#line 700 "sql.y" +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_INTEGER; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_INTEGER);} +#line 3657 "sql.c" + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; case 234: /* expr ::= FLOAT */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 702 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_FLOAT);} +#line 3663 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 235: /* expr ::= MINUS FLOAT */ case 236: /* expr ::= PLUS FLOAT */ yytestcase(yyruleno==236); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} - yymsp[-1].minor.yy370 = yylhsminor.yy370; +#line 703 "sql.y" +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_FLOAT; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_FLOAT);} +#line 3670 "sql.c" + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; case 237: /* expr ::= STRING */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 705 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_STRING);} +#line 3676 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 238: /* expr ::= NOW */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 706 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NOW); } +#line 3682 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 239: /* expr ::= VARIABLE */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 707 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_VARIABLE);} +#line 3688 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 240: /* expr ::= PLUS VARIABLE */ case 241: /* expr ::= MINUS VARIABLE */ yytestcase(yyruleno==241); -{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} - yymsp[-1].minor.yy370 = yylhsminor.yy370; +#line 708 "sql.y" +{ yymsp[-1].minor.yy0.n += yymsp[0].minor.yy0.n; yymsp[-1].minor.yy0.type = TK_VARIABLE; yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[-1].minor.yy0, TK_VARIABLE);} +#line 3695 "sql.c" + yymsp[-1].minor.yy46 = yylhsminor.yy46; break; case 242: /* expr ::= BOOL */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 710 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_BOOL);} +#line 3701 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 243: /* expr ::= NULL */ -{ yylhsminor.yy370 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 711 "sql.y" +{ yylhsminor.yy46 = tSqlExprCreateIdValue(&yymsp[0].minor.yy0, TK_NULL);} +#line 3707 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 244: /* expr ::= ID LP exprlist RP */ -{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy370 = tSqlExprCreateFunction(yymsp[-1].minor.yy525, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy370 = yylhsminor.yy370; +#line 714 "sql.y" +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(yymsp[-1].minor.yy131, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } +#line 3713 "sql.c" + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; case 245: /* expr ::= ID LP STAR RP */ -{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy370 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } - yymsp[-3].minor.yy370 = yylhsminor.yy370; +#line 717 "sql.y" +{ tStrTokenAppend(pInfo->funcs, &yymsp[-3].minor.yy0); yylhsminor.yy46 = tSqlExprCreateFunction(NULL, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, yymsp[-3].minor.yy0.type); } +#line 3719 "sql.c" + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; case 246: /* expr ::= expr IS NULL */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, NULL, TK_ISNULL);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 720 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, NULL, TK_ISNULL);} +#line 3725 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 247: /* expr ::= expr IS NOT NULL */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-3].minor.yy370, NULL, TK_NOTNULL);} - yymsp[-3].minor.yy370 = yylhsminor.yy370; +#line 721 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-3].minor.yy46, NULL, TK_NOTNULL);} +#line 3731 "sql.c" + yymsp[-3].minor.yy46 = yylhsminor.yy46; break; case 248: /* expr ::= expr LT expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LT);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 724 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LT);} +#line 3737 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 249: /* expr ::= expr GT expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_GT);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 725 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GT);} +#line 3743 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 250: /* expr ::= expr LE expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LE);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 726 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LE);} +#line 3749 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 251: /* expr ::= expr GE expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_GE);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 727 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_GE);} +#line 3755 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 252: /* expr ::= expr NE expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_NE);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 728 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_NE);} +#line 3761 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 253: /* expr ::= expr EQ expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_EQ);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 729 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_EQ);} +#line 3767 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 254: /* expr ::= expr BETWEEN expr AND expr */ -{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy370); yylhsminor.yy370 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy370, yymsp[-2].minor.yy370, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy370, TK_LE), TK_AND);} - yymsp[-4].minor.yy370 = yylhsminor.yy370; +#line 731 "sql.y" +{ tSqlExpr* X2 = tSqlExprClone(yymsp[-4].minor.yy46); yylhsminor.yy46 = tSqlExprCreate(tSqlExprCreate(yymsp[-4].minor.yy46, yymsp[-2].minor.yy46, TK_GE), tSqlExprCreate(X2, yymsp[0].minor.yy46, TK_LE), TK_AND);} +#line 3773 "sql.c" + yymsp[-4].minor.yy46 = yylhsminor.yy46; break; case 255: /* expr ::= expr AND expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_AND);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 733 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_AND);} +#line 3779 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 256: /* expr ::= expr OR expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_OR); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 734 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_OR); } +#line 3785 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 257: /* expr ::= expr PLUS expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_PLUS); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 737 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_PLUS); } +#line 3791 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 258: /* expr ::= expr MINUS expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_MINUS); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 738 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_MINUS); } +#line 3797 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 259: /* expr ::= expr STAR expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_STAR); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 739 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_STAR); } +#line 3803 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 260: /* expr ::= expr SLASH expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_DIVIDE);} - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 740 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_DIVIDE);} +#line 3809 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 261: /* expr ::= expr REM expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_REM); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 741 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_REM); } +#line 3815 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 262: /* expr ::= expr LIKE expr */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-2].minor.yy370, yymsp[0].minor.yy370, TK_LIKE); } - yymsp[-2].minor.yy370 = yylhsminor.yy370; +#line 744 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-2].minor.yy46, yymsp[0].minor.yy46, TK_LIKE); } +#line 3821 "sql.c" + yymsp[-2].minor.yy46 = yylhsminor.yy46; break; case 263: /* expr ::= expr IN LP exprlist RP */ -{yylhsminor.yy370 = tSqlExprCreate(yymsp[-4].minor.yy370, (tSqlExpr*)yymsp[-1].minor.yy525, TK_IN); } - yymsp[-4].minor.yy370 = yylhsminor.yy370; +#line 747 "sql.y" +{yylhsminor.yy46 = tSqlExprCreate(yymsp[-4].minor.yy46, (tSqlExpr*)yymsp[-1].minor.yy131, TK_IN); } +#line 3827 "sql.c" + yymsp[-4].minor.yy46 = yylhsminor.yy46; break; case 264: /* exprlist ::= exprlist COMMA expritem */ -{yylhsminor.yy525 = tSqlExprListAppend(yymsp[-2].minor.yy525,yymsp[0].minor.yy370,0, 0);} - yymsp[-2].minor.yy525 = yylhsminor.yy525; +#line 755 "sql.y" +{yylhsminor.yy131 = tSqlExprListAppend(yymsp[-2].minor.yy131,yymsp[0].minor.yy46,0, 0);} +#line 3833 "sql.c" + yymsp[-2].minor.yy131 = yylhsminor.yy131; break; case 265: /* exprlist ::= expritem */ -{yylhsminor.yy525 = tSqlExprListAppend(0,yymsp[0].minor.yy370,0, 0);} - yymsp[0].minor.yy525 = yylhsminor.yy525; +#line 756 "sql.y" +{yylhsminor.yy131 = tSqlExprListAppend(0,yymsp[0].minor.yy46,0, 0);} +#line 3839 "sql.c" + yymsp[0].minor.yy131 = yylhsminor.yy131; break; case 266: /* expritem ::= expr */ -{yylhsminor.yy370 = yymsp[0].minor.yy370;} - yymsp[0].minor.yy370 = yylhsminor.yy370; +#line 757 "sql.y" +{yylhsminor.yy46 = yymsp[0].minor.yy46;} +#line 3845 "sql.c" + yymsp[0].minor.yy46 = yylhsminor.yy46; break; case 268: /* cmd ::= RESET QUERY CACHE */ +#line 761 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);} +#line 3851 "sql.c" break; case 269: /* cmd ::= SYNCDB ids REPLICA */ +#line 764 "sql.y" { setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &yymsp[-1].minor.yy0);} +#line 3856 "sql.c" break; case 270: /* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */ +#line 767 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3865 "sql.c" break; case 271: /* cmd ::= ALTER TABLE ids cpxName DROP COLUMN ids */ +#line 773 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3134,22 +3874,28 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3878 "sql.c" break; case 272: /* cmd ::= ALTER TABLE ids cpxName MODIFY COLUMN columnlist */ +#line 783 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3887 "sql.c" break; case 273: /* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */ +#line 790 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3896 "sql.c" break; case 274: /* cmd ::= ALTER TABLE ids cpxName DROP TAG ids */ +#line 795 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3159,8 +3905,10 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3909 "sql.c" break; case 275: /* cmd ::= ALTER TABLE ids cpxName CHANGE TAG ids ids */ +#line 805 "sql.y" { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3173,34 +3921,42 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3925 "sql.c" break; case 276: /* cmd ::= ALTER TABLE ids cpxName SET TAG ids EQ tagitem */ +#line 818 "sql.y" { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy506, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy516, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3939 "sql.c" break; case 277: /* cmd ::= ALTER TABLE ids cpxName MODIFY TAG columnlist */ +#line 829 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3948 "sql.c" break; case 278: /* cmd ::= ALTER STABLE ids cpxName ADD COLUMN columnlist */ +#line 836 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3957 "sql.c" break; case 279: /* cmd ::= ALTER STABLE ids cpxName DROP COLUMN ids */ +#line 842 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3210,22 +3966,28 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3970 "sql.c" break; case 280: /* cmd ::= ALTER STABLE ids cpxName MODIFY COLUMN columnlist */ +#line 852 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3979 "sql.c" break; case 281: /* cmd ::= ALTER STABLE ids cpxName ADD TAG columnlist */ +#line 859 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 3988 "sql.c" break; case 282: /* cmd ::= ALTER STABLE ids cpxName DROP TAG ids */ +#line 864 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; @@ -3235,8 +3997,10 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 4001 "sql.c" break; case 283: /* cmd ::= ALTER STABLE ids cpxName CHANGE TAG ids ids */ +#line 874 "sql.y" { yymsp[-5].minor.yy0.n += yymsp[-4].minor.yy0.n; @@ -3249,42 +4013,53 @@ static void yy_reduce( SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-5].minor.yy0, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 4017 "sql.c" break; case 284: /* cmd ::= ALTER STABLE ids cpxName SET TAG ids EQ tagitem */ +#line 887 "sql.y" { yymsp[-6].minor.yy0.n += yymsp[-5].minor.yy0.n; toTSDBType(yymsp[-2].minor.yy0.type); SArray* A = tVariantListAppendToken(NULL, &yymsp[-2].minor.yy0, -1); - A = tVariantListAppend(A, &yymsp[0].minor.yy506, -1); + A = tVariantListAppend(A, &yymsp[0].minor.yy516, -1); SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-6].minor.yy0, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 4031 "sql.c" break; case 285: /* cmd ::= ALTER STABLE ids cpxName MODIFY TAG columnlist */ +#line 898 "sql.y" { yymsp[-4].minor.yy0.n += yymsp[-3].minor.yy0.n; - SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy525, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); + SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&yymsp[-4].minor.yy0, yymsp[0].minor.yy131, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE); setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE); } +#line 4040 "sql.c" break; case 286: /* cmd ::= KILL CONNECTION INTEGER */ +#line 905 "sql.y" {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &yymsp[0].minor.yy0);} +#line 4045 "sql.c" break; case 287: /* cmd ::= KILL STREAM INTEGER COLON INTEGER */ +#line 906 "sql.y" {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &yymsp[-2].minor.yy0);} +#line 4050 "sql.c" break; case 288: /* cmd ::= KILL QUERY INTEGER COLON INTEGER */ +#line 907 "sql.y" {yymsp[-2].minor.yy0.n += (yymsp[-1].minor.yy0.n + yymsp[0].minor.yy0.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &yymsp[-2].minor.yy0);} +#line 4055 "sql.c" break; default: break; /********** End reduce actions ************************************************/ }; - assert( yyrulenostateno = (YYACTIONTYPE)yyact; yymsp->major = (YYCODETYPE)yygoto; yyTraceShift(yypParser, yyact, "... then shift"); + return yyact; } /* @@ -3308,7 +4084,8 @@ static void yy_reduce( static void yy_parse_failed( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt); @@ -3319,7 +4096,8 @@ static void yy_parse_failed( ** parser fails */ /************ Begin %parse_failure code ***************************************/ /************ End %parse_failure code *****************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } #endif /* YYNOERRORRECOVERY */ @@ -3331,9 +4109,11 @@ static void yy_syntax_error( int yymajor, /* The major type of the error token */ ParseTOKENTYPE yyminor /* The minor type of the error token */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #define TOKEN yyminor /************ Begin %syntax_error code ****************************************/ +#line 37 "sql.y" pInfo->valid = false; int32_t outputBufLen = tListLen(pInfo->msg); @@ -3356,8 +4136,10 @@ static void yy_syntax_error( } assert(len <= outputBufLen); +#line 4140 "sql.c" /************ End %syntax_error code ******************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } /* @@ -3366,7 +4148,8 @@ static void yy_syntax_error( static void yy_accept( yyParser *yypParser /* The parser */ ){ - ParseARG_FETCH; + ParseARG_FETCH + ParseCTX_FETCH #ifndef NDEBUG if( yyTraceFILE ){ fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt); @@ -3379,9 +4162,11 @@ static void yy_accept( /* Here code is inserted which will be executed whenever the ** parser accepts */ /*********** Begin %parse_accept code *****************************************/ - +#line 61 "sql.y" +#line 4167 "sql.c" /*********** End %parse_accept code *******************************************/ - ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */ + ParseARG_STORE /* Suppress warning about unused %extra_argument variable */ + ParseCTX_STORE } /* The main parser program. @@ -3410,45 +4195,47 @@ void Parse( ParseARG_PDECL /* Optional %extra_argument parameter */ ){ YYMINORTYPE yyminorunion; - unsigned int yyact; /* The parser action. */ + YYACTIONTYPE yyact; /* The parser action. */ #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) int yyendofinput; /* True if we are at the end of input */ #endif #ifdef YYERRORSYMBOL int yyerrorhit = 0; /* True if yymajor has invoked an error */ #endif - yyParser *yypParser; /* The parser */ + yyParser *yypParser = (yyParser*)yyp; /* The parser */ + ParseCTX_FETCH + ParseARG_STORE - yypParser = (yyParser*)yyp; assert( yypParser->yytos!=0 ); #if !defined(YYERRORSYMBOL) && !defined(YYNOERRORRECOVERY) yyendofinput = (yymajor==0); #endif - ParseARG_STORE; + yyact = yypParser->yytos->stateno; #ifndef NDEBUG if( yyTraceFILE ){ - int stateno = yypParser->yytos->stateno; - if( stateno < YY_MIN_REDUCE ){ + if( yyact < YY_MIN_REDUCE ){ fprintf(yyTraceFILE,"%sInput '%s' in state %d\n", - yyTracePrompt,yyTokenName[yymajor],stateno); + yyTracePrompt,yyTokenName[yymajor],yyact); }else{ fprintf(yyTraceFILE,"%sInput '%s' with pending reduce %d\n", - yyTracePrompt,yyTokenName[yymajor],stateno-YY_MIN_REDUCE); + yyTracePrompt,yyTokenName[yymajor],yyact-YY_MIN_REDUCE); } } #endif do{ - yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor); + assert( yyact==yypParser->yytos->stateno ); + yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ - yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor,yyminor); + yyact = yy_reduce(yypParser,yyact-YY_MIN_REDUCE,yymajor, + yyminor ParseCTX_PARAM); }else if( yyact <= YY_MAX_SHIFTREDUCE ){ - yy_shift(yypParser,yyact,yymajor,yyminor); + yy_shift(yypParser,yyact,(YYCODETYPE)yymajor,yyminor); #ifndef YYNOERRORRECOVERY yypParser->yyerrcnt--; #endif - yymajor = YYNOCODE; + break; }else if( yyact==YY_ACCEPT_ACTION ){ yypParser->yytos--; yy_accept(yypParser); @@ -3499,10 +4286,9 @@ void Parse( yymajor = YYNOCODE; }else{ while( yypParser->yytos >= yypParser->yystack - && yymx != YYERRORSYMBOL && (yyact = yy_find_reduce_action( yypParser->yytos->stateno, - YYERRORSYMBOL)) >= YY_MIN_REDUCE + YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE ){ yy_pop_parser_stack(yypParser); } @@ -3519,6 +4305,8 @@ void Parse( } yypParser->yyerrcnt = 3; yyerrorhit = 1; + if( yymajor==YYNOCODE ) break; + yyact = yypParser->yytos->stateno; #elif defined(YYNOERRORRECOVERY) /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to ** do any kind of error recovery. Instead, simply invoke the syntax @@ -3529,8 +4317,7 @@ void Parse( */ yy_syntax_error(yypParser,yymajor, yyminor); yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); - yymajor = YYNOCODE; - + break; #else /* YYERRORSYMBOL is not defined */ /* This is what we do if the grammar does not define ERROR: ** @@ -3552,10 +4339,10 @@ void Parse( yypParser->yyerrcnt = -1; #endif } - yymajor = YYNOCODE; + break; #endif } - }while( yymajor!=YYNOCODE && yypParser->yytos>yypParser->yystack ); + }while( yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; @@ -3570,3 +4357,17 @@ void Parse( #endif return; } + +/* +** Return the fallback token corresponding to canonical token iToken, or +** 0 if iToken has no fallback. +*/ +int ParseFallback(int iToken){ +#ifdef YYFALLBACK + assert( iToken<(int)(sizeof(yyFallback)/sizeof(yyFallback[0])) ); + return yyFallback[iToken]; +#else + (void)iToken; + return 0; +#endif +} diff --git a/tests/pytest/client/client.py b/tests/pytest/client/client.py index b40511094b..c17e947f8b 100644 --- a/tests/pytest/client/client.py +++ b/tests/pytest/client/client.py @@ -36,8 +36,12 @@ class TDTestCase: ret = tdSql.query('show dnodes') - ret = tdSql.execute('alter dnode "%s" debugFlag 135' % tdSql.getData(0,0)) - tdLog.info('alter dnode "%s" debugFlag 135 -> ret: %d' % (tdSql.getData(0, 0), ret)) + dnodeId = tdSql.getData(0, 0); + dnodeEndpoint = tdSql.getData(0, 1); + + ret = tdSql.execute('alter dnode "%s" debugFlag 135' % dnodeId) + tdLog.info('alter dnode "%s" debugFlag 135 -> ret: %d' % (dnodeId, ret)) + ret = tdSql.query('show mnodes') tdSql.checkRows(1) @@ -45,6 +49,13 @@ class TDTestCase: ret = tdSql.query('show vgroups') tdSql.checkRows(0) + tdSql.execute('create stable st (ts timestamp, f int) tags(t int)') + tdSql.execute('create table ct1 using st tags(1)'); + tdSql.execute('create table ct2 using st tags(2)'); + ret = tdSql.query('show vnodes "{}"'.format(dnodeEndpoint)) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + tdSql.checkData(0, 1, "master") def stop(self): tdSql.close() From 399a7d94b6888bbe3f9f117e373efac214ba7c93 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Thu, 5 Aug 2021 11:15:14 +0800 Subject: [PATCH 063/100] [TD-5806]:add role_time to show mnodes --- src/mnode/inc/mnodeDef.h | 1 + src/mnode/src/mnodeMnode.c | 13 ++++++++++++- src/mnode/src/mnodeSdb.c | 1 + tests/pytest/client/client.py | 11 +++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index e974251d2e..5521267841 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -80,6 +80,7 @@ typedef struct SMnodeObj { int8_t updateEnd[4]; int32_t refCount; int8_t role; + int64_t roleTime; int8_t reserved2[3]; } SMnodeObj; diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index bccad22157..13dd06bcac 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -122,6 +122,7 @@ static int32_t mnodeMnodeActionRestored() { void *pIter = mnodeGetNextMnode(NULL, &pMnode); if (pMnode != NULL) { pMnode->role = TAOS_SYNC_ROLE_MASTER; + pMnode->roleTime = taosGetTimestampMs(); mnodeDecMnodeRef(pMnode); } mnodeCancelGetNextMnode(pIter); @@ -496,7 +497,13 @@ static int32_t mnodeGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC strcpy(pSchema[cols].name, "role"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - + + pShow->bytes[cols] = 8; + pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; + strcpy(pSchema[cols].name, "role_time"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = 8; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; strcpy(pSchema[cols].name, "create_time"); @@ -552,6 +559,10 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo STR_WITH_MAXSIZE_TO_VARSTR(pWrite, roles, pShow->bytes[cols]); cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = pMnode->roleTime; + cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int64_t *)pWrite = pMnode->createdTime; cols++; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 7644f4d733..1e3057f270 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -227,6 +227,7 @@ void sdbUpdateMnodeRoles() { SMnodeObj *pMnode = mnodeGetMnode(roles.nodeId[i]); if (pMnode != NULL) { if (pMnode->role != roles.role[i]) { + pMnode->roleTime = taosGetTimestampMs(); bnNotify(); } diff --git a/tests/pytest/client/client.py b/tests/pytest/client/client.py index b40511094b..81a02482ed 100644 --- a/tests/pytest/client/client.py +++ b/tests/pytest/client/client.py @@ -16,6 +16,7 @@ from util.log import * from util.cases import * from util.sql import * +from datetime import timedelta class TDTestCase: def init(self, conn, logSql): @@ -41,6 +42,16 @@ class TDTestCase: ret = tdSql.query('show mnodes') tdSql.checkRows(1) + tdSql.checkData(0, 2, "master") + + role_time = tdSql.getData(0, 3) + create_time = tdSql.getData(0, 4) + time_delta = timedelta(milliseconds=100) + + if create_time-time_delta < role_time < create_time+time_delta: + tdLog.info("role_time {} and create_time {} expected within range".format(role_time, create_time)) + else: + tdLog.exit("role_time {} and create_time {} not expected within range".format(role_time, create_time)) ret = tdSql.query('show vgroups') tdSql.checkRows(0) From 842b3cb3078045d7a93ed445e2a471c0bde95126 Mon Sep 17 00:00:00 2001 From: wenzhouwww Date: Thu, 5 Aug 2021 16:04:07 +0800 Subject: [PATCH 064/100] [TD-5619] : this is test case about parse timezone which is based on RCF3339/ISO8601 --- tests/pytest/TimeZone/TestCaseTimeZone.py | 253 ++++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 tests/pytest/TimeZone/TestCaseTimeZone.py diff --git a/tests/pytest/TimeZone/TestCaseTimeZone.py b/tests/pytest/TimeZone/TestCaseTimeZone.py new file mode 100644 index 0000000000..d99af7b995 --- /dev/null +++ b/tests/pytest/TimeZone/TestCaseTimeZone.py @@ -0,0 +1,253 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import os +import subprocess +import time +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import datetime + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root)-len("/build/bin")] + break + return buildPath + + def run(self): + tdSql.prepare() + buildPath = self.getBuildPath() + if (buildPath == ""): + tdLog.exit("taosd not found!") + else: + tdLog.info("taosd found in %s" % buildPath) + binPath = buildPath+ "/build/bin/" + + tdSql.execute("create database timezone") + tdSql.execute("use timezone") + tdSql.execute("create stable st (ts timestamp, id int ) tags (index int)") + + tdSql.execute("insert into tb0 using st tags (1) values ('2021-07-01 00:00:00.000',0)") + res = tdSql.getResult("select * from tb0") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 0)]: + tdLog.info("time format is check pass : '2021-07-01 00:00:00.000' ") + else: + tdLog.info(" '2021-07-01 00:00:00.000' failed ") + + tdSql.execute("insert into tb1 using st tags (1) values ('2021-07-01T00:00:00.000+07:50',1)") + res = tdSql.getResult("select * from tb1") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 10), 1)]: + tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+07:50' ") + else: + tdLog.info(" '2021-07-01T00:00:00.000+07:50' failed ") + + tdSql.execute("insert into tb2 using st tags (1) values ('2021-07-01T00:00:00.000+08:00',2)") + res = tdSql.getResult("select * from tb2") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 2)]: + tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+08:00' ") + else: + tdLog.info(" '2021-07-01T00:00:00.000+08:00' failed ") + + tdSql.execute("insert into tb3 using st tags (1) values ('2021-07-01T00:00:00.000Z',3)") + res = tdSql.getResult("select * from tb3") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 8, 0), 3)]: + tdLog.info("time format is check pass : '2021-07-01T00:00:00.000Z' ") + else: + tdLog.info(" '2021-07-01T00:00:00.000Z' failed ") + + tdSql.execute("insert into tb4 using st tags (1) values ('2021-07-01 00:00:00.000+07:50',4)") + res = tdSql.getResult("select * from tb4") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 10), 4)]: + tdLog.info("time format is check pass : '2021-07-01 00:00:00.000+07:50' ") + else: + tdLog.info(" '2021-07-01 00:00:00.000+07:50' failed ") + + tdSql.execute("insert into tb5 using st tags (1) values ('2021-07-01 00:00:00.000Z',5)") + res = tdSql.getResult("select * from tb5") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 8, 0), 5)]: + tdLog.info("time format is check pass : '2021-07-01 00:00:00.000Z' ") + else: + tdLog.info(" '2021-07-01 00:00:00.000Z' failed ") + + tdSql.execute("insert into tb6 using st tags (1) values ('2021-07-01T00:00:00.000+0800',6)") + res = tdSql.getResult("select * from tb6") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 6)]: + tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+0800' ") + else: + tdLog.info(" '2021-07-01T00:00:00.000+0800' failed ") + + tdSql.execute("insert into tb7 using st tags (1) values ('2021-07-01 00:00:00.000+0800',7)") + res = tdSql.getResult("select * from tb7") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 7)]: + tdLog.info("time format is check pass : '2021-07-01 00:00:00.000+0800' ") + else: + tdLog.info(" '2021-07-01 00:00:00.000+0800' failed ") + + tdSql.execute("insert into tb8 using st tags (1) values ('2021-07-0100:00:00.000',8)") + res = tdSql.getResult("select * from tb8") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 8)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000' ") + else: + tdLog.info(" '2021-07-0100:00:00.000' failed ") + + tdSql.execute("insert into tb9 using st tags (1) values ('2021-07-0100:00:00.000+0800',9)") + res = tdSql.getResult("select * from tb9") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 9)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0800' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+0800' failed ") + + tdSql.execute("insert into tb10 using st tags (1) values ('2021-07-0100:00:00.000+08:00',10)") + res = tdSql.getResult("select * from tb10") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 0), 10)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+08:00' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+08:00' failed ") + + tdSql.execute("insert into tb11 using st tags (1) values ('2021-07-0100:00:00.000+07:00',11)") + res = tdSql.getResult("select * from tb11") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 1, 0), 11)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07:00' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+07:00' failed ") + + tdSql.execute("insert into tb12 using st tags (1) values ('2021-07-0100:00:00.000+07:00',12)") + res = tdSql.getResult("select * from tb12") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 1, 0), 12)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+07' failed ") + + tdSql.execute("insert into tb13 using st tags (1) values ('2021-07-0100:00:00.000+07:12',13)") + res = tdSql.getResult("select * from tb13") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 48), 13)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07:12' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+07:12' failed ") + + tdSql.execute("insert into tb14 using st tags (1) values ('2021-07-0100:00:00.000+712',14)") + res = tdSql.getResult("select * from tb14") + print(res) + if res == [(datetime.datetime(2021, 6, 28, 8, 58), 14)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+712' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+712' failed ") + + tdSql.execute("insert into tb15 using st tags (1) values ('2021-07-0100:00:00.000Z',15)") + res = tdSql.getResult("select * from tb15") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 8, 0), 15)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000Z' ") + else: + tdLog.info(" '2021-07-0100:00:00.000Z' failed ") + + tdSql.execute("insert into tb16 using st tags (1) values ('2021-7-1 00:00:00.000Z',16)") + res = tdSql.getResult("select * from tb16") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 8, 0), 16)]: + tdLog.info("time format is check pass : '2021-7-1 00:00:00.000Z' ") + else: + tdLog.info(" '2021-7-1 00:00:00.000Z' failed ") + + tdSql.execute("insert into tb17 using st tags (1) values ('2021-07-0100:00:00.000+0750',17)") + res = tdSql.getResult("select * from tb17") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 10), 17)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0750' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+0750' failed ") + + tdSql.execute("insert into tb18 using st tags (1) values ('2021-07-0100:00:00.000+0752',18)") + res = tdSql.getResult("select * from tb18") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 8), 18)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0752' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+0752' failed ") + + tdSql.execute("insert into tb19 using st tags (1) values ('2021-07-0100:00:00.000+075',19)") + res = tdSql.getResult("select * from tb19") + print(res) + if res == [(datetime.datetime(2021, 7, 1, 0, 55), 19)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+075' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+075' failed ") + + tdSql.execute("insert into tb20 using st tags (1) values ('2021-07-0100:00:00.000+75',20)") + res = tdSql.getResult("select * from tb20") + print(res) + if res == [(datetime.datetime(2021, 6, 28, 5, 0), 20)]: + tdLog.info("time format is check pass : '2021-07-0100:00:00.000+75' ") + else: + tdLog.info(" '2021-07-0100:00:00.000+75' failed ") + + + tdSql.error("insert into tberror using st tags (1) values ('20210701 00:00:00.000+0800',0)") + tdSql.error("insert into tberror using st tags (1) values ('2021070100:00:00.000+0800',0)") + tdSql.error("insert into tberror using st tags (1) values ('202171 00:00:00.000+0800',0)") + tdSql.error("insert into tberror using st tags (1) values ('2021 07 01 00:00:00.000+0800',0)") + tdSql.error("insert into tberror using st tags (1) values ('2021 -07-0100:00:00.000+0800',0)") + + + + + + + + + + + + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From cb1da4f1e05e37ebf2c43bafeb0a1b3991e515f7 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 5 Aug 2021 16:09:20 +0800 Subject: [PATCH 065/100] Merge branch 'develop' into fix/TD-5578 --- src/client/inc/tscUtil.h | 1 + src/client/src/tscServer.c | 8 +++++--- src/client/src/tscUtil.c | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 577ce2a0fd..b3674a7bf5 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -344,6 +344,7 @@ int32_t tscCreateTableMetaFromSTableMeta(STableMeta** pChild, const char* name, STableMeta* tscTableMetaDup(STableMeta* pTableMeta); SVgroupsInfo* tscVgroupsInfoDup(SVgroupsInfo* pVgroupsInfo); +int32_t tscGetTagFilterSerializeLen(SQueryInfo* pQueryInfo); int32_t tscGetColFilterSerializeLen(SQueryInfo* pQueryInfo); int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr); void* createQInfoFromQueryNode(SQueryInfo* pQueryInfo, STableGroupInfo* pTableGroupInfo, SOperatorInfo* pOperator, char* sql, void* addr, int32_t stage, uint64_t qId); diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 9230b2bc68..3e8dfac1da 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -676,6 +676,8 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { int32_t srcColListSize = (int32_t)(taosArrayGetSize(pQueryInfo->colList) * sizeof(SColumnInfo)); int32_t srcColFilterSize = tscGetColFilterSerializeLen(pQueryInfo); + int32_t srcTagFilterSize = tscGetTagFilterSerializeLen(pQueryInfo); + size_t numOfExprs = tscNumOfExprs(pQueryInfo); int32_t exprSize = (int32_t)(sizeof(SSqlExpr) * numOfExprs * 2); @@ -696,8 +698,8 @@ static int32_t tscEstimateQueryMsgSize(SSqlObj *pSql) { tableSerialize = totalTables * sizeof(STableIdInfo); } - return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + exprSize + tsBufSize + - tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; + return MIN_QUERY_MSG_PKT_SIZE + minMsgSize() + sizeof(SQueryTableMsg) + srcColListSize + srcColFilterSize + srcTagFilterSize + + exprSize + tsBufSize + tableSerialize + sqlLen + 4096 + pQueryInfo->bufLen; } static char *doSerializeTableInfo(SQueryTableMsg *pQueryMsg, SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, char *pMsg, @@ -1033,7 +1035,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->tagCondLen = htons(pCond->len); + pQueryMsg->tagCondLen = htonl(pCond->len); memcpy(pMsg, pCond->cond, pCond->len); pMsg += pCond->len; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 47783c30b6..5a724af7bf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -4700,6 +4700,21 @@ int32_t tscGetColFilterSerializeLen(SQueryInfo* pQueryInfo) { return len; } +int32_t tscGetTagFilterSerializeLen(SQueryInfo* pQueryInfo) { + // serialize tag column query condition + if (pQueryInfo->tagCond.pCond != NULL && taosArrayGetSize(pQueryInfo->tagCond.pCond) > 0) { + STagCond* pTagCond = &pQueryInfo->tagCond; + + STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); + STableMeta * pTableMeta = pTableMetaInfo->pTableMeta; + SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); + if (pCond != NULL && pCond->cond != NULL) { + return pCond->len; + } + } + return 0; +} + int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr) { memset(pQueryAttr, 0, sizeof(SQueryAttr)); From d2dcecda649e8cb11e018c8f5c6c2246d7c9d9f2 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 5 Aug 2021 16:25:15 +0800 Subject: [PATCH 066/100] [TD-5619]: optimized checkTzPresent function --- src/os/src/detail/osTime.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/os/src/detail/osTime.c b/src/os/src/detail/osTime.c index 078b9c62d0..44c6a7d74c 100644 --- a/src/os/src/detail/osTime.c +++ b/src/os/src/detail/osTime.c @@ -110,10 +110,15 @@ bool checkTzPresent(char *str, int32_t len) { char *seg = forwardToTimeStringEnd(str); int32_t seg_len = len - (int32_t)(seg - str); - return (strnchr(seg, 'Z', seg_len, false) != NULL || - strnchr(seg, 'z', seg_len, false) != NULL || - strnchr(seg, '+', seg_len, false) != NULL || - strnchr(seg, '-', seg_len, false) != NULL); + char *c = &seg[seg_len - 1]; + for (int i = 0; i < seg_len; ++i) { + if (*c == 'Z' || *c == 'z' || *c == '+' || *c == '-') { + return true; + } + c--; + } + return false; + } char* forwardToTimeStringEnd(char* str) { From f0c988d92789770c7a824d86929c0cb781a1ef4f Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Thu, 5 Aug 2021 16:28:13 +0800 Subject: [PATCH 067/100] [TD-5505]: add taosParseTime profiling unitTests --- src/query/tests/unitTest.cpp | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index 740a783ca0..9f6e219c0a 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -524,6 +524,64 @@ TEST(testCase, parse_time) { } +/* test parse time profiling */ +TEST(testCase, parse_time_profile) { + taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); + char t1[] = "2018-1-8 1:1:1.952"; + char t2[] = "2018-1-8T1:1:1.952+0800"; + char t3[] = "2018-1-8 1:1:1.952+0800"; + char t4[] = "2018-1-81:1:1.952+0800"; + + char t5[] = "2018-1-8 1:1:1.952"; + char t6[] = "2018-1-8T1:1:1.952+08:00"; + char t7[] = "2018-1-8 1:1:1.952+08:00"; + char t8[] = "2018-1-81:1:1.952+08:00"; + + char t9[] = "2018-1-8 1:1:1.952"; + char t10[] = "2018-1-8T1:1:1.952Z"; + char t11[] = "2018-1-8 1:1:1.952z"; + char t12[] = "2018-1-81:1:1.952Z"; + + struct timeval start, end; + int64_t time = 0, time1 = 0; + + int32_t total_run = 100000000; + long total_time_us; + + gettimeofday(&start, NULL); + for (int i = 0; i < total_run; ++i) { + taosParseTime(t1, &time, strlen(t1), TSDB_TIME_PRECISION_MILLI, 0); + } + gettimeofday(&end, NULL); + total_time_us = ((end.tv_sec - start.tv_sec)* 1000000) + (end.tv_usec - start.tv_usec); + printf("[t1] The elapsed time is %f seconds in %d run, average:%fns\n", total_time_us/1000000.0, total_run, 1000*(float)total_time_us/(float)total_run); + + gettimeofday(&start, NULL); + for (int i = 0; i < total_run; ++i) { + taosParseTime(t2, &time, strlen(t2), TSDB_TIME_PRECISION_MILLI, 0); + } + gettimeofday(&end, NULL); + total_time_us = ((end.tv_sec - start.tv_sec)* 1000000) + (end.tv_usec - start.tv_usec); + printf("[t2] The elapsed time is %f seconds in %d run, average:%fns\n", total_time_us/1000000.0, total_run, 1000*(float)total_time_us/(float)total_run); + + gettimeofday(&start, NULL); + for (int i = 0; i < total_run; ++i) { + taosParseTime(t3, &time, strlen(t3), TSDB_TIME_PRECISION_MILLI, 0); + } + gettimeofday(&end, NULL); + total_time_us = ((end.tv_sec - start.tv_sec)* 1000000) + (end.tv_usec - start.tv_usec); + printf("[t3] The elapsed time is %f seconds in %d run, average:%fns\n", total_time_us/1000000.0, total_run, 1000*(float)total_time_us/(float)total_run); + + gettimeofday(&start, NULL); + for (int i = 0; i < total_run; ++i) { + taosParseTime(t4, &time, strlen(t4), TSDB_TIME_PRECISION_MILLI, 0); + } + gettimeofday(&end, NULL); + total_time_us = ((end.tv_sec - start.tv_sec)* 1000000) + (end.tv_usec - start.tv_usec); + printf("[t4] The elapsed time is %f seconds in %d run, average:%fns\n", total_time_us/1000000.0, total_run, 1000*(float)total_time_us/(float)total_run); +} + + TEST(testCase, tvariant_convert) { // 1. bool data to all other data types tVariant t = {0}; From dbadc405ee6f76afdce284127be073abf5a8f2de Mon Sep 17 00:00:00 2001 From: wenzhouwww Date: Thu, 5 Aug 2021 17:00:07 +0800 Subject: [PATCH 068/100] [TD-5619] add new case for timezone --- tests/pytest/TimeZone/TestCaseTimeZone.py | 195 +++++++--------------- tests/pytest/fulltest.sh | 4 + 2 files changed, 63 insertions(+), 136 deletions(-) diff --git a/tests/pytest/TimeZone/TestCaseTimeZone.py b/tests/pytest/TimeZone/TestCaseTimeZone.py index d99af7b995..0bad52ef98 100644 --- a/tests/pytest/TimeZone/TestCaseTimeZone.py +++ b/tests/pytest/TimeZone/TestCaseTimeZone.py @@ -57,172 +57,100 @@ class TDTestCase: tdSql.execute("create stable st (ts timestamp, id int ) tags (index int)") tdSql.execute("insert into tb0 using st tags (1) values ('2021-07-01 00:00:00.000',0)") - res = tdSql.getResult("select * from tb0") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 0)]: - tdLog.info("time format is check pass : '2021-07-01 00:00:00.000' ") - else: - tdLog.info(" '2021-07-01 00:00:00.000' failed ") + tdSql.query("select ts from tb0") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb1 using st tags (1) values ('2021-07-01T00:00:00.000+07:50',1)") - res = tdSql.getResult("select * from tb1") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 10), 1)]: - tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+07:50' ") - else: - tdLog.info(" '2021-07-01T00:00:00.000+07:50' failed ") - - tdSql.execute("insert into tb2 using st tags (1) values ('2021-07-01T00:00:00.000+08:00',2)") - res = tdSql.getResult("select * from tb2") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 2)]: - tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+08:00' ") - else: - tdLog.info(" '2021-07-01T00:00:00.000+08:00' failed ") + tdSql.query("select ts from tb1") + tdSql.checkData(0, 0, "2021-07-01 00:10:00.000") + tdSql.execute("insert into tb2 using st tags (1) values ('2021-07-01T00:00:00.000+08:00',2)") + tdSql.query("select ts from tb2") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") + tdSql.execute("insert into tb3 using st tags (1) values ('2021-07-01T00:00:00.000Z',3)") - res = tdSql.getResult("select * from tb3") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 8, 0), 3)]: - tdLog.info("time format is check pass : '2021-07-01T00:00:00.000Z' ") - else: - tdLog.info(" '2021-07-01T00:00:00.000Z' failed ") + tdSql.query("select ts from tb3") + tdSql.checkData(0, 0, "2021-07-01 08:00:00.000") tdSql.execute("insert into tb4 using st tags (1) values ('2021-07-01 00:00:00.000+07:50',4)") - res = tdSql.getResult("select * from tb4") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 10), 4)]: - tdLog.info("time format is check pass : '2021-07-01 00:00:00.000+07:50' ") - else: - tdLog.info(" '2021-07-01 00:00:00.000+07:50' failed ") + tdSql.query("select ts from tb4") + tdSql.checkData(0, 0, "2021-07-01 00:10:00.000") tdSql.execute("insert into tb5 using st tags (1) values ('2021-07-01 00:00:00.000Z',5)") - res = tdSql.getResult("select * from tb5") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 8, 0), 5)]: - tdLog.info("time format is check pass : '2021-07-01 00:00:00.000Z' ") - else: - tdLog.info(" '2021-07-01 00:00:00.000Z' failed ") + tdSql.query("select ts from tb5") + tdSql.checkData(0, 0, "2021-07-01 08:00:00.000") tdSql.execute("insert into tb6 using st tags (1) values ('2021-07-01T00:00:00.000+0800',6)") - res = tdSql.getResult("select * from tb6") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 6)]: - tdLog.info("time format is check pass : '2021-07-01T00:00:00.000+0800' ") - else: - tdLog.info(" '2021-07-01T00:00:00.000+0800' failed ") + tdSql.query("select ts from tb6") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb7 using st tags (1) values ('2021-07-01 00:00:00.000+0800',7)") - res = tdSql.getResult("select * from tb7") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 7)]: - tdLog.info("time format is check pass : '2021-07-01 00:00:00.000+0800' ") - else: - tdLog.info(" '2021-07-01 00:00:00.000+0800' failed ") + tdSql.query("select ts from tb7") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb8 using st tags (1) values ('2021-07-0100:00:00.000',8)") - res = tdSql.getResult("select * from tb8") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 8)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000' ") - else: - tdLog.info(" '2021-07-0100:00:00.000' failed ") + tdSql.query("select ts from tb8") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb9 using st tags (1) values ('2021-07-0100:00:00.000+0800',9)") - res = tdSql.getResult("select * from tb9") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 9)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0800' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+0800' failed ") + tdSql.query("select ts from tb9") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb10 using st tags (1) values ('2021-07-0100:00:00.000+08:00',10)") - res = tdSql.getResult("select * from tb10") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 0), 10)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+08:00' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+08:00' failed ") + tdSql.query("select ts from tb10") + tdSql.checkData(0, 0, "2021-07-01 00:00:00.000") tdSql.execute("insert into tb11 using st tags (1) values ('2021-07-0100:00:00.000+07:00',11)") - res = tdSql.getResult("select * from tb11") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 1, 0), 11)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07:00' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+07:00' failed ") + tdSql.query("select ts from tb11") + tdSql.checkData(0, 0, "2021-07-01 01:00:00.000") - tdSql.execute("insert into tb12 using st tags (1) values ('2021-07-0100:00:00.000+07:00',12)") - res = tdSql.getResult("select * from tb12") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 1, 0), 12)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+07' failed ") + tdSql.execute("insert into tb12 using st tags (1) values ('2021-07-0100:00:00.000+0700',12)") + tdSql.query("select ts from tb12") + tdSql.checkData(0, 0, "2021-07-01 01:00:00.000") tdSql.execute("insert into tb13 using st tags (1) values ('2021-07-0100:00:00.000+07:12',13)") - res = tdSql.getResult("select * from tb13") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 48), 13)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+07:12' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+07:12' failed ") + tdSql.query("select ts from tb13") + tdSql.checkData(0, 0, "2021-07-01 00:48:00.000") tdSql.execute("insert into tb14 using st tags (1) values ('2021-07-0100:00:00.000+712',14)") - res = tdSql.getResult("select * from tb14") - print(res) - if res == [(datetime.datetime(2021, 6, 28, 8, 58), 14)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+712' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+712' failed ") + tdSql.query("select ts from tb14") + tdSql.checkData(0, 0, "2021-06-28 08:58:00.000") tdSql.execute("insert into tb15 using st tags (1) values ('2021-07-0100:00:00.000Z',15)") - res = tdSql.getResult("select * from tb15") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 8, 0), 15)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000Z' ") - else: - tdLog.info(" '2021-07-0100:00:00.000Z' failed ") + tdSql.query("select ts from tb15") + tdSql.checkData(0, 0, "2021-07-01 08:00:00.000") tdSql.execute("insert into tb16 using st tags (1) values ('2021-7-1 00:00:00.000Z',16)") - res = tdSql.getResult("select * from tb16") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 8, 0), 16)]: - tdLog.info("time format is check pass : '2021-7-1 00:00:00.000Z' ") - else: - tdLog.info(" '2021-7-1 00:00:00.000Z' failed ") + tdSql.query("select ts from tb16") + tdSql.checkData(0, 0, "2021-07-01 08:00:00.000") tdSql.execute("insert into tb17 using st tags (1) values ('2021-07-0100:00:00.000+0750',17)") - res = tdSql.getResult("select * from tb17") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 10), 17)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0750' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+0750' failed ") + tdSql.query("select ts from tb17") + tdSql.checkData(0, 0, "2021-07-01 00:10:00.000") tdSql.execute("insert into tb18 using st tags (1) values ('2021-07-0100:00:00.000+0752',18)") - res = tdSql.getResult("select * from tb18") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 8), 18)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+0752' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+0752' failed ") + tdSql.query("select ts from tb18") + tdSql.checkData(0, 0, "2021-07-01 00:08:00.000") tdSql.execute("insert into tb19 using st tags (1) values ('2021-07-0100:00:00.000+075',19)") - res = tdSql.getResult("select * from tb19") - print(res) - if res == [(datetime.datetime(2021, 7, 1, 0, 55), 19)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+075' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+075' failed ") + tdSql.query("select ts from tb19") + tdSql.checkData(0, 0, "2021-07-01 00:55:00.000") tdSql.execute("insert into tb20 using st tags (1) values ('2021-07-0100:00:00.000+75',20)") - res = tdSql.getResult("select * from tb20") - print(res) - if res == [(datetime.datetime(2021, 6, 28, 5, 0), 20)]: - tdLog.info("time format is check pass : '2021-07-0100:00:00.000+75' ") - else: - tdLog.info(" '2021-07-0100:00:00.000+75' failed ") + tdSql.query("select ts from tb20") + tdSql.checkData(0, 0, "2021-06-28 05:00:00.000") + + tdSql.execute("insert into tb21 using st tags (1) values ('2021-7-1 1:1:1.234+075',21)") + tdSql.query("select ts from tb21") + tdSql.checkData(0, 0, "2021-07-01 01:56:01.234") + + tdSql.execute("insert into tb22 using st tags (1) values ('2021-7-1T1:1:1.234+075',22)") + tdSql.query("select ts from tb22") + tdSql.checkData(0, 0, "2021-07-01 01:56:01.234") + + tdSql.execute("insert into tb23 using st tags (1) values ('2021-7-131:1:1.234+075',22)") + tdSql.query("select ts from tb23") + tdSql.checkData(0, 0, "2021-07-13 01:56:01.234") tdSql.error("insert into tberror using st tags (1) values ('20210701 00:00:00.000+0800',0)") @@ -230,16 +158,11 @@ class TDTestCase: tdSql.error("insert into tberror using st tags (1) values ('202171 00:00:00.000+0800',0)") tdSql.error("insert into tberror using st tags (1) values ('2021 07 01 00:00:00.000+0800',0)") tdSql.error("insert into tberror using st tags (1) values ('2021 -07-0100:00:00.000+0800',0)") - - + tdSql.error("insert into tberror using st tags (1) values ('2021-7-11:1:1.234+075',0)") + os.system("rm -rf ./TimeZone/*.py.sql") - - - - - diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index bc410107e6..fb609430c9 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -29,6 +29,10 @@ python3 ./test.py -f insert/in_function.py python3 ./test.py -f insert/modify_column.py python3 ./test.py -f insert/line_insert.py +# timezone + +python3 ./test.py -f TimeZone/TestCaseTimeZone.py + #table python3 ./test.py -f table/alter_wal0.py python3 ./test.py -f table/column_name.py From 4af2ab3d1d831c9f7225d6e06747bc92657863e8 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 5 Aug 2021 18:08:29 +0800 Subject: [PATCH 069/100] [TD-5822] optimize invalidate operation tips --- src/client/src/tscSQLParser.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 5739333886..f534140be9 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7556,6 +7556,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg6 = "from missing in subclause"; const char* msg7 = "time interval is required"; const char* msg8 = "the first column should be primary timestamp column"; + const char* msg9 = "Continuous query do not support sub query"; SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); @@ -7576,7 +7577,11 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { if (pFromInfo == NULL || taosArrayGetSize(pFromInfo->list) == 0) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - + + if (pFromInfo->type == SQL_NODE_FROM_SUBQUERY){ + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg9); + } + SRelElementPair* p1 = taosArrayGet(pFromInfo->list, 0); SStrToken srcToken = {.z = p1->tableName.z, .n = p1->tableName.n, .type = TK_STRING}; if (tscValidateName(&srcToken) != TSDB_CODE_SUCCESS) { From c00ff3ff9677191f529410787bccd5864f4336f0 Mon Sep 17 00:00:00 2001 From: wpan Date: Thu, 5 Aug 2021 18:28:58 +0800 Subject: [PATCH 070/100] improve performance --- src/query/inc/qFilter.h | 10 ++-- src/query/src/qFilter.c | 123 +++++++++++++++++++++++++++++++++------- src/util/inc/tcompare.h | 32 +++++++++++ src/util/src/tcompare.c | 6 +- 4 files changed, 143 insertions(+), 28 deletions(-) diff --git a/src/query/inc/qFilter.h b/src/query/inc/qFilter.h index ba65360624..7a7b3157ea 100644 --- a/src/query/inc/qFilter.h +++ b/src/query/inc/qFilter.h @@ -181,7 +181,7 @@ typedef struct SFilterColCtx { } SFilterColCtx; typedef struct SFilterCompare { - int32_t type; + uint8_t type; uint8_t optr; uint8_t optr2; } SFilterCompare; @@ -194,14 +194,14 @@ typedef struct SFilterUnit { } SFilterUnit; typedef struct SFilterComUnit { - __compar_fn_t func; - rangeCompFunc rfunc; void *colData; void *valData; void *valData2; - int32_t dataType; uint16_t dataSize; - uint16_t optr; + uint8_t dataType; + uint8_t optr; + int8_t func; + int8_t rfunc; } SFilterComUnit; typedef struct SFilterPCtx { diff --git a/src/query/src/qFilter.c b/src/query/src/qFilter.c index d6e69bb480..1171bb0896 100644 --- a/src/query/src/qFilter.c +++ b/src/query/src/qFilter.c @@ -114,41 +114,123 @@ rangeCompFunc filterGetRangeCompFunc(char sflag, char eflag) { return filterRangeCompii; } -rangeCompFunc filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { +rangeCompFunc gRangeCompare[] = {filterRangeCompee, filterRangeCompei, filterRangeCompie, filterRangeCompii, filterRangeCompGe, + filterRangeCompGi, filterRangeCompLe, filterRangeCompLi}; + + +int8_t filterGetRangeCompFuncFromOptrs(uint8_t optr, uint8_t optr2) { if (optr2) { assert(optr2 == TSDB_RELATION_LESS || optr2 == TSDB_RELATION_LESS_EQUAL); if (optr == TSDB_RELATION_GREATER) { if (optr2 == TSDB_RELATION_LESS) { - return filterRangeCompee; + return 0; } - return filterRangeCompei; + return 1; } if (optr2 == TSDB_RELATION_LESS) { - return filterRangeCompie; + return 2; } - return filterRangeCompii; + return 3; } else { switch (optr) { case TSDB_RELATION_GREATER: - return filterRangeCompGe; + return 4; case TSDB_RELATION_GREATER_EQUAL: - return filterRangeCompGi; + return 5; case TSDB_RELATION_LESS: - return filterRangeCompLe; + return 6; case TSDB_RELATION_LESS_EQUAL: - return filterRangeCompLi; + return 7; default: break; } } - return NULL; + return -1; } +__compar_fn_t gDataCompare[] = {compareInt32Val, compareInt8Val, compareInt16Val, compareInt64Val, compareFloatVal, + compareDoubleVal, compareLenPrefixedStr, compareStrPatternComp, compareFindItemInSet, compareWStrPatternComp, + compareLenPrefixedWStr, compareUint8Val, compareUint16Val, compareUint32Val, compareUint64Val, + setCompareBytes1, setCompareBytes2, setCompareBytes4, setCompareBytes8 +}; + +int8_t filterGetCompFuncIdx(int32_t type, int32_t optr) { + int8_t comparFn = 0; + + if (optr == TSDB_RELATION_IN && (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR)) { + switch (type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: + return 15; + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: + return 16; + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: + case TSDB_DATA_TYPE_FLOAT: + return 17; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_TIMESTAMP: + return 18; + default: + assert(0); + } + } + + switch (type) { + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: comparFn = 1; break; + case TSDB_DATA_TYPE_SMALLINT: comparFn = 2; break; + case TSDB_DATA_TYPE_INT: comparFn = 0; break; + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_TIMESTAMP: comparFn = 3; break; + case TSDB_DATA_TYPE_FLOAT: comparFn = 4; break; + case TSDB_DATA_TYPE_DOUBLE: comparFn = 5; break; + case TSDB_DATA_TYPE_BINARY: { + if (optr == TSDB_RELATION_LIKE) { /* wildcard query using like operator */ + comparFn = 7; + } else if (optr == TSDB_RELATION_IN) { + comparFn = 8; + } else { /* normal relational comparFn */ + comparFn = 6; + } + + break; + } + + case TSDB_DATA_TYPE_NCHAR: { + if (optr == TSDB_RELATION_LIKE) { + comparFn = 9; + } else if (optr == TSDB_RELATION_IN) { + comparFn = 8; + } else { + comparFn = 10; + } + break; + } + + case TSDB_DATA_TYPE_UTINYINT: comparFn = 11; break; + case TSDB_DATA_TYPE_USMALLINT: comparFn = 12;break; + case TSDB_DATA_TYPE_UINT: comparFn = 13;break; + case TSDB_DATA_TYPE_UBIGINT: comparFn = 14;break; + + default: + comparFn = 0; + break; + } + + return comparFn; +} + + static FORCE_INLINE int32_t filterCompareGroupCtx(const void *pLeft, const void *pRight) { SFilterGroupCtx *left = *((SFilterGroupCtx**)pLeft), *right = *((SFilterGroupCtx**)pRight); if (left->colNum > right->colNum) return 1; @@ -1392,6 +1474,7 @@ _return: return code; } +#if 0 int32_t filterInitUnitFunc(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit* unit = &info->units[i]; @@ -1401,7 +1484,7 @@ int32_t filterInitUnitFunc(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - +#endif void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) { @@ -2406,7 +2489,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { for (uint16_t i = 0; i < info->unitNum; ++i) { SFilterUnit *unit = &info->units[i]; - info->cunits[i].func = getComparFunc(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); + info->cunits[i].func = filterGetCompFuncIdx(FILTER_UNIT_DATA_TYPE(unit), unit->compare.optr); info->cunits[i].rfunc = filterGetRangeCompFuncFromOptrs(unit->compare.optr, unit->compare.optr2); info->cunits[i].optr = FILTER_UNIT_OPTR(unit); info->cunits[i].colData = NULL; @@ -2500,10 +2583,10 @@ bool filterExecuteImplRange(void *pinfo, int32_t numOfRows, int8_t* p) { bool all = true; uint16_t dataSize = info->cunits[0].dataSize; char *colData = (char *)info->cunits[0].colData; - rangeCompFunc rfunc = info->cunits[0].rfunc; + rangeCompFunc rfunc = gRangeCompare[info->cunits[0].rfunc]; void *valData = info->cunits[0].valData; void *valData2 = info->cunits[0].valData2; - __compar_fn_t func = info->cunits[0].func; + __compar_fn_t func = gDataCompare[info->cunits[0].func]; for (int32_t i = 0; i < numOfRows; ++i) { if (isNull(colData, info->cunits[0].dataType)) { @@ -2536,7 +2619,7 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t* p) { continue; } - p[i] = filterDoCompare(info->cunits[uidx].func, info->cunits[uidx].optr, colData, info->cunits[uidx].valData); + p[i] = filterDoCompare(gDataCompare[info->cunits[uidx].func], info->cunits[uidx].optr, colData, info->cunits[uidx].valData); if (p[i] == 0) { all = false; @@ -2573,10 +2656,10 @@ bool filterExecuteImpl(void *pinfo, int32_t numOfRows, int8_t* p) { p[i] = 1; } else if (optr == TSDB_RELATION_ISNULL) { p[i] = 0; - } else if (cunit->rfunc) { - p[i] = (*cunit->rfunc)(colData, colData, cunit->valData, cunit->valData2, cunit->func); + } else if (cunit->rfunc >= 0) { + p[i] = (*gRangeCompare[cunit->rfunc])(colData, colData, cunit->valData, cunit->valData2, gDataCompare[cunit->func]); } else { - p[i] = filterDoCompare(cunit->func, cunit->optr, colData, cunit->valData); + p[i] = filterDoCompare(gDataCompare[cunit->func], cunit->optr, colData, cunit->valData); } //FILTER_UNIT_SET_R(info, uidx, p[i]); @@ -2631,7 +2714,7 @@ int32_t filterSetExecFunc(SFilterInfo *info) { return TSDB_CODE_SUCCESS; } - if (info->cunits[0].rfunc) { + if (info->cunits[0].rfunc >= 0) { info->func = filterExecuteImplRange; return TSDB_CODE_SUCCESS; } @@ -2746,7 +2829,7 @@ int32_t filterInitFromTree(tExprNode* tree, SFilterInfo **pinfo, uint32_t option return code; } - ERR_JRET(filterInitUnitFunc(info)); + //ERR_JRET(filterInitUnitFunc(info)); } info->unitRes = malloc(info->unitNum * sizeof(*info->unitRes)); diff --git a/src/util/inc/tcompare.h b/src/util/inc/tcompare.h index 612ce7ede0..baa09bfde6 100644 --- a/src/util/inc/tcompare.h +++ b/src/util/inc/tcompare.h @@ -53,6 +53,38 @@ __compar_fn_t getComparFunc(int32_t type, int32_t optr); int32_t taosArrayCompareString(const void* a, const void* b); +int32_t setCompareBytes1(const void *pLeft, const void *pRight); + +int32_t setCompareBytes2(const void *pLeft, const void *pRight); + +int32_t setCompareBytes4(const void *pLeft, const void *pRight); +int32_t setCompareBytes8(const void *pLeft, const void *pRight); + +int32_t compareInt32Val(const void *pLeft, const void *pRight); +int32_t compareInt64Val(const void *pLeft, const void *pRight); + +int32_t compareInt16Val(const void *pLeft, const void *pRight); + +int32_t compareInt8Val(const void *pLeft, const void *pRight); + +int32_t compareUint32Val(const void *pLeft, const void *pRight); +int32_t compareUint64Val(const void *pLeft, const void *pRight); + +int32_t compareUint16Val(const void *pLeft, const void *pRight); + +int32_t compareUint8Val(const void* pLeft, const void* pRight); + +int32_t compareFloatVal(const void *pLeft, const void *pRight); + +int32_t compareDoubleVal(const void *pLeft, const void *pRight); + +int32_t compareLenPrefixedStr(const void *pLeft, const void *pRight); + +int32_t compareLenPrefixedWStr(const void *pLeft, const void *pRight); +int32_t compareStrPatternComp(const void* pLeft, const void* pRight); +int32_t compareFindItemInSet(const void *pLeft, const void* pRight); +int32_t compareWStrPatternComp(const void* pLeft, const void* pRight); + #ifdef __cplusplus } #endif diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 6d4d6dc0b8..7577451f88 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -278,7 +278,7 @@ int WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t size, c return (str[j] == 0 || j >= size) ? TSDB_PATTERN_MATCH : TSDB_PATTERN_NOMATCH; } -static int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { +int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; char pattern[128] = {0}; @@ -306,11 +306,11 @@ int32_t taosArrayCompareString(const void* a, const void* b) { // const SArray* arr = (const SArray*) pRight; // return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; //} -static int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { +int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; } -static int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { +int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; wchar_t pattern[128] = {0}; From 8da778c5050e366a31a6fe5fcb4ce0c36a025180 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 5 Aug 2021 19:19:07 +0800 Subject: [PATCH 071/100] [TD-5833] fix 1 column error when create table use select _c0 from.. --- src/client/src/tscSQLParser.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index f534140be9..4154335bb4 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7557,6 +7557,7 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { const char* msg7 = "time interval is required"; const char* msg8 = "the first column should be primary timestamp column"; const char* msg9 = "Continuous query do not support sub query"; + const char* msg10 = "illegal number of columns"; SSqlCmd* pCmd = &pSql->cmd; SQueryInfo* pQueryInfo = tscGetQueryInfo(pCmd); @@ -7598,6 +7599,10 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return code; } + if (taosArrayGetSize(pSqlNode->pSelNodeList) <= 1) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); + } + if (validateSelectNodeList(&pSql->cmd, pQueryInfo, pSqlNode->pSelNodeList, false, false, false) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } From 02951f2fb9c3a1240741195914220be0fe7c800c Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Aug 2021 05:25:51 +0800 Subject: [PATCH 072/100] [TD-5610] Unable to Resolve FQDN --- src/client/src/tscServer.c | 9 +++++++++ src/client/src/tscSql.c | 7 ++++++- src/kit/shell/src/shellEngine.c | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 3e8dfac1da..36cc212868 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -501,6 +501,15 @@ static void doProcessMsgFromServer(SSchedMsg* pSchedMsg) { pRes->code = rpcMsg->code; } rpcMsg->code = (pRes->code == TSDB_CODE_SUCCESS) ? (int32_t)pRes->numOfRows : pRes->code; + if (pRes->code == TSDB_CODE_RPC_FQDN_ERROR) { + if (pEpSet) { + char buf[TSDB_FQDN_LEN + 64] = {0}; + tscAllocPayload(pCmd, sizeof(buf)); + sprintf(tscGetErrorMsgPayload(pCmd), "%s\"%s\"", tstrerror(pRes->code),pEpSet->fqdn[(pEpSet->inUse)%(pEpSet->numOfEps)]); + } else { + sprintf(tscGetErrorMsgPayload(pCmd), "%s", tstrerror(pRes->code)); + } + } (*pSql->fp)(pSql->param, pSql, rpcMsg->code); } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 6f3d5c3a63..5f55e1c50d 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -196,6 +196,11 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, if (pSql->res.code != TSDB_CODE_SUCCESS) { terrno = pSql->res.code; + if (terrno ==TSDB_CODE_RPC_FQDN_ERROR) { + printf("taos connect failed, reason: %s\n\n", taos_errstr(pSql)); + } else { + printf("taos connect failed, reason: %s.\n\n", tstrerror(terrno)); + } taos_free_result(pSql); taos_close(pObj); return NULL; @@ -643,7 +648,7 @@ char *taos_errstr(TAOS_RES *tres) { return (char*) tstrerror(terrno); } - if (hasAdditionalErrorInfo(pSql->res.code, &pSql->cmd)) { + if (hasAdditionalErrorInfo(pSql->res.code, &pSql->cmd) || pSql->res.code == TSDB_CODE_RPC_FQDN_ERROR) { return pSql->cmd.payload; } else { return (char*)tstrerror(pSql->res.code); diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 58f4b7ff02..cdce61e578 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -98,7 +98,6 @@ TAOS *shellInit(SShellArguments *_args) { } if (con == NULL) { - printf("taos connect failed, reason: %s.\n\n", tstrerror(terrno)); fflush(stdout); return con; } From 378c41c8ce2e7c62302c93c6fab4675744273d72 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Aug 2021 07:46:53 +0800 Subject: [PATCH 073/100] [TD-5610] Unable to Resolve FQDN --- src/client/src/tscAsync.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index f39169c193..174610ec79 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -339,6 +339,11 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { const char* msg = (sub->cmd.command == TSDB_SQL_STABLEVGROUP)? "vgroup-list":"multi-tableMeta"; if (code != TSDB_CODE_SUCCESS) { tscError("0x%"PRIx64" get %s failed, code:%s", pSql->self, msg, tstrerror(code)); + if (code == TSDB_CODE_RPC_FQDN_ERROR) { + size_t sz = strlen(tscGetErrorMsgPayload(&sub->cmd)); + tscAllocPayload(&pSql->cmd, (int)sz + 1); + memcpy(tscGetErrorMsgPayload(&pSql->cmd), tscGetErrorMsgPayload(&sub->cmd), sz); + } goto _error; } From 865658d0f49b8b8ecb5366bb0b2e8979f3eee949 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 6 Aug 2021 09:33:19 +0800 Subject: [PATCH 074/100] [TD-5578] fixmerge error --- src/inc/taosmsg.h | 2 +- src/query/src/qExecutor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 52162ea4b4..c2918cfdf7 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -489,7 +489,7 @@ typedef struct { int16_t numOfCols; // the number of columns will be load from vnode SInterval interval; SSessionWindow sw; // session window - uint16_t tagCondLen; // tag length in current query + uint32_t tagCondLen; // tag length in current query uint32_t tbnameCondLen; // table name filter condition string length int16_t numOfGroupCols; // num of group by columns int16_t orderByIdx; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 93a2535d56..5323b4306f 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6899,7 +6899,7 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) { pQueryMsg->numOfCols = htons(pQueryMsg->numOfCols); pQueryMsg->numOfOutput = htons(pQueryMsg->numOfOutput); pQueryMsg->numOfGroupCols = htons(pQueryMsg->numOfGroupCols); - pQueryMsg->tagCondLen = htons(pQueryMsg->tagCondLen); + pQueryMsg->tagCondLen = htonl(pQueryMsg->tagCondLen); pQueryMsg->tsBuf.tsOffset = htonl(pQueryMsg->tsBuf.tsOffset); pQueryMsg->tsBuf.tsLen = htonl(pQueryMsg->tsBuf.tsLen); pQueryMsg->tsBuf.tsNumOfBlocks = htonl(pQueryMsg->tsBuf.tsNumOfBlocks); From bc7ffbbb7e12ec9d657c48d1c1fa9ade712a6178 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 6 Aug 2021 15:09:45 +0800 Subject: [PATCH 075/100] [TD-5833] fix 1 column error when create table use select _c0 from.. --- src/client/src/tscSQLParser.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 4154335bb4..cd92b4f507 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7599,10 +7599,6 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return code; } - if (taosArrayGetSize(pSqlNode->pSelNodeList) <= 1) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); - } - if (validateSelectNodeList(&pSql->cmd, pQueryInfo, pSqlNode->pSelNodeList, false, false, false) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -7648,7 +7644,9 @@ int32_t doCheckForStream(SSqlObj* pSql, SSqlInfo* pInfo) { return TSDB_CODE_TSC_INVALID_OPERATION; } - pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; + if (pQueryInfo->fieldsInfo.numOfOutput <= 1) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10); + } if (validateSqlFunctionInStreamSql(pCmd, pQueryInfo) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; From 710f2d824b41e6391d72add519bd2971977b06e7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 6 Aug 2021 15:25:20 +0800 Subject: [PATCH 076/100] [TD-5877] fix mem leak in compact --- src/query/src/qSqlParser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index a512c7bf1a..e93553c4df 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -954,6 +954,8 @@ void SqlInfoDestroy(SSqlInfo *pInfo) { taosArrayDestroy(pInfo->pAlterInfo->pAddColumns); tfree(pInfo->pAlterInfo->tagData.data); tfree(pInfo->pAlterInfo); + } else if (pInfo->type == TSDB_SQL_COMPACT_VNODE) { + tSqlExprListDestroy(pInfo->list); } else { if (pInfo->pMiscInfo != NULL) { taosArrayDestroy(pInfo->pMiscInfo->a); From a3036f5f3e13572d74effcef327484a318ce5b04 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 8 Aug 2021 03:20:14 +0800 Subject: [PATCH 077/100] [TD-5612] handle taos -h invalideFqdn --- src/rpc/src/rpcMain.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index e958a8e5ec..c93a3f929d 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -1133,8 +1133,8 @@ static void rpcNotifyClient(SRpcReqContext *pContext, SRpcMsg *pMsg) { } else { // for asynchronous API SRpcEpSet *pEpSet = NULL; - if (pContext->epSet.inUse != pContext->oldInUse || pContext->redirect) - pEpSet = &pContext->epSet; + //if (pContext->epSet.inUse != pContext->oldInUse || pContext->redirect) + pEpSet = &pContext->epSet; (*pRpc->cfp)(pMsg, pEpSet); } From 3916161f851def5e3e7895d30b1cf42e27092627 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 8 Aug 2021 08:14:48 +0800 Subject: [PATCH 078/100] [TD-5930] fix mem leak --- src/query/src/qAggMain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index dad05df22a..1b1ebec4a3 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -4047,9 +4047,9 @@ void block_func_merge(SQLFunctionCtx* pCtx) { STableBlockDist info = {0}; int32_t len = *(int32_t*) pCtx->pInput; blockDistInfoFromBinary(((char*)pCtx->pInput) + sizeof(int32_t), len, &info); - SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); mergeTableBlockDist(pResInfo, &info); + taosArrayDestroy(info.dataBlockInfos); pResInfo->numOfRes = 1; pResInfo->hasResult = DATA_SET_FLAG; From b13780f15ca8ede26c27d2afef53e31dc7253ea0 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 9 Aug 2021 08:23:15 +0800 Subject: [PATCH 079/100] add test case --- tests/script/general/parser/condition_query.sim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/script/general/parser/condition_query.sim b/tests/script/general/parser/condition_query.sim index 5ea707311a..7600e510d3 100644 --- a/tests/script/general/parser/condition_query.sim +++ b/tests/script/general/parser/condition_query.sim @@ -38,6 +38,8 @@ sql_error select * from stb1 where c9 > 'nuLl'; sql_error select * from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b; sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and a.c1 > 50 or b.c1 < 60; sql_error select a.ts,a.c1,a.c8 from (select * from stb1 where c7=true) a, (select * from stb1 where c1 > 30) b where a.ts=b.ts and ((a.c1 > 50 and a.c1 < 60) or (b.c2 > 60)); +sql_error select * from stb1 where 'c2' is null; +sql_error select * from stb1 where 'c2' is not null; sql select * from stb1 where c2 > 3.0 or c2 < 60; if $rows != 28 then From abbc1a726256d4990d9f909f1ebd9f5c92ea3c77 Mon Sep 17 00:00:00 2001 From: wpan Date: Mon, 9 Aug 2021 10:01:38 +0800 Subject: [PATCH 080/100] fix merge issue --- src/client/src/tscSQLParser.c | 4 ++++ src/client/src/tscServer.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b0ad6d4a3c..7e31118a90 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4314,6 +4314,10 @@ static bool isValidExpr(tSqlExpr* pLeft, tSqlExpr* pRight, int32_t optr) { return false; } + if (pLeft->tokenId >= TK_BOOL && pLeft->tokenId <= TK_BINARY && (optr == TK_NOTNULL || optr == TK_ISNULL)) { + return false; + } + return true; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 107f630f3d..a1415c3ef8 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -1054,7 +1054,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { SCond *pCond = tsGetSTableQueryCond(pTagCond, pTableMeta->id.uid); if (pCond != NULL && pCond->cond != NULL) { - pQueryMsg->tagCondLen = htonl(pCond->len); + pQueryMsg->tagCondLen = htons(pCond->len); memcpy(pMsg, pCond->cond, pCond->len); pMsg += pCond->len; From 2a9a78ca9a1fd37908816e15daa8c73475d5870b Mon Sep 17 00:00:00 2001 From: xywang Date: Mon, 9 Aug 2021 10:59:44 +0800 Subject: [PATCH 081/100] [TD-5784]: fixed a wrong check --- src/plugins/http/src/httpUtil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index 27b95a4934..ade50bdad6 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -188,7 +188,7 @@ bool httpMallocMultiCmds(HttpContext *pContext, int32_t cmdSize, int32_t bufferS bool httpReMallocMultiCmdsSize(HttpContext *pContext, int32_t cmdSize) { HttpSqlCmds *multiCmds = pContext->multiCmds; - if (cmdSize <= 0 && cmdSize > HTTP_MAX_CMD_SIZE) { + if (cmdSize <= 0 || cmdSize > HTTP_MAX_CMD_SIZE) { httpError("context:%p, fd:%d, user:%s, mulitcmd size:%d large then %d", pContext, pContext->fd, pContext->user, cmdSize, HTTP_MAX_CMD_SIZE); return false; From f73d68a50b24267d5c4465210481da66528fe9a1 Mon Sep 17 00:00:00 2001 From: Zhiyu Yang <69311263+zyyang-taosdata@users.noreply.github.com> Date: Mon, 9 Aug 2021 15:08:39 +0800 Subject: [PATCH 082/100] Hotfix/td 5831 (#7242) * remove useless method * [TD-5831]: add reset query cache test case for restful * [TD-5831]: jni and restful must have user and password properties * add without password test case * add without password test case * change * change * change * change * change * change * change * change * try to remove execute syntax check * change * remove System.out * change * change --- src/connector/jdbc/pom.xml | 1 - .../java/com/taosdata/jdbc/TSDBDriver.java | 7 ++ .../java/com/taosdata/jdbc/TSDBError.java | 2 + .../com/taosdata/jdbc/TSDBErrorNumbers.java | 5 ++ .../com/taosdata/jdbc/TSDBJNIConnector.java | 1 - .../com/taosdata/jdbc/rs/RestfulDriver.java | 10 ++- .../taosdata/jdbc/rs/RestfulStatement.java | 59 ++++++++--------- .../jdbc/utils/SqlSyntaxValidator.java | 15 +---- .../java/com/taosdata/jdbc/SubscribeTest.java | 2 + .../jdbc/cases/AuthenticationTest.java | 44 +++++++++++++ .../taosdata/jdbc/cases/BatchInsertTest.java | 2 + .../com/taosdata/jdbc/cases/ImportTest.java | 2 + .../cases/InsertSpecialCharacterJniTest.java | 41 ++++++++++-- .../InsertSpecialCharacterRestfulTest.java | 6 +- .../taosdata/jdbc/cases/QueryDataTest.java | 2 + .../jdbc/cases/ResetQueryCacheTest.java | 66 +++++++++---------- .../com/taosdata/jdbc/cases/SelectTest.java | 2 + .../com/taosdata/jdbc/cases/StableTest.java | 2 + .../jdbc/utils/SqlSyntaxValidatorTest.java | 21 ------ 19 files changed, 176 insertions(+), 114 deletions(-) delete mode 100644 src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml index 907562fe26..fbeeeb56d3 100644 --- a/src/connector/jdbc/pom.xml +++ b/src/connector/jdbc/pom.xml @@ -113,7 +113,6 @@ **/AppMemoryLeakTest.java - **/AuthenticationTest.java **/ConnectMultiTaosdByRestfulWithDifferentTokenTest.java **/DatetimeBefore1970Test.java **/FailOverTest.java diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java index f5f16758c1..521a88b128 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBDriver.java @@ -14,6 +14,8 @@ *****************************************************************************/ package com.taosdata.jdbc; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.sql.*; import java.util.*; import java.util.logging.Logger; @@ -127,6 +129,11 @@ public class TSDBDriver extends AbstractDriver { return null; } + if (!props.containsKey(TSDBDriver.PROPERTY_KEY_USER)) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED); + if (!props.containsKey(TSDBDriver.PROPERTY_KEY_PASSWORD)) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED); + try { TSDBJNIConnector.init((String) props.get(PROPERTY_KEY_CONFIG_DIR), (String) props.get(PROPERTY_KEY_LOCALE), (String) props.get(PROPERTY_KEY_CHARSET), (String) props.get(PROPERTY_KEY_TIME_ZONE)); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java index d626698663..977ae66515 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBError.java @@ -33,6 +33,8 @@ public class TSDBError { TSDBErrorMap.put(TSDBErrorNumbers.ERROR_NUMERIC_VALUE_OUT_OF_RANGE, "numeric value out of range"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TAOS_TYPE, "unknown taos type in tdengine"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN_TIMESTAMP_PRECISION, "unknown timestamp precision"); + TSDBErrorMap.put(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, "user is required"); + TSDBErrorMap.put(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, "password is required"); TSDBErrorMap.put(TSDBErrorNumbers.ERROR_UNKNOWN, "unknown error"); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java index 3c44d69be5..2207db6f93 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java @@ -29,6 +29,9 @@ public class TSDBErrorNumbers { public static final int ERROR_UNKNOWN_TIMESTAMP_PRECISION = 0x2316; // unknown timestamp precision public static final int ERROR_RESTFul_Client_Protocol_Exception = 0x2317; public static final int ERROR_RESTFul_Client_IOException = 0x2318; + public static final int ERROR_USER_IS_REQUIRED = 0x2319; // user is required + public static final int ERROR_PASSWORD_IS_REQUIRED = 0x231a; // password is required + public static final int ERROR_UNKNOWN = 0x2350; //unknown error @@ -67,6 +70,8 @@ public class TSDBErrorNumbers { errorNumbers.add(ERROR_UNKNOWN_TAOS_TYPE); errorNumbers.add(ERROR_UNKNOWN_TIMESTAMP_PRECISION); errorNumbers.add(ERROR_RESTFul_Client_IOException); + errorNumbers.add(ERROR_USER_IS_REQUIRED); + errorNumbers.add(ERROR_PASSWORD_IS_REQUIRED); errorNumbers.add(ERROR_RESTFul_Client_Protocol_Exception); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java index 4fdbb308c5..c634fe2e95 100755 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java @@ -36,7 +36,6 @@ public class TSDBJNIConnector { static { System.loadLibrary("taos"); - System.out.println("java.library.path:" + System.getProperty("java.library.path")); } public boolean isClosed() { diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java index 9ab67c5502..0a8809e84f 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulDriver.java @@ -7,6 +7,7 @@ import com.taosdata.jdbc.utils.HttpClientPoolUtil; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.sql.*; import java.util.Properties; import java.util.logging.Logger; @@ -40,8 +41,13 @@ public class RestfulDriver extends AbstractDriver { String loginUrl = "http://" + host + ":" + port + "/rest/login/" + props.getProperty(TSDBDriver.PROPERTY_KEY_USER) + "/" + props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD) + ""; try { - String user = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_USER), "UTF-8"); - String password = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD), "UTF-8"); + if (!props.containsKey(TSDBDriver.PROPERTY_KEY_USER)) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED); + if (!props.containsKey(TSDBDriver.PROPERTY_KEY_PASSWORD)) + throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED); + + String user = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_USER), StandardCharsets.UTF_8.displayName()); + String password = URLEncoder.encode(props.getProperty(TSDBDriver.PROPERTY_KEY_PASSWORD), StandardCharsets.UTF_8.displayName()); loginUrl = "http://" + props.getProperty(TSDBDriver.PROPERTY_KEY_HOST) + ":" + props.getProperty(TSDBDriver.PROPERTY_KEY_PORT) + "/rest/login/" + user + "/" + password + ""; } catch (UnsupportedEncodingException e) { e.printStackTrace(); diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java index f8acd8f061..a88dc411f3 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulStatement.java @@ -7,6 +7,7 @@ import com.taosdata.jdbc.AbstractStatement; import com.taosdata.jdbc.TSDBDriver; import com.taosdata.jdbc.TSDBError; import com.taosdata.jdbc.TSDBErrorNumbers; +import com.taosdata.jdbc.enums.TimestampFormat; import com.taosdata.jdbc.utils.HttpClientPoolUtil; import com.taosdata.jdbc.utils.SqlSyntaxValidator; @@ -45,9 +46,7 @@ public class RestfulStatement extends AbstractStatement { if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql); - final String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - - return executeOneUpdate(url, sql); + return executeOneUpdate(sql); } @Override @@ -62,34 +61,25 @@ public class RestfulStatement extends AbstractStatement { public boolean execute(String sql) throws SQLException { if (isClosed()) throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_STATEMENT_CLOSED); - if (!SqlSyntaxValidator.isValidForExecute(sql)) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE, "not a valid sql for execute: " + sql); //如果执行了use操作应该将当前Statement的catalog设置为新的database boolean result = true; - String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - if (conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT).equals("TIMESTAMP")) { - url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlt"; - } - if (conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT).equals("UTC")) { - url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc"; - } if (SqlSyntaxValidator.isUseSql(sql)) { - HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); + HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); this.database = sql.trim().replace("use", "").trim(); this.conn.setCatalog(this.database); result = false; } else if (SqlSyntaxValidator.isDatabaseUnspecifiedQuery(sql)) { executeOneQuery(sql); } else if (SqlSyntaxValidator.isDatabaseUnspecifiedUpdate(sql)) { - executeOneUpdate(url, sql); + executeOneUpdate(sql); result = false; } else { if (SqlSyntaxValidator.isValidForExecuteQuery(sql)) { - executeQuery(sql); + executeOneQuery(sql); } else { - executeUpdate(sql); + executeOneUpdate(sql); result = false; } } @@ -97,19 +87,25 @@ public class RestfulStatement extends AbstractStatement { return result; } + private String getUrl() throws SQLException { + TimestampFormat timestampFormat = TimestampFormat.valueOf(conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT).trim().toUpperCase()); + String url; + switch (timestampFormat) { + case TIMESTAMP: + url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlt"; + break; + case UTC: + url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc"; + break; + default: + url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; + } + return url; + } + private ResultSet executeOneQuery(String sql) throws SQLException { - if (!SqlSyntaxValidator.isValidForExecuteQuery(sql)) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_QUERY, "not a valid sql for executeQuery: " + sql); - // row data - String url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sql"; - String timestampFormat = conn.getClientInfo(TSDBDriver.PROPERTY_KEY_TIMESTAMP_FORMAT); - if ("TIMESTAMP".equalsIgnoreCase(timestampFormat)) - url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlt"; - if ("UTC".equalsIgnoreCase(timestampFormat)) - url = "http://" + conn.getHost() + ":" + conn.getPort() + "/rest/sqlutc"; - - String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); + String result = HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); JSONObject resultJson = JSON.parseObject(result); if (resultJson.getString("status").equals("error")) { throw TSDBError.createSQLException(resultJson.getInteger("code"), resultJson.getString("desc")); @@ -119,11 +115,8 @@ public class RestfulStatement extends AbstractStatement { return resultSet; } - private int executeOneUpdate(String url, String sql) throws SQLException { - if (!SqlSyntaxValidator.isValidForExecuteUpdate(sql)) - throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_INVALID_FOR_EXECUTE_UPDATE, "not a valid sql for executeUpdate: " + sql); - - String result = HttpClientPoolUtil.execute(url, sql, this.conn.getToken()); + private int executeOneUpdate(String sql) throws SQLException { + String result = HttpClientPoolUtil.execute(getUrl(), sql, this.conn.getToken()); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject.getString("status").equals("error")) { throw TSDBError.createSQLException(jsonObject.getInteger("code"), jsonObject.getString("desc")); @@ -134,7 +127,7 @@ public class RestfulStatement extends AbstractStatement { } private int getAffectedRows(JSONObject jsonObject) throws SQLException { - // create ... SQLs should return 0 , and Restful result is this: + // create ... SQLs should return 0 , and Restful result like this: // {"status": "succ", "head": ["affected_rows"], "data": [[0]], "rows": 1} JSONArray head = jsonObject.getJSONArray("head"); if (head.size() != 1 || !"affected_rows".equals(head.getString(0))) diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java index 0f99ff4f66..cbd806b35a 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/SqlSyntaxValidator.java @@ -16,8 +16,7 @@ package com.taosdata.jdbc.utils; public class SqlSyntaxValidator { - private static final String[] SQL = {"select", "insert", "import", "create", "use", "alter", "drop", "set", "show", "describe", "reset"}; - private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set"}; + private static final String[] updateSQL = {"insert", "import", "create", "use", "alter", "drop", "set", "reset"}; private static final String[] querySQL = {"select", "show", "describe"}; private static final String[] databaseUnspecifiedShow = {"databases", "dnodes", "mnodes", "variables"}; @@ -38,14 +37,6 @@ public class SqlSyntaxValidator { return false; } - public static boolean isValidForExecute(String sql) { - for (String prefix : SQL) { - if (sql.trim().toLowerCase().startsWith(prefix)) - return true; - } - return false; - } - public static boolean isDatabaseUnspecifiedQuery(String sql) { for (String databaseObj : databaseUnspecifiedShow) { if (sql.trim().toLowerCase().matches("show\\s+" + databaseObj + ".*")) @@ -63,9 +54,5 @@ public class SqlSyntaxValidator { return sql.trim().toLowerCase().startsWith("use"); } - public static boolean isSelectSql(String sql) { - return sql.trim().toLowerCase().startsWith("select"); - } - } diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java index 24c73fdd5c..95307071e1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/SubscribeTest.java @@ -69,6 +69,8 @@ public class SubscribeTest { @Before public void createDatabase() throws SQLException { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java index 6702de9bdb..0ea46dade2 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/AuthenticationTest.java @@ -1,6 +1,9 @@ package com.taosdata.jdbc.cases; +import com.taosdata.jdbc.TSDBErrorNumbers; +import org.junit.Assert; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import java.sql.*; @@ -12,6 +15,47 @@ public class AuthenticationTest { private static final String password = "taos?data"; private Connection conn; + @Test + public void connectWithoutUserByJni() { + try { + DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?"); + } catch (SQLException e) { + Assert.assertEquals(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, e.getErrorCode()); + Assert.assertEquals("ERROR (2319): user is required", e.getMessage()); + } + } + + @Test + public void connectWithoutUserByRestful() { + try { + DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?"); + } catch (SQLException e) { + Assert.assertEquals(TSDBErrorNumbers.ERROR_USER_IS_REQUIRED, e.getErrorCode()); + Assert.assertEquals("ERROR (2319): user is required", e.getMessage()); + } + } + + @Test + public void connectWithoutPasswordByJni() { + try { + DriverManager.getConnection("jdbc:TAOS://" + host + ":0/?user=root"); + } catch (SQLException e) { + Assert.assertEquals(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, e.getErrorCode()); + Assert.assertEquals("ERROR (231a): password is required", e.getMessage()); + } + } + + @Test + public void connectWithoutPasswordByRestful() { + try { + DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/?user=root"); + } catch (SQLException e) { + Assert.assertEquals(TSDBErrorNumbers.ERROR_PASSWORD_IS_REQUIRED, e.getErrorCode()); + Assert.assertEquals("ERROR (231a): password is required", e.getMessage()); + } + } + + @Ignore @Test public void test() { // change password diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java index e175d6d114..f2b102cfe7 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/BatchInsertTest.java @@ -29,6 +29,8 @@ public class BatchInsertTest { public void before() { try { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java index bc11c7f34e..1297a6b4c4 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ImportTest.java @@ -21,6 +21,8 @@ public class ImportTest { public static void before() { try { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java index 9f8243542f..ac254bebf3 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterJniTest.java @@ -270,6 +270,41 @@ public class InsertSpecialCharacterJniTest { } } + @Ignore + @Test + public void testSingleQuotaEscape() throws SQLException { + final long now = System.currentTimeMillis(); + final String sql = "insert into t? using ? tags(?) values(?, ?, ?) t? using " + tbname2 + " tags(?) values(?,?,?) "; + try (PreparedStatement pstmt = conn.prepareStatement(sql)) { + // t1 + pstmt.setInt(1, 1); + pstmt.setString(2, tbname2); + pstmt.setString(3, special_character_str_5); + pstmt.setTimestamp(4, new Timestamp(now)); + pstmt.setBytes(5, special_character_str_5.getBytes()); + // t2 + pstmt.setInt(7, 2); + pstmt.setString(8, special_character_str_5); + pstmt.setTimestamp(9, new Timestamp(now)); + pstmt.setString(11, special_character_str_5); + + int ret = pstmt.executeUpdate(); + Assert.assertEquals(2, ret); + } + + String query = "select * from ?.t? where ? < ? and ts >= ? and f1 is not null"; + try (PreparedStatement pstmt = conn.prepareStatement(query)) { + pstmt.setString(1, dbName); + pstmt.setInt(2, 1); + pstmt.setString(3, "ts"); + pstmt.setTimestamp(4, new Timestamp(System.currentTimeMillis())); + pstmt.setTimestamp(5, new Timestamp(0)); + + ResultSet rs = pstmt.executeQuery(); + Assert.assertNotNull(rs); + } + } + @Test public void testCase10() throws SQLException { final long now = System.currentTimeMillis(); @@ -293,13 +328,12 @@ public class InsertSpecialCharacterJniTest { Assert.assertEquals(2, ret); } //query t1 - String query = "select * from ?.t? where ts < ? and ts >= ? and ? is not null"; + String query = "select * from ?.t? where ts < ? and ts >= ? and f1 is not null"; try (PreparedStatement pstmt = conn.prepareStatement(query)) { pstmt.setString(1, dbName); pstmt.setInt(2, 1); pstmt.setTimestamp(3, new Timestamp(System.currentTimeMillis())); pstmt.setTimestamp(4, new Timestamp(0)); - pstmt.setString(5, "f1"); ResultSet rs = pstmt.executeQuery(); rs.next(); @@ -311,12 +345,11 @@ public class InsertSpecialCharacterJniTest { Assert.assertNull(f2); } // query t2 - query = "select * from t? where ts < ? and ts >= ? and ? is not null"; + query = "select * from t? where ts < ? and ts >= ? and f2 is not null"; try (PreparedStatement pstmt = conn.prepareStatement(query)) { pstmt.setInt(1, 2); pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis())); pstmt.setTimestamp(3, new Timestamp(0)); - pstmt.setString(4, "f2"); ResultSet rs = pstmt.executeQuery(); rs.next(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java index 2e981e7f41..eedccec6f1 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/InsertSpecialCharacterRestfulTest.java @@ -293,13 +293,12 @@ public class InsertSpecialCharacterRestfulTest { Assert.assertEquals(2, ret); } //query t1 - String query = "select * from ?.t? where ts < ? and ts >= ? and ? is not null"; + String query = "select * from ?.t? where ts < ? and ts >= ? and f1 is not null"; try (PreparedStatement pstmt = conn.prepareStatement(query)) { pstmt.setString(1, dbName); pstmt.setInt(2, 1); pstmt.setTimestamp(3, new Timestamp(System.currentTimeMillis())); pstmt.setTimestamp(4, new Timestamp(0)); - pstmt.setString(5, "f1"); ResultSet rs = pstmt.executeQuery(); rs.next(); @@ -311,12 +310,11 @@ public class InsertSpecialCharacterRestfulTest { Assert.assertNull(f2); } // query t2 - query = "select * from t? where ts < ? and ts >= ? and ? is not null"; + query = "select * from t? where ts < ? and ts >= ? and f2 is not null"; try (PreparedStatement pstmt = conn.prepareStatement(query)) { pstmt.setInt(1, 2); pstmt.setTimestamp(2, new Timestamp(System.currentTimeMillis())); pstmt.setTimestamp(3, new Timestamp(0)); - pstmt.setString(4, "f2"); ResultSet rs = pstmt.executeQuery(); rs.next(); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java index 3fea221446..b4449491a9 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/QueryDataTest.java @@ -22,6 +22,8 @@ public class QueryDataTest { public void createDatabase() { try { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResetQueryCacheTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResetQueryCacheTest.java index 4eebbd08e8..48753d62f0 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResetQueryCacheTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/ResetQueryCacheTest.java @@ -1,51 +1,49 @@ package com.taosdata.jdbc.cases; -import com.taosdata.jdbc.TSDBDriver; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import java.sql.*; -import java.util.Properties; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.Statement; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; public class ResetQueryCacheTest { - static Connection connection; - static Statement statement; - static String host = "127.0.0.1"; + @Test + public void jni() throws SQLException { + // given + Connection connection = DriverManager.getConnection("jdbc:TAOS://127.0.0.1:0/?user=root&password=taosdata&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"); + Statement statement = connection.createStatement(); - @Before - public void init() { - try { - Properties properties = new Properties(); - properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - connection = DriverManager.getConnection("jdbc:TAOS://" + host + ":0/", properties); - statement = connection.createStatement(); - } catch (SQLException e) { - return; - } + // when + boolean execute = statement.execute("reset query cache"); + + // then + assertFalse(execute); + assertEquals(0, statement.getUpdateCount()); + + statement.close(); + connection.close(); } @Test - public void testResetQueryCache() throws SQLException { - String resetSql = "reset query cache"; - statement.execute(resetSql); - } + public void restful() throws SQLException { + // given + Connection connection = DriverManager.getConnection("jdbc:TAOS-RS://127.0.0.1:6041/?user=root&password=taosdata&timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8"); + Statement statement = connection.createStatement(); - @After - public void close() { - try { - if (statement != null) - statement.close(); - if (connection != null) - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } + // when + boolean execute = statement.execute("reset query cache"); + + // then + assertFalse(execute); + assertEquals(0, statement.getUpdateCount()); + + statement.close(); + connection.close(); } } \ No newline at end of file diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java index 0022ceaf21..b51c0309be 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/SelectTest.java @@ -20,6 +20,8 @@ public class SelectTest { public void createDatabaseAndTable() { try { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java index 1600fec13d..8e10743e5e 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/StableTest.java @@ -24,6 +24,8 @@ public class StableTest { public static void createDatabase() { try { Properties properties = new Properties(); + properties.setProperty(TSDBDriver.PROPERTY_KEY_USER, "root"); + properties.setProperty(TSDBDriver.PROPERTY_KEY_PASSWORD, "taosdata"); properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java deleted file mode 100644 index ccb0941da0..0000000000 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/SqlSyntaxValidatorTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.taosdata.jdbc.utils; - -import org.junit.Assert; -import org.junit.Test; - -public class SqlSyntaxValidatorTest { - - @Test - public void isSelectSQL() { - Assert.assertTrue(SqlSyntaxValidator.isSelectSql("select * from test.weather")); - Assert.assertTrue(SqlSyntaxValidator.isSelectSql(" select * from test.weather")); - Assert.assertTrue(SqlSyntaxValidator.isSelectSql(" select * from test.weather ")); - Assert.assertFalse(SqlSyntaxValidator.isSelectSql("insert into test.weather values(now, 1.1, 2)")); - } - - @Test - public void isUseSQL() { - Assert.assertTrue(SqlSyntaxValidator.isUseSql("use database test")); - } - -} \ No newline at end of file From 370be2788751eb5fdac3374ff1fdace71e65372f Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Mon, 9 Aug 2021 15:36:30 +0800 Subject: [PATCH 083/100] [TD-5578] add show like wild cards max length --- src/client/src/tscSQLParser.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 2d8196982c..7b4d861e24 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -3218,7 +3218,7 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { pCmd->command = TSDB_SQL_SHOW; const char* msg1 = "invalid name"; - const char* msg2 = "pattern filter string too long"; + const char* msg2 = "wildcard string should be less than %d characters"; const char* msg3 = "database name too long"; const char* msg4 = "invalid ip address"; const char* msg5 = "database name is empty"; @@ -3262,8 +3262,10 @@ int32_t setShowInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg6); } - if (!tscValidateTableNameLength(pCmd->payloadLen)) { - return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); + if (pPattern->n > tsMaxWildCardsLen){ + char tmp[64] = {0}; + sprintf(tmp, msg2, tsMaxWildCardsLen); + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), tmp); } } } else if (showType == TSDB_MGMT_TABLE_VNODES) { From dd2c83fc287782a4e587becdb2941a0ce0ace482 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Mon, 9 Aug 2021 08:29:13 -0300 Subject: [PATCH 084/100] [TD-5616]: finish like wildcard max_length test add getVariable() to util/sql.py add 4 testcases to query/queryWildcardLength.py leave a uncorrelated bug ---> TD-5918 --- tests/pytest/query/queryWildcardLength.py | 217 ++++++++++++++++++++++ tests/pytest/util/sql.py | 16 ++ 2 files changed, 233 insertions(+) create mode 100644 tests/pytest/query/queryWildcardLength.py diff --git a/tests/pytest/query/queryWildcardLength.py b/tests/pytest/query/queryWildcardLength.py new file mode 100644 index 0000000000..d15085f751 --- /dev/null +++ b/tests/pytest/query/queryWildcardLength.py @@ -0,0 +1,217 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +from copy import deepcopy +import string +import random +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def cleanTb(self): + query_sql = "show stables" + res_row_list = tdSql.query(query_sql, True) + stb_list = map(lambda x: x[0], res_row_list) + for stb in stb_list: + tdSql.execute(f'drop table if exists {stb}') + + query_sql = "show tables" + res_row_list = tdSql.query(query_sql, True) + tb_list = map(lambda x: x[0], res_row_list) + for tb in tb_list: + tdSql.execute(f'drop table if exists {tb}') + + def getLongWildcardStr(self, len=None): + """ + generate long wildcard str + """ + maxWildCardsLength = int(tdSql.getVariable('maxWildCardsLength')[0]) + if len: + chars = ''.join(random.choice(string.ascii_letters.lower()) for i in range(len)) + else: + chars = ''.join(random.choice(string.ascii_letters.lower()) for i in range(maxWildCardsLength+1)) + return chars + + def genTableName(self): + ''' + generate table name + hp_name--->'%str' + lp_name--->'str%' + ul_name--->'st_r' + ''' + table_name = self.getLongWildcardStr() + table_name_list = list(table_name) + table_name_list.pop(-1) + + if len(table_name_list) > 1: + lp_name = deepcopy(table_name_list) + lp_name[-1] = '%' + lp_name = ''.join(lp_name) + + ul_name = list(lp_name) + ul_name[int(len(ul_name)/2)] = '_' + ul_name = ''.join(ul_name) + + table_name_list = list(table_name) + hp_name = deepcopy(table_name_list) + hp_name.pop(1) + hp_name[0] = '%' + hp_name = ''.join(hp_name) + else: + hp_name = '%' + lp_name = '%' + ul_name = '_' + return table_name, hp_name, lp_name, ul_name + + def checkRegularTableWildcardLength(self): + ''' + check regular table wildcard length with % and _ + ''' + self.cleanTb() + table_name, hp_name, lp_name, ul_name = self.genTableName() + tdSql.execute(f"CREATE TABLE {table_name} (ts timestamp, a1 int)") + sql_list = [f'show tables like "{hp_name}"', f'show tables like "{lp_name}"', f'show tables like "{ul_name}"'] + for sql in sql_list: + tdSql.query(sql) + if len(table_name) >= 1: + tdSql.checkRows(1) + else: + tdSql.error(sql) + + exceed_sql_list = [f'show tables like "%{hp_name}"', f'show tables like "{lp_name}%"', f'show tables like "{ul_name}%"'] + for sql in exceed_sql_list: + tdSql.error(sql) + + def checkSuperTableWildcardLength(self): + ''' + check super table wildcard length with % and _ + ''' + self.cleanTb() + table_name, hp_name, lp_name, ul_name = self.genTableName() + tdSql.execute(f"CREATE TABLE {table_name} (ts timestamp, c1 int) tags (t1 int)") + sql_list = [f'show stables like "{hp_name}"', f'show stables like "{lp_name}"', f'show stables like "{ul_name}"'] + for sql in sql_list: + tdSql.query(sql) + if len(table_name) >= 1: + tdSql.checkRows(1) + else: + tdSql.error(sql) + + exceed_sql_list = [f'show stables like "%{hp_name}"', f'show stables like "{lp_name}%"', f'show stables like "{ul_name}%"'] + for sql in exceed_sql_list: + tdSql.error(sql) + + def checkRegularWildcardSelectLength(self): + ''' + check regular table wildcard select length with % and _ + ''' + self.cleanTb() + table_name, hp_name, lp_name, ul_name = self.genTableName() + tdSql.execute(f"CREATE TABLE {table_name} (ts timestamp, bi1 binary(200), nc1 nchar(200))") + tdSql.execute(f'insert into {table_name} values (now, "{table_name}", "{table_name}")') + sql_list = [f'select * from {table_name} where bi1 like "{hp_name}"', + f'select * from {table_name} where bi1 like "{lp_name}"', + f'select * from {table_name} where bi1 like "{ul_name}"', + f'select * from {table_name} where nc1 like "{hp_name}"', + f'select * from {table_name} where nc1 like "{lp_name}"', + f'select * from {table_name} where nc1 like "{ul_name}"'] + for sql in sql_list: + tdSql.query(sql) + if len(table_name) >= 1: + tdSql.checkRows(1) + else: + tdSql.error(sql) + + exceed_sql_list = [f'select * from {table_name} where bi1 like "%{hp_name}"', + f'select * from {table_name} where bi1 like "{lp_name}%"', + f'select * from {table_name} where bi1 like "{ul_name}%"', + f'select * from {table_name} where nc1 like "%{hp_name}"', + f'select * from {table_name} where nc1 like "{lp_name}%"', + f'select * from {table_name} where nc1 like "{ul_name}%"'] + for sql in exceed_sql_list: + tdSql.error(sql) + + def checkStbWildcardSelectLength(self): + ''' + check stb wildcard select length with % and _ + ''' + self.cleanTb() + table_name, hp_name, lp_name, ul_name = self.genTableName() + + tdSql.execute(f'CREATE TABLE {table_name} (ts timestamp, bi1 binary(200), nc1 nchar(200)) tags (si1 binary(200), sc1 nchar(200))') + tdSql.execute(f'create table {table_name}_sub1 using {table_name} tags ("{table_name}", "{table_name}")') + tdSql.execute(f'insert into {table_name}_sub1 values (now, "{table_name}", "{table_name}");') + + # TODO sc1 leave a bug ---> TD-5918 + # sql_list = [f'select * from {table_name} where bi1 like "{hp_name}"', + # f'select * from {table_name} where bi1 like "{lp_name}"', + # f'select * from {table_name} where bi1 like "{ul_name}"', + # f'select * from {table_name} where nc1 like "{hp_name}"', + # f'select * from {table_name} where nc1 like "{lp_name}"', + # f'select * from {table_name} where nc1 like "{ul_name}"', + # f'select * from {table_name} where si1 like "{hp_name}"', + # f'select * from {table_name} where si1 like "{lp_name}"', + # f'select * from {table_name} where si1 like "{ul_name}"', + # f'select * from {table_name} where sc1 like "{hp_name}"', + # f'select * from {table_name} where sc1 like "{lp_name}"', + # f'select * from {table_name} where sc1 like "{ul_name}"'] + sql_list = [f'select * from {table_name} where bi1 like "{hp_name}"', + f'select * from {table_name} where bi1 like "{lp_name}"', + f'select * from {table_name} where bi1 like "{ul_name}"', + f'select * from {table_name} where nc1 like "{hp_name}"', + f'select * from {table_name} where nc1 like "{lp_name}"', + f'select * from {table_name} where nc1 like "{ul_name}"', + f'select * from {table_name} where si1 like "{hp_name}"', + f'select * from {table_name} where si1 like "{lp_name}"', + f'select * from {table_name} where si1 like "{ul_name}"'] + for sql in sql_list: + tdSql.query(sql) + if len(table_name) >= 1: + tdSql.checkRows(1) + else: + tdSql.error(sql) + exceed_sql_list = [f'select * from {table_name} where bi1 like "%{hp_name}"', + f'select * from {table_name} where bi1 like "{lp_name}%"', + f'select * from {table_name} where bi1 like "{ul_name}%"', + f'select * from {table_name} where nc1 like "%{hp_name}"', + f'select * from {table_name} where nc1 like "{lp_name}%"', + f'select * from {table_name} where nc1 like "{ul_name}%"', + f'select * from {table_name} where si1 like "%{hp_name}"', + f'select * from {table_name} where si1 like "{lp_name}%"', + f'select * from {table_name} where si1 like "{ul_name}%"', + f'select * from {table_name} where sc1 like "%{hp_name}"', + f'select * from {table_name} where sc1 like "{lp_name}%"', + f'select * from {table_name} where sc1 like "{ul_name}%"'] + for sql in exceed_sql_list: + tdSql.error(sql) + + def run(self): + tdSql.prepare() + self.checkRegularTableWildcardLength() + self.checkSuperTableWildcardLength() + self.checkRegularWildcardSelectLength() + self.checkStbWildcardSelectLength() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index b42af27d06..dfe1e4a582 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -81,6 +81,22 @@ class TDSql: return self.queryResult return self.queryRows + def getVariable(self, search_attr): + ''' + get variable of search_attr access "show variables" + ''' + try: + sql = 'show variables' + param_list = self.query(sql, row_tag=True) + for param in param_list: + if param[0] == search_attr: + return param[1], param_list + except Exception as e: + caller = inspect.getframeinfo(inspect.stack()[1][0]) + args = (caller.filename, caller.lineno, sql, repr(e)) + tdLog.notice("%s(%d) failed: sql:%s, %s" % args) + raise Exception(repr(e)) + def getColNameList(self, sql, col_tag=None): self.sql = sql try: From a5cd3fb1cbffe228b83064077438361f9e4ffe74 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Mon, 9 Aug 2021 20:41:05 +0800 Subject: [PATCH 085/100] test[ci skip] --- Jenkinsfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index e6e8a1df32..f1de92cded 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ node { } def skipstage=0 - +def skipbuild=0 def abortPreviousBuilds() { def currentJobName = env.JOB_NAME def currentBuildNumber = env.BUILD_NUMBER.toInteger() @@ -146,6 +146,7 @@ pipeline { script{ env.skipstage=sh(script:"cd ${WORKSPACE}.tes && git --no-pager diff --name-only FETCH_HEAD ${env.CHANGE_TARGET}|grep -v -E '.*md|//src//connector|Jenkinsfile|test-all.sh' || echo 0 ",returnStdout:true) + env.skipbuild=sh(script: "git log -1 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) } println env.skipstage sh''' @@ -160,6 +161,7 @@ pipeline { changeRequest() expression { env.skipstage != 0 + env.skipbuild ==1 } } parallel { From f68b955cc08b44811fdd26ed8928477b842bb432 Mon Sep 17 00:00:00 2001 From: Yiqing Liu Date: Tue, 10 Aug 2021 10:12:23 +0800 Subject: [PATCH 086/100] Revert "test[ci skip]" --- Jenkinsfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f1de92cded..e6e8a1df32 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -6,7 +6,7 @@ node { } def skipstage=0 -def skipbuild=0 + def abortPreviousBuilds() { def currentJobName = env.JOB_NAME def currentBuildNumber = env.BUILD_NUMBER.toInteger() @@ -146,7 +146,6 @@ pipeline { script{ env.skipstage=sh(script:"cd ${WORKSPACE}.tes && git --no-pager diff --name-only FETCH_HEAD ${env.CHANGE_TARGET}|grep -v -E '.*md|//src//connector|Jenkinsfile|test-all.sh' || echo 0 ",returnStdout:true) - env.skipbuild=sh(script: "git log -1 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) } println env.skipstage sh''' @@ -161,7 +160,6 @@ pipeline { changeRequest() expression { env.skipstage != 0 - env.skipbuild ==1 } } parallel { From ca5f589d85b6f716d840f376bf0accbf6015e362 Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Tue, 10 Aug 2021 11:24:52 +0800 Subject: [PATCH 087/100] [TD-5707]: add test case --- tests/pytest/fulltest.sh | 1 + tests/pytest/functions/function_interp.py | 46 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/pytest/functions/function_interp.py diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 6d7f1d00bf..c929d8da22 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -343,6 +343,7 @@ python3 ./test.py -f functions/function_twa.py -r 1 python3 ./test.py -f functions/function_twa_test2.py python3 ./test.py -f functions/function_stddev_td2555.py python3 ./test.py -f functions/showOfflineThresholdIs864000.py +python3 ./test.py -f functions/function_interp.py python3 ./test.py -f insert/metadataUpdate.py python3 ./test.py -f query/last_cache.py python3 ./test.py -f query/last_row_cache.py diff --git a/tests/pytest/functions/function_interp.py b/tests/pytest/functions/function_interp.py new file mode 100644 index 0000000000..810c90279c --- /dev/null +++ b/tests/pytest/functions/function_interp.py @@ -0,0 +1,46 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import * +from util.cases import * +from util.sql import * +import numpy as np + + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + + self.rowNum = 10 + self.ts = 1537146000000 + + def run(self): + tdSql.prepare() + tdSql.execute("create table t(ts timestamp, k int)") + tdSql.execute("insert into t values('2021-1-1 1:1:1', 12);") + + tdSql.query("select interp(*) from t where ts='2021-1-1 1:1:1'") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 12) + + tdSql.error("select interp(*) from t where ts >'2021-1-1 1:1:1' and ts < now interval(1s) fill(next)") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From c585958a7723c90d9b397bee60610b6d216a3b3e Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 10 Aug 2021 12:37:35 +0800 Subject: [PATCH 088/100] [TD-5918] fix assert core by expand wild cards --- src/common/src/tglobal.c | 2 +- src/util/src/tcompare.c | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 3c904dc034..f9135605bb 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -991,7 +991,7 @@ static void doInitGlobalConfig(void) { cfg.valType = TAOS_CFG_VTYPE_INT32; cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; cfg.minValue = 0; - cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN; + cfg.maxValue = TSDB_MAX_FIELD_LEN; cfg.ptrLength = 0; cfg.unitType = TAOS_CFG_UTYPE_BYTE; taosInitConfigOption(cfg); diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 7577451f88..906995053b 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -280,25 +280,26 @@ int WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t size, c int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; - - char pattern[128] = {0}; + + assert(varDataLen(pRight) < TSDB_MAX_FIELD_LEN); + char *pattern = calloc(varDataLen(pRight) + 1, sizeof(char)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); - assert(varDataLen(pRight) < 128); size_t sz = varDataLen(pLeft); - char *buf = malloc(sz + 1); - memcpy(buf, varDataVal(pLeft), sz); + char *buf = malloc(sz + 1); + memcpy(buf, varDataVal(pLeft), sz); buf[sz] = 0; int32_t ret = patternMatch(pattern, buf, sz, &pInfo); free(buf); + free(pattern); return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; } int32_t taosArrayCompareString(const void* a, const void* b) { const char* x = *(const char**)a; const char* y = *(const char**)b; - + return compareLenPrefixedStr(x, y); } @@ -307,19 +308,19 @@ int32_t taosArrayCompareString(const void* a, const void* b) { // return taosArraySearchString(arr, pLeft, taosArrayCompareString, TD_EQ) == NULL ? 0 : 1; //} int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { - return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; + return NULL != taosHashGet((SHashObj *)pRight, varDataVal(pLeft), varDataLen(pLeft)) ? 1 : 0; } int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; - wchar_t pattern[128] = {0}; - assert(TSDB_PATTERN_STRING_MAX_LEN < 128); + assert(varDataLen(pRight) < TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); + wchar_t *pattern = calloc(varDataLen(pRight) + 1, sizeof(wchar_t)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); - assert(varDataLen(pRight) < 128); - + int32_t ret = WCSPatternMatch(pattern, varDataVal(pLeft), varDataLen(pLeft)/TSDB_NCHAR_SIZE, &pInfo); + free(pattern); return (ret == TSDB_PATTERN_MATCH) ? 0 : 1; } From e8af7af7d615b44449d3e4506b67cf4895988f17 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 10 Aug 2021 17:20:57 +0800 Subject: [PATCH 089/100] [TD-5918] fix assert core by expand wild cards --- src/util/src/tcompare.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/src/tcompare.c b/src/util/src/tcompare.c index 906995053b..a3c01d2be7 100644 --- a/src/util/src/tcompare.c +++ b/src/util/src/tcompare.c @@ -281,7 +281,7 @@ int WCSPatternMatch(const wchar_t *patterStr, const wchar_t *str, size_t size, c int32_t compareStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; - assert(varDataLen(pRight) < TSDB_MAX_FIELD_LEN); + assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN); char *pattern = calloc(varDataLen(pRight) + 1, sizeof(char)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); @@ -314,7 +314,7 @@ int32_t compareFindItemInSet(const void *pLeft, const void* pRight) { int32_t compareWStrPatternComp(const void* pLeft, const void* pRight) { SPatternCompareInfo pInfo = {'%', '_'}; - assert(varDataLen(pRight) < TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); + assert(varDataLen(pRight) <= TSDB_MAX_FIELD_LEN * TSDB_NCHAR_SIZE); wchar_t *pattern = calloc(varDataLen(pRight) + 1, sizeof(wchar_t)); memcpy(pattern, varDataVal(pRight), varDataLen(pRight)); From 28725856d74f974c16dad8e68e0ed0142c765691 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Tue, 10 Aug 2021 07:01:41 -0300 Subject: [PATCH 090/100] [TD-5918]bug fixed in branch fix/TD-5918 modify testcases test maxWildCardsLength=16384 by manual --- tests/pytest/query/queryWildcardLength.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/pytest/query/queryWildcardLength.py b/tests/pytest/query/queryWildcardLength.py index d15085f751..1fc46fe7d6 100644 --- a/tests/pytest/query/queryWildcardLength.py +++ b/tests/pytest/query/queryWildcardLength.py @@ -157,19 +157,6 @@ class TDTestCase: tdSql.execute(f'create table {table_name}_sub1 using {table_name} tags ("{table_name}", "{table_name}")') tdSql.execute(f'insert into {table_name}_sub1 values (now, "{table_name}", "{table_name}");') - # TODO sc1 leave a bug ---> TD-5918 - # sql_list = [f'select * from {table_name} where bi1 like "{hp_name}"', - # f'select * from {table_name} where bi1 like "{lp_name}"', - # f'select * from {table_name} where bi1 like "{ul_name}"', - # f'select * from {table_name} where nc1 like "{hp_name}"', - # f'select * from {table_name} where nc1 like "{lp_name}"', - # f'select * from {table_name} where nc1 like "{ul_name}"', - # f'select * from {table_name} where si1 like "{hp_name}"', - # f'select * from {table_name} where si1 like "{lp_name}"', - # f'select * from {table_name} where si1 like "{ul_name}"', - # f'select * from {table_name} where sc1 like "{hp_name}"', - # f'select * from {table_name} where sc1 like "{lp_name}"', - # f'select * from {table_name} where sc1 like "{ul_name}"'] sql_list = [f'select * from {table_name} where bi1 like "{hp_name}"', f'select * from {table_name} where bi1 like "{lp_name}"', f'select * from {table_name} where bi1 like "{ul_name}"', @@ -178,7 +165,11 @@ class TDTestCase: f'select * from {table_name} where nc1 like "{ul_name}"', f'select * from {table_name} where si1 like "{hp_name}"', f'select * from {table_name} where si1 like "{lp_name}"', - f'select * from {table_name} where si1 like "{ul_name}"'] + f'select * from {table_name} where si1 like "{ul_name}"', + f'select * from {table_name} where sc1 like "{hp_name}"', + f'select * from {table_name} where sc1 like "{lp_name}"', + f'select * from {table_name} where sc1 like "{ul_name}"'] + for sql in sql_list: tdSql.query(sql) if len(table_name) >= 1: @@ -211,7 +202,6 @@ class TDTestCase: tdSql.close() tdLog.success("%s successfully executed" % __file__) - tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) From 78844c5ea893d44daa82d8156c3e7b0a74a7b8b8 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Tue, 10 Aug 2021 18:06:54 +0800 Subject: [PATCH 091/100] [TD-5907]add some nodes[ci skip] --- Jenkinsfile | 42 ++- tests/pytest/crash_gen/valgrind_taos.supp | 368 +++++++++++++++++++++- 2 files changed, 386 insertions(+), 24 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index f1de92cded..0ccf302ba6 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,8 +4,6 @@ properties([pipelineTriggers([githubPush()])]) node { git url: 'https://github.com/taosdata/TDengine.git' } - -def skipstage=0 def skipbuild=0 def abortPreviousBuilds() { def currentJobName = env.JOB_NAME @@ -34,7 +32,7 @@ def abort_previous(){ } def pre_test(){ - + sh'hostname' sh ''' sudo rmtaos || echo "taosd has not installed" ''' @@ -144,11 +142,11 @@ pipeline { git checkout -qf FETCH_HEAD ''' - script{ - env.skipstage=sh(script:"cd ${WORKSPACE}.tes && git --no-pager diff --name-only FETCH_HEAD ${env.CHANGE_TARGET}|grep -v -E '.*md|//src//connector|Jenkinsfile|test-all.sh' || echo 0 ",returnStdout:true) - env.skipbuild=sh(script: "git log -1 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]'", returnStatus: true) + script{ + skipbuild='2' + skipbuild=sh(script: "git log -2 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]' && echo 1 || echo 2", returnStdout:true) + println skipbuild } - println env.skipstage sh''' rm -rf ${WORKSPACE}.tes ''' @@ -158,17 +156,17 @@ pipeline { stage('Parallel test stage') { //only build pr when { + allOf { changeRequest() - expression { - env.skipstage != 0 - env.skipbuild ==1 + expression{ + return skipbuild.trim() == '2' } + } } parallel { stage('python_1_s1') { - agent{label 'p1'} + agent any steps { - pre_test() timeout(time: 45, unit: 'MINUTES'){ sh ''' @@ -181,7 +179,7 @@ pipeline { } } stage('python_2_s5') { - agent{label 'p2'} + agent any steps { pre_test() @@ -195,7 +193,7 @@ pipeline { } } stage('python_3_s6') { - agent{label 'p3'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() @@ -208,7 +206,7 @@ pipeline { } } stage('test_b1_s2') { - agent{label 'b1'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() @@ -221,8 +219,7 @@ pipeline { } stage('test_crash_gen_s3') { - agent{label "b2"} - + agent any steps { pre_test() catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { @@ -260,8 +257,7 @@ pipeline { } stage('test_valgrind_s4') { - agent{label "b3"} - + agent any steps { pre_test() catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { @@ -286,7 +282,7 @@ pipeline { } } stage('test_b4_s7') { - agent{label 'b4'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() @@ -305,7 +301,7 @@ pipeline { } } stage('test_b5_s8') { - agent{label 'b5'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() @@ -318,7 +314,7 @@ pipeline { } } stage('test_b6_s9') { - agent{label 'b6'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() @@ -331,7 +327,7 @@ pipeline { } } stage('test_b7_s10') { - agent{label 'b7'} + agent any steps { timeout(time: 45, unit: 'MINUTES'){ pre_test() diff --git a/tests/pytest/crash_gen/valgrind_taos.supp b/tests/pytest/crash_gen/valgrind_taos.supp index 376567b7e8..b9296f008e 100644 --- a/tests/pytest/crash_gen/valgrind_taos.supp +++ b/tests/pytest/crash_gen/valgrind_taos.supp @@ -17742,4 +17742,370 @@ fun:taosGetFqdn fun:taosCheckGlobalCfg fun:taos_init_imp -} \ No newline at end of file +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/bin/python3.8 + fun:PyObject_GetItem + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + fun:PyCode_NewWithPosOnlyArgs + fun:PyCode_New + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/tslibs/parsing.cpython-38-x86_64-linux-gnu.so + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/tslibs/parsing.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/local/lib/python3.8 + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_New + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_New + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun: malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/interval.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun: malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + obj:/usr/bin/python3.8 + fun:PyObject_CallFunctionObjArgs + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyObject_GetAttr + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8) + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8) + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8) + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8) + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/interval.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8) + obj:/usr/bin/python3.8) + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/tslibs/np_datetime.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/tslibs/ccalendar.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/interval.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_Pack + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/hashtable.cpython-38-x86_64-linux-gnu.so + obj:/usr/local/lib/python3.8/dist-packages/pandas/_libs/hashtable.cpython-38-x86_64-linux-gnu.so + fun:PyModule_ExecDef + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:PyVectorcall_Call + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall +} +{ + + Memcheck:Leak + match-leak-kinds: definite + ... + obj:/usr/local/lib/python3.8/dist-packages/pandas/* + ... +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_New + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_New + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:_PyObject_MakeTpCall + fun:_PyEval_EvalFrameDefault + fun:_PyFunction_Vectorcall + fun:_PyEval_EvalFrameDefault + obj:/usr/bin/python3.8 + fun:PyObject_GetAttr + fun:_PyEval_EvalFrameDefault +} +{ + + Memcheck:Leak + match-leak-kinds: definite + fun:malloc + obj:/usr/bin/python3.8 + fun:PyTuple_New + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + obj:/usr/bin/python3.8 + fun:_PyEval_EvalFrameDefault + fun:_PyEval_EvalCodeWithName + fun:_PyFunction_Vectorcall +} \ No newline at end of file From 4a210d79340e5bb5b0ac5d0ce9b31eeceabf2d19 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Tue, 10 Aug 2021 18:09:41 +0800 Subject: [PATCH 092/100] test[ci skip] --- tests/pytest/crash_gen/valgrind_taos.supp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/pytest/crash_gen/valgrind_taos.supp b/tests/pytest/crash_gen/valgrind_taos.supp index b9296f008e..6c92f33018 100644 --- a/tests/pytest/crash_gen/valgrind_taos.supp +++ b/tests/pytest/crash_gen/valgrind_taos.supp @@ -18108,4 +18108,4 @@ fun:_PyEval_EvalFrameDefault fun:_PyEval_EvalCodeWithName fun:_PyFunction_Vectorcall -} \ No newline at end of file +} \ No newline at end of file From a28da20984f1ad4ed28e17bea767722c909234c5 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Tue, 10 Aug 2021 18:40:19 +0800 Subject: [PATCH 093/100] [TD-4181] : update Administrator related doc. --- documentation20/cn/11.administrator/docs.md | 405 +++++++++++++++++--- 1 file changed, 347 insertions(+), 58 deletions(-) diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index 2eb4ac50cc..496d16ec63 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -1,4 +1,4 @@ -# TDengine的运营与维护 +# TDengine的运营与运维 ## 容量规划 @@ -28,12 +28,28 @@ taosd 内存总量 = vnode 内存 + mnode 内存 + 查询内存 最后,如果内存充裕,可以考虑加大 Blocks 的配置,这样更多数据将保存在内存里,提高查询速度。 +#### 客户端内存需求 + +客户端应用采用 taosc 客户端驱动连接服务端,会有内存需求的开销。 + +客户端的内存开销主要由写入过程中的 SQL 语句、表的元数据信息缓存、以及结构性开销构成。系统最大容纳的表数量为 N(每个通过超级表创建的表的 meta data 开销约 256 字节),最大并行写入线程数量 T,最大 SQL 语句长度 S(通常是 1 Mbytes)。由此可以进行客户端内存开销的估算(单位 MBytes): +``` +M = (T * S * 3 + (N / 4096) + 100) +``` + +举例如下:用户最大并发写入线程数 100,子表数总数 10,000,000,那么客户端的内存最低要求是: +``` +100 * 3 + (10000000 / 4096) + 100 = 2741 (MBytes) +``` + +即配置 3 GBytes 内存是最低要求。 + ### CPU 需求 CPU 的需求取决于如下两方面: -* __数据插入__ TDengine 单核每秒能至少处理一万个插入请求。每个插入请求可以带多条记录,一次插入一条记录与插入 10 条记录,消耗的计算资源差别很小。因此每次插入,条数越大,插入效率越高。如果一个插入请求带 200 条以上记录,单核就能达到每秒插入 100 万条记录的速度。但对前端数据采集的要求越高,因为需要缓存记录,然后一批插入。 -* __查询需求__ TDengine 提供高效的查询,但是每个场景的查询差异很大,查询频次变化也很大,难以给出客观数字。需要用户针对自己的场景,写一些查询语句,才能确定。 +* **数据插入** TDengine 单核每秒能至少处理一万个插入请求。每个插入请求可以带多条记录,一次插入一条记录与插入 10 条记录,消耗的计算资源差别很小。因此每次插入,条数越大,插入效率越高。如果一个插入请求带 200 条以上记录,单核就能达到每秒插入 100 万条记录的速度。但对前端数据采集的要求越高,因为需要缓存记录,然后一批插入。 +* **查询需求** TDengine 提供高效的查询,但是每个场景的查询差异很大,查询频次变化也很大,难以给出客观数字。需要用户针对自己的场景,写一些查询语句,才能确定。 因此仅对数据插入而言,CPU 是可以估算出来的,但查询所耗的计算资源无法估算。在实际运营过程中,不建议 CPU 使用率超过 50%,超过后,需要增加新的节点,以获得更多计算资源。 @@ -96,51 +112,169 @@ TDengine系统后台服务由taosd提供,可以在配置文件taos.cfg里修 taosd -C ``` -下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是工作的,一般无需设置。**注意:配置修改后,需要重启*taosd*服务才能生效。** +下面仅仅列出一些重要的配置参数,更多的参数请看配置文件里的说明。各个参数的详细介绍及作用请看前述章节,而且这些参数的缺省配置都是可以工作的,一般无需设置。**注意:配置文件参数修改后,需要重启*taosd*服务,或客户端应用才能生效。** -- firstEp: taosd启动时,主动连接的集群中首个dnode的end point, 默认值为localhost:6030。 -- fqdn:数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。这个参数值的长度需要控制在 96 个字符以内。 -- serverPort:taosd启动后,对外服务的端口号,默认值为6030。(RESTful服务使用的端口号是在此基础上+11,即默认值为6041。) -- dataDir: 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。 -- logDir:日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos。 -- arbitrator:系统中裁决器的end point, 缺省值为空。 -- role:dnode的可选角色。0-any; 既可作为mnode,也可分配vnode;1-mgmt;只能作为mnode,不能分配vnode;2-dnode;不能作为mnode,只能分配vnode -- debugFlag:运行日志开关。131(输出错误和警告日志),135( 输出错误、警告和调试日志),143( 输出错误、警告、调试和跟踪日志)。默认值:131或135(不同模块有不同的默认值)。 -- numOfLogLines:单个日志文件允许的最大行数。默认值:10,000,000行。 -- logKeepDays:日志文件的最长保存时间。大于0时,日志文件会被重命名为taosdlog.xxx,其中xxx为日志文件最后修改的时间戳,单位为秒。默认值:0天。 -- maxSQLLength:单条SQL语句允许最长限制。默认值:65380字节。 -- telemetryReporting: 是否允许 TDengine 采集和上报基本使用信息,0表示不允许,1表示允许。 默认值:1。 -- stream: 是否启用连续查询(流计算功能),0表示不允许,1表示允许。 默认值:1。 -- queryBufferSize: 为所有并发查询占用保留的内存大小。计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。单位为 MB(2.0.15 以前的版本中,此参数的单位是字节)。 -- ratioOfQueryCores: 设置查询线程的最大数量。最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。 +| **#** | **配置参数名称** | **内部** | **S\|C** | **单位** | **含义** | **取值范围** | **缺省值** | **备注** | +| ----- | ----------------------- | -------- | -------- | -------- | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | +| 1 | firstEP | | **SC** | | taosd启动时,主动连接的集群中首个dnode的end point | | localhost:6030 | | +| 2 | secondEP | YES | **SC** | | taosd启动时,如果firstEp连接不上,尝试连接集群中第二个dnode的end point | | 无 | | +| 3 | fqdn | | **SC** | | 数据节点的FQDN。如果习惯IP地址访问,可设置为该节点的IP地址。 | | 缺省为操作系统配置的第一个hostname。 | 这个参数值的长度需要控制在 96 个字符以内。 | +| 4 | serverPort | | **SC** | | taosd启动后,对外服务的端口号 | | 6030 | RESTful服务使用的端口号是在此基础上+11,即默认值为6041。 | +| 5 | logDir | | **SC** | | 日志文件目录,客户端和服务器的运行日志将写入该目录 | | /var/log/taos | | +| 6 | scriptDir | YES | **S** | | | | | | +| 7 | dataDir | | **S** | | 数据文件目录,所有的数据文件都将写入该目录 | | /var/lib/taos | | +| 8 | arbitrator | | **S** | | 系统中裁决器的end point | | 空 | | +| 9 | numOfThreadsPerCore | | **SC** | | 每个CPU核生成的队列消费者线程数量 | | 1.0 | | +| 10 | ratioOfQueryThreads | | **S** | | 设置查询线程的最大数量 | 0:表示只有1个查询线程;1:表示最大和CPU核数相等的查询线程;2:表示最大建立2倍CPU核数的查询线程。 | 1 | 该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。 | +| 11 | numOfMnodes | | **S** | | 系统中管理节点个数 | | 3 | | +| 12 | vnodeBak | | **S** | | 删除vnode时是否备份vnode目录 | 0:否,1:是 | 1 | | +| 13 | telemetryRePorting | | **S** | | 是否允许 TDengine 采集和上报基本使用信息 | 0:不允许;1:允许 | 1 | | +| 14 | balance | | **S** | | 是否启动负载均衡 | 0,1 | 1 | | +| 15 | balanceInterval | YES | **S** | 秒 | 管理节点在正常运行状态下,检查负载均衡的时间间隔 | 1-30000 | 300 | | +| 16 | role | | **S** | | dnode的可选角色 | 0:any(既可作为mnode,也可分配vnode);1:mgmt(只能作为mnode,不能分配vnode);2:dnode(不能作为mnode,只能分配vnode) | 0 | | +| 17 | maxTmerCtrl | | **SC** | 个 | 定时器个数 | 8-2048 | 512 | | +| 18 | monitorInterval | | **S** | 秒 | 监控数据库记录系统参数(CPU/内存)的时间间隔 | 1-600 | 30 | | +| 19 | offlineThreshold | | **S** | 秒 | dnode离线阈值,超过该时间将导致dnode离线 | 5-7200000 | 86400*10(10天) | | +| 20 | rpcTimer | | **SC** | 毫秒 | rpc重试时长 | 100-3000 | 300 | | +| 21 | rpcMaxTime | | **SC** | 秒 | rpc等待应答最大时长 | 100-7200 | 600 | | +| 22 | statusInterval | | **S** | 秒 | dnode向mnode报告状态间隔 | 1-10 | 1 | | +| 23 | shellActivityTimer | | **SC** | 秒 | shell客户端向mnode发送心跳间隔 | 1-120 | 3 | | +| 24 | tableMetaKeepTimer | | **S** | 秒 | 表的元数据cache时长 | 1-8640000 | 7200 | | +| 25 | minSlidingTime | | **S** | 毫秒 | 最小滑动窗口时长 | 10-1000000 | 10 | 支持us补值后,这个值就是1us了。 | +| 26 | minIntervalTime | | **S** | 毫秒 | 时间窗口最小值 | 1-1000000 | 10 | | +| 27 | stream | | **S** | | 是否启用连续查询(流计算功能) | 0:不允许;1:允许 | 1 | | +| 28 | maxStreamCompDelay | | **S** | 毫秒 | 连续查询启动最大延迟 | 10-1000000000 | 20000 | 为避免多个stream同时执行占用太多系统资源,程序中对stream的执行时间人为增加了一些随机的延时。maxFirstStreamCompDelay 是stream第一次执行前最少要等待的时间。streamCompDelayRatio 是延迟时间的计算系数,它乘以查询的 interval 后为延迟时间基准。maxStreamCompDelay是延迟时间基准的上限。实际延迟时间为一个不超过延迟时间基准的随机值。stream某次计算失败后需要重试,retryStreamCompDelay是重试的等待时间基准。实际重试等待时间为不超过等待时间基准的随机值。 | +| 29 | maxFirstStreamCompDelay | | **S** | 毫秒 | 第一次连续查询启动最大延迟 | 10-1000000000 | 10000 | | +| 30 | retryStreamCompDelay | | **S** | 毫秒 | 连续查询重试等待间隔 | 10-1000000000 | 10 | | +| 31 | streamCompDelayRatio | | **S** | | 连续查询的延迟时间计算系数 | 0.1-0.9 | 0.1 | | +| 32 | maxVgroupsPerDb | | **S** | | 每个DB中 能够使用的最大vnode个数 | 0-8192 | | | +| 33 | maxTablesPerVnode | | **S** | | 每个vnode中能够创建的最大表个数 | | 1000000 | | +| 34 | minTablesPerVnode | YES | **S** | | 每个vnode中必须创建的最小表个数 | | 100 | | +| 35 | tableIncStepPerVnode | YES | **S** | | 每个vnode中超过最小表数后递增步长 | | 1000 | | +| 36 | cache | | **S** | MB | 内存块的大小 | | 16 | | +| 37 | blocks | | **S** | | 每个vnode(tsdb)中有多少cache大小的内存块。因此一个vnode的用的内存大小粗略为(cache * blocks) | | 6 | | +| 38 | days | | **S** | 天 | 数据文件存储数据的时间跨度 | | 10 | | +| 39 | keep | | **S** | 天 | 数据保留的天数 | | 3650 | | +| 40 | minRows | | **S** | | 文件块中记录的最小条数 | | 100 | | +| 41 | maxRows | | **S** | | 文件块中记录的最大条数 | | 4096 | | +| 42 | quorum | | **S** | | 异步写入成功所需应答之法定数 | 1-3 | 1 | | +| 43 | comp | | **S** | | 文件压缩标志位 | 0:关闭,1:一阶段压缩,2:两阶段压缩 | 2 | | +| 44 | walLevel | | **S** | | WAL级别 | 1:写wal, 但不执行fsync; 2:写wal, 而且执行fsync | 1 | | +| 45 | fsync | | **S** | 毫秒 | 当wal设置为2时,执行fsync的周期 | 最小为0,表示每次写入,立即执行fsync;最大为180000(三分钟) | 3000 | | +| 46 | replica | | **S** | | 副本个数 | 1-3 | 1 | | +| 47 | mqttHostName | YES | **S** | | mqtt uri | | | [mqtt://username:password@hostname:1883/taos/](mqtt://username:password@hostname:1883/taos/) | +| 48 | mqttPort | YES | **S** | | mqtt client name | | | 1883 | +| 49 | mqttTopic | YES | **S** | | | | | /test | +| 50 | compressMsgSize | | **S** | bytes | 客户端与服务器之间进行消息通讯过程中,对通讯的消息进行压缩的阈值。如果要压缩消息,建议设置为64330字节,即大于64330字节的消息体才进行压缩。 | `0 `表示对所有的消息均进行压缩 >0: 超过该值的消息才进行压缩 -1: 不压缩 | -1 | | +| 51 | maxSQLLength | | **C** | bytes | 单条SQL语句允许的最长限制 | 65480-1048576 | 65380 | | +| 52 | maxNumOfOrderedRes | | **SC** | | 支持超级表时间排序允许的最多记录数限制 | | 10万 | | +| 53 | timezone | | **SC** | | 时区 | | 从系统中动态获取当前的时区设置 | | +| 54 | locale | | **SC** | | 系统区位信息及编码格式 | | 系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 | | +| 55 | charset | | **SC** | | 字符集编码 | | 系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 | | +| 56 | maxShellConns | | **S** | | 一个dnode容许的连接数 | 10-50000000 | 5000 | | +| 57 | maxConnections | | **S** | | 一个数据库连接所容许的dnode连接数 | 1-100000 | 5000 | 实际测试下来,如果默认没有配,选 50 个 worker thread 会产生 Network unavailable | +| 58 | minimalLogDirGB | | **SC** | GB | 当日志文件夹的磁盘大小小于该值时,停止写日志 | | 0.1 | | +| 59 | minimalTmpDirGB | | **SC** | GB | 当日志文件夹的磁盘大小小于该值时,停止写临时文件 | | 0.1 | | +| 60 | minimalDataDirGB | | **S** | GB | 当日志文件夹的磁盘大小小于该值时,停止写时序数据 | | 0.1 | | +| 61 | mnodeEqualVnodeNum | | **S** | | 一个mnode等同于vnode消耗的个数 | | 4 | | +| 62 | http | | **S** | | 服务器内部的http服务开关。 | 0:关闭http服务, 1:激活http服务。 | 1 | | +| 63 | mqtt | YES | **S** | | 服务器内部的mqtt服务开关。 | 0:关闭mqtt服务, 1:激活mqtt服务。 | 0 | | +| 64 | monitor | | **S** | | 服务器内部的系统监控开关。监控主要负责收集物理节点的负载状况,包括CPU、内存、硬盘、网络带宽、HTTP请求量的监控记录,记录信息存储在`LOG`库中。 | 0:关闭监控服务, 1:激活监控服务。 | 0 | | +| 65 | httpEnableRecordSql | | **S** | | 内部使用,记录通过RESTFul接口,产生的SQL调用 | | 0 | 生成的文件(httpnote.0/httpnote.1),与服务端日志所在目录相同。 | +| 66 | httpMaxThreads | | **S** | | RESTFul接口的线程数 | | 2 | | +| 67 | telegrafUseFieldNum | YES | | | | | | | +| 68 | restfulRowLimit | | **S** | | RESTFul接口单次返回的记录条数 | | 10240 | 最大10,000,000 | +| 69 | numOfLogLines | | **SC** | | 单个日志文件允许的最大行数。 | | 10,000,000 | | +| 70 | asyncLog | | **SC** | | 日志写入模式 | 0:同步、1:异步 | 1 | | +| 71 | logKeepDays | | **SC** | 天 | 日志文件的最长保存时间 | | 0 | 大于0时,日志文件会被重命名为taosdlog.xxx,其中xxx为日志文件最后修改的时间戳。 | +| 72 | debugFlag | | **SC** | | 运行日志开关 | 131(输出错误和警告日志),135(输出错误、警告和调试日志),143(输出错误、警告、调试和跟踪日志) | 131或135(不同模块有不同的默认值) | | +| 73 | mDebugFlag | | **S** | | 管理模块的日志开关 | 同上 | 135 | | +| 74 | dDebugFlag | | **SC** | | dnode模块的日志开关 | 同上 | 135 | | +| 75 | sDebugFlag | | **SC** | | sync模块的日志开关 | 同上 | 135 | | +| 76 | wDebugFlag | | **SC** | | wal模块的日志开关 | 同上 | 135 | | +| 77 | sdbDebugFlag | | **SC** | | sdb模块的日志开关 | 同上 | 135 | | +| 78 | rpcDebugFlag | | **SC** | | rpc模块的日志开关 | 同上 | | | +| 79 | tmrDebugFlag | | **SC** | | 定时器模块的日志开关 | 同上 | | | +| 80 | cDebugFlag | | **C** | | client模块的日志开关 | 同上 | | | +| 81 | jniDebugFlag | | **C** | | jni模块的日志开关 | 同上 | | | +| 82 | odbcDebugFlag | | **C** | | odbc模块的日志开关 | 同上 | | | +| 83 | uDebugFlag | | **SC** | | 共用功能模块的日志开关 | 同上 | | | +| 84 | httpDebugFlag | | **S** | | http模块的日志开关 | 同上 | | | +| 85 | mqttDebugFlag | | **S** | | mqtt模块的日志开关 | 同上 | | | +| 86 | monitorDebugFlag | | **S** | | 监控模块的日志开关 | 同上 | | | +| 87 | qDebugFlag | | **SC** | | 查询模块的日志开关 | 同上 | | | +| 88 | vDebugFlag | | **SC** | | vnode模块的日志开关 | 同上 | | | +| 89 | tsdbDebugFlag | | **S** | | TSDB模块的日志开关 | 同上 | | | +| 90 | cqDebugFlag | | **SC** | | 连续查询模块的日志开关 | 同上 | | | +| 91 | tscEnableRecordSql | | **C** | | 是否记录客户端sql语句到文件 | 0:否,1:是 | 0 | 生成的文件(tscnote-xxxx.0/tscnote-xxx.1,xxxx是pid),与客户端日志所在目录相同。 | +| 92 | enableCoreFile | | **SC** | | 是否开启服务crash时生成core文件 | 0:否,1:是 | 1 | 不同的启动方式,生成core文件的目录如下:1、systemctl start taosd启动:生成的core在根目录下;2、手动启动,就在taosd执行目录下。 | +| 93 | gitinfo | YES | **SC** | | | 1 | | | +| 94 | gitinfoofInternal | YES | **SC** | | | 2 | | | +| 95 | Buildinfo | YES | **SC** | | | 3 | | | +| 96 | version | YES | **SC** | | | 4 | | | +| 97 | | | | | | | | | +| 98 | maxBinaryDisplayWidth | | **C** | | Taos shell中binary 和 nchar字段的显示宽度上限,超过此限制的部分将被隐藏 | 5 - | 30 | 实际上限按以下规则计算:如果字段值的长度大于 maxBinaryDisplayWidth,则显示上限为 **字段名长度** 和 **maxBinaryDisplayWidth** 的较大者。否则,上限为 **字段名长度** 和 **字段值长度** 的较大者。可在 shell 中通过命令 set max_binary_display_width nn动态修改此选项 | +| 99 | queryBufferSize | | **S** | MB | 为所有并发查询占用保留的内存大小。 | | | 计算规则可以根据实际应用可能的最大并发数和表的数字相乘,再乘 170 。(2.0.15 以前的版本中,此参数的单位是字节) | +| 100 | ratioOfQueryCores | | **S** | | 设置查询线程的最大数量。 | | | 最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。 | +| 101 | update | | **S** | | 允许更新已存在的数据行 | 0 \| 1 | 0 | 从 2.0.8.0 版本开始 | +| 102 | cacheLast | | **S** | | 是否在内存中缓存子表的最近数据 | 0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值;3:同时打开缓存最近行和列功能。 | 0 | 2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。 | +| 103 | numOfCommitThreads | YES | **S** | | 设置写入线程的最大数量 | | | **注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port)) 不同应用场景的数据往往具有不同的数据特征,比如保留天数、副本数、采集频次、记录大小、采集点的数量、压缩等都可完全不同。为获得在存储上的最高效率,TDengine提供如下存储相关的系统配置参数(既可以作为 create database 指令的参数,也可以写在 taos.cfg 配置文件中用来设定创建新数据库时所采用的默认值): -- days:一个数据文件存储数据的时间跨度。单位为天,默认值:10。 -- keep:数据库中数据保留的天数。单位为天,默认值:3650。(可通过 alter database 修改) -- minRows:文件块中记录的最小条数。单位为条,默认值:100。 -- maxRows:文件块中记录的最大条数。单位为条,默认值:4096。 -- comp:文件压缩标志位。0:关闭;1:一阶段压缩;2:两阶段压缩。默认值:2。(可通过 alter database 修改) -- wal:WAL级别。1:写wal,但不执行fsync;2:写wal, 而且执行fsync。默认值:1。(在 taos.cfg 中参数名需要写作 walLevel) -- fsync:当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。单位为毫秒,默认值:3000。 -- cache:内存块的大小。单位为兆字节(MB),默认值:16。 -- blocks:每个VNODE(TSDB)中有多少cache大小的内存块。因此一个VNODE的用的内存大小粗略为(cache * blocks)。单位为块,默认值:4。(可通过 alter database 修改) -- replica:副本个数。取值范围:1-3,单位为个,默认值:1。(可通过 alter database 修改) -- quorum:多副本环境下指令执行的确认数要求。取值范围:1、2,单位为个,默认值:1。(可通过 alter database 修改) -- precision:时间戳精度标识。ms表示毫秒,us表示微秒,默认值:ms。(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) -- cacheLast:是否在内存中缓存子表的最近数据。0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值;3:同时打开缓存最近行和列功能。默认值:0。(可通过 alter database 修改)(从 2.1.2.0 版本开始此参数支持 0~3 的取值范围,在此之前取值只能是 [0, 1];而 2.0.11.0 之前的版本在 SQL 指令中不支持此参数。)(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) -- update:是否允许更新。0:不允许;1:允许。默认值:0。 +| **#** | **配置参数名称** | **单位** | **含义** | **取值范围** | **缺省值** | +| ----- | ---------------- | -------- | ------------------------------------------------------------ | ------------------------------------------------ | ---------- | +| 1 | days | 天 | 一个数据文件存储数据的时间跨度 | | 10 | +| 2 | keep | 天 | (可通过 alter database 修改)数据库中数据保留的天数。 | 3650 | +| 3 | cache | MB | 内存块的大小 | | 16 | +| 4 | blocks | | (可通过 alter database 修改)每个 VNODE(TSDB)中有多少个 cache 大小的内存块。因此一个 VNODE 使用的内存大小粗略为(cache * blocks)。 | | 4 | +| 5 | quorum | | (可通过 alter database 修改)多副本环境下指令执行的确认数要求 | 1-2 | 1 | +| 6 | minRows | | 文件块中记录的最小条数 | | 100 | +| 7 | maxRows | | 文件块中记录的最大条数 | | 4096 | +| 8 | comp | | (可通过 alter database 修改)文件压缩标志位 | 0:关闭,1:一阶段压缩,2:两阶段压缩 | 2 | +| 9 | walLevel | | (作为 database 的参数时名为 wal;在 taos.cfg 中作为参数时需要写作 walLevel)WAL级别 | 1:写wal,但不执行fsync;2:写wal, 而且执行fsync | 1 | +| 10 | fsync | 毫秒 | 当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。 | | 3000 | +| 11 | replica | | (可通过 alter database 修改)副本个数 | 1-3 | 1 | +| 12 | precision | | 时间戳精度标识(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) | ms 表示毫秒,us 表示微秒 | ms | +| 13 | update | | 是否允许更新 | 0:不允许;1:允许 | 0 | +| 14 | cacheLast | | (可通过 alter database 修改)是否在内存中缓存子表的最近数据(从 2.1.2.0 版本开始此参数支持 0~3 的取值范围,在此之前取值只能是 [0, 1];而 2.0.11.0 之前的版本在 SQL 指令中不支持此参数。)(2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。) | 0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值;3:同时打开缓存最近行和列功能 | 0 | 对于一个应用场景,可能有多种数据特征的数据并存,最佳的设计是将具有相同数据特征的表放在一个库里,这样一个应用有多个库,而每个库可以配置不同的存储参数,从而保证系统有最优的性能。TDengine允许应用在创建库时指定上述存储参数,如果指定,该参数就将覆盖对应的系统配置参数。举例,有下述SQL: -``` - create database demo days 10 cache 32 blocks 8 replica 3 update 1; +```mysql + CREATE DATABASE demo DAYS 10 CACHE 32 BLOCKS 8 REPLICA 3 UPDATE 1; ``` 该SQL创建了一个库demo, 每个数据文件存储10天数据,内存块为32兆字节,每个VNODE占用8个内存块,副本数为3,允许更新,而其他参数与系统配置完全一致。 +一个数据库创建成功后,仅部分参数可以修改并实时生效,其余参数不能修改: + +| **参数名** | **能否修改** | **范围** | **修改语法示例** | +| ----------- | ------------ | ------------------------------------------------------------ | ------------------------------------- | +| name | | | | +| create time | | | | +| ntables | | | | +| vgroups | | | | +| replica | **YES** | 在线dnode数目为1:1-1;2:1-2;>=3:1-3 | ALTER DATABASE REPLICA *n* | +| quorum | **YES** | 1-2 | ALTER DATABASE QUORUM *n* | +| days | | | | +| keep | **YES** | days-365000 | ALTER DATABASE KEEP *n* | +| cache | | | | +| blocks | **YES** | 3-1000 | ALTER DATABASE BLOCKS *n* | +| minrows | | | | +| maxrows | | | | +| wal | | | | +| fsync | | | | +| comp | **YES** | 0-2 | ALTER DATABASE COMP *n* | +| precision | | | | +| status | | | | +| update | | | | +| cachelast | **YES** | 0 \| 1 \| 2 \| 3 | ALTER DATABASE CACHELAST *n* | + +**说明:**在 2.1.3.0 版本之前,通过 ALTER DATABASE 语句修改这些参数后,需要重启服务器才能生效。 + TDengine集群中加入一个新的dnode时,涉及集群相关的一些参数必须与已有集群的配置相同,否则不能成功加入到集群中。会进行校验的参数如下: - numOfMnodes:系统中管理节点个数。默认值:3。(2.0 版本从 2.0.20.11 开始、2.1 及以上版本从 2.1.6.0 开始,numOfMnodes 默认值改为 1。) @@ -172,7 +306,7 @@ ALTER DNODE alter dnode 1 debugFlag 135; ``` -## 客户端配置 +## 客户端及应用驱动配置 TDengine系统的前台交互客户端应用程序为taos,以及应用驱动,它与taosd共享同一个配置文件taos.cfg。运行taos时,使用参数-c指定配置文件目录,如taos -c /home/cfg,表示使用/home/cfg/目录下的taos.cfg配置文件中的参数,缺省目录是/etc/taos。更多taos的使用方法请见帮助信息 `taos --help`。本节主要说明 taos 客户端应用在配置文件 taos.cfg 文件中使用到的参数。 @@ -182,15 +316,15 @@ TDengine系统的前台交互客户端应用程序为taos,以及应用驱动 taos -C 或 taos --dump-config ``` -客户端配置参数 +客户端及应用驱动配置参数列表及解释 - firstEp: taos启动时,主动连接的集群中第一个taosd实例的end point, 缺省值为 localhost:6030。 - secondEp: taos 启动时,如果 firstEp 连不上,将尝试连接 secondEp。 -- locale +- locale:系统区位信息及编码格式。 - 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 + 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置。 TDengine为存储中文、日文、韩文等非ASCII编码的宽字符,提供一种专门的字段类型nchar。写入nchar字段的数据将统一采用UCS4-LE格式进行编码并发送到服务器。需要注意的是,编码正确性是客户端来保证。因此,如果用户想要正常使用nchar字段来存储诸如中文、日文、韩文等非ASCII字符,需要正确设置客户端的编码格式。 @@ -198,9 +332,9 @@ taos -C 或 taos --dump-config 在 Linux 中 locale 的命名规则为: <语言>\_<地区>.<字符集编码> 如:zh_CN.UTF-8,zh代表中文,CN代表大陆地区,UTF-8表示字符集。字符集编码为客户端正确解析本地字符串提供编码转换的说明。Linux系统与 Mac OSX 系统可以通过设置locale来确定系统的字符编码,由于Windows使用的locale中不是POSIX标准的locale格式,因此在Windows下需要采用另一个配置参数charset来指定字符编码。在Linux 系统中也可以使用charset来指定字符编码。 -- charset +- charset:字符集编码。 - 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 + 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置。 如果配置文件中不设置charset,在Linux系统中,taos在启动时候,自动读取系统当前的locale信息,并从locale信息中解析提取charset编码格式。如果自动读取locale信息失败,则尝试读取charset配置,如果读取charset配置也失败,则中断启动过程。 @@ -260,7 +394,7 @@ taos -C 或 taos --dump-config - maxBinaryDisplayWidth - Shell中binary 和 nchar字段的显示宽度上限,超过此限制的部分将被隐藏。默认值:30。可在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项。 + Shell中 binary 和 nchar 字段的显示宽度上限,超过此限制的部分将被隐藏。默认值:30。可在 taos shell 中通过命令 set max_binary_display_width nn 动态修改此选项。 ## 用户管理 @@ -315,7 +449,7 @@ TDengine也支持在shell对已存在的表从CSV文件中进行数据导入。C ```mysql insert into tb1 file 'path/data.csv'; ``` -注意:如果CSV文件首行存在描述信息,请手动删除后再导入 +**注意:如果CSV文件首行存在描述信息,请手动删除后再导入。如某列为空,填NULL,无引号。** 例如,现在存在一个子表d1001, 其表结构如下: @@ -343,7 +477,7 @@ taos> DESCRIBE d1001 '2018-10-11 06:38:05.000',17.30000,219,0.32000 '2018-10-12 06:38:05.000',18.30000,219,0.31000 ``` -那么可以用如下命令导入数据 +那么可以用如下命令导入数据: ```mysql taos> insert into d1001 file '~/data.csv'; @@ -360,7 +494,7 @@ TDengine提供了方便的数据库导入导出工具taosdump。用户可以将t **按表导出CSV文件** -如果用户需要导出一个表或一个STable中的数据,可在shell中运行 +如果用户需要导出一个表或一个STable中的数据,可在taos shell中运行: ```mysql select * from >> data.csv; @@ -370,7 +504,9 @@ select * from >> data.csv; **用taosdump导出数据** -TDengine提供了方便的数据库导出工具taosdump。用户可以根据需要选择导出所有数据库、一个数据库或者数据库中的一张表,所有数据或一时间段的数据,甚至仅仅表的定义。具体使用方法,请参见博客:[TDengine DUMP工具使用指南](https://www.taosdata.com/blog/2020/03/09/1334.html) +利用taosdump,用户可以根据需要选择导出所有数据库、一个数据库或者数据库中的一张表,所有数据或一时间段的数据,甚至仅仅表的定义。 + +具体使用方法,请参见博客:[TDengine DUMP工具使用指南](https://www.taosdata.com/blog/2020/03/09/1334.html)。 ## 系统连接、任务查询管理 @@ -435,46 +571,100 @@ COMPACT 命令对指定的一个或多个 VGroup 启动碎片重整,系统会 安装TDengine后,默认会在操作系统中生成下列目录或文件: -| 目录/文件 | 说明 | -| ------------------------- | :----------------------------------------------------------- | +| **目录/文件** | **说明** | +| ------------------------- | ------------------------------------------------------------ | | /usr/local/taos/bin | TDengine可执行文件目录。其中的执行文件都会软链接到/usr/bin目录下。 | | /usr/local/taos/connector | TDengine各种连接器目录。 | | /usr/local/taos/driver | TDengine动态链接库目录。会软链接到/usr/lib目录下。 | | /usr/local/taos/examples | TDengine各种语言应用示例目录。 | | /usr/local/taos/include | TDengine对外提供的C语言接口的头文件。 | | /etc/taos/taos.cfg | TDengine默认[配置文件] | -| /var/lib/taos | TDengine默认数据文件目录,可通过[配置文件]修改位置. | -| /var/log/taos | TDengine默认日志文件目录,可通过[配置文件]修改位置 | +| /var/lib/taos | TDengine默认数据文件目录。可通过[配置文件]修改位置。 | +| /var/log/taos | TDengine默认日志文件目录。可通过[配置文件]修改位置。 | **可执行文件** TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下。其中包括: -- _taosd_:TDengine服务端可执行文件 -- _taos_: TDengine Shell可执行文件 -- _taosdump_:数据导入导出工具 -- remove.sh:卸载TDengine的脚本, 请谨慎执行,链接到/usr/bin目录下的rmtaos命令。会删除TDengine的安装目录/usr/local/taos,但会保留/etc/taos、/var/lib/taos、/var/log/taos。 +- *taosd*:TDengine服务端可执行文件 +- *taos*:TDengine Shell可执行文件 +- *taosdump*:数据导入导出工具 +- *taosdemo*:TDengine测试工具 +- remove.sh:卸载TDengine的脚本,请谨慎执行,链接到/usr/bin目录下的**rmtaos**命令。会删除TDengine的安装目录/usr/local/taos,但会保留/etc/taos、/var/lib/taos、/var/log/taos。 您可以通过修改系统配置文件taos.cfg来配置不同的数据目录和日志目录。 +## TDengine 的启动、停止、卸载 + +TDengine 使用 Linux 系统的 systemd/systemctl/service 来管理系统的启动和、停止、重启操作。TDengine 的服务进程是 taosd,默认情况下 TDengine 在系统启动后将自动启动。DBA 可以通过 systemd/systemctl/service 手动操作停止、启动、重新启动服务。 + +以 systemctl 为例,命令如下: + +- 启动服务进程:`systemctl start taosd` + +- 停止服务进程:`systemctl stop taosd` + +- 重启服务进程:`systemctl restart taosd` + +- 查看服务状态:`systemctl status taosd` + +如果服务进程处于活动状态,则 status 指令会显示如下的相关信息: +``` +...... + +Active: active (running) + +...... +``` + +如果后台服务进程处于停止状态,则 status 指令会显示如下的相关信息: +``` +...... + +Active: inactive (dead) + +...... +``` + +卸载 TDengine,只需要执行如下命令 +``` +rmtaos +``` + +**警告:执行该命令后,TDengine 程序将被完全删除,务必谨慎使用。** + ## TDengine参数限制与保留关键字 +**名称命名规则** + +1. 合法字符:英文字符、数字和下划线 +2. 允许英文字符或下划线开头,不允许以数字开头 +3. 不区分大小写 + +**密码合法字符集** + +`[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]` + +去掉了 ```‘“`\``` (单双引号、撇号、反斜杠、空格) + - 数据库名:不能包含“.”以及特殊字符,不能超过 32 个字符 -- 表名:不能包含“.”以及特殊字符,与所属数据库名一起,不能超过 192 个字符 +- 表名:不能包含“.”以及特殊字符,与所属数据库名一起,不能超过 192 个字符,每行数据最大长度 16k 个字符 - 表的列名:不能包含特殊字符,不能超过 64 个字符 - 数据库名、表名、列名,都不能以数字开头,合法的可用字符集是“英文字符、数字和下划线” -- 表的列数:不能超过 1024 列 +- 表的列数:不能超过 1024 列,最少需要 2 列,第一列必须是时间戳 - 记录的最大长度:包括时间戳 8 byte,不能超过 16KB(每个 BINARY/NCHAR 类型的列还会额外占用 2 个 byte 的存储位置) -- 单条 SQL 语句默认最大字符串长度:65480 byte +- 单条 SQL 语句默认最大字符串长度:65480 byte,但可通过系统配置参数 maxSQLLength 修改,最长可配置为 1048576 byte - 数据库副本数:不能超过 3 - 用户名:不能超过 23 个 byte - 用户密码:不能超过 15 个 byte -- 标签(Tags)数量:不能超过 128 个 +- 标签(Tags)数量:不能超过 128 个,可以 0 个 - 标签的总长度:不能超过 16K byte - 记录条数:仅受存储空间限制 - 表的个数:仅受节点个数限制 - 库的个数:仅受节点个数限制 - 单个库上虚拟节点个数:不能超过 64 个 +- 库的数目,超级表的数目、表的数目,系统不做限制,仅受系统资源限制 +- SELECT 语句的查询结果,最多允许返回 1024 列(语句中的函数调用可能也会占用一些列空间),超限时需要显式指定较少的返回数据列,以避免语句执行报错。 目前 TDengine 有将近 200 个内部保留关键字,这些关键字无论大小写均不可以用作库名、表名、STable 名、数据列名及标签列名等。这些关键字列表如下: @@ -519,3 +709,102 @@ TDengine的所有可执行文件默认存放在 _/usr/local/taos/bin_ 目录下 | CONNS | ID | NOTNULL | STABLE | WAL | | COPY | IF | NOW | STABLES | WHERE | +## 诊断及其他 + +#### 网络连接诊断 + +当出现客户端应用无法访问服务端时,需要确认客户端与服务端之间网络的各端口连通情况,以便有针对性地排除故障。 + +目前网络连接诊断支持在:Linux 与 Linux,Linux 与 Windows 之间进行诊断测试。 + +诊断步骤: + +1. 如拟诊断的端口范围与服务器 taosd 实例的端口范围相同,须先停掉 taosd 实例 +2. 服务端命令行输入:`taos -n server -P ` 以服务端身份启动对端口 port 为基准端口的监听 +3. 客户端命令行输入:`taos -n client -h -P ` 以客户端身份启动对指定的服务器、指定的端口发送测试包 + +服务端运行正常的话会输出以下信息 + +```bash +# taos -n server -P 6000 +12/21 14:50:13.522509 0x7f536f455200 UTL work as server, host:172.27.0.7 startPort:6000 endPort:6011 pkgLen:1000 + +12/21 14:50:13.522659 0x7f5352242700 UTL TCP server at port:6000 is listening +12/21 14:50:13.522727 0x7f5351240700 UTL TCP server at port:6001 is listening +... +... +... +12/21 14:50:13.523954 0x7f5342fed700 UTL TCP server at port:6011 is listening +12/21 14:50:13.523989 0x7f53437ee700 UTL UDP server at port:6010 is listening +12/21 14:50:13.524019 0x7f53427ec700 UTL UDP server at port:6011 is listening +12/21 14:50:22.192849 0x7f5352242700 UTL TCP: read:1000 bytes from 172.27.0.8 at 6000 +12/21 14:50:22.192993 0x7f5352242700 UTL TCP: write:1000 bytes to 172.27.0.8 at 6000 +12/21 14:50:22.237082 0x7f5351a41700 UTL UDP: recv:1000 bytes from 172.27.0.8 at 6000 +12/21 14:50:22.237203 0x7f5351a41700 UTL UDP: send:1000 bytes to 172.27.0.8 at 6000 +12/21 14:50:22.237450 0x7f5351240700 UTL TCP: read:1000 bytes from 172.27.0.8 at 6001 +12/21 14:50:22.237576 0x7f5351240700 UTL TCP: write:1000 bytes to 172.27.0.8 at 6001 +12/21 14:50:22.281038 0x7f5350a3f700 UTL UDP: recv:1000 bytes from 172.27.0.8 at 6001 +12/21 14:50:22.281141 0x7f5350a3f700 UTL UDP: send:1000 bytes to 172.27.0.8 at 6001 +... +... +... +12/21 14:50:22.677443 0x7f5342fed700 UTL TCP: read:1000 bytes from 172.27.0.8 at 6011 +12/21 14:50:22.677576 0x7f5342fed700 UTL TCP: write:1000 bytes to 172.27.0.8 at 6011 +12/21 14:50:22.721144 0x7f53427ec700 UTL UDP: recv:1000 bytes from 172.27.0.8 at 6011 +12/21 14:50:22.721261 0x7f53427ec700 UTL UDP: send:1000 bytes to 172.27.0.8 at 6011 +``` + +客户端运行正常会输出以下信息: + +```bash +# taos -n client -h 172.27.0.7 -P 6000 +12/21 14:50:22.192434 0x7fc95d859200 UTL work as client, host:172.27.0.7 startPort:6000 endPort:6011 pkgLen:1000 + +12/21 14:50:22.192472 0x7fc95d859200 UTL server ip:172.27.0.7 is resolved from host:172.27.0.7 +12/21 14:50:22.236869 0x7fc95d859200 UTL successed to test TCP port:6000 +12/21 14:50:22.237215 0x7fc95d859200 UTL successed to test UDP port:6000 +... +... +... +12/21 14:50:22.676891 0x7fc95d859200 UTL successed to test TCP port:6010 +12/21 14:50:22.677240 0x7fc95d859200 UTL successed to test UDP port:6010 +12/21 14:50:22.720893 0x7fc95d859200 UTL successed to test TCP port:6011 +12/21 14:50:22.721274 0x7fc95d859200 UTL successed to test UDP port:6011 +``` + +仔细阅读打印出来的错误信息,可以帮助管理员找到原因,以解决问题。 + +#### 启动状态及RPC诊断 + +`taos -n startup -h ` + +判断 taosd 服务端是否成功启动,是数据库管理员经常遇到的一种情形。特别当若干台服务器组成集群时,判断每个服务端实例是否成功启动就会是一个重要问题。除检索 taosd 服务端日志文件进行问题定位、分析外,还可以通过 `taos -n startup -h ` 来诊断一个 taosd 进程的启动状态。 + +针对多台服务器组成的集群,当服务启动过程耗时较长时,可通过该命令行来诊断每台服务器的 taosd 实例的启动状态,以准确定位问题。 + +`taos -n rpc -h ` + +该命令用来诊断已经启动的 taosd 实例的端口是否可正常访问。如果 taosd 程序异常或者失去响应,可以通过 `taos -n rpc -h ` 来发起一个与指定 fqdn 的 rpc 通信,看看 taosd 是否能收到,以此来判定是网络问题还是 taosd 程序异常问题。 + +#### sync 及 arbitrator 诊断 + +``` +taos -n sync -P 6040 -h +taos -n sync -P 6042 -h +``` + +用来诊断 sync 端口是否工作正常,判断服务端 sync 模块是否成功工作。另外,-P 6042 用来诊断 arbitrator 是否配置正常,判断指定服务器的 arbitrator 是否能正常工作。 + +#### 服务端日志 + +taosd 服务端日志文件标志位 debugflag 默认为 131,在 debug 时往往需要将其提升到 135 或 143 。 + +一旦设定为 135 或 143,日志文件增长很快,特别是写入、查询请求量较大时,增长速度惊人。如合并保存日志,很容易把日志内的关键信息(如配置信息、错误信息等)冲掉。为此,服务端将重要信息日志与其他日志分开存放: + +- taosinfo 存放重要信息日志 +- taosdlog 存放其他日志 + +其中,taosinfo 日志文件最大长度由 numOfLogLines 来进行配置,一个 taosd 实例最多保留两个文件。 + +taosd 服务端日志采用异步落盘写入机制,优点是可以避免硬盘写入压力太大,对性能造成很大影响。缺点是,在极端情况下,存在少量日志行数丢失的可能。 + From e2ced2dcf831200255ce06c4f6f4670a61668f17 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Tue, 10 Aug 2021 19:00:29 +0800 Subject: [PATCH 094/100] [TD-2339] : describe SQL function "INTERP". --- documentation20/cn/12.taos-sql/docs.md | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index ed5c282da1..89d20cedb4 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -1215,6 +1215,37 @@ TDengine支持针对数据的聚合查询。提供支持的聚合和选择函数 Query OK, 1 row(s) in set (0.001042s) ``` +- **INTERP** + ```mysql + SELECT INTERP(field_name) FROM { tb_name | stb_name } WHERE ts='timestamp' [FILL ({ VALUE | PREV | NULL | LINEAR})]; + ``` + 功能说明:返回表/超级表的指定时间截面、指定字段的记录。 + + 返回结果数据类型:同应用的字段。 + + 应用字段:所有字段。 + + 适用于:**表、超级表**。 + + 说明:(从 2.0.15.0 版本开始新增此函数)INTERP 必须指定时间断面,如果该时间断面不存在直接对应的数据,那么会根据 FILL 参数的设定进行插值。其中,条件语句里面可以附带更多的筛选条件,例如标签、tbname。 + + 限制:INTERP 目前不支持 FILL(NEXT)。 + + 示例: + ```mysql + taos> select interp(*) from meters where ts='2017-7-14 10:42:00.005' fill(prev); + interp(ts) | interp(f1) | interp(f2) | interp(f3) | + ==================================================================== + 2017-07-14 10:42:00.005 | 5 | 9 | 6 | + Query OK, 1 row(s) in set (0.002912s) + + taos> select interp(*) from meters where tbname in ('t1') and ts='2017-7-14 10:42:00.005' fill(prev); + interp(ts) | interp(f1) | interp(f2) | interp(f3) | + ==================================================================== + 2017-07-14 10:42:00.005 | 5 | 6 | 7 | + Query OK, 1 row(s) in set (0.002005s) + ``` + ### 计算函数 - **DIFF** From d0ce2656a606108a2f5c1047b2bfb45a2caca0e0 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Tue, 10 Aug 2021 19:15:35 +0800 Subject: [PATCH 095/100] [TD-4905] : add example about "INSERT INTO FILE" with table auto creation. --- documentation20/cn/12.taos-sql/docs.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 89d20cedb4..c0be5cc68f 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -435,6 +435,17 @@ INSERT INTO INSERT INTO d1001 FILE '/tmp/csvfile.csv'; ``` +- **插入来自文件的数据记录,并自动建表** + 从 2.1.5.0 版本开始,支持在插入来自 CSV 文件的数据时,以超级表为模板来自动创建不存在的数据表。例如: + ```mysql + INSERT INTO d21001 USING meters TAGS ('Beijing.Chaoyang', 2) FILE '/tmp/csvfile.csv'; + ``` + 也可以在一条语句中向多个表以自动建表的方式插入记录。例如: + ```mysql + INSERT INTO d21001 USING meters TAGS ('Beijing.Chaoyang', 2) FILE '/tmp/csvfile_21001.csv' + d21002 USING meters (groupId) TAGS (2) FILE '/tmp/csvfile_21002.csv'; + ``` + **历史记录写入**:可使用IMPORT或者INSERT命令,IMPORT的语法,功能与INSERT完全一样。 **说明:**针对 insert 类型的 SQL 语句,我们采用的流式解析策略,在发现后面的错误之前,前面正确的部分 SQL 仍会执行。下面的 SQL 中,INSERT 语句是无效的,但是 d1001 仍会被创建。 From 12cdfa563f7a80de62d8e9ef65ea9db3b0ec152b Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Wed, 11 Aug 2021 09:24:06 +0800 Subject: [PATCH 096/100] add more ci time[ci skip] --- Jenkinsfile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index e6e8a1df32..680fcce37f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -168,7 +168,7 @@ pipeline { steps { pre_test() - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ sh ''' date cd ${WKC}/tests @@ -183,7 +183,7 @@ pipeline { steps { pre_test() - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ sh ''' date cd ${WKC}/tests @@ -195,7 +195,7 @@ pipeline { stage('python_3_s6') { agent{label 'p3'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' date @@ -208,7 +208,7 @@ pipeline { stage('test_b1_s2') { agent{label 'b1'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' cd ${WKC}/tests @@ -245,7 +245,7 @@ pipeline { ./handle_taosd_val_log.sh ''' } - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ sh ''' date cd ${WKC}/tests @@ -269,7 +269,7 @@ pipeline { ./handle_val_log.sh ''' } - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ sh ''' date cd ${WKC}/tests @@ -286,7 +286,7 @@ pipeline { stage('test_b4_s7') { agent{label 'b4'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' date @@ -305,7 +305,7 @@ pipeline { stage('test_b5_s8') { agent{label 'b5'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' date @@ -318,7 +318,7 @@ pipeline { stage('test_b6_s9') { agent{label 'b6'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' date @@ -331,7 +331,7 @@ pipeline { stage('test_b7_s10') { agent{label 'b7'} steps { - timeout(time: 45, unit: 'MINUTES'){ + timeout(time: 55, unit: 'MINUTES'){ pre_test() sh ''' date From 73f97d136438a4b95f580ffcca8719d9f74dda28 Mon Sep 17 00:00:00 2001 From: Elias Soong Date: Wed, 11 Aug 2021 13:32:05 +0800 Subject: [PATCH 097/100] [TD-5617] : allow wild card string for LIKE to be 100 bytes at max. --- documentation20/cn/11.administrator/docs.md | 3 ++- documentation20/cn/12.taos-sql/docs.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation20/cn/11.administrator/docs.md b/documentation20/cn/11.administrator/docs.md index 496d16ec63..4a6eca4bb3 100644 --- a/documentation20/cn/11.administrator/docs.md +++ b/documentation20/cn/11.administrator/docs.md @@ -218,7 +218,8 @@ taosd -C | 100 | ratioOfQueryCores | | **S** | | 设置查询线程的最大数量。 | | | 最小值0 表示只有1个查询线程;最大值2表示最大建立2倍CPU核数的查询线程。默认为1,表示最大和CPU核数相等的查询线程。该值可以为小数,即0.5表示最大建立CPU核数一半的查询线程。 | | 101 | update | | **S** | | 允许更新已存在的数据行 | 0 \| 1 | 0 | 从 2.0.8.0 版本开始 | | 102 | cacheLast | | **S** | | 是否在内存中缓存子表的最近数据 | 0:关闭;1:缓存子表最近一行数据;2:缓存子表每一列的最近的非NULL值;3:同时打开缓存最近行和列功能。 | 0 | 2.1.2.0 版本之前、2.0.20.7 版本之前在 taos.cfg 文件中不支持此参数。 | -| 103 | numOfCommitThreads | YES | **S** | | 设置写入线程的最大数量 | | | +| 103 | numOfCommitThreads | YES | **S** | | 设置写入线程的最大数量 | | | | +| 104 | maxWildCardsLength | | **C** | bytes | 设定 LIKE 算子的通配符字符串允许的最大长度 | 0-16384 | 100 | 2.1.6.1 版本新增。 | **注意:**对于端口,TDengine会使用从serverPort起13个连续的TCP和UDP端口号,请务必在防火墙打开。因此如果是缺省配置,需要打开从6030到6042共13个端口,而且必须TCP和UDP都打开。(详细的端口情况请参见 [TDengine 2.0 端口说明](https://www.taosdata.com/cn/documentation/faq#port)) diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index c0be5cc68f..d8128db3a9 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -206,7 +206,7 @@ TDengine 缺省的时间戳是毫秒精度,但通过在 CREATE DATABASE 时传 显示当前数据库下的所有数据表信息。 - 说明:可在like中使用通配符进行名称的匹配,这一通配符字符串最长不能超过24字节。 + 说明:可在 like 中使用通配符进行名称的匹配,这一通配符字符串最长不能超过 20 字节。( 从 2.1.6.1 版本开始,通配符字符串的长度放宽到了 100 字节,并可以通过 taos.cfg 中的 maxWildCardsLength 参数来配置这一长度限制。但不建议使用太长的通配符字符串,将有可能严重影响 LIKE 操作的执行性能。) 通配符匹配:1)'%'(百分号)匹配0到任意个字符;2)'\_'下划线匹配单个任意字符。 From 5f8e37504acdb17a9f1a949122bd81dd897fdd31 Mon Sep 17 00:00:00 2001 From: liuyq-617 Date: Wed, 11 Aug 2021 14:01:59 +0800 Subject: [PATCH 098/100] test --- Jenkinsfile | 80 ++++++++++++----------- tests/pytest/crash_gen/valgrind_taos.supp | 2 +- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 64ee9b2134..8fa7e78a5f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,9 +4,6 @@ properties([pipelineTriggers([githubPush()])]) node { git url: 'https://github.com/taosdata/TDengine.git' } - -def skipbuild=0 - def abortPreviousBuilds() { def currentJobName = env.JOB_NAME def currentBuildNumber = env.BUILD_NUMBER.toInteger() @@ -33,7 +30,6 @@ def abort_previous(){ milestone(buildNumber) } def pre_test(){ - sh'hostname' sh ''' sudo rmtaos || echo "taosd has not installed" @@ -52,12 +48,18 @@ def pre_test(){ git checkout master ''' } - else { + else if(env.CHANGE_TARGET == '2.0'){ + sh ''' + cd ${WKC} + git checkout 2.0 + ''' + } + else{ sh ''' cd ${WKC} git checkout develop ''' - } + } } sh''' cd ${WKC} @@ -75,7 +77,13 @@ def pre_test(){ git checkout master ''' } - else { + else if(env.CHANGE_TARGET == '2.0'){ + sh ''' + cd ${WK} + git checkout 2.0 + ''' + } + else{ sh ''' cd ${WK} git checkout develop @@ -95,19 +103,17 @@ def pre_test(){ make > /dev/null make install > /dev/null cd ${WKC}/tests - pip3 install ${WKC}/src/connector/python + pip3 install ${WKC}/src/connector/python/ ''' return 1 } pipeline { agent none - environment{ WK = '/var/lib/jenkins/workspace/TDinternal' WKC= '/var/lib/jenkins/workspace/TDinternal/community' } - stages { stage('pre_build'){ agent{label 'master'} @@ -123,19 +129,22 @@ pipeline { rm -rf ${WORKSPACE}.tes cp -r ${WORKSPACE} ${WORKSPACE}.tes cd ${WORKSPACE}.tes - + git fetch ''' script { if (env.CHANGE_TARGET == 'master') { sh ''' git checkout master - git pull origin master ''' } - else { + else if(env.CHANGE_TARGET == '2.0'){ + sh ''' + git checkout 2.0 + ''' + } + else{ sh ''' git checkout develop - git pull origin develop ''' } } @@ -143,34 +152,31 @@ pipeline { git fetch origin +refs/pull/${CHANGE_ID}/merge git checkout -qf FETCH_HEAD ''' - script{ skipbuild='2' skipbuild=sh(script: "git log -2 --pretty=%B | fgrep -ie '[skip ci]' -e '[ci skip]' && echo 1 || echo 2", returnStdout:true) println skipbuild - } sh''' rm -rf ${WORKSPACE}.tes ''' } } - stage('Parallel test stage') { //only build pr when { - allOf { + allOf{ changeRequest() - expression{ + expression{ return skipbuild.trim() == '2' - } - } + } } parallel { stage('python_1_s1') { - agent any + agent{label " slave1 || slave11 "} steps { + pre_test() timeout(time: 55, unit: 'MINUTES'){ sh ''' @@ -183,7 +189,7 @@ pipeline { } } stage('python_2_s5') { - agent any + agent{label " slave5 || slave15 "} steps { pre_test() @@ -197,7 +203,7 @@ pipeline { } } stage('python_3_s6') { - agent any + agent{label " slave6 || slave16 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -210,7 +216,7 @@ pipeline { } } stage('test_b1_s2') { - agent any + agent{label " slave2 || slave12 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -221,9 +227,9 @@ pipeline { } } } - stage('test_crash_gen_s3') { - agent any + agent{label " slave3 || slave13 "} + steps { pre_test() catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { @@ -255,13 +261,12 @@ pipeline { ./test-all.sh b2fq date ''' - } - + } } } - stage('test_valgrind_s4') { - agent any + agent{label " slave4 || slave14 "} + steps { pre_test() catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { @@ -286,7 +291,7 @@ pipeline { } } stage('test_b4_s7') { - agent any + agent{label " slave7 || slave17 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -305,7 +310,7 @@ pipeline { } } stage('test_b5_s8') { - agent any + agent{label " slave8 || slave18 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -318,7 +323,7 @@ pipeline { } } stage('test_b6_s9') { - agent any + agent{label " slave9 || slave19 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -331,7 +336,7 @@ pipeline { } } stage('test_b7_s10') { - agent any + agent{label " slave10 || slave20 "} steps { timeout(time: 55, unit: 'MINUTES'){ pre_test() @@ -423,6 +428,5 @@ pipeline { from: "support@taosdata.com" ) } - } - -} + } +} \ No newline at end of file diff --git a/tests/pytest/crash_gen/valgrind_taos.supp b/tests/pytest/crash_gen/valgrind_taos.supp index 6c92f33018..b9296f008e 100644 --- a/tests/pytest/crash_gen/valgrind_taos.supp +++ b/tests/pytest/crash_gen/valgrind_taos.supp @@ -18108,4 +18108,4 @@ fun:_PyEval_EvalFrameDefault fun:_PyEval_EvalCodeWithName fun:_PyFunction_Vectorcall -} \ No newline at end of file +} \ No newline at end of file From bc2181f4e4dbb9920680d6de206b34d3f1c558ea Mon Sep 17 00:00:00 2001 From: Ping Xiao Date: Wed, 11 Aug 2021 18:43:42 +0800 Subject: [PATCH 099/100] [TD-5835]: update performance test script --- tests/pytest/tools/taosdemoPerformance.py | 62 +++++++++++++++++++---- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/tests/pytest/tools/taosdemoPerformance.py b/tests/pytest/tools/taosdemoPerformance.py index 6b5681dfbc..c28f94b3db 100644 --- a/tests/pytest/tools/taosdemoPerformance.py +++ b/tests/pytest/tools/taosdemoPerformance.py @@ -19,11 +19,16 @@ import json import sys class taosdemoPerformace: - def __init__(self, commitID, dbName, branch, type): + def __init__(self, commitID, dbName, branch, type, numOfTables, numOfRows, numOfInt, numOfDouble, numOfBinary): self.commitID = commitID self.dbName = dbName self.branch = branch self.type = type + self.numOfTables = numOfTables + self.numOfRows = numOfRows + self.numOfInt = numOfInt + self.numOfDouble = numOfDouble + self.numOfBinary = numOfBinary self.host = "127.0.0.1" self.user = "root" self.password = "taosdata" @@ -51,13 +56,13 @@ class taosdemoPerformace: stb = { "name": "meters", "child_table_exists": "no", - "childtable_count": 10000, + "childtable_count": self.numOfTables, "childtable_prefix": "stb_", "auto_create_table": "no", "data_source": "rand", "batch_create_tbl_num": 10, "insert_mode": "taosc", - "insert_rows": 100000, + "insert_rows": self.numOfRows, "interlace_rows": 100, "max_sql_len": 1024000, "disorder_ratio": 0, @@ -68,7 +73,9 @@ class taosdemoPerformace: "sample_file": "./sample.csv", "tags_file": "", "columns": [ - {"type": "INT", "count": 4} + {"type": "INT", "count": self.numOfInt}, + {"type": "DOUBLE", "count": self.numOfDouble}, + {"type": "BINARY", "len": 128, "count": self.numOfBinary} ], "tags": [ {"type": "INT", "count": 1}, @@ -76,6 +83,7 @@ class taosdemoPerformace: ] } + stables = [] stables.append(stb) @@ -163,7 +171,7 @@ class taosdemoPerformace: cursor.execute("create database if not exists %s" % self.dbName) cursor.execute("use %s" % self.dbName) - cursor.execute("create table if not exists taosdemo_perf (ts timestamp, create_table_time float, insert_records_time float, records_per_second float, commit_id binary(50), avg_delay float, max_delay float, min_delay float, branch binary(50), type binary(20))") + cursor.execute("create table if not exists taosdemo_perf (ts timestamp, create_table_time float, insert_records_time float, records_per_second float, commit_id binary(50), avg_delay float, max_delay float, min_delay float, branch binary(50), type binary(20), numoftables int, numofrows int, numofint int, numofdouble int, numofbinary int)") print("==================== taosdemo performance ====================") print("create tables time: %f" % float(self.createTableTime)) print("insert records time: %f" % float(self.insertRecordsTime)) @@ -171,13 +179,14 @@ class taosdemoPerformace: print("avg delay: %f" % float(self.avgDelay)) print("max delay: %f" % float(self.maxDelay)) print("min delay: %f" % float(self.minDelay)) - cursor.execute("insert into taosdemo_perf values(now, %f, %f, %f, '%s', %f, %f, %f, '%s', '%s')" % + cursor.execute("insert into taosdemo_perf values(now, %f, %f, %f, '%s', %f, %f, %f, '%s', '%s', %d, %d, %d, %d, %d)" % (float(self.createTableTime), float(self.insertRecordsTime), float(self.recordsPerSecond), - self.commitID, float(self.avgDelay), float(self.maxDelay), float(self.minDelay), self.branch, self.type)) + self.commitID, float(self.avgDelay), float(self.maxDelay), float(self.minDelay), self.branch, + self.type, self.numOfTables, self.numOfRows, self.numOfInt, self.numOfDouble, self.numOfBinary)) cursor.close() cursor1 = self.conn.cursor() - cursor1.execute("drop database if exists %s" % self.insertDB) + # cursor1.execute("drop database if exists %s" % self.insertDB) cursor1.close() if __name__ == '__main__': @@ -209,8 +218,43 @@ if __name__ == '__main__': default='glibc', type=str, help='build type (default: glibc)') + parser.add_argument( + '-i', + '--num-of-int', + action='store', + default=4, + type=int, + help='num of int columns (default: 4)') + parser.add_argument( + '-D', + '--num-of-double', + action='store', + default=0, + type=int, + help='num of double columns (default: 4)') + parser.add_argument( + '-B', + '--num-of-binary', + action='store', + default=0, + type=int, + help='num of binary columns (default: 4)') + parser.add_argument( + '-t', + '--num-of-tables', + action='store', + default=10000, + type=int, + help='num of tables (default: 10000)') + parser.add_argument( + '-r', + '--num-of-rows', + action='store', + default=100000, + type=int, + help='num of rows (default: 100000)') args = parser.parse_args() - perftest = taosdemoPerformace(args.commit_id, args.database_name, args.git_branch, args.build_type) + perftest = taosdemoPerformace(args.commit_id, args.database_name, args.git_branch, args.build_type, args.num_of_tables, args.num_of_rows, args.num_of_int, args.num_of_double, args.num_of_binary) perftest.insertData() perftest.createTablesAndStoreData() From a767acea517cef07e5ac5caae0b9e0b683df3eef Mon Sep 17 00:00:00 2001 From: Shuduo Sang Date: Thu, 12 Aug 2021 07:00:52 +0800 Subject: [PATCH 100/100] [TD-5875]: taosdemo show progress (#7288) * [TD-5875]: taosdemo show progress * empty commit for CI --- src/kit/taosdemo/taosdemo.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 3838344a8b..7870dd6b03 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -245,7 +245,6 @@ typedef struct SArguments_S { uint32_t disorderRatio; // 0: no disorder, >0: x% int disorderRange; // ms, us or ns. accordig to database precision uint32_t method_of_delete; - char ** arg_list; uint64_t totalInsertRows; uint64_t totalAffectedRows; bool demo_mode; // use default column name and semi-random data @@ -637,7 +636,6 @@ SArguments g_args = { 0, // disorderRatio 1000, // disorderRange 1, // method_of_delete - NULL, // arg_list 0, // totalInsertRows; 0, // totalAffectedRows; true, // demo_mode; @@ -6407,6 +6405,9 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { bool flagSleep = true; uint64_t sleepTimeTotal = 0; + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + while(pThreadInfo->totalInsertRows < pThreadInfo->ntables * insertRows) { if ((flagSleep) && (insert_interval)) { st = taosGetTimestampMs(); @@ -6583,6 +6584,11 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { pThreadInfo->totalAffectedRows += affectedRows; + int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; + if (currentPercent > percentComplete ) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } int64_t currentPrintTime = taosGetTimestampMs(); if (currentPrintTime - lastPrintTime > 30*1000) { printf("thread[%d] has currently inserted rows: %"PRIu64 ", affected rows: %"PRIu64 "\n", @@ -6604,6 +6610,8 @@ static void* syncWriteInterlace(threadInfo *pThreadInfo) { } } } + if (percentComplete < 100) + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); free_of_interlace: tmfree(pThreadInfo->buffer); @@ -6641,6 +6649,9 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { pThreadInfo->samplePos = 0; + int percentComplete = 0; + int64_t totalRows = insertRows * pThreadInfo->ntables; + for (uint64_t tableSeq = pThreadInfo->start_table_from; tableSeq <= pThreadInfo->end_table_to; tableSeq ++) { @@ -6746,6 +6757,11 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { pThreadInfo->totalAffectedRows += affectedRows; + int currentPercent = pThreadInfo->totalAffectedRows * 100 / totalRows; + if (currentPercent > percentComplete ) { + printf("[%d]:%d%%\n", pThreadInfo->threadID, currentPercent); + percentComplete = currentPercent; + } int64_t currentPrintTime = taosGetTimestampMs(); if (currentPrintTime - lastPrintTime > 30*1000) { printf("thread[%d] has currently inserted rows: %"PRId64 ", affected rows: %"PRId64 "\n", @@ -6768,6 +6784,8 @@ static void* syncWriteProgressive(threadInfo *pThreadInfo) { __func__, __LINE__, pThreadInfo->samplePos); } } // tableSeq + if (percentComplete < 100) + printf("[%d]:%d%%\n", pThreadInfo->threadID, percentComplete); free_of_progressive: tmfree(pThreadInfo->buffer);