From 71e5094f83cb13448d680d38ccd18de3623abce8 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 8 Mar 2022 14:22:21 +0800 Subject: [PATCH] [TD-11216]: Time window related keywords --- src/client/src/tscSQLParser.c | 17 ++--------------- src/query/inc/qAggMain.h | 2 ++ src/query/src/qAggMain.c | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 9ee4397662..df46bd8786 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -2516,21 +2516,8 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7); } colSchema = *tGetTimeWindowColumnSchema(index.columnIndex); - switch (index.columnIndex) { - case TSDB_TSWIN_START_COLUMN_INDEX: { - functionId = TSDB_FUNC_WSTART; - break; - } - case TSDB_TSWIN_STOP_COLUMN_INDEX: { - functionId = TSDB_FUNC_WSTOP; - break; - } - case TSDB_TSWIN_DURATION_COLUMN_INDEX: { - functionId = TSDB_FUNC_WDURATION; - break; - } - } - colType = TSDB_COL_NORMAL; + functionId = getTimeWindowFunctionID(index.columnIndex); + colType = TSDB_COL_NORMAL; } char name[TSDB_COL_NAME_LEN] = {0}; getColumnName(pItem, name, colSchema.name, sizeof(colSchema.name) - 1); diff --git a/src/query/inc/qAggMain.h b/src/query/inc/qAggMain.h index b48489b87b..3eb542cb4c 100644 --- a/src/query/inc/qAggMain.h +++ b/src/query/inc/qAggMain.h @@ -233,6 +233,8 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI 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); + #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 05067a668a..1ebee07036 100644 --- a/src/query/src/qAggMain.c +++ b/src/query/src/qAggMain.c @@ -5627,6 +5627,22 @@ static void tail_func_finalizer(SQLFunctionCtx *pCtx) { doFinalizer(pCtx); } +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; -- GitLab