[TD-2236]<fix>: fix bugs in groupby normal colunms + last query
This commit is contained in:
parent
b8f38e0568
commit
7d22ca3fb9
|
@ -54,8 +54,8 @@
|
||||||
|
|
||||||
#define DO_UPDATE_TAG_COLUMNS(ctx, ts) \
|
#define DO_UPDATE_TAG_COLUMNS(ctx, ts) \
|
||||||
do { \
|
do { \
|
||||||
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
|
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
|
||||||
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
|
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
|
||||||
if (__ctx->functionId == TSDB_FUNC_TS_DUMMY) { \
|
if (__ctx->functionId == TSDB_FUNC_TS_DUMMY) { \
|
||||||
__ctx->tag.i64Key = (ts); \
|
__ctx->tag.i64Key = (ts); \
|
||||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT; \
|
||||||
|
@ -66,8 +66,8 @@
|
||||||
|
|
||||||
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
#define DO_UPDATE_TAG_COLUMNS_WITHOUT_TS(ctx) \
|
||||||
do { \
|
do { \
|
||||||
for (int32_t i = 0; i < (ctx)->tagInfo.numOfTagCols; ++i) { \
|
for (int32_t _i = 0; _i < (ctx)->tagInfo.numOfTagCols; ++_i) { \
|
||||||
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[i]; \
|
SQLFunctionCtx *__ctx = (ctx)->tagInfo.pTagCtxList[_i]; \
|
||||||
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
|
aAggs[TSDB_FUNC_TAG].xFunction(__ctx); \
|
||||||
} \
|
} \
|
||||||
} while (0);
|
} while (0);
|
||||||
|
@ -305,7 +305,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
|
||||||
} else if (functionId == TSDB_FUNC_FIRST || functionId == TSDB_FUNC_LAST) {
|
} else if (functionId == TSDB_FUNC_FIRST || functionId == TSDB_FUNC_LAST) {
|
||||||
*type = (int16_t)dataType;
|
*type = (int16_t)dataType;
|
||||||
*bytes = (int16_t)dataBytes;
|
*bytes = (int16_t)dataBytes;
|
||||||
*interBytes = dataBytes;
|
*interBytes = (int16_t)(dataBytes + sizeof(SFirstLastInfo));
|
||||||
} else if (functionId == TSDB_FUNC_SPREAD) {
|
} else if (functionId == TSDB_FUNC_SPREAD) {
|
||||||
*type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
|
*type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
|
||||||
*bytes = sizeof(double);
|
*bytes = sizeof(double);
|
||||||
|
@ -1169,8 +1169,8 @@ static int32_t minmax_merge_impl(SQLFunctionCtx *pCtx, int32_t bytes, char *outp
|
||||||
if ((*(int32_t *)output < v) ^ isMin) {
|
if ((*(int32_t *)output < v) ^ isMin) {
|
||||||
*(int32_t *)output = v;
|
*(int32_t *)output = v;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pCtx->tagInfo.numOfTagCols; ++i) {
|
for (int32_t j = 0; j < pCtx->tagInfo.numOfTagCols; ++j) {
|
||||||
SQLFunctionCtx *__ctx = pCtx->tagInfo.pTagCtxList[i];
|
SQLFunctionCtx *__ctx = pCtx->tagInfo.pTagCtxList[j];
|
||||||
aAggs[TSDB_FUNC_TAG].xFunction(__ctx);
|
aAggs[TSDB_FUNC_TAG].xFunction(__ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1680,6 +1680,12 @@ static void last_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the scan order is not the required order, ignore it
|
||||||
|
if (pCtx->order != pCtx->param[0].i64Key) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCtx->order == TSDB_ORDER_DESC) {
|
||||||
SET_VAL(pCtx, 1, 1);
|
SET_VAL(pCtx, 1, 1);
|
||||||
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
|
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
|
||||||
|
|
||||||
|
@ -1689,6 +1695,19 @@ static void last_function_f(SQLFunctionCtx *pCtx, int32_t index) {
|
||||||
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
SResultRowCellInfo *pResInfo = GET_RES_INFO(pCtx);
|
||||||
pResInfo->hasResult = DATA_SET_FLAG;
|
pResInfo->hasResult = DATA_SET_FLAG;
|
||||||
pResInfo->complete = true; // set query completed
|
pResInfo->complete = true; // set query completed
|
||||||
|
} else { // in case of ascending order check, all data needs to be checked
|
||||||
|
SResultRowCellInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||||
|
TSKEY ts = pCtx->ptsList[index];
|
||||||
|
|
||||||
|
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
if (pResInfo->hasResult != DATA_SET_FLAG || (*(TSKEY*)buf) < ts) {
|
||||||
|
pResInfo->hasResult = DATA_SET_FLAG;
|
||||||
|
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
|
||||||
|
|
||||||
|
*(TSKEY*)buf = ts;
|
||||||
|
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t index) {
|
static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t index) {
|
||||||
|
@ -1711,7 +1730,7 @@ static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t ind
|
||||||
|
|
||||||
static void last_dist_function(SQLFunctionCtx *pCtx) {
|
static void last_dist_function(SQLFunctionCtx *pCtx) {
|
||||||
/*
|
/*
|
||||||
* 1. for scan data in asc order, no need to check data
|
* 1. for scan data is not the required order
|
||||||
* 2. for data blocks that are not loaded, no need to check data
|
* 2. for data blocks that are not loaded, no need to check data
|
||||||
*/
|
*/
|
||||||
if (pCtx->order != pCtx->param[0].i64Key) {
|
if (pCtx->order != pCtx->param[0].i64Key) {
|
||||||
|
|
Loading…
Reference in New Issue