From 4b4913bc89ca562b6c30bd57478078f024154cba Mon Sep 17 00:00:00 2001 From: wpan Date: Wed, 23 Jun 2021 08:55:46 +0800 Subject: [PATCH] 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"