diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 671b7f1728e6bdadf016732233166f2624f763a1..4442338a7bbc8789f883f7a427687130c50a548f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -51,7 +51,7 @@ #define COLUMN_INDEX_INITIAL_VAL (-2) #define COLUMN_INDEX_INITIALIZER \ { COLUMN_INDEX_INITIAL_VAL, COLUMN_INDEX_INITIAL_VAL } -#define COLUMN_INDEX_VALIDE(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_TBNAME_COLUMN_INDEX)) +#define COLUMN_INDEX_VALID(index) (((index).tableIndex >= 0) && ((index).columnIndex >= TSDB_MIN_VALID_COLUMN_INDEX)) #define TBNAME_LIST_SEP "," typedef struct SColumnList { // todo refactor @@ -98,7 +98,7 @@ static int32_t parseIntervalOffset(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrTo static int32_t parseSlidingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SStrToken* pSliding); static int32_t validateStateWindowNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode, bool isStable); -static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem, bool outerQuery); +static int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem, bool outerQuery, bool timeWindowQuery); static int32_t validateWhereNode(SQueryInfo* pQueryInfo, tSqlExpr** pExpr, SSqlObj* pSql, bool joinQuery); static int32_t validateFillNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SSqlNode* pSqlNode); @@ -2262,7 +2262,7 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS (type == SQL_NODE_EXPR && pItem->pNode->tokenId == TK_ARROW)) { // use the dynamic array list to decide if the function is valid or not // select table_name1.field_name1, table_name2.field_name2 from table_name1, table_name2 - if (addProjectionExprAndResultField(pCmd, pQueryInfo, pItem, outerQuery) != TSDB_CODE_SUCCESS) { + if (addProjectionExprAndResultField(pCmd, pQueryInfo, pItem, outerQuery, timeWindowQuery) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; } } else { @@ -2405,13 +2405,14 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum return numOfTotalColumns; } -int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem, bool outerQuery) { +int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExprItem* pItem, bool outerQuery, bool timeWindowQuery) { const char* msg1 = "tag for normal table query is not allowed"; const char* msg2 = "invalid column name"; - const char* msg3 = "tbname not allowed in outer query"; + const char* msg3 = "tbname/_wstart/_wstop/_wduration in outer query does not match inner query result"; const char* msg4 = "-> operate can only used in json type"; const char* msg5 = "the right value of -> operation must be string"; const char* msg6 = "select name is too long than 64, please use alias name"; + const char* msg7 = "_wstart/_wstop/_wduraion can only be applied to time window query"; int32_t startPos = (int32_t)tscNumOfExprs(pQueryInfo); int32_t tokenId = pItem->pNode->tokenId; @@ -2477,7 +2478,8 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg2); } - if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + //for tbname and other pseudo columns + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX || TSDB_COL_IS_TSWIN_COL(index.columnIndex)) { if (outerQuery) { STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, index.tableIndex); int32_t numOfCols = tscGetNumOfColumns(pTableMetaInfo->pTableMeta); @@ -2485,7 +2487,14 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t bool existed = false; SSchema* pSchema = pTableMetaInfo->pTableMeta->schema; for (int32_t i = 0; i < numOfCols; ++i) { - if (strncasecmp(pSchema[i].name, TSQL_TBNAME_L, tListLen(pSchema[i].name)) == 0) { + if ((strncasecmp(pSchema[i].name, TSQL_TBNAME_L, tListLen(pSchema[i].name)) == 0 && + index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) || + (strncasecmp(pSchema[i].name, TSQL_TSWIN_START, tListLen(pSchema[i].name)) == 0 && + index.columnIndex == TSDB_TSWIN_START_COLUMN_INDEX) || + (strncasecmp(pSchema[i].name, TSQL_TSWIN_STOP, tListLen(pSchema[i].name)) == 0 && + index.columnIndex == TSDB_TSWIN_STOP_COLUMN_INDEX) || + (strncasecmp(pSchema[i].name, TSQL_TSWIN_DURATION, tListLen(pSchema[i].name)) == 0 && + index.columnIndex == TSDB_TSWIN_DURATION_COLUMN_INDEX)) { existed = true; index.columnIndex = i; break; @@ -2504,13 +2513,26 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t /*SExprInfo* pExpr = */ tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_PRJ, &index, &colSchema, TSDB_COL_NORMAL, getNewResColId(pCmd)); } else { - SSchema colSchema = *tGetTbnameColumnSchema(); - char name[TSDB_COL_NAME_LEN] = {0}; + SSchema colSchema; + int16_t functionId, colType; + if (index.columnIndex == TSDB_TBNAME_COLUMN_INDEX) { + colSchema = *tGetTbnameColumnSchema(); + functionId = TSDB_FUNC_TAGPRJ; + colType = TSDB_COL_TAG; + } else { + if (!timeWindowQuery) { + return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); + } + colSchema = *tGetTimeWindowColumnSchema(index.columnIndex); + functionId = getTimeWindowFunctionID(index.columnIndex); + colType = TSDB_COL_NORMAL; + } + char name[TSDB_COL_NAME_LEN] = {0}; getColumnName(pItem, name, colSchema.name, sizeof(colSchema.name) - 1); tstrncpy(colSchema.name, name, TSDB_COL_NAME_LEN); - /*SExprInfo* pExpr = */ tscAddFuncInSelectClause(pQueryInfo, startPos, TSDB_FUNC_TAGPRJ, &index, &colSchema, - TSDB_COL_TAG, getNewResColId(pCmd)); + /*SExprInfo* pExpr = */ tscAddFuncInSelectClause(pQueryInfo, startPos, functionId, &index, &colSchema, + colType, getNewResColId(pCmd)); } pQueryInfo->type |= TSDB_QUERY_TYPE_PROJECTION_QUERY; } else { @@ -3817,6 +3839,25 @@ static bool isTablenameToken(SStrToken* token) { return (tmpToken.n == strlen(TSQL_TBNAME_L) && strncasecmp(TSQL_TBNAME_L, tmpToken.z, tmpToken.n) == 0); } +static bool isTimeWindowToken(SStrToken* token, int16_t *columnIndex) { + SStrToken tmpToken = *token; + SStrToken tableToken = {0}; + + extractTableNameFromToken(&tmpToken, &tableToken); + if (tmpToken.n == strlen(TSQL_TSWIN_START) && strncasecmp(TSQL_TSWIN_START, tmpToken.z, tmpToken.n) == 0) { + *columnIndex = TSDB_TSWIN_START_COLUMN_INDEX; + return true; + } else if (tmpToken.n == strlen(TSQL_TSWIN_STOP) && strncasecmp(TSQL_TSWIN_STOP, tmpToken.z, tmpToken.n) == 0) { + *columnIndex = TSDB_TSWIN_STOP_COLUMN_INDEX; + return true; + } else if (tmpToken.n == strlen(TSQL_TSWIN_DURATION) && strncasecmp(TSQL_TSWIN_DURATION, tmpToken.z, tmpToken.n) == 0) { + *columnIndex = TSDB_TSWIN_DURATION_COLUMN_INDEX; + return true; + } else { + return false; + } +} + static int16_t doGetColumnIndex(SQueryInfo* pQueryInfo, int32_t index, SStrToken* pToken) { STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, index)->pTableMeta; @@ -3853,11 +3894,14 @@ int32_t doGetColumnIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColum return TSDB_CODE_TSC_INVALID_OPERATION; } + int16_t tsWinColumnIndex; if (isTablenameToken(pToken)) { pIndex->columnIndex = TSDB_TBNAME_COLUMN_INDEX; } else if (strlen(DEFAULT_PRIMARY_TIMESTAMP_COL_NAME) == pToken->n && strncasecmp(pToken->z, DEFAULT_PRIMARY_TIMESTAMP_COL_NAME, pToken->n) == 0) { pIndex->columnIndex = PRIMARYKEY_TIMESTAMP_COL_INDEX; // just make runtime happy, need fix java test case InsertSpecialCharacterJniTest + } else if (isTimeWindowToken(pToken, &tsWinColumnIndex)) { + pIndex->columnIndex = tsWinColumnIndex; } else { // not specify the table name, try to locate the table index by column name if (pIndex->tableIndex == COLUMN_INDEX_INITIAL_VAL) { @@ -3885,7 +3929,7 @@ int32_t doGetColumnIndexByName(SStrToken* pToken, SQueryInfo* pQueryInfo, SColum } } - if (COLUMN_INDEX_VALIDE(*pIndex)) { + if (COLUMN_INDEX_VALID(*pIndex)) { return TSDB_CODE_SUCCESS; } else { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -8211,6 +8255,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { int16_t numOfScalar = 0; int16_t numOfSelectivity = 0; int16_t numOfAggregation = 0; + int16_t numOfTimeWindow = 0; size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprList); for (int32_t i = 0; i < numOfExprs; ++i) { @@ -8232,6 +8277,10 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { continue; } + if (functionId == TSDB_FUNC_WSTART || functionId == TSDB_FUNC_WSTOP || functionId == TSDB_FUNC_WDURATION) { + numOfTimeWindow++; + } + if (functionId < 0) { SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1); if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) { @@ -8302,7 +8351,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) { } } else { if ((pQueryInfo->type & TSDB_QUERY_TYPE_PROJECTION_QUERY) != 0) { - if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0) { + if (numOfAggregation > 0 && pQueryInfo->groupbyExpr.numOfGroupCols == 0 && numOfTimeWindow == 0) { return invalidOperationMsg(msg, msg2); } @@ -10155,11 +10204,14 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } int32_t timeWindowQuery = - (TPARSER_HAS_TOKEN(pSqlNode->interval.interval) || TPARSER_HAS_TOKEN(pSqlNode->sessionVal.gap)); - TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TABLE_QUERY); + (TPARSER_HAS_TOKEN(pSqlNode->interval.interval) || + TPARSER_HAS_TOKEN(pSqlNode->sessionVal.gap) || + TPARSER_HAS_TOKEN(pSqlNode->windowstateVal.col)); int32_t joinQuery = (pSqlNode->from != NULL && taosArrayGetSize(pSqlNode->from->list) > 1); + TSDB_QUERY_SET_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_TABLE_QUERY); + // parse the group by clause in the first place if (validateGroupbyNode(pQueryInfo, pSqlNode->pGroupby, pCmd) != TSDB_CODE_SUCCESS) { return TSDB_CODE_TSC_INVALID_OPERATION; @@ -10317,7 +10369,9 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf } int32_t timeWindowQuery = - (TPARSER_HAS_TOKEN(pSqlNode->interval.interval) || TPARSER_HAS_TOKEN(pSqlNode->sessionVal.gap)); + (TPARSER_HAS_TOKEN(pSqlNode->interval.interval) || + TPARSER_HAS_TOKEN(pSqlNode->sessionVal.gap) || + TPARSER_HAS_TOKEN(pSqlNode->windowstateVal.col)); if (validateSelectNodeList(pCmd, pQueryInfo, pSqlNode->pSelNodeList, joinQuery, timeWindowQuery, false) != TSDB_CODE_SUCCESS) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 60f6d7d028e7c40ec4b49737b460b6de60e548a4..c821c25987042d0c26c4aa302a142544a08b943c 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -951,7 +951,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->window.ekey = htobe64(query.window.ekey); pQueryMsg->range.skey = htobe64(query.range.skey); pQueryMsg->range.ekey = htobe64(query.range.ekey); - + pQueryMsg->order = htons(query.order.order); pQueryMsg->orderColId = htons(query.order.orderColId); pQueryMsg->fillType = htons(query.fillType); @@ -990,7 +990,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pQueryMsg->numOfGroupCols = htons(pQueryInfo->groupbyExpr.numOfGroupCols); pQueryMsg->queryType = htonl(pQueryInfo->type); pQueryMsg->prevResultLen = htonl(pQueryInfo->bufLen); - + // set column list ids size_t numOfCols = taosArrayGetSize(pQueryInfo->colList); char *pMsg = (char *)(pQueryMsg->tableCols) + numOfCols * sizeof(SColumnInfo); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index e481109231970ca7c46659d720dbe0b8642bf0f7..91e2d0c388d0b6dd50ca999d35be7712f8bb18dd 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2551,6 +2551,11 @@ SExprInfo* tscExprCreate(STableMetaInfo* pTableMetaInfo, int16_t functionId, SCo p->colInfo.colId = TSDB_TBNAME_COLUMN_INDEX; p->colBytes = s->bytes; p->colType = s->type; + } else if (TSDB_COL_IS_TSWIN_COL(pColIndex->columnIndex)) { + SSchema* s = tGetTimeWindowColumnSchema(pColIndex->columnIndex); + p->colInfo.colId = s->colId; + p->colBytes = s->bytes; + p->colType = s->type; } else if (pColIndex->columnIndex <= TSDB_UD_COLUMN_INDEX) { p->colInfo.colId = pColIndex->columnIndex; p->colBytes = size; @@ -3073,7 +3078,8 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId) { return false; } - if (colId == TSDB_TBNAME_COLUMN_INDEX || colId <= TSDB_UD_COLUMN_INDEX) { + if (colId == TSDB_TBNAME_COLUMN_INDEX || TSDB_COL_IS_TSWIN_COL(colId) || + colId <= TSDB_UD_COLUMN_INDEX) { return true; } diff --git a/src/common/inc/tname.h b/src/common/inc/tname.h index e6b7dd1463a754bfaa78bb1081e3b6b0b753d752..9c8e31a9131d0d9ffa3d4cb71e813e3d2a34f2b7 100644 --- a/src/common/inc/tname.h +++ b/src/common/inc/tname.h @@ -103,6 +103,7 @@ bool tscValidateTableNameLength(size_t len); SColumnFilterInfo* tFilterInfoDup(const SColumnFilterInfo* src, int32_t numOfFilters); SSchema* tGetTbnameColumnSchema(); +SSchema* tGetTimeWindowColumnSchema(int16_t columnIndex); /** * check if the schema is valid or not, including following aspects: diff --git a/src/common/src/tname.c b/src/common/src/tname.c index 68aa1be6b2ed0d9d1a248e6fc6ee2e701071fb21..9357f657ba7059bef133616673bbe93f92f46001 100644 --- a/src/common/src/tname.c +++ b/src/common/src/tname.c @@ -244,6 +244,29 @@ static struct SSchema _s = { .name = TSQL_TBNAME_L, }; +static struct SSchema _tswin[3] = { + {TSDB_DATA_TYPE_TIMESTAMP, TSQL_TSWIN_START, TSDB_TSWIN_START_COLUMN_INDEX, LONG_BYTES}, + {TSDB_DATA_TYPE_TIMESTAMP, TSQL_TSWIN_STOP, TSDB_TSWIN_STOP_COLUMN_INDEX, LONG_BYTES}, + {TSDB_DATA_TYPE_BIGINT, TSQL_TSWIN_DURATION, TSDB_TSWIN_DURATION_COLUMN_INDEX, LONG_BYTES}, +}; + +SSchema* tGetTimeWindowColumnSchema(int16_t columnIndex) { + switch (columnIndex) { + case TSDB_TSWIN_START_COLUMN_INDEX: { + return &_tswin[0]; + } + case TSDB_TSWIN_STOP_COLUMN_INDEX: { + return &_tswin[1]; + } + case TSDB_TSWIN_DURATION_COLUMN_INDEX: { + return &_tswin[2]; + } + default: { + return NULL; + } + } +} + SSchema* tGetTbnameColumnSchema() { return &_s; } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index 8f31e1860fe2a1fa08b3eb65466a0f23b656f95d..9779115432cfc5720f84734b656d12de3ff8571d 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -276,7 +276,14 @@ do { \ #define TSDB_MAX_REPLICA 5 -#define TSDB_TBNAME_COLUMN_INDEX (-1) +#define TSDB_TBNAME_COLUMN_INDEX (-1) +#define TSDB_TSWIN_START_COLUMN_INDEX (-2) +#define TSDB_TSWIN_STOP_COLUMN_INDEX (-3) +#define TSDB_TSWIN_DURATION_COLUMN_INDEX (-4) +#define TSDB_MIN_VALID_COLUMN_INDEX (-4) + +#define TSDB_COL_IS_TSWIN_COL(_i) ((_i) <= TSDB_TSWIN_START_COLUMN_INDEX && (_i) >= TSDB_TSWIN_DURATION_COLUMN_INDEX) + #define TSDB_UD_COLUMN_INDEX (-1000) #define TSDB_RES_COL_ID (-5000) diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index 0080b8b66299c6d2ba79568d9ba71c3a8b5e3173..0b87c546d570e8bf4dfc723ae9dc380442009280 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -30,61 +30,64 @@ extern "C" { #include "tsdb.h" #include "qUdf.h" -#define TSDB_FUNC_INVALID_ID -1 -#define TSDB_FUNC_COUNT 0 -#define TSDB_FUNC_SUM 1 -#define TSDB_FUNC_AVG 2 -#define TSDB_FUNC_MIN 3 -#define TSDB_FUNC_MAX 4 -#define TSDB_FUNC_STDDEV 5 -#define TSDB_FUNC_PERCT 6 -#define TSDB_FUNC_APERCT 7 -#define TSDB_FUNC_FIRST 8 -#define TSDB_FUNC_LAST 9 -#define TSDB_FUNC_LAST_ROW 10 -#define TSDB_FUNC_TOP 11 -#define TSDB_FUNC_BOTTOM 12 -#define TSDB_FUNC_SPREAD 13 -#define TSDB_FUNC_TWA 14 -#define TSDB_FUNC_LEASTSQR 15 - -#define TSDB_FUNC_TS 16 -#define TSDB_FUNC_TS_DUMMY 17 -#define TSDB_FUNC_TAG_DUMMY 18 -#define TSDB_FUNC_TS_COMP 19 - -#define TSDB_FUNC_TAG 20 -#define TSDB_FUNC_PRJ 21 - -#define TSDB_FUNC_TAGPRJ 22 -#define TSDB_FUNC_SCALAR_EXPR 23 -#define TSDB_FUNC_DIFF 24 - -#define TSDB_FUNC_FIRST_DST 25 -#define TSDB_FUNC_LAST_DST 26 -#define TSDB_FUNC_STDDEV_DST 27 -#define TSDB_FUNC_INTERP 28 - -#define TSDB_FUNC_RATE 29 -#define TSDB_FUNC_IRATE 30 -#define TSDB_FUNC_TID_TAG 31 -#define TSDB_FUNC_DERIVATIVE 32 - -#define TSDB_FUNC_CSUM 33 -#define TSDB_FUNC_MAVG 34 -#define TSDB_FUNC_SAMPLE 35 - -#define TSDB_FUNC_BLKINFO 36 - -#define TSDB_FUNC_ELAPSED 37 -#define TSDB_FUNC_HISTOGRAM 38 -#define TSDB_FUNC_UNIQUE 39 -#define TSDB_FUNC_MODE 40 -#define TSDB_FUNC_TAIL 41 -#define TSDB_FUNC_STATE_COUNT 42 -#define TSDB_FUNC_STATE_DURATION 43 - -#define TSDB_FUNC_MAX_NUM 44 +#define TSDB_FUNC_INVALID_ID -1 +#define TSDB_FUNC_COUNT 0 +#define TSDB_FUNC_SUM 1 +#define TSDB_FUNC_AVG 2 +#define TSDB_FUNC_MIN 3 +#define TSDB_FUNC_MAX 4 +#define TSDB_FUNC_STDDEV 5 +#define TSDB_FUNC_PERCT 6 +#define TSDB_FUNC_APERCT 7 +#define TSDB_FUNC_FIRST 8 +#define TSDB_FUNC_LAST 9 +#define TSDB_FUNC_LAST_ROW 10 +#define TSDB_FUNC_TOP 11 +#define TSDB_FUNC_BOTTOM 12 +#define TSDB_FUNC_SPREAD 13 +#define TSDB_FUNC_TWA 14 +#define TSDB_FUNC_LEASTSQR 15 + +#define TSDB_FUNC_TS 16 +#define TSDB_FUNC_TS_DUMMY 17 +#define TSDB_FUNC_TAG_DUMMY 18 +#define TSDB_FUNC_TS_COMP 19 + +#define TSDB_FUNC_TAG 20 +#define TSDB_FUNC_PRJ 21 + +#define TSDB_FUNC_TAGPRJ 22 +#define TSDB_FUNC_SCALAR_EXPR 23 +#define TSDB_FUNC_DIFF 24 + +#define TSDB_FUNC_FIRST_DST 25 +#define TSDB_FUNC_LAST_DST 26 +#define TSDB_FUNC_STDDEV_DST 27 +#define TSDB_FUNC_INTERP 28 + +#define TSDB_FUNC_RATE 29 +#define TSDB_FUNC_IRATE 30 +#define TSDB_FUNC_TID_TAG 31 +#define TSDB_FUNC_DERIVATIVE 32 + +#define TSDB_FUNC_CSUM 33 +#define TSDB_FUNC_MAVG 34 +#define TSDB_FUNC_SAMPLE 35 + +#define TSDB_FUNC_BLKINFO 36 + +#define TSDB_FUNC_ELAPSED 37 +#define TSDB_FUNC_HISTOGRAM 38 +#define TSDB_FUNC_UNIQUE 39 +#define TSDB_FUNC_MODE 40 +#define TSDB_FUNC_TAIL 41 +#define TSDB_FUNC_STATE_COUNT 42 +#define TSDB_FUNC_STATE_DURATION 43 +#define TSDB_FUNC_WSTART 44 +#define TSDB_FUNC_WSTOP 45 +#define TSDB_FUNC_WDURATION 46 + +#define TSDB_FUNC_MAX_NUM 47 #define TSDB_FUNCSTATE_SO 0x1u // single output #define TSDB_FUNCSTATE_MO 0x2u // dynamic number of output, not multinumber of output e.g., TOP/BOTTOM @@ -230,10 +233,12 @@ typedef struct SAggFunctionInfo { int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int32_t *len, int32_t *interBytes, int16_t extLength, bool isSuperTable, SUdfInfo* pUdfInfo); -int32_t isValidFunction(const char* name, int32_t len); +int16_t getTimeWindowFunctionID(int16_t colIndex); +int32_t isValidFunction(const char* name, int32_t len); bool isValidStateOper(char *oper, int32_t len); + #define IS_STREAM_QUERY_VALID(x) (((x)&TSDB_FUNCSTATE_STREAM) != 0) #define IS_MULTIOUTPUT(x) (((x)&TSDB_FUNCSTATE_MO) != 0) #define IS_SINGLEOUTPUT(x) (((x)&TSDB_FUNCSTATE_SO) != 0) diff --git a/src/query/src/qAggMain.c b/src/query/src/qAggMain.c index fd05e6b80f6501c5050ef3e46bfe9420cd0bc362..9c330b52375899215b764437751622db97c1c9e6 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -5712,6 +5712,7 @@ static void tail_func_finalizer(SQLFunctionCtx *pCtx) { doFinalizer(pCtx); } + static void state_count_function(SQLFunctionCtx *pCtx) { SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx); SStateInfo *pStateInfo = GET_ROWCELL_INTERBUF(pResInfo); @@ -5775,6 +5776,41 @@ static void state_duration_function(SQLFunctionCtx *pCtx) { } pResInfo->numOfRes += pCtx->size; } + +int16_t getTimeWindowFunctionID(int16_t colIndex) { + switch (colIndex) { + case TSDB_TSWIN_START_COLUMN_INDEX: { + return TSDB_FUNC_WSTART; + } + case TSDB_TSWIN_STOP_COLUMN_INDEX: { + return TSDB_FUNC_WSTOP; + } + case TSDB_TSWIN_DURATION_COLUMN_INDEX: { + return TSDB_FUNC_WDURATION; + } + default: + return TSDB_FUNC_INVALID_ID; + } +} + +static void wstart_function(SQLFunctionCtx *pCtx) { + SET_VAL(pCtx, pCtx->size, 1); + *(int64_t *)(pCtx->pOutput) = pCtx->startTs; +} + +static void wstop_function(SQLFunctionCtx *pCtx) { + SET_VAL(pCtx, pCtx->size, 1); + *(int64_t *)(pCtx->pOutput) = pCtx->endTs; +} + +static void wduration_function(SQLFunctionCtx *pCtx) { + SET_VAL(pCtx, pCtx->size, 1); + int64_t duration = pCtx->endTs - pCtx->startTs; + if (duration < 0) { + duration = -duration; + } + *(int64_t *)(pCtx->pOutput) = duration; +} ///////////////////////////////////////////////////////////////////////////////////////////// /* * function compatible list. @@ -5787,16 +5823,16 @@ static void state_duration_function(SQLFunctionCtx *pCtx) { * */ int32_t functionCompatList[] = { - // count, sum, avg, min, max, stddev, percentile, apercentile, first, last - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - // last_row,top, bottom, spread, twa, leastsqr, ts, ts_dummy, tag_dummy, ts_comp - 4, -1, -1, 1, 1, 1, 1, 1, 1, -1, - // tag, colprj, tagprj, arithm, diff, first_dist, last_dist, stddev_dst, interp rate, irate - 1, 1, 1, 1, -1, 1, 1, 1, 5, 1, 1, - // tid_tag, deriv, csum, mavg, sample, - 6, 8, -1, -1, -1, - // block_info,elapsed,histogram,unique,mode,tail, stateCount, stateDuration - 7, 1, -1, -1, 1, -1, 1, 1, + // count, sum, avg, min, max, stddev, percentile, apercentile, first, last + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + // last_row, top, bottom, spread, twa, leastsqr, ts, ts_dummy, tag_dummy, ts_comp + 4, -1, -1, 1, 1, 1, 1, 1, 1, -1, + // tag, colprj, tagprj, arithm, diff, first_dist, last_dist, stddev_dst, interp rate, irate + 1, 1, 1, 1, -1, 1, 1, 1, 5, 1, 1, + // tid_tag, deriv, csum, mavg, sample, block_info, elapsed, histogram, unique, mode, tail + 6, 8, -1, -1, -1, 7, 1, -1, -1, 1, -1, + // stateCount, stateDuration, wstart, wstop, wduration, + 1, 1, 1, 1, 1, }; SAggFunctionInfo aAggs[TSDB_FUNC_MAX_NUM] = {{ @@ -6294,40 +6330,76 @@ SAggFunctionInfo aAggs[TSDB_FUNC_MAX_NUM] = {{ mode_function_merge, dataBlockRequired, }, - { - // 41 - "tail", - TSDB_FUNC_TAIL, - TSDB_FUNC_TAIL, - TSDB_BASE_FUNC_MO | TSDB_FUNCSTATE_SELECTIVITY, - tail_function_setup, - tail_function, - tail_func_finalizer, - tail_func_merge, - tailFuncRequired, - }, - { - // 42 - "stateCount", - TSDB_FUNC_STATE_COUNT, - TSDB_FUNC_INVALID_ID, - TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, - function_setup, - state_count_function, - doFinalizer, - noop1, - dataBlockRequired, - }, - { - // 43 - "stateDuration", - TSDB_FUNC_STATE_DURATION, - TSDB_FUNC_INVALID_ID, - TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, - function_setup, - state_duration_function, - doFinalizer, - noop1, - dataBlockRequired, - } + { + // 41 + "tail", + TSDB_FUNC_TAIL, + TSDB_FUNC_TAIL, + TSDB_BASE_FUNC_MO | TSDB_FUNCSTATE_SELECTIVITY, + tail_function_setup, + tail_function, + tail_func_finalizer, + tail_func_merge, + tailFuncRequired, + }, + { + // 42 + "stateCount", + TSDB_FUNC_STATE_COUNT, + TSDB_FUNC_INVALID_ID, + TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, + function_setup, + state_count_function, + doFinalizer, + noop1, + dataBlockRequired, + }, + { + // 43 + "stateDuration", + TSDB_FUNC_STATE_DURATION, + TSDB_FUNC_INVALID_ID, + TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_NEED_TS, + function_setup, + state_duration_function, + doFinalizer, + noop1, + dataBlockRequired, + }, + { + // 44 + "_wstart", + TSDB_FUNC_WSTART, + TSDB_FUNC_WSTART, + TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_SELECTIVITY, + function_setup, + wstart_function, + doFinalizer, + copy_function, + dataBlockRequired, + }, + { + // 45 + "_wstop", + TSDB_FUNC_WSTOP, + TSDB_FUNC_WSTOP, + TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_SELECTIVITY, + function_setup, + wstop_function, + doFinalizer, + copy_function, + dataBlockRequired, + }, + { + // 46 + "_wduration", + TSDB_FUNC_WDURATION, + TSDB_FUNC_WDURATION, + TSDB_BASE_FUNC_SO | TSDB_FUNCSTATE_SELECTIVITY, + function_setup, + wduration_function, + doFinalizer, + copy_function, + dataBlockRequired, + } }; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index b52de4d233148a1f900cdfd28783f780d613096b..8cb05977cd6430e41e8eceaeeb50f84f0abdc2fc 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -461,7 +461,8 @@ static bool isProjQuery(SQueryAttr *pQueryAttr) { } static bool hasNull(SColIndex* pColIndex, SDataStatis *pStatis) { - if (TSDB_COL_IS_TAG(pColIndex->flag) || TSDB_COL_IS_UD_COL(pColIndex->flag) || pColIndex->colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { + if (TSDB_COL_IS_TAG(pColIndex->flag) || TSDB_COL_IS_UD_COL(pColIndex->flag) || + TSDB_COL_IS_TSWIN_COL(pColIndex->colId) || pColIndex->colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) { return false; } @@ -953,6 +954,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx pCtx[k].size = forwardStep; pCtx[k].startTs = pWin->skey; + pCtx[k].endTs = pWin->ekey; // keep it temporarialy char* start = pCtx[k].pInput; @@ -1190,7 +1192,7 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, setArithParams((SScalarExprSupport*)pCtx[i].param[1].pz, &pOperator->pExpr[i], pBlock); } else { SColIndex* pCol = &pOperator->pExpr[i].base.colInfo; - if (TSDB_COL_IS_NORMAL_COL(pCol->flag) || (pCtx[i].functionId == TSDB_FUNC_BLKINFO) || + if ((TSDB_COL_IS_NORMAL_COL(pCol->flag) && !TSDB_COL_IS_TSWIN_COL(pCol->colId)) || (pCtx[i].functionId == TSDB_FUNC_BLKINFO) || (TSDB_COL_IS_TAG(pCol->flag) && pOperator->pRuntimeEnv->scanFlag == MERGE_STAGE)) { SColIndex* pColIndex = &pOperator->pExpr[i].base.colInfo; SColumnInfoData* p = taosArrayGet(pBlock->pDataBlock, pColIndex->colIndex); @@ -1698,7 +1700,6 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf } else { // start a new session window SResultRow* pResult = NULL; - pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.tid, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -1719,7 +1720,6 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSWindowOperatorInf SResultRow* pResult = NULL; - pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.tid, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -1842,7 +1842,7 @@ static bool functionNeedToExecute(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx void setBlockStatisInfo(SQLFunctionCtx *pCtx, SSDataBlock* pSDataBlock, SColIndex* pColIndex) { SDataStatis *pStatis = NULL; - if (pSDataBlock->pBlockStatis != NULL && TSDB_COL_IS_NORMAL_COL(pColIndex->flag)) { + if (pSDataBlock->pBlockStatis != NULL && TSDB_COL_IS_NORMAL_COL(pColIndex->flag) && !TSDB_COL_IS_TSWIN_COL(pColIndex->colId)) { pStatis = &pSDataBlock->pBlockStatis[pColIndex->colIndex]; pCtx->preAggVals.statis = *pStatis; @@ -6924,7 +6924,6 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } } else { SResultRow* pResult = NULL; - pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.tid, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -6944,8 +6943,6 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } SResultRow* pResult = NULL; - - pInfo->curWindow.ekey = pInfo->curWindow.skey; int32_t ret = setResultOutputBufByKey(pRuntimeEnv, &pBInfo->resultRowInfo, pSDataBlock->info.tid, &pInfo->curWindow, masterScan, &pResult, item->groupIndex, pBInfo->pCtx, pOperator->numOfOutput, pBInfo->rowCellInfoOffset); @@ -8388,8 +8385,9 @@ static int32_t getColumnIndexInSource(SQueriedTableInfo *pTableInfo, SSqlExpr *p int32_t j = 0; if (TSDB_COL_IS_TAG(pExpr->colInfo.flag)) { - if (pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX) { - return TSDB_TBNAME_COLUMN_INDEX; + if (pExpr->colInfo.colId == TSDB_TBNAME_COLUMN_INDEX || + TSDB_COL_IS_TSWIN_COL(pExpr->colInfo.colId)) { + return pExpr->colInfo.colId; } while(j < pTableInfo->numOfTags) { @@ -9172,6 +9170,11 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp SSchema* s = tGetTbnameColumnSchema(); type = s->type; bytes = s->bytes; + } else if (TSDB_COL_IS_TSWIN_COL(pExprs[i].base.colInfo.colId) && + (pExprs[i].base.functionId >= TSDB_FUNC_WSTART || pExprs[i].base.functionId <= TSDB_FUNC_WDURATION)) { + SSchema* s = tGetTimeWindowColumnSchema(pExprs[i].base.colInfo.colId); + type = s->type; + bytes = s->bytes; } else if (pExprs[i].base.colInfo.colId <= TSDB_UD_COLUMN_INDEX && pExprs[i].base.colInfo.colId > TSDB_RES_COL_ID) { // it is a user-defined constant value column assert(pExprs[i].base.functionId == TSDB_FUNC_PRJ); @@ -9184,7 +9187,7 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp } else { int32_t j = getColumnIndexInSource(pTableInfo, &pExprs[i].base, pTagCols); if (TSDB_COL_IS_TAG(pExprs[i].base.colInfo.flag)) { - if (j < TSDB_TBNAME_COLUMN_INDEX || j >= pTableInfo->numOfTags) { + if (j < TSDB_MIN_VALID_COLUMN_INDEX || j >= pTableInfo->numOfTags) { tfree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -9217,15 +9220,23 @@ int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExp } int32_t param = (int32_t)pExprs[i].base.param[0].i64; - if (pExprs[i].base.functionId > 0 && pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR && + if (pExprs[i].base.functionId > 0 && + pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR && + pExprs[i].base.functionId != TSDB_FUNC_WSTART && + pExprs[i].base.functionId != TSDB_FUNC_WSTOP && + pExprs[i].base.functionId != TSDB_FUNC_WDURATION && (type != pExprs[i].base.colType || bytes != pExprs[i].base.colBytes)) { tfree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } // todo remove it - if (pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR && getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes, - &pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) { + if (pExprs[i].base.functionId != TSDB_FUNC_SCALAR_EXPR && + pExprs[i].base.functionId != TSDB_FUNC_WSTART && + pExprs[i].base.functionId != TSDB_FUNC_WSTOP && + pExprs[i].base.functionId != TSDB_FUNC_WDURATION && + getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].base.resType, &pExprs[i].base.resBytes, + &pExprs[i].base.interBytes, 0, isSuperTable, pUdfInfo) != TSDB_CODE_SUCCESS) { tfree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -9438,7 +9449,10 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) { for (int32_t k = 0; k < pQueryAttr->numOfOutput; ++k) { SSqlExpr *pSqlExprMsg = &pQueryAttr->pExpr1[k].base; - if (pSqlExprMsg->functionId == TSDB_FUNC_SCALAR_EXPR) { + if (pSqlExprMsg->functionId == TSDB_FUNC_SCALAR_EXPR || + pSqlExprMsg->functionId == TSDB_FUNC_WSTART || + pSqlExprMsg->functionId == TSDB_FUNC_WSTOP || + pSqlExprMsg->functionId == TSDB_FUNC_WDURATION) { continue; } @@ -9465,7 +9479,7 @@ static void doUpdateExprColumnIndex(SQueryAttr *pQueryAttr) { } } - assert(f < pQueryAttr->numOfTags || pColIndex->colId == TSDB_TBNAME_COLUMN_INDEX); + assert(f < pQueryAttr->numOfTags || pColIndex->colId <= TSDB_TBNAME_COLUMN_INDEX); } } } diff --git a/src/util/inc/ttoken.h b/src/util/inc/ttoken.h index 17f2bf5a79f9dd2c6650e4b0cb24a492c4d68e3a..da84d2586dbb56710500aa93b69d60f00352a7d1 100644 --- a/src/util/inc/ttoken.h +++ b/src/util/inc/ttoken.h @@ -27,6 +27,10 @@ extern "C" { #define TSQL_TBNAME "TBNAME" #define TSQL_TBNAME_L "tbname" +#define TSQL_TSWIN_START "_wstart" +#define TSQL_TSWIN_STOP "_wstop" +#define TSQL_TSWIN_DURATION "_wduration" + #define TSQL_BLOCK_DIST "_BLOCK_DIST" #define TSQL_BLOCK_DIST_L "_block_dist" diff --git a/tests/develop-test/2-query/time_window_keywords.py b/tests/develop-test/2-query/time_window_keywords.py new file mode 100644 index 0000000000000000000000000000000000000000..48c0973aa7e8fc24294304053170ab3ed56fde6c --- /dev/null +++ b/tests/develop-test/2-query/time_window_keywords.py @@ -0,0 +1,4123 @@ +################################################################### +# Copyright (c) 2021 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 +from util.log import * +from util.cases import * +from util.sql import * + + +class TDTestCase: + def caseDescription(self): + ''' + case1: [TD-11216]: Time window related keywords + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getBuildPath(self): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if ("community" in selfPath): + projPath = selfPath[:selfPath.find("community")] + else: + projPath = selfPath[:selfPath.find("tests")] + + for root, dirs, files in os.walk(projPath): + if ("taosd" in files): + rootRealPath = os.path.dirname(os.path.realpath(root)) + if ("packaging" not in rootRealPath): + buildPath = root[:len(root) - len("/build/bin")] + break + return buildPath + + def checkTimestampEqual(self, elm, expect_elm): + caller = inspect.getframeinfo(inspect.stack()[1][0]) + if len(elm) == len(expect_elm): + delta = abs(int(elm[-1]) - int(expect_elm[-1])) + if delta == 1: #ignore 1 second diff + new_elm = expect_elm[0:-1] + elm[-1] + else: + new_elm = expect_elm; + if elm == new_elm: + tdLog.info("sql:%s, elm:%s == expect_elm:%s" % (tdSql.sql, elm, new_elm)) + else: + args = (caller.filename, caller.lineno, tdSql.sql, elm, new_elm) + tdLog.exit("%s(%d) failed: sql:%s, elm:%s != expect_elm:%s" % args) + else: + args = (caller.filename, caller.lineno, tdSql.sql, elm, expect_elm) + tdLog.exit("%s(%d) failed: sql:%s, elm:%s != expect_elm:%s" % args) + + + def run(self): + print("running {}".format(__file__)) + + #Prepare data + #db precision "ms" + tdSql.execute("drop database if exists db_m") + tdSql.execute("create database if not exists db_m") + tdSql.execute('use db_m') + + #for interval query + tdSql.execute("create stable stb_i (ts timestamp, c0 int) tags (t0 int);") + tdSql.execute("create table ctb1_i using stb_i tags (1);") + tdSql.execute("create table ctb2_i using stb_i tags (2);") + tdSql.execute("create table tb_i (ts timestamp, c0 int);") + + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:05', 5)") + + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:00', 0)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:01', 1)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:02', 2)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:03', 3)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:04', 4)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:05', 5)") + + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:05', 5)") + + #for state_window query + tdSql.execute("create table tb_w (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:01', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:03', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:05', 2)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:06', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:07', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:08', 0)") + + #for session query + tdSql.execute("create table tb_s (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:00', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:07', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:10', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:14', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:18', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:23', 1)") + + #db precision "us" + tdSql.execute("drop database if exists db_u") + tdSql.execute("create database if not exists db_u precision 'us'") + tdSql.execute('use db_u') + + #for interval query + tdSql.execute("create stable stb_i (ts timestamp, c0 int) tags (t0 int);") + tdSql.execute("create table ctb1_i using stb_i tags (1);") + tdSql.execute("create table ctb2_i using stb_i tags (2);") + tdSql.execute("create table tb_i (ts timestamp, c0 int);") + + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:05', 5)") + + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:00', 0)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:01', 1)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:02', 2)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:03', 3)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:04', 4)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:05', 5)") + + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:05', 5)") + + #for state_window query + tdSql.execute("create table tb_w (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:01', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:03', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:05', 2)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:06', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:07', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:08', 0)") + + #for session query + tdSql.execute("create table tb_s (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:00', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:07', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:10', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:14', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:18', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:23', 1)") + + #db precision "ns" + tdSql.execute("drop database if exists db_n") + tdSql.execute("create database if not exists db_n precision 'ns'") + tdSql.execute('use db_n') + + #for interval query + tdSql.execute("create stable stb_i (ts timestamp, c0 int) tags (t0 int);") + tdSql.execute("create table ctb1_i using stb_i tags (1);") + tdSql.execute("create table ctb2_i using stb_i tags (2);") + tdSql.execute("create table tb_i (ts timestamp, c0 int);") + + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into ctb1_i values ('2022-02-02 02:00:05', 5)") + + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:00', 0)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:01', 1)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:02', 2)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:03', 3)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:04', 4)") + tdSql.execute("insert into ctb2_i values ('2022-02-02 03:00:05', 5)") + + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:01', 1)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:02', 2)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:03', 3)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:04', 4)") + tdSql.execute("insert into tb_i values ('2022-02-02 02:00:05', 5)") + + #for state_window query + tdSql.execute("create table tb_w (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:00', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:01', 0)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:03', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:05', 2)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:06', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:07', 5)") + tdSql.execute("insert into tb_w values ('2022-02-02 02:00:08', 0)") + + #for session query + tdSql.execute("create table tb_s (ts timestamp, c0 int);") + + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:00', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:02', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:04', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:07', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:10', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:14', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:18', 1)") + tdSql.execute("insert into tb_s values ('2022-02-02 02:00:23', 1)") + + #execute query + print("============== STEP 1: select _wsatrt,_wstop,_wduration in interval query ================== ") + + # db precision "ms" + tdSql.execute('use db_m') + + ## _wstart + tdSql.query("select _wstart from tb_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from ctb1_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from stb_i interval (1a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05") + + tdSql.query("select _wstart from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + + tdSql.query("select _wstart from tb_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query("select _wstart from ctb1_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query("select _wstart from stb_i interval (2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + + tdSql.query("select _wstart from tb_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + tdSql.query("select _wstart from ctb1_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + tdSql.query("select _wstart from stb_i interval (1m);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + + tdSql.query("select _wstart,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + + tdSql.query("select avg(c0),_wstart from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 2) + + tdSql.query("select avg(c0),_wstart,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 2) + + ##_wstop + tdSql.query("select _wstop from tb_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstop from ctb1_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstop from stb_i interval (1a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05") + + tdSql.query("select _wstop from tb_i interval (10a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009000") + tdSql.query("select _wstop from ctb1_i interval (10a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009000") + tdSql.query("select _wstop from stb_i interval (10a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009000") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.009000") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.009000") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.009000") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.009000") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.009000") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.009000") + + tdSql.query("select _wstop from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999000") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999000") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999000") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + tdSql.query("select _wstop from tb_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop from ctb1_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop from stb_i interval (2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + tdSql.query("select _wstop from tb_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999000") + tdSql.query("select _wstop from ctb1_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999000") + tdSql.query("select _wstop from stb_i interval (1m);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:59.999000") + + tdSql.query("select _wstop,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wstop,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999000") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999000") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999000") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + tdSql.query("select avg(c0),_wstop from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select avg(c0),_wstop from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select avg(c0),_wstop from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999000") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999000") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999000") + res = tdSql.getData(11, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + tdSql.query("select avg(c0),_wstop,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select avg(c0),_wstop,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select avg(c0),_wstop,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999000") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999000") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999000") + res = tdSql.getData(11, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + ##_wduration + tdSql.query("select _wduration from tb_i interval (1a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.query("select _wduration from ctb1_i interval (1a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.query("select _wduration from stb_i interval (1a);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.checkData(6, 1, 0) + tdSql.checkData(7, 1, 0) + tdSql.checkData(8, 1, 0) + tdSql.checkData(9, 1, 0) + tdSql.checkData(10, 1, 0) + tdSql.checkData(11, 1, 0) + + tdSql.query("select _wduration from tb_i interval (10a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.query("select _wduration from ctb1_i interval (10a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.query("select _wduration from stb_i interval (10a);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.checkData(6, 1, 9) + tdSql.checkData(7, 1, 9) + tdSql.checkData(8, 1, 9) + tdSql.checkData(9, 1, 9) + tdSql.checkData(10, 1, 9) + tdSql.checkData(11, 1, 9) + + tdSql.query("select _wduration from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.checkData(6, 1, 999) + tdSql.checkData(7, 1, 999) + tdSql.checkData(8, 1, 999) + tdSql.checkData(9, 1, 999) + tdSql.checkData(10, 1, 999) + tdSql.checkData(11, 1, 999) + + tdSql.query("select _wduration from tb_i interval (2s);") + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + tdSql.query("select _wduration from ctb1_i interval (2s);") + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + tdSql.query("select _wduration from stb_i interval (2s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + tdSql.checkData(3, 1, 1999) + tdSql.checkData(4, 1, 1999) + tdSql.checkData(5, 1, 1999) + + tdSql.query("select _wduration from tb_i interval (1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 59999) + tdSql.query("select _wduration from ctb1_i interval (1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 59999) + tdSql.query("select _wduration from stb_i interval (1m);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 59999) + tdSql.checkData(1, 1, 59999) + + tdSql.query("select _wduration,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.checkData(6, 1, 999) + tdSql.checkData(7, 1, 999) + tdSql.checkData(8, 1, 999) + tdSql.checkData(9, 1, 999) + tdSql.checkData(10, 1, 999) + tdSql.checkData(11, 1, 999) + + tdSql.query("select avg(c0),_wduration from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.query("select avg(c0),_wduration from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.query("select avg(c0),_wduration from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.checkData(6, 2, 999) + tdSql.checkData(7, 2, 999) + tdSql.checkData(8, 2, 999) + tdSql.checkData(9, 2, 999) + tdSql.checkData(10, 2, 999) + tdSql.checkData(11, 2, 999) + + tdSql.query("select avg(c0),_wduration,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.query("select avg(c0),_wduration,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.query("select avg(c0),_wduration,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 2, 999) + tdSql.checkData(1, 2, 999) + tdSql.checkData(2, 2, 999) + tdSql.checkData(3, 2, 999) + tdSql.checkData(4, 2, 999) + tdSql.checkData(5, 2, 999) + tdSql.checkData(6, 2, 999) + tdSql.checkData(7, 2, 999) + tdSql.checkData(8, 2, 999) + tdSql.checkData(9, 2, 999) + tdSql.checkData(10, 2, 999) + tdSql.checkData(11, 2, 999) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.query("select _wstart,_wstop,_wduration from ctb1_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.query("select _wstart,_wstop,_wduration from stb_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.checkData(3, 3, 1999) + tdSql.checkData(4, 3, 1999) + tdSql.checkData(5, 3, 1999) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from ctb1_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from stb_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + tdSql.checkData(0, 3, 1999) + tdSql.checkData(1, 3, 1999) + tdSql.checkData(2, 3, 1999) + tdSql.checkData(3, 3, 1999) + tdSql.checkData(4, 3, 1999) + tdSql.checkData(5, 3, 1999) + + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from tb_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from ctb1_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from stb_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(6) + tdSql.checkData(0, 1, 1999) + tdSql.checkData(1, 1, 1999) + tdSql.checkData(2, 1, 1999) + tdSql.checkData(3, 1, 1999) + tdSql.checkData(4, 1, 1999) + tdSql.checkData(5, 1, 1999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(3, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(4, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(5, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + # db precision "us" + tdSql.execute('use db_u') + + ## _wstart + tdSql.query("select _wstart from tb_i interval (1u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from ctb1_i interval (1u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from stb_i interval (1u);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05") + + tdSql.query("select _wstart from tb_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from ctb1_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from stb_i interval (1a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05") + + tdSql.query("select _wstart from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + + tdSql.query("select _wstart from tb_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query("select _wstart from ctb1_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query("select _wstart from stb_i interval (2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + + tdSql.query("select _wstart from tb_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + tdSql.query("select _wstart from ctb1_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + tdSql.query("select _wstart from stb_i interval (1m);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + + tdSql.query("select _wstart,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstart,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + + tdSql.query("select avg(c0),_wstart from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 2) + + tdSql.query("select avg(c0),_wstart,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select avg(c0),_wstart,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 2) + + ##_wstop + tdSql.query("select _wstop from tb_i interval (1u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstop from ctb1_i interval (1u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + tdSql.query("select _wstop from stb_i interval (1u);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05") + + tdSql.query("select _wstop from tb_i interval (10u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000009") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000009") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000009") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000009") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000009") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000009") + tdSql.query("select _wstop from ctb1_i interval (10u);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000009") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000009") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000009") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000009") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000009") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000009") + tdSql.query("select _wstop from stb_i interval (10u);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000009") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000009") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000009") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000009") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000009") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000009") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.000009") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.000009") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.000009") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.000009") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.000009") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.000009") + + tdSql.query("select _wstop from tb_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000999") + tdSql.query("select _wstop from ctb1_i interval (1a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000999") + tdSql.query("select _wstop from stb_i interval (1a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.000999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.000999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.000999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.000999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.000999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.000999") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.000999") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.000999") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.000999") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.000999") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.000999") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.000999") + + tdSql.query("select _wstop from tb_i interval (10a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009999") + tdSql.query("select _wstop from ctb1_i interval (10a);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009999") + tdSql.query("select _wstop from stb_i interval (10a);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.009999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.009999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.009999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.009999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.009999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.009999") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.009999") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.009999") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.009999") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.009999") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.009999") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.009999") + + tdSql.query("select _wstop from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999999") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999999") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999999") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + tdSql.query("select _wstop from tb_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop from ctb1_i interval (2s);") + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop from stb_i interval (2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + tdSql.query("select _wstop from tb_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999999") + tdSql.query("select _wstop from ctb1_i interval (1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999999") + tdSql.query("select _wstop from stb_i interval (1m);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:59.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:59.999999") + + tdSql.query("select _wstop,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wstop,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999999") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(8, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999999") + res = tdSql.getData(9, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(10, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999999") + res = tdSql.getData(11, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + tdSql.query("select avg(c0),_wstop from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select avg(c0),_wstop from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select avg(c0),_wstop from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999999") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999999") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999999") + res = tdSql.getData(11, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + tdSql.query("select avg(c0),_wstop,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select avg(c0),_wstop,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select avg(c0),_wstop,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00.999999") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(8, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02.999999") + res = tdSql.getData(9, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(10, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04.999999") + res = tdSql.getData(11, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + ##_wduration + tdSql.query("select _wduration from tb_i interval (1u);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.query("select _wduration from ctb1_i interval (1u);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.query("select _wduration from stb_i interval (1u);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.checkData(6, 1, 0) + tdSql.checkData(7, 1, 0) + tdSql.checkData(8, 1, 0) + tdSql.checkData(9, 1, 0) + tdSql.checkData(10, 1, 0) + tdSql.checkData(11, 1, 0) + + tdSql.query("select _wduration from tb_i interval (10u);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.query("select _wduration from ctb1_i interval (10u);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.query("select _wduration from stb_i interval (10u);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 9) + tdSql.checkData(1, 1, 9) + tdSql.checkData(2, 1, 9) + tdSql.checkData(3, 1, 9) + tdSql.checkData(4, 1, 9) + tdSql.checkData(5, 1, 9) + tdSql.checkData(6, 1, 9) + tdSql.checkData(7, 1, 9) + tdSql.checkData(8, 1, 9) + tdSql.checkData(9, 1, 9) + tdSql.checkData(10, 1, 9) + tdSql.checkData(11, 1, 9) + + tdSql.query("select _wduration from tb_i interval (1a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration from ctb1_i interval (1a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.query("select _wduration from stb_i interval (1a);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 999) + tdSql.checkData(1, 1, 999) + tdSql.checkData(2, 1, 999) + tdSql.checkData(3, 1, 999) + tdSql.checkData(4, 1, 999) + tdSql.checkData(5, 1, 999) + tdSql.checkData(6, 1, 999) + tdSql.checkData(7, 1, 999) + tdSql.checkData(8, 1, 999) + tdSql.checkData(9, 1, 999) + tdSql.checkData(10, 1, 999) + tdSql.checkData(11, 1, 999) + + tdSql.query("select _wduration from tb_i interval (10a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9999) + tdSql.checkData(1, 1, 9999) + tdSql.checkData(2, 1, 9999) + tdSql.checkData(3, 1, 9999) + tdSql.checkData(4, 1, 9999) + tdSql.checkData(5, 1, 9999) + tdSql.query("select _wduration from ctb1_i interval (10a);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 9999) + tdSql.checkData(1, 1, 9999) + tdSql.checkData(2, 1, 9999) + tdSql.checkData(3, 1, 9999) + tdSql.checkData(4, 1, 9999) + tdSql.checkData(5, 1, 9999) + tdSql.query("select _wduration from stb_i interval (10a);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 9999) + tdSql.checkData(1, 1, 9999) + tdSql.checkData(2, 1, 9999) + tdSql.checkData(3, 1, 9999) + tdSql.checkData(4, 1, 9999) + tdSql.checkData(5, 1, 9999) + tdSql.checkData(6, 1, 9999) + tdSql.checkData(7, 1, 9999) + tdSql.checkData(8, 1, 9999) + tdSql.checkData(9, 1, 9999) + tdSql.checkData(10, 1, 9999) + tdSql.checkData(11, 1, 9999) + + tdSql.query("select _wduration from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.query("select _wduration from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.query("select _wduration from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.checkData(6, 1, 999999) + tdSql.checkData(7, 1, 999999) + tdSql.checkData(8, 1, 999999) + tdSql.checkData(9, 1, 999999) + tdSql.checkData(10, 1, 999999) + tdSql.checkData(11, 1, 999999) + + tdSql.query("select _wduration from tb_i interval (2s);") + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + tdSql.query("select _wduration from ctb1_i interval (2s);") + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + tdSql.query("select _wduration from stb_i interval (2s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + tdSql.checkData(3, 1, 1999999) + tdSql.checkData(4, 1, 1999999) + tdSql.checkData(5, 1, 1999999) + + tdSql.query("select _wduration from tb_i interval (1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 59999999) + tdSql.query("select _wduration from ctb1_i interval (1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 59999999) + tdSql.query("select _wduration from stb_i interval (1m);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 59999999) + tdSql.checkData(1, 1, 59999999) + + tdSql.query("select _wduration,avg(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.query("select _wduration,avg(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.query("select _wduration,avg(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 1, 999999) + tdSql.checkData(1, 1, 999999) + tdSql.checkData(2, 1, 999999) + tdSql.checkData(3, 1, 999999) + tdSql.checkData(4, 1, 999999) + tdSql.checkData(5, 1, 999999) + tdSql.checkData(6, 1, 999999) + tdSql.checkData(7, 1, 999999) + tdSql.checkData(8, 1, 999999) + tdSql.checkData(9, 1, 999999) + tdSql.checkData(10, 1, 999999) + tdSql.checkData(11, 1, 999999) + + tdSql.query("select avg(c0),_wduration from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.query("select avg(c0),_wduration from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.query("select avg(c0),_wduration from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.checkData(6, 2, 999999) + tdSql.checkData(7, 2, 999999) + tdSql.checkData(8, 2, 999999) + tdSql.checkData(9, 2, 999999) + tdSql.checkData(10, 2, 999999) + tdSql.checkData(11, 2, 999999) + + tdSql.query("select avg(c0),_wduration,sum(c0) from tb_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.query("select avg(c0),_wduration,sum(c0) from ctb1_i interval (1s);") + tdSql.checkRows(6) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.query("select avg(c0),_wduration,sum(c0) from stb_i interval (1s);") + tdSql.checkRows(12) + tdSql.checkData(0, 2, 999999) + tdSql.checkData(1, 2, 999999) + tdSql.checkData(2, 2, 999999) + tdSql.checkData(3, 2, 999999) + tdSql.checkData(4, 2, 999999) + tdSql.checkData(5, 2, 999999) + tdSql.checkData(6, 2, 999999) + tdSql.checkData(7, 2, 999999) + tdSql.checkData(8, 2, 999999) + tdSql.checkData(9, 2, 999999) + tdSql.checkData(10, 2, 999999) + tdSql.checkData(11, 2, 999999) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.query("select _wstart,_wstop,_wduration from ctb1_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.query("select _wstart,_wstop,_wduration from stb_i interval (2s);") + tdSql.checkCols(4) + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.checkData(3, 3, 1999999) + tdSql.checkData(4, 3, 1999999) + tdSql.checkData(5, 3, 1999999) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from ctb1_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(3) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from stb_i interval (2s);") + tdSql.checkCols(5) + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + tdSql.checkData(0, 3, 1999999) + tdSql.checkData(1, 3, 1999999) + tdSql.checkData(2, 3, 1999999) + tdSql.checkData(3, 3, 1999999) + tdSql.checkData(4, 3, 1999999) + tdSql.checkData(5, 3, 1999999) + + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from tb_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from ctb1_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(3) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from stb_i interval (2s);") + tdSql.checkCols(7) + tdSql.checkRows(6) + tdSql.checkData(0, 1, 1999999) + tdSql.checkData(1, 1, 1999999) + tdSql.checkData(2, 1, 1999999) + tdSql.checkData(3, 1, 1999999) + tdSql.checkData(4, 1, 1999999) + tdSql.checkData(5, 1, 1999999) + res = tdSql.getData(0, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 3) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 3) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + res = tdSql.getData(0, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999999") + res = tdSql.getData(1, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999999") + res = tdSql.getData(2, 5) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999999") + res = tdSql.getData(3, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999999") + res = tdSql.getData(4, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999999") + res = tdSql.getData(5, 5) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999999") + + + print("============== STEP 2: select _wsatrt,_wstop,_wduration in state_window query ================== ") + + # db precision "ms" + tdSql.execute('use db_m') + + ## _wstart + tdSql.query("select _wstart from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select _wstart,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select sum(c0),_wstart,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + ##_wstop + tdSql.query("select _wstop from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select _wstop,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select sum(c0),_wstop,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + ##_wduration + tdSql.query("select _wduration from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000) + tdSql.checkData(1, 0, 2000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select _wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000) + tdSql.checkData(1, 0, 2000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select sum(c0),_wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 1, 1000) + tdSql.checkData(1, 1, 2000) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 1000) + tdSql.checkData(4, 1, 0) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + tdSql.checkData(0, 2, 1000) + tdSql.checkData(1, 2, 2000) + tdSql.checkData(2, 2, 0) + tdSql.checkData(3, 2, 1000) + tdSql.checkData(4, 2, 0) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + tdSql.checkData(0, 2, 1000) + tdSql.checkData(1, 2, 2000) + tdSql.checkData(2, 2, 0) + tdSql.checkData(3, 2, 1000) + tdSql.checkData(4, 2, 0) + + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000) + tdSql.checkData(1, 0, 2000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000) + tdSql.checkData(4, 0, 0) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + # db precision "us" + tdSql.execute('use db_u') + + ## _wstart + tdSql.query("select _wstart from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select _wstart,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select sum(c0),_wstart,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + ##_wstop + tdSql.query("select _wstop from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select _wstop,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query("select sum(c0),_wstop,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + ##_wduration + tdSql.query("select _wduration from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000000) + tdSql.checkData(1, 0, 2000000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select _wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000000) + tdSql.checkData(1, 0, 2000000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select sum(c0),_wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 1, 1000000) + tdSql.checkData(1, 1, 2000000) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 1000000) + tdSql.checkData(4, 1, 0) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + tdSql.checkData(0, 0, 1000000) + tdSql.checkData(1, 0, 2000000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + tdSql.checkData(0, 0, 1000000) + tdSql.checkData(1, 0, 2000000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000000) + tdSql.checkData(4, 0, 0) + + tdSql.query("select _wduration,avg(c0),_wstart,sum(c0),_wstop,stddev(c0) from tb_w state_window(c0);") + tdSql.checkRows(5) + tdSql.checkData(0, 0, 1000000) + tdSql.checkData(1, 0, 2000000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000000) + tdSql.checkData(4, 0, 0) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + res = tdSql.getData(0, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 4) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + print("============== STEP 3: select _wsatrt,_wstop,_wduration in session query ================== ") + + # db precision "ms" + tdSql.execute('use db_m') + + ## _wstart + tdSql.query("select _wstart from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 3s);") + tdSql.checkRows(4) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 5s);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + + tdSql.query("select _wstart from tb_s session(ts, 1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + + tdSql.query("select _wstart,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select sum(c0),_wstart,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wstop + tdSql.query("select _wstop from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 3s);") + tdSql.checkRows(4) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 5s);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select sum(c0),_wstop,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wduration + tdSql.query("select _wduration from tb_s session(ts, 1s);") + tdSql.checkRows(8) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.checkData(6, 1, 0) + tdSql.checkData(7, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 2s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 4000) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 3s);") + tdSql.checkRows(4) + tdSql.checkData(0, 1, 10000) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 18000) + tdSql.checkData(1, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 5s);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 23000) + + tdSql.query("select _wduration from tb_s session(ts, 1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 23000) + + tdSql.query("select _wduration,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 18000) + tdSql.checkData(1, 1, 0) + + tdSql.query("select sum(c0),_wduration,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 2, 18000) + tdSql.checkData(1, 2, 0) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + tdSql.checkData(0, 3, 0) + tdSql.checkData(1, 3, 0) + tdSql.checkData(2, 3, 0) + tdSql.checkData(3, 3, 0) + tdSql.checkData(4, 3, 0) + tdSql.checkData(5, 3, 0) + tdSql.checkData(6, 3, 0) + tdSql.checkData(7, 3, 0) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + tdSql.checkData(0, 3, 0) + tdSql.checkData(1, 3, 0) + tdSql.checkData(2, 3, 0) + tdSql.checkData(3, 3, 0) + tdSql.checkData(4, 3, 0) + tdSql.checkData(5, 3, 0) + tdSql.checkData(6, 3, 0) + tdSql.checkData(7, 3, 0) + + + # db precision "us" + tdSql.execute('use db_u') + + ## _wstart + tdSql.query("select _wstart from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 3s);") + tdSql.checkRows(4) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstart from tb_s session(ts, 5s);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + + tdSql.query("select _wstart from tb_s session(ts, 1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + + tdSql.query("select _wstart,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select sum(c0),_wstart,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wstop + tdSql.query("select _wstop from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 2s);") + tdSql.checkRows(6) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 3s);") + tdSql.checkRows(4) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 5s);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop from tb_s session(ts, 1m);") + tdSql.checkRows(1) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select _wstop,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + tdSql.query("select sum(c0),_wstop,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wduration + tdSql.query("select _wduration from tb_s session(ts, 1s);") + tdSql.checkRows(8) + tdSql.checkData(0, 1, 0) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + tdSql.checkData(6, 1, 0) + tdSql.checkData(7, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 2s);") + tdSql.checkRows(6) + tdSql.checkData(0, 1, 4000000) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + tdSql.checkData(4, 1, 0) + tdSql.checkData(5, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 3s);") + tdSql.checkRows(4) + tdSql.checkData(0, 1, 10000000) + tdSql.checkData(1, 1, 0) + tdSql.checkData(2, 1, 0) + tdSql.checkData(3, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 18000000) + tdSql.checkData(1, 1, 0) + + tdSql.query("select _wduration from tb_s session(ts, 5s);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 23000000) + + tdSql.query("select _wduration from tb_s session(ts, 1m);") + tdSql.checkRows(1) + tdSql.checkData(0, 1, 23000000) + + tdSql.query("select _wduration,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 1, 18000000) + tdSql.checkData(1, 1, 0) + + tdSql.query("select sum(c0),_wduration,avg(c0) from tb_s session(ts, 4s);") + tdSql.checkRows(2) + tdSql.checkData(0, 2, 18000000) + tdSql.checkData(1, 2, 0) + + #_wstart,_wstop,_wduration together + tdSql.query("select _wstart,_wstop,_wduration from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + tdSql.checkData(0, 3, 0) + tdSql.checkData(1, 3, 0) + tdSql.checkData(2, 3, 0) + tdSql.checkData(3, 3, 0) + tdSql.checkData(4, 3, 0) + tdSql.checkData(5, 3, 0) + tdSql.checkData(6, 3, 0) + tdSql.checkData(7, 3, 0) + + tdSql.query("select _wstart,_wstop,_wduration,avg(c0) from tb_s session(ts, 1s);") + tdSql.checkRows(8) + res = tdSql.getData(0, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 1) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + res = tdSql.getData(0, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(5, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(6, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(7, 2) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + tdSql.checkData(0, 3, 0) + tdSql.checkData(1, 3, 0) + tdSql.checkData(2, 3, 0) + tdSql.checkData(3, 3, 0) + tdSql.checkData(4, 3, 0) + tdSql.checkData(5, 3, 0) + tdSql.checkData(6, 3, 0) + tdSql.checkData(7, 3, 0) + + print("============== STEP 4: select _wsatrt,_wstop,_wduration in nested outer query ================== ") + tdSql.execute('use db_m') + ##_wstart + tdSql.query('select _wstart from (select _wstart from tb_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query('select _wstart from (select _wstart from ctb1_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + tdSql.query('select _wstart from (select _wstart from stb_i interval (2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:00") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:02") + res = tdSql.getData(5, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:04") + + tdSql.query('select _wstart from (select _wstart from tb_w state_window(c0))') + tdSql.checkRows(5) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:02") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:06") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query('select _wstart from (select _wstart from tb_s session(ts, 2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:00") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wstop + tdSql.query('select _wstop from (select _wstop from tb_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query('select _wstop from (select _wstop from ctb1_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + tdSql.query('select _wstop from (select _wstop from stb_i interval (2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01.999000") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:03.999000") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05.999000") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:01.999000") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:03.999000") + res = tdSql.getData(5, 0) + tdSql.checkEqual(str(res), "2022-02-02 03:00:05.999000") + + tdSql.query('select _wstop from (select _wstop from tb_w state_window(c0))') + tdSql.checkRows(5) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:01") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:05") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:08") + + tdSql.query('select _wstop from (select _wstop from tb_s session(ts, 2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + res = tdSql.getData(0, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:04") + res = tdSql.getData(1, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:07") + res = tdSql.getData(2, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:10") + res = tdSql.getData(3, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:14") + res = tdSql.getData(4, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:18") + res = tdSql.getData(5, 0) + tdSql.checkEqual(str(res), "2022-02-02 02:00:23") + + ##_wduration + tdSql.query('select _wduration from (select _wduration from tb_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + tdSql.checkData(0, 0, 1999) + tdSql.checkData(1, 0, 1999) + tdSql.checkData(2, 0, 1999) + tdSql.query('select _wduration from (select _wduration from ctb1_i interval (2s))') + tdSql.checkRows(3) + tdSql.checkCols(1) + tdSql.checkData(0, 0, 1999) + tdSql.checkData(1, 0, 1999) + tdSql.checkData(2, 0, 1999) + tdSql.query('select _wduration from (select _wduration from stb_i interval (2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + tdSql.checkData(0, 0, 1999) + tdSql.checkData(1, 0, 1999) + tdSql.checkData(2, 0, 1999) + tdSql.checkData(3, 0, 1999) + tdSql.checkData(4, 0, 1999) + tdSql.checkData(5, 0, 1999) + + tdSql.query('select _wduration from (select _wduration from tb_w state_window(c0))') + tdSql.checkRows(5) + tdSql.checkCols(1) + tdSql.checkData(0, 0, 1000) + tdSql.checkData(1, 0, 2000) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 1000) + tdSql.checkData(4, 0, 0) + + tdSql.query('select _wduration from (select _wduration from tb_s session(ts, 2s))') + tdSql.checkRows(6) + tdSql.checkCols(1) + tdSql.checkData(0, 0, 4000) + tdSql.checkData(1, 0, 0) + tdSql.checkData(2, 0, 0) + tdSql.checkData(3, 0, 0) + tdSql.checkData(4, 0, 0) + tdSql.checkData(5, 0, 0) + + print("============== STEP 5: select _wstart/_wstop/_wduration other cases ================== ") + + #distinct + tdSql.query("select distinct _wstart from tb_i interval (1s)") + tdSql.query("select distinct _wstart from ctb1_i interval (1s)") + tdSql.query("select distinct _wstart from stb_i interval (1s)") + + tdSql.query("select distinct _wstop from tb_i interval (1s)") + tdSql.query("select distinct _wstop from ctb1_i interval (1s)") + tdSql.query("select distinct _wstop from stb_i interval (1s)") + + tdSql.query("select distinct _wduration from tb_i interval (1s)") + tdSql.query("select distinct _wduration from ctb1_i interval (1s)") + tdSql.query("select distinct _wduration from stb_i interval (1s)") + + #_ws,col + tdSql.query("select _wstart,ts from tb_i interval (1s)") + tdSql.query("select _wstart,ts from ctb1_i interval (1s)") + tdSql.query("select _wstart,ts from stb_i interval (1s)") + #tdSql.query("select _wstart,c0 from tb_i interval (1s)") + #tdSql.query("select _wstart,c0 from ctb1_i interval (1s)") + #tdSql.query("select _wstart,c0 from stb_i interval (1s)") + tdSql.query("select _wstart,_wstart from tb_i interval (1s)") + tdSql.query("select _wstart,_wstart from ctb1_i interval (1s)") + tdSql.query("select _wstart,_wstart from stb_i interval (1s)") + tdSql.query("select _wstart,t0 from ctb1_i interval (1s)") + tdSql.query("select _wstart,t0 from stb_i interval (1s)") + + tdSql.query("select _wstop,ts from tb_i interval (1s)") + tdSql.query("select _wstop,ts from ctb1_i interval (1s)") + tdSql.query("select _wstop,ts from stb_i interval (1s)") + #tdSql.query("select _wstop,c0 from tb_i interval (1s)") + #tdSql.query("select _wstop,c0 from ctb1_i interval (1s)") + #tdSql.query("select _wstop,c0 from stb_i interval (1s)") + tdSql.query("select _wstop,_wstop from tb_i interval (1s)") + tdSql.query("select _wstop,_wstop from ctb1_i interval (1s)") + tdSql.query("select _wstop,_wstop from stb_i interval (1s)") + tdSql.query("select _wstop,t0 from ctb1_i interval (1s)") + tdSql.query("select _wstop,t0 from stb_i interval (1s)") + + tdSql.query("select _wduration,ts from tb_i interval (1s)") + tdSql.query("select _wduration,ts from ctb1_i interval (1s)") + tdSql.query("select _wduration,ts from stb_i interval (1s)") + #tdSql.query("select _wduration,c0 from tb_i interval (1s)") + #tdSql.query("select _wduration,c0 from ctb1_i interval (1s)") + #tdSql.query("select _wduration,c0 from stb_i interval (1s)") + tdSql.query("select _wduration,_wduration from tb_i interval (1s)") + tdSql.query("select _wduration,_wduration from ctb1_i interval (1s)") + tdSql.query("select _wduration,_wduration from stb_i interval (1s)") + tdSql.query("select _wduration,t0 from ctb1_i interval (1s)") + tdSql.query("select _wduration,t0 from stb_i interval (1s)") + + #_ws,constant + tdSql.query("select _wstart,1 from tb_i interval (1s)") + tdSql.query("select _wstart,1 from ctb1_i interval (1s)") + tdSql.query("select _wstart,1 from stb_i interval (1s)") + tdSql.query("select _wstart,true from tb_i interval (1s)") + tdSql.query("select _wstart,true from ctb1_i interval (1s)") + tdSql.query("select _wstart,true from stb_i interval (1s)") + tdSql.query("select _wstart,'abc' from tb_i interval (1s)") + tdSql.query("select _wstart,'abc' from ctb1_i interval (1s)") + tdSql.query("select _wstart,'abc' from stb_i interval (1s)") + + tdSql.query("select _wstop,1 from tb_i interval (1s)") + tdSql.query("select _wstop,1 from ctb1_i interval (1s)") + tdSql.query("select _wstop,1 from stb_i interval (1s)") + tdSql.query("select _wstop,true from tb_i interval (1s)") + tdSql.query("select _wstop,true from ctb1_i interval (1s)") + tdSql.query("select _wstop,true from stb_i interval (1s)") + tdSql.query("select _wstop,'abc' from tb_i interval (1s)") + tdSql.query("select _wstop,'abc' from ctb1_i interval (1s)") + tdSql.query("select _wstop,'abc' from stb_i interval (1s)") + + tdSql.query("select _wduration,1 from tb_i interval (1s)") + tdSql.query("select _wduration,1 from ctb1_i interval (1s)") + tdSql.query("select _wduration,1 from stb_i interval (1s)") + tdSql.query("select _wduration,true from tb_i interval (1s)") + tdSql.query("select _wduration,true from ctb1_i interval (1s)") + tdSql.query("select _wduration,true from stb_i interval (1s)") + tdSql.query("select _wduration,'abc' from tb_i interval (1s)") + tdSql.query("select _wduration,'abc' from ctb1_i interval (1s)") + tdSql.query("select _wduration,'abc' from stb_i interval (1s)") + + #interval sliding + tdSql.query("select _wstart from tb_i interval (1s) sliding (1s)") + tdSql.query("select _wstart from ctb1_i interval (1s) sliding (1s)") + tdSql.query("select _wstart from stb_i interval (1s) sliding (1s)") + + tdSql.query("select _wstop from tb_i interval (1s) sliding (1s)") + tdSql.query("select _wstop from ctb1_i interval (1s) sliding (1s)") + tdSql.query("select _wstop from stb_i interval (1s) sliding (1s)") + + tdSql.query("select _wduration from tb_i interval (1s) sliding (1s)") + tdSql.query("select _wduration from ctb1_i interval (1s) sliding (1s)") + tdSql.query("select _wduration from stb_i interval (1s) sliding (1s)") + + #group by + tdSql.query("select _wstart from stb_i interval (1s) group by tbname") + + tdSql.query("select _wstop from stb_i interval (1s) group by tbname") + + tdSql.query("select _wduration from stb_i interval (1s) group by tbname") + + #order by + tdSql.query("select _wstart from tb_i interval (1s) order by ts") + tdSql.query("select _wstart from ctb1_i interval (1s) order by ts") + tdSql.query("select _wstart from stb_i interval (1s) order by ts") + tdSql.query("select _wstart from tb_i interval (1s) order by ts desc") + tdSql.query("select _wstart from ctb1_i interval (1s) order by ts desc") + tdSql.query("select _wstart from stb_i interval (1s) order by ts desc") + + tdSql.query("select _wstop from tb_i interval (1s) order by ts") + tdSql.query("select _wstop from ctb1_i interval (1s) order by ts") + tdSql.query("select _wstop from stb_i interval (1s) order by ts") + tdSql.query("select _wstop from tb_i interval (1s) order by ts desc") + tdSql.query("select _wstop from ctb1_i interval (1s) order by ts desc") + tdSql.query("select _wstop from stb_i interval (1s) order by ts desc") + + + tdSql.query("select _wduration from tb_i interval (1s) order by ts") + tdSql.query("select _wduration from ctb1_i interval (1s) order by ts") + tdSql.query("select _wduration from stb_i interval (1s) order by ts") + tdSql.query("select _wduration from tb_i interval (1s) order by ts desc") + tdSql.query("select _wduration from ctb1_i interval (1s) order by ts desc") + tdSql.query("select _wduration from stb_i interval (1s) order by ts desc") + + #limit + tdSql.query("select _wstart from tb_i interval (1s) limit 3") + tdSql.query("select _wstart from ctb1_i interval (1s) limit 3") + tdSql.query("select _wstart from stb_i interval (1s) limit 3") + + tdSql.query("select _wstop from tb_i interval (1s) limit 3") + tdSql.query("select _wstop from ctb1_i interval (1s) limit 3") + tdSql.query("select _wstop from stb_i interval (1s) limit 3") + + + tdSql.query("select _wduration from tb_i interval (1s) limit 3") + tdSql.query("select _wduration from ctb1_i interval (1s) limit 3") + tdSql.query("select _wduration from stb_i interval (1s) limit 3") + + ############# not supported ############### + tdSql.error("select _wstart from tb_i") + tdSql.error("select _wstart from ctb1_i") + tdSql.error("select _wstart from stb_i") + tdSql.error("select _wstart + 1 from tb_i interval (1s)") + tdSql.error("select _wstart + 1 from ctb1_i interval (1s)") + tdSql.error("select _wstart + 1 from stb_i interval (1s)") + tdSql.error("select _wstart + 1.0 from tb_i interval (1s)") + tdSql.error("select _wstart + 1.0 from ctb1_i interval (1s)") + tdSql.error("select _wstart + 1.0 from stb_i interval (1s)") + tdSql.error("select _wstart + true from tb_i interval (1s)") + tdSql.error("select _wstart + true from ctb1_i interval (1s)") + tdSql.error("select _wstart + true from stb_i interval (1s)") + tdSql.error("select _wstart + 'abc' from tb_i interval (1s)") + tdSql.error("select _wstart + 'abc' from ctb1_i interval (1s)") + tdSql.error("select _wstart + 'abc' from stb_i interval (1s)") + tdSql.error("select _wstart + 1s from tb_i interval (1s)") + tdSql.error("select _wstart + 1s from ctb1_i interval (1s)") + tdSql.error("select _wstart + 1s from stb_i interval (1s)") + tdSql.error("select _wstart + ts from tb_i interval (1s)") + tdSql.error("select _wstart + ts from ctb1_i interval (1s)") + tdSql.error("select _wstart + ts from stb_i interval (1s)") + tdSql.error("select _wstart + c0 from tb_i interval (1s)") + tdSql.error("select _wstart + c0 from ctb1_i interval (1s)") + tdSql.error("select _wstart + c0 from stb_i interval (1s)") + tdSql.error("select _wstart + _wstop from tb_i interval (1s)") + tdSql.error("select _wstart + _wstop from ctb1_i interval (1s)") + tdSql.error("select _wstart + _wstop from stb_i interval (1s)") + tdSql.error("select _wstart + _wduration from tb_i interval (1s)") + tdSql.error("select _wstart + _wduration from ctb1_i interval (1s)") + tdSql.error("select _wstart + _wduration from stb_i interval (1s)") + + tdSql.error("select _wstop from tb_i") + tdSql.error("select _wstop from ctb1_i") + tdSql.error("select _wstop from stb_i") + tdSql.error("select _wstop + 1 from tb_i interval (1s)") + tdSql.error("select _wstop + 1 from ctb1_i interval (1s)") + tdSql.error("select _wstop + 1 from stb_i interval (1s)") + tdSql.error("select _wstop + 1.0 from tb_i interval (1s)") + tdSql.error("select _wstop + 1.0 from ctb1_i interval (1s)") + tdSql.error("select _wstop + 1.0 from stb_i interval (1s)") + tdSql.error("select _wstop + true from tb_i interval (1s)") + tdSql.error("select _wstop + true from ctb1_i interval (1s)") + tdSql.error("select _wstop + true from stb_i interval (1s)") + tdSql.error("select _wstop + 'abc' from tb_i interval (1s)") + tdSql.error("select _wstop + 'abc' from ctb1_i interval (1s)") + tdSql.error("select _wstop + 'abc' from stb_i interval (1s)") + tdSql.error("select _wstop + 1s from tb_i interval (1s)") + tdSql.error("select _wstop + 1s from ctb1_i interval (1s)") + tdSql.error("select _wstop + 1s from stb_i interval (1s)") + tdSql.error("select _wstop + ts from tb_i interval (1s)") + tdSql.error("select _wstop + ts from ctb1_i interval (1s)") + tdSql.error("select _wstop + ts from stb_i interval (1s)") + tdSql.error("select _wstop + c0 from tb_i interval (1s)") + tdSql.error("select _wstop + c0 from ctb1_i interval (1s)") + tdSql.error("select _wstop + c0 from stb_i interval (1s)") + tdSql.error("select _wstop + _wstart from tb_i interval (1s)") + tdSql.error("select _wstop + _wstart from ctb1_i interval (1s)") + tdSql.error("select _wstop + _wstart from stb_i interval (1s)") + tdSql.error("select _wstop + _wduration from tb_i interval (1s)") + tdSql.error("select _wstop + _wduration from ctb1_i interval (1s)") + tdSql.error("select _wstop + _wduration from stb_i interval (1s)") + + tdSql.error("select _wduration from tb_i") + tdSql.error("select _wduration from ctb1_i") + tdSql.error("select _wduration from stb_i") + tdSql.error("select _wduration + 1 from tb_i interval (1s)") + tdSql.error("select _wduration + 1 from ctb1_i interval (1s)") + tdSql.error("select _wduration + 1 from stb_i interval (1s)") + tdSql.error("select _wduration + 1.0 from tb_i interval (1s)") + tdSql.error("select _wduration + 1.0 from ctb1_i interval (1s)") + tdSql.error("select _wduration + 1.0 from stb_i interval (1s)") + tdSql.error("select _wduration + true from tb_i interval (1s)") + tdSql.error("select _wduration + true from ctb1_i interval (1s)") + tdSql.error("select _wduration + true from stb_i interval (1s)") + tdSql.error("select _wduration + 'abc' from tb_i interval (1s)") + tdSql.error("select _wduration + 'abc' from ctb1_i interval (1s)") + tdSql.error("select _wduration + 'abc' from stb_i interval (1s)") + tdSql.error("select _wduration + 1s from tb_i interval (1s)") + tdSql.error("select _wduration + 1s from ctb1_i interval (1s)") + tdSql.error("select _wduration + 1s from stb_i interval (1s)") + tdSql.error("select _wduration + ts from tb_i interval (1s)") + tdSql.error("select _wduration + ts from ctb1_i interval (1s)") + tdSql.error("select _wduration + ts from stb_i interval (1s)") + tdSql.error("select _wduration + c0 from tb_i interval (1s)") + tdSql.error("select _wduration + c0 from ctb1_i interval (1s)") + tdSql.error("select _wduration + c0 from stb_i interval (1s)") + tdSql.error("select _wduration + _wstart from tb_i interval (1s)") + tdSql.error("select _wduration + _wstart from ctb1_i interval (1s)") + tdSql.error("select _wduration + _wstart from stb_i interval (1s)") + tdSql.error("select _wduration + _wduration from tb_i interval (1s)") + tdSql.error("select _wduration + _wduration from ctb1_i interval (1s)") + tdSql.error("select _wduration + _wduration from stb_i interval (1s)") + + + tdSql.execute('drop database db_m') + tdSql.execute('drop database db_u') + tdSql.execute('drop database db_n') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 952b6ab7efabfe7c5d56a874942c842ba7c4a7c3..7a83fddaa6343c7fd050d5241634bc70c0b2c789 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -711,6 +711,7 @@ 5,,develop-test,python3 ./test.py -f 2-query/function_timezone.py 5,,develop-test,python3 ./test.py -f 2-query/function_to_iso8601.py 5,,develop-test,python3 ./test.py -f 2-query/function_to_unixtimestamp.py +5,,develop-test,python3 ./test.py -f 2-query/time_window_keywords.py 4,,system-test,python3 test.py -f 4-taosAdapter/TD-12163.py 4,,system-test,python3 ./test.py -f 3-connectors/restful/restful_binddbname.py 4,,system-test,python3 ./test.py -f 2-query/TD-12614.py