From 234b9c86110bba76ea73f0077a4962cd1d32ac4e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 17 Jun 2020 15:20:27 +0800 Subject: [PATCH] [td-225] fix bugs when tag is NULL --- src/query/src/qExecutor.c | 14 ++++++++++++-- src/tsdb/src/tsdbRead.c | 18 +++++++++++++++--- tests/script/general/parser/set_tag_vals.sim | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index e3a0f15949..2dff94bee0 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -2206,8 +2206,18 @@ static void doSetTagValueInParam(void *tsdb, STableId* pTableId, int32_t tagColI } if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) { + if (isNull(varDataVal(val), type)) { + tag->nType = TSDB_DATA_TYPE_NULL; + return; + } + tVariantCreateFromBinary(tag, varDataVal(val), varDataLen(val), type); } else { + if (isNull(val, type)) { + tag->nType = TSDB_DATA_TYPE_NULL; + return; + } + tVariantCreateFromBinary(tag, val, bytes, type); } } @@ -4285,12 +4295,12 @@ static void sequentialTableProcess(SQInfo *pQInfo) { assert(taosArrayGetSize(s) >= 1); setTagVal(pRuntimeEnv, (STableId*) taosArrayGet(s, 0), pQInfo->tsdb); - if (isFirstLastRowQuery(pQuery)) { assert(taosArrayGetSize(s) == 1); } + taosArrayDestroy(s); - + // here we simply set the first table as current table pQuery->current = ((SGroupItem*) taosArrayGet(group, 0))->info; scanOneTableDataBlocks(pRuntimeEnv, pQuery->current->lastKey); diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 93f5ca9355..732e8e9008 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -1930,8 +1930,7 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { SColIndex* pColIndex = &pTableGroupSupp->pCols[i]; int32_t colIndex = pColIndex->colIndex; - assert((colIndex >= 0 && colIndex < schemaNCols(pTableGroupSupp->pTagSchema)) || - (colIndex == TSDB_TBNAME_COLUMN_INDEX)); + assert(colIndex >= TSDB_TBNAME_COLUMN_INDEX); char * f1 = NULL; char * f2 = NULL; @@ -1950,7 +1949,20 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) { f1 = tdGetKVRowValOfCol(pTable1->tagVal, pCol->colId); f2 = tdGetKVRowValOfCol(pTable2->tagVal, pCol->colId); } - + + // this tags value may be NULL + if (f1 == NULL && f2 == NULL) { + continue; + } + + if (f1 == NULL) { + return -1; + } + + if (f2 == NULL) { + return 1; + } + int32_t ret = doCompare(f1, f2, type, bytes); if (ret == 0) { continue; diff --git a/tests/script/general/parser/set_tag_vals.sim b/tests/script/general/parser/set_tag_vals.sim index a684fd5406..9d7ac9678d 100644 --- a/tests/script/general/parser/set_tag_vals.sim +++ b/tests/script/general/parser/set_tag_vals.sim @@ -9,7 +9,7 @@ sql connect $dbPrefix = db $tbPrefix = tb $stbPrefix = stb -$tbNum = 1000 +$tbNum = 100 $rowNum = 100 $totalNum = $tbNum * $rowNum $ts0 = 1537146000000 @@ -26,7 +26,7 @@ $stb = $stbPrefix . $i sql drop database $db -x step1 step1: sql create database $db -print ====== create tables +print ====== create $tbNum tables sql use $db sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 binary(9), t2 binary(8)) -- GitLab