diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index dca70d0cbbd141223c921c9fe0258ef7c37fa62d..8ac47d1ec3b6278256568ec3d57998dd1fb0bdd1 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4598,7 +4598,7 @@ static void setDefaultOrderInfo(SQueryInfo* pQueryInfo) { int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQuerySql, SSchema* pSchema) { const char* msg0 = "only support order by primary timestamp"; const char* msg1 = "invalid column name"; - const char* msg2 = "only support order by primary timestamp or queried column"; + const char* msg2 = "only support order by primary timestamp or first tag in groupby clause allowed"; const char* msg3 = "invalid column in order by clause, only primary timestamp or first tag in groupby clause allowed"; setDefaultOrderInfo(pQueryInfo); diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 9fccb0d627fc4574ef90865e94e43c10cbdfc9bf..075448344971b545920b28f8d07198f2babe91c2 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -1328,7 +1328,7 @@ static void stddev_function_f(SQLFunctionCtx *pCtx, int32_t index) { /* the first stage is to calculate average value */ if (pStd->stage == 0) { avg_function_f(pCtx, index); - } else { + } else if (pStd->num > 0) { double avg = pStd->avg; void * pData = GET_INPUT_DATA(pCtx, index); diff --git a/src/query/src/qHistogram.c b/src/query/src/qHistogram.c index 0d31948e59e520452605ac4577b695c53b3fad6c..98b825c11f32642bdc1a16e83a76c9686fdecd46 100644 --- a/src/query/src/qHistogram.c +++ b/src/query/src/qHistogram.c @@ -143,6 +143,9 @@ SHistogramInfo* tHistogramCreateFrom(void* pBuf, int32_t numOfBins) { SHistogramInfo* pHisto = (SHistogramInfo*)pBuf; pHisto->elems = (SHistBin*)((char*)pBuf + sizeof(SHistogramInfo)); + for(int32_t i = 0; i < numOfBins; ++i) { + pHisto->elems[i].val = -DBL_MAX; + } pHisto->maxEntries = numOfBins; diff --git a/src/query/tests/histogramTest.cpp b/src/query/tests/histogramTest.cpp index 82fd4bcf9907eeb1286f9b6d0976e541e7b1a16b..3088d6f8078483c39ec3780250e8bfa2d613f218 100644 --- a/src/query/tests/histogramTest.cpp +++ b/src/query/tests/histogramTest.cpp @@ -4,42 +4,9 @@ #include #include "taos.h" -#include "tsdb.h" - -#include "tstoken.h" -#include "tutil.h" - #include "qHistogram.h" - -/* 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) { +namespace { +void doHistogramAddTest() { SHistogramInfo* pHisto = NULL; /** @@ -99,6 +66,56 @@ TEST(testCase, histogram_add) { 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; diff --git a/tests/script/general/parser/tags_filter.sim b/tests/script/general/parser/tags_filter.sim index e05776ff11a67fb0b577219046044fdc8e825dc8..d77581582846e98fe4e11a1a717c9336ebb69566 100644 --- a/tests/script/general/parser/tags_filter.sim +++ b/tests/script/general/parser/tags_filter.sim @@ -73,6 +73,9 @@ endi sql select * from stb where t1 > '1' sql select * from stb where t1 > 'a' +print =====================> TD-2685 +sql_error select t1, count(t1) from stb; + ## wildcard '%' #sql select * from stb where t1 like '%' #if $rows != 1 then