提交 400989c0 编写于 作者: H Haojun Liao

[td-13039] refactor scalar function.

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