feature/qnode
This commit is contained in:
parent
8f7b375b54
commit
93baf85a4f
|
@ -91,6 +91,8 @@ typedef struct {
|
|||
do { \
|
||||
switch (_type) { \
|
||||
case TSDB_DATA_TYPE_BOOL: \
|
||||
*(bool *)(_v) = (bool)(_data); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_TINYINT: \
|
||||
*(int8_t *)(_v) = (int8_t)(_data); \
|
||||
break; \
|
||||
|
|
|
@ -228,6 +228,7 @@ typedef struct SAggFunctionInfo {
|
|||
|
||||
typedef struct SScalarParam {
|
||||
void* data;
|
||||
bool colData;
|
||||
int32_t num;
|
||||
int32_t type;
|
||||
int32_t bytes;
|
||||
|
|
|
@ -141,6 +141,7 @@ typedef struct SLogicConditionNode {
|
|||
|
||||
typedef struct SNodeListNode {
|
||||
ENodeType type; // QUERY_NODE_NODE_LIST
|
||||
SDataType dataType;
|
||||
SNodeList* pNodeList;
|
||||
} SNodeListNode;
|
||||
|
||||
|
|
|
@ -546,7 +546,7 @@ int32_t ctgGetTableMetaFromCache(SCatalog* pCtg, const SName* pTableName, STable
|
|||
|
||||
if (tbMeta->tableType != TSDB_CHILD_TABLE) {
|
||||
ctgReleaseDBCache(pCtg, dbCache);
|
||||
ctgDebug("Got tbl from cache, type:%d, dbFName:%s, tbName:%s", tbMeta->tableType, dbFName, pTableName->tname);
|
||||
ctgDebug("Got meta from cache, type:%d, dbFName:%s, tbName:%s", tbMeta->tableType, dbFName, pTableName->tname);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,6 +63,8 @@ SNode* nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SNodeListNode));
|
||||
case QUERY_NODE_FILL:
|
||||
return makeNode(type, sizeof(SFillNode));
|
||||
case QUERY_NODE_COLUMN_REF:
|
||||
return makeNode(type, sizeof(SColumnRefNode));
|
||||
case QUERY_NODE_RAW_EXPR:
|
||||
return makeNode(type, sizeof(SRawExprNode));
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
|
|
|
@ -1820,6 +1820,9 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
|
|||
case TSDB_RELATION_LIKE: {
|
||||
return ret == 0;
|
||||
}
|
||||
case TSDB_RELATION_NOT_LIKE: {
|
||||
return ret == 0;
|
||||
}
|
||||
case TSDB_RELATION_MATCH: {
|
||||
return ret == 0;
|
||||
}
|
||||
|
@ -1829,6 +1832,9 @@ bool filterDoCompare(__compar_fn_t func, uint8_t optr, void *left, void *right)
|
|||
case TSDB_RELATION_IN: {
|
||||
return ret == 1;
|
||||
}
|
||||
case TSDB_RELATION_NOT_IN: {
|
||||
return ret == 1;
|
||||
}
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
|
|
|
@ -50,20 +50,28 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
|
|||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
len = varDataLen(out.data);
|
||||
buf = varDataVal(out.data);
|
||||
} else {
|
||||
len = tDataTypes[type].bytes;
|
||||
buf = out.data;
|
||||
}
|
||||
|
||||
buf = out.data;
|
||||
} else {
|
||||
buf = nodesGetValueFromNode(valueNode);
|
||||
len = valueNode->node.resType.bytes;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
len = varDataLen(buf);
|
||||
buf = varDataVal(buf);
|
||||
} else {
|
||||
len = valueNode->node.resType.bytes;
|
||||
buf = out.data;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosHashPut(pObj, buf, (size_t)len, &dummy, sizeof(dummy))) {
|
||||
sclError("taosHashPut failed");
|
||||
SCL_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
cell = cell->pNext;
|
||||
}
|
||||
|
||||
tfree(out.data);
|
||||
|
@ -108,6 +116,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
|
|||
param->num = 1;
|
||||
param->type = valueNode->node.resType.type;
|
||||
param->bytes = valueNode->node.resType.bytes;
|
||||
param->colData = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -121,6 +130,7 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
|
|||
SCL_ERR_RET(scalarGenerateSetFromList(¶m->data, node, nodeList->dataType.type));
|
||||
param->num = 1;
|
||||
param->type = SCL_DATA_TYPE_DUMMY_HASH;
|
||||
param->colData = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -137,7 +147,14 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t
|
|||
}
|
||||
|
||||
SColumnInfoData *columnData = (SColumnInfoData *)taosArrayGet(ctx->pSrc->pDataBlock, ref->slotId);
|
||||
param->data = columnData->pData;
|
||||
if (IS_VAR_DATA_TYPE(columnData->info.type)) {
|
||||
param->data = columnData;
|
||||
param->colData = true;
|
||||
} else {
|
||||
param->data = columnData->pData;
|
||||
param->colData = false;
|
||||
}
|
||||
|
||||
param->num = ctx->pSrc->info.rows;
|
||||
param->type = columnData->info.type;
|
||||
param->bytes = columnData->info.bytes;
|
||||
|
@ -366,6 +383,7 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
|
|||
|
||||
output->type = node->node.resType.type;
|
||||
output->num = rowNum;
|
||||
output->bytes = tDataTypes[output->type].bytes;
|
||||
output->data = calloc(rowNum, tDataTypes[output->type].bytes);
|
||||
if (NULL == output->data) {
|
||||
sclError("calloc %d failed", (int32_t)rowNum * tDataTypes[output->type].bytes);
|
||||
|
@ -377,21 +395,8 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp
|
|||
int32_t paramNum = scalarGetOperatorParamNum(node->opType);
|
||||
SScalarParam* pLeft = ¶ms[0];
|
||||
SScalarParam* pRight = paramNum > 1 ? ¶ms[1] : NULL;
|
||||
|
||||
void *data = output->data;
|
||||
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
|
||||
OperatorFn(pLeft, pRight, output->data, TSDB_ORDER_ASC);
|
||||
|
||||
sclParamMoveNext(output, 1);
|
||||
sclParamMoveNext(pLeft, 1);
|
||||
if (pRight) {
|
||||
sclParamMoveNext(pRight, 1);
|
||||
}
|
||||
}
|
||||
|
||||
output->data = data;
|
||||
OperatorFn(pLeft, pRight, output->data, TSDB_ORDER_ASC);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -506,7 +511,7 @@ EDealRes sclRewriteOperator(SNode** pNode, void* pContext) {
|
|||
|
||||
|
||||
EDealRes sclConstantsRewriter(SNode** pNode, void* pContext) {
|
||||
if (QUERY_NODE_VALUE == nodeType(*pNode)) {
|
||||
if (QUERY_NODE_VALUE == nodeType(*pNode) || QUERY_NODE_NODE_LIST == nodeType(*pNode)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -588,10 +593,10 @@ EDealRes sclWalkOperator(SNode* pNode, void* pContext) {
|
|||
|
||||
|
||||
EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
|
||||
if (QUERY_NODE_VALUE == nodeType(pNode)) {
|
||||
if (QUERY_NODE_VALUE == nodeType(pNode) || QUERY_NODE_NODE_LIST == nodeType(pNode) || QUERY_NODE_COLUMN_REF == nodeType(pNode)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pNode)) {
|
||||
return sclWalkFunction(pNode, pContext);
|
||||
}
|
||||
|
@ -604,7 +609,7 @@ EDealRes sclCalcWalker(SNode* pNode, void* pContext) {
|
|||
return sclWalkOperator(pNode, pContext);
|
||||
}
|
||||
|
||||
sclError("invalid node type for calculating constants, type:%d", nodeType(pNode));
|
||||
sclError("invalid node type for scalar calculating, type:%d", nodeType(pNode));
|
||||
|
||||
SScalarCtx *ctx = (SScalarCtx *)pContext;
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "querynodes.h"
|
||||
#include "filterInt.h"
|
||||
#include "query.h"
|
||||
#include "sclInt.h"
|
||||
#include "tep.h"
|
||||
|
||||
//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i]));
|
||||
|
||||
|
@ -93,6 +95,7 @@ double getVectorDoubleValue_FLOAT(void *src, int32_t index) {
|
|||
double getVectorDoubleValue_DOUBLE(void *src, int32_t index) {
|
||||
return (double)*((double *)src + index);
|
||||
}
|
||||
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
|
||||
_getDoubleValue_fn_t p = NULL;
|
||||
if(srcType==TSDB_DATA_TYPE_TINYINT) {
|
||||
|
@ -218,6 +221,12 @@ void* getVectorValueAddr_FLOAT(void *src, int32_t index) {
|
|||
void* getVectorValueAddr_DOUBLE(void *src, int32_t index) {
|
||||
return (void*)((double *)src + index);
|
||||
}
|
||||
void* getVectorValueAddr_default(void *src, int32_t index) {
|
||||
return src;
|
||||
}
|
||||
void* getVectorValueAddr_VAR(void *src, int32_t index) {
|
||||
return colDataGet((SColumnInfoData *)src, index);
|
||||
}
|
||||
|
||||
_getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
|
||||
_getValueAddr_fn_t p = NULL;
|
||||
|
@ -241,8 +250,12 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
|
|||
p = getVectorValueAddr_FLOAT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
|
||||
p = getVectorValueAddr_DOUBLE;
|
||||
}else if(srcType==TSDB_DATA_TYPE_BINARY) {
|
||||
p = getVectorValueAddr_VAR;
|
||||
}else if(srcType==TSDB_DATA_TYPE_NCHAR) {
|
||||
p = getVectorValueAddr_VAR;
|
||||
}else {
|
||||
assert(0);
|
||||
p = getVectorValueAddr_default;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
@ -267,6 +280,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) + 1;
|
||||
char *tmp = malloc(bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("malloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -295,6 +309,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1;
|
||||
char *tmp = calloc(1, bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("calloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -309,7 +324,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
|
||||
int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), tmp);
|
||||
if (len < 0){
|
||||
qError("castConvert taosUcs4ToMbs error 1");
|
||||
sclError("castConvert taosUcs4ToMbs error 1");
|
||||
tfree(tmp);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
@ -343,6 +358,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) + 1;
|
||||
char *tmp = malloc(bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("malloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -370,6 +386,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1;
|
||||
char *tmp = calloc(1, bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("calloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -384,7 +401,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
|
||||
int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), tmp);
|
||||
if (len < 0){
|
||||
qError("castConvert taosUcs4ToMbs error 1");
|
||||
sclError("castConvert taosUcs4ToMbs error 1");
|
||||
tfree(tmp);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
@ -420,6 +437,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) + 1;
|
||||
char *tmp = malloc(bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("malloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -448,6 +466,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
int32_t bufSize = varDataLen(input) * TSDB_NCHAR_SIZE + 1;
|
||||
char *tmp = calloc(1, bufSize);
|
||||
if (NULL == tmp) {
|
||||
sclError("calloc %d failed", bufSize);
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -462,7 +481,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
|
||||
int len = taosUcs4ToMbs(varDataVal(input), varDataLen(input), tmp);
|
||||
if (len < 0){
|
||||
qError("castConvert taosUcs4ToMbs error 1");
|
||||
sclError("castConvert taosUcs4ToMbs error 1");
|
||||
tfree(tmp);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
@ -493,7 +512,7 @@ int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
qError("invalid convert output type:%d", outType);
|
||||
sclError("invalid convert output type:%d", outType);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
|
||||
|
@ -541,6 +560,10 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (SCL_DATA_TYPE_DUMMY_HASH == pLeft->type || SCL_DATA_TYPE_DUMMY_HASH == pRight->type) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SScalarParam *param1 = NULL, *paramOut1 = NULL;
|
||||
SScalarParam *param2 = NULL, *paramOut2 = NULL;
|
||||
int32_t code = 0;
|
||||
|
@ -604,6 +627,46 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or
|
|||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(double));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pLeft, &leftParam)) {
|
||||
return;
|
||||
}
|
||||
pLeft = &leftParam;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pRight->type)) {
|
||||
rightParam.data = calloc(rightParam.num, sizeof(double));
|
||||
if (NULL == rightParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -637,12 +700,55 @@ void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or
|
|||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) + getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(double));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pLeft, &leftParam)) {
|
||||
return;
|
||||
}
|
||||
pLeft = &leftParam;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pRight->type)) {
|
||||
rightParam.data = calloc(rightParam.num, sizeof(double));
|
||||
if (NULL == rightParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -675,11 +781,54 @@ void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _or
|
|||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(double));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pLeft, &leftParam)) {
|
||||
return;
|
||||
}
|
||||
pLeft = &leftParam;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pRight->type)) {
|
||||
rightParam.data = calloc(rightParam.num, sizeof(double));
|
||||
if (NULL == rightParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -713,12 +862,55 @@ void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_
|
|||
SET_DOUBLE_VAL(output,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(double));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pLeft, &leftParam)) {
|
||||
return;
|
||||
}
|
||||
pLeft = &leftParam;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pRight->type)) {
|
||||
rightParam.data = calloc(rightParam.num, sizeof(double));
|
||||
if (NULL == rightParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
double *output=(double*)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -759,12 +951,55 @@ void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
|
|||
SET_DOUBLE_VAL(output, getVectorDoubleValueFnLeft(pLeft->data, i) / right);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(double));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pLeft, &leftParam)) {
|
||||
return;
|
||||
}
|
||||
pLeft = &leftParam;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pRight->type)) {
|
||||
rightParam.data = calloc(rightParam.num, sizeof(double));
|
||||
if (NULL == rightParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
double * output = (double *)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -831,6 +1066,9 @@ void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32
|
|||
SET_DOUBLE_VAL(output, left - ((int64_t)(left / right)) * right);
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
|
@ -888,6 +1126,46 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
|
|||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(int64_t));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(int64_t)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
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(int64_t)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
int64_t *output=(int64_t *)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -921,12 +1199,55 @@ void vectorBitAnd(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
|
|||
SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data,i) & getVectorBigintValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
|
||||
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
|
||||
|
||||
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pLeft->num};
|
||||
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num};
|
||||
if (IS_VAR_DATA_TYPE(pLeft->type)) {
|
||||
leftParam.data = calloc(leftParam.num, sizeof(int64_t));
|
||||
if (NULL == leftParam.data) {
|
||||
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(int64_t)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pLeft->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pLeft->data;
|
||||
pLeft->data = colInfo->pData;
|
||||
}
|
||||
|
||||
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(int64_t)));
|
||||
tfree(leftParam.data);
|
||||
return;
|
||||
}
|
||||
|
||||
if (pRight->colData) {
|
||||
SColumnInfoData *colInfo = (SColumnInfoData *)pRight->data;
|
||||
pRight->data = colInfo->pData;
|
||||
}
|
||||
|
||||
if (vectorConvertImpl(pRight, &rightParam)) {
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
return;
|
||||
}
|
||||
pRight = &rightParam;
|
||||
}
|
||||
|
||||
int64_t *output=(int64_t *)out;
|
||||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
@ -960,6 +1281,9 @@ void vectorBitOr(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _
|
|||
SET_BIGINT_VAL(output,getVectorBigintValueFnLeft(pLeft->data,i) | getVectorBigintValueFnRight(pRight->data,0));
|
||||
}
|
||||
}
|
||||
|
||||
tfree(leftParam.data);
|
||||
tfree(rightParam.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -973,7 +1297,7 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, void *out, int
|
|||
_getValueAddr_fn_t getVectorValueAddrFnLeft = getVectorValueAddrFn(pLeft->type);
|
||||
_getValueAddr_fn_t getVectorValueAddrFnRight = getVectorValueAddrFn(pRight->type);
|
||||
|
||||
if (pLeft->num == pRight->num) {
|
||||
if (pLeft->num == pRight->num) {
|
||||
for (; i < pRight->num && i >= 0; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data, i), pLeft->type) ||
|
||||
isNull(getVectorValueAddrFnRight(pRight->data, i), pRight->type)) {
|
||||
|
@ -1001,7 +1325,7 @@ void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, void *out, int
|
|||
SET_TYPED_DATA(output, TSDB_DATA_TYPE_BOOL, res);
|
||||
}
|
||||
} else if (pRight->num == 1) {
|
||||
void *rightData = getVectorValueAddrFnRight(pRight->data, 0);
|
||||
void *rightData = getVectorValueAddrFnRight(pRight->data, 0);
|
||||
|
||||
for (; i >= 0 && i < pLeft->num; i += step, output += 1) {
|
||||
if (isNull(getVectorValueAddrFnLeft(pLeft->data,i), pLeft->type) || isNull(rightData, pRight->type)) {
|
||||
|
@ -1039,7 +1363,7 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t
|
|||
param2 = pRight;
|
||||
}
|
||||
|
||||
vectorCompareImpl(param1, param2, out, _ord, TSDB_RELATION_GREATER);
|
||||
vectorCompareImpl(param1, param2, out, _ord, optr);
|
||||
}
|
||||
|
||||
void vectorGreater(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t _ord) {
|
||||
|
|
|
@ -37,12 +37,28 @@
|
|||
#include "addr_any.h"
|
||||
#include "scalar.h"
|
||||
#include "nodes.h"
|
||||
#include "tlog.h"
|
||||
|
||||
namespace {
|
||||
|
||||
int64_t scltLeftV = 21, scltRightV = 10;
|
||||
double scltLeftVd = 21.0, scltRightVd = 10.0;
|
||||
|
||||
void scltInitLogFile() {
|
||||
const char *defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
|
||||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
|
||||
char temp[128] = {0};
|
||||
sprintf(temp, "%s/%s", tsLogDir, defaultLogFileNamePrefix);
|
||||
if (taosInitLog(temp, tsNumOfLogLines, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
|
||||
SNode *node = nodesMakeNode(QUERY_NODE_VALUE);
|
||||
SValueNode *vnode = (SValueNode *)node;
|
||||
|
@ -60,6 +76,64 @@ void scltMakeValueNode(SNode **pNode, int32_t dataType, void *value) {
|
|||
*pNode = (SNode *)vnode;
|
||||
}
|
||||
|
||||
void scltMakeColRefNode(SNode **pNode, SSDataBlock **block, int32_t dataType, int32_t dataBytes, int32_t rowNum, void *value) {
|
||||
SNode *node = nodesMakeNode(QUERY_NODE_COLUMN_REF);
|
||||
SColumnRefNode *rnode = (SColumnRefNode *)node;
|
||||
rnode->dataType.type = dataType;
|
||||
rnode->dataType.bytes = dataBytes;
|
||||
rnode->tupleId = 0;
|
||||
|
||||
if (NULL == *block) {
|
||||
SSDataBlock *res = (SSDataBlock *)calloc(1, sizeof(SSDataBlock));
|
||||
res->info.numOfCols = 3;
|
||||
res->info.rows = rowNum;
|
||||
res->pDataBlock = taosArrayInit(3, sizeof(SColumnInfoData));
|
||||
for (int32_t i = 0; i < 2; ++i) {
|
||||
SColumnInfoData idata = {{0}};
|
||||
idata.info.type = TSDB_DATA_TYPE_NULL;
|
||||
idata.info.bytes = 10;
|
||||
idata.info.colId = 0;
|
||||
|
||||
int32_t size = idata.info.bytes * rowNum;
|
||||
idata.pData = (char *)calloc(1, size);
|
||||
taosArrayPush(res->pDataBlock, &idata);
|
||||
}
|
||||
|
||||
SColumnInfoData idata = {{0}};
|
||||
idata.info.type = dataType;
|
||||
idata.info.bytes = dataBytes;
|
||||
idata.info.colId = 55;
|
||||
idata.pData = (char *)value;
|
||||
if (IS_VAR_DATA_TYPE(dataType)) {
|
||||
idata.varmeta.offset = (int32_t *)calloc(rowNum, sizeof(int32_t));
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
idata.varmeta.offset[i] = (dataBytes + VARSTR_HEADER_SIZE) * i;
|
||||
}
|
||||
}
|
||||
taosArrayPush(res->pDataBlock, &idata);
|
||||
|
||||
rnode->slotId = 2;
|
||||
rnode->columnId = 55;
|
||||
|
||||
*block = res;
|
||||
} else {
|
||||
SSDataBlock *res = *block;
|
||||
|
||||
int32_t idx = taosArrayGetSize(res->pDataBlock);
|
||||
SColumnInfoData idata = {{0}};
|
||||
idata.info.type = dataType;
|
||||
idata.info.bytes = dataBytes;
|
||||
idata.info.colId = 55 + idx;
|
||||
idata.pData = (char *)value;
|
||||
taosArrayPush(res->pDataBlock, &idata);
|
||||
|
||||
rnode->slotId = idx;
|
||||
rnode->columnId = 55 + idx;
|
||||
}
|
||||
|
||||
*pNode = (SNode *)rnode;
|
||||
}
|
||||
|
||||
void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode *pLeft, SNode *pRight) {
|
||||
SNode *node = nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
SOperatorNode *onode = (SOperatorNode *)node;
|
||||
|
@ -73,6 +147,7 @@ void scltMakeOpNode(SNode **pNode, EOperatorType opType, int32_t resType, SNode
|
|||
*pNode = (SNode *)onode;
|
||||
}
|
||||
|
||||
|
||||
void scltMakeListNode(SNode **pNode, SNodeList *list, int32_t resType) {
|
||||
SNode *node = nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
SNodeListNode *lnode = (SNodeListNode *)node;
|
||||
|
@ -145,6 +220,25 @@ TEST(constantTest, bigint_or_double) {
|
|||
ASSERT_EQ(v->datum.i, (int64_t)scltLeftV | (int64_t)scltRightVd);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_or_binary) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char binaryStr[64] = {0};
|
||||
sprintf(&binaryStr[2], "%d", scltRightV);
|
||||
varDataSetLen(binaryStr, strlen(&binaryStr[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, binaryStr);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(v->datum.b, scltLeftV | scltRightV);
|
||||
}
|
||||
|
||||
|
||||
TEST(constantTest, int_greater_double) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
|
||||
|
@ -209,7 +303,7 @@ TEST(constantTest, usmallint_lower_equal_ubigint) {
|
|||
ASSERT_EQ(v->datum.b, leftv <= rightv);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_equal_smallint) {
|
||||
TEST(constantTest, int_equal_smallint1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
|
@ -225,7 +319,59 @@ TEST(constantTest, int_equal_smallint) {
|
|||
ASSERT_EQ(v->datum.b, leftv == rightv);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_in_smallint) {
|
||||
TEST(constantTest, int_equal_smallint2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 0, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, leftv == rightv);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_not_equal_smallint1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, leftv != rightv);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_not_equal_smallint2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 0, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_EQUAL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, leftv != rightv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(constantTest, int_in_smallint1) {
|
||||
scltInitLogFile();
|
||||
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
|
||||
int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
|
@ -236,8 +382,8 @@ TEST(constantTest, int_in_smallint) {
|
|||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_SMALLINT);
|
||||
scltMakeOpNode(opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode)
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
@ -248,6 +394,586 @@ TEST(constantTest, int_in_smallint) {
|
|||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_in_smallint2) {
|
||||
scltInitLogFile();
|
||||
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
|
||||
int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
SNodeList* list = nodesMakeList();
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_not_in_smallint1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
|
||||
int32_t leftv = 1, rightv1 = 1,rightv2 = 2,rightv3 = 3;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
SNodeList* list = nodesMakeList();
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_not_in_smallint2) {
|
||||
scltInitLogFile();
|
||||
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *res = NULL, *opNode = NULL;
|
||||
int32_t leftv = 4, rightv1 = 1,rightv2 = 2,rightv3 = 3;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
SNodeList* list = nodesMakeList();
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv1);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv2);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_SMALLINT, &rightv3);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_like_binary1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "a_c");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_like_binary2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "ac");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_not_like_binary1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "a%c");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_not_like_binary2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "ac");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NOT_LIKE, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_match_binary1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", ".*");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_match_binary2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "abc.+");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_MATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_not_match_binary1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "a[1-9]c");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, binary_not_match_binary2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
char leftv[64] = {0}, rightv[64] = {0};
|
||||
sprintf(&leftv[2], "%s", "abc");
|
||||
varDataSetLen(leftv, strlen(&leftv[2]));
|
||||
sprintf(&rightv[2], "%s", "a[ab]c");
|
||||
varDataSetLen(rightv, strlen(&rightv[2]));
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_BINARY, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_NMATCH, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_is_null1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_is_null2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_is_not_null1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_is_not_null2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = TSDB_DATA_INT_NULL, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_NOT_NULL, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_add_int_is_true1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_add_int_is_true2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = -1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
|
||||
TEST(constantTest, int_greater_int_is_true1) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 1;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, false);
|
||||
}
|
||||
|
||||
TEST(constantTest, int_greater_int_is_true2) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
|
||||
int32_t leftv = 1, rightv = 0;
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_INT, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, opNode, NULL);
|
||||
|
||||
int32_t code = scalarCalculateConstants(opNode, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_TRUE(res);
|
||||
ASSERT_EQ(nodeType(res), QUERY_NODE_VALUE);
|
||||
SValueNode *v = (SValueNode *)res;
|
||||
ASSERT_EQ(v->node.resType.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(v->datum.b, true);
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_value_add_int_column) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int32_t leftv = 1;
|
||||
int16_t rightv[5]= {0, -5, -4, 23, 100};
|
||||
double eRes[5] = {1.0, -4, -3, 24, 101};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
|
||||
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &leftv);
|
||||
scltMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_ADD, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((double *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, bigint_column_multi_binary_column) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int64_t leftv[5]= {1, 2, 3, 4, 5};
|
||||
char rightv[5][5]= {0};
|
||||
for (int32_t i = 0; i < 5; ++i) {
|
||||
rightv[i][2] = rightv[i][3] = '0';
|
||||
rightv[i][4] = '0' + i;
|
||||
varDataSetLen(rightv[i], 3);
|
||||
}
|
||||
double eRes[5] = {0, 2, 6, 12, 20};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BIGINT, sizeof(int64_t), rowNum, leftv);
|
||||
scltMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_MULTI, TSDB_DATA_TYPE_DOUBLE, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_DOUBLE);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((double *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_column_and_binary_column) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int16_t leftv[5]= {1, 2, 3, 4, 5};
|
||||
char rightv[5][5]= {0};
|
||||
for (int32_t i = 0; i < 5; ++i) {
|
||||
rightv[i][2] = rightv[i][3] = '0';
|
||||
rightv[i][4] = '0' + i;
|
||||
varDataSetLen(rightv[i], 3);
|
||||
}
|
||||
int64_t eRes[5] = {0, 0, 2, 0, 4};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
|
||||
scltMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_BIT_AND, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_column_or_float_column) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int16_t leftv[5]= {1, 2, 3, 4, 5};
|
||||
float rightv[5]= {2.0, 3.0, 4.1, 5.2, 6.0};
|
||||
int64_t eRes[5] = {3, 3, 7, 5, 7};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(rightv)/sizeof(rightv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
|
||||
scltMakeColRefNode(&pRight, &src, TSDB_DATA_TYPE_FLOAT, sizeof(float), rowNum, rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_column_or_double_value) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int16_t leftv[5]= {1, 2, 3, 4, 5};
|
||||
double rightv= 10.2;
|
||||
int64_t eRes[5] = {11, 10, 11, 14, 15};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_BIT_OR, TSDB_DATA_TYPE_BIGINT, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BIGINT);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((int64_t *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, smallint_column_greater_double_value) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL;
|
||||
int16_t leftv[5]= {1, 2, 3, 4, 5};
|
||||
double rightv= 2.5;
|
||||
bool eRes[5] = {false, false, true, true, true};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_SMALLINT, sizeof(int16_t), rowNum, leftv);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_GREATER_THAN, TSDB_DATA_TYPE_BOOL, pLeft, pRight);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, int_column_in_double_list) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
|
||||
int32_t leftv[5] = {1, 2, 3, 4, 5};
|
||||
double rightv1 = 1.1,rightv2 = 2.2,rightv3 = 3.3;
|
||||
bool eRes[5] = {true, true, true, false, false};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_INT, sizeof(int32_t), rowNum, leftv);
|
||||
SNodeList* list = nodesMakeList();
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv1);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv2);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_DOUBLE, &rightv3);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_INT);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(columnTest, binary_column_in_binary_list) {
|
||||
SNode *pLeft = NULL, *pRight = NULL, *listNode = NULL, *opNode = NULL;
|
||||
bool eRes[5] = {true, true, false, false, false};
|
||||
SSDataBlock *src = NULL;
|
||||
SScalarParam res = {0};
|
||||
char leftv[5][5]= {0};
|
||||
char rightv[3][5]= {0};
|
||||
for (int32_t i = 0; i < 5; ++i) {
|
||||
leftv[i][2] = 'a' + i;
|
||||
leftv[i][3] = 'b' + i;
|
||||
leftv[i][4] = '0' + i;
|
||||
varDataSetLen(leftv[i], 3);
|
||||
}
|
||||
for (int32_t i = 0; i < 2; ++i) {
|
||||
rightv[i][2] = 'a' + i;
|
||||
rightv[i][3] = 'b' + i;
|
||||
rightv[i][4] = '0' + i;
|
||||
varDataSetLen(rightv[i], 3);
|
||||
}
|
||||
for (int32_t i = 2; i < 3; ++i) {
|
||||
rightv[i][2] = 'a' + i;
|
||||
rightv[i][3] = 'a' + i;
|
||||
rightv[i][4] = 'a' + i;
|
||||
varDataSetLen(rightv[i], 3);
|
||||
}
|
||||
|
||||
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
|
||||
scltMakeColRefNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv);
|
||||
SNodeList* list = nodesMakeList();
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[0]);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[1]);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeValueNode(&pRight, TSDB_DATA_TYPE_BINARY, rightv[2]);
|
||||
nodesListAppend(list, pRight);
|
||||
scltMakeListNode(&listNode,list, TSDB_DATA_TYPE_BINARY);
|
||||
scltMakeOpNode(&opNode, OP_TYPE_IN, TSDB_DATA_TYPE_BOOL, pLeft, listNode);
|
||||
|
||||
int32_t code = scalarCalculate(opNode, src, &res);
|
||||
ASSERT_EQ(code, 0);
|
||||
ASSERT_EQ(res.num, rowNum);
|
||||
ASSERT_EQ(res.type, TSDB_DATA_TYPE_BOOL);
|
||||
ASSERT_EQ(res.bytes, tDataTypes[TSDB_DATA_TYPE_BOOL].bytes);
|
||||
for (int32_t i = 0; i < rowNum; ++i) {
|
||||
ASSERT_EQ(*((bool *)res.data + i), eRes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue