@@ -1268,6 +1268,21 @@ static int32_t sclCalcStreamExtWinsTimeRange(SScalarCtx *ctx, SOperator
12681268 int32_t code = 0 ;
12691269 int64_t timeValue = 0 ;
12701270 SNode * pNode = NULL ;
1271+ int64_t * pTsValList = NULL ;
1272+ int32_t tsValRows = 0 ;
1273+ int32_t winNum = 0 ;
1274+
1275+ if (!ctx -> stream .pStreamRuntimeFuncInfo || !ctx -> stream .pStreamRuntimeFuncInfo -> pStreamPesudoFuncVals ) {
1276+ sclError ("invalid stream runtime func info for ext window range calc" );
1277+ return TSDB_CODE_QRY_INVALID_INPUT ;
1278+ }
1279+
1280+ winNum = taosArrayGetSize (ctx -> stream .pStreamRuntimeFuncInfo -> pStreamPesudoFuncVals );
1281+ if (winNum <= 0 ) {
1282+ sclError ("invalid ext window count:%d" , winNum );
1283+ return TSDB_CODE_QRY_INVALID_INPUT ;
1284+ }
1285+
12711286 if (sclIsPrimTimeStampCol (node -> pRight )) {
12721287 pNode = node -> pLeft ;
12731288 } else if (sclIsPrimTimeStampCol (node -> pLeft )) {
@@ -1278,29 +1293,49 @@ static int32_t sclCalcStreamExtWinsTimeRange(SScalarCtx *ctx, SOperator
12781293 return TSDB_CODE_STREAM_INTERNAL_ERROR ;
12791294 }
12801295
1281- SScalarParam * res = (SScalarParam * )taosHashGet (ctx -> pRes , (void * )& pNode , POINTER_BYTES );
1282- if (res == NULL || res -> columnData == NULL ) {
1283- sclError ("no result for node, type:%d, node:%p" , nodeType (pNode ), pNode );
1284- return TSDB_CODE_QRY_INVALID_INPUT ;
1285- }
1286- if (res -> columnData -> pData == NULL ) {
1287- sclError ("invalid column data for ts range expr, type:%d, node:%p" , res -> columnData -> info .type , pNode );
1288- return TSDB_CODE_QRY_INVALID_INPUT ;
1289- }
1290- if (res -> columnData -> info .type != TSDB_DATA_TYPE_TIMESTAMP ) {
1291- sclError ("invalid type for ts range expr, type:%d, node:%p" , res -> columnData -> info .type , pNode );
1292- return TSDB_CODE_QRY_INVALID_INPUT ;
1296+ if (nodeType (pNode ) == QUERY_NODE_VALUE ) {
1297+ SValueNode * pVal = (SValueNode * )pNode ;
1298+ if (!IS_INTEGER_TYPE (pVal -> node .resType .type ) && !IS_TIMESTAMP_TYPE (pVal -> node .resType .type )) {
1299+ sclError ("invalid value type for ts range expr, type:%d, node:%p" , pVal -> node .resType .type , pNode );
1300+ return TSDB_CODE_QRY_INVALID_INPUT ;
1301+ }
1302+ timeValue = pVal -> datum .i ;
1303+ pTsValList = & timeValue ;
1304+ tsValRows = 1 ;
1305+ } else {
1306+ SScalarParam * res = (SScalarParam * )taosHashGet (ctx -> pRes , (void * )& pNode , POINTER_BYTES );
1307+ if (res == NULL || res -> columnData == NULL ) {
1308+ sclError ("no result for node, type:%d, node:%p" , nodeType (pNode ), pNode );
1309+ return TSDB_CODE_QRY_INVALID_INPUT ;
1310+ }
1311+ if (res -> columnData -> pData == NULL ) {
1312+ sclError ("invalid column data for ts range expr, type:%d, node:%p" , res -> columnData -> info .type , pNode );
1313+ return TSDB_CODE_QRY_INVALID_INPUT ;
1314+ }
1315+ if (res -> columnData -> info .type != TSDB_DATA_TYPE_TIMESTAMP ) {
1316+ sclError ("invalid type for ts range expr, type:%d, node:%p" , res -> columnData -> info .type , pNode );
1317+ return TSDB_CODE_QRY_INVALID_INPUT ;
1318+ }
1319+
1320+ pTsValList = (int64_t * )res -> columnData -> pData ;
1321+ tsValRows = res -> numOfRows ;
1322+ if (tsValRows != 1 && tsValRows != winNum ) {
1323+ sclError ("invalid ts range rows:%d, ext window count:%d, node:%p" , tsValRows , winNum , pNode );
1324+ return TSDB_CODE_QRY_INVALID_INPUT ;
1325+ }
12931326 }
12941327
12951328 if (1 == ctx -> stream .extWinType ) {
12961329 if (node -> opType == OP_TYPE_GREATER_THAN ) {
1297- for (int32_t i = 0 ; i < res -> numOfRows ; ++ i ) {
1298- ctx -> stream .pWins [i ].tw .skey = (-1 == ctx -> stream .pWins [i ].winOutIdx ) ? TMAX (((int64_t * )res -> columnData -> pData )[i ] + 1 , ctx -> stream .pWins [i ].tw .skey ) : (((int64_t * )res -> columnData -> pData )[i ] + 1 );
1330+ for (int32_t i = 0 ; i < winNum ; ++ i ) {
1331+ int64_t tsVal = pTsValList [(tsValRows == 1 ) ? 0 : i ];
1332+ ctx -> stream .pWins [i ].tw .skey = (-1 == ctx -> stream .pWins [i ].winOutIdx ) ? TMAX (tsVal + 1 , ctx -> stream .pWins [i ].tw .skey ) : (tsVal + 1 );
12991333 ctx -> stream .pWins [i ].winOutIdx = -1 ;
13001334 }
13011335 } else if (node -> opType == OP_TYPE_GREATER_EQUAL ) {
1302- for (int32_t i = 0 ; i < res -> numOfRows ; ++ i ) {
1303- ctx -> stream .pWins [i ].tw .skey = (-1 == ctx -> stream .pWins [i ].winOutIdx ) ? TMAX (((int64_t * )res -> columnData -> pData )[i ], ctx -> stream .pWins [i ].tw .skey ) : (((int64_t * )res -> columnData -> pData )[i ]);
1336+ for (int32_t i = 0 ; i < winNum ; ++ i ) {
1337+ int64_t tsVal = pTsValList [(tsValRows == 1 ) ? 0 : i ];
1338+ ctx -> stream .pWins [i ].tw .skey = (-1 == ctx -> stream .pWins [i ].winOutIdx ) ? TMAX (tsVal , ctx -> stream .pWins [i ].tw .skey ) : tsVal ;
13041339 ctx -> stream .pWins [i ].winOutIdx = -1 ;
13051340 }
13061341 } else {
@@ -1313,13 +1348,15 @@ static int32_t sclCalcStreamExtWinsTimeRange(SScalarCtx *ctx, SOperator
13131348 //if (ctx->stream.pStreamRuntimeFuncInfo->triggerType != STREAM_TRIGGER_SLIDING) {
13141349 // consider triggerType and keep the ekey exclude
13151350 if (node -> opType == OP_TYPE_LOWER_THAN ) {
1316- for (int32_t i = 0 ; i < res -> numOfRows ; ++ i ) {
1317- ctx -> stream .pWins [i ].tw .ekey = (-2 == ctx -> stream .pWins [i ].winOutIdx ) ? TMIN (((int64_t * )res -> columnData -> pData )[i ], ctx -> stream .pWins [i ].tw .ekey ) : (((int64_t * )res -> columnData -> pData )[i ]);
1351+ for (int32_t i = 0 ; i < winNum ; ++ i ) {
1352+ int64_t tsVal = pTsValList [(tsValRows == 1 ) ? 0 : i ];
1353+ ctx -> stream .pWins [i ].tw .ekey = (-2 == ctx -> stream .pWins [i ].winOutIdx ) ? TMIN (tsVal , ctx -> stream .pWins [i ].tw .ekey ) : tsVal ;
13181354 ctx -> stream .pWins [i ].winOutIdx = -2 ;
13191355 }
13201356 } else if (node -> opType == OP_TYPE_LOWER_EQUAL ) {
1321- for (int32_t i = 0 ; i < res -> numOfRows ; ++ i ) {
1322- ctx -> stream .pWins [i ].tw .ekey = (-2 == ctx -> stream .pWins [i ].winOutIdx ) ? TMIN (((int64_t * )res -> columnData -> pData )[i ] + 1 , ctx -> stream .pWins [i ].tw .ekey ) : (((int64_t * )res -> columnData -> pData )[i ] + 1 );
1357+ for (int32_t i = 0 ; i < winNum ; ++ i ) {
1358+ int64_t tsVal = pTsValList [(tsValRows == 1 ) ? 0 : i ];
1359+ ctx -> stream .pWins [i ].tw .ekey = (-2 == ctx -> stream .pWins [i ].winOutIdx ) ? TMIN (tsVal + 1 , ctx -> stream .pWins [i ].tw .ekey ) : (tsVal + 1 );
13231360 ctx -> stream .pWins [i ].winOutIdx = -2 ;
13241361 }
13251362 } else {
0 commit comments