From 955beb81f5bf65201afa8157cd3906507d42e211 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Sun, 19 Sep 2021 12:21:32 +0800 Subject: [PATCH] getresultdatainfo when parsing --- src/client/src/tscSQLParser.c | 28 +++++++++++++++++++++++++++- src/query/src/qAggMain.c | 3 +-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index fbe9172329..548a280d9e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2820,6 +2820,32 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), interResult, false); tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); + } else if (functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE) { + tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true); + + int64_t numRowsSelected = GET_INT32_VAL(val); + if (numRowsSelected <= 0 || numRowsSelected > 1000) { // todo use macro + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12); + } + + // todo REFACTOR + // set the first column ts for top/bottom query + SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; + pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd), + 0, false); + tstrncpy(pExpr->base.aliasName, aAggs[TSDB_FUNC_TS_DUMMY].name, sizeof(pExpr->base.aliasName)); + + const int32_t TS_COLUMN_INDEX = PRIMARYKEY_TIMESTAMP_COL_INDEX; + SColumnList ids = createColumnList(1, index.tableIndex, TS_COLUMN_INDEX); + insertResultField(pQueryInfo, colIndex, &ids, TSDB_KEYSIZE, TSDB_DATA_TYPE_TIMESTAMP, + aAggs[TSDB_FUNC_TS_DUMMY].name, pExpr); + + colIndex += 1; // the first column is ts + + getResultDataInfo(pSchema->type, pSchema->bytes, functionId, numRowsSelected, &resultType, &resultSize, &interResult, 0, false, + pUdfInfo); + pExpr = tscExprAppend(pQueryInfo, functionId, &index, resultType, resultSize, getNewResColId(pCmd), interResult, false); + tscExprAddParams(&pExpr->base, val, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t)); } else { tVariantDump(pVariant, val, TSDB_DATA_TYPE_BIGINT, true); @@ -2829,7 +2855,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col } // todo REFACTOR - // set the first column ts for top/bottom/mavg/sample query + // set the first column ts for top/bottom query SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX}; pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd), 0, false); diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 886803d51a..3e01f7ed5a 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -4678,7 +4678,7 @@ static void assignResultSample(SSampleFuncInfo *pInfo, int32_t index, int64_t ts tVariantCreateFromBinary(pInfo->values + index, pData, bytes, type); } - *(pInfo->timeStamps + pInfo->numSampled) = ts; + *(pInfo->timeStamps + index) = ts; return; } @@ -4691,7 +4691,6 @@ static void do_reservoir_sample(SSampleFuncInfo *pInfo, int32_t samplesK, int64_ int32_t j = rand() % (pInfo->totalPoints); if (j < samplesK) { assignResultSample(pInfo, j, ts, pData, bytes, type); - *(pInfo->timeStamps + j) = ts; } } } -- GitLab