diff --git a/Jenkinsfile b/Jenkinsfile index 8fa7e78a5fce50901d46a3e57274b693a967298a..b073c32e1384dc7fa527695ab3be8dfde26be978 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,9 @@ 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() @@ -152,6 +155,7 @@ 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) diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index b7a2320b07b08abaa164b030507adf65ecaae3c1..89e3832007f11dc0ede00e639d75875f142b12f1 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -657,9 +657,7 @@ int32_t tsParseValues(char **str, STableDataBlocks *pDataBlock, int maxRows, SIn index = 0; sToken = tStrGetToken(*str, &index, false); if (sToken.n == 0 || sToken.type != TK_RP) { - tscSQLSyntaxErrMsg(pInsertParam->msg, ") expected", *str); - code = TSDB_CODE_TSC_SQL_SYNTAX_ERROR; - return code; + return tscSQLSyntaxErrMsg(pInsertParam->msg, ") expected", *str); } *str += index; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index ad91209f1833b14e86603223888df92300557f32..59978d90f0f550d9967c7a411b3f9d2a58d1e04e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4293,7 +4293,7 @@ static bool isValidExpr(tSqlExpr* pLeft, tSqlExpr* pRight, int32_t optr) { if (pRight == NULL) { return true; } - + if (pLeft->tokenId >= TK_BOOL && pLeft->tokenId <= TK_BINARY && pRight->tokenId >= TK_BOOL && pRight->tokenId <= TK_BINARY) { return false; } diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 3554b43ff6c2a8800409fdd67be7040d143627d0..0d26ec58f68b02cf7e04eccad19c1efff8f16373 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -2404,8 +2404,8 @@ int32_t tscHandleFirstRoundStableQuery(SSqlObj *pSql) { SColumn* x = taosArrayGetP(pNewQueryInfo->colList, index1); tscColumnCopy(x, pCol); } else { - SColumn *p = tscColumnClone(pCol); - taosArrayPush(pNewQueryInfo->colList, &p); + SSchema ss = {.type = (uint8_t)pCol->info.type, .bytes = pCol->info.bytes, .colId = (int16_t)pCol->columnIndex}; + tscColumnListInsert(pNewQueryInfo->colList, pCol->columnIndex, pCol->tableUid, &ss); } } } diff --git a/src/dnode/src/dnodeSystem.c b/src/dnode/src/dnodeSystem.c index ee37ffdcbb90f710253d051f1d4895ee8bc26dea..2f77788025e6d5f36460ceb866b64d54736af6a1 100644 --- a/src/dnode/src/dnodeSystem.c +++ b/src/dnode/src/dnodeSystem.c @@ -42,6 +42,8 @@ int32_t main(int32_t argc, char *argv[]) { } } else if (strcmp(argv[i], "-C") == 0) { dump_config = 1; + } else if (strcmp(argv[i], "--force-keep-file") == 0) { + tsdbForceKeepFile = true; } else if (strcmp(argv[i], "--compact-mnode-wal") == 0) { tsCompactMnodeWal = 1; } else if (strcmp(argv[i], "-V") == 0) { diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index a74a531361e64126ad922660d0fd57fc7a8693d5..1767b25402f0b33bce6068568810b499768dd0ba 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -471,6 +471,7 @@ typedef struct { bool stableQuery; // super table query or not bool topBotQuery; // TODO used bitwise flag + bool interpQuery; // interp query or not bool groupbyColumn; // denote if this is a groupby normal column query bool hasTagResults; // if there are tag values in final result or not bool timeWindowInterpo;// if the time window start/end required interpolation diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index 7870dd6b033fae06b48c73aa90149f42e71221fd..e0ca76a922644e764c38b5136fe0acc2bc5c4a4c 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -75,6 +75,7 @@ extern char configDir[]; #define BUFFER_SIZE TSDB_MAX_ALLOWED_SQL_LEN #define COND_BUF_LEN (BUFFER_SIZE - 30) #define COL_BUFFER_LEN ((TSDB_COL_NAME_LEN + 15) * TSDB_MAX_COLUMNS) + #define MAX_USERNAME_SIZE 64 #define MAX_PASSWORD_SIZE 16 #define MAX_HOSTNAME_SIZE 253 // https://man7.org/linux/man-pages/man7/hostname.7.html @@ -1007,6 +1008,7 @@ static void parse_args(int argc, char *argv[], SArguments *arguments) { exit(EXIT_FAILURE); } arguments->datatype[0] = argv[i]; + arguments->datatype[1] = NULL; } else { // more than one col int index = 0; @@ -1411,6 +1413,7 @@ static char *rand_float_str() return g_randfloat_buff + (cursor * FLOAT_BUFF_LEN); } + static float rand_float() { static int cursor; diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 5fe22826b7d0a2270300bacc3d1ae8f59d346a54..570f5c344b624eea1f23fd13f11bfc6e230c61d5 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -253,11 +253,15 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { int32_t connId = htonl(pHBMsg->connId); SConnObj *pConn = mnodeAccquireConn(connId, connInfo.user, connInfo.clientIp, connInfo.clientPort); + if (pConn == NULL) { + pHBMsg->pid = htonl(pHBMsg->pid); + pConn = mnodeCreateConn(connInfo.user, connInfo.clientIp, connInfo.clientPort, pHBMsg->pid, pHBMsg->appName); + } if (pConn == NULL) { // do not close existing links, otherwise // mError("failed to create connId, close connect"); - // pRsp->killConnection = 1; + // pRsp->killConnection = 1; } else { pRsp->connId = htonl(pConn->connId); mnodeSaveQueryStreamList(pConn, pHBMsg); diff --git a/src/mnode/src/mnodeWrite.c b/src/mnode/src/mnodeWrite.c index c0699b05b364927492b8c2656bead0e14d46ab5a..9a993dfaafab725847a43097497287fbe5642511 100644 --- a/src/mnode/src/mnodeWrite.c +++ b/src/mnode/src/mnodeWrite.c @@ -65,7 +65,14 @@ int32_t mnodeProcessWrite(SMnodeMsg *pMsg) { return TSDB_CODE_MND_MSG_NOT_PROCESSED; } - int32_t code = mnodeInitMsg(pMsg); + int32_t code = grantCheck(TSDB_GRANT_TIME); + if (code != TSDB_CODE_SUCCESS) { + mError("msg:%p, app:%p type:%s not processed, reason:%s", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType], + tstrerror(code)); + return code; + } + + code = mnodeInitMsg(pMsg); if (code != TSDB_CODE_SUCCESS) { mError("msg:%p, app:%p type:%s not processed, reason:%s", pMsg, pMsg->rpcMsg.ahandle, taosMsg[pMsg->rpcMsg.msgType], tstrerror(code)); diff --git a/src/query/inc/qExecutor.h b/src/query/inc/qExecutor.h index 996d9257560be8587f0e6ccf9d5d5b0ea4bbc0e1..56fab57e26227212ca6d2502fc7e035e2af258d5 100644 --- a/src/query/inc/qExecutor.h +++ b/src/query/inc/qExecutor.h @@ -333,6 +333,8 @@ enum OPERATOR_TYPE_E { OP_Distinct = 20, OP_Join = 21, OP_StateWindow = 22, + OP_AllTimeWindow = 23, + OP_AllMultiTableTimeInterval = 24, }; typedef struct SOperatorInfo { @@ -554,11 +556,13 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera SOperatorInfo* createProjectOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createLimitOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream); SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createFillOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableAggOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); +SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTagScanOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createDistinctOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput); SOperatorInfo* createTableBlockInfoScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv); diff --git a/src/query/inc/qUtil.h b/src/query/inc/qUtil.h index d2802d9fe00be74f750abd39b81cc3585bcef773..ce607f0fe20a2743579e99e71ddf78fc2e1dbcdc 100644 --- a/src/query/inc/qUtil.h +++ b/src/query/inc/qUtil.h @@ -39,7 +39,6 @@ #define GET_QID(_r) (((SQInfo*)((_r)->qinfo))->qId) #define curTimeWindowIndex(_winres) ((_winres)->curIndex) -#define GET_ROW_PARAM_FOR_MULTIOUTPUT(_q, tbq, sq) (((tbq) && (!(sq)))? (_q)->pExpr1[1].base.param[0].i64:1) int32_t getOutputInterResultBufSize(SQueryAttr* pQueryAttr); @@ -60,6 +59,7 @@ SResultRowCellInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr); void* freeColumnInfo(SColumnInfo* pColumnInfo, int32_t numOfCols); +int32_t getRowNumForMultioutput(SQueryAttr* pQueryAttr, bool topBottomQuery, bool stable); static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) { assert(pResultRowInfo != NULL && slot >= 0 && slot < pResultRowInfo->size); @@ -70,7 +70,7 @@ static FORCE_INLINE char* getPosInResultPage(SQueryAttr* pQueryAttr, tFilePage* int32_t offset) { assert(rowOffset >= 0 && pQueryAttr != NULL); - int32_t numOfRows = (int32_t)GET_ROW_PARAM_FOR_MULTIOUTPUT(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); + int32_t numOfRows = (int32_t)getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery); return ((char *)page->data) + rowOffset + offset * numOfRows; } diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index 1b1ebec4a3b3f2ed59985a045b356a14c2d4bae3..8d7f52eb2604b6cead74c5cadbd2afcc331c0490 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -3708,27 +3708,59 @@ static void interp_function_impl(SQLFunctionCtx *pCtx) { } } else { // no data generated yet - if (pCtx->size == 1) { + if (pCtx->size < 1) { return; } // check the timestamp in input buffer TSKEY skey = GET_TS_DATA(pCtx, 0); - TSKEY ekey = GET_TS_DATA(pCtx, 1); - - // no data generated yet - if (!(skey < pCtx->startTs && ekey > pCtx->startTs)) { - return; - } - - assert(pCtx->start.key == INT64_MIN && skey < pCtx->startTs && ekey > pCtx->startTs); if (type == TSDB_FILL_PREV) { + if (skey > pCtx->startTs) { + return; + } + + if (pCtx->size > 1) { + TSKEY ekey = GET_TS_DATA(pCtx, 1); + if (ekey > skey && ekey <= pCtx->startTs) { + skey = ekey; + } + } assignVal(pCtx->pOutput, pCtx->pInput, pCtx->outputBytes, pCtx->inputType); } else if (type == TSDB_FILL_NEXT) { - char* val = ((char*)pCtx->pInput) + pCtx->inputBytes; + TSKEY ekey = skey; + char* val = NULL; + + if (ekey < pCtx->startTs) { + if (pCtx->size > 1) { + ekey = GET_TS_DATA(pCtx, 1); + if (ekey < pCtx->startTs) { + return; + } + + val = ((char*)pCtx->pInput) + pCtx->inputBytes; + } else { + return; + } + } else { + val = (char*)pCtx->pInput; + } + assignVal(pCtx->pOutput, val, pCtx->outputBytes, pCtx->inputType); } else if (type == TSDB_FILL_LINEAR) { + if (pCtx->size <= 1) { + return; + } + + TSKEY ekey = GET_TS_DATA(pCtx, 1); + + // no data generated yet + if (!(skey < pCtx->startTs && ekey > pCtx->startTs)) { + return; + } + + assert(pCtx->start.key == INT64_MIN && skey < pCtx->startTs && ekey > pCtx->startTs); + char *start = GET_INPUT_DATA(pCtx, 0); char *end = GET_INPUT_DATA(pCtx, 1); diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 22e4f87ef98dd1d8fbca8016e3e7f781eb8e84ff..f93163665188c3e57d1bcdbce73bfae8020858fb 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -448,6 +448,44 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, SQueryRuntim pResultRowInfo->capacity = (int32_t)newCapacity; } +static bool chkResultRowFromKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, char *pData, + int16_t bytes, bool masterscan, uint64_t uid) { + bool existed = false; + SET_RES_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid); + + SResultRow **p1 = + (SResultRow **)taosHashGet(pRuntimeEnv->pResultRowHashTable, pRuntimeEnv->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes)); + + // in case of repeat scan/reverse scan, no new time window added. + if (QUERY_IS_INTERVAL_QUERY(pRuntimeEnv->pQueryAttr)) { + if (!masterscan) { // the *p1 may be NULL in case of sliding+offset exists. + return p1 != NULL; + } + + if (p1 != NULL) { + if (pResultRowInfo->size == 0) { + existed = false; + assert(pResultRowInfo->curPos == -1); + } else if (pResultRowInfo->size == 1) { + existed = (pResultRowInfo->pResult[0] == (*p1)); + } else { // check if current pResultRowInfo contains the existed pResultRow + SET_RES_EXT_WINDOW_KEY(pRuntimeEnv->keyBuf, pData, bytes, uid, pResultRowInfo); + int64_t* index = taosHashGet(pRuntimeEnv->pResultRowListSet, pRuntimeEnv->keyBuf, GET_RES_EXT_WINDOW_KEY_LEN(bytes)); + if (index != NULL) { + existed = true; + } else { + existed = false; + } + } + } + + return existed; + } + + return p1 != NULL; +} + + static SResultRow* doSetResultOutBufByKey(SQueryRuntimeEnv* pRuntimeEnv, SResultRowInfo* pResultRowInfo, int64_t tid, char* pData, int16_t bytes, bool masterscan, uint64_t tableGroupId) { bool existed = false; @@ -592,6 +630,35 @@ static STimeWindow getActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t return w; } +// get the correct time window according to the handled timestamp +static STimeWindow getCurrentActiveTimeWindow(SResultRowInfo * pResultRowInfo, int64_t ts, SQueryAttr *pQueryAttr) { + STimeWindow w = {0}; + + if (pResultRowInfo->curPos == -1) { // the first window, from the previous stored value + getInitialStartTimeWindow(pQueryAttr, ts, &w); + + if (pQueryAttr->interval.intervalUnit == 'n' || pQueryAttr->interval.intervalUnit == 'y') { + w.ekey = taosTimeAdd(w.skey, pQueryAttr->interval.interval, pQueryAttr->interval.intervalUnit, pQueryAttr->precision) - 1; + } else { + w.ekey = w.skey + pQueryAttr->interval.interval - 1; + } + } else { + w = getResultRow(pResultRowInfo, pResultRowInfo->curPos)->win; + } + + /* + * query border check, skey should not be bounded by the query time range, since the value skey will + * be used as the time window index value. So we only change ekey of time window accordingly. + */ + if (w.ekey > pQueryAttr->window.ekey && QUERY_IS_ASC_QUERY(pQueryAttr)) { + w.ekey = pQueryAttr->window.ekey; + } + + return w; +} + + + // a new buffer page for each table. Needs to opt this design static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf *pResultBuf, int32_t tid, uint32_t size) { if (pWindowRes->pageId != -1) { @@ -637,6 +704,14 @@ static int32_t addNewWindowResultBuf(SResultRow *pWindowRes, SDiskbasedResultBuf return 0; } +static bool chkWindowOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, STimeWindow *win, + bool masterscan, SResultRow **pResult, int64_t groupId, SQLFunctionCtx* pCtx, + int32_t numOfOutput, int32_t* rowCellInfoOffset) { + assert(win->skey <= win->ekey); + + return chkResultRowFromKey(pRuntimeEnv, pResultRowInfo, (char *)&win->skey, TSDB_KEYSIZE, masterscan, groupId); +} + static int32_t setResultOutputBufByKey(SQueryRuntimeEnv *pRuntimeEnv, SResultRowInfo *pResultRowInfo, int64_t tid, STimeWindow *win, bool masterscan, SResultRow **pResult, int64_t tableGroupId, SQLFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset) { @@ -707,7 +782,7 @@ static FORCE_INLINE int32_t getForwardStepsInBlock(int32_t numOfRows, __block_se } } - assert(forwardStep > 0); + assert(forwardStep >= 0); return forwardStep; } @@ -764,6 +839,8 @@ static void doUpdateResultRowIndex(SResultRowInfo*pResultRowInfo, TSKEY lastKey, pResultRowInfo->curPos = i + 1; // current not closed result object } } + + //pResultRowInfo->prevSKey = pResultRowInfo->pResult[pResultRowInfo->curIndex]->win.skey; } static void updateResultRowInfoActiveIndex(SResultRowInfo* pResultRowInfo, SQueryAttr* pQueryAttr, TSKEY lastKey) { @@ -813,7 +890,7 @@ static int32_t getNumOfRowsInTimeWindow(SQueryRuntimeEnv* pRuntimeEnv, SDataBloc } } - assert(num > 0); + assert(num >= 0); return num; } @@ -973,6 +1050,11 @@ static int32_t getNextQualifiedWindow(SQueryAttr* pQueryAttr, STimeWindow *pNext } } + /* interp query with fill should not skip time window */ + if (pQueryAttr->pointInterpQuery && pQueryAttr->fillType != TSDB_FILL_NONE) { + return startPos; + } + /* * This time window does not cover any data, try next time window, * this case may happen when the time window is too small @@ -1485,6 +1567,82 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); } + +static void hashAllIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResultRowInfo, SSDataBlock* pSDataBlock, int32_t tableGroupId) { + STableIntervalOperatorInfo* pInfo = (STableIntervalOperatorInfo*) pOperatorInfo->info; + + SQueryRuntimeEnv* pRuntimeEnv = pOperatorInfo->pRuntimeEnv; + int32_t numOfOutput = pOperatorInfo->numOfOutput; + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + + int32_t step = GET_FORWARD_DIRECTION_FACTOR(pQueryAttr->order.order); + bool ascQuery = QUERY_IS_ASC_QUERY(pQueryAttr); + + TSKEY* tsCols = NULL; + if (pSDataBlock->pDataBlock != NULL) { + SColumnInfoData* pColDataInfo = taosArrayGet(pSDataBlock->pDataBlock, 0); + tsCols = (int64_t*) pColDataInfo->pData; + assert(tsCols[0] == pSDataBlock->info.window.skey && + tsCols[pSDataBlock->info.rows - 1] == pSDataBlock->info.window.ekey); + } + + int32_t startPos = ascQuery? 0 : (pSDataBlock->info.rows - 1); + TSKEY ts = getStartTsKey(pQueryAttr, &pSDataBlock->info.window, tsCols, pSDataBlock->info.rows); + + STimeWindow win = getCurrentActiveTimeWindow(pResultRowInfo, ts, pQueryAttr); + bool masterScan = IS_MASTER_SCAN(pRuntimeEnv); + + SResultRow* pResult = NULL; + int32_t forwardStep = 0; + int32_t ret = 0; + + while (1) { + // null data, failed to allocate more memory buffer + ret = setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.tid, &win, masterScan, &pResult, + tableGroupId, pInfo->pCtx, numOfOutput, pInfo->rowCellInfoOffset); + if (ret != TSDB_CODE_SUCCESS) { + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + TSKEY ekey = reviseWindowEkey(pQueryAttr, &win); + forwardStep = getNumOfRowsInTimeWindow(pRuntimeEnv, &pSDataBlock->info, tsCols, startPos, ekey, binarySearchForKey, true); + + // window start(end) key interpolation + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->pCtx, pResult, &win, startPos, forwardStep); + doApplyFunctions(pRuntimeEnv, pInfo->pCtx, &win, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); + + int32_t prevEndPos = (forwardStep - 1) * step + startPos; + startPos = getNextQualifiedWindow(pQueryAttr, &win, &pSDataBlock->info, tsCols, binarySearchForKey, prevEndPos); + if (startPos < 0) { + if (win.skey <= pQueryAttr->window.ekey) { + int32_t code = setResultOutputBufByKey(pRuntimeEnv, pResultRowInfo, pSDataBlock->info.tid, &win, masterScan, &pResult, tableGroupId, + pInfo->pCtx, numOfOutput, pInfo->rowCellInfoOffset); + if (code != TSDB_CODE_SUCCESS || pResult == NULL) { + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + startPos = pSDataBlock->info.rows - 1; + + // window start(end) key interpolation + doWindowBorderInterpolation(pOperatorInfo, pSDataBlock, pInfo->pCtx, pResult, &win, startPos, forwardStep); + doApplyFunctions(pRuntimeEnv, pInfo->pCtx, &win, startPos, forwardStep, tsCols, pSDataBlock->info.rows, numOfOutput); + } + + break; + } + setResultRowInterpo(pResult, RESULT_ROW_END_INTERP); + } + + if (pQueryAttr->timeWindowInterpo) { + int32_t rowIndex = ascQuery? (pSDataBlock->info.rows-1):0; + saveDataBlockLastRow(pRuntimeEnv, &pSDataBlock->info, pSDataBlock->pDataBlock, rowIndex); + } + + updateResultRowInfoActiveIndex(pResultRowInfo, pQueryAttr, pRuntimeEnv->current->lastKey); +} + + + static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; STableQueryInfo* item = pRuntimeEnv->current; @@ -1981,6 +2139,12 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); break; } + case OP_AllMultiTableTimeInterval: { + pRuntimeEnv->proot = + createAllMultiTableTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); + setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); + break; + } case OP_TimeWindow: { pRuntimeEnv->proot = createTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); @@ -1990,6 +2154,15 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int32_t numOf } break; } + case OP_AllTimeWindow: { + pRuntimeEnv->proot = + createAllTimeIntervalOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); + int32_t opType = pRuntimeEnv->proot->upstream[0]->operatorType; + if (opType != OP_DummyInput && opType != OP_Join) { + setTableScanFilterOperatorInfo(pRuntimeEnv->proot->upstream[0]->info, pRuntimeEnv->proot); + } + break; + } case OP_Groupby: { pRuntimeEnv->proot = createGroupbyOperatorInfo(pRuntimeEnv, pRuntimeEnv->proot, pQueryAttr->pExpr1, pQueryAttr->numOfOutput); @@ -2533,7 +2706,7 @@ static void getIntermediateBufInfo(SQueryRuntimeEnv* pRuntimeEnv, int32_t* ps, i SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; int32_t MIN_ROWS_PER_PAGE = 4; - *rowsize = (int32_t)(pQueryAttr->resultRowSize * GET_ROW_PARAM_FOR_MULTIOUTPUT(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); + *rowsize = (int32_t)(pQueryAttr->resultRowSize * getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); int32_t overhead = sizeof(tFilePage); // one page contains at least two rows @@ -2907,6 +3080,8 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa // check if this data block is required to load if ((*status) != BLK_DATA_ALL_NEEDED) { + bool needFilter = true; + // the pCtx[i] result is belonged to previous time window since the outputBuf has not been set yet, // the filter result may be incorrect. So in case of interval query, we need to set the correct time output buffer if (QUERY_IS_INTERVAL_QUERY(pQueryAttr)) { @@ -2916,10 +3091,16 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa TSKEY k = ascQuery? pBlock->info.window.skey : pBlock->info.window.ekey; STimeWindow win = getActiveTimeWindow(pTableScanInfo->pResultRowInfo, k, pQueryAttr); - if (setResultOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pBlock->info.tid, &win, masterScan, &pResult, groupId, - pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, - pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { - longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + if (pQueryAttr->pointInterpQuery) { + needFilter = chkWindowOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, &win, masterScan, &pResult, groupId, + pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, + pTableScanInfo->rowCellInfoOffset); + } else { + if (setResultOutputBufByKey(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pBlock->info.tid, &win, masterScan, &pResult, groupId, + pTableScanInfo->pCtx, pTableScanInfo->numOfOutput, + pTableScanInfo->rowCellInfoOffset) != TSDB_CODE_SUCCESS) { + longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); + } } } else if (pQueryAttr->stableQuery && (!pQueryAttr->tsCompQuery) && (!pQueryAttr->diffQuery)) { // stable aggregate, not interval aggregate or normal column aggregate doSetTableGroupOutputBuf(pRuntimeEnv, pTableScanInfo->pResultRowInfo, pTableScanInfo->pCtx, @@ -2927,7 +3108,11 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa pRuntimeEnv->current->groupIndex); } - (*status) = doFilterByBlockTimeWindow(pTableScanInfo, pBlock); + if (needFilter) { + (*status) = doFilterByBlockTimeWindow(pTableScanInfo, pBlock); + } else { + (*status) = BLK_DATA_ALL_NEEDED; + } } SDataBlockInfo* pBlockInfo = &pBlock->info; @@ -3437,7 +3622,7 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf // re-estabilish output buffer pointer. int32_t functionId = pBInfo->pCtx[i].functionId; if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) { - pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[0].pOutput; + pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput; } } } @@ -4538,6 +4723,7 @@ int32_t doInitQInfo(SQInfo* pQInfo, STSBuf* pTsBuf, void* tsdb, void* sourceOptr SQueryAttr *pQueryAttr = pQInfo->runtimeEnv.pQueryAttr; pQueryAttr->tsdb = tsdb; + if (tsdb != NULL) { int32_t code = setupQueryHandle(tsdb, pRuntimeEnv, pQInfo->qId, pQueryAttr->stableQuery); if (code != TSDB_CODE_SUCCESS) { @@ -4946,7 +5132,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf pTableScanInfo->pCtx = pAggInfo->binfo.pCtx; pTableScanInfo->pResultRowInfo = &pAggInfo->binfo.resultRowInfo; pTableScanInfo->rowCellInfoOffset = pAggInfo->binfo.rowCellInfoOffset; - } else if (pDownstream->operatorType == OP_TimeWindow) { + } else if (pDownstream->operatorType == OP_TimeWindow || pDownstream->operatorType == OP_AllTimeWindow) { STableIntervalOperatorInfo *pIntervalInfo = pDownstream->info; pTableScanInfo->pCtx = pIntervalInfo->pCtx; @@ -4960,7 +5146,7 @@ void setTableScanFilterOperatorInfo(STableScanInfo* pTableScanInfo, SOperatorInf pTableScanInfo->pResultRowInfo = &pGroupbyInfo->binfo.resultRowInfo; pTableScanInfo->rowCellInfoOffset = pGroupbyInfo->binfo.rowCellInfoOffset; - } else if (pDownstream->operatorType == OP_MultiTableTimeInterval) { + } else if (pDownstream->operatorType == OP_MultiTableTimeInterval || pDownstream->operatorType == OP_AllMultiTableTimeInterval) { STableIntervalOperatorInfo *pInfo = pDownstream->info; pTableScanInfo->pCtx = pInfo->pCtx; @@ -5104,7 +5290,7 @@ SOperatorInfo* createGlobalAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SMultiwayMergeInfo* pInfo = calloc(1, sizeof(SMultiwayMergeInfo)); pInfo->resultRowFactor = - (int32_t)(GET_ROW_PARAM_FOR_MULTIOUTPUT(pRuntimeEnv->pQueryAttr, pRuntimeEnv->pQueryAttr->topBotQuery, false)); + (int32_t)(getRowNumForMultioutput(pRuntimeEnv->pQueryAttr, pRuntimeEnv->pQueryAttr->topBotQuery, false)); pRuntimeEnv->scanFlag = MERGE_STAGE; // TODO init when creating pCtx @@ -5579,6 +5765,66 @@ static SSDataBlock* doIntervalAgg(void* param, bool* newgroup) { return pIntervalInfo->pRes->info.rows == 0? NULL:pIntervalInfo->pRes; } +static SSDataBlock* doAllIntervalAgg(void* param, bool* newgroup) { + SOperatorInfo* pOperator = (SOperatorInfo*) param; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; + + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + if (pOperator->status == OP_RES_TO_RETURN) { + toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + + if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + + return pIntervalInfo->pRes; + } + + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + int32_t order = pQueryAttr->order.order; + STimeWindow win = pQueryAttr->window; + + SOperatorInfo* upstream = pOperator->upstream[0]; + + while(1) { + publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); + SSDataBlock* pBlock = upstream->exec(upstream, newgroup); + publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); + + if (pBlock == NULL) { + break; + } + + setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); + + // the pDataBlock are always the same one, no need to call this again + setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); + hashAllIntervalAgg(pOperator, &pIntervalInfo->resultRowInfo, pBlock, 0); + } + + // restore the value + pQueryAttr->order.order = order; + pQueryAttr->window = win; + + pOperator->status = OP_RES_TO_RETURN; + closeAllResultRows(&pIntervalInfo->resultRowInfo); + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + finalizeQueryResult(pOperator, pIntervalInfo->pCtx, &pIntervalInfo->resultRowInfo, pIntervalInfo->rowCellInfoOffset); + + initGroupResInfo(&pRuntimeEnv->groupResInfo, &pIntervalInfo->resultRowInfo); + toSSDataBlock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pIntervalInfo->pRes); + + if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + + return pIntervalInfo->pRes->info.rows == 0? NULL:pIntervalInfo->pRes; +} + static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { SOperatorInfo* pOperator = (SOperatorInfo*) param; if (pOperator->status == OP_EXEC_DONE) { @@ -5634,6 +5880,63 @@ static SSDataBlock* doSTableIntervalAgg(void* param, bool* newgroup) { return pIntervalInfo->pRes; } +static SSDataBlock* doAllSTableIntervalAgg(void* param, bool* newgroup) { + SOperatorInfo* pOperator = (SOperatorInfo*) param; + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + STableIntervalOperatorInfo* pIntervalInfo = pOperator->info; + SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; + + if (pOperator->status == OP_RES_TO_RETURN) { + copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + + return pIntervalInfo->pRes; + } + + SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; + int32_t order = pQueryAttr->order.order; + + SOperatorInfo* upstream = pOperator->upstream[0]; + + while(1) { + publishOperatorProfEvent(upstream, QUERY_PROF_BEFORE_OPERATOR_EXEC); + SSDataBlock* pBlock = upstream->exec(upstream, newgroup); + publishOperatorProfEvent(upstream, QUERY_PROF_AFTER_OPERATOR_EXEC); + + if (pBlock == NULL) { + break; + } + + // the pDataBlock are always the same one, no need to call this again + STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current; + + setTagValue(pOperator, pTableQueryInfo->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput); + setInputDataBlock(pOperator, pIntervalInfo->pCtx, pBlock, pQueryAttr->order.order); + setIntervalQueryRange(pRuntimeEnv, pBlock->info.window.skey); + + hashAllIntervalAgg(pOperator, &pTableQueryInfo->resInfo, pBlock, pTableQueryInfo->groupIndex); + } + + pOperator->status = OP_RES_TO_RETURN; + pQueryAttr->order.order = order; // TODO : restore the order + doCloseAllTimeWindow(pRuntimeEnv); + setQueryStatus(pRuntimeEnv, QUERY_COMPLETED); + + copyToSDataBlock(pRuntimeEnv, 3000, pIntervalInfo->pRes, pIntervalInfo->rowCellInfoOffset); + if (pIntervalInfo->pRes->info.rows == 0 || !hasRemainData(&pRuntimeEnv->groupResInfo)) { + pOperator->status = OP_EXEC_DONE; + } + + return pIntervalInfo->pRes; +} + + + static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorInfo *pInfo, SSDataBlock *pSDataBlock) { SQueryRuntimeEnv* pRuntimeEnv = pOperator->pRuntimeEnv; @@ -6016,7 +6319,7 @@ SOperatorInfo* createAggregateOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpera SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo)); SQueryAttr* pQueryAttr = pRuntimeEnv->pQueryAttr; - int32_t numOfRows = (int32_t)(GET_ROW_PARAM_FOR_MULTIOUTPUT(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); + int32_t numOfRows = (int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery)); pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, numOfRows); pInfo->binfo.pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); @@ -6255,6 +6558,32 @@ SOperatorInfo* createTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOp appendUpstream(pOperator, upstream); return pOperator; } + + +SOperatorInfo* createAllTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { + STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); + + pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset); + pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); + initResultRowInfo(&pInfo->resultRowInfo, 8, TSDB_DATA_TYPE_INT); + + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + + pOperator->name = "AllTimeIntervalAggOperator"; + pOperator->operatorType = OP_AllTimeWindow; + pOperator->blockingOptr = true; + pOperator->status = OP_IN_EXECUTING; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; + pOperator->exec = doAllIntervalAgg; + pOperator->cleanup = destroyBasicOperatorInfo; + + appendUpstream(pOperator, upstream); + return pOperator; +} + SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SStateWindowOperatorInfo* pInfo = calloc(1, sizeof(SStateWindowOperatorInfo)); pInfo->colIndex = -1; @@ -6277,7 +6606,6 @@ SOperatorInfo* createStatewindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOpe appendUpstream(pOperator, upstream); return pOperator; - } SOperatorInfo* createSWindowOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SSWindowOperatorInfo* pInfo = calloc(1, sizeof(SSWindowOperatorInfo)); @@ -6329,6 +6657,32 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRunti return pOperator; } +SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { + STableIntervalOperatorInfo* pInfo = calloc(1, sizeof(STableIntervalOperatorInfo)); + + pInfo->pCtx = createSQLFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->rowCellInfoOffset); + pInfo->pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); + initResultRowInfo(&pInfo->resultRowInfo, 8, TSDB_DATA_TYPE_INT); + + SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo)); + pOperator->name = "AllMultiTableTimeIntervalOperator"; + pOperator->operatorType = OP_AllMultiTableTimeInterval; + pOperator->blockingOptr = true; + pOperator->status = OP_IN_EXECUTING; + pOperator->pExpr = pExpr; + pOperator->numOfOutput = numOfOutput; + pOperator->info = pInfo; + pOperator->pRuntimeEnv = pRuntimeEnv; + + pOperator->exec = doAllSTableIntervalAgg; + pOperator->cleanup = destroyBasicOperatorInfo; + + appendUpstream(pOperator, upstream); + + return pOperator; +} + + SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* upstream, SExprInfo* pExpr, int32_t numOfOutput) { SGroupbyOperatorInfo* pInfo = calloc(1, sizeof(SGroupbyOperatorInfo)); pInfo->colIndex = -1; // group by column index @@ -6339,7 +6693,7 @@ SOperatorInfo* createGroupbyOperatorInfo(SQueryRuntimeEnv* pRuntimeEnv, SOperato SQueryAttr *pQueryAttr = pRuntimeEnv->pQueryAttr; pQueryAttr->resultRowSize = (pQueryAttr->resultRowSize * - (int32_t)(GET_ROW_PARAM_FOR_MULTIOUTPUT(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery))); + (int32_t)(getRowNumForMultioutput(pQueryAttr, pQueryAttr->topBotQuery, pQueryAttr->stableQuery))); pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pRuntimeEnv->resultInfo.capacity); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8, TSDB_DATA_TYPE_INT); diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 7dd73c9fe48be39ee3a7a879348076ac3fbe9f44..1a86bbae36697224585522b5be836c61394c7cc4 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -206,6 +206,12 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputR } else { assert(pFillInfo->currentKey == ts); initBeforeAfterDataBuf(pFillInfo, prev); + if (pFillInfo->type == TSDB_FILL_NEXT && (pFillInfo->index + 1) < pFillInfo->numOfRows) { + initBeforeAfterDataBuf(pFillInfo, next); + ++pFillInfo->index; + copyCurrentRowIntoBuf(pFillInfo, srcData, *next); + --pFillInfo->index; + } // assign rows to dst buffer for (int32_t i = 0; i < pFillInfo->numOfCols; ++i) { @@ -227,6 +233,12 @@ static int32_t fillResultImpl(SFillInfo* pFillInfo, void** data, int32_t outputR } else if (pFillInfo->type == TSDB_FILL_LINEAR) { assignVal(output, src, pCol->col.bytes, pCol->col.type); memcpy(*prev + pCol->col.offset, src, pCol->col.bytes); + } else if (pFillInfo->type == TSDB_FILL_NEXT) { + if (*next) { + assignVal(output, *next + pCol->col.offset, pCol->col.bytes, pCol->col.type); + } else { + setNull(output, pCol->col.type, pCol->col.bytes); + } } else { assignVal(output, (char*)&pCol->fillVal.i, pCol->col.bytes, pCol->col.type); } diff --git a/src/query/src/qPlan.c b/src/query/src/qPlan.c index e01f41276fb73e9293ba5e3b379c85600053ed93..b8a5ee7699b34fed82ad67a592a6ca9148cc92cb 100644 --- a/src/query/src/qPlan.c +++ b/src/query/src/qPlan.c @@ -567,10 +567,18 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { } } else if (pQueryAttr->interval.interval > 0) { if (pQueryAttr->stableQuery) { - op = OP_MultiTableTimeInterval; + if (pQueryAttr->pointInterpQuery) { + op = OP_AllMultiTableTimeInterval; + } else { + op = OP_MultiTableTimeInterval; + } taosArrayPush(plan, &op); - } else { - op = OP_TimeWindow; + } else { + if (pQueryAttr->pointInterpQuery) { + op = OP_AllTimeWindow; + } else { + op = OP_TimeWindow; + } taosArrayPush(plan, &op); if (pQueryAttr->pExpr2 != NULL) { @@ -578,7 +586,7 @@ SArray* createExecOperatorPlan(SQueryAttr* pQueryAttr) { taosArrayPush(plan, &op); } - if (pQueryAttr->fillType != TSDB_FILL_NONE && (!pQueryAttr->pointInterpQuery)) { + if (pQueryAttr->fillType != TSDB_FILL_NONE) { op = OP_Fill; taosArrayPush(plan, &op); } diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index a3d2e424d23e5ee566bc54117d3fc421d5b42d78..4caf351799adbf000265566fb22617067efb725d 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -30,6 +30,18 @@ typedef struct SCompSupporter { int32_t order; } SCompSupporter; +int32_t getRowNumForMultioutput(SQueryAttr* pQueryAttr, bool topBottomQuery, bool stable) { + if (pQueryAttr && (!stable)) { + for (int16_t i = 0; i < pQueryAttr->numOfOutput; ++i) { + if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_TOP || pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_BOTTOM) { + return (int32_t)pQueryAttr->pExpr1[i].base.param[0].i64; + } + } + } + + return 1; +} + int32_t getOutputInterResultBufSize(SQueryAttr* pQueryAttr) { int32_t size = 0; diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 0449ecac8b228662455930b8caf7ff2b5a2da7b2..25495182498f7c1a82f9f9459290e44f082f5eb2 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -397,7 +397,11 @@ void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uin SThreadObj *pThreadObj = pClientObj->pThreadObj[index]; SOCKET fd = taosOpenTcpClientSocket(ip, port, pThreadObj->ip); +#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) + if (fd == (SOCKET)-1) return NULL; +#else if (fd <= 0) return NULL; +#endif struct sockaddr_in sin; uint16_t localPort = 0; diff --git a/src/tsdb/inc/tsdbMeta.h b/src/tsdb/inc/tsdbMeta.h index 9a8de01f71331d091e75fedac61cc333dca165cc..51801c843c279f10e9e0895a0f2dee2839a3f6a2 100644 --- a/src/tsdb/inc/tsdbMeta.h +++ b/src/tsdb/inc/tsdbMeta.h @@ -24,8 +24,7 @@ typedef struct STable { tstr* name; // NOTE: there a flexible string here uint64_t suid; struct STable* pSuper; // super table pointer - uint8_t numOfSchemas; - STSchema* schema[TSDB_MAX_TABLE_SCHEMAS]; + SArray* schema; STSchema* tagSchema; SKVRow tagVal; SSkipList* pIndex; // For TSDB_SUPER_TABLE, it is the skiplist index @@ -107,10 +106,9 @@ static FORCE_INLINE STSchema* tsdbGetTableSchemaImpl(STable* pTable, bool lock, if (lock) TSDB_RLOCK_TABLE(pDTable); if (_version < 0) { // get the latest version of schema - pTSchema = pDTable->schema[pDTable->numOfSchemas - 1]; + pTSchema = *(STSchema **)taosArrayGetLast(pDTable->schema); } else { // get the schema with version - void* ptr = taosbsearch(&_version, pDTable->schema, pDTable->numOfSchemas, sizeof(STSchema*), - tsdbCompareSchemaVersion, TD_EQ); + void* ptr = taosArraySearch(pDTable->schema, &_version, tsdbCompareSchemaVersion, TD_EQ); if (ptr == NULL) { terrno = TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION; goto _exit; diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index e53d2826c76acb057020b05bfeba4e22cf128c51..68450301d8f0c8536327e593d87030920f27ff49 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -37,6 +37,8 @@ static void tsdbScanAndTryFixDFilesHeader(STsdbRepo *pRepo, int32_t *nExpired); static int tsdbProcessExpiredFS(STsdbRepo *pRepo); static int tsdbCreateMeta(STsdbRepo *pRepo); +// For backward compatibility +bool tsdbForceKeepFile = false; // ================== CURRENT file header info static int tsdbEncodeFSHeader(void **buf, SFSHeader *pHeader) { int tlen = 0; @@ -1048,6 +1050,26 @@ static int tsdbRestoreMeta(STsdbRepo *pRepo) { return -1; } + if (tsdbForceKeepFile) { + struct stat tfstat; + + // Get real file size + if (fstat(pfs->cstatus->pmf->fd, &tfstat) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + tsdbCloseMFile(pfs->cstatus->pmf); + tfsClosedir(tdir); + regfree(®ex); + return -1; + } + + if (pfs->cstatus->pmf->info.size != tfstat.st_size) { + int64_t tfsize = pfs->cstatus->pmf->info.size; + pfs->cstatus->pmf->info.size = tfstat.st_size; + tsdbInfo("vgId:%d file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo), + TSDB_FILE_FULL_NAME(pfs->cstatus->pmf), tfsize, pfs->cstatus->pmf->info.size); + } + } + tsdbCloseMFile(pfs->cstatus->pmf); } } else if (code == REG_NOMATCH) { @@ -1212,6 +1234,24 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { return -1; } + if (tsdbForceKeepFile) { + struct stat tfstat; + + // Get real file size + if (fstat(pDFile->fd, &tfstat) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + taosArrayDestroy(fArray); + return -1; + } + + if (pDFile->info.size != tfstat.st_size) { + int64_t tfsize = pDFile->info.size; + pDFile->info.size = tfstat.st_size; + tsdbInfo("vgId:%d file %s header size is changed from %" PRId64 " to %" PRId64, REPO_ID(pRepo), + TSDB_FILE_FULL_NAME(pDFile), tfsize, pDFile->info.size); + } + } + tsdbCloseDFile(pDFile); index++; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index 21150c66e21cf2488981bd9d475f333073e7aa22..96e86a6d99ce05624d72a557f112fa1aa0919e1f 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -43,6 +43,8 @@ static int tsdbRemoveTableFromStore(STsdbRepo *pRepo, STable *pTable); static int tsdbRmTableFromMeta(STsdbRepo *pRepo, STable *pTable); static int tsdbAdjustMetaTables(STsdbRepo *pRepo, int tid); static int tsdbCheckTableTagVal(SKVRow *pKVRow, STSchema *pSchema); +static int tsdbAddSchema(STable *pTable, STSchema *pSchema); +static void tsdbFreeTableSchema(STable *pTable); // ------------------ OUTER FUNCTIONS ------------------ int tsdbCreateTable(STsdbRepo *repo, STableCfg *pCfg) { @@ -722,17 +724,10 @@ void tsdbUpdateTableSchema(STsdbRepo *pRepo, STable *pTable, STSchema *pSchema, STsdbMeta *pMeta = pRepo->tsdbMeta; STable *pCTable = (TABLE_TYPE(pTable) == TSDB_CHILD_TABLE) ? pTable->pSuper : pTable; - ASSERT(schemaVersion(pSchema) > schemaVersion(pCTable->schema[pCTable->numOfSchemas - 1])); + ASSERT(schemaVersion(pSchema) > schemaVersion(*(STSchema **)taosArrayGetLast(pCTable->schema))); TSDB_WLOCK_TABLE(pCTable); - if (pCTable->numOfSchemas < TSDB_MAX_TABLE_SCHEMAS) { - pCTable->schema[pCTable->numOfSchemas++] = pSchema; - } else { - ASSERT(pCTable->numOfSchemas == TSDB_MAX_TABLE_SCHEMAS); - tdFreeSchema(pCTable->schema[0]); - memmove(pCTable->schema, pCTable->schema + 1, sizeof(STSchema *) * (TSDB_MAX_TABLE_SCHEMAS - 1)); - pCTable->schema[pCTable->numOfSchemas - 1] = pSchema; - } + tsdbAddSchema(pCTable, pSchema); if (schemaNCols(pSchema) > pMeta->maxCols) pMeta->maxCols = schemaNCols(pSchema); if (schemaTLen(pSchema) > pMeta->maxRowBytes) pMeta->maxRowBytes = schemaTLen(pSchema); @@ -828,9 +823,7 @@ static STable *tsdbCreateTableFromCfg(STableCfg *pCfg, bool isSuper, STable *pST TABLE_TID(pTable) = -1; TABLE_SUID(pTable) = -1; pTable->pSuper = NULL; - pTable->numOfSchemas = 1; - pTable->schema[0] = tdDupSchema(pCfg->schema); - if (pTable->schema[0] == NULL) { + if (tsdbAddSchema(pTable, tdDupSchema(pCfg->schema)) < 0) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } @@ -841,7 +834,8 @@ static STable *tsdbCreateTableFromCfg(STableCfg *pCfg, bool isSuper, STable *pST } pTable->tagVal = NULL; STColumn *pCol = schemaColAt(pTable->tagSchema, DEFAULT_TAG_INDEX_COLUMN); - pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), NULL, SL_ALLOW_DUP_KEY, getTagIndexKey); + pTable->pIndex = tSkipListCreate(TSDB_SUPER_TABLE_SL_LEVEL, colType(pCol), (uint8_t)(colBytes(pCol)), NULL, + SL_ALLOW_DUP_KEY, getTagIndexKey); if (pTable->pIndex == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; @@ -870,9 +864,7 @@ static STable *tsdbCreateTableFromCfg(STableCfg *pCfg, bool isSuper, STable *pST } } else { TABLE_SUID(pTable) = -1; - pTable->numOfSchemas = 1; - pTable->schema[0] = tdDupSchema(pCfg->schema); - if (pTable->schema[0] == NULL) { + if (tsdbAddSchema(pTable, tdDupSchema(pCfg->schema)) < 0) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; } @@ -906,9 +898,7 @@ static void tsdbFreeTable(STable *pTable) { TABLE_UID(pTable)); tfree(TABLE_NAME(pTable)); if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) { - for (int i = 0; i < TSDB_MAX_TABLE_SCHEMAS; i++) { - tdFreeSchema(pTable->schema[i]); - } + tsdbFreeTableSchema(pTable); if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) { tdFreeSchema(pTable->tagSchema); @@ -1260,9 +1250,10 @@ static int tsdbEncodeTable(void **buf, STable *pTable) { tlen += taosEncodeFixedU64(buf, TABLE_SUID(pTable)); tlen += tdEncodeKVRow(buf, pTable->tagVal); } else { - tlen += taosEncodeFixedU8(buf, pTable->numOfSchemas); - for (int i = 0; i < pTable->numOfSchemas; i++) { - tlen += tdEncodeSchema(buf, pTable->schema[i]); + tlen += taosEncodeFixedU8(buf, (uint8_t)taosArrayGetSize(pTable->schema)); + for (int i = 0; i < taosArrayGetSize(pTable->schema); i++) { + STSchema *pSchema = taosArrayGetP(pTable->schema, i); + tlen += tdEncodeSchema(buf, pSchema); } if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) { @@ -1293,9 +1284,12 @@ static void *tsdbDecodeTable(void *buf, STable **pRTable) { buf = taosDecodeFixedU64(buf, &TABLE_SUID(pTable)); buf = tdDecodeKVRow(buf, &(pTable->tagVal)); } else { - buf = taosDecodeFixedU8(buf, &(pTable->numOfSchemas)); - for (int i = 0; i < pTable->numOfSchemas; i++) { - buf = tdDecodeSchema(buf, &(pTable->schema[i])); + uint8_t nSchemas; + buf = taosDecodeFixedU8(buf, &nSchemas); + for (int i = 0; i < nSchemas; i++) { + STSchema *pSchema; + buf = tdDecodeSchema(buf, &pSchema); + tsdbAddSchema(pTable, pSchema); } if (TABLE_TYPE(pTable) == TSDB_SUPER_TABLE) { @@ -1457,3 +1451,38 @@ static int tsdbCheckTableTagVal(SKVRow *pKVRow, STSchema *pSchema) { return 0; } + +static int tsdbAddSchema(STable *pTable, STSchema *pSchema) { + ASSERT(TABLE_TYPE(pTable) != TSDB_CHILD_TABLE); + + if (pTable->schema == NULL) { + pTable->schema = taosArrayInit(TSDB_MAX_TABLE_SCHEMAS, sizeof(SSchema *)); + if (pTable->schema == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } + + ASSERT(taosArrayGetSize(pTable->schema) == 0 || + schemaVersion(pSchema) > schemaVersion(*(STSchema **)taosArrayGetLast(pTable->schema))); + + if (taosArrayPush(pTable->schema, &pSchema) == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + + return 0; +} + +static void tsdbFreeTableSchema(STable *pTable) { + ASSERT(pTable != NULL); + + if (pTable->schema) { + for (size_t i = 0; i < taosArrayGetSize(pTable->schema); i++) { + STSchema *pSchema = taosArrayGetP(pTable->schema, i); + tdFreeSchema(pSchema); + } + + taosArrayDestroy(pTable->schema); + } +} \ No newline at end of file diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 716f82d1545d5aa3adb257dc3ed8ea3047acb3ca..e1d40aa7d046c4fce79d76bcbea36ee3f635163a 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -2693,7 +2693,7 @@ static void destroyHelper(void* param) { free(param); } -static bool loadBlockOfActiveTable(STsdbQueryHandle* pQueryHandle) { +static bool loadBlockOfActiveTable(STsdbQueryHandle* pQueryHandle) { if (pQueryHandle->checkFiles) { // check if the query range overlaps with the file data block bool exists = true; diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index d03ce6e0f1f34478951a84b2ab18020f5cbec92b..f146ec0b8b675527b41dfb2267946193e5e5fe89 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -81,6 +81,7 @@ typedef struct { extern SGlobalCfg tsGlobalConfig[]; extern int32_t tsGlobalConfigNum; extern char * tsCfgStatusStr[]; +extern bool tsdbForceKeepFile; void taosReadGlobalLogCfg(); bool taosReadGlobalCfg(); diff --git a/tests/pytest/alter/alterColMultiTimes.py b/tests/pytest/alter/alterColMultiTimes.py new file mode 100644 index 0000000000000000000000000000000000000000..173ca8158deeb1e98bd3fc5ff3b942b20b8bc26e --- /dev/null +++ b/tests/pytest/alter/alterColMultiTimes.py @@ -0,0 +1,67 @@ +################################################################### +# 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 random +import string +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * + +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def genColList(self): + ''' + generate column list + ''' + col_list = list() + for i in range(1, 18): + col_list.append(f'c{i}') + return col_list + + def genIncreaseValue(self, input_value): + ''' + add ', 1' to end of value every loop + ''' + value_list = list(input_value) + value_list.insert(-1, ", 1") + return ''.join(value_list) + + def insertAlter(self): + ''' + after each alter and insert, when execute 'select * from {tbname};' taosd will coredump + ''' + tbname = ''.join(random.choice(string.ascii_letters.lower()) for i in range(7)) + input_value = '(now, 1)' + tdSql.execute(f'create table {tbname} (ts timestamp, c0 int);') + tdSql.execute(f'insert into {tbname} values {input_value};') + for col in self.genColList(): + input_value = self.genIncreaseValue(input_value) + tdSql.execute(f'alter table {tbname} add column {col} int;') + tdSql.execute(f'insert into {tbname} values {input_value};') + tdSql.query(f'select * from {tbname};') + tdSql.checkRows(18) + + def run(self): + tdSql.prepare() + self.insertAlter() + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/crash_gen/valgrind_taos.supp b/tests/pytest/crash_gen/valgrind_taos.supp index b9296f008e97d0ebcf8498a29b4ebedc2313cf84..ec44a85d5b29c0471db64b0362126804ae73adec 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 +} diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index 841395210cf6f03a7f23932d712375c1db033741..137069e6b634195002f20dc0709db72fef5670a0 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -386,6 +386,7 @@ python3 ./test.py -f query/querySession.py python3 test.py -f alter/alter_create_exception.py python3 ./test.py -f insert/flushwhiledrop.py python3 ./test.py -f insert/schemalessInsert.py +python3 ./test.py -f alter/alterColMultiTimes.py #======================p4-end=============== diff --git a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py index f069bb8f7030dbd8d4eec8c9c741d246f261671b..643886f434d7694f55dce193e5cc2566a4347d3e 100644 --- a/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py +++ b/tests/pytest/tools/taosdemoAllTest/NanoTestCase/taosdemoTestSupportNanoInsert.py @@ -47,7 +47,6 @@ class TDTestCase: else: tdLog.info("taosd found in %s" % buildPath) binPath = buildPath + "/build/bin/" - # insert: create one or mutiple tables per sql and insert multiple rows per sql # insert data from a special timestamp # check stable stb0 @@ -90,7 +89,6 @@ class TDTestCase: os.system( "%staosdemo -f tools/taosdemoAllTest/NanoTestCase/taosdemoTestNanoDatabaseNow.json -y " % binPath) - tdSql.execute("use nsdb2") tdSql.query("show stables") tdSql.checkData(0, 4, 100) diff --git a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py index 393ced14fddcc1b1eb7374ce5fb730aea5975f29..da02f45fa1141a028cfc305bae9babb1856ccb40 100644 --- a/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py +++ b/tests/pytest/tools/taosdemoAllTest/taosdemoTestSupportNanosubscribe.py @@ -103,7 +103,6 @@ class TDTestCase: os.system("cat subscribe_res0.txt* > all_subscribe_res0.txt") subTimes0 = self.subTimes("all_subscribe_res0.txt") - print("pass") self.assertCheck("all_subscribe_res0.txt",subTimes0 ,202) diff --git a/tests/script/general/parser/fill.sim b/tests/script/general/parser/fill.sim index d109dd50f7c0ba0684295dbf093ba1b280e04fce..3413a0b59652550701b7220e3c8cc1fc90785b91 100644 --- a/tests/script/general/parser/fill.sim +++ b/tests/script/general/parser/fill.sim @@ -1050,6 +1050,27 @@ sql_error select min(c3) from m_fl_mt0 interval(10w) fill(value, 20) sql_error select max(c3) from m_fl_mt0 interval(1n) fill(prev) sql_error select min(c3) from m_fl_mt0 interval(1y) fill(value, 20) +sql create table nexttb1 (ts timestamp, f1 int); +sql insert into nexttb1 values ('2021-08-08 1:1:1', NULL); +sql insert into nexttb1 values ('2021-08-08 1:1:5', 3); + +sql select last(*) from nexttb1 where ts >= '2021-08-08 1:1:1' and ts < '2021-08-08 1:1:10' interval(1s) fill(next); +if $rows != 9 then + return -1 +endi +if $data00 != @21-08-08 01:01:01.000@ then + return -1 +endi +if $data01 != @21-08-08 01:01:01.000@ then + return -1 +endi +if $data02 != 3 then + return -1 +endi + + + + print =============== clear #sql drop database $db #sql show databases @@ -1057,4 +1078,4 @@ print =============== clear # 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 diff --git a/tests/script/general/parser/function.sim b/tests/script/general/parser/function.sim index 5edadad3a6686ad8fafee6d24e741bb63622c20e..0c93fe919a8f8d934017135ecf1d3cff4515a3e1 100644 --- a/tests/script/general/parser/function.sim +++ b/tests/script/general/parser/function.sim @@ -1148,3 +1148,21 @@ endi sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s)); + +sql create table smeters (ts timestamp, current float, voltage int); +sql insert into smeters values ('2021-08-08 10:10:10', 10, 1); +sql insert into smeters values ('2021-08-08 10:10:12', 10, 2); + +sql select stddev(voltage) from smeters where ts>='2021-08-08 10:10:10.000' and ts < '2021-08-08 10:10:20.000' and current=10 interval(1000a); +if $rows != 2 then + return -1 +endi +if $data00 != @21-08-08 10:10:10.000@ then + return -1 +endi +if $data10 != @21-08-08 10:10:12.000@ then + return -1 +endi + + + diff --git a/tests/script/general/parser/interp.sim b/tests/script/general/parser/interp.sim index 3fb91e36c66985d90776b33b89607fa9a272d500..55c5701985e8968a88891e4b11415136f48ed346 100644 --- a/tests/script/general/parser/interp.sim +++ b/tests/script/general/parser/interp.sim @@ -55,6 +55,9 @@ while $i < $halfNum endw print ====== tables created +sql create table ap1 (ts timestamp, pav float); +sql INSERT INTO ap1 VALUES ('2021-07-25 02:19:54.100',1) ('2021-07-25 02:19:54.200',2) ('2021-07-25 02:19:54.300',3) ('2021-07-25 02:19:56.500',4) ('2021-07-25 02:19:57.500',5) ('2021-07-25 02:19:57.600',6) ('2021-07-25 02:19:57.900',7) ('2021-07-25 02:19:58.100',8) ('2021-07-25 02:19:58.300',9) ('2021-07-25 02:19:59.100',10) ('2021-07-25 02:19:59.300',11) ('2021-07-25 02:19:59.500',12) ('2021-07-25 02:19:59.700',13) ('2021-07-25 02:19:59.900',14) ('2021-07-25 02:20:05.000', 20) ('2021-07-25 02:25:00.000', 10000); + run general/parser/interp_test.sim print ================== restart server to commit data into disk @@ -65,4 +68,4 @@ print ================== server restart completed run general/parser/interp_test.sim -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 diff --git a/tests/script/general/parser/interp_test.sim b/tests/script/general/parser/interp_test.sim index 81a77995fb828db00b65d085e0839e3b652385e0..845afb0173685bf609897646eb188d689be6df10 100644 --- a/tests/script/general/parser/interp_test.sim +++ b/tests/script/general/parser/interp_test.sim @@ -927,4 +927,1323 @@ endi if $data44 != @18-11-25 19:06:00.000@ then return -1 -endi \ No newline at end of file +endi + + + + + + + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' interval(1s) fill(linear); +if $rows != 6 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' interval(1s) fill(value, 1); +if $rows != 6 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 1.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 1.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 1.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 1.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 1.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' interval(1s) fill(NULL); +if $rows != 6 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != NULL then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != NULL then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != NULL then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' interval(1s) fill(prev); +if $rows != 6 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:00' interval(1s) fill(next); +if $rows != 6 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi + + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' interval(1s) fill(linear); +if $rows != 0 then + return -1 +endi +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' interval(1s) fill(prev); +if $rows != 2 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:56' interval(1s) fill(next); +if $rows != 2 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' interval(1s) fill(linear); +if $rows != 3 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' interval(1s) fill(prev); +if $rows != 3 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:19:57' interval(1s) fill(next); +if $rows != 3 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' interval(1s) fill(linear); +if $rows != 10 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != NULL then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' interval(1s) fill(prev); +if $rows != 10 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 14.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 14.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 14.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:03' interval(1s) fill(next); +if $rows != 10 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != NULL then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != NULL then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != NULL then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != NULL then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' interval(1s) fill(linear); +if $rows != 12 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.11765 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 15.29412 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' interval(1s) fill(prev); +if $rows != 12 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 14.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 14.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 14.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:05' interval(1s) fill(next); +if $rows != 12 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 20.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 20.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 20.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 20.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:20:02' and ts<='2021-07-25 02:20:05' interval(1s) fill(value, 1); +if $rows != 4 then + return -1 +endi +if $data00 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data11 != 1.00000 then + return -1 +endi +if $data20 != @21-07-25 02:20:04.000@ then + return -1 +endi +if $data21 != 1.00000 then + return -1 +endi +if $data30 != @21-07-25 02:20:05.000@ then + return -1 +endi +if $data31 != 20.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:20:02' and ts<='2021-07-25 02:20:05' interval(1s) fill(null); +if $rows != 4 then + return -1 +endi +if $data00 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data11 != NULL then + return -1 +endi +if $data20 != @21-07-25 02:20:04.000@ then + return -1 +endi +if $data21 != NULL then + return -1 +endi +if $data30 != @21-07-25 02:20:05.000@ then + return -1 +endi +if $data31 != 20.00000 then + return -1 +endi + + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' interval(1s) fill(linear); +if $rows != 32 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.11765 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 15.29412 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' interval(1s) fill(prev); +if $rows != 32 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 14.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 14.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 14.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:20:25' interval(1s) fill(next); +if $rows != 32 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 20.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 20.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 20.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 20.00000 then + return -1 +endi + + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' interval(1s) fill(linear); +if $rows != 307 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.11765 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 15.29412 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' interval(1s) fill(prev); +if $rows != 307 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 14.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 14.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 14.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 02:25:00' interval(1s) fill(next); +if $rows != 307 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 20.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 20.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 20.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 20.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' interval(1s) fill(linear); +if $rows != 3907 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.31818 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.77273 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.50000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.50000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.87500 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.11765 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 15.29412 then + return -1 +endi + + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' interval(1s) fill(prev); +if $rows != 3907 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != NULL then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 3.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 3.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 4.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 7.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 9.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 14.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 14.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 14.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 14.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<='2021-07-25 03:25:00' interval(1s) fill(next); +if $rows != 3907 then + return -1 +endi +if $data00 != @21-07-25 02:19:54.000@ then + return -1 +endi +if $data01 != 1.00000 then + return -1 +endi +if $data10 != @21-07-25 02:19:55.000@ then + return -1 +endi +if $data11 != 4.00000 then + return -1 +endi +if $data20 != @21-07-25 02:19:56.000@ then + return -1 +endi +if $data21 != 4.00000 then + return -1 +endi +if $data30 != @21-07-25 02:19:57.000@ then + return -1 +endi +if $data31 != 5.00000 then + return -1 +endi +if $data40 != @21-07-25 02:19:58.000@ then + return -1 +endi +if $data41 != 8.00000 then + return -1 +endi +if $data50 != @21-07-25 02:19:59.000@ then + return -1 +endi +if $data51 != 10.00000 then + return -1 +endi +if $data60 != @21-07-25 02:20:00.000@ then + return -1 +endi +if $data61 != 20.00000 then + return -1 +endi +if $data70 != @21-07-25 02:20:01.000@ then + return -1 +endi +if $data71 != 20.00000 then + return -1 +endi +if $data80 != @21-07-25 02:20:02.000@ then + return -1 +endi +if $data81 != 20.00000 then + return -1 +endi +if $data90 != @21-07-25 02:20:03.000@ then + return -1 +endi +if $data91 != 20.00000 then + return -1 +endi + +sql select interp(pav) from ap1 where ts> '2021-07-25 02:19:54' and ts<'2021-07-25 02:20:07' interval(1s); +if $rows != 1 then + return -1 +endi +if $data00 != @21-07-25 02:20:05.000@ then + return -1 +endi +if $data01 != 20.00000 then + return -1 +endi +