未验证 提交 f738c547 编写于 作者: D dapan1121 提交者: GitHub

Merge pull request #7998 from taosdata/feature/szhou/csum-sample-mavg

[TD-5513]<feature>:cumulative sum/moving average/sample function
......@@ -149,6 +149,7 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
bool tscIsPointInterpQuery(SQueryInfo* pQueryInfo);
bool tscIsTWAQuery(SQueryInfo* pQueryInfo);
bool tscIsIrateQuery(SQueryInfo* pQueryInfo);
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId);
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo);
bool tscIsSecondStageQuery(SQueryInfo* pQueryInfo);
......@@ -165,7 +166,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo);
bool tscNonOrderedProjectionQueryOnSTable(SQueryInfo *pQueryInfo, int32_t tableIndex);
bool tscOrderedProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo);
bool tscIsDiffDerivLikeQuery(SQueryInfo* pQueryInfo);
bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex);
bool tscIsProjectionQuery(SQueryInfo* pQueryInfo);
......
......@@ -648,7 +648,8 @@ static void doExecuteFinalMerge(SOperatorInfo* pOperator, int32_t numOfExpr, SSD
for(int32_t j = 0; j < numOfExpr; ++j) {
pCtx[j].pOutput += (pCtx[j].outputBytes * numOfRows);
if (pCtx[j].functionId == TSDB_FUNC_TOP || pCtx[j].functionId == TSDB_FUNC_BOTTOM) {
if (pCtx[j].functionId == TSDB_FUNC_TOP || pCtx[j].functionId == TSDB_FUNC_BOTTOM ||
pCtx[j].functionId == TSDB_FUNC_SAMPLE) {
if(j > 0) pCtx[j].ptsOutputBuf = pCtx[j - 1].pOutput;
}
}
......
......@@ -2499,6 +2499,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_MAX:
case TSDB_FUNC_DIFF:
case TSDB_FUNC_DERIVATIVE:
case TSDB_FUNC_CSUM:
case TSDB_FUNC_CEIL:
case TSDB_FUNC_FLOOR:
case TSDB_FUNC_ROUND:
......@@ -2551,7 +2552,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// set the first column ts for diff query
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE || functionId == TSDB_FUNC_CSUM) {
SColumnIndex indexTS = {.tableIndex = index.tableIndex, .columnIndex = 0};
SExprInfo* pExpr = tscExprAppend(pQueryInfo, TSDB_FUNC_TS_DUMMY, &indexTS, TSDB_DATA_TYPE_TIMESTAMP,
TSDB_KEYSIZE, getNewResColId(pCmd), TSDB_KEYSIZE, false);
......@@ -2591,7 +2592,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tickPerSec /= TSDB_TICK_PER_SECOND(TSDB_TIME_PRECISION_MICRO);
} else if (info.precision == TSDB_TIME_PRECISION_MICRO) {
tickPerSec /= TSDB_TICK_PER_SECOND(TSDB_TIME_PRECISION_MILLI);
}
}
if (tickPerSec <= 0 || tickPerSec < TSDB_TICK_PER_SECOND(info.precision)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg10);
......@@ -2747,6 +2748,8 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
case TSDB_FUNC_TOP:
case TSDB_FUNC_BOTTOM:
case TSDB_FUNC_MAVG:
case TSDB_FUNC_SAMPLE:
case TSDB_FUNC_PERCT:
case TSDB_FUNC_APERCT: {
// 1. valid the number of parameters
......@@ -2778,7 +2781,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
}
// 2. valid the column type
if (!IS_NUMERIC_TYPE(pSchema->type)) {
if (functionId != TSDB_FUNC_SAMPLE && !IS_NUMERIC_TYPE(pSchema->type)) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
......@@ -2817,11 +2820,38 @@ 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) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12);
}
// todo REFACTOR
// set the first column ts for top/bottom query
int32_t tsFuncId = (functionId == TSDB_FUNC_MAVG) ? TSDB_FUNC_TS_DUMMY : TSDB_FUNC_TS;
SColumnIndex index1 = {index.tableIndex, PRIMARYKEY_TIMESTAMP_COL_INDEX};
pExpr = tscExprAppend(pQueryInfo, tsFuncId, &index1, TSDB_DATA_TYPE_TIMESTAMP, TSDB_KEYSIZE, getNewResColId(pCmd),
0, false);
tstrncpy(pExpr->base.aliasName, aAggs[tsFuncId].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[tsFuncId].name, pExpr);
colIndex += 1; // the first column is ts
getResultDataInfo(pSchema->type, pSchema->bytes, functionId, (int32_t)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);
int64_t nTop = GET_INT32_VAL(val);
if (nTop <= 0 || nTop > 100) { // todo use macro
int64_t numRowsSelected = GET_INT32_VAL(val);
if (numRowsSelected <= 0 || numRowsSelected > 100) { // todo use macro
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg12);
}
......@@ -3314,7 +3344,8 @@ int32_t tscTansformFuncForSTableQuery(SQueryInfo* pQueryInfo) {
if ((functionId >= TSDB_FUNC_SUM && functionId <= TSDB_FUNC_TWA) ||
(functionId >= TSDB_FUNC_FIRST_DST && functionId <= TSDB_FUNC_STDDEV_DST) ||
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_IRATE)) {
(functionId >= TSDB_FUNC_RATE && functionId <= TSDB_FUNC_IRATE) ||
(functionId == TSDB_FUNC_SAMPLE)) {
if (getResultDataInfo(pSrcSchema->type, pSrcSchema->bytes, functionId, (int32_t)pExpr->base.param[0].i64, &type, &bytes,
&interBytes, 0, true, NULL) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
......@@ -3369,8 +3400,8 @@ void tscRestoreFuncForSTableQuery(SQueryInfo* pQueryInfo) {
}
bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
const char* msg1 = "TWA/Diff/Derivative/Irate are not allowed to apply to super table directly";
const char* msg2 = "TWA/Diff/Derivative/Irate only support group by tbname for super table query";
const char* msg1 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE are not allowed to apply to super table directly";
const char* msg2 = "TWA/Diff/Derivative/Irate/CSUM/MAVG/SAMPLE only support group by tbname for super table query";
const char* msg3 = "functions not support for super table query";
// filter sql function not supported by metric query yet.
......@@ -3387,7 +3418,8 @@ bool hasUnsupportFunctionsForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo)
}
}
if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo)) {
if (tscIsTWAQuery(pQueryInfo) || tscIsDiffDerivLikeQuery(pQueryInfo) || tscIsIrateQuery(pQueryInfo) ||
tscQueryContainsFunction(pQueryInfo, TSDB_FUNC_SAMPLE)) {
if (pQueryInfo->groupbyExpr.numOfGroupCols == 0) {
invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg1);
return true;
......@@ -5446,7 +5478,7 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
const char* msg1 = "value is expected";
const char* msg2 = "invalid fill option";
const char* msg3 = "top/bottom not support fill";
const char* msg3 = "top/bottom/sample not support fill";
const char* msg4 = "illegal value or data overflow";
const char* msg5 = "fill only available for interval query";
const char* msg6 = "not supported function now";
......@@ -5554,7 +5586,8 @@ int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNo
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
for(int32_t i = 0; i < numOfExprs; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr->base.functionId == TSDB_FUNC_TOP || pExpr->base.functionId == TSDB_FUNC_BOTTOM) {
if (pExpr->base.functionId == TSDB_FUNC_TOP || pExpr->base.functionId == TSDB_FUNC_BOTTOM
|| pExpr->base.functionId == TSDB_FUNC_SAMPLE) {
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg3);
}
}
......@@ -6284,7 +6317,9 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
}
int32_t f = pExpr->base.functionId;
if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) || f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE ||
if ((f == TSDB_FUNC_PRJ && pExpr->base.numOfParams == 0) ||
f == TSDB_FUNC_DIFF || f == TSDB_FUNC_ARITHM || f == TSDB_FUNC_DERIVATIVE ||
f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG ||
f == TSDB_FUNC_CEIL || f == TSDB_FUNC_FLOOR || f == TSDB_FUNC_ROUND)
{
isProjectionFunction = true;
......@@ -7025,7 +7060,7 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
if (TSDB_COL_IS_TAG(pColIndex->flag)) {
int32_t f = TSDB_FUNC_TAG;
if (tscIsDiffDerivQuery(pQueryInfo)) {
if (tscIsDiffDerivLikeQuery(pQueryInfo)) {
f = TSDB_FUNC_TAGPRJ;
}
......@@ -7170,6 +7205,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
}
if (IS_MULTIOUTPUT(aAggs[f].status) && f != TSDB_FUNC_TOP && f != TSDB_FUNC_BOTTOM && f != TSDB_FUNC_DIFF &&
f != TSDB_FUNC_MAVG && f != TSDB_FUNC_CSUM && f != TSDB_FUNC_SAMPLE &&
f != TSDB_FUNC_DERIVATIVE && f != TSDB_FUNC_TAGPRJ && f != TSDB_FUNC_PRJ) {
return invalidOperationMsg(msg, msg1);
}
......@@ -7188,7 +7224,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, char*
}
// projection query on super table does not compatible with "group by" syntax
if (tscIsProjectionQuery(pQueryInfo) && !(tscIsDiffDerivQuery(pQueryInfo))) {
if (tscIsProjectionQuery(pQueryInfo) && !(tscIsDiffDerivLikeQuery(pQueryInfo))) {
return invalidOperationMsg(msg, msg3);
}
......
......@@ -271,6 +271,8 @@ bool tscIsProjectionQueryOnSTable(SQueryInfo* pQueryInfo, int32_t tableIndex) {
functionId != TSDB_FUNC_TS_COMP &&
functionId != TSDB_FUNC_DIFF &&
functionId != TSDB_FUNC_DERIVATIVE &&
functionId != TSDB_FUNC_MAVG &&
functionId != TSDB_FUNC_CSUM &&
functionId != TSDB_FUNC_TS_DUMMY &&
functionId != TSDB_FUNC_TID_TAG &&
functionId != TSDB_FUNC_CEIL &&
......@@ -321,7 +323,9 @@ bool tscIsProjectionQuery(SQueryInfo* pQueryInfo) {
return true;
}
bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo) {
// these functions diff/derivative/csum/mavg will return the result computed on current row and history row/rows
// as the result for current row
bool tscIsDiffDerivLikeQuery(SQueryInfo* pQueryInfo) {
size_t size = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < size; ++i) {
......@@ -330,7 +334,8 @@ bool tscIsDiffDerivQuery(SQueryInfo* pQueryInfo) {
continue;
}
if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE) {
if (f == TSDB_FUNC_DIFF || f == TSDB_FUNC_DERIVATIVE ||
f == TSDB_FUNC_CSUM || f == TSDB_FUNC_MAVG) {
return true;
}
}
......@@ -551,6 +556,22 @@ bool tscIsIrateQuery(SQueryInfo* pQueryInfo) {
return false;
}
bool tscQueryContainsFunction(SQueryInfo* pQueryInfo, int16_t functionId) {
size_t numOfExprs = tscNumOfExprs(pQueryInfo);
for (int32_t i = 0; i < numOfExprs; ++i) {
SExprInfo* pExpr = tscExprGet(pQueryInfo, i);
if (pExpr == NULL) {
continue;
}
if (pExpr->base.functionId == functionId) {
return true;
}
}
return false;
}
bool tscIsSessionWindowQuery(SQueryInfo* pQueryInfo) {
return pQueryInfo->sessionWindow.gap > 0;
}
......@@ -589,7 +610,7 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
return false;
}
if (tscIsDiffDerivQuery(pQueryInfo)) {
if (tscIsDiffDerivLikeQuery(pQueryInfo)) {
return false;
}
......@@ -615,7 +636,9 @@ bool isSimpleAggregateRv(SQueryInfo* pQueryInfo) {
}
if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) ||
(functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_TS_COMP)) {
(functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_TS_COMP ||
functionId == TSDB_FUNC_SAMPLE)) {
return true;
}
}
......@@ -4836,7 +4859,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
pQueryAttr->hasTagResults = hasTagValOutput(pQueryInfo);
pQueryAttr->stabledev = isStabledev(pQueryInfo);
pQueryAttr->tsCompQuery = isTsCompQuery(pQueryInfo);
pQueryAttr->diffQuery = tscIsDiffDerivQuery(pQueryInfo);
pQueryAttr->diffQuery = tscIsDiffDerivLikeQuery(pQueryInfo);
pQueryAttr->simpleAgg = isSimpleAggregateRv(pQueryInfo);
pQueryAttr->needReverseScan = tscNeedReverseScan(pQueryInfo);
pQueryAttr->stableQuery = QUERY_IS_STABLE_QUERY(pQueryInfo->type);
......
......@@ -68,18 +68,23 @@ extern "C" {
#define TSDB_FUNC_IRATE 30
#define TSDB_FUNC_TID_TAG 31
#define TSDB_FUNC_DERIVATIVE 32
#define TSDB_FUNC_BLKINFO 33
#define TSDB_FUNC_CEIL 34
#define TSDB_FUNC_FLOOR 35
#define TSDB_FUNC_ROUND 36
#define TSDB_FUNC_HISTOGRAM 37
#define TSDB_FUNC_HLL 38
#define TSDB_FUNC_MODE 39
#define TSDB_FUNC_SAMPLE 40
#define TSDB_FUNC_MAVG 41
#define TSDB_FUNC_CSUM 42
#define TSDB_FUNC_CEIL 33
#define TSDB_FUNC_FLOOR 34
#define TSDB_FUNC_ROUND 35
#define TSDB_FUNC_CSUM 36
#define TSDB_FUNC_MAVG 37
#define TSDB_FUNC_SAMPLE 38
#define TSDB_FUNC_BLKINFO 39
///////////////////////////////////////////
// the following functions is not implemented.
// after implementation, move them before TSDB_FUNC_BLKINFO. also make TSDB_FUNC_BLKINFO the maxium function index
// #define TSDB_FUNC_HISTOGRAM 40
// #define TSDB_FUNC_HLL 41
// #define TSDB_FUNC_MODE 42
#define TSDB_FUNCSTATE_SO 0x1u // single output
#define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM
......
此差异已折叠。
......@@ -2060,7 +2060,7 @@ static SQLFunctionCtx* createSQLFunctionCtx(SQueryRuntimeEnv* pRuntimeEnv, SExpr
int32_t functionId = pCtx->functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) {
int32_t f = pExpr[0].base.functionId;
int32_t f = pExpr[i-1].base.functionId;
assert(f == TSDB_FUNC_TS || f == TSDB_FUNC_TS_DUMMY);
pCtx->param[2].i64 = pQueryAttr->order.order;
......@@ -3653,7 +3653,8 @@ void setDefaultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SOptrBasicInfo *pInfo, i
// set the timestamp output buffer for top/bottom/diff query
int32_t fid = pCtx[i].functionId;
if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE) {
if (fid == TSDB_FUNC_TOP || fid == TSDB_FUNC_BOTTOM || fid == TSDB_FUNC_DIFF || fid == TSDB_FUNC_DERIVATIVE ||
fid == TSDB_FUNC_SAMPLE || fid == TSDB_FUNC_MAVG || fid == TSDB_FUNC_CSUM) {
if (i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
}
......@@ -3690,7 +3691,10 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t *bufCapacity, int32_t numOf
// set the correct pointer after the memory buffer reallocated.
int32_t functionId = pBInfo->pCtx[i].functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG ||
functionId == TSDB_FUNC_SAMPLE ) {
if (i > 0) pBInfo->pCtx[i].ptsOutputBuf = pBInfo->pCtx[i-1].pOutput;
}
}
......@@ -3702,7 +3706,9 @@ void copyTsColoum(SSDataBlock* pRes, SQLFunctionCtx* pCtx, int32_t numOfOutput)
char *src = NULL;
for (int32_t i = 0; i < numOfOutput; i++) {
int32_t functionId = pCtx[i].functionId;
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_CSUM ||
functionId == TSDB_FUNC_SAMPLE) {
needCopyTs = true;
if (i > 0 && pCtx[i-1].functionId == TSDB_FUNC_TS_DUMMY){
SColumnInfoData* pColRes = taosArrayGet(pRes->pDataBlock, i - 1); // find ts data
......@@ -3918,7 +3924,8 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
continue;
}
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF ||
functionId == TSDB_FUNC_CSUM || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_SAMPLE) {
if(i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
......@@ -3979,7 +3986,9 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
offset += pCtx[i].outputBytes;
int32_t functionId = pCtx[i].functionId;
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM || functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE) {
if (functionId == TSDB_FUNC_TOP || functionId == TSDB_FUNC_BOTTOM ||
functionId == TSDB_FUNC_DIFF || functionId == TSDB_FUNC_DERIVATIVE ||
functionId == TSDB_FUNC_SAMPLE || functionId == TSDB_FUNC_MAVG || functionId == TSDB_FUNC_CSUM) {
if(i > 0) pCtx[i].ptsOutputBuf = pCtx[i-1].pOutput;
}
......@@ -7922,7 +7931,7 @@ static int32_t updateOutputBufForTopBotQuery(SQueriedTableInfo* pTableInfo, SCol
for (int32_t i = 0; i < numOfOutput; ++i) {
int16_t functId = pExprs[i].base.functionId;
if (functId == TSDB_FUNC_TOP || functId == TSDB_FUNC_BOTTOM) {
if (functId == TSDB_FUNC_TOP || functId == TSDB_FUNC_BOTTOM || functId == TSDB_FUNC_SAMPLE) {
int32_t j = getColumnIndexInSource(pTableInfo, &pExprs[i].base, pTagCols);
if (j < 0 || j >= pTableInfo->numOfCols) {
return TSDB_CODE_QRY_INVALID_MSG;
......
......@@ -33,7 +33,9 @@ typedef struct 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) {
if (pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_TOP ||
pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_BOTTOM ||
pQueryAttr->pExpr1[i].base.functionId == TSDB_FUNC_SAMPLE) {
return (int32_t)pQueryAttr->pExpr1[i].base.param[0].i64;
}
}
......
......@@ -345,6 +345,7 @@ python3 ./test.py -f functions/function_spread.py -r 1
python3 ./test.py -f functions/function_stddev.py -r 1
python3 ./test.py -f functions/function_sum.py -r 1
python3 ./test.py -f functions/function_top.py -r 1
python3 ./test.py -f functions/function_sample.py -r 1
python3 ./test.py -f functions/function_twa.py -r 1
python3 ./test.py -f functions/function_twa_test2.py
python3 ./test.py -f functions/function_stddev_td2555.py
......
###################################################################
# 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 sys
import taos
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np
import collections
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.rowNum = 10
self.sample_times = 10000
self.ts = 1537146000000
def run(self):
tdSql.prepare()
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
tdSql.execute("create table test1 using test tags('beijing')")
for i in range(self.rowNum):
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
% (self.ts + i, i, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
print("begin sampling. sql: select sample(col1, 2) from test1")
freqDict = collections.defaultdict(int)
for i in range(self.sample_times):
tdSql.query('select sample(col1, 2) from test1')
res1 = tdSql.getData(0, 1);
res2 = tdSql.getData(1, 1);
freqDict[res1] = freqDict[res1] + 1
freqDict[res2] = freqDict[res2] + 1
print("end sampling.")
lower_bound = self.sample_times/5 - self.sample_times/50;
upper_bound = self.sample_times/5 + self.sample_times/50;
for i in range(self.rowNum):
print("{} are sampled in {} times".format(i, freqDict[i]))
if not (freqDict[i]>=lower_bound and freqDict[i]<=upper_bound):
print("run it aggain. if it keeps appearing, sample function bug")
caller = inspect.getframeinfo(inspect.stack()[0][0])
args = (caller.filename, caller.lineno-2)
tdLog.exit("{}({}) failed. sample function failure".format(args[0], args[1]))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
###################################################################
# 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 sys
import taos
from util.log import *
from util.cases import *
from util.sql import *
import numpy as np
import collections
class TDTestCase:
def init(self, conn, logSql):
tdLog.debug("start to execute %s" % __file__)
tdSql.init(conn.cursor())
self.rowNum = 10
self.sample_times = 10000
self.ts = 1537146000000
def run(self):
tdSql.prepare()
tdSql.execute('''create table test(ts timestamp, col1 tinyint, col2 smallint, col3 int, col4 bigint, col5 float, col6 double,
col7 bool, col8 binary(20), col9 nchar(20), col11 tinyint unsigned, col12 smallint unsigned, col13 int unsigned, col14 bigint unsigned) tags(loc nchar(20))''')
tdSql.execute("create table test1 using test tags('beijing')")
for i in range(self.rowNum):
tdSql.execute("insert into test1 values(%d, %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', %d, %d, %d, %d)"
% (self.ts + i, i, i + 1, i + 1, i + 1, i + 0.1, i + 0.1, i % 2, i + 1, i + 1, i + 1, i + 1, i + 1, i + 1))
print("begin sampling. sql: select sample(col1, 2) from test1")
freqDict = collections.defaultdict(int)
for i in range(self.sample_times):
tdSql.query('select sample(col1, 2) from test1')
res1 = tdSql.getData(0, 1);
res2 = tdSql.getData(1, 1);
freqDict[res1] = freqDict[res1] + 1
freqDict[res2] = freqDict[res2] + 1
print("end sampling.")
lower_bound = self.sample_times/5 - self.sample_times/50;
upper_bound = self.sample_times/5 + self.sample_times/50;
for i in range(self.rowNum):
print("{} are sampled in {} times".format(i, freqDict[i]))
if not (freqDict[i]>=lower_bound and freqDict[i]<=upper_bound):
print("run it aggain. if it keeps appearing, sample function bug")
caller = inspect.getframeinfo(inspect.stack()[0][0])
args = (caller.filename, caller.lineno-2)
tdLog.exit("{}({}) failed. sample function failure".format(args[0], args[1]))
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
tdCases.addWindows(__file__, TDTestCase())
tdCases.addLinux(__file__, TDTestCase())
......@@ -21,6 +21,10 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select csum(tbcol) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) from $tb where ts > $ms
print ===> $data11
if $data11 != 11 then
return -1
endi
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) from $tb where ts <= $ms
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step4
sql select csum(tbcol) as b from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
print =============== step5
sql select csum(tbcol) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select csum(tbcol) as b from $tb where ts <= $ms interval(1m) -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 2
$rowNum = 1000
$totalNum = 2000
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 nchar(5), c9 binary(10)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
$tinyint = $x / 128
sql insert into $tb values ($ms , $x , $x , $x , $x , $tinyint , $x , $x , $x , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select csum(c1) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c2) from $tb
print ===> $data11
if $data11 != 1.000000000 then
return -1
endi
sql select csum(c3) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c4) from $tb
print ===> $data11
if $data11 != 1 then
return -1
endi
sql select csum(c5) from $tb
print ===> $data11
if $data11 != 0 then
return -1
endi
sql select csum(c6) from $tb
print ===> $data11
if $data11 != 1.000000000 then
return -1
endi
sql_error select csum(c7) from $tb
sql_error select csum(c8) from $tb
sql_error select csum(c9) from $tb
sql_error select csum(ts) from $tb
sql_error select csum(c1), csum(c2) from $tb
#sql_error select 2+csum(c1) from $tb
sql_error select csum(c1+2) from $tb
sql_error select csum(c1) from $tb where ts > 0 and ts < now + 100m interval(10m)
sql_error select csum(c1) from $mt
sql_error select csum(csum(c1)) from $tb
sql_error select csum(c1) from m_di_tb1 where c2 like '2%'
print =============== step3
sql select csum(c1) from $tb where c1 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c2) from $tb where c2 > 5
print ===> $data11
if $data11 != 13.000000000 then
return -1
endi
sql select csum(c3) from $tb where c3 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c4) from $tb where c4 > 5
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c5) from $tb where c5 > 5
print ===> $data11
if $data11 != 12 then
return -1
endi
sql select csum(c6) from $tb where c6 > 5
print ===> $data11
if $data11 != 13.000000000 then
return -1
endi
print =============== step4
sql select csum(c1) from $tb where c1 > 5 and c2 < $rowNum
print ===> $data11
if $data11 != 13 then
return -1
endi
sql select csum(c1) from $tb where c9 like '%9' and c1 <= 20
print ===> $rows
if $rows != 2 then
return -1
endi
print ===>$data01, $data11
if $data01 != 9 then
return -1
endi
if $data11 != 28 then
return -1
endi
print =============== step5
sql select csum(c1) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
sql select csum(c1) as b from $tb where ts < now + 4m interval(1m) -x step6
return -1
step6:
print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select mavg(tbcol,2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol,2) from $tb where ts > $ms
print ===> $data11
if $data11 != 6.500000000 then
return -1
endi
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol,2) from $tb where ts <= $ms
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step4
sql select mavg(tbcol,2) as b from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
print =============== step5
sql select mavg(tbcol, 2) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select mavg(tbcol, 2) as b from $tb where ts <= $ms interval(1m) -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_di_db
$tbPrefix = m_di_tb
$mtPrefix = m_di_mt
$tbNum = 2
$rowNum = 10000
$totalNum = 20000
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool, c8 nchar(5), c9 binary(10)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
$tinyint = $x / 128
sql insert into $tb values ($ms , $x , $x , $x , $x , $tinyint , $x , $x , $x , $x )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select mavg(c1, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c2, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c3, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c4, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql select mavg(c5, 2) from $tb
print ===> $data11
if $data11 != 0.000000000 then
return -1
endi
sql select mavg(c6, 2) from $tb
print ===> $data11
if $data11 != 1.500000000 then
return -1
endi
sql_error select mavg(c7,2) from $tb
sql_error select mavg(c8,2) from $tb
sql_error select mavg(c9,2) from $tb
sql_error select mavg(ts,2) from $tb
sql_error select mavg(c1,2), mavg(c2,2) from $tb
#sql_error select 2+mavg(c1,2) from $tb
sql_error select mavg(c1+2) from $tb
sql_error select mavg(c1,2) from $tb where ts > 0 and ts < now + 100m interval(10m)
sql_error select mavg(c1,2) from $mt
sql_error select mavg(mavg(c1,2)) from $tb
sql_error select mavg(c1,2) from m_di_tb1 where c2 like '2%'
print =============== step3
sql select mavg(c1,2) from $tb where c1 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c2,2) from $tb where c2 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c3,2) from $tb where c3 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c4,2) from $tb where c4 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c5,2) from $tb where c5 > 5
print ===> $data11
if $data11 != 6.000000000 then
return -1
endi
sql select mavg(c6,2) from $tb where c6 > 5
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
print =============== step4
sql select mavg(c1,2) from $tb where c1 > 5 and c2 < $rowNum
print ===> $data11
if $data11 != 7.500000000 then
return -1
endi
sql select mavg(c1,2) from $tb where c9 like '%9' and c1 <= 20
if $rows != 1 then
return -1
endi
print ===> $data01
if $data01 != 14.000000000 then
return -1
endi
print =============== step5
sql select mavg(c1,2) as b from $tb interval(1m) -x step5
return -1
step5:
print =============== step6
sql select mavg(c1,2) as b from $tb where ts < now + 4m interval(1m) -x step6
return -1
step6:
print =============== clear
#sql drop database $db
#sql show databases
#if $rows != 0 then
# return -1
#endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 1
system sh/exec.sh -n dnode1 -s start
sleep 200
sql connect
$dbPrefix = m_db
$tbPrefix = m_tb
$mtPrefix = m_mt
$tbNum = 10
$rowNum = 20
$totalNum = 200
print =============== step1
$i = 0
$db = $dbPrefix . $i
$mt = $mtPrefix . $i
sql drop database $db -x step1
step1:
sql create database $db
sql use $db
sql create table $mt (ts timestamp, tbcol int, bin binary(43), nch nchar(43)) TAGS(tgcol int)
$i = 0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $mt tags( $i )
$x = 0
while $x < $rowNum
$cc = $x * 60000
$ms = 1601481600000 + $cc
sql insert into $tb values ($ms , $x , 'binary' , 'nchar' )
$x = $x + 1
endw
$i = $i + 1
endw
sleep 100
print =============== step2
$i = 1
$tb = $tbPrefix . $i
sql select sample(tbcol, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 > 19 then
return -1
endi
sql select sample(bin, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 != @binary@ then
return -1
endi
sql select sample(nch, 1) from $tb
if $rows != 1 then
return -1
endi
if $data01 != @nchar@ then
return -1
endi
print =============== step3
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select sample(tbcol, 1) from $tb where ts <= $ms
if $data01 > 4 then
return -1
endi
sql select sample(bin, 1) from $tb where ts <= $ms
if $data01 != @binary@ then
return -1
endi
sql select sample(nch, 1) from $tb where ts <= $ms
if $data01 != @nchar@ then
return -1
endi
print =============== step4
sql select sample(tbcol, 1) as b from $tb
if $data01 > 19 then
return -1
endi
sql select sample(bin, 1) as b from $tb
print =============== step5
sql select sample(tbcol, 2) as b from $tb
if $rows != 2 then
return -1
endi
if $data01 > 19 then
return -1
endi
if $data11 > 19 then
return -1
endi
sql_error select sample(nchar, 2) as b from $tb
sql select sample(nch, 2) as b from $tb
if $rows != 2 then
return -1
endi
print =====> $data01 , $data11
if $data01 != @nchar@ then
return -1
endi
if $data11 != @nchar@ then
return -1
endi
sql select sample(bin, 2) as b from $tb
if $rows != 2 then
return -1
endi
if $data01 != @binary@ then
return -1
endi
if $data11 != @binary@ then
return -1
endi
print =============== step6
$cc = 4 * 60000
$ms = 1601481600000 + $cc
sql select sample(tbcol, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
if $data01 > 4 then
return -1
endi
if $data11 > 4 then
return -1
endi
sql select sample(bin, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
sql select sample(nch, 2) as b from $tb where ts <= $ms
if $rows != 2 then
return -1
endi
sql select sample(tbcol, 1001) as b from $tb -x step6
return -1
step6:
print =============== clear
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -3,6 +3,11 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/sample.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
......@@ -124,8 +124,11 @@ sql select spread(ts )/(1000*3600*24) from $stb interval(1y)
sql_error select first(c1, c2) - last(c1, c2) from $stb interval(1y)
sql_error select first(ts) - last(ts) from $stb interval(1y)
sql_error select top(c1, 2) - last(c1) from $stb;
sql_error select sample(c1, 2) - last(c1) from $stb;
sql_error select stddev(c1) - last(c1) from $stb;
sql_error select diff(c1) - last(c1) from $stb;
sql_error select mavg(c1, 2) - last(c1) from $stb;
sql_error select csum(c1) - last(c1) from $stb;
sql_error select first(c7) - last(c7) from $stb;
sql_error select first(c8) - last(c8) from $stb;
sql_error select first(c9) - last(c9) from $stb;
......@@ -151,4 +154,4 @@ if $data02 != 225000 then
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
......@@ -174,6 +174,9 @@ endi
sql_error select top(c1, 1) - bottom(c1, 1) from $tb
sql_error select top(c1, 99) - bottom(c1, 99) from $tb
sql_error select top(c1,1) - 88 from $tb
sql_error select sample(c1, 1) - bottom(c1, 1) from $tb
sql_error select sample(c1, 99) - bottom(c1, 99) from $tb
sql_error select sample(c1,1) - 88 from $tb
# all data types [d.6] ================================================================
sql select c2-c1*1.1, c3/c2, c4*c3, c5%c4, (c6+c4)%22, c2-c2 from $tb
......@@ -475,11 +478,16 @@ endi
sql_error select first(c1, c2) - last(c1, c2) from $stb
sql_error select top(c1, 5) - bottom(c1, 5) from $stb
sql_error select first(*) - 99 from $stb
sql_error select sample(c1, 5) - bottom(c1, 5) from $stb
# multi row result aggregation [d.4]
sql_error select top(c1, 1) - bottom(c1, 1) from $stb
sql_error select top(c1, 99) - bottom(c1, 99) from $stb
sql_error select sample(c1, 1) - top(c1, 1) from $stb
sql_error select sample(c1, 99) - top(c1, 99) from $stb
# query on super table [d.5]=============================================================
# all cases in this part are query on super table
......
......@@ -1087,6 +1087,14 @@ sql select diff(val) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql select mavg(val,2) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql select csum(val) from (select derivative(k, 1s, 0) val from t1);
if $rows != 0 then
return -1
endi
sql insert into t1 values('2020-1-1 1:1:4', 20);
sql insert into t1 values('2020-1-1 1:1:6', 200);
......
......@@ -121,6 +121,7 @@ if $data31 != 4 then
return -1
endi
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql select last(f1) from st2 group by f1 having count(f2) > 0;
......@@ -140,9 +141,12 @@ if $data30 != 4 then
return -1
endi
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from st2 group by f1 having avg(f1) > 0;
sql select avg(f1),count(f1) from st2 group by f1 having avg(f1) > 2;
if $rows != 2 then
......@@ -1059,6 +1063,13 @@ if $data26 != 4 then
endi
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having sample(f1,1);
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having sample(f1,1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1) from st2 group by f1 having sum(f1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from st2 group by f1 having bottom(f1,1) > 1;
sql_error select avg(f1),count(st2.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from st2 group by f1 having top(f1,1);
......@@ -1149,6 +1160,18 @@ sql_error select avg(f1),diff(f1) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),diff(f1) from st2 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from st2 group by f1 having mavg(f1, 2) > 0;
sql_error select avg(f1),mavg(f1, 3) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),mavg(f1, 4) from st2 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from st2 group by f1 having csum(f1) > 0;
sql_error select avg(f1),csum(f1) from st2 group by f1 having avg(f1) > 0;
sql_error select avg(f1),csum(f1) from st2 group by f1 having spread(f2) > 0;
sql select avg(f1) from st2 group by f1 having spread(f2) > 0;
if $rows != 0 then
return -1
......@@ -1834,6 +1857,7 @@ if $data04 != 1 then
return -1
endi
sql_error select sample(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select top(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select count(*) from tb1 group by f1 having last(*) > 0;
......
......@@ -120,6 +120,7 @@ if $data31 != 4 then
endi
sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql select last(f1) from tb1 group by f1 having count(f2) > 0;
if $rows != 4 then
......@@ -144,6 +145,12 @@ sql_error select top(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from tb1 group by f1 having avg(f1) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f2) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having avg(f1) > 0;
sql select avg(f1),count(f1) from tb1 group by f1 having avg(f1) > 2;
if $rows != 2 then
return -1
......@@ -1067,7 +1074,13 @@ if $data26 != 4 then
return -1
endi
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having sample(f1,1);
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having sample(f1,1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from tb1 group by f1 having bottom(f1,1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1),sample(f1,1),bottom(f1,1) from tb1 group by f1 having sum(f1) > 1;
sql_error select avg(f1),count(tb1.*),sum(f1),stddev(f1),min(f1),max(f1),first(f1),last(f1) from tb1 group by f1 having top(f1,1);
......@@ -1164,6 +1177,20 @@ sql_error select avg(f1),diff(f1) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),diff(f1) from tb1 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from tb1 group by f1 having mavg(f1,4) > 0;
sql_error select avg(f1),mavg(f1,5) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),mavg(f1,6) from tb1 group by f1 having spread(f2) > 0;
sql_error select avg(f1) from tb1 group by f1 having csum(f1) > 0;
sql_error select avg(f1),csum(f1) from tb1 group by f1 having avg(f1) > 0;
sql_error select avg(f1),csum(f1) from tb1 group by f1 having spread(f2) > 0;
sql select avg(f1) from tb1 group by f1 having spread(f2) > 0;
if $rows != 0 then
return -1
......@@ -1857,4 +1884,6 @@ endi
sql_error select top(f1,2) from tb1 group by f1 having count(f1) > 0;
sql_error select sample(f1,2) from tb1 group by f1 having count(f1) > 0;
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -80,4 +80,7 @@ sql use $db
sql select * from (select ts, top(c1, 5) from $tb where ts >= $ts0 order by ts desc limit 3 offset 1)
sql select * from (select ts, top(c1, 5) from $stb where ts >= $ts0 order by ts desc limit 3 offset 1)
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
sql select * from (select ts, sample(c1, 5) from $tb where ts >= $ts0 order by ts desc limit 3 offset 1)
sql_error select * from (select ts, sample(c1, 5) from $stb where ts >= $ts0 order by ts desc limit 3 offset 1)
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -471,6 +471,92 @@ if $data81 != -9 then
return -1
endi
sql select mavg(c1,2) from $tb
$res = $rowNum - 1
if $rows != $res then
return -1
endi
sql select mavg(c1,2) from $tb where c1 > 5 limit 2 offset 1
print $rows , $data00 , $data01 , $data10 , $data11
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data01 != 7.500000000 then
return -1
endi
if $data10 != @18-09-17 10:30:00.000@ then
return -1
endi
if $data11 != 8.500000000 then
return -1
endi
$limit = $rowNum / 2
$offset = $limit - 1
sql select mavg(c1,2) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $limit then
return -1
endi
$limit = $rowNum / 2
$offset = $limit + 1
$val = $limit - 2
sql select mavg(c1,2) from $tb where c1 >= 0 limit $limit offset $offset
print $rows , $data01 , $data81
if $rows != $val then
return -1
endi
if $data01 != 1.500000000 then
return -1
endi
if $data81 != 4.500000000 then
return -1
endi
sql select csum(c1) from $tb
$res = $rowNum
if $rows != $res then
return -1
endi
sql select csum(c1) from $tb where c1 > 5 limit 2 offset 1
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:10:00.000@ then
return -1
endi
if $data01 != 13 then
return -1
endi
if $data10 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data11 != 21 then
return -1
endi
$limit = $rowNum / 2
$offset = $limit - 1
sql select csum(c1) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $limit then
return -1
endi
$limit = $rowNum / 2
$offset = $limit + 1
$val = $limit - 1
sql select csum(c1) from $tb where c1 >= 0 limit $limit offset $offset
if $rows != $val then
return -1
endi
if $data01 != 22501 then
return -1
endi
if $data81 != 22545 then
return -1
endi
### aggregation + limit offset (with interval)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5
if $rows != 5 then
......
......@@ -828,6 +828,8 @@ if $data59 != 4 then
return -1
endi
sql_error select sample(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
sql select top(c1, 1) from $stb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
......
......@@ -355,6 +355,21 @@ sql select top(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
endi
sql select sample(c1, 1) from $tb where ts >= $ts0 and ts <= $tsu limit 5 offset 1
if $rows != 0 then
return -1
endi
sql select * from (select ts, sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1)
sql select ts,sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
if $rows != 3 then
return -1
endi
print select ts,sample(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1
print $data00 $data01 $data02
print $data10 $data11 $data12
print $data20 $data21 $data22
print ========> TD-6017
sql select * from (select ts, top(c1, 5) from $tb where ts >= $ts0 and ts <= $tsu order by ts desc limit 3 offset 1)
......@@ -463,6 +478,35 @@ if $data11 != 1 then
return -1
endi
sql select mavg(c1,3) from $tb where c1 > 5 limit 2 offset 1
print $rows , $data00 , $data01
if $rows != 1 then
return -1
endi
if $data00 != @18-09-17 10:30:00.000@ then
return -1
endi
if $data01 != 8.000000000 then
return -1
endi
sql select csum(c1) from $tb where c1 > 5 limit 2 offset 1
if $rows != 2 then
return -1
endi
if $data00 != @18-09-17 10:10:00.000@ then
return -1
endi
if $data01 != 13 then
return -1
endi
if $data10 != @18-09-17 10:20:00.000@ then
return -1
endi
if $data11 != 21 then
return -1
endi
### aggregation + limit offset (with interval)
sql select max(c1), max(c2), max(c3), max(c4), max(c5), max(c6) from $tb where ts >= $ts0 and ts <= $tsu interval(5m) limit 5
if $rows != 5 then
......
......@@ -186,6 +186,8 @@ sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
sql_error select twa(c1) from (select c1 from nest_tb0);
sql_error select irate(c1) from (select c1 from nest_tb0);
sql_error select diff(c1), twa(c1) from (select * from nest_tb0);
sql_error select mavg(c1,2), twa(c1) from (select * from nest_tb0);
sql_error select csum(c1), twa(c1) from (select * from nest_tb0);
sql_error select irate(c1), interp(c1), twa(c1) from (select * from nest_tb0);
sql select apercentile(c1, 50) from (select * from nest_tb0) interval(1d)
......@@ -273,6 +275,14 @@ sql select diff(c1) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
sql select mavg(c1,2) from (select * from nest_tb0);
if $rows != 9999 then
return -1
endi
sql select csum(c1) from (select * from nest_tb0);
if $rows != 10000 then
return -1
endi
sql select avg(c1),sum(c2), max(c3), min(c4), count(*), first(c7), last(c7),spread(c6) from (select * from nest_tb0) interval(1d);
if $rows != 7 then
......@@ -330,6 +340,8 @@ if $data12 != 71680.000000000 then
return -1
endi
sql select sample(x, 20) from (select c1 x from nest_tb0);
sql select top(x, 20) from (select c1 x from nest_tb0);
sql select bottom(x, 20) from (select c1 x from nest_tb0)
......@@ -420,6 +432,35 @@ if $data01 != 1 then
return -1
endi
sql select mavg(val, 2) from (select c1 val from nest_tb0);
if $rows != 9999 then
return -1
endi
if $data00 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data01 != 0.500000000 then
return -1
endi
sql select csum(val) from (select c1 val from nest_tb0);
if $rows != 10000 then
return -1
endi
if $data00 != @70-01-01 08:00:00.000@ then
return -1
endi
if $data01 != 0 then
return -1
endi
if $data41 != 10 then
return -1
endi
sql_error select last_row(*) from (select * from nest_tb0) having c1 > 0
print ===========>td-4805
......@@ -508,4 +549,4 @@ if $data11 != 2.000000000 then
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
......@@ -296,6 +296,7 @@ sql_error select last(t1) from group_mt0;
sql_error select min(t1) from group_mt0;
sql_error select max(t1) from group_mt0;
sql_error select top(t1, 20) from group_mt0;
sql_error select sample(t1, 20) from group_mt0;
sql_error select bottom(t1, 20) from group_mt0;
sql_error select avg(t1) from group_mt0;
sql_error select percentile(t1, 50) from group_mt0;
......@@ -393,6 +394,25 @@ if $data21 != -1 then
return -1
endi
sql select mavg(k,3) from tm0
print ====> $rows , $data21
if $row != 2 then
return -1
endi
if $data11 != 2.333333333 then
return -1
endi
sql select csum(k) from tm0
print ====> $rows , $data21
if $row != 4 then
return -1
endi
if $data21 != 6 then
return -1
endi
#error sql
sql_error select * from 1;
#sql_error select 1; // equals to select server_status();
......
......@@ -181,6 +181,12 @@ if $data03 != @abc15@ then
return -1
endi
sql_error select sample(c6, 3) from select_tags_mt0 interval(10a)
sql select sample(c3,10) from select_tags_mt0 interval(10a) group by tbname,t1,t2
sql select sample(c6, 3) from select_tags_mt0 interval(10a) group by tbname;
sql_error select sample(c6, 10) from select_tags_mt0 interval(10a);
sql_error select sample(c1, 80), tbname, t1, t2 from select_tags_mt0;
sql select top(c6, 3) from select_tags_mt0 interval(10a)
sql select top(c3,10) from select_tags_mt0 interval(10a) group by tbname,t1,t2
sql select top(c6, 3) from select_tags_mt0 interval(10a) group by tbname;
......@@ -418,6 +424,11 @@ if $data11 != @70-01-01 08:01:40.001@ then
return -1
endi
sql select sample(c1, 100), tbname, t1, t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname;
if $rows != 200 then
return -1
endi
sql select top(c1, 100), tbname, t1, t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname;
if $row != 200 then
return -1
......@@ -455,6 +466,11 @@ if $data04 != @abc0@ then
return -1
endi
sql select sample(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2;
if $rows != 4 then
return -1
endi
sql select top(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2;
if $row != 4 then
return -1
......@@ -542,6 +558,11 @@ endi
# slimit /limit
sql select sample(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2 limit 2 offset 1;
if $rows != 2 then
return -1
endi
sql select top(c1, 2), t2 from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by tbname,t2 limit 2 offset 1;
if $row != 2 then
return -1
......@@ -715,6 +736,11 @@ if $data25 != @select_tags_tb2@ then
return -1
endi
sql select sample(c1, 5), t2 from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 15 then
return -1
endi
sql select top(c1, 5), t2 from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 15 then
return -1
......@@ -753,6 +779,11 @@ if $data93 != @select_tags_tb1@ then
endi
#if data
sql select sample(c1, 50), t2, t1, tbname from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 48 then
return -1
endi
sql select top(c1, 50), t2, t1, tbname from select_tags_mt0 where c1<=2 interval(1d) group by tbname;
if $row != 48 then
return -1
......@@ -838,6 +869,8 @@ endi
print TODO ======= selectivity + tags+ group by + tags + filter + interval + join===========
print ==========================mix tag columns and group by columns======================
sql_error select sample(c1, 100), tbname from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by t3
sql select top(c1, 100), tbname from select_tags_mt0 where tbname in ('select_tags_tb0', 'select_tags_tb1') group by t3
if $rows != 100 then
return -1
......
......@@ -489,6 +489,7 @@ sql_error select ts,sum_double(f1),f1 from tb1;
sql_error select add_one(f1),count(f1) from tb1;
sql_error select sum_double(f1),count(f1) from tb1;
sql_error select add_one(f1),top(f1,3) from tb1;
sql_error select add_one(f1),sample(f1,3) from tb1;
sql_error select add_one(f1) from tb1 interval(10a);
system sh/exec.sh -n dnode1 -s stop -x SIGINT
......@@ -508,6 +508,7 @@ sql_error select ts,sum_double(f1),f1 from tb1;
sql_error select add_one(f1),count(f1) from tb1;
sql_error select sum_double(f1),count(f1) from tb1;
sql_error select add_one(f1),top(f1,3) from tb1;
sql_error select add_one(f1),sample(f1,3) from tb1;
sql_error select add_one(f1) from tb1 interval(10a);
......
......@@ -21,6 +21,11 @@ run general/compute/bottom.sim
run general/compute/count.sim
run general/compute/diff.sim
run general/compute/diff2.sim
run general/compute/mavg.sim
run general/compute/mavg2.sim
run general/compute/sample.sim
run general/compute/csum.sim
run general/compute/csum2.sim
run general/compute/first.sim
run general/compute/interval.sim
run general/compute/last.sim
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册