diff --git a/include/common/tep.h b/include/common/tep.h index 956cf6ec361531ed12bf20027f77d2136f8c8d7b..0cd3f1dbd4a94a9881bb7eb90aaa397a23a24b47 100644 --- a/include/common/tep.h +++ b/include/common/tep.h @@ -67,6 +67,9 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u } } +#define BitmapLen(_n) (((_n) + ((1<> NBIT) + + #define colDataGet(p1_, r_) \ ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \ : ((p1_)->pData + ((r_) * (p1_)->info.bytes))) diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 2b03fbd933af98cf92099d39c11fc72579b1a565..3c1c2cb0eaa73cfdb056315a352b42edf7b7ac80 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -228,7 +228,10 @@ typedef struct SAggFunctionInfo { typedef struct SScalarParam { void *data; - SColumnInfoData *columnData; + union { + SColumnInfoData *columnData; + void *data; + } orig; char *bitmap; bool dataInBlock; int32_t num; diff --git a/include/libs/scalar/scalar.h b/include/libs/scalar/scalar.h index 1902c11cc68097b63141d640ce7a8bdf4656d713..2e876c8296d0135c00bd1848ed593f7b5ec90592 100644 --- a/include/libs/scalar/scalar.h +++ b/include/libs/scalar/scalar.h @@ -27,7 +27,7 @@ typedef struct SFilterInfo SFilterInfo; int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes); -int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SScalarParam *pDst); +int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst); int32_t scalarGetOperatorParamNum(EOperatorType type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); diff --git a/source/common/src/tep.c b/source/common/src/tep.c index 970b6d954f1faa4f1f439f1f415e0d7059852311..d7e7aec1e1dc8a53d97a7dd5a27408c2204b5af2 100644 --- a/source/common/src/tep.c +++ b/source/common/src/tep.c @@ -61,7 +61,6 @@ SEpSet getEpSet_s(SCorEpSet *pEpSet) { return ep; } -#define BitmapLen(_n) (((_n) + ((1<> NBIT) int32_t colDataGetSize(const SColumnInfoData* pColumnInfoData, int32_t numOfRows) { ASSERT(pColumnInfoData != NULL); diff --git a/source/libs/scalar/inc/filterInt.h b/source/libs/scalar/inc/filterInt.h index a0d4bc680cc1742ee76dffa0b139f83bb079ff3e..646e75e11db311966f2cb1411f5187470f9da54c 100644 --- a/source/libs/scalar/inc/filterInt.h +++ b/source/libs/scalar/inc/filterInt.h @@ -253,6 +253,7 @@ typedef struct SFilterInfo { uint32_t *blkUnits; int8_t *blkUnitRes; void *pTable; + SArray *blkList; SFilterPCtx pctx; } SFilterInfo; diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index 41ee90667e012dde68d9c7179a05b3595001182f..748c0df797f8981b36316fb7dc88a1d06c7b9486 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -24,7 +24,7 @@ extern "C" { typedef struct SScalarCtx { int32_t code; - SSDataBlock *pSrc; + SArray *pBlockList; /* element is SSDataBlock* */ SHashObj *pRes; /* element is SScalarParam */ } SScalarCtx; @@ -44,10 +44,13 @@ typedef struct SScalarCtx { #define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) - +int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx); +bool sclIsNull(SScalarParam* param, int32_t idx); +void sclSetNull(SScalarParam* param, int32_t idx); +void sclFreeParam(SScalarParam *param); #ifdef __cplusplus } #endif -#endif // TDENGINE_SCALARINT_H \ No newline at end of file +#endif // TDENGINE_SCALARINT_H diff --git a/source/libs/scalar/inc/sclvector.h b/source/libs/scalar/inc/sclvector.h index fd0f8b896f7679d10e9b892ae6a5a77dbca84619..51af74208dc3c080881c10b64b7d426e1263fa97 100644 --- a/source/libs/scalar/inc/sclvector.h +++ b/source/libs/scalar/inc/sclvector.h @@ -23,7 +23,7 @@ extern "C" { #include "sclfunc.h" typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType); -typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, void *output, int32_t order); +typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binOperator); #ifdef __cplusplus diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 5eb0003662cf0ce30719598c49357a6dbdfeffb0..d6caea856315ce878827adf5a5db7185ac3542d7 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -3668,7 +3668,12 @@ _return: bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols) { if (info->scalarMode) { SScalarParam output = {0}; - FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pSrc, &output)); + SArray *pList = taosArrayInit(1, POINTER_BYTES); + taosArrayPush(pList, &pSrc); + + FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); + + taosArrayDestroy(pList); *p = output.data; diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 05af5f63b4d0d1fe35be9523b60584716b209090..c2ce09210f7b13df30723643a17fb0fedf3736c2 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -5,6 +5,7 @@ #include "functionMgt.h" #include "sclvector.h" #include "sclInt.h" +#include "tep.h" int32_t scalarGetOperatorParamNum(EOperatorType type) { if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type @@ -87,15 +88,23 @@ _return: SCL_RET(code); } -bool sclIsNull(SScalarParam* param, int32_t idx) { +FORCE_INLINE bool sclIsNull(SScalarParam* param, int32_t idx) { if (param->dataInBlock) { - return colDataIsNull(param->columnData, 0, idx, NULL); + return colDataIsNull(param->orig.columnData, 0, idx, NULL); } - return colDataIsNull_f(param->bitmap, idx); + return param->bitmap ? colDataIsNull_f(param->bitmap, idx) : false; } -void sclSetNull(SScalarParam* param, int32_t idx) { +FORCE_INLINE void sclSetNull(SScalarParam* param, int32_t idx) { + if (NULL == param->bitmap) { + param->bitmap = calloc(BitmapLen(param->num), sizeof(char)); + if (NULL == param->bitmap) { + sclError("calloc %d failed", param->num); + return; + } + } + colDataSetNull_f(param->bitmap, idx); } @@ -107,7 +116,7 @@ void sclFreeRes(SHashObj *res) { p = (SScalarParam *)pIter; if (p) { - tfree(p->data); + sclFreeParam(p); } pIter = taosHashIterate(res, pIter); @@ -117,7 +126,15 @@ void sclFreeRes(SHashObj *res) { } void sclFreeParam(SScalarParam *param) { - tfree(param->data); + tfree(param->bitmap); + + if (!param->dataInBlock) { + if (SCL_DATA_TYPE_DUMMY_HASH == param->type) { + taosHashCleanup((SHashObj *)param->orig.data); + } else { + tfree(param->orig.data); + } + } } int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t *rowNum) { @@ -140,30 +157,45 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } SCL_ERR_RET(scalarGenerateSetFromList(¶m->data, node, nodeList->dataType.type)); + param->orig.data = param->data; param->num = 1; param->type = SCL_DATA_TYPE_DUMMY_HASH; param->dataInBlock = false; + + if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) { + taosHashCleanup(param->orig.data); + param->orig.data = NULL; + sclError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param)); + return TSDB_CODE_QRY_OUT_OF_MEMORY; + } break; } case QUERY_NODE_COLUMN: { - if (NULL == ctx) { - sclError("invalid node type for constant calculating, type:%d, ctx:%p", nodeType(node), ctx); + if (NULL == ctx->pBlockList) { + sclError("invalid node type for constant calculating, type:%d, src:%p", nodeType(node), ctx->pBlockList); SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } SColumnNode *ref = (SColumnNode *)node; - if (ref->slotId >= taosArrayGetSize(ctx->pSrc->pDataBlock)) { - sclError("column ref slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(ctx->pSrc->pDataBlock)); + if (ref->tupleId >= taosArrayGetSize(ctx->pBlockList)) { + sclError("column tupleId is too big, tupleId:%d, dataBlockNum:%d", ref->tupleId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + SSDataBlock *block = taosArrayGet(ctx->pBlockList, ref->tupleId); + + if (NULL == block || ref->slotId >= taosArrayGetSize(block->pDataBlock)) { + sclError("column slotId is too big, slodId:%d, dataBlockSize:%d", ref->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(ctx->pSrc->pDataBlock, ref->slotId); + SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(block->pDataBlock, ref->slotId); param->data = NULL; - param->columnData = columnData; + param->orig.columnData = columnData; param->dataInBlock = true; - param->num = ctx->pSrc->info.rows; + param->num = block->info.rows; param->type = columnData->info.type; param->bytes = columnData->info.bytes; @@ -171,11 +203,6 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_OPERATOR: { - if (NULL == ctx) { - sclError("invalid node type for constant calculating, type:%d, ctx:%p", nodeType(node), ctx); - SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR); - } - SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES); if (NULL == res) { sclError("no result for node, type:%d, node:%p", nodeType(node), node); @@ -211,13 +238,15 @@ int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx) } if (param->dataInBlock) { - param->data = colDataGet(param->columnData, idx); + param->data = colDataGet(param->orig.columnData, idx); } else if (idx) { if (IS_VAR_DATA_TYPE(param->type)) { param->data = (char *)(param->data) + varDataTLen(param->data); } else { param->data = (char *)(param->data) + tDataTypes[param->type].bytes; } + } else { + param->data = param->orig.data; } } @@ -307,6 +336,7 @@ int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outpu sclError("calloc %d failed", (int32_t)(rowNum * sizeof(tDataTypes[output->type].bytes))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + output->orig.data = output->data; for (int32_t i = 0; i < rowNum; ++i) { sclMoveParamListData(output, 1, i); @@ -358,9 +388,8 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + output->orig.data = output->data; - void *data = output->data; - bool value = false; for (int32_t i = 0; i < rowNum; ++i) { @@ -382,8 +411,6 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o *(bool *)output->data = value; } - output->data = data; - return TSDB_CODE_SUCCESS; _return: @@ -407,6 +434,7 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp sclError("calloc %d failed", (int32_t)rowNum * tDataTypes[output->type].bytes); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } + output->orig.data = output->data; _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); @@ -414,7 +442,7 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp SScalarParam* pLeft = ¶ms[0]; SScalarParam* pRight = paramNum > 1 ? ¶ms[1] : NULL; - OperatorFn(pLeft, pRight, output->data, TSDB_ORDER_ASC); + OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC); return TSDB_CODE_SUCCESS; @@ -425,12 +453,12 @@ _return: } -EDealRes sclRewriteFunction(SNode** pNode, void* pContext) { +EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; SScalarParam output = {0}; - *(int32_t *)pContext = sclExecFuncion(node, NULL, &output); - if (*(int32_t *)pContext) { + ctx->code = sclExecFuncion(node, ctx, &output); + if (ctx->code) { return DEAL_RES_ERROR; } @@ -438,7 +466,7 @@ EDealRes sclRewriteFunction(SNode** pNode, void* pContext) { if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); - *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY; + ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; } @@ -459,12 +487,12 @@ EDealRes sclRewriteFunction(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } -EDealRes sclRewriteLogic(SNode** pNode, void* pContext) { +EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)*pNode; SScalarParam output = {0}; - *(int32_t *)pContext = sclExecLogic(node, NULL, &output); - if (*(int32_t *)pContext) { + ctx->code = sclExecLogic(node, ctx, &output); + if (ctx->code) { return DEAL_RES_ERROR; } @@ -472,7 +500,7 @@ EDealRes sclRewriteLogic(SNode** pNode, void* pContext) { if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); - *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY; + ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; } @@ -493,12 +521,12 @@ EDealRes sclRewriteLogic(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } -EDealRes sclRewriteOperator(SNode** pNode, void* pContext) { +EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; SScalarParam output = {0}; - *(int32_t *)pContext = sclExecOperator(node, NULL, &output); - if (*(int32_t *)pContext) { + ctx->code = sclExecOperator(node, ctx, &output); + if (ctx->code) { return DEAL_RES_ERROR; } @@ -506,7 +534,7 @@ EDealRes sclRewriteOperator(SNode** pNode, void* pContext) { if (NULL == res) { sclError("make value node failed"); sclFreeParam(&output); - *(int32_t *)pContext = TSDB_CODE_QRY_OUT_OF_MEMORY; + ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY; return DEAL_RES_ERROR; } @@ -533,28 +561,29 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { return DEAL_RES_CONTINUE; } + SScalarCtx *ctx = (SScalarCtx *)pContext; + if (QUERY_NODE_FUNCTION == nodeType(*pNode)) { - return sclRewriteFunction(pNode, pContext); + return sclRewriteFunction(pNode, ctx); } if (QUERY_NODE_LOGIC_CONDITION == nodeType(*pNode)) { - return sclRewriteLogic(pNode, pContext); + return sclRewriteLogic(pNode, ctx); } if (QUERY_NODE_OPERATOR == nodeType(*pNode)) { - return sclRewriteOperator(pNode, pContext); + return sclRewriteOperator(pNode, ctx); } sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode)); - - *(int32_t *)pContext = TSDB_CODE_QRY_INVALID_INPUT; + + ctx->code = TSDB_CODE_QRY_INVALID_INPUT; return DEAL_RES_ERROR; } -EDealRes sclWalkFunction(SNode* pNode, void* pContext) { - SScalarCtx *ctx = (SScalarCtx *)pContext; +EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; SScalarParam output = {0}; @@ -572,8 +601,7 @@ EDealRes sclWalkFunction(SNode* pNode, void* pContext) { } -EDealRes sclWalkLogic(SNode* pNode, void* pContext) { - SScalarCtx *ctx = (SScalarCtx *)pContext; +EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)pNode; SScalarParam output = {0}; @@ -591,8 +619,7 @@ EDealRes sclWalkLogic(SNode* pNode, void* pContext) { } -EDealRes sclWalkOperator(SNode* pNode, void* pContext) { - SScalarCtx *ctx = (SScalarCtx *)pContext; +EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)pNode; SScalarParam output = {0}; @@ -609,27 +636,69 @@ EDealRes sclWalkOperator(SNode* pNode, void* pContext) { return DEAL_RES_CONTINUE; } +EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { + STargetNode *target = (STargetNode *)pNode; + + if (target->tupleId >= taosArrayGetSize(ctx->pBlockList)) { + sclError("target tupleId is too big, tupleId:%d, dataBlockNum:%d", target->tupleId, (int32_t)taosArrayGetSize(ctx->pBlockList)); + ctx->code = TSDB_CODE_QRY_INVALID_INPUT; + return DEAL_RES_ERROR; + } + + SSDataBlock *block = taosArrayGet(ctx->pBlockList, target->tupleId); + if (target->slotId >= taosArrayGetSize(block->pDataBlock)) { + sclError("target slot not exist, slotId:%d, dataBlockNum:%d", target->slotId, (int32_t)taosArrayGetSize(block->pDataBlock)); + ctx->code = TSDB_CODE_QRY_INVALID_INPUT; + return DEAL_RES_ERROR; + } + + SColumnInfoData *col = taosArrayGet(block->pDataBlock, target->slotId); + + SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); + if (NULL == res) { + sclError("no valid res in hash, node:%p, type:%d", target->pExpr, nodeType(target->pExpr)); + ctx->code = TSDB_CODE_QRY_APP_ERROR; + return DEAL_RES_ERROR; + } + + taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); + + for (int32_t i = 0; i < res->num; ++i) { + sclMoveParamListData(res, 1, i); + + colDataAppend(col, i, res->data, sclIsNull(res, i)); + } + + sclFreeParam(res); + + return DEAL_RES_CONTINUE; +} + EDealRes sclCalcWalker(SNode* pNode, void* pContext) { if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) || QUERY_NODE_COLUMN == nodeType(pNode)) { return DEAL_RES_CONTINUE; } + + SScalarCtx *ctx = (SScalarCtx *)pContext; if (QUERY_NODE_FUNCTION == nodeType(pNode)) { - return sclWalkFunction(pNode, pContext); + return sclWalkFunction(pNode, ctx); } if (QUERY_NODE_LOGIC_CONDITION == nodeType(pNode)) { - return sclWalkLogic(pNode, pContext); + return sclWalkLogic(pNode, ctx); } if (QUERY_NODE_OPERATOR == nodeType(pNode)) { - return sclWalkOperator(pNode, pContext); + return sclWalkOperator(pNode, ctx); } - sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode)); + if (QUERY_NODE_TARGET == nodeType(pNode)) { + return sclWalkTarget(pNode, ctx); + } - SScalarCtx *ctx = (SScalarCtx *)pContext; + sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode)); ctx->code = TSDB_CODE_QRY_INVALID_INPUT; @@ -644,26 +713,33 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { } int32_t code = 0; + SScalarCtx ctx = {0}; + ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); + if (NULL == ctx.pRes) { + sclError("taosHashInit failed, num:%d", SCL_DEFAULT_OP_NUM); + SCL_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } - nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&code); + nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&ctx); - if (code) { - nodesDestroyNode(pNode); - SCL_ERR_RET(code); - } + SCL_ERR_JRET(ctx.code); *pRes = pNode; - SCL_RET(code); +_return: + + sclFreeRes(ctx.pRes); + + return code; } -int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SScalarParam *pDst) { - if (NULL == pNode || NULL == pSrc || NULL == pDst) { +int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { + if (NULL == pNode || NULL == pBlockList || NULL == pDst) { SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } int32_t code = 0; - SScalarCtx ctx = {.code = 0, .pSrc = pSrc}; + SScalarCtx ctx = {.code = 0, .pBlockList = pBlockList}; ctx.pRes = taosHashInit(SCL_DEFAULT_OP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == ctx.pRes) { @@ -673,23 +749,24 @@ int32_t scalarCalculate(SNode *pNode, SSDataBlock *pSrc, SScalarParam *pDst) { nodesWalkNodePostOrder(pNode, sclCalcWalker, (void *)&ctx); - if (ctx.code) { - nodesDestroyNode(pNode); - sclFreeRes(ctx.pRes); - SCL_ERR_RET(ctx.code); - } + SCL_ERR_JRET(ctx.code); SScalarParam *res = (SScalarParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES); if (NULL == res) { - sclError("no res for calculating, node:%p, type:%d", pNode, nodeType(pNode)); - SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + sclError("no valid res in hash, node:%p, type:%d", pNode, nodeType(pNode)); + SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } + taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + *pDst = *res; +_return: + nodesDestroyNode(pNode); + sclFreeRes(ctx.pRes); - return TSDB_CODE_SUCCESS; + return code; } diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 57899f0e82bd081d66d9428d08e5ca973726bb9d..4003603eb5b73977a0da4ce69b0698967c7f19ce 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -261,19 +261,19 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { return p; } -static FORCE_INLINE void convertToSigned(char *buf, SScalarParam* pOut, int32_t outType) { +static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t outType) { int64_t value = strtoll(buf, NULL, 10); SET_TYPED_DATA(pOut->data, outType, value); } -static FORCE_INLINE void convertToUnsigned(char *buf, SScalarParam* pOut, int32_t outType) { +static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t outType) { uint64_t value = strtoull(buf, NULL, 10); SET_TYPED_DATA(pOut->data, outType, value); } -static FORCE_INLINE void convertToFloat(char *buf, SScalarParam* pOut, int32_t outType) { - double value = strtod(tmp, NULL); - SET_TYPED_DATA(output, outType, value); +static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t outType) { + double value = strtod(buf, NULL); + SET_TYPED_DATA(pOut->data, outType, value); } @@ -282,14 +282,14 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t char *tmp = NULL; _bufConverteFunc func = NULL; - if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType) { - func = convertToSigned; + if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType || TSDB_DATA_TYPE_BOOL == outType) { + func = varToSigned; } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { - func = convertToUnsigned; + func = varToUnsigned; } else if (IS_FLOAT_TYPE(outType)) { - func = convertToFloat; + func = varToFloat; } else { - sclError("unknown outType:%d", outType); + sclError("invalid convert outType:%d", outType); return TSDB_CODE_QRY_APP_ERROR; } @@ -301,29 +301,49 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t sclSetNull(pOut, i); continue; } - - if (varDataLen(pIn->data) >= bufSize) { - bufSize = varDataLen(pIn->data) + 1; - tmp = realloc(tmp, bufSize); + + if (TSDB_DATA_TYPE_BINARY == inType) { + if (varDataLen(pIn->data) >= bufSize) { + bufSize = varDataLen(pIn->data) + 1; + tmp = realloc(tmp, bufSize); + } + + memcpy(tmp, varDataVal(pIn->data), varDataLen(pIn->data)); + tmp[varDataLen(pIn->data)] = 0; + } else { + if (varDataLen(pIn->data) * TSDB_NCHAR_SIZE >= bufSize) { + bufSize = varDataLen(pIn->data) * TSDB_NCHAR_SIZE + 1; + tmp = realloc(tmp, bufSize); + } + + int len = taosUcs4ToMbs(varDataVal(pIn->data), varDataLen(pIn->data), tmp); + if (len < 0){ + sclError("castConvert taosUcs4ToMbs error 1"); + tfree(tmp); + return TSDB_CODE_QRY_APP_ERROR; + } + + tmp[len] = 0; } - memcpy(tmp, varDataVal(pIn->data), varDataLen(pIn->data)); - tmp[varDataLen(pIn->data)] = 0; - (*func)(tmp, pOut, outType); } tfree(tmp); + + return TSDB_CODE_SUCCESS; } int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { int16_t inType = pIn->type; int16_t inBytes = pIn->bytes; - char *input = pIn->data; int16_t outType = pOut->type; int16_t outBytes = pOut->bytes; - char *output = pOut->data; + if (inType == TSDB_DATA_TYPE_BINARY || inType == TSDB_DATA_TYPE_NCHAR) { + return vectorConvertFromVarData(pIn, pOut, inType, outType); + } + switch (outType) { case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_TINYINT: @@ -331,234 +351,55 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - if (inType == TSDB_DATA_TYPE_BINARY) { - int32_t bufSize = 0; - char *tmp = NULL; + for (int32_t i = 0; i < pIn->num; ++i) { + sclMoveParamListData(pIn, 1, i); + sclMoveParamListData(pOut, 1, i); - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); - continue; - } - - if (varDataLen(pIn->data) >= bufSize) { - bufSize = varDataLen(pIn->data) + 1; - tmp = realloc(tmp, bufSize); - } - - memcpy(tmp, varDataVal(pIn->data), varDataLen(pIn->data)); - tmp[varDataLen(pIn->data)] = 0; - - int64_t value = strtoll(tmp, NULL, 10); - SET_TYPED_DATA(pOut->data, outType, value); - } - - tfree(tmp); - } else if (inType == TSDB_DATA_TYPE_NCHAR) { - int32_t bufSize = 0; - char *tmp = NULL; - - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); - continue; - } - - if (varDataLen(pIn->data) * TSDB_NCHAR_SIZE >= bufSize) { - bufSize = varDataLen(pIn->data) * TSDB_NCHAR_SIZE + 1; - tmp = realloc(tmp, bufSize); - } - - int len = taosUcs4ToMbs(varDataVal(pIn->data), varDataLen(pIn->data), tmp); - if (len < 0){ - sclError("castConvert taosUcs4ToMbs error 1"); - tfree(tmp); - return TSDB_CODE_QRY_APP_ERROR; - } - - tmp[len] = 0; - - int64_t value = strtoll(tmp, NULL, 10); - SET_TYPED_DATA(pOut->data, outType, value); + if (sclIsNull(pIn, i)) { + sclSetNull(pOut, i); + continue; } + + int64_t value = 0; - tfree(tmp); - } else { - for (int32_t i = 0; i < pIn->num; ++i) { - int64_t value = 0; - GET_TYPED_DATA(value, int64_t, inType, input); - SET_TYPED_DATA(output, outType, value); - - input += tDataTypes[inType].bytes; - output += tDataTypes[outType].bytes; - } + GET_TYPED_DATA(value, int64_t, inType, pIn->data); + SET_TYPED_DATA(pOut->data, outType, value); } break; case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: - if (inType == TSDB_DATA_TYPE_BINARY) { - int32_t bufSize = varDataLen(input) + 1; - char *tmp = malloc(bufSize); - if (NULL == tmp) { - sclError("malloc %d failed", bufSize); - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - if (varDataLen(input) >= bufSize) { - bufSize = varDataLen(input) + 1; - tmp = realloc(tmp, bufSize); - } - - memcpy(tmp, varDataVal(input), varDataLen(input)); - tmp[varDataLen(input)] = 0; - uint64_t value = strtoull(tmp, NULL, 10); - SET_TYPED_DATA(output, outType, value); - } - - input += varDataLen(input) + VARSTR_HEADER_SIZE; - output += tDataTypes[outType].bytes; - } + for (int32_t i = 0; i < pIn->num; ++i) { + sclMoveParamListData(pIn, 1, i); + sclMoveParamListData(pOut, 1, i); - tfree(tmp); - } else if (inType == TSDB_DATA_TYPE_NCHAR) { - int32_t bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1; - char *tmp = calloc(1, bufSize); - if (NULL == tmp) { - sclError("calloc %d failed", bufSize); - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (sclIsNull(pIn, i)) { + sclSetNull(pOut, i); + continue; } - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - if (varDataLen(input)* TSDB_NCHAR_SIZE >= bufSize) { - bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1; - tmp = realloc(tmp, bufSize); - } - - int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), tmp); - if (len < 0){ - sclError("castConvert taosUcs4ToMbs error 1"); - tfree(tmp); - return TSDB_CODE_QRY_APP_ERROR; - } - - tmp[len] = 0; - uint64_t value = strtoull(tmp, NULL, 10); - SET_TYPED_DATA(output, outType, value); - } - - input += varDataLen(input) + VARSTR_HEADER_SIZE; - output += tDataTypes[outType].bytes; - } - - tfree(tmp); - } else { - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - uint64_t value = 0; - GET_TYPED_DATA(value, uint64_t, inType, input); - SET_TYPED_DATA(output, outType, value); - } - - input += tDataTypes[inType].bytes; - output += tDataTypes[outType].bytes; - } + uint64_t value = 0; + + GET_TYPED_DATA(value, uint64_t, inType, pIn->data); + SET_TYPED_DATA(pOut->data, outType, value); } break; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: - if (inType == TSDB_DATA_TYPE_BINARY) { - int32_t bufSize = varDataLen(input) + 1; - char *tmp = malloc(bufSize); - if (NULL == tmp) { - sclError("malloc %d failed", bufSize); - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } + for (int32_t i = 0; i < pIn->num; ++i) { + sclMoveParamListData(pIn, 1, i); + sclMoveParamListData(pOut, 1, i); - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - if (varDataLen(input) >= bufSize) { - bufSize = varDataLen(input) + 1; - tmp = realloc(tmp, bufSize); - } - - memcpy(tmp, varDataVal(input), varDataLen(input)); - tmp[varDataLen(input)] = 0; - - double value = strtod(tmp, NULL); - SET_TYPED_DATA(output, outType, value); - } - - input += varDataLen(input) + VARSTR_HEADER_SIZE; - output += tDataTypes[outType].bytes; + if (sclIsNull(pIn, i)) { + sclSetNull(pOut, i); + continue; } - tfree(tmp); - } else if (inType == TSDB_DATA_TYPE_NCHAR) { - int32_t bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1; - char *tmp = calloc(1, bufSize); - if (NULL == tmp) { - sclError("calloc %d failed", bufSize); - return TSDB_CODE_QRY_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - if (varDataLen(input)* TSDB_NCHAR_SIZE >= bufSize) { - bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1; - tmp = realloc(tmp, bufSize); - } - - int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), tmp); - if (len < 0){ - sclError("castConvert taosUcs4ToMbs error 1"); - tfree(tmp); - return TSDB_CODE_QRY_APP_ERROR; - } - - tmp[len] = 0; - double value = strtod(tmp, NULL); - SET_TYPED_DATA(output, outType, value); - } - - input += varDataLen(input) + VARSTR_HEADER_SIZE; - output += tDataTypes[outType].bytes; - } - - tfree(tmp); - } else { - for (int32_t i = 0; i < pIn->num; ++i) { - if (isNull(input, inType)) { - assignVal(output, getNullValue(outType), 0, outType); - } else { - int64_t value = 0; - GET_TYPED_DATA(value, int64_t, inType, input); - SET_TYPED_DATA(output, outType, value); - } - - input += tDataTypes[inType].bytes; - output += tDataTypes[outType].bytes; - } + double value = 0; + + GET_TYPED_DATA(value, double, inType, pIn->data); + SET_TYPED_DATA(pOut->data, outType, value); } break; default: @@ -673,7 +514,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p return TSDB_CODE_SUCCESS; } -void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -686,11 +527,6 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -700,62 +536,65 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - tfree(leftParam.data); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - double *output=(double*)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) + getVectorDoubleValueFnRight(pRight->data, i)); + SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) + getVectorDoubleValueFnRight(pRight->data, i)); } } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; - } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) + getVectorDoubleValueFnRight(pRight->data,i)); + } + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) + getVectorDoubleValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) + getVectorDoubleValueFnRight(pRight->data,0)); + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) + getVectorDoubleValueFnRight(pRight->data,0)); } } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -768,11 +607,6 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -782,60 +616,65 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - tfree(leftParam.data); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - double *output=(double*)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); - continue; + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); + continue; } - SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i)); - } + + SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i)); + } } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; - } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) - getVectorDoubleValueFnRight(pRight->data,i)); + } + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) - getVectorDoubleValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0)); + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0)); } } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -848,11 +687,6 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_ return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -862,62 +696,66 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_ rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - tfree(leftParam.data); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - double *output=(double*)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i)); + SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i)); } } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; - } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data, 0) * getVectorDoubleValueFnRight(pRight->data,i)); + } + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) * getVectorDoubleValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0)); + + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0)); } - } + } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -930,11 +768,6 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -944,69 +777,66 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - tfree(leftParam.data); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - double *output=(double*)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i)); + SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i)); } } else if (pLeft->num == 1) { - double left = getVectorDoubleValueFnLeft(pLeft->data, 0); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(&left, pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_DOUBLE_NULL(output); + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; - } + } - SET_DOUBLE_VAL(output,left / getVectorDoubleValueFnRight(pRight->data,i)); + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) / getVectorDoubleValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - double right = getVectorDoubleValueFnRight(pRight->data, 0); - - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(&right, pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) / right); + SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) / getVectorDoubleValueFnRight(pRight->data,0)); } } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -1019,11 +849,6 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32 return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -1033,92 +858,92 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32 rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - tfree(leftParam.data); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - double * output = (double *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, i)); + GET_TYPED_DATA(v, double, pRight->type, pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - SET_DOUBLE_NULL(output); + sclSetNull(pOut, i); continue; } double left = getVectorDoubleValueFnLeft(pLeft->data, i); double right = getVectorDoubleValueFnRight(pRight->data, i); - SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right); + SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); } } else if (pLeft->num == 1) { double left = getVectorDoubleValueFnLeft(pLeft->data, 0); - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(&left, pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, i)); + GET_TYPED_DATA(v, double, pRight->type, pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - SET_DOUBLE_NULL(output); + sclSetNull(pOut, i); continue; } double right = getVectorDoubleValueFnRight(pRight->data, i); - SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right); + SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); } } else if (pRight->num == 1) { double right = getVectorDoubleValueFnRight(pRight->data, 0); - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(&right, pRight->type)) { - SET_DOUBLE_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, getVectorValueAddrFnRight(pRight->data, 0)); + GET_TYPED_DATA(v, double, pRight->type, pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { - SET_DOUBLE_NULL(output); + sclSetNull(pOut, i); continue; } double left = getVectorDoubleValueFnLeft(pLeft->data, i); - SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right); + SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); } } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { @@ -1168,11 +993,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t varDataSetLen(output, varDataLen(left) + varDataLen(pRight->data)); } } - } -void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -1181,15 +1005,10 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t if (IS_VAR_DATA_TYPE(pLeft->type)) { leftParam.data = calloc(leftParam.num, sizeof(int64_t)); if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(int64_t))); + sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -1198,63 +1017,67 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t if (IS_VAR_DATA_TYPE(pRight->type)) { rightParam.data = calloc(rightParam.num, sizeof(int64_t)); if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(int64_t))); - tfree(leftParam.data); + sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); + sclFreeParam(&leftParam); return; } - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } - if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - int64_t *output=(int64_t *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeft->type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output, getVectorBigintValueFnLeft(pLeft->data, i) & getVectorBigintValueFnRight(pRight->data, i)); + SET_BIGINT_VAL(pOut->data, getVectorBigintValueFnLeft(pLeft->data, i) & getVectorBigintValueFnRight(pRight->data, i)); } } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data, 0) & getVectorBigintValueFnRight(pRight->data,i)); + + SET_BIGINT_VAL(pOut->data,getVectorBigintValueFnLeft(pLeft->data, 0) & getVectorBigintValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data,i) & getVectorBigintValueFnRight(pRight->data,0)); + + SET_BIGINT_VAL(pOut->data,getVectorBigintValueFnLeft(pLeft->data,i) & getVectorBigintValueFnRight(pRight->data,0)); } } - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; @@ -1263,15 +1086,10 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ if (IS_VAR_DATA_TYPE(pLeft->type)) { leftParam.data = calloc(leftParam.num, sizeof(int64_t)); if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(int64_t))); + sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); return; } - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - if (vectorConvertImpl(pLeft, &leftParam)) { return; } @@ -1280,131 +1098,119 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ if (IS_VAR_DATA_TYPE(pRight->type)) { rightParam.data = calloc(rightParam.num, sizeof(int64_t)); if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(int64_t))); - tfree(leftParam.data); + sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); + sclFreeParam(&leftParam); return; } - - if (pRight->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data; - pRight->data = colInfo->pData; - } if (vectorConvertImpl(pRight, &rightParam)) { - tfree(leftParam.data); - tfree(rightParam.data); + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); return; } pRight = &rightParam; } - int64_t *output=(int64_t *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - _getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeft->type); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRight->type); if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output, getVectorBigintValueFnLeft(pLeft->data, i) | getVectorBigintValueFnRight(pRight->data, i)); + SET_BIGINT_VAL(pOut->data, getVectorBigintValueFnLeft(pLeft->data, i) | getVectorBigintValueFnRight(pRight->data, i)); } } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, 0), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data, 0) | getVectorBigintValueFnRight(pRight->data,i)); + + SET_BIGINT_VAL(pOut->data,getVectorBigintValueFnLeft(pLeft->data, 0) | getVectorBigintValueFnRight(pRight->data,i)); } } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,0), pRight->type)) { - SET_BIGINT_NULL(output); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data,i) | getVectorBigintValueFnRight(pRight->data,0)); + + SET_BIGINT_VAL(pOut->data,getVectorBigintValueFnLeft(pLeft->data,i) | getVectorBigintValueFnRight(pRight->data,0)); } } - tfree(leftParam.data); - tfree(rightParam.data); + + sclFreeParam(&leftParam); + sclFreeParam(&rightParam); } -void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord, int32_t optr) { +void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; __compar_fn_t fp = filterGetCompFunc(pLeft->type, optr); bool res = false; - - bool *output=(bool *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = NULL; - _getValueAddr_fn_t getVectorValueAddrFnRight = NULL; - - if (IS_VAR_DATA_TYPE(pLeft->type) && !pLeft->dataInBlock) { - getVectorValueAddrFnLeft = getVectorValueAddr_default; - } else { - getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - } - - if (IS_VAR_DATA_TYPE(pRight->type) && !pRight->dataInBlock) { - getVectorValueAddrFnRight = getVectorValueAddr_default; - } else { - getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type); - } - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) || - isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) { - res = false; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + for (; i < pRight->num && i >= 0; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pRight, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - - res = filterDoCompare(fp, optr, getVectorValueAddrFnLeft(pLeft->data, i), getVectorValueAddrFnRight(pRight->data,i)); - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + res = filterDoCompare(fp, optr, pLeft->data, pRight->data); + + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); } } else if (pLeft->num == 1) { - void *leftData = getVectorValueAddrFnLeft(pLeft->data, 0); - - for (; i >= 0 && i < pRight->num; i += step, output += 1) { - if (isNull(leftData, pLeft->type) || isNull(getVectorValueAddrFnRight(pRight->data,i), pRight->type)) { - res = false; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + for (; i >= 0 && i < pRight->num; i += step) { + sclMoveParamListData(pRight, 1, i); + + if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { + sclSetNull(pOut, i); continue; } - res = filterDoCompare(fp, optr, leftData, getVectorValueAddrFnRight(pRight->data,i)); - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + res = filterDoCompare(fp, optr, pLeft->data, pRight->data); + + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); } } else if (pRight->num == 1) { - void *rightData = getVectorValueAddrFnRight(pRight->data, 0); - - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(rightData, pRight->type)) { - res = false; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + + if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { + sclSetNull(pOut, i); continue; } - res = filterDoCompare(fp, optr, getVectorValueAddrFnLeft(pLeft->data,i), rightData); + res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); } } } -void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord, int32_t optr) { +void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { SScalarParam pLeftOut = {0}; SScalarParam pRightOut = {0}; @@ -1426,118 +1232,100 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t param2 = pRight; } - vectorCompareImpl(param1, param2, out, _ord, optr); + vectorCompareImpl(param1, param2, pOut, _ord, optr); } -void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_GREATER_THAN); +void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_THAN); } -void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_GREATER_EQUAL); +void vectorGreaterEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_GREATER_EQUAL); } -void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LOWER_THAN); +void vectorLower(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_THAN); } -void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LOWER_EQUAL); +void vectorLowerEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LOWER_EQUAL); } -void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_EQUAL); +void vectorEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_EQUAL); } -void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_EQUAL); +void vectorNotEqual(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_EQUAL); } -void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_IN); +void vectorIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_IN); } -void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_IN); +void vectorNotIn(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_IN); } -void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_LIKE); +void vectorLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_LIKE); } -void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NOT_LIKE); +void vectorNotLike(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NOT_LIKE); } -void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_MATCH); +void vectorMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_MATCH); } -void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - vectorCompare(pLeft, pRight, out, _ord, OP_TYPE_NMATCH); +void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorCompare(pLeft, pRight, pOut, _ord, OP_TYPE_NMATCH); } -void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorIsNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; bool res = false; - bool *output=(bool *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = NULL; - - if (IS_VAR_DATA_TYPE(pLeft->type) && !pLeft->dataInBlock) { - getVectorValueAddrFnLeft = getVectorValueAddr_default; - } else { - getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - } - - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type)) { + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i)) { res = true; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); continue; } res = false; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); } } -void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +void vectorNotNull(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; bool res = false; - - bool *output = (bool *)out; - _getValueAddr_fn_t getVectorValueAddrFnLeft = NULL; - if (IS_VAR_DATA_TYPE(pLeft->type) && !pLeft->dataInBlock) { - getVectorValueAddrFnLeft = getVectorValueAddr_default; - } else { - getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type); - } - - for (; i >= 0 && i < pLeft->num; i += step, output += 1) { - if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type)) { + for (; i >= 0 && i < pLeft->num; i += step) { + sclMoveParamListData(pLeft, 1, i); + sclMoveParamListData(pOut, 1, i); + + if (sclIsNull(pLeft, i)) { res = false; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); continue; } res = true; - SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res); + SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); } -} -void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { - SScalarParam output = {.data = out, .num = pLeft->num, .type = TSDB_DATA_TYPE_BOOL}; +} - if (pLeft->dataInBlock) { - SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data; - pLeft->data = colInfo->pData; - } - - vectorConvertImpl(pLeft, &output); +void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + vectorConvertImpl(pLeft, pOut); }