diff --git a/include/common/tcommon.h b/include/common/tcommon.h index c91efc3ce2..27a0962e15 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -93,6 +93,7 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); int32_t tEncodeDataBlocks(void** buf, const SArray* blocks); void* tDecodeDataBlocks(const void* buf, SArray* blocks); +void colDataDestroy(SColumnInfoData* pColData) ; static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { // WARNING: do not use info.numOfCols, @@ -100,13 +101,7 @@ static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { int32_t numOfOutput = taosArrayGetSize(pBlock->pDataBlock); for (int32_t i = 0; i < numOfOutput; ++i) { SColumnInfoData* pColInfoData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i); - if (IS_VAR_DATA_TYPE(pColInfoData->info.type)) { - tfree(pColInfoData->varmeta.offset); - } else { - tfree(pColInfoData->nullbitmap); - } - - tfree(pColInfoData->pData); + colDataDestroy(pColInfoData); } taosArrayDestroy(pBlock->pDataBlock); diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 6c4774c3be..f6dfc6f65c 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -251,16 +251,9 @@ typedef struct SAggFunctionInfo { } SAggFunctionInfo; typedef struct SScalarParam { - void *data; - union { - SColumnInfoData *columnData; - void *data; - } orig; - char *bitmap; - bool dataInBlock; - int32_t num; - int32_t type; - int32_t bytes; + SColumnInfoData *columnData; + SHashObj *pHashFilter; + int32_t numOfRows; } SScalarParam; typedef struct SScalarFunctionInfo { diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 67e7333597..0b6ce28079 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -1241,6 +1241,16 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { return pageSize / (blockDataGetSerialRowSize(pBlock) + blockDataGetSerialMetaSize(pBlock)); } +void colDataDestroy(SColumnInfoData* pColData) { + if (IS_VAR_DATA_TYPE(pColData->info.type)) { + tfree(pColData->varmeta.offset); + } else { + tfree(pColData->nullbitmap); + } + + tfree(pColData->pData); +} + int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlock) { int64_t tbUid = pBlock->info.uid; int16_t numOfCols = pBlock->info.numOfCols; diff --git a/source/libs/function/src/taggfunction.c b/source/libs/function/src/taggfunction.c index 4360515328..6372d23fe1 100644 --- a/source/libs/function/src/taggfunction.c +++ b/source/libs/function/src/taggfunction.c @@ -3078,8 +3078,8 @@ static void arithmetic_function(SqlFunctionCtx *pCtx) { GET_RES_INFO(pCtx)->numOfRes += pCtx->size; //SScalarFunctionSupport *pSup = (SScalarFunctionSupport *)pCtx->param[1].pz; - SScalarParam output = {0}; - output.data = pCtx->pOutput; +// SScalarParam output = {0}; +// output.data = pCtx->pOutput; //evaluateExprNodeTree(pSup->pExprInfo->pExpr, pCtx->size, &output, pSup, getArithColumnData); } diff --git a/source/libs/scalar/inc/sclInt.h b/source/libs/scalar/inc/sclInt.h index b79221cf82..721911d48d 100644 --- a/source/libs/scalar/inc/sclInt.h +++ b/source/libs/scalar/inc/sclInt.h @@ -43,10 +43,12 @@ typedef struct SScalarCtx { #define SCL_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0) #define SCL_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0) +int32_t doConvertDataType(SScalarParam* in, SScalarParam* out, SValueNode* pValueNode); +SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows); -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); +//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 diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 58b5c8340a..636154a417 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -1021,26 +1021,21 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { if (node->opType == OP_TYPE_IN && (!IS_VAR_DATA_TYPE(type))) { SNodeListNode *listNode = (SNodeListNode *)node->pRight; SListCell *cell = listNode->pNodeList->pHead; - SScalarParam in = {.num = 1}, out = {.num = 1, .type = type}; + + SScalarParam in = {.columnData = calloc(1, sizeof(SColumnInfoData))}, out = {.columnData = calloc(1, sizeof(SColumnInfoData))}; + out.columnData->info.type = type; for (int32_t i = 0; i < listNode->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; - in.type = valueNode->node.resType.type; - in.bytes = valueNode->node.resType.bytes; - in.data = nodesGetValueFromNode(valueNode); - out.data = malloc(sizeof(int64_t)); - - code = vectorConvertImpl(&in, &out); + code = doConvertDataType(&in, &out, valueNode); if (code) { - fltError("convert from %d to %d failed", in.type, out.type); - tfree(out.data); +// fltError("convert from %d to %d failed", in.type, out.type); FLT_ERR_RET(code); } len = tDataTypes[type].bytes; - filterAddField(info, NULL, &out.data, FLD_TYPE_VALUE, &right, len, true); - + filterAddField(info, NULL, (void**) &out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); filterAddUnit(info, OP_TYPE_EQUAL, &left, &right, &uidx); SFilterGroup fgroup = {0}; @@ -1054,7 +1049,6 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode* tree, SArray *group) { filterAddFieldFromNode(info, node->pRight, &right); FLT_ERR_RET(filterAddUnit(info, node->opType, &left, &right, &uidx)); - SFilterGroup fgroup = {0}; filterAddUnitToGroup(&fgroup, uidx); @@ -1080,7 +1074,6 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, POINTER_BYTES, false); // POINTER_BYTES should be sizeof(SHashObj), but POINTER_BYTES is also right. t = FILTER_GET_FIELD(dst, right); - FILTER_SET_FLAG(t->flag, FLD_DATA_IS_HASH); } else { filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, varDataTLen(data), false); @@ -1101,14 +1094,12 @@ int32_t filterAddUnitFromUnit(SFilterInfo *dst, SFilterInfo *src, SFilterUnit* u int32_t filterAddUnitRight(SFilterInfo *info, uint8_t optr, SFilterFieldId *right, uint32_t uidx) { SFilterUnit *u = &info->units[uidx]; - u->compare.optr2 = optr; u->right2 = *right; return TSDB_CODE_SUCCESS; } - int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRangeCtx *ctx, uint32_t cidx, SFilterGroup *g, int32_t optr, SArray *res) { SFilterFieldId left, right, right2; uint32_t uidx = 0; @@ -1800,9 +1791,12 @@ int32_t fltInitValFieldData(SFilterInfo *info) { if (dType->type == type) { assignVal(fi->data, nodesGetValueFromNode(var), dType->bytes, type); } else { - SScalarParam in = {.data = nodesGetValueFromNode(var), .num = 1, .type = dType->type, .bytes = dType->bytes}; - SScalarParam out = {.data = fi->data, .num = 1, .type = type}; - if (vectorConvertImpl(&in, &out)) { + SScalarParam in = {.columnData = calloc(1, sizeof(SColumnInfoData))}; + SScalarParam out = {.columnData = calloc(1, sizeof(SColumnInfoData))}; + out.columnData->info.type = type; + + int32_t code = doConvertDataType(&in, &out, var); + if (code != TSDB_CODE_SUCCESS) { qError("convert value to type[%d] failed", type); return TSDB_CODE_TSC_INVALID_OPERATION; } @@ -3676,18 +3670,18 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnData FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); taosArrayDestroy(pList); - - *p = output.orig.data; - output.orig.data = NULL; - - sclFreeParam(&output); - - int8_t *r = output.data; - for (int32_t i = 0; i < output.num; ++i) { - if (0 == *(r+i)) { - return false; - } - } + // TODO Fix it +// *p = output.orig.data; +// output.orig.data = NULL; +// +// sclFreeParam(&output); +// +// int8_t *r = output.data; +// for (int32_t i = 0; i < output.num; ++i) { +// if (0 == *(r+i)) { +// return false; +// } +// } return true; } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 8e7eaa0f8c..7a0deb8dc3 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -16,6 +16,35 @@ int32_t scalarGetOperatorParamNum(EOperatorType type) { return 2; } +SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) { + SColumnInfoData* pColumnData = calloc(1, sizeof(SColumnInfoData)); + if (pColumnData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pColumnData->info.type = pType->type; + pColumnData->info.bytes = pType->bytes; + pColumnData->info.scale = pType->scale; + pColumnData->info.precision = pType->precision; + + int32_t code = blockDataEnsureColumnCapacity(pColumnData, numOfRows); + if (code != TSDB_CODE_SUCCESS) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + tfree(pColumnData); + return NULL; + } else { + return pColumnData; + } +} + +int32_t doConvertDataType(SScalarParam* in, SScalarParam* out, SValueNode* pValueNode) { + in->columnData = createColumnInfoData(&pValueNode->node.resType, 1); + colDataAppend(in->columnData, 0, nodesGetValueFromNode(pValueNode), false); + + return vectorConvertImpl(in, out); +} + int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SHashObj *pObj = taosHashInit(256, taosGetDefaultHashFunction(type), true, false); if (NULL == pObj) { @@ -28,10 +57,9 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { int32_t code = 0; SNodeListNode *nodeList = (SNodeListNode *)pNode; SListCell *cell = nodeList->pNodeList->pHead; - SScalarParam in = {.num = 1}, out = {.num = 1, .type = type}; - int8_t dummy = 0; - int32_t bufLen = 60; - out.data = malloc(bufLen); + + SScalarParam in = {.columnData = calloc(1, sizeof(SColumnInfoData))}, out = {.columnData = calloc(1, sizeof(SColumnInfoData))}; + int32_t len = 0; void *buf = NULL; @@ -39,22 +67,18 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { SValueNode *valueNode = (SValueNode *)cell->pNode; if (valueNode->node.resType.type != type) { - in.type = valueNode->node.resType.type; - in.bytes = valueNode->node.resType.bytes; - in.data = nodesGetValueFromNode(valueNode); - - code = vectorConvertImpl(&in, &out); + doConvertDataType(&in, &out, valueNode); if (code) { - sclError("convert from %d to %d failed", in.type, out.type); +// sclError("convert data from %d to %d failed", in.type, out.type); SCL_ERR_JRET(code); } if (IS_VAR_DATA_TYPE(type)) { - len = varDataLen(out.data); - buf = varDataVal(out.data); + len = varDataLen(out.columnData->pData); + buf = varDataVal(out.columnData->pData); } else { len = tDataTypes[type].bytes; - buf = out.data; + buf = out.columnData->pData; } } else { buf = nodesGetValueFromNode(valueNode); @@ -63,11 +87,10 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { buf = varDataVal(buf); } else { len = valueNode->node.resType.bytes; - buf = out.data; - } + } } - if (taosHashPut(pObj, buf, (size_t)len, &dummy, sizeof(dummy))) { + if (taosHashPut(pObj, buf, (size_t)len, NULL, 0)) { sclError("taosHashPut failed"); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -75,40 +98,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { cell = cell->pNext; } - tfree(out.data); *data = pObj; - return TSDB_CODE_SUCCESS; _return: - - tfree(out.data); taosHashCleanup(pObj); - SCL_RET(code); } -FORCE_INLINE bool sclIsNull(SScalarParam* param, int32_t idx) { - if (param->dataInBlock) { - return colDataIsNull(param->orig.columnData, 0, idx, NULL); - } - - return param->bitmap ? colDataIsNull_f(param->bitmap, idx) : false; -} - -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); -} - - void sclFreeRes(SHashObj *res) { SScalarParam *p = NULL; void *pIter = taosHashIterate(res, NULL); @@ -118,31 +115,26 @@ void sclFreeRes(SHashObj *res) { if (p) { sclFreeParam(p); } - pIter = taosHashIterate(res, pIter); } - taosHashCleanup(res); } void sclFreeParamNoData(SScalarParam *param) { - tfree(param->bitmap); +// tfree(param->bitmap); } - void sclFreeParam(SScalarParam *param) { sclFreeParamNoData(param); - - if (!param->dataInBlock) { - if (SCL_DATA_TYPE_DUMMY_HASH == param->type) { - taosHashCleanup((SHashObj *)param->orig.data); - } else { - tfree(param->orig.data); - } - } +// if (!param->dataInBlock) { +// if (SCL_DATA_TYPE_DUMMY_HASH == param->type) { +// taosHashCleanup((SHashObj *)param->orig.data); +// } else { +// tfree(param->orig.data); +// } +// } } - int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { if (TSDB_DATA_TYPE_NULL == pNode->node.resType.type) { return TSDB_CODE_SUCCESS; @@ -155,7 +147,6 @@ int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { } memcpy(*res, nodesGetValueFromNode(pNode), pNode->node.resType.bytes); - return TSDB_CODE_SUCCESS; } @@ -163,19 +154,17 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t switch (nodeType(node)) { case QUERY_NODE_VALUE: { SValueNode *valueNode = (SValueNode *)node; - //SCL_ERR_RET(sclCopyValueNodeValue(valueNode, ¶m->data)); - param->data = nodesGetValueFromNode(valueNode); - param->orig.data = param->data; - param->num = 1; - param->type = valueNode->node.resType.type; - param->bytes = valueNode->node.resType.bytes; - if (TSDB_DATA_TYPE_NULL == param->type) { - sclSetNull(param, 0); + + param->numOfRows = 1; + param->columnData = createColumnInfoData(&valueNode->node.resType, 1); + if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type) { + colDataAppend(param->columnData, 0, NULL, true); + } else { + colDataAppend(param->columnData, 0, nodesGetValueFromNode(valueNode), false); } - param->dataInBlock = false; - break; } + case QUERY_NODE_NODE_LIST: { SNodeListNode *nodeList = (SNodeListNode *)node; if (nodeList->pNodeList->length <= 0) { @@ -183,15 +172,9 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t SCL_RET(TSDB_CODE_QRY_INVALID_INPUT); } - 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; - + SCL_ERR_RET(scalarGenerateSetFromList((void**) ¶m->pHashFilter, node, nodeList->dataType.type)); if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) { - taosHashCleanup(param->orig.data); - param->orig.data = NULL; + taosHashCleanup(param->pHashFilter); sclError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param)); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -210,21 +193,14 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t } SSDataBlock *block = *(SSDataBlock **)taosArrayGet(ctx->pBlockList, ref->dataBlockId); - 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(block->pDataBlock, ref->slotId); - param->data = NULL; - param->orig.columnData = columnData; - param->dataInBlock = true; - - param->num = block->info.rows; - param->type = columnData->info.type; - param->bytes = columnData->info.bytes; - + param->numOfRows = block->info.rows; + param->columnData = columnData; break; } case QUERY_NODE_LOGIC_CONDITION: @@ -234,9 +210,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t sclError("no result for node, type:%d, node:%p", nodeType(node), node); SCL_ERR_RET(TSDB_CODE_QRY_APP_ERROR); } - *param = *res; - break; } @@ -244,39 +218,13 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t break; } - if (param->num > *rowNum) { - if ((1 != param->num) && (1 < *rowNum)) { - sclError("different row nums, rowNum:%d, newRowNum:%d", *rowNum, param->num); + if (param->numOfRows > *rowNum) { + if ((1 != param->numOfRows) && (1 < *rowNum)) { + sclError("different row nums, rowNum:%d, newRowNum:%d", *rowNum, param->numOfRows); SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } - *rowNum = param->num; - } - - return TSDB_CODE_SUCCESS; -} - -int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx) { - SScalarParam *param = NULL; - - for (int32_t i = 0; i < listNum; ++i) { - param = params + i; - - if (1 == param->num) { - continue; - } - - if (param->dataInBlock) { - param->data = colDataGetData(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; - } + *rowNum = param->numOfRows; } return TSDB_CODE_SUCCESS; @@ -298,16 +246,13 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC } SCL_ERR_JRET(sclInitParam(cell->pNode, ¶mList[i], ctx, rowNum)); - cell = cell->pNext; } *pParams = paramList; - return TSDB_CODE_SUCCESS; _return: - tfree(paramList); SCL_RET(code); } @@ -332,16 +277,13 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal } *pParams = paramList; - return TSDB_CODE_SUCCESS; _return: - tfree(paramList); SCL_RET(code); } - int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { sclError("invalid function parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); @@ -359,18 +301,16 @@ int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outpu int32_t rowNum = 0; SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum)); - output->type = node->node.resType.type; - output->data = calloc(rowNum, sizeof(tDataTypes[output->type].bytes)); - if (NULL == output->data) { - sclError("calloc %d failed", (int32_t)(rowNum * sizeof(tDataTypes[output->type].bytes))); + output->columnData->info.type = node->node.resType.type; + output->columnData->info.bytes = tDataTypes[node->node.resType.type].bytes; + + code = blockDataEnsureColumnCapacity(output->columnData, rowNum); + if (code != TSDB_CODE_SUCCESS) { + sclError("calloc %d failed", (int32_t)(rowNum * output->columnData->info.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); - sclMoveParamListData(params, node->pParameterList->length, i); - code = (*ffpSet.process)(params, node->pParameterList->length, output); if (code) { sclError("scalar function exec failed, funcId:%d, code:%s", node->funcId, tstrerror(code)); @@ -385,11 +325,9 @@ _return: } tfree(params); - SCL_RET(code); } - int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *output) { if (NULL == node->pParameterList || node->pParameterList->length <= 0) { sclError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); @@ -409,28 +347,24 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o SScalarParam *params = NULL; int32_t rowNum = 0; int32_t code = 0; - SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum)); - output->type = node->node.resType.type; - output->bytes = sizeof(bool); - output->num = rowNum; - output->data = calloc(rowNum, sizeof(bool)); - if (NULL == output->data) { + int32_t type = node->node.resType.type; + output->numOfRows = rowNum; + + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + output->columnData = createColumnInfoData(&t, rowNum); + if (output->columnData == NULL) { sclError("calloc %d failed", (int32_t)(rowNum * sizeof(bool))); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - output->orig.data = output->data; bool value = false; - for (int32_t i = 0; i < rowNum; ++i) { - sclMoveParamListData(output, 1, i); - sclMoveParamListData(params, node->pParameterList->length, i); - for (int32_t m = 0; m < node->pParameterList->length; ++m) { - GET_TYPED_DATA(value, bool, params[m].type, params[m].data); - + char* p = colDataGetData(params[m].columnData, i); + GET_TYPED_DATA(value, bool, params[m].columnData->info.type, p); + if (LOGIC_COND_TYPE_AND == node->condType && (false == value)) { break; } else if (LOGIC_COND_TYPE_OR == node->condType && value) { @@ -440,11 +374,10 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o } } - *(bool *)output->data = value; + colDataAppend(output->columnData, i, (char*) &value, false); } _return: - for (int32_t i = 0; i < node->pParameterList->length; ++i) { sclFreeParamNoData(params + i); } @@ -459,16 +392,11 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp int32_t code = 0; SCL_ERR_RET(sclInitOperatorParams(¶ms, node, ctx, &rowNum)); - - output->type = node->node.resType.type; - output->num = rowNum; - output->bytes = tDataTypes[output->type].bytes; - output->data = calloc(rowNum, tDataTypes[output->type].bytes); - if (NULL == output->data) { - sclError("calloc %d failed", (int32_t)rowNum * tDataTypes[output->type].bytes); + output->columnData = createColumnInfoData(&node->node.resType, rowNum); + if (output->columnData == NULL) { + sclError("calloc failed, size:%d", (int32_t)rowNum * node->node.resType.bytes); SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY); } - output->orig.data = output->data; _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(node->opType); @@ -479,18 +407,14 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp OperatorFn(pLeft, pRight, output, TSDB_ORDER_ASC); _return: - - for (int32_t i = 0; i < paramNum; ++i) { sclFreeParamNoData(params + i); } tfree(params); - SCL_RET(code); } - EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)*pNode; SScalarParam output = {0}; @@ -510,11 +434,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); @@ -527,8 +452,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)*pNode; - SScalarParam output = {0}; + SScalarParam output = {.columnData = calloc(1, sizeof(SColumnInfoData))}; ctx->code = sclExecLogic(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -544,11 +469,12 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); @@ -561,8 +487,8 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)*pNode; - SScalarParam output = {0}; + SScalarParam output = {.columnData = calloc(1, sizeof(SColumnInfoData))}; ctx->code = sclExecOperator(node, ctx, &output); if (ctx->code) { return DEAL_RES_ERROR; @@ -578,22 +504,21 @@ EDealRes sclRewriteOperator(SNode** pNode, SScalarCtx *ctx) { res->node.resType = node->node.resType; - if (IS_VAR_DATA_TYPE(output.type)) { - res->datum.p = output.data; - output.data = NULL; + int32_t type = output.columnData->info.type; + if (IS_VAR_DATA_TYPE(type)) { + res->datum.p = output.columnData->pData; + output.columnData->pData = NULL; } else { - memcpy(nodesGetValueFromNode(res), output.data, tDataTypes[output.type].bytes); + memcpy(nodesGetValueFromNode(res), output.columnData->pData, tDataTypes[type].bytes); } nodesDestroyNode(*pNode); *pNode = (SNode*)res; sclFreeParam(&output); - return DEAL_RES_CONTINUE; } - EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) { return DEAL_RES_CONTINUE; @@ -614,13 +539,10 @@ EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) { } sclError("invalid node type for calculating constants, type:%d", nodeType(*pNode)); - ctx->code = TSDB_CODE_QRY_INVALID_INPUT; - return DEAL_RES_ERROR; } - EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { SFunctionNode *node = (SFunctionNode *)pNode; SScalarParam output = {0}; @@ -638,7 +560,6 @@ EDealRes sclWalkFunction(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } - EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { SLogicConditionNode *node = (SLogicConditionNode *)pNode; SScalarParam output = {0}; @@ -656,7 +577,6 @@ EDealRes sclWalkLogic(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_CONTINUE; } - EDealRes sclWalkOperator(SNode* pNode, SScalarCtx *ctx) { SOperatorNode *node = (SOperatorNode *)pNode; SScalarParam output = {0}; @@ -699,27 +619,26 @@ EDealRes sclWalkTarget(SNode* pNode, SScalarCtx *ctx) { return DEAL_RES_ERROR; } - for (int32_t i = 0; i < res->num; ++i) { - sclMoveParamListData(res, 1, i); - - colDataAppend(col, i, res->data, sclIsNull(res, i)); + for (int32_t i = 0; i < res->numOfRows; ++i) { + if (colDataIsNull(res->columnData, res->numOfRows, i, NULL)) { + colDataAppend(col, i, NULL, true); + } else { + char *p = colDataGetData(res->columnData, i); + colDataAppend(col, i, p, false); + } } sclFreeParam(res); - taosHashRemove(ctx->pRes, (void *)&target->pExpr, POINTER_BYTES); - 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, ctx); } @@ -737,14 +656,10 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) { } sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode)); - ctx->code = TSDB_CODE_QRY_INVALID_INPUT; - return DEAL_RES_ERROR; } - - int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { if (NULL == pNode) { SCL_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); @@ -759,15 +674,11 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) { } nodesRewriteNodePostOrder(&pNode, sclConstantsRewriter, (void *)&ctx); - SCL_ERR_JRET(ctx.code); - *pRes = pNode; _return: - sclFreeRes(ctx.pRes); - return code; } @@ -786,7 +697,6 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { } nodesWalkNodePostOrder(pNode, sclCalcWalker, (void *)&ctx); - SCL_ERR_JRET(ctx.code); if (pDst) { @@ -796,18 +706,14 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { SCL_ERR_JRET(TSDB_CODE_QRY_APP_ERROR); } - sclMoveParamListData(res, 1, 0); - +// sclMoveParamListData(res, 1, 0); *pDst = *res; - taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); } _return: - //nodesDestroyNode(pNode); sclFreeRes(ctx.pRes); - return code; } diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index fd900afcda..b8c8a59d7e 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -2,15 +2,15 @@ #include "sclvector.h" static void assignBasicParaInfo(struct SScalarParam* dst, const struct SScalarParam* src) { - dst->type = src->type; - dst->bytes = src->bytes; - dst->num = src->num; +// dst->type = src->type; +// dst->bytes = src->bytes; +// dst->num = src->num; } static void tceil(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assignBasicParaInfo(pOutput, pLeft); assert(numOfInput == 1); - +#if 0 switch (pLeft->bytes) { case TSDB_DATA_TYPE_FLOAT: { float* p = (float*) pLeft->data; @@ -31,12 +31,14 @@ static void tceil(SScalarParam* pOutput, size_t numOfInput, const SScalarParam * default: memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes); } +#endif + } static void tfloor(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assignBasicParaInfo(pOutput, pLeft); assert(numOfInput == 1); - +#if 0 switch (pLeft->bytes) { case TSDB_DATA_TYPE_FLOAT: { float* p = (float*) pLeft->data; @@ -59,12 +61,13 @@ static void tfloor(SScalarParam* pOutput, size_t numOfInput, const SScalarParam default: memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes); } +#endif } static void _tabs(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assignBasicParaInfo(pOutput, pLeft); assert(numOfInput == 1); - +#if 0 switch (pLeft->bytes) { case TSDB_DATA_TYPE_FLOAT: { float* p = (float*) pLeft->data; @@ -117,12 +120,13 @@ static void _tabs(SScalarParam* pOutput, size_t numOfInput, const SScalarParam * default: memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes); } +#endif } static void tround(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assignBasicParaInfo(pOutput, pLeft); assert(numOfInput == 1); - +#if 0 switch (pLeft->bytes) { case TSDB_DATA_TYPE_FLOAT: { float* p = (float*) pLeft->data; @@ -143,22 +147,24 @@ static void tround(SScalarParam* pOutput, size_t numOfInput, const SScalarParam default: memcpy(pOutput->data, pLeft->data, pLeft->num* pLeft->bytes); } +#endif } static void tlength(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assert(numOfInput == 1); - +#if 0 int64_t* out = (int64_t*) pOutput->data; char* s = pLeft->data; for(int32_t i = 0; i < pLeft->num; ++i) { out[i] = varDataLen(POINTER_SHIFT(s, i * pLeft->bytes)); } +#endif } static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { assert(numOfInput > 0); - +#if 0 int32_t rowLen = 0; int32_t num = 1; for(int32_t i = 0; i < numOfInput; ++i) { @@ -186,6 +192,7 @@ static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam rstart += rowLen; } +#endif } static void tltrim(SScalarParam* pOutput, size_t numOfInput, const SScalarParam *pLeft) { @@ -262,13 +269,12 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf } static void setScalarFuncParam(SScalarParam* param, int32_t type, int32_t bytes, void* pInput, int32_t numOfRows) { - param->bytes = bytes; - param->type = type; - param->num = numOfRows; - param->data = pInput; +// param->bytes = bytes; +// param->type = type; +// param->num = numOfRows; +// param->data = pInput; } - #if 0 int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param, char* (*getSourceDataBlock)(void*, const char*, int32_t)) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 17ac9b19fd..3495de106e 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -25,7 +25,7 @@ #include "tdatablock.h" #include "ttypes.h" -//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i])); +//GET_TYPED_DATA(v, double, GET_PARAM_TYPE(pRight), (char *)&((right)[i])); void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight, void *output, int32_t order) { int32_t *pLeft = (int32_t *)left; @@ -64,6 +64,9 @@ void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight } } +#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type) +#define GET_PARAM_BYTES(_c) ((_c)->pColumnInfoData[0]->info.bytes) + typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index); double getVectorDoubleValue_TINYINT(void *src, int32_t index) { @@ -125,8 +128,6 @@ _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) { return p; } - - typedef int64_t (*_getBigintValue_fn_t)(void *src, int32_t index); int64_t getVectorBigintValue_TINYINT(void *src, int32_t index) { @@ -187,9 +188,6 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { return p; } - - - typedef void* (*_getValueAddr_fn_t)(void *src, int32_t index); void* getVectorValueAddr_TINYINT(void *src, int32_t index) { @@ -263,23 +261,23 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { 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); + SET_TYPED_DATA(pOut->columnData->pData, outType, value); } 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); + SET_TYPED_DATA(pOut->columnData->pData, 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); + SET_TYPED_DATA(pOut->columnData->pData, outType, value); } - int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { - int32_t bufSize = 0; - char *tmp = NULL; + int32_t bufSize = pIn->columnData->info.bytes; + char *tmp = malloc(bufSize); + _bufConverteFunc func = NULL; if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType || TSDB_DATA_TYPE_BOOL == outType) { @@ -293,30 +291,20 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t return TSDB_CODE_QRY_APP_ERROR; } - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) { + colDataAppend(pOut->columnData, i, NULL, true); continue; } + char* data = colDataGetData(pIn->columnData, i); 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; + memcpy(tmp, varDataVal(data), varDataLen(data)); + tmp[varDataLen(data)] = 0; } else { - if (varDataLen(pIn->data) * TSDB_NCHAR_SIZE >= bufSize) { - bufSize = varDataLen(pIn->data) * TSDB_NCHAR_SIZE + 1; - tmp = realloc(tmp, bufSize); - } + ASSERT (varDataLen(data) <= bufSize); - int len = taosUcs4ToMbs((TdUcs4*)varDataVal(pIn->data), varDataLen(pIn->data), tmp); + int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp); if (len < 0){ sclError("castConvert taosUcs4ToMbs error 1"); tfree(tmp); @@ -330,17 +318,18 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t } tfree(tmp); - return TSDB_CODE_SUCCESS; } +// TODO opt performance int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { - int16_t inType = pIn->type; - int16_t inBytes = pIn->bytes; - int16_t outType = pOut->type; - int16_t outBytes = pOut->bytes; + SColumnInfoData* pInputCol = pIn->columnData; + SColumnInfoData* pOutputCol = pOut->columnData; + + int16_t inType = pInputCol->info.type; + int16_t outType = pOutputCol->info.type; - if (inType == TSDB_DATA_TYPE_BINARY || inType == TSDB_DATA_TYPE_NCHAR) { + if (IS_VAR_DATA_TYPE(inType)) { return vectorConvertFromVarData(pIn, pOut, inType, outType); } @@ -351,55 +340,43 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { case TSDB_DATA_TYPE_INT: case TSDB_DATA_TYPE_BIGINT: case TSDB_DATA_TYPE_TIMESTAMP: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } int64_t value = 0; - - GET_TYPED_DATA(value, int64_t, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); } break; case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_USMALLINT: case TSDB_DATA_TYPE_UINT: case TSDB_DATA_TYPE_UBIGINT: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } uint64_t value = 0; - - GET_TYPED_DATA(value, uint64_t, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, uint64_t, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); } break; case TSDB_DATA_TYPE_FLOAT: case TSDB_DATA_TYPE_DOUBLE: - for (int32_t i = 0; i < pIn->num; ++i) { - sclMoveParamListData(pIn, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pIn, i)) { - sclSetNull(pOut, i); + for (int32_t i = 0; i < pIn->numOfRows; ++i) { + if (colDataIsNull_f(pInputCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } double value = 0; - - GET_TYPED_DATA(value, double, inType, pIn->data); - SET_TYPED_DATA(pOut->data, outType, value); + GET_TYPED_DATA(value, double, inType, colDataGetData(pInputCol, i)); + colDataAppend(pOutputCol, i, (char*) &value, false); } break; default: @@ -446,11 +423,13 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { } int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* pLeftOut, SScalarParam* pRightOut) { - if (pLeft->type == pRight->type) { + if (pLeft->pHashFilter != NULL || pRight->pHashFilter != NULL) { return TSDB_CODE_SUCCESS; } - if (SCL_DATA_TYPE_DUMMY_HASH == pLeft->type || SCL_DATA_TYPE_DUMMY_HASH == pRight->type) { + int32_t leftType = GET_PARAM_TYPE(pLeft); + int32_t rightType = GET_PARAM_TYPE(pRight); + if (leftType == rightType) { return TSDB_CODE_SUCCESS; } @@ -458,7 +437,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p SScalarParam *param2 = NULL, *paramOut2 = NULL; int32_t code = 0; - if (pLeft->type < pRight->type) { + if (leftType < rightType) { param1 = pLeft; param2 = pRight; paramOut1 = pLeftOut; @@ -470,44 +449,38 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p paramOut2 = pLeftOut; } - - int8_t type = vectorGetConvertType(param1->type, param2->type); + int8_t type = vectorGetConvertType(GET_PARAM_TYPE(param1), GET_PARAM_TYPE(param2)); if (0 == type) { return TSDB_CODE_SUCCESS; } - if (type != param1->type) { - paramOut1->bytes = param1->bytes; - paramOut1->type = type; - paramOut1->num = param1->num; - paramOut1->data = malloc(paramOut1->num * tDataTypes[paramOut1->type].bytes); - if (NULL == paramOut1->data) { - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (type != GET_PARAM_TYPE(param1)) { + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + paramOut1->numOfRows = param1->numOfRows; + + paramOut1->columnData = createColumnInfoData(&t, param1->numOfRows); + if (paramOut1->columnData == NULL) { + return terrno; } - paramOut1->orig.data = paramOut1->data; - + code = vectorConvertImpl(param1, paramOut1); if (code) { - tfree(paramOut1->data); +// tfree(paramOut1->data); return code; } } - if (type != param2->type) { - paramOut2->bytes = param2->bytes; - paramOut2->type = type; - paramOut2->num = param2->num; - paramOut2->data = malloc(paramOut2->num * tDataTypes[paramOut2->type].bytes); - if (NULL == paramOut2->data) { - tfree(paramOut1->data); - return TSDB_CODE_QRY_OUT_OF_MEMORY; + if (type != GET_PARAM_TYPE(param2)) { + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + paramOut2->numOfRows = param2->numOfRows; + + paramOut2->columnData = createColumnInfoData(&t, param2->numOfRows); + if (paramOut2->columnData == NULL) { + return terrno; } - paramOut2->orig.data = paramOut2->data; - + code = vectorConvertImpl(param2, paramOut2); if (code) { - tfree(paramOut1->data); - tfree(paramOut2->data); return code; } } @@ -515,144 +488,350 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p return TSDB_CODE_SUCCESS; } -void vectorMath(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, _mathFunc func) { - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; - int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - double leftv = 0, rightv = 0; - bool isNull = false; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { - leftParam.data = calloc(leftParam.num, sizeof(double)); - if (NULL == leftParam.data) { - sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); - return; - } - leftParam.orig.data = leftParam.data; +static int32_t doConvertHelper(SScalarParam* pParam, int32_t type) { + SScalarParam param = {0}; + SColumnInfoData* pCol = pParam->columnData; - if (vectorConvertImpl(pLeft, &leftParam)) { - return; + if (IS_VAR_DATA_TYPE(pCol->info.type)) { + param.numOfRows = pParam->numOfRows; + + SDataType t = {.type = type, .bytes = tDataTypes[type].bytes}; + param.columnData = createColumnInfoData(&t, pParam->numOfRows); + if (param.columnData == NULL) { + sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double))); + return TSDB_CODE_OUT_OF_MEMORY; } - pLeft = &leftParam; - } - if (IS_VAR_DATA_TYPE(pRight->type)) { - rightParam.data = calloc(rightParam.num, sizeof(double)); - if (NULL == rightParam.data) { - sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); - sclFreeParam(&leftParam); - return; + + int32_t code = vectorConvertImpl(pParam, ¶m); + if (code != TSDB_CODE_SUCCESS) { + return code; } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; + + colDataDestroy(pParam->columnData); + pParam->columnData = param.columnData; } - if (pLeft->num == pRight->num) { - 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); + return TSDB_CODE_SUCCESS; +} + +// TODO not correct for descending order scan +static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + doConvertHelper(pLeft, TSDB_DATA_TYPE_DOUBLE); + doConvertHelper(pRight, TSDB_DATA_TYPE_DOUBLE); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); + } +} + +// TODO not correct for descending order scan +static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor; + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + doConvertHelper(pLeft, TSDB_DATA_TYPE_DOUBLE); + doConvertHelper(pRight, TSDB_DATA_TYPE_DOUBLE); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i); + } else if (pRight->numOfRows == 1) { + vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i); + } +} + +// TODO not correct for descending order scan +static void vectorMathMultiplyHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + doConvertHelper(pLeft, TSDB_DATA_TYPE_DOUBLE); + doConvertHelper(pRight, TSDB_DATA_TYPE_DOUBLE); + + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorMathMultiplyHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorMathMultiplyHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); + } +} + +// TODO not correct for descending order scan +static void vectorMathDivideHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} + +void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + doConvertHelper(pLeft, TSDB_DATA_TYPE_DOUBLE); + doConvertHelper(pRight, TSDB_DATA_TYPE_DOUBLE); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { // check for the 0 value + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, 0) / getVectorDoubleValueFnRight(pRightCol->pData, i); + } + pOutputCol->hasNull = pRightCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pRightCol->nullbitmap, BitmapLen(pRight->numOfRows)); + } + } + } else if (pRight->numOfRows == 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { + output[i] = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows)); + } + } + } +} + +void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; + int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1; + + doConvertHelper(pLeft, TSDB_DATA_TYPE_DOUBLE); + doConvertHelper(pRight, TSDB_DATA_TYPE_DOUBLE); + + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + double zero = 0.0; + + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; - } - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - 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; - } - - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; - } - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); - - 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); + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i); + double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + if (compareDoubleVal(&zero, &rx)) { + colDataAppend(pOutputCol, i, NULL, true); continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - - SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); - if (isNull) { - sclSetNull(pOut, i); - isNull = false; + output[i] = lx - ((int64_t)(lx / rx)) * rx; + } + } else if (pLeft->numOfRows == 1) { + double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, 0); + if (colDataIsNull_f(pLeftCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + double rx = getVectorDoubleValueFnRight(pRightCol->pData, i); + if (compareDoubleVal(&zero, &rx)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + output[i] = lx - ((int64_t)(lx / rx)) * rx; + } + } + } else if (pRight->numOfRows == 1) { + double rx = getVectorDoubleValueFnRight(pRightCol->pData, 0); + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) { + if (colDataIsNull_f(pRightCol->nullbitmap, i)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + double lx = getVectorDoubleValueFnLeft(pRightCol->pData, i); + if (compareDoubleVal(&zero, &lx)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + output[i] = lx - ((int64_t)(lx / rx)) * rx; } } } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); } -double mathAdd(double leftv, double rightv, bool *isNull) { - return leftv + rightv; -} - -double mathSub(double leftv, double rightv, bool *isNull) { - return leftv - rightv; -} - -double mathMultiply(double leftv, double rightv, bool *isNull) { - return leftv * rightv; -} - -double mathDivide(double leftv, double rightv, bool *isNull) { - double zero = 0; - if (0 == compareDoubleVal(&rightv, &zero)) { - *isNull = true; - return zero; - } - - return leftv / rightv; -} - -double mathRemainder(double leftv, double rightv, bool *isNull) { - double zero = 0; - if (0 == compareDoubleVal(&rightv, &zero)) { - *isNull = true; - return zero; - } - - return leftv - ((int64_t)(leftv / rightv)) * rightv; -} - - +#if 0 void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { vectorMath(pLeft, pRight, pOut, _ord, mathAdd); } @@ -673,14 +852,14 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO vectorMath(pLeft, pRight, pOut, _ord, mathRemainder); } -#if 0 +//#if 0 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { + SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->numOfRows, .dataInBlock = false}; + SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->numOfRows, .dataInBlock = false}; + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pLeft))) { leftParam.data = calloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); @@ -693,7 +872,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in } pLeft = &leftParam; } - if (IS_VAR_DATA_TYPE(pRight->type)) { + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pRight))) { rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); @@ -710,8 +889,8 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in pRight = &rightParam; } - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -721,16 +900,16 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); SET_DOUBLE_VAL(pOut->data, leftv + rightv); } - } else if (pLeft->num == 1) { + } else if (pLeft->numOfRows == 1) { sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); - for (; i >= 0 && i < pRight->num; i += step) { + for (; i >= 0 && i < pRight->numOfRows; i += step) { sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -739,15 +918,15 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in continue; } - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); SET_DOUBLE_VAL(pOut->data, leftv + rightv); } - } else if (pRight->num == 1) { + } else if (pRight->numOfRows == 1) { sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); - for (; i >= 0 && i < pLeft->num; i += step) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pOut, 1, i); @@ -756,7 +935,7 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); SET_DOUBLE_VAL(pOut->data, leftv + rightv); } @@ -767,13 +946,13 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in } 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { + SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->numOfRows}; + SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->numOfRows}; + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pLeft))) { leftParam.data = calloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); @@ -786,7 +965,7 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in } pLeft = &leftParam; } - if (IS_VAR_DATA_TYPE(pRight->type)) { + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pRight))) { rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); @@ -804,11 +983,11 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in } - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(GET_PARAM_TYPE(pLeft)); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(GET_PARAM_TYPE(pRight)); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -818,16 +997,16 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i)); } - } else if (pLeft->num == 1) { + } else if (pLeft->numOfRows == 1) { sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); - for (; i >= 0 && i < pRight->num; i += step) { + for (; i >= 0 && i < pRight->numOfRows; i += step) { sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -838,8 +1017,8 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in 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) { + } else if (pRight->numOfRows == 1) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pOut, 1, i); @@ -856,13 +1035,13 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, in sclFreeParam(&rightParam); } 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { + SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->numOfRows}; + SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->numOfRows}; + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pLeft))) { leftParam.data = calloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); @@ -875,7 +1054,7 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu } pLeft = &leftParam; } - if (IS_VAR_DATA_TYPE(pRight->type)) { + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pRight))) { rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); @@ -893,11 +1072,11 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu } - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(GET_PARAM_TYPE(pLeft)); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(GET_PARAM_TYPE(pRight)); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -907,16 +1086,16 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i)); } - } else if (pLeft->num == 1) { + } else if (pLeft->numOfRows == 1) { sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); - for (; i >= 0 && i < pRight->num; i += step) { + for (; i >= 0 && i < pRight->numOfRows; i += step) { sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -927,8 +1106,8 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu 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) { + } else if (pRight->numOfRows == 1) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pOut, 1, i); @@ -946,13 +1125,13 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu } 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { + SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->numOfRows}; + SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->numOfRows}; + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pLeft))) { leftParam.data = calloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); @@ -965,7 +1144,7 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, } pLeft = &leftParam; } - if (IS_VAR_DATA_TYPE(pRight->type)) { + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pRight))) { rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); @@ -983,11 +1162,11 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, } - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(GET_PARAM_TYPE(pLeft)); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(GET_PARAM_TYPE(pRight)); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -997,13 +1176,13 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); 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) { + } else if (pLeft->numOfRows == 1) { + for (; i >= 0 && i < pRight->numOfRows; i += step) { sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -1014,8 +1193,8 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, 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) { + } else if (pRight->numOfRows == 1) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pOut, 1, i); @@ -1033,13 +1212,13 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, } 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; double leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num}; - if (IS_VAR_DATA_TYPE(pLeft->type)) { + SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->numOfRows}; + SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->numOfRows}; + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pLeft))) { leftParam.data = calloc(leftParam.num, sizeof(double)); if (NULL == leftParam.data) { sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double))); @@ -1052,7 +1231,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO } pLeft = &leftParam; } - if (IS_VAR_DATA_TYPE(pRight->type)) { + if (IS_VAR_DATA_TYPE(GET_PARAM_TYPE(pRight))) { rightParam.data = calloc(rightParam.num, sizeof(double)); if (NULL == rightParam.data) { sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); @@ -1070,11 +1249,11 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO } - _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); - _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); + _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(GET_PARAM_TYPE(pLeft)); + _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(GET_PARAM_TYPE(pRight)); - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -1085,21 +1264,21 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); + GET_TYPED_DATA(v, double, GET_PARAM_TYPE(pRight), pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { sclSetNull(pOut, i); continue; } - GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); + GET_TYPED_DATA(leftv, double, GET_PARAM_TYPE(pLeft), pLeft->data); + GET_TYPED_DATA(rightv, double, GET_PARAM_TYPE(pRight), pRight->data); SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); } - } else if (pLeft->num == 1) { + } else if (pLeft->numOfRows == 1) { double left = getVectorDoubleValueFnLeft(pLeft->data, 0); - for (; i >= 0 && i < pRight->num; i += step) { + for (; i >= 0 && i < pRight->numOfRows; i += step) { sclMoveParamListData(pRight, 1, i); sclMoveParamListData(pOut, 1, i); @@ -1109,7 +1288,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); + GET_TYPED_DATA(v, double, GET_PARAM_TYPE(pRight), pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { sclSetNull(pOut, i); continue; @@ -1118,10 +1297,10 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO double right = getVectorDoubleValueFnRight(pRight->data, i); SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right); } - } else if (pRight->num == 1) { + } else if (pRight->numOfRows == 1) { double right = getVectorDoubleValueFnRight(pRight->data, 0); - for (; i >= 0 && i < pLeft->num; i += step) { + for (; i >= 0 && i < pLeft->numOfRows; i += step) { sclMoveParamListData(pLeft, 1, i); sclMoveParamListData(pOut, 1, i); @@ -1131,7 +1310,7 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO } double v, u = 0.0; - GET_TYPED_DATA(v, double, pRight->type, pRight->data); + GET_TYPED_DATA(v, double, GET_PARAM_TYPE(pRight), pRight->data); if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { sclSetNull(pOut, i); continue; @@ -1145,22 +1324,22 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO sclFreeParam(&leftParam); sclFreeParam(&rightParam); } - #endif void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) { +#if 0 int32_t len = pLeft->bytes + pRight->bytes; - int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; char *output = (char *)out; - if (pLeft->num == pRight->num) { - for (; i < pRight->num && i >= 0; i += step, output += len) { + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += len) { char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); char* right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - if (isNull(left, pLeft->type) || isNull(right, pRight->type)) { + if (isNull(left, GET_PARAM_TYPE(pLeft)) || isNull(right, GET_PARAM_TYPE(pRight))) { setVardataNull(output, TSDB_DATA_TYPE_BINARY); continue; } @@ -1170,10 +1349,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t memcpy(varDataVal(output) + varDataLen(left), varDataVal(right), varDataLen(right)); varDataSetLen(output, varDataLen(left) + varDataLen(right)); } - } else if (pLeft->num == 1) { - for (; i >= 0 && i < pRight->num; i += step, output += len) { + } else if (pLeft->numOfRows == 1) { + for (; i >= 0 && i < pRight->numOfRows; i += step, output += len) { char *right = POINTER_SHIFT(pRight->data, pRight->bytes * i); - if (isNull(pLeft->data, pLeft->type) || isNull(right, pRight->type)) { + if (isNull(pLeft->data, GET_PARAM_TYPE(pLeft)) || isNull(right, GET_PARAM_TYPE(pRight))) { setVardataNull(output, TSDB_DATA_TYPE_BINARY); continue; } @@ -1182,10 +1361,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t memcpy(varDataVal(output) + varDataLen(pLeft->data), varDataVal(right), varDataLen(right)); varDataSetLen(output, varDataLen(pLeft->data) + varDataLen(right)); } - } else if (pRight->num == 1) { - for (; i >= 0 && i < pLeft->num; i += step, output += len) { + } else if (pRight->numOfRows == 1) { + for (; i >= 0 && i < pLeft->numOfRows; i += step, output += len) { char* left = POINTER_SHIFT(pLeft->data, pLeft->bytes * i); - if (isNull(left, pLeft->type) || isNull(pRight->data, pRight->type)) { + if (isNull(left, GET_PARAM_TYPE(pLeft)) || isNull(pRight->data, GET_PARAM_TYPE(pRight))) { SET_DOUBLE_NULL(output); continue; } @@ -1195,258 +1374,163 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t varDataSetLen(output, varDataLen(left) + varDataLen(pRight->data)); } } +#endif } +static void vectorBitAndHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0); + } + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} 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; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - int64_t leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; - 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(double))); - return; - } - leftParam.orig.data = leftParam.data; + doConvertHelper(pLeft, TSDB_DATA_TYPE_BIGINT); + doConvertHelper(pRight, TSDB_DATA_TYPE_BIGINT); - if (vectorConvertImpl(pLeft, &leftParam)) { - return; + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; + + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(GET_PARAM_TYPE(pLeft)); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(GET_PARAM_TYPE(pRight)); + + int64_t *output = (int64_t *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, i); } - pLeft = &leftParam; + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] & pRightCol->nullbitmap[j]; + } + } + + } else if (pLeft->numOfRows == 1) { + vectorBitAndHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - 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(double))); - sclFreeParam(&leftParam); - return; +} + +static void vectorBitOrHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) { + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type); + + double *output = (double *)pOutputCol->pData; + + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step, output += 1) { + output[i] = getVectorBigintValueFnLeft(pLeftCol->pData, i) | getVectorBigintValueFnRight(pRightCol->pData, 0); } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } - - - _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) { - sclMoveParamListData(pLeft, 1, i); - sclMoveParamListData(pRight, 1, i); - sclMoveParamListData(pOut, 1, i); - - if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { - sclSetNull(pOut, i); - continue; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - 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; - } - - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - 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; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - SET_BIGINT_VAL(pOut->data, leftv & rightv); + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); } } - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); } 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; + SColumnInfoData *pOutputCol = pOut->columnData; + + int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - int64_t leftv = 0, rightv = 0; - SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num}; - SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num}; - 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(double))); - return; - } - leftParam.orig.data = leftParam.data; + doConvertHelper(pLeft, TSDB_DATA_TYPE_BIGINT); + doConvertHelper(pRight, TSDB_DATA_TYPE_BIGINT); - if (vectorConvertImpl(pLeft, &leftParam)) { - return; - } - pLeft = &leftParam; - } - 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(double))); - sclFreeParam(&leftParam); - return; - } - rightParam.orig.data = rightParam.data; - - if (vectorConvertImpl(pRight, &rightParam)) { - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); - return; - } - pRight = &rightParam; - } + SColumnInfoData *pLeftCol = pLeft->columnData; + SColumnInfoData *pRightCol = pRight->columnData; - _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeft->type); - _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRight->type); + _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(GET_PARAM_TYPE(pLeft)); + _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(GET_PARAM_TYPE(pRight)); - if (pLeft->num == pRight->num) { - 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; + int64_t *output = (int64_t *)pOutputCol->pData; + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) { + output[i] = getVectorBigintValueFnLeft(pLeftCol->pData, i) | getVectorBigintValueFnRight(pRightCol->pData, i); + } + + pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull); + if (pOutputCol->hasNull) { + int32_t numOfBitLen = BitmapLen(pLeft->numOfRows); + for (int32_t j = 0; j < numOfBitLen; ++j) { + pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j]; } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - 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; - } - - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); - - 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; - } - - GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data); - - SET_BIGINT_VAL(pOut->data, leftv | rightv); } + } else if (pLeft->numOfRows == 1) { + vectorBitOrHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i); + } else if (pRight->numOfRows == 1) { + vectorBitOrHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i); } - - - sclFreeParam(&leftParam); - sclFreeParam(&rightParam); } +static void vectorCompareHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i, + __compar_fn_t fp, int32_t optr) { + if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value + // TODO set numOfRows NULL value + } else { + for (; i >= 0 && i < numOfRows; i += step) { + if (colDataIsNull(pRightCol, numOfRows, i, NULL)) { + colDataAppend(pOutputCol, i, NULL, true); + continue; + } + + char *pLeftData = colDataGetData(pLeftCol, i); + char *pRightData = colDataGetData(pRightCol, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRightData); + colDataAppend(pOutputCol, i, (char *)&res, false); + } + + pOutputCol->hasNull = pLeftCol->hasNull; + if (pOutputCol->hasNull) { + memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows)); + } + } +} 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 i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1; int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; - __compar_fn_t fp = filterGetCompFunc(pLeft->type, optr); - bool res = false; + __compar_fn_t fp = filterGetCompFunc(GET_PARAM_TYPE(pLeft), optr); - if (pLeft->num == pRight->num) { - 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); + if (pLeft->numOfRows == pRight->numOfRows) { + for (; i < pRight->numOfRows && i >= 0; i += step) { + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) || + colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)) { continue; } - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); - } - } else if (pLeft->num == 1) { - sclMoveParamListData(pLeft, 1, 0); - - 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; - } - - - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); - } - } else if (pRight->num == 1) { - sclMoveParamListData(pRight, 1, 0); - - 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; - } - - res = filterDoCompare(fp, optr, pLeft->data, pRight->data); - - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + char *pLeftData = colDataGetData(pLeft->columnData, i); + char *pRightData = colDataGetData(pRight->columnData, i); + bool res = filterDoCompare(fp, optr, pLeftData, pRightData); + colDataAppend(pOut->columnData, i, (char*) &res, false); } + } else if (pLeft->numOfRows == 1) { + vectorCompareHelper(pRight->columnData, pLeft->columnData, pOut->columnData, pRight->numOfRows, step, i, fp, optr); + } else if (pRight->numOfRows == 1) { + vectorCompareHelper(pLeft->columnData, pRight->columnData, pOut->columnData, pLeft->numOfRows, step, i, fp, optr); } } @@ -1459,21 +1543,19 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut SScalarParam *param1 = NULL; SScalarParam *param2 = NULL; - int32_t type = 0; - if (pLeftOut.type) { + if (pLeftOut.columnData != NULL) { param1 = &pLeftOut; } else { param1 = pLeft; } - if (pRightOut.type) { + if (pRightOut.columnData != NULL) { param2 = &pRightOut; } else { param2 = pRight; } vectorCompareImpl(param1, param2, pOut, _ord, optr); - sclFreeParam(&pLeftOut); sclFreeParam(&pRightOut); } @@ -1527,63 +1609,41 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu } 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; - - 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(pOut->data, TSDB_DATA_TYPE_BOOL, res); - continue; + for(int32_t i = 0; i < pLeft->numOfRows; ++i) { + int8_t v = 0; + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { + v = 1; } - - res = false; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + colDataAppend(pOut->columnData, i, (char*) &v, false); } } 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; - - 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(pOut->data, TSDB_DATA_TYPE_BOOL, res); - continue; + for(int32_t i = 0; i < pLeft->numOfRows; ++i) { + int8_t v = 1; + if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL)) { + v = 0; } - - res = true; - SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); + colDataAppend(pOut->columnData, i, (char*) &v, false); } - } void vectorIsTrue(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { vectorConvertImpl(pLeft, pOut); } - _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { switch (binFunctionId) { case OP_TYPE_ADD: - return vectorAdd; + return vectorMathAdd; case OP_TYPE_SUB: - return vectorSub; + return vectorMathSub; case OP_TYPE_MULTI: - return vectorMultiply; + return vectorMathMultiply; case OP_TYPE_DIV: - return vectorDivide; + return vectorMathDivide; case OP_TYPE_MOD: - return vectorRemainder; + return vectorMathRemainder; case OP_TYPE_GREATER_THAN: return vectorGreater; case OP_TYPE_GREATER_EQUAL: diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index d6a73d99bb..61a40078fc 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -261,7 +261,7 @@ TEST(constantTest, bigint_add_bigint) { ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); SValueNode *v = (SValueNode *)res; ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(v->datum.d, (scltLeftV + scltRightV)); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftV + scltRightV)); nodesDestroyNode(res); } @@ -277,7 +277,7 @@ TEST(constantTest, double_sub_bigint) { ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE); SValueNode *v = (SValueNode *)res; ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_DOUBLE); - ASSERT_EQ(v->datum.d, (scltLeftVd - scltRightV)); + ASSERT_FLOAT_EQ(v->datum.d, (scltLeftVd - scltRightV)); nodesDestroyNode(res); } @@ -959,7 +959,6 @@ TEST(columnTest, bigint_column_multi_binary_column) { scltMakeColumnNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv); scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight); - SArray *blockList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(blockList, &src); SColumnInfo colInfo = createColumnInfo(1, TSDB_DATA_TYPE_DOUBLE, sizeof(double));