refactor: do some internal refactor.
This commit is contained in:
parent
92276bfa87
commit
211985f03e
|
@ -88,8 +88,6 @@ typedef struct {
|
||||||
#pragma pack(push, 1)
|
#pragma pack(push, 1)
|
||||||
typedef struct SColumnDataAgg {
|
typedef struct SColumnDataAgg {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
int16_t minIndex;
|
|
||||||
int16_t maxIndex;
|
|
||||||
int16_t numOfNull;
|
int16_t numOfNull;
|
||||||
int64_t sum;
|
int64_t sum;
|
||||||
int64_t max;
|
int64_t max;
|
||||||
|
|
|
@ -2801,11 +2801,11 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SColumnDataAgg*** pBlockS
|
||||||
if (pAgg->colId == pSup->colIds[j]) {
|
if (pAgg->colId == pSup->colIds[j]) {
|
||||||
if (IS_BSMA_ON(&(pReader->pSchema->columns[i]))) {
|
if (IS_BSMA_ON(&(pReader->pSchema->columns[i]))) {
|
||||||
pSup->plist[j] = pAgg;
|
pSup->plist[j] = pAgg;
|
||||||
i += 1;
|
|
||||||
j += 1;
|
|
||||||
} else {
|
} else {
|
||||||
*allHave = false;
|
*allHave = false;
|
||||||
}
|
}
|
||||||
|
i += 1;
|
||||||
|
j += 1;
|
||||||
} else if (pAgg->colId < pSup->colIds[j]) {
|
} else if (pAgg->colId < pSup->colIds[j]) {
|
||||||
i += 1;
|
i += 1;
|
||||||
} else if (pSup->colIds[j] < pAgg->colId) {
|
} else if (pSup->colIds[j] < pAgg->colId) {
|
||||||
|
|
|
@ -741,10 +741,10 @@ static int32_t doCreateConstantValColumnAggInfo(SInputColumnInfoData* pInput, SF
|
||||||
|
|
||||||
if (type == TSDB_DATA_TYPE_BIGINT) {
|
if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||||
int64_t v = pFuncParam->param.i;
|
int64_t v = pFuncParam->param.i;
|
||||||
*da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .maxIndex = 0, .minIndex = 0, .sum = v * numOfRows};
|
*da = (SColumnDataAgg){.numOfNull = 0, .min = v, .max = v, .sum = v * numOfRows};
|
||||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||||
double v = pFuncParam->param.d;
|
double v = pFuncParam->param.d;
|
||||||
*da = (SColumnDataAgg){.numOfNull = 0, .maxIndex = 0, .minIndex = 0};
|
*da = (SColumnDataAgg){.numOfNull = 0};
|
||||||
|
|
||||||
*(double*)&da->min = v;
|
*(double*)&da->min = v;
|
||||||
*(double*)&da->max = v;
|
*(double*)&da->max = v;
|
||||||
|
@ -752,7 +752,7 @@ static int32_t doCreateConstantValColumnAggInfo(SInputColumnInfoData* pInput, SF
|
||||||
} else if (type == TSDB_DATA_TYPE_BOOL) { // todo validate this data type
|
} else if (type == TSDB_DATA_TYPE_BOOL) { // todo validate this data type
|
||||||
bool v = pFuncParam->param.i;
|
bool v = pFuncParam->param.i;
|
||||||
|
|
||||||
*da = (SColumnDataAgg){.numOfNull = 0, .maxIndex = 0, .minIndex = 0};
|
*da = (SColumnDataAgg){.numOfNull = 0};
|
||||||
*(bool*)&da->min = 0;
|
*(bool*)&da->min = 0;
|
||||||
*(bool*)&da->max = v;
|
*(bool*)&da->max = v;
|
||||||
*(bool*)&da->sum = v * numOfRows;
|
*(bool*)&da->sum = v * numOfRows;
|
||||||
|
|
|
@ -1080,6 +1080,19 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||||
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||||
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||||
|
|
||||||
|
static int32_t findRowIndex(int32_t start, int32_t num, SColumnInfoData* pCol, const char* tval) {
|
||||||
|
// the data is loaded, not only the block SMA value
|
||||||
|
for(int32_t i = start; i < num + start; ++i) {
|
||||||
|
char* p = colDataGetData(pCol, i);
|
||||||
|
if (memcpy((void*)tval, p, pCol->info.bytes) == 0) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
int32_t numOfElems = 0;
|
int32_t numOfElems = 0;
|
||||||
|
|
||||||
|
@ -1111,15 +1124,14 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
|
|
||||||
if (isMinFunc) {
|
if (isMinFunc) {
|
||||||
tval = &pInput->pColumnDataAgg[0]->min;
|
tval = &pInput->pColumnDataAgg[0]->min;
|
||||||
index = pInput->pColumnDataAgg[0]->minIndex;
|
|
||||||
} else {
|
} else {
|
||||||
tval = &pInput->pColumnDataAgg[0]->max;
|
tval = &pInput->pColumnDataAgg[0]->max;
|
||||||
index = pInput->pColumnDataAgg[0]->maxIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pBuf->assign) {
|
if (!pBuf->assign) {
|
||||||
pBuf->v = *(int64_t*)tval;
|
pBuf->v = *(int64_t*)tval;
|
||||||
if (pCtx->subsidiaries.num > 0) {
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1131,6 +1143,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
pBuf->v = val;
|
pBuf->v = val;
|
||||||
if (pCtx->subsidiaries.num > 0) {
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1143,6 +1156,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
pBuf->v = val;
|
pBuf->v = val;
|
||||||
if (pCtx->subsidiaries.num > 0) {
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1154,6 +1168,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
if ((prev < val) ^ isMinFunc) {
|
if ((prev < val) ^ isMinFunc) {
|
||||||
pBuf->v = val;
|
pBuf->v = val;
|
||||||
if (pCtx->subsidiaries.num > 0) {
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1167,6 +1182,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCtx->subsidiaries.num > 0) {
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
index = findRowIndex(pInput->startRowIndex, pInput->numOfRows, pCol, tval);
|
||||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
#python3 ./test.py -f 2-query/last.py -Q 3
|
Loading…
Reference in New Issue