提交 7f755f60 编写于 作者: S Shengliang Guan

Merge remote-tracking branch 'origin/3.0' into feature/shm

...@@ -54,16 +54,13 @@ typedef struct SColumnDataAgg { ...@@ -54,16 +54,13 @@ typedef struct SColumnDataAgg {
} SColumnDataAgg; } SColumnDataAgg;
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
int32_t rows; int32_t rows;
int32_t rowSize; int32_t rowSize;
int16_t numOfCols; int16_t numOfCols;
int16_t hasVarCol; int16_t hasVarCol;
union { union {int64_t uid; int64_t blockId;};
int64_t uid; int64_t groupId; // no need to serialize
int64_t blockId;
};
int64_t groupId; // no need to serialize
} SDataBlockInfo; } SDataBlockInfo;
typedef struct SSDataBlock { typedef struct SSDataBlock {
...@@ -96,6 +93,7 @@ void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock); ...@@ -96,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,
...@@ -103,13 +101,7 @@ static FORCE_INLINE void blockDestroyInner(SSDataBlock* pBlock) { ...@@ -103,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);
taosMemoryFreeClear(pColInfoData->varmeta.offset);
} else {
taosMemoryFreeClear(pColInfoData->nullbitmap);
}
taosMemoryFreeClear(pColInfoData->pData);
} }
taosArrayDestroy(pBlock->pDataBlock); taosArrayDestroy(pBlock->pDataBlock);
......
...@@ -101,6 +101,54 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u ...@@ -101,6 +101,54 @@ static FORCE_INLINE bool colDataIsNull(const SColumnInfoData* pColumnInfoData, u
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \ ((IS_VAR_DATA_TYPE((p1_)->info.type)) ? ((p1_)->pData + (p1_)->varmeta.offset[(r_)]) \
: ((p1_)->pData + ((r_) * (p1_)->info.bytes))) : ((p1_)->pData + ((r_) * (p1_)->info.bytes)))
static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uint32_t currentRow) {
// There is a placehold for each NULL value of binary or nchar type.
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
pColumnInfoData->varmeta.offset[currentRow] = -1; // it is a null value of VAR type.
} else {
colDataSetNull_f(pColumnInfoData->nullbitmap, currentRow);
}
pColumnInfoData->hasNull = true;
}
static FORCE_INLINE int32_t colDataAppendInt8(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int8_t* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_TINYINT ||
pColumnInfoData->info.type == TSDB_DATA_TYPE_UTINYINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_BOOL);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(int8_t*)p = *(int8_t*)v;
}
static FORCE_INLINE int32_t colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(int16_t*)p = *(int16_t*)v;
}
static FORCE_INLINE int32_t colDataAppendInt32(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int32_t* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_INT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UINT);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(int32_t*)p = *(int32_t*)v;
}
static FORCE_INLINE int32_t colDataAppendInt64(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int64_t* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_BIGINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_UBIGINT);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(int64_t*)p = *(int64_t*)v;
}
static FORCE_INLINE int32_t colDataAppendFloat(SColumnInfoData* pColumnInfoData, uint32_t currentRow, float* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_FLOAT);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(float*)p = *(float*)v;
}
static FORCE_INLINE int32_t colDataAppendDouble(SColumnInfoData* pColumnInfoData, uint32_t currentRow, double* v) {
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_DOUBLE);
char* p = pColumnInfoData->pData + pColumnInfoData->info.bytes * currentRow;
*(double*)p = *(double*)v;
}
int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull); int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, const char* pData, bool isNull);
int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource, int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, const SColumnInfoData* pSource,
uint32_t numOfRow2); uint32_t numOfRow2);
......
...@@ -192,7 +192,6 @@ enum { ...@@ -192,7 +192,6 @@ enum {
TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp) TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp)
TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqCVConsumeReq, SMqCVConsumeRsp) TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqCVConsumeReq, SMqCVConsumeRsp)
TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_DEPLOY, "vnode-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp)
TD_DEF_MSG_TYPE(TDMT_VND_TASK_EXEC, "vnode-task-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
TD_DEF_MSG_TYPE(TDMT_VND_TASK_PIPE_EXEC, "vnode-task-pipe-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_PIPE_EXEC, "vnode-task-pipe-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
TD_DEF_MSG_TYPE(TDMT_VND_TASK_MERGE_EXEC, "vnode-task-merge-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_MERGE_EXEC, "vnode-task-merge-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
TD_DEF_MSG_TYPE(TDMT_VND_TASK_WRITE_EXEC, "vnode-task-write-exec", SStreamTaskExecReq, SStreamTaskExecRsp) TD_DEF_MSG_TYPE(TDMT_VND_TASK_WRITE_EXEC, "vnode-task-write-exec", SStreamTaskExecReq, SStreamTaskExecRsp)
......
...@@ -27,16 +27,22 @@ extern "C" { ...@@ -27,16 +27,22 @@ extern "C" {
struct SqlFunctionCtx; struct SqlFunctionCtx;
struct SResultRowEntryInfo; struct SResultRowEntryInfo;
typedef struct SFunctionNode SFunctionNode; struct SFunctionNode;
typedef struct SScalarParam SScalarParam;
typedef struct SFuncExecEnv { typedef struct SFuncExecEnv {
int32_t calcMemSize; int32_t calcMemSize;
} SFuncExecEnv; } SFuncExecEnv;
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv); typedef bool (*FExecGetEnv)(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx); typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx);
typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx); typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
typedef struct SScalarFuncExecFuncs {
FScalarExecProcess process;
} SScalarFuncExecFuncs;
typedef struct SFuncExecFuncs { typedef struct SFuncExecFuncs {
FExecGetEnv getEnv; FExecGetEnv getEnv;
...@@ -191,6 +197,7 @@ typedef struct SqlFunctionCtx { ...@@ -191,6 +197,7 @@ typedef struct SqlFunctionCtx {
SPoint1 start; SPoint1 start;
SPoint1 end; SPoint1 end;
SFuncExecFuncs fpSet; SFuncExecFuncs fpSet;
SScalarFuncExecFuncs sfp;
} SqlFunctionCtx; } SqlFunctionCtx;
enum { enum {
...@@ -203,7 +210,7 @@ enum { ...@@ -203,7 +210,7 @@ enum {
}; };
typedef struct tExprNode { typedef struct tExprNode {
uint8_t nodeType; int32_t nodeType;
union { union {
struct { struct {
int32_t optr; // binary operator int32_t optr; // binary operator
...@@ -219,7 +226,7 @@ typedef struct tExprNode { ...@@ -219,7 +226,7 @@ typedef struct tExprNode {
char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor
int32_t functionId; int32_t functionId;
int32_t num; int32_t num;
SFunctionNode *pFunctNode; struct SFunctionNode *pFunctNode;
// Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the // Note that the attribute of pChild is not the parameter of function, it is the columns that involved in the
// calculation instead. // calculation instead.
// E.g., Cov(col1, col2), the column information, w.r.t. the col1 and col2, is kept in pChild nodes. // E.g., Cov(col1, col2), the column information, w.r.t. the col1 and col2, is kept in pChild nodes.
...@@ -227,6 +234,10 @@ typedef struct tExprNode { ...@@ -227,6 +234,10 @@ typedef struct tExprNode {
// operator and is kept in the attribute of _node. // operator and is kept in the attribute of _node.
struct tExprNode **pChild; struct tExprNode **pChild;
} _function; } _function;
struct {
struct SNode* pRootNode;
} _optrRoot;
}; };
} tExprNode; } tExprNode;
...@@ -250,25 +261,11 @@ typedef struct SAggFunctionInfo { ...@@ -250,25 +261,11 @@ typedef struct SAggFunctionInfo {
int32_t (*dataReqFunc)(SqlFunctionCtx *pCtx, STimeWindow* w, int32_t colId); int32_t (*dataReqFunc)(SqlFunctionCtx *pCtx, STimeWindow* w, int32_t colId);
} SAggFunctionInfo; } SAggFunctionInfo;
typedef struct SScalarParam { 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;
typedef struct SScalarFunctionInfo {
char name[FUNCTIONS_NAME_MAX_LENGTH];
int8_t type; // scalar function or aggregation function
uint32_t functionId; // index of scalar function
void (*process)(struct SScalarParam* pOutput, size_t numOfInput, const struct SScalarParam *pInput);
} SScalarFunctionInfo;
typedef struct SMultiFunctionsDesc { typedef struct SMultiFunctionsDesc {
bool stableQuery; bool stableQuery;
......
...@@ -103,13 +103,6 @@ struct SqlFunctionCtx; ...@@ -103,13 +103,6 @@ struct SqlFunctionCtx;
struct SResultRowEntryInfo; struct SResultRowEntryInfo;
struct STimeWindow; struct STimeWindow;
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
typedef struct SScalarFuncExecFuncs {
FScalarExecProcess process;
} SScalarFuncExecFuncs;
int32_t fmFuncMgtInit(); int32_t fmFuncMgtInit();
void fmFuncMgtDestroy(); void fmFuncMgtDestroy();
......
...@@ -40,7 +40,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type); ...@@ -40,7 +40,7 @@ int32_t scalarGetOperatorParamNum(EOperatorType type);
int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type); int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type);
int32_t vectorGetConvertType(int32_t type1, int32_t type2); int32_t vectorGetConvertType(int32_t type1, int32_t type2);
int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut); int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut);
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
......
...@@ -82,8 +82,12 @@ typedef struct { ...@@ -82,8 +82,12 @@ typedef struct {
SHashObj* pHash; // groupId to tbuid SHashObj* pHash; // groupId to tbuid
} STaskSinkTb; } STaskSinkTb;
typedef void FSmaHandle(void* vnode, int64_t smaId, const SArray* data);
typedef struct { typedef struct {
int8_t reserved; int64_t smaId;
// following are not applicable to encoder and decoder
FSmaHandle* smaHandle;
} STaskSinkSma; } STaskSinkSma;
typedef struct { typedef struct {
...@@ -156,7 +160,8 @@ typedef struct { ...@@ -156,7 +160,8 @@ typedef struct {
STaskDispatcherShuffle shuffleDispatcher; STaskDispatcherShuffle shuffleDispatcher;
}; };
// state storage // application storage
void* ahandle;
} SStreamTask; } SStreamTask;
......
...@@ -235,7 +235,7 @@ void initMsgHandleFp(); ...@@ -235,7 +235,7 @@ void initMsgHandleFp();
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db, TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
uint16_t port); uint16_t port);
void* doFetchRow(SRequestObj* pRequest); void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr);
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows); int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
......
...@@ -545,7 +545,33 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c ...@@ -545,7 +545,33 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c
return taos_connect(ipStr, userStr, passStr, dbStr, port); return taos_connect(ipStr, userStr, passStr, dbStr, port);
} }
void* doFetchRow(SRequestObj* pRequest) { static void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) {
SResultColumn* pCol = &pResultInfo->pCol[i];
int32_t type = pResultInfo->fields[i].type;
int32_t bytes = pResultInfo->fields[i].bytes;
if (IS_VAR_DATA_TYPE(type)) {
if (pCol->offset[pResultInfo->current] != -1) {
char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData;
pResultInfo->length[i] = varDataLen(pStart);
pResultInfo->row[i] = varDataVal(pStart);
} else {
pResultInfo->row[i] = NULL;
}
} else {
if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) {
pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current;
} else {
pResultInfo->row[i] = NULL;
}
}
}
}
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) {
assert(pRequest != NULL); assert(pRequest != NULL);
SReqResultInfo* pResultInfo = &pRequest->body.resInfo; SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
...@@ -555,17 +581,20 @@ void* doFetchRow(SRequestObj* pRequest) { ...@@ -555,17 +581,20 @@ void* doFetchRow(SRequestObj* pRequest) {
if (pRequest->type == TDMT_VND_QUERY) { if (pRequest->type == TDMT_VND_QUERY) {
// All data has returned to App already, no need to try again // All data has returned to App already, no need to try again
if (pResultInfo->completed) { if (pResultInfo->completed) {
pResultInfo->numOfRows = 0;
return NULL; return NULL;
} }
SReqResultInfo* pResInfo = &pRequest->body.resInfo; SReqResultInfo* pResInfo = &pRequest->body.resInfo;
pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData); pRequest->code = schedulerFetchRows(pRequest->body.queryJob, (void**)&pResInfo->pData);
if (pRequest->code != TSDB_CODE_SUCCESS) { if (pRequest->code != TSDB_CODE_SUCCESS) {
pResultInfo->numOfRows = 0;
return NULL; return NULL;
} }
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData); pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData);
if (pRequest->code != TSDB_CODE_SUCCESS) { if (pRequest->code != TSDB_CODE_SUCCESS) {
pResultInfo->numOfRows = 0;
return NULL; return NULL;
} }
...@@ -633,41 +662,11 @@ void* doFetchRow(SRequestObj* pRequest) { ...@@ -633,41 +662,11 @@ void* doFetchRow(SRequestObj* pRequest) {
} }
_return: _return:
if (setupOneRowPtr) {
for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) { doSetOneRowPtr(pResultInfo);
SResultColumn* pCol = &pResultInfo->pCol[i]; pResultInfo->current += 1;
int32_t type = pResultInfo->fields[i].type;
int32_t bytes = pResultInfo->fields[i].bytes;
if (IS_VAR_DATA_TYPE(type)) {
if (pCol->offset[pResultInfo->current] != -1) {
char* pStart = pResultInfo->pCol[i].offset[pResultInfo->current] + pResultInfo->pCol[i].pData;
pResultInfo->length[i] = varDataLen(pStart);
pResultInfo->row[i] = varDataVal(pStart);
if (type == TSDB_DATA_TYPE_NCHAR) {
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(pResultInfo->convertBuf[i]));
ASSERT(len <= bytes);
pResultInfo->row[i] = varDataVal(pResultInfo->convertBuf[i]);
varDataSetLen(pResultInfo->convertBuf[i], len);
pResultInfo->length[i] = len;
}
} else {
pResultInfo->row[i] = NULL;
}
} else {
if (!colDataIsNull_f(pCol->nullbitmap, pResultInfo->current)) {
pResultInfo->row[i] = pResultInfo->pCol[i].pData + bytes * pResultInfo->current;
} else {
pResultInfo->row[i] = NULL;
}
}
} }
pResultInfo->current += 1;
return pResultInfo->row; return pResultInfo->row;
} }
...@@ -681,12 +680,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) { ...@@ -681,12 +680,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) { if (pResInfo->row == NULL || pResInfo->pCol == NULL || pResInfo->length == NULL || pResInfo->convertBuf == NULL) {
return TSDB_CODE_OUT_OF_MEMORY; return TSDB_CODE_OUT_OF_MEMORY;
} }
for(int32_t i = 0; i < pResInfo->numOfCols; ++i) {
if(pResInfo->fields[i].type == TSDB_DATA_TYPE_NCHAR) {
pResInfo->convertBuf[i] = taosMemoryCalloc(1, NCHAR_WIDTH_TO_BYTES(pResInfo->fields[i].bytes));
}
}
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -723,6 +716,35 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32 ...@@ -723,6 +716,35 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
pStart += colLength[i]; pStart += colLength[i];
} }
for (int32_t i = 0; i < numOfCols; ++i) {
int32_t type = pResultInfo->fields[i].type;
int32_t bytes = pResultInfo->fields[i].bytes;
if (type == TSDB_DATA_TYPE_NCHAR) {
char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]);
if (p == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pResultInfo->convertBuf[i] = p;
SResultColumn* pCol = &pResultInfo->pCol[i];
for (int32_t j = 0; j < numOfRows; ++j) {
if (pCol->offset[j] != -1) {
pStart = pCol->offset[j] + pCol->pData;
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p));
ASSERT(len <= bytes);
varDataSetLen(p, len);
pCol->offset[j] = (p - pResultInfo->convertBuf[i]);
p += (len + VARSTR_HEADER_SIZE);
}
}
pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i];
}
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
...@@ -138,20 +138,20 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) { ...@@ -138,20 +138,20 @@ TAOS_RES *taos_query(TAOS *taos, const char *sql) {
return taos_query_l(taos, sql, (int32_t) strlen(sql)); return taos_query_l(taos, sql, (int32_t) strlen(sql));
} }
TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { TAOS_ROW taos_fetch_row(TAOS_RES *res) {
if (pRes == NULL) { if (res == NULL) {
return NULL; return NULL;
} }
SRequestObj *pRequest = (SRequestObj *) pRes; SRequestObj *pRequest = (SRequestObj *) res;
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT || if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
pRequest->type == TSDB_SQL_INSERT || pRequest->type == TSDB_SQL_INSERT ||
pRequest->code != TSDB_CODE_SUCCESS || pRequest->code != TSDB_CODE_SUCCESS ||
taos_num_fields(pRes) == 0) { taos_num_fields(res) == 0) {
return NULL; return NULL;
} }
return doFetchRow(pRequest); return doFetchRow(pRequest, true);
} }
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) { int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
...@@ -246,6 +246,7 @@ int* taos_fetch_lengths(TAOS_RES *res) { ...@@ -246,6 +246,7 @@ int* taos_fetch_lengths(TAOS_RES *res) {
return ((SRequestObj*) res)->body.resInfo.length; return ((SRequestObj*) res)->body.resInfo.length;
} }
// todo intergrate with tDataTypes
const char *taos_data_type(int type) { const char *taos_data_type(int type) {
switch (type) { switch (type) {
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL"; case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
...@@ -256,9 +257,11 @@ const char *taos_data_type(int type) { ...@@ -256,9 +257,11 @@ const char *taos_data_type(int type) {
case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT"; case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT";
case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT"; case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT";
case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE"; case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE";
case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_BINARY"; case TSDB_DATA_TYPE_VARCHAR: return "TSDB_DATA_TYPE_VARCHAR";
// case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_VARCHAR";
case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP"; case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP";
case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR"; case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR";
case TSDB_DATA_TYPE_JSON: return "TSDB_DATA_TYPE_JSON";
default: return "UNKNOWN"; default: return "UNKNOWN";
} }
} }
...@@ -316,11 +319,37 @@ void taos_stop_query(TAOS_RES *res) { ...@@ -316,11 +319,37 @@ void taos_stop_query(TAOS_RES *res) {
} }
bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) { bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
return false; SRequestObj* pRequestObj = res;
SReqResultInfo* pResultInfo = &pRequestObj->body.resInfo;
if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) {
return true;
}
SResultColumn* pCol = &pRequestObj->body.resInfo.pCol[col];
return colDataIsNull_f(pCol->nullbitmap, row);
} }
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
return 0; if (res == NULL) {
return 0;
}
SRequestObj *pRequest = (SRequestObj *) res;
if (pRequest->type == TSDB_SQL_RETRIEVE_EMPTY_RESULT ||
pRequest->type == TSDB_SQL_INSERT ||
pRequest->code != TSDB_CODE_SUCCESS ||
taos_num_fields(res) == 0) {
return 0;
}
doFetchRow(pRequest, false);
// TODO refactor
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
pResultInfo->current = pResultInfo->numOfRows;
*rows = pResultInfo->row;
return pResultInfo->numOfRows;
} }
int taos_validate_sql(TAOS *taos, const char *sql) { int taos_validate_sql(TAOS *taos, const char *sql) {
......
...@@ -877,7 +877,7 @@ WRITE_QUEUE_FAIL: ...@@ -877,7 +877,7 @@ WRITE_QUEUE_FAIL:
} }
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) { bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
printf("call update ep %d\n", epoch); /*printf("call update ep %d\n", epoch);*/
bool set = false; bool set = false;
int32_t sz = taosArrayGetSize(pRsp->topics); int32_t sz = taosArrayGetSize(pRsp->topics);
SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic)); SArray* newTopics = taosArrayInit(sz, sizeof(SMqClientTopic));
......
...@@ -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)) {
taosMemoryFree(pColData->varmeta.offset);
} else {
taosMemoryFree(pColData->nullbitmap);
}
taosMemoryFree(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;
......
...@@ -279,7 +279,6 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) { ...@@ -279,7 +279,6 @@ void vmInitMsgHandles(SMgmtWrapper *pWrapper) {
dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_CONSUME, vmProcessFetchMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_DEPLOY, vmProcessWriteMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_QUERY_HEARTBEAT, vmProcessFetchMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_EXEC, vmProcessFetchMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_PIPE_EXEC, vmProcessFetchMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_TASK_MERGE_EXEC, vmProcessMergeMsg, VND_VGID);
dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, VND_VGID); dndSetMsgHandle(pWrapper, TDMT_VND_STREAM_TRIGGER, vmProcessFetchMsg, VND_VGID);
......
...@@ -27,7 +27,7 @@ void mndCleanupScheduler(SMnode* pMnode); ...@@ -27,7 +27,7 @@ void mndCleanupScheduler(SMnode* pMnode);
int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub); int32_t mndSchedInitSubEp(SMnode* pMnode, const SMqTopicObj* pTopic, SMqSubscribeObj* pSub);
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream); int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream); ...@@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream);
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream);
SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw); SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw);
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans); int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -36,11 +36,11 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) { ...@@ -36,11 +36,11 @@ int32_t tEncodeSStreamObj(SCoder *pEncoder, const SStreamObj *pObj) {
if (tEncodeI32(pEncoder, sz) < 0) return -1; if (tEncodeI32(pEncoder, sz) < 0) return -1;
for (int32_t i = 0; i < sz; i++) { for (int32_t i = 0; i < sz; i++) {
SArray *pArray = taosArrayGet(pObj->tasks, i); SArray *pArray = taosArrayGetP(pObj->tasks, i);
int32_t innerSz = taosArrayGetSize(pArray); int32_t innerSz = taosArrayGetSize(pArray);
if (tEncodeI32(pEncoder, innerSz) < 0) return -1; if (tEncodeI32(pEncoder, innerSz) < 0) return -1;
for (int32_t j = 0; j < innerSz; j++) { for (int32_t j = 0; j < innerSz; j++) {
SStreamTask *pTask = taosArrayGet(pArray, j); SStreamTask *pTask = taosArrayGetP(pArray, j);
if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1; if (tEncodeSStreamTask(pEncoder, pTask) < 0) return -1;
} }
} }
...@@ -76,17 +76,18 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) { ...@@ -76,17 +76,18 @@ int32_t tDecodeSStreamObj(SCoder *pDecoder, SStreamObj *pObj) {
int32_t sz; int32_t sz;
if (tDecodeI32(pDecoder, &sz) < 0) return -1; if (tDecodeI32(pDecoder, &sz) < 0) return -1;
if (sz != 0) { if (sz != 0) {
pObj->tasks = taosArrayInit(sz, sizeof(SArray)); pObj->tasks = taosArrayInit(sz, sizeof(void *));
for (int32_t i = 0; i < sz; i++) { for (int32_t i = 0; i < sz; i++) {
int32_t innerSz; int32_t innerSz;
if (tDecodeI32(pDecoder, &innerSz) < 0) return -1; if (tDecodeI32(pDecoder, &innerSz) < 0) return -1;
SArray *pArray = taosArrayInit(innerSz, sizeof(SStreamTask)); SArray *pArray = taosArrayInit(innerSz, sizeof(void *));
for (int32_t j = 0; j < innerSz; j++) { for (int32_t j = 0; j < innerSz; j++) {
SStreamTask task; SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask));
if (tDecodeSStreamTask(pDecoder, &task) < 0) return -1; if (pTask == NULL) return -1;
taosArrayPush(pArray, &task); if (tDecodeSStreamTask(pDecoder, pTask) < 0) return -1;
taosArrayPush(pArray, &pTask);
} }
taosArrayPush(pObj->tasks, pArray); taosArrayPush(pObj->tasks, &pArray);
} }
} }
......
...@@ -119,7 +119,7 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) { ...@@ -119,7 +119,7 @@ SVgObj* mndSchedFetchOneVg(SMnode* pMnode, int64_t dbUid) {
return pVgroup; return pVgroup;
} }
int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream, int64_t smaId) {
SSdb* pSdb = pMnode->pSdb; SSdb* pSdb = pMnode->pSdb;
SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan); SQueryPlan* pPlan = qStringToQueryPlan(pStream->physicalPlan);
if (pPlan == NULL) { if (pPlan == NULL) {
...@@ -164,6 +164,10 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) { ...@@ -164,6 +164,10 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
// only for inplace // only for inplace
pTask->sinkType = TASK_SINK__SHOW; pTask->sinkType = TASK_SINK__SHOW;
pTask->showSink.reserved = 0; pTask->showSink.reserved = 0;
if (smaId != -1) {
pTask->sinkType = TASK_SINK__SMA;
pTask->smaSink.smaId = smaId;
}
} else { } else {
pTask->sinkType = TASK_SINK__NONE; pTask->sinkType = TASK_SINK__NONE;
} }
......
...@@ -69,7 +69,8 @@ void mndCleanupSma(SMnode *pMnode) {} ...@@ -69,7 +69,8 @@ void mndCleanupSma(SMnode *pMnode) {}
static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) { static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size = sizeof(SSmaObj) + pSma->exprLen + pSma->tagsFilterLen + pSma->sqlLen + pSma->astLen + TSDB_SMA_RESERVE_SIZE; int32_t size =
sizeof(SSmaObj) + pSma->exprLen + pSma->tagsFilterLen + pSma->sqlLen + pSma->astLen + TSDB_SMA_RESERVE_SIZE;
SSdbRaw *pRaw = sdbAllocRaw(SDB_SMA, TSDB_SMA_VER_NUMBER, size); SSdbRaw *pRaw = sdbAllocRaw(SDB_SMA, TSDB_SMA_VER_NUMBER, size);
if (pRaw == NULL) goto _OVER; if (pRaw == NULL) goto _OVER;
...@@ -427,7 +428,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre ...@@ -427,7 +428,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER; if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER;
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER; if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, smaObj.uid) != 0) goto _OVER;
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
code = 0; code = 0;
...@@ -491,7 +492,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) { ...@@ -491,7 +492,7 @@ static int32_t mndProcessMCreateSmaReq(SNodeMsg *pReq) {
mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb); mError("sma:%s, failed to create since stb:%s not exist", createReq.name, createReq.stb);
goto _OVER; goto _OVER;
} }
pStream = mndAcquireStream(pMnode, createReq.name); pStream = mndAcquireStream(pMnode, createReq.name);
if (pStream != NULL) { if (pStream != NULL) {
mError("sma:%s, failed to create since stream:%s already exist", createReq.name, createReq.name); mError("sma:%s, failed to create since stream:%s already exist", createReq.name, createReq.name);
......
...@@ -246,7 +246,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) { ...@@ -246,7 +246,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
return code; return code;
} }
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) { int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans, int64_t smaId) {
SNode *pAst = NULL; SNode *pAst = NULL;
if (nodesStringToNode(ast, &pAst) < 0) { if (nodesStringToNode(ast, &pAst) < 0) {
...@@ -271,7 +271,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast ...@@ -271,7 +271,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
return -1; return -1;
} }
if (mndScheduleStream(pMnode, pTrans, pStream) < 0) { if (mndScheduleStream(pMnode, pTrans, pStream, smaId) < 0) {
mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr()); mError("stream:%ld, schedule stream since %s", pStream->uid, terrstr());
return -1; return -1;
} }
...@@ -310,7 +310,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe ...@@ -310,7 +310,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
} }
mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name); mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name);
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) { if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans, -1) != 0) {
mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr()); mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr());
mndTransDrop(pTrans); mndTransDrop(pTrans);
return -1; return -1;
......
...@@ -19,15 +19,14 @@ ...@@ -19,15 +19,14 @@
#include "tmallocator.h" #include "tmallocator.h"
// #include "sync.h" // #include "sync.h"
#include "tcoding.h" #include "tcoding.h"
#include "tdatablock.h"
#include "tfs.h" #include "tfs.h"
#include "tlist.h" #include "tlist.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "tmacro.h" #include "tmacro.h"
#include "wal.h"
#include "vnode.h" #include "vnode.h"
#include "vnodeQuery.h" #include "vnodeQuery.h"
#include "wal.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -198,10 +197,13 @@ int tqCommit(STQ*); ...@@ -198,10 +197,13 @@ int tqCommit(STQ*);
int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg);
int32_t tqProcessSetConnReq(STQ* pTq, char* msg); int32_t tqProcessSetConnReq(STQ* pTq, char* msg);
int32_t tqProcessRebReq(STQ* pTq, char* msg); int32_t tqProcessRebReq(STQ* pTq, char* msg);
int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg); int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen);
int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen); int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen);
int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen); int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen);
// sma
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -473,10 +473,17 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) { ...@@ -473,10 +473,17 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
} }
tCoderClear(&decoder); tCoderClear(&decoder);
// exec
if (tqExpandTask(pTq, pTask, 4) < 0) { if (tqExpandTask(pTq, pTask, 4) < 0) {
ASSERT(0); ASSERT(0);
} }
// sink
pTask->ahandle = pTq->pVnode;
if (pTask->sinkType == TASK_SINK__SMA) {
pTask->smaSink.smaHandle = smaHandleRes;
}
taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask)); taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));
return 0; return 0;
...@@ -497,11 +504,9 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) { ...@@ -497,11 +504,9 @@ int32_t tqProcessStreamTrigger(STQ* pTq, void* data, int32_t dataLen) {
return 0; return 0;
} }
int32_t tqProcessTaskExec(STQ* pTq, SRpcMsg* msg) { int32_t tqProcessTaskExec(STQ* pTq, char* msg, int32_t msgLen) {
char* msgstr = POINTER_SHIFT(msg->pCont, sizeof(SMsgHead));
SStreamTaskExecReq req; SStreamTaskExecReq req;
tDecodeSStreamTaskExecReq(msgstr, &req); tDecodeSStreamTaskExecReq(msg, &req);
int32_t taskId = req.taskId; int32_t taskId = req.taskId;
SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t)); SStreamTask* pTask = taosHashGet(pTq->pStreamTasks, &taskId, sizeof(int32_t));
......
...@@ -43,6 +43,8 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -43,6 +43,8 @@ int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
vTrace("message in fetch queue is processing"); vTrace("message in fetch queue is processing");
char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
int32_t msgLen = pMsg->contLen - sizeof(SMsgHead);
switch (pMsg->msgType) { switch (pMsg->msgType) {
case TDMT_VND_FETCH: case TDMT_VND_FETCH:
return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg); return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg);
...@@ -65,10 +67,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) { ...@@ -65,10 +67,9 @@ int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg) {
return vnodeGetTableMeta(pVnode, pMsg); return vnodeGetTableMeta(pVnode, pMsg);
case TDMT_VND_CONSUME: case TDMT_VND_CONSUME:
return tqProcessPollReq(pVnode->pTq, pMsg); return tqProcessPollReq(pVnode->pTq, pMsg);
case TDMT_VND_TASK_EXEC:
case TDMT_VND_TASK_PIPE_EXEC: case TDMT_VND_TASK_PIPE_EXEC:
case TDMT_VND_TASK_MERGE_EXEC: case TDMT_VND_TASK_MERGE_EXEC:
return tqProcessTaskExec(pVnode->pTq, pMsg); return tqProcessTaskExec(pVnode->pTq, msgstr, msgLen);
case TDMT_VND_STREAM_TRIGGER: case TDMT_VND_STREAM_TRIGGER:
return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen); return tqProcessStreamTrigger(pVnode->pTq, pMsg->pCont, pMsg->contLen);
case TDMT_VND_QUERY_HEARTBEAT: case TDMT_VND_QUERY_HEARTBEAT:
......
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
#include "vnd.h" #include "vnd.h"
void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) {
// TODO
blockDebugShowData(data);
}
void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { void vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
SNodeMsg *pMsg; SNodeMsg *pMsg;
SRpcMsg *pRpc; SRpcMsg *pRpc;
...@@ -178,6 +183,11 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { ...@@ -178,6 +183,11 @@ int vnodeApplyWMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
pMsg->contLen - sizeof(SMsgHead)) < 0) { pMsg->contLen - sizeof(SMsgHead)) < 0) {
} }
} break; } break;
case TDMT_VND_TASK_WRITE_EXEC: {
if (tqProcessTaskExec(pVnode->pTq, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)),
pMsg->contLen - sizeof(SMsgHead)) < 0) {
}
} break;
case TDMT_VND_CREATE_SMA: { // timeRangeSMA case TDMT_VND_CREATE_SMA: { // timeRangeSMA
#if 0 #if 0
SSmaCfg vCreateSmaReq = {0}; SSmaCfg vCreateSmaReq = {0};
......
add_subdirectory(transport) add_subdirectory(transport)
add_subdirectory(sync) add_subdirectory(sync)
# add_subdirectory(tdb) add_subdirectory(tdb)
add_subdirectory(index) add_subdirectory(index)
add_subdirectory(wal) add_subdirectory(wal)
add_subdirectory(parser) add_subdirectory(parser)
......
...@@ -469,7 +469,7 @@ typedef struct SOptrBasicInfo { ...@@ -469,7 +469,7 @@ typedef struct SOptrBasicInfo {
int32_t* rowCellInfoOffset; // offset value for each row result cell info int32_t* rowCellInfoOffset; // offset value for each row result cell info
SqlFunctionCtx* pCtx; SqlFunctionCtx* pCtx;
SSDataBlock* pRes; SSDataBlock* pRes;
int32_t capacity; int32_t capacity; // TODO remove it
} SOptrBasicInfo; } SOptrBasicInfo;
//TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset //TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
......
...@@ -1246,17 +1246,40 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction ...@@ -1246,17 +1246,40 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction
} }
} }
static void projectApplyFunctions(SSDataBlock* pResult, SqlFunctionCtx *pCtx, int32_t numOfOutput) { static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx *pCtx, int32_t numOfOutput) {
for (int32_t k = 0; k < numOfOutput; ++k) { for (int32_t k = 0; k < numOfOutput; ++k) {
if (pCtx[k].fpSet.init == NULL) { // it is a project query if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k); SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k);
colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows); colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows);
} else { // TODO: arithmetic and other process.
pResult->info.rows = pCtx[0].input.numOfRows;
} else if (pExpr[k].pExpr->nodeType == QUERY_NODE_OPERATOR) {
SArray* pBlockList = taosArrayInit(4, POINTER_BYTES);
taosArrayPush(pBlockList, &pSrcBlock);
SScalarParam dest = {0};
dest.columnData = taosArrayGet(pResult->pDataBlock, k);
scalarCalculate(pExpr[k].pExpr->_optrRoot.pRootNode, pBlockList, &dest);
pResult->info.rows = dest.numOfRows;
taosArrayDestroy(pBlockList);
} else if (pExpr[k].pExpr->nodeType == QUERY_NODE_FUNCTION) {
ASSERT(!fmIsAggFunc(pCtx->functionId));
SScalarParam p = {.numOfRows = pSrcBlock->info.rows};
int32_t slotId = pExpr[k].base.pParam[0].pCol->slotId;
p.columnData = taosArrayGet(pSrcBlock->pDataBlock, slotId);
SScalarParam dest = {0};
dest.columnData = taosArrayGet(pResult->pDataBlock, k);
pCtx[k].sfp.process(&p, 1, &dest);
pResult->info.rows = dest.numOfRows;
} else {
ASSERT(0); ASSERT(0);
} }
} }
pResult->info.rows = pCtx[0].input.numOfRows;
} }
void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SArray* pDataBlock, TSKEY prevTs, void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo, SArray* pDataBlock, TSKEY prevTs,
...@@ -2013,107 +2036,6 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) { ...@@ -2013,107 +2036,6 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx *pCtx, int32_t numOfOutput) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static SqlFunctionCtx* createSqlFunctionCtx(STaskRuntimeEnv* pRuntimeEnv, SExprInfo* pExpr, int32_t numOfOutput,
int32_t** rowCellInfoOffset) {
STaskAttr* pQueryAttr = pRuntimeEnv->pQueryAttr;
SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx));
if (pFuncCtx == NULL) {
return NULL;
}
*rowCellInfoOffset = taosMemoryCalloc(numOfOutput, sizeof(int32_t));
if (*rowCellInfoOffset == 0) {
taosMemoryFreeClear(pFuncCtx);
return NULL;
}
for (int32_t i = 0; i < numOfOutput; ++i) {
SExprBasicInfo *pFunct = &pExpr[i].base;
SqlFunctionCtx* pCtx = &pFuncCtx[i];
#if 0
SColIndex *pIndex = &pFunct->colInfo;
if (TSDB_COL_REQ_NULL(pIndex->flag)) {
pCtx->requireNull = true;
pIndex->flag &= ~(TSDB_COL_NULL);
} else {
pCtx->requireNull = false;
}
#endif
// pCtx->inputBytes = pFunct->colBytes;
// pCtx->inputType = pFunct->colType;
pCtx->ptsOutputBuf = NULL;
pCtx->resDataInfo.bytes = pFunct->resSchema.bytes;
pCtx->resDataInfo.type = pFunct->resSchema.type;
pCtx->order = pQueryAttr->order.order;
// pCtx->functionId = pFunct->functionId;
pCtx->stableQuery = pQueryAttr->stableQuery;
// pCtx->resDataInfo.interBufSize = pFunct->interBytes;
pCtx->start.key = INT64_MIN;
pCtx->end.key = INT64_MIN;
pCtx->numOfParams = pFunct->numOfParams;
for (int32_t j = 0; j < pCtx->numOfParams; ++j) {
int16_t type = pFunct->pParam[j].param.nType;
int16_t bytes = pFunct->pParam[j].param.nType;
if (type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_NCHAR) {
// taosVariantCreateFromBinary(&pCtx->param[j], pFunct->param[j].pz, bytes, type);
} else {
// taosVariantCreateFromBinary(&pCtx->param[j], (char *)&pFunct->param[j].i, bytes, type);
}
}
// set the order information for top/bottom query
int32_t functionId = pCtx->functionId;
if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_DIFF) {
int32_t f = getExprFunctionId(&pExpr[0]);
assert(f == FUNCTION_TS || f == FUNCTION_TS_DUMMY);
pCtx->param[2].i = pQueryAttr->order.order;
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[3].i = functionId;
pCtx->param[3].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[1].i = pQueryAttr->order.col.colId;
} else if (functionId == FUNCTION_INTERP) {
pCtx->param[2].i = (int8_t)pQueryAttr->fillType;
if (pQueryAttr->fillVal != NULL) {
if (isNull((const char *)&pQueryAttr->fillVal[i], pCtx->inputType)) {
pCtx->param[1].nType = TSDB_DATA_TYPE_NULL;
} else { // todo refactor, taosVariantCreateFromBinary should handle the NULL value
if (pCtx->inputType != TSDB_DATA_TYPE_BINARY && pCtx->inputType != TSDB_DATA_TYPE_NCHAR) {
taosVariantCreateFromBinary(&pCtx->param[1], (char *)&pQueryAttr->fillVal[i], pCtx->inputBytes, pCtx->inputType);
}
}
}
} else if (functionId == FUNCTION_TS_COMP) {
pCtx->param[0].i = pQueryAttr->vgId; //TODO this should be the parameter from client
pCtx->param[0].nType = TSDB_DATA_TYPE_BIGINT;
} else if (functionId == FUNCTION_TWA) {
pCtx->param[1].i = pQueryAttr->window.skey;
pCtx->param[1].nType = TSDB_DATA_TYPE_BIGINT;
pCtx->param[2].i = pQueryAttr->window.ekey;
pCtx->param[2].nType = TSDB_DATA_TYPE_BIGINT;
} else if (functionId == FUNCTION_ARITHM) {
// pCtx->param[1].pz = (char*) getScalarFuncSupport(pRuntimeEnv->scalarSup, i);
}
}
// for(int32_t i = 1; i < numOfOutput; ++i) {
// (*rowCellInfoOffset)[i] = (int32_t)((*rowCellInfoOffset)[i - 1] + sizeof(SResultRowEntryInfo) + pExpr[i - 1].base.interBytes);
// }
setCtxTagColumnInfo(pFuncCtx, numOfOutput);
return pFuncCtx;
}
static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) { static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) {
SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx)); SqlFunctionCtx * pFuncCtx = (SqlFunctionCtx *)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx));
if (pFuncCtx == NULL) { if (pFuncCtx == NULL) {
...@@ -2132,15 +2054,22 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num ...@@ -2132,15 +2054,22 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num
SExprBasicInfo *pFunct = &pExpr->base; SExprBasicInfo *pFunct = &pExpr->base;
SqlFunctionCtx* pCtx = &pFuncCtx[i]; SqlFunctionCtx* pCtx = &pFuncCtx[i];
if (pExpr->pExpr->_function.pFunctNode != NULL) { pCtx->functionId = -1;
if (pExpr->pExpr->nodeType == QUERY_NODE_FUNCTION) {
SFuncExecEnv env = {0}; SFuncExecEnv env = {0};
pCtx->functionId = pExpr->pExpr->_function.pFunctNode->funcId; pCtx->functionId = pExpr->pExpr->_function.pFunctNode->funcId;
fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet); if (fmIsAggFunc(pCtx->functionId)) {
pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env); fmGetFuncExecFuncs(pCtx->functionId, &pCtx->fpSet);
pCtx->fpSet.getEnv(pExpr->pExpr->_function.pFunctNode, &env);
} else {
fmGetScalarFuncExecFuncs(pCtx->functionId, &pCtx->sfp);
}
pCtx->resDataInfo.interBufSize = env.calcMemSize; pCtx->resDataInfo.interBufSize = env.calcMemSize;
} else { } else if (pExpr->pExpr->nodeType == QUERY_NODE_COLUMN) {
pCtx->functionId = -1;
} else if (pExpr->pExpr->nodeType == QUERY_NODE_OPERATOR) {
} }
pCtx->input.numOfInputCols = pFunct->numOfParams; pCtx->input.numOfInputCols = pFunct->numOfParams;
...@@ -5578,11 +5507,11 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { ...@@ -5578,11 +5507,11 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
SOperatorNode *node = (SOperatorNode *)pNode; SOperatorNode *node = (SOperatorNode *)pNode;
if (OP_TYPE_EQUAL == node->opType) { if (OP_TYPE_EQUAL == node->opType) {
*(int32_t *)pContext = 1; *(int32_t *)pContext = 1;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
*(int32_t *)pContext = 0; *(int32_t *)pContext = 0;
return DEAL_RES_IGNORE_CHILD; return DEAL_RES_IGNORE_CHILD;
} }
...@@ -5590,14 +5519,14 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { ...@@ -5590,14 +5519,14 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
if (1 != *(int32_t *)pContext) { if (1 != *(int32_t *)pContext) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
SColumnNode *node = (SColumnNode *)pNode; SColumnNode *node = (SColumnNode *)pNode;
if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) { if (TSDB_INS_USER_STABLES_DBNAME_COLID == node->colId) {
*(int32_t *)pContext = 2; *(int32_t *)pContext = 2;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
*(int32_t *)pContext = 0; *(int32_t *)pContext = 0;
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
case QUERY_NODE_VALUE: { case QUERY_NODE_VALUE: {
...@@ -5607,7 +5536,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) { ...@@ -5607,7 +5536,7 @@ EDealRes getDBNameFromConditionWalker(SNode* pNode, void* pContext) {
SValueNode *node = (SValueNode *)pNode; SValueNode *node = (SValueNode *)pNode;
char *dbName = nodesGetValueFromNode(node); char *dbName = nodesGetValueFromNode(node);
strncpy(pContext, varDataVal(dbName), varDataLen(dbName)); strncpy(pContext, varDataVal(dbName), varDataLen(dbName));
*((char *)pContext + varDataLen(dbName)) = 0; *((char *)pContext + varDataLen(dbName)) = 0;
return DEAL_RES_ERROR; // stop walk return DEAL_RES_ERROR; // stop walk
} }
...@@ -6654,7 +6583,6 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) ...@@ -6654,7 +6583,6 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup)
blockDataCleanup(pRes); blockDataCleanup(pRes);
if (pProjectInfo->existDataBlock) { // TODO refactor if (pProjectInfo->existDataBlock) { // TODO refactor
// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current;
SSDataBlock* pBlock = pProjectInfo->existDataBlock; SSDataBlock* pBlock = pProjectInfo->existDataBlock;
pProjectInfo->existDataBlock = NULL; pProjectInfo->existDataBlock = NULL;
*newgroup = true; *newgroup = true;
...@@ -6668,9 +6596,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) ...@@ -6668,9 +6596,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup)
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC); setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC);
blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows); blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
projectApplyFunctions(pInfo->pRes, pInfo->pCtx, pOperator->numOfOutput); projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput);
pRes->info.rows = getNumOfResult(pInfo->pCtx, pOperator->numOfOutput, NULL);
if (pRes->info.rows >= pProjectInfo->binfo.capacity*0.8) { if (pRes->info.rows >= pProjectInfo->binfo.capacity*0.8) {
copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput);
resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfOutput); resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfOutput);
...@@ -6713,15 +6639,15 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup) ...@@ -6713,15 +6639,15 @@ static SSDataBlock* doProjectOperation(SOperatorInfo *pOperator, bool* newgroup)
// the pDataBlock are always the same one, no need to call this again // the pDataBlock are always the same one, no need to call this again
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC); setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC);
updateOutputBuf(pInfo, &pInfo->capacity, pBlock->info.rows); blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows);
projectApplyFunctions(pInfo->pRes, pInfo->pCtx, pOperator->numOfOutput); projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput);
if (pRes->info.rows >= pProjectInfo->threshold) { if (pRes->info.rows >= pOperator->resultInfo.threshold) {
break; break;
} }
} }
copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput); // copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput);
return (pInfo->pRes->info.rows > 0)? pInfo->pRes:NULL; return (pInfo->pRes->info.rows > 0)? pInfo->pRes:NULL;
} }
...@@ -7811,7 +7737,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* ...@@ -7811,7 +7737,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { SOperatorInfo* createAllTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) {
STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo));
pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
...@@ -7836,7 +7762,7 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper ...@@ -7836,7 +7762,7 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper
SStateWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStateWindowOperatorInfo)); SStateWindowOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SStateWindowOperatorInfo));
pInfo->colIndex = -1; pInfo->colIndex = -1;
pInfo->reptScan = false; pInfo->reptScan = false;
pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
...@@ -7901,7 +7827,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo ...@@ -7901,7 +7827,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo
SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) {
STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo));
pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
...@@ -7925,7 +7851,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim ...@@ -7925,7 +7851,7 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim
SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) { SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfOutput) {
STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo)); STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo));
pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset); // pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity); // pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8); initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
...@@ -8533,16 +8459,18 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* ...@@ -8533,16 +8459,18 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
// it is a project query, or group by column // it is a project query, or group by column
if (nodeType(pTargetNode->pExpr) == QUERY_NODE_COLUMN) { if (nodeType(pTargetNode->pExpr) == QUERY_NODE_COLUMN) {
pExp->pExpr->nodeType = QUERY_NODE_COLUMN;
SColumnNode* pColNode = (SColumnNode*) pTargetNode->pExpr; SColumnNode* pColNode = (SColumnNode*) pTargetNode->pExpr;
SDataType* pType = &pColNode->node.resType; SDataType* pType = &pColNode->node.resType;
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pColNode->colName); pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pColNode->colName);
pCol->slotId = pColNode->slotId; pCol->slotId = pColNode->slotId; // TODO refactor
pCol->bytes = pType->bytes; pCol->bytes = pType->bytes;
pCol->type = pType->type; pCol->type = pType->type;
pCol->scale = pType->scale; pCol->scale = pType->scale;
pCol->precision = pType->precision; pCol->precision = pType->precision;
} else { } else if (nodeType(pTargetNode->pExpr) == QUERY_NODE_FUNCTION) {
pExp->pExpr->nodeType = QUERY_NODE_FUNCTION;
SFunctionNode* pFuncNode = (SFunctionNode*)pTargetNode->pExpr; SFunctionNode* pFuncNode = (SFunctionNode*)pTargetNode->pExpr;
SDataType* pType = &pFuncNode->node.resType; SDataType* pType = &pFuncNode->node.resType;
...@@ -8556,7 +8484,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* ...@@ -8556,7 +8484,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList); int32_t numOfParam = LIST_LENGTH(pFuncNode->pParameterList);
for (int32_t j = 0; j < numOfParam; ++j) { for (int32_t j = 0; j < numOfParam; ++j) {
SNode* p1 = nodesListGetNode(pFuncNode->pParameterList, j); SNode* p1 = nodesListGetNode(pFuncNode->pParameterList, j);
SColumnNode* pcn = (SColumnNode*)p1; SColumnNode* pcn = (SColumnNode*)p1; // TODO refactor
pCol->slotId = pcn->slotId; pCol->slotId = pcn->slotId;
pCol->bytes = pcn->node.resType.bytes; pCol->bytes = pcn->node.resType.bytes;
...@@ -8565,6 +8493,22 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t* ...@@ -8565,6 +8493,22 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
pCol->precision = pcn->node.resType.precision; pCol->precision = pcn->node.resType.precision;
pCol->dataBlockId = pcn->dataBlockId; pCol->dataBlockId = pcn->dataBlockId;
} }
} else if (nodeType(pTargetNode->pExpr) == QUERY_NODE_OPERATOR) {
pExp->pExpr->nodeType = QUERY_NODE_OPERATOR;
SOperatorNode* pNode = (SOperatorNode*) pTargetNode->pExpr;
SDataType* pType = &pNode->node.resType;
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, pTargetNode->slotId, pType->scale, pType->precision, pNode->node.aliasName);
pExp->pExpr->_optrRoot.pRootNode = pTargetNode->pExpr;
pCol->slotId = pTargetNode->slotId; // TODO refactor
pCol->bytes = pType->bytes;
pCol->type = pType->type;
pCol->scale = pType->scale;
pCol->precision = pType->precision;
} else {
ASSERT(0);
} }
} }
...@@ -8627,7 +8571,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa ...@@ -8627,7 +8571,7 @@ SOperatorInfo* doCreateOperatorTreeNode(SPhysiNode* pPhyNode, SExecTaskInfo* pTa
SArray* colList = extractScanColumnId(pScanNode->pScanCols); SArray* colList = extractScanColumnId(pScanNode->pScanCols);
SOperatorInfo* pOperator = createSysTableScanOperatorInfo(pHandle->meta, pResBlock, &pScanNode->tableName, SOperatorInfo* pOperator = createSysTableScanOperatorInfo(pHandle->meta, pResBlock, &pScanNode->tableName,
pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet, pScanNode->node.pConditions, pSysScanPhyNode->mgmtEpSet,
colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId); colList, pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId);
return pOperator; return pOperator;
} else { } else {
......
...@@ -25,23 +25,23 @@ extern "C" { ...@@ -25,23 +25,23 @@ extern "C" {
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
void functionFinalize(SqlFunctionCtx *pCtx); void functionFinalize(SqlFunctionCtx *pCtx);
bool getCountFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void countFunction(SqlFunctionCtx *pCtx); void countFunction(SqlFunctionCtx *pCtx);
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void sumFunction(SqlFunctionCtx *pCtx); void sumFunction(SqlFunctionCtx *pCtx);
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo); bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
bool getMinmaxFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void minFunction(SqlFunctionCtx* pCtx); void minFunction(SqlFunctionCtx* pCtx);
void maxFunction(SqlFunctionCtx *pCtx); void maxFunction(SqlFunctionCtx *pCtx);
bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getStddevFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void stddevFunction(SqlFunctionCtx* pCtx); void stddevFunction(SqlFunctionCtx* pCtx);
void stddevFinalize(SqlFunctionCtx* pCtx); void stddevFinalize(SqlFunctionCtx* pCtx);
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv); bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void firstFunction(SqlFunctionCtx *pCtx); void firstFunction(SqlFunctionCtx *pCtx);
void lastFunction(SqlFunctionCtx *pCtx); void lastFunction(SqlFunctionCtx *pCtx);
......
...@@ -331,6 +331,14 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { ...@@ -331,6 +331,14 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
case FUNCTION_TYPE_CONCAT: case FUNCTION_TYPE_CONCAT:
// todo // todo
break; break;
case FUNCTION_TYPE_ABS: {
SColumnNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
int32_t paraType = pParam->node.resType.type;
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[paraType].bytes, .type = paraType };
break;
}
default: default:
ASSERT(0); // to found the fault ASAP. ASSERT(0); // to found the fault ASAP.
} }
......
...@@ -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(SValueNode* pValueNode, SScalarParam* out);
SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows);
#define GET_PARAM_TYPE(_c) ((_c)->columnData->info.type)
#define GET_PARAM_BYTES(_c) ((_c)->pColumnInfoData->info.bytes)
int32_t sclMoveParamListData(SScalarParam *params, int32_t listNum, int32_t idx);
bool sclIsNull(SScalarParam* param, int32_t idx);
void sclSetNull(SScalarParam* param, int32_t idx);
void sclFreeParam(SScalarParam *param); void sclFreeParam(SScalarParam *param);
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -22,19 +22,7 @@ extern "C" { ...@@ -22,19 +22,7 @@ extern "C" {
#include "function.h" #include "function.h"
#include "scalar.h" #include "scalar.h"
typedef struct SScalarFunctionSupport {
struct SExprInfo *pExprInfo;
int32_t numOfCols;
SColumnInfo *colList;
void *exprList; // client side used
int32_t offset;
char** data;
} SScalarFunctionSupport;
extern struct SScalarFunctionInfo scalarFunc[8];
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarParam* pOutput,
void* param, char* (*getSourceDataBlock)(void*, const char*, int32_t));
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -20,10 +20,66 @@ ...@@ -20,10 +20,66 @@
extern "C" { extern "C" {
#endif #endif
#include "sclfunc.h" typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index);
typedef double (*_mathFunc)(double, double, bool *); static FORCE_INLINE double getVectorDoubleValue_TINYINT(void *src, int32_t index) {
return (double)*((int8_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_UTINYINT(void *src, int32_t index) {
return (double)*((uint8_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_SMALLINT(void *src, int32_t index) {
return (double)*((int16_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_USMALLINT(void *src, int32_t index) {
return (double)*((uint16_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_INT(void *src, int32_t index) {
return (double)*((int32_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_UINT(void *src, int32_t index) {
return (double)*((uint32_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_BIGINT(void *src, int32_t index) {
return (double)*((int64_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_UBIGINT(void *src, int32_t index) {
return (double)*((uint64_t *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_FLOAT(void *src, int32_t index) {
return (double)*((float *)src + index);
}
static FORCE_INLINE double getVectorDoubleValue_DOUBLE(void *src, int32_t index) {
return (double)*((double *)src + index);
}
static FORCE_INLINE _getDoubleValue_fn_t getVectorDoubleValueFn(int32_t srcType) {
_getDoubleValue_fn_t p = NULL;
if (srcType == TSDB_DATA_TYPE_TINYINT) {
p = getVectorDoubleValue_TINYINT;
} else if (srcType == TSDB_DATA_TYPE_UTINYINT) {
p = getVectorDoubleValue_UTINYINT;
} else if (srcType == TSDB_DATA_TYPE_SMALLINT) {
p = getVectorDoubleValue_SMALLINT;
} else if (srcType == TSDB_DATA_TYPE_USMALLINT) {
p = getVectorDoubleValue_USMALLINT;
} else if (srcType == TSDB_DATA_TYPE_INT) {
p = getVectorDoubleValue_INT;
} else if (srcType == TSDB_DATA_TYPE_UINT) {
p = getVectorDoubleValue_UINT;
} else if (srcType == TSDB_DATA_TYPE_BIGINT) {
p = getVectorDoubleValue_BIGINT;
} else if (srcType == TSDB_DATA_TYPE_UBIGINT) {
p = getVectorDoubleValue_UBIGINT;
} else if (srcType == TSDB_DATA_TYPE_FLOAT) {
p = getVectorDoubleValue_FLOAT;
} else if (srcType == TSDB_DATA_TYPE_DOUBLE) {
p = getVectorDoubleValue_DOUBLE;
} else {
assert(0);
}
return p;
}
typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType); typedef void (*_bufConverteFunc)(char *buf, SScalarParam* pOut, int32_t outType);
typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order); typedef void (*_bin_scalar_fn_t)(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *output, int32_t order);
......
...@@ -318,7 +318,7 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt ...@@ -318,7 +318,7 @@ static FORCE_INLINE SFilterRangeNode* filterNewRange(SFilterRangeCtx *ctx, SFilt
r->prev = NULL; r->prev = NULL;
r->next = NULL; r->next = NULL;
} else { } else {
r = taosMemoryCalloc(1, sizeof(SFilterRangeNode)); r = taosMemoryCalloc(1, sizeof(SFilterRangeNode));
} }
FILTER_COPY_RA(&r->ra, ra); FILTER_COPY_RA(&r->ra, ra);
...@@ -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 out = {.columnData = taosMemoryCalloc(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(valueNode, &out);
in.bytes = valueNode->node.resType.bytes;
in.data = nodesGetValueFromNode(valueNode);
out.data = taosMemoryMalloc(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);
taosMemoryFreeClear(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 out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
SScalarParam out = {.data = fi->data, .num = 1, .type = type}; out.columnData->info.type = type;
if (vectorConvertImpl(&in, &out)) {
// todo refactor the convert
int32_t code = doConvertDataType(var, &out);
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;
} }
...@@ -3636,7 +3630,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options) ...@@ -3636,7 +3630,7 @@ int32_t filterInitFromNode(SNode* pNode, SFilterInfo **pInfo, uint32_t options)
if (*pInfo == NULL) { if (*pInfo == NULL) {
*pInfo = taosMemoryCalloc(1, sizeof(SFilterInfo)); *pInfo = taosMemoryCalloc(1, sizeof(SFilterInfo));
if (NULL == *pInfo) { if (NULL == *pInfo) {
fltError("calloc %d failed", (int32_t)sizeof(SFilterInfo)); fltError("taosMemoryCalloc %d failed", (int32_t)sizeof(SFilterInfo));
FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
} }
} }
...@@ -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;
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "sclvector.h" #include "sclvector.h"
#include "tcommon.h" #include "tcommon.h"
#include "tdatablock.h" #include "tdatablock.h"
#include "scalar.h"
int32_t scalarGetOperatorParamNum(EOperatorType type) { int32_t scalarGetOperatorParamNum(EOperatorType type) {
if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type if (OP_TYPE_IS_NULL == type || OP_TYPE_IS_NOT_NULL == type || OP_TYPE_IS_TRUE == type || OP_TYPE_IS_NOT_TRUE == type
...@@ -16,6 +17,41 @@ int32_t scalarGetOperatorParamNum(EOperatorType type) { ...@@ -16,6 +17,41 @@ int32_t scalarGetOperatorParamNum(EOperatorType type) {
return 2; return 2;
} }
SColumnInfoData* createColumnInfoData(SDataType* pType, int32_t numOfRows) {
SColumnInfoData* pColumnData = taosMemoryCalloc(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;
taosMemoryFree(pColumnData);
return NULL;
} else {
return pColumnData;
}
}
int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) {
SScalarParam in = {.numOfRows = 1};
in.columnData = createColumnInfoData(&pValueNode->node.resType, 1);
colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false);
blockDataEnsureColumnCapacity(out->columnData, 1);
int32_t code = vectorConvertImpl(&in, out);
sclFreeParam(&in);
return code;
}
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 +64,8 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -28,10 +64,8 @@ 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}; SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
int8_t dummy = 0;
int32_t bufLen = 60;
out.data = taosMemoryMalloc(bufLen);
int32_t len = 0; int32_t len = 0;
void *buf = NULL; void *buf = NULL;
...@@ -39,22 +73,21 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -39,22 +73,21 @@ 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; out.columnData->info.type = type;
in.bytes = valueNode->node.resType.bytes; out.columnData->info.bytes = tDataTypes[type].bytes;
in.data = nodesGetValueFromNode(valueNode);
code = doConvertDataType(valueNode, &out);
code = vectorConvertImpl(&in, &out); if (code != TSDB_CODE_SUCCESS) {
if (code) { // sclError("convert data from %d to %d failed", in.type, out.type);
sclError("convert 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 +96,10 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -63,11 +96,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 +107,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) { ...@@ -75,40 +107,14 @@ int32_t scalarGenerateSetFromList(void **data, void *pNode, uint32_t type) {
cell = cell->pNext; cell = cell->pNext;
} }
taosMemoryFreeClear(out.data);
*data = pObj; *data = pObj;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
_return: _return:
taosMemoryFreeClear(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 = taosMemoryCalloc(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,30 +124,21 @@ void sclFreeRes(SHashObj *res) { ...@@ -118,30 +124,21 @@ 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) {
taosMemoryFreeClear(param->bitmap);
}
void sclFreeParam(SScalarParam *param) { void sclFreeParam(SScalarParam *param) {
sclFreeParamNoData(param); if (param->columnData != NULL) {
colDataDestroy(param->columnData);
if (!param->dataInBlock) { taosMemoryFreeClear(param->columnData);
if (SCL_DATA_TYPE_DUMMY_HASH == param->type) {
taosHashCleanup((SHashObj *)param->orig.data);
} else {
taosMemoryFreeClear(param->orig.data);
}
} }
}
if (param->pHashFilter != NULL) {
taosHashCleanup(param->pHashFilter);
}
}
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) {
...@@ -155,7 +152,6 @@ int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { ...@@ -155,7 +152,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,35 +159,26 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ...@@ -163,35 +159,26 @@ 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 (LIST_LENGTH(nodeList->pNodeList) <= 0) {
sclError("invalid length in nodeList, length:%d", nodeList->pNodeList->length); sclError("invalid length in nodeList, length:%d", LIST_LENGTH(nodeList->pNodeList));
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,73 +197,38 @@ int32_t sclInitParam(SNode* node, SScalarParam *param, SScalarCtx *ctx, int32_t ...@@ -210,73 +197,38 @@ 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_FUNCTION:
case QUERY_NODE_OPERATOR: { case QUERY_NODE_OPERATOR:
case QUERY_NODE_LOGIC_CONDITION: {
SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES); SScalarParam *res = (SScalarParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES);
if (NULL == res) { if (NULL == res) {
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;
} }
default: default:
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 +250,13 @@ int32_t sclInitParamList(SScalarParam **pParams, SNodeList* pParamList, SScalarC ...@@ -298,16 +250,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:
taosMemoryFreeClear(paramList); taosMemoryFreeClear(paramList);
SCL_RET(code); SCL_RET(code);
} }
...@@ -332,16 +281,13 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal ...@@ -332,16 +281,13 @@ int32_t sclInitOperatorParams(SScalarParam **pParams, SOperatorNode *node, SScal
} }
*pParams = paramList; *pParams = paramList;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
_return: _return:
taosMemoryFreeClear(paramList); taosMemoryFreeClear(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,37 +305,30 @@ int32_t sclExecFuncion(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outpu ...@@ -359,37 +305,30 @@ 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 = createColumnInfoData(&node->node.resType, rowNum);
output->data = taosMemoryCalloc(rowNum, sizeof(tDataTypes[output->type].bytes)); if (output->columnData == NULL) {
if (NULL == output->data) { sclError("calloc %d failed", (int32_t)(rowNum * output->columnData->info.bytes));
sclError("calloc %d failed", (int32_t)(rowNum * sizeof(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;
for (int32_t i = 0; i < rowNum; ++i) {
sclMoveParamListData(output, 1, i);
sclMoveParamListData(params, node->pParameterList->length, i);
// for (int32_t i = 0; i < rowNum; ++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));
SCL_ERR_JRET(code); SCL_ERR_JRET(code);
} // }
} }
_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);
} }
taosMemoryFreeClear(params); taosMemoryFreeClear(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 +348,24 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o ...@@ -409,28 +348,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 = taosMemoryCalloc(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,13 +375,12 @@ int32_t sclExecLogic(SLogicConditionNode *node, SScalarCtx *ctx, SScalarParam *o ...@@ -440,13 +375,12 @@ 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);
} }
taosMemoryFreeClear(params); taosMemoryFreeClear(params);
...@@ -459,16 +393,11 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp ...@@ -459,16 +393,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 = taosMemoryCalloc(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 +408,14 @@ int32_t sclExecOperator(SOperatorNode *node, SScalarCtx *ctx, SScalarParam *outp ...@@ -479,18 +408,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); // sclFreeParam(&params[i]);
} }
taosMemoryFreeClear(params); taosMemoryFreeClear(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 +435,12 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { ...@@ -510,11 +435,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 +453,8 @@ EDealRes sclRewriteFunction(SNode** pNode, SScalarCtx *ctx) { ...@@ -527,8 +453,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 = {0};
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,25 +470,25 @@ EDealRes sclRewriteLogic(SNode** pNode, SScalarCtx *ctx) { ...@@ -544,25 +470,25 @@ 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);
*pNode = (SNode*)res; *pNode = (SNode*)res;
sclFreeParam(&output); sclFreeParam(&output);
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
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 = taosMemoryCalloc(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)) { // todo refactor
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); colDataAssign(pDst->columnData, res->columnData, res->numOfRows);
pDst->numOfRows = res->numOfRows;
*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;
} }
......
#include "sclfunc.h" #include "sclfunc.h"
#include <common/tdatablock.h>
#include "sclInt.h"
#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;
} }
/** Math functions **/ /** Math functions **/
int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t absFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
assignBasicParaInfo(pOutput, pInput); SColumnInfoData *pInputData = pInput->columnData;
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { SColumnInfoData *pOutputData = pOutput->columnData;
int32_t type = GET_PARAM_TYPE(pInput);
if (!IS_NUMERIC_TYPE(type)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
char *input = NULL, *output = NULL; switch (type) {
for (int32_t i = 0; i < pOutput->num; ++i) { case TSDB_DATA_TYPE_FLOAT: {
if (pInput->num == 1) { float *in = (float *)pInputData->pData;
input = pInput->data; float *out = (float *)pOutputData->pData;
} else { for (int32_t i = 0; i < pInput->numOfRows; ++i) {
input = pInput->data + i * pInput->bytes; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
} colDataSetNull_f(pOutputData->nullbitmap, i);
output = pOutput->data + i * pOutput->bytes; continue;
}
if (isNull(input, pInput->type)) { out[i] = (in[i] > 0)? in[i] : -in[i];
setNull(output, pOutput->type, pOutput->bytes); }
continue; break;
} }
switch (pInput->type) { case TSDB_DATA_TYPE_DOUBLE: {
case TSDB_DATA_TYPE_FLOAT: { double *in = (double *)pInputData->pData;
float v; double *out = (double *)pOutputData->pData;
GET_TYPED_DATA(v, float, pInput->type, input); for (int32_t i = 0; i < pInput->numOfRows; ++i) {
float result; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
result = (v > 0) ? v : -v; colDataSetNull_f(pOutputData->nullbitmap, i);
SET_TYPED_DATA(output, pOutput->type, result); continue;
break; }
out[i] = (in[i] > 0)? in[i] : -in[i];
} }
break;
case TSDB_DATA_TYPE_DOUBLE: { }
double v;
GET_TYPED_DATA(v, double, pInput->type, input); case TSDB_DATA_TYPE_TINYINT: {
double result; int8_t *in = (int8_t *)pInputData->pData;
result = (v > 0) ? v : -v; int8_t *out = (int8_t *)pOutputData->pData;
SET_TYPED_DATA(output, pOutput->type, result); for (int32_t i = 0; i < pInput->numOfRows; ++i) {
break; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
}
out[i] = (in[i] > 0)? in[i] : -in[i];
} }
break;
case TSDB_DATA_TYPE_TINYINT: { }
int8_t v;
GET_TYPED_DATA(v, int8_t, pInput->type, input); case TSDB_DATA_TYPE_SMALLINT: {
int8_t result; int16_t *in = (int16_t *)pInputData->pData;
result = (v > 0) ? v : -v; int16_t *out = (int16_t *)pOutputData->pData;
SET_TYPED_DATA(output, pOutput->type, result); for (int32_t i = 0; i < pInput->numOfRows; ++i) {
break; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
}
out[i] = (in[i] > 0)? in[i] : -in[i];
} }
break;
case TSDB_DATA_TYPE_SMALLINT: { }
int16_t v;
GET_TYPED_DATA(v, int16_t, pInput->type, input); case TSDB_DATA_TYPE_INT: {
int16_t result; int32_t *in = (int32_t *)pInputData->pData;
result = (v > 0) ? v : -v; int32_t *out = (int32_t *)pOutputData->pData;
SET_TYPED_DATA(output, pOutput->type, result); for (int32_t i = 0; i < pInput->numOfRows; ++i) {
break; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
}
out[i] = (in[i] > 0)? in[i] : -in[i];
} }
break;
case TSDB_DATA_TYPE_INT: { }
int32_t v;
GET_TYPED_DATA(v, int32_t, pInput->type, input); case TSDB_DATA_TYPE_BIGINT: {
int32_t result; int64_t *in = (int64_t *)pInputData->pData;
result = (v > 0) ? v : -v; int64_t *out = (int64_t *)pOutputData->pData;
SET_TYPED_DATA(output, pOutput->type, result); for (int32_t i = 0; i < pInput->numOfRows; ++i) {
break; if (colDataIsNull_f(pInputData->nullbitmap, i)) {
} colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
case TSDB_DATA_TYPE_BIGINT: { }
int64_t v; out[i] = (in[i] > 0)? in[i] : -in[i];
GET_TYPED_DATA(v, int64_t, pInput->type, input);
int64_t result;
result = (v > 0) ? v : -v;
SET_TYPED_DATA(output, pOutput->type, result);
break;
} }
break;
}
default: { default: {
memcpy(output, input, pInput->bytes); colDataAssign(pOutputData, pInputData, pInput->numOfRows);
break;
}
} }
} }
pOutput->numOfRows = pInput->numOfRows;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
#if 0
if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) { if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char **input = NULL, *output = NULL; char **input = NULL, *output = NULL;
bool hasNullInput = false; bool hasNullInput = false;
input = taosMemoryCalloc(inputNum, sizeof(char *)); input = taosMemoryCalloc(inputNum, sizeof(char *));
...@@ -132,11 +144,13 @@ int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -132,11 +144,13 @@ int32_t logFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
} }
taosMemoryFree(input); taosMemoryFree(input);
#endif
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
#if 0
if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) { if (inputNum != 2 || !IS_NUMERIC_TYPE(pInput[0].type) || !IS_NUMERIC_TYPE(pInput[1].type)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
...@@ -175,381 +189,140 @@ int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu ...@@ -175,381 +189,140 @@ int32_t powFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutpu
} }
taosMemoryFree(input); taosMemoryFree(input);
#endif
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { typedef float (*_float_fn)(float);
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { typedef double (*_double_fn)(double);
int32_t doScalarFunctionUnique(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _double_fn valFn) {
int32_t type = GET_PARAM_TYPE(pInput);
if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
pOutput->type = TSDB_DATA_TYPE_DOUBLE; SColumnInfoData *pInputData = pInput->columnData;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; SColumnInfoData *pOutputData = pOutput->columnData;
char *input = NULL, *output = NULL; _getDoubleValue_fn_t getValueFn = getVectorDoubleValueFn(type);
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) { double *out = (double *)pOutputData->pData;
setNull(output, pOutput->type, pOutput->bytes);
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue; continue;
} }
out[i] = valFn(getValueFn(pInputData->pData, i));
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = sqrt(v);
SET_TYPED_DATA(output, pOutput->type, result);
} }
pOutput->numOfRows = pInput->numOfRows;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t doScalarFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam* pOutput, _float_fn f1, _double_fn d1) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { int32_t type = GET_PARAM_TYPE(pInput);
if (inputNum != 1 || !IS_NUMERIC_TYPE(type)) {
return TSDB_CODE_FAILED; return TSDB_CODE_FAILED;
} }
pOutput->type = TSDB_DATA_TYPE_DOUBLE; SColumnInfoData *pInputData = pInput->columnData;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes; SColumnInfoData *pOutputData = pOutput->columnData;
char *input = NULL, *output = NULL; switch (type) {
for (int32_t i = 0; i < pOutput->num; ++i) { case TSDB_DATA_TYPE_FLOAT: {
if (pInput->num == 1) { float *in = (float *)pInputData->pData;
input = pInput->data; float *out = (float *)pOutputData->pData;
} else {
input = pInput->data + i * pInput->bytes; for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
}
out[i] = f1(in[i]);
}
break;
} }
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) { case TSDB_DATA_TYPE_DOUBLE: {
setNull(output, pOutput->type, pOutput->bytes); double *in = (double *)pInputData->pData;
continue; double *out = (double *)pOutputData->pData;
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
colDataSetNull_f(pOutputData->nullbitmap, i);
continue;
}
out[i] = d1(in[i]);
}
break;
} }
double v; default: {
GET_TYPED_DATA(v, double, pInput->type, input); colDataAssign(pOutputData, pInputData, pInput->numOfRows);
double result = sin(v); }
SET_TYPED_DATA(output, pOutput->type, result);
} }
pOutput->numOfRows = pInput->numOfRows;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunctionUnique(pInput, inputNum, pOutput, atan);
return TSDB_CODE_FAILED; }
}
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
double v; int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
GET_TYPED_DATA(v, double, pInput->type, input); return doScalarFunctionUnique(pInput, inputNum, pOutput, sin);
double result = cos(v); }
SET_TYPED_DATA(output, pOutput->type, result);
}
return TSDB_CODE_SUCCESS; int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
return doScalarFunctionUnique(pInput, inputNum, pOutput, cos);
} }
int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunctionUnique(pInput, inputNum, pOutput, tan);
return TSDB_CODE_FAILED;
}
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = tan(v);
SET_TYPED_DATA(output, pOutput->type, result);
}
return TSDB_CODE_SUCCESS;
} }
int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunctionUnique(pInput, inputNum, pOutput, asin);
return TSDB_CODE_FAILED;
}
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = asin(v);
SET_TYPED_DATA(output, pOutput->type, result);
}
return TSDB_CODE_SUCCESS;
} }
int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunctionUnique(pInput, inputNum, pOutput, acos);
return TSDB_CODE_FAILED;
}
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = acos(v);
SET_TYPED_DATA(output, pOutput->type, result);
}
return TSDB_CODE_SUCCESS;
} }
int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunctionUnique(pInput, inputNum, pOutput, sqrt);
return TSDB_CODE_FAILED;
}
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = atan(v);
SET_TYPED_DATA(output, pOutput->type, result);
}
return TSDB_CODE_SUCCESS;
} }
int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t ceilFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) { return doScalarFunction(pInput, inputNum, pOutput, ceilf, ceil);
return TSDB_CODE_FAILED;
}
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
switch (pInput->type) {
case TSDB_DATA_TYPE_FLOAT: {
float v;
GET_TYPED_DATA(v, float, pInput->type, input);
float result = ceilf(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = ceil(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
default: {
memcpy(output, input, pInput->bytes);
break;
}
}
}
return TSDB_CODE_SUCCESS;
} }
int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t floorFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
assignBasicParaInfo(pOutput, pInput); return doScalarFunction(pInput, inputNum, pOutput, floorf, floor);
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
return TSDB_CODE_FAILED;
}
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
switch (pInput->type) {
case TSDB_DATA_TYPE_FLOAT: {
float v;
GET_TYPED_DATA(v, float, pInput->type, input);
float result = floorf(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = floor(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
default: {
memcpy(output, input, pInput->bytes);
break;
}
}
}
return TSDB_CODE_SUCCESS;
} }
int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { int32_t roundFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
assignBasicParaInfo(pOutput, pInput); return doScalarFunction(pInput, inputNum, pOutput, roundf, round);
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
return TSDB_CODE_FAILED;
}
char *input = NULL, *output = NULL;
for (int32_t i = 0; i < pOutput->num; ++i) {
if (pInput->num == 1) {
input = pInput->data;
} else {
input = pInput->data + i * pInput->bytes;
}
output = pOutput->data + i * pOutput->bytes;
if (isNull(input, pInput->type)) {
setNull(output, pOutput->type, pOutput->bytes);
continue;
}
switch (pInput->type) {
case TSDB_DATA_TYPE_FLOAT: {
float v;
GET_TYPED_DATA(v, float, pInput->type, input);
float result = roundf(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
case TSDB_DATA_TYPE_DOUBLE: {
double v;
GET_TYPED_DATA(v, double, pInput->type, input);
double result = round(v);
SET_TYPED_DATA(output, pOutput->type, result);
break;
}
default: {
memcpy(output, input, pInput->bytes);
break;
}
}
}
return TSDB_CODE_SUCCESS;
} }
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) {
...@@ -577,6 +350,7 @@ static void tconcat(SScalarParam* pOutput, size_t numOfInput, const SScalarParam ...@@ -577,6 +350,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) {
...@@ -652,154 +426,3 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf ...@@ -652,154 +426,3 @@ static void reverseCopy(char* dest, const char* src, int16_t type, int32_t numOf
} }
} }
static void setScalarFuncParam(SScalarParam* param, int32_t type, int32_t bytes, void* pInput, int32_t numOfRows) {
param->bytes = bytes;
param->type = type;
param->num = numOfRows;
param->data = pInput;
}
#if 0
int32_t evaluateExprNodeTree(tExprNode* pExprs, int32_t numOfRows, SScalarFuncParam* pOutput, void* param,
char* (*getSourceDataBlock)(void*, const char*, int32_t)) {
if (pExprs == NULL) {
return 0;
}
tExprNode* pLeft = pExprs->_node.pLeft;
tExprNode* pRight = pExprs->_node.pRight;
/* the left output has result from the left child syntax tree */
SScalarFuncParam leftOutput = {0};
SScalarFuncParam rightOutput = {0};
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
leftOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows);
evaluateExprNodeTree(pLeft, numOfRows, &leftOutput, param, getSourceDataBlock);
}
// the right output has result from the right child syntax tree
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) {
rightOutput.data = taosMemoryMalloc(sizeof(int64_t) * numOfRows);
evaluateExprNodeTree(pRight, numOfRows, &rightOutput, param, getSourceDataBlock);
}
if (pExprs->nodeType == TEXPR_BINARYEXPR_NODE) {
_bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(pExprs->_node.optr);
SScalarFuncParam left = {0}, right = {0};
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num);
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
SSchema* pschema = pLeft->pSchema;
char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
setScalarFuncParam(&right, pschema->type, pschema->bytes, pLeftInputData, numOfRows);
} else if (pLeft->nodeType == TEXPR_VALUE_NODE) {
SVariant* pVar = pRight->pVal;
setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1);
}
if (pRight->nodeType == TEXPR_BINARYEXPR_NODE || pRight->nodeType == TEXPR_UNARYEXPR_NODE) {
setScalarFuncParam(&right, rightOutput.type, rightOutput.bytes, rightOutput.data, rightOutput.num);
} else if (pRight->nodeType == TEXPR_COL_NODE) { // exprLeft + columnRight
SSchema* pschema = pRight->pSchema;
char* pInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
setScalarFuncParam(&right, pschema->type, pschema->bytes, pInputData, numOfRows);
} else if (pRight->nodeType == TEXPR_VALUE_NODE) { // exprLeft + 12
SVariant* pVar = pRight->pVal;
setScalarFuncParam(&right, pVar->nType, pVar->nLen, &pVar->i, 1);
}
void* outputBuf = pOutput->data;
if (isStringOp(pExprs->_node.optr)) {
outputBuf = taosMemoryRealloc(pOutput->data, (left.bytes + right.bytes) * left.num);
}
OperatorFn(&left, &right, outputBuf, TSDB_ORDER_ASC);
// Set the result info
setScalarFuncParam(pOutput, TSDB_DATA_TYPE_DOUBLE, sizeof(double), outputBuf, numOfRows);
} else if (pExprs->nodeType == TEXPR_UNARYEXPR_NODE) {
_unary_scalar_fn_t OperatorFn = getUnaryScalarOperatorFn(pExprs->_node.optr);
SScalarFuncParam left = {0};
if (pLeft->nodeType == TEXPR_BINARYEXPR_NODE || pLeft->nodeType == TEXPR_UNARYEXPR_NODE) {
setScalarFuncParam(&left, leftOutput.type, leftOutput.bytes, leftOutput.data, leftOutput.num);
} else if (pLeft->nodeType == TEXPR_COL_NODE) {
SSchema* pschema = pLeft->pSchema;
char* pLeftInputData = getSourceDataBlock(param, pschema->name, pschema->colId);
setScalarFuncParam(&left, pschema->type, pschema->bytes, pLeftInputData, numOfRows);
} else if (pLeft->nodeType == TEXPR_VALUE_NODE) {
SVariant* pVar = pLeft->pVal;
setScalarFuncParam(&left, pVar->nType, pVar->nLen, &pVar->i, 1);
}
// reserve enough memory buffer
if (isBinaryStringOp(pExprs->_node.optr)) {
void* outputBuf = taosMemoryRealloc(pOutput->data, left.bytes * left.num);
assert(outputBuf != NULL);
pOutput->data = outputBuf;
}
OperatorFn(&left, pOutput);
}
taosMemoryFreeClear(leftOutput.data);
taosMemoryFreeClear(rightOutput.data);
return 0;
}
#endif
//SScalarFunctionInfo scalarFunc[8] = {
// {"ceil", FUNCTION_TYPE_SCALAR, FUNCTION_CEIL, tceil},
// {"floor", FUNCTION_TYPE_SCALAR, FUNCTION_FLOOR, tfloor},
// {"abs", FUNCTION_TYPE_SCALAR, FUNCTION_ABS, _tabs},
// {"round", FUNCTION_TYPE_SCALAR, FUNCTION_ROUND, tround},
// {"length", FUNCTION_TYPE_SCALAR, FUNCTION_LENGTH, tlength},
// {"concat", FUNCTION_TYPE_SCALAR, FUNCTION_CONCAT, tconcat},
// {"ltrim", FUNCTION_TYPE_SCALAR, FUNCTION_LTRIM, tltrim},
// {"rtrim", FUNCTION_TYPE_SCALAR, FUNCTION_RTRIM, trtrim},
//};
void setScalarFunctionSupp(struct SScalarFunctionSupport* sas, SExprInfo *pExprInfo, SSDataBlock* pSDataBlock) {
sas->numOfCols = (int32_t) pSDataBlock->info.numOfCols;
sas->pExprInfo = pExprInfo;
if (sas->colList != NULL) {
return;
}
sas->colList = taosMemoryCalloc(1, pSDataBlock->info.numOfCols*sizeof(SColumnInfo));
for(int32_t i = 0; i < sas->numOfCols; ++i) {
SColumnInfoData* pColData = taosArrayGet(pSDataBlock->pDataBlock, i);
sas->colList[i] = pColData->info;
}
sas->data = taosMemoryCalloc(sas->numOfCols, POINTER_BYTES);
// set the input column data
for (int32_t f = 0; f < pSDataBlock->info.numOfCols; ++f) {
SColumnInfoData *pColumnInfoData = taosArrayGet(pSDataBlock->pDataBlock, f);
sas->data[f] = pColumnInfoData->pData;
}
}
SScalarFunctionSupport* createScalarFuncSupport(int32_t num) {
SScalarFunctionSupport* pSupp = taosMemoryCalloc(num, sizeof(SScalarFunctionSupport));
return pSupp;
}
void destroyScalarFuncSupport(struct SScalarFunctionSupport* pSupport, int32_t num) {
if (pSupport == NULL) {
return;
}
for(int32_t i = 0; i < num; ++i) {
SScalarFunctionSupport* pSupp = &pSupport[i];
taosMemoryFreeClear(pSupp->data);
taosMemoryFreeClear(pSupp->colList);
}
taosMemoryFreeClear(pSupport);
}
...@@ -25,108 +25,6 @@ ...@@ -25,108 +25,6 @@
#include "tdatablock.h" #include "tdatablock.h"
#include "ttypes.h" #include "ttypes.h"
//GET_TYPED_DATA(v, double, pRight->type, (char *)&((right)[i]));
void calc_i32_i32_add(void *left, void *right, int32_t numLeft, int32_t numRight, void *output, int32_t order) {
int32_t *pLeft = (int32_t *)left;
int32_t *pRight = (int32_t *)right;
double * pOutput = (double *)output;
int32_t i = (order == TSDB_ORDER_ASC) ? 0 : TMAX(numLeft, numRight) - 1;
int32_t step = (order == TSDB_ORDER_ASC) ? 1 : -1;
if (numLeft == numRight) {
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
SET_DOUBLE_NULL(pOutput);
continue;
}
*pOutput = (double)pLeft[i] + pRight[i];
}
} else if (numLeft == 1) {
for (; i >= 0 && i < numRight; i += step, pOutput += 1) {
if (isNull((char *)(pLeft), TSDB_DATA_TYPE_INT) || isNull((char *)&(pRight[i]), TSDB_DATA_TYPE_INT)) {
SET_DOUBLE_NULL(pOutput);
continue;
}
*pOutput = (double)pLeft[0] + pRight[i];
}
} else if (numRight == 1) {
for (; i >= 0 && i < numLeft; i += step, pOutput += 1) {
if (isNull((char *)&(pLeft[i]), TSDB_DATA_TYPE_INT) || isNull((char *)(pRight), TSDB_DATA_TYPE_INT)) {
SET_DOUBLE_NULL(pOutput);
continue;
}
*pOutput = (double)pLeft[i] + pRight[0];
}
}
}
typedef double (*_getDoubleValue_fn_t)(void *src, int32_t index);
double getVectorDoubleValue_TINYINT(void *src, int32_t index) {
return (double)*((int8_t *)src + index);
}
double getVectorDoubleValue_UTINYINT(void *src, int32_t index) {
return (double)*((uint8_t *)src + index);
}
double getVectorDoubleValue_SMALLINT(void *src, int32_t index) {
return (double)*((int16_t *)src + index);
}
double getVectorDoubleValue_USMALLINT(void *src, int32_t index) {
return (double)*((uint16_t *)src + index);
}
double getVectorDoubleValue_INT(void *src, int32_t index) {
return (double)*((int32_t *)src + index);
}
double getVectorDoubleValue_UINT(void *src, int32_t index) {
return (double)*((uint32_t *)src + index);
}
double getVectorDoubleValue_BIGINT(void *src, int32_t index) {
return (double)*((int64_t *)src + index);
}
double getVectorDoubleValue_UBIGINT(void *src, int32_t index) {
return (double)*((uint64_t *)src + index);
}
double getVectorDoubleValue_FLOAT(void *src, int32_t index) {
return (double)*((float *)src + 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) {
p = getVectorDoubleValue_TINYINT;
}else if(srcType==TSDB_DATA_TYPE_UTINYINT) {
p = getVectorDoubleValue_UTINYINT;
}else if(srcType==TSDB_DATA_TYPE_SMALLINT) {
p = getVectorDoubleValue_SMALLINT;
}else if(srcType==TSDB_DATA_TYPE_USMALLINT) {
p = getVectorDoubleValue_USMALLINT;
}else if(srcType==TSDB_DATA_TYPE_INT) {
p = getVectorDoubleValue_INT;
}else if(srcType==TSDB_DATA_TYPE_UINT) {
p = getVectorDoubleValue_UINT;
}else if(srcType==TSDB_DATA_TYPE_BIGINT) {
p = getVectorDoubleValue_BIGINT;
}else if(srcType==TSDB_DATA_TYPE_UBIGINT) {
p = getVectorDoubleValue_UBIGINT;
}else if(srcType==TSDB_DATA_TYPE_FLOAT) {
p = getVectorDoubleValue_FLOAT;
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
p = getVectorDoubleValue_DOUBLE;
}else {
assert(0);
}
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 +85,6 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) { ...@@ -187,9 +85,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) {
...@@ -261,28 +156,35 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) { ...@@ -261,28 +156,35 @@ _getValueAddr_fn_t getVectorValueAddrFn(int32_t srcType) {
return p; return p;
} }
static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t outType) { static FORCE_INLINE void varToSigned(char *buf, SScalarParam* pOut, int32_t rowIndex) {
int64_t value = strtoll(buf, NULL, 10); int64_t value = strtoll(buf, NULL, 10);
SET_TYPED_DATA(pOut->data, outType, value); colDataAppend(pOut->columnData, rowIndex, (char*) &value, false);
} }
static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t outType) { static FORCE_INLINE void varToUnsigned(char *buf, SScalarParam* pOut, int32_t rowIndex) {
uint64_t value = strtoull(buf, NULL, 10); uint64_t value = strtoull(buf, NULL, 10);
SET_TYPED_DATA(pOut->data, outType, value); colDataAppend(pOut->columnData, rowIndex, (char*) &value, false);
} }
static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t outType) { static FORCE_INLINE void varToFloat(char *buf, SScalarParam* pOut, int32_t rowIndex) {
double value = strtod(buf, NULL); double value = strtod(buf, NULL);
SET_TYPED_DATA(pOut->data, outType, value); colDataAppend(pOut->columnData, rowIndex, (char*) &value, false);
} }
static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowIndex) {
int64_t value = strtoll(buf, NULL, 10);
bool v = (value != 0)? true:false;
colDataAppend(pOut->columnData, rowIndex, (char*) &v, false);
}
int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) { int32_t vectorConvertFromVarData(const 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 = taosMemoryMalloc(bufSize);
_bufConverteFunc func = NULL;
if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType || TSDB_DATA_TYPE_BOOL == outType) { _bufConverteFunc func = NULL;
if (TSDB_DATA_TYPE_BOOL == outType) {
func = varToBool;
} else if (IS_SIGNED_NUMERIC_TYPE(outType) || TSDB_DATA_TYPE_TIMESTAMP == outType) {
func = varToSigned; func = varToSigned;
} else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) { } else if (IS_UNSIGNED_NUMERIC_TYPE(outType)) {
func = varToUnsigned; func = varToUnsigned;
...@@ -292,31 +194,22 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t ...@@ -292,31 +194,22 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t
sclError("invalid convert outType:%d", outType); sclError("invalid convert outType:%d", outType);
return TSDB_CODE_QRY_APP_ERROR; return TSDB_CODE_QRY_APP_ERROR;
} }
for (int32_t i = 0; i < pIn->num; ++i) { pOut->numOfRows = pIn->numOfRows;
sclMoveParamListData(pIn, 1, i); for (int32_t i = 0; i < pIn->numOfRows; ++i) {
sclMoveParamListData(pOut, 1, i); if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) {
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 = taosMemoryRealloc(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 = taosMemoryRealloc(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");
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
...@@ -326,80 +219,82 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t ...@@ -326,80 +219,82 @@ int32_t vectorConvertFromVarData(SScalarParam* pIn, SScalarParam* pOut, int32_t
tmp[len] = 0; tmp[len] = 0;
} }
(*func)(tmp, pOut, outType); (*func)(tmp, pOut, i);
} }
taosMemoryFreeClear(tmp); taosMemoryFreeClear(tmp);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t vectorConvertImpl(SScalarParam* pIn, SScalarParam* pOut) { // TODO opt performance
int16_t inType = pIn->type; int32_t vectorConvertImpl(const SScalarParam* pIn, SScalarParam* pOut) {
int16_t inBytes = pIn->bytes; SColumnInfoData* pInputCol = pIn->columnData;
int16_t outType = pOut->type; SColumnInfoData* pOutputCol = pOut->columnData;
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);
} }
switch (outType) { switch (outType) {
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL: {
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
if (colDataIsNull_f(pInputCol->nullbitmap, i)) {
colDataAppend(pOutputCol, i, NULL, true);
continue;
}
bool value = 0;
GET_TYPED_DATA(value, int64_t, inType, colDataGetData(pInputCol, i));
colDataAppend(pOutputCol, i, (char*) &value, false);
}
break;
}
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
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 +341,13 @@ int32_t vectorGetConvertType(int32_t type1, int32_t type2) { ...@@ -446,11 +341,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 +355,7 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p ...@@ -458,7 +355,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 +367,38 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p ...@@ -470,44 +367,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 = taosMemoryMalloc(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) {
taosMemoryFreeClear(paramOut1->data); // taosMemoryFreeClear(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 = taosMemoryMalloc(paramOut2->num * tDataTypes[paramOut2->type].bytes); paramOut2->columnData = createColumnInfoData(&t, param2->numOfRows);
if (NULL == paramOut2->data) { if (paramOut2->columnData == NULL) {
taosMemoryFreeClear(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) {
taosMemoryFreeClear(paramOut1->data);
taosMemoryFreeClear(paramOut2->data);
return code; return code;
} }
} }
...@@ -515,652 +406,387 @@ int32_t vectorConvert(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam* p ...@@ -515,652 +406,387 @@ 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) { enum {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; VECTOR_DO_CONVERT = 0x1,
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; VECTOR_UN_CONVERT = 0x2,
double leftv = 0, rightv = 0; };
bool isNull = false;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
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 = taosMemoryCalloc(rightParam.num, sizeof(double));
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;
}
if (pLeft->num == pRight->num) { static int32_t doConvertHelper(SScalarParam* pDest, int32_t* convert, const SScalarParam* pParam, int32_t type) {
for (; i < pRight->num && i >= 0; i += step) { SColumnInfoData* pCol = pParam->columnData;
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, double, pLeft->type, pLeft->data); if (IS_VAR_DATA_TYPE(pCol->info.type)) {
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); pDest->numOfRows = pParam->numOfRows;
SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); SDataType t = {.type = type, .bytes = tDataTypes[type].bytes};
if (isNull) { pDest->columnData = createColumnInfoData(&t, pParam->numOfRows);
sclSetNull(pOut, i); if (pDest->columnData == NULL) {
isNull = false; sclError("malloc %d failed", (int32_t)(pParam->numOfRows * sizeof(double)));
} return TSDB_CODE_OUT_OF_MEMORY;
} }
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { int32_t code = vectorConvertImpl(pParam, pDest);
sclSetNull(pOut, i); if (code != TSDB_CODE_SUCCESS) {
continue; return code;
}
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull));
if (isNull) {
sclSetNull(pOut, i);
isNull = false;
}
} }
} else if (pRight->num == 1) {
sclMoveParamListData(pRight, 1, 0);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
for (; i >= 0 && i < pLeft->num; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) {
sclSetNull(pOut, i);
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); *convert = VECTOR_DO_CONVERT;
} else {
SET_DOUBLE_VAL(pOut->data, (*func)(leftv, rightv, &isNull)); *convert = VECTOR_UN_CONVERT;
if (isNull) {
sclSetNull(pOut, i);
isNull = false;
}
}
} }
sclFreeParam(&leftParam); return TSDB_CODE_SUCCESS;
sclFreeParam(&rightParam);
} }
double mathAdd(double leftv, double rightv, bool *isNull) { // TODO not correct for descending order scan
return leftv + rightv; 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 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) {
double mathDivide(double leftv, double rightv, bool *isNull) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, 0);
double zero = 0; }
if (0 == compareDoubleVal(&rightv, &zero)) { pOutputCol->hasNull = pLeftCol->hasNull;
*isNull = true; if (pOutputCol->hasNull) {
return zero; memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
}
} }
return leftv / rightv;
} }
double mathRemainder(double leftv, double rightv, bool *isNull) { static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) {
double zero = 0; SScalarParam convertParam = {0};
if (0 == compareDoubleVal(&rightv, &zero)) {
*isNull = true; int32_t code = doConvertHelper(&convertParam, doConvert, pInput, TSDB_DATA_TYPE_DOUBLE);
return zero; if (code != TSDB_CODE_SUCCESS) {
terrno = code;
return NULL;
} }
return leftv - ((int64_t)(leftv / rightv)) * rightv; if (*doConvert == VECTOR_DO_CONVERT) {
return convertParam.columnData;
} else {
return pInput->columnData;
}
} }
static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { if (type == VECTOR_DO_CONVERT) {
vectorMath(pLeft, pRight, pOut, _ord, mathAdd); colDataDestroy(pCol);
taosMemoryFree(pCol);
}
} }
void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
vectorMath(pLeft, pRight, pOut, _ord, mathSub); SColumnInfoData *pOutputCol = pOut->columnData;
}
void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
vectorMath(pLeft, pRight, pOut, _ord, mathMultiply); int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
}
void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
vectorMath(pLeft, pRight, pOut, _ord, mathDivide);
}
void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { int32_t leftConvert = 0, rightConvert = 0;
vectorMath(pLeft, pRight, pOut, _ord, mathRemainder); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
} SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
#if 0 _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
void vectorAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num, .dataInBlock = false};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num, .dataInBlock = false};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) { double *output = (double *)pOutputCol->pData;
return; if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i);
} }
pLeft = &leftParam;
}
if (IS_VAR_DATA_TYPE(pRight->type)) {
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double));
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;
}
if (pLeft->num == pRight->num) { pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
for (; i < pRight->num && i >= 0; i += step) { if (pOutputCol->hasNull) {
sclMoveParamListData(pLeft, 1, i); int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
sclMoveParamListData(pRight, 1, i); for (int32_t j = 0; j < numOfBitLen; ++j) {
sclMoveParamListData(pOut, 1, i); pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
} }
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, leftv + rightv);
}
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, leftv + rightv);
} }
} 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); } else if (pLeft->numOfRows == 1) {
vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
SET_DOUBLE_VAL(pOut->data, leftv + rightv); } else if (pRight->numOfRows == 1) {
} vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
void vectorSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { // TODO not correct for descending order scan
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
double leftv = 0, rightv = 0; _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
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 = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) { double *output = (double *)pOutputCol->pData;
return;
} if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
pLeft = &leftParam; // TODO set numOfRows NULL value
} } else {
if (IS_VAR_DATA_TYPE(pRight->type)) { for (; i >= 0 && i < numOfRows; i += step, output += 1) {
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double)); *output = (getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, 0)) * factor;
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 vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData;
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type);
if (pLeft->num == pRight->num) {
for (; i < pRight->num && i >= 0; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) - getVectorDoubleValueFnRight(pRight->data, i)); int32_t leftConvert = 0, rightConvert = 0;
} SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
} else if (pLeft->num == 1) { SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
sclSetNull(pOut, i); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
continue;
}
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) - getVectorDoubleValueFnRight(pRight->data,i)); double *output = (double *)pOutputCol->pData;
if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i);
} }
} else if (pRight->num == 1) {
for (; i >= 0 && i < pLeft->num; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) {
sclSetNull(pOut, i);
continue;
}
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) - getVectorDoubleValueFnRight(pRight->data,0)); pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
if (pOutputCol->hasNull) {
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
for (int32_t j = 0; j < numOfBitLen; ++j) {
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
}
} }
} else if (pLeft->numOfRows == 1) {
vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
} else if (pRight->numOfRows == 1) {
vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
void vectorMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1;
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) { // TODO not correct for descending order scan
return; 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);
pLeft = &leftParam; _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
}
if (IS_VAR_DATA_TYPE(pRight->type)) { double *output = (double *)pOutputCol->pData;
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double));
if (NULL == rightParam.data) { if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
sclError("malloc %d failed", (int32_t)(rightParam.num * sizeof(double))); // TODO set numOfRows NULL value
sclFreeParam(&leftParam); } else {
return; for (; i >= 0 && i < numOfRows; i += step, output += 1) {
*output = 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;
} }
}
void vectorMathMultiply(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
SColumnInfoData *pOutputCol = pOut->columnData;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
if (pLeft->num == pRight->num) { int32_t leftConvert = 0, rightConvert = 0;
for (; i < pRight->num && i >= 0; i += step) { SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
sclMoveParamListData(pLeft, 1, i); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) * getVectorDoubleValueFnRight(pRight->data, i)); double *output = (double *)pOutputCol->pData;
if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) * getVectorDoubleValueFnRight(pRightCol->pData, i);
} }
} else if (pLeft->num == 1) {
sclMoveParamListData(pLeft, 1, 0);
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) * getVectorDoubleValueFnRight(pRight->data,i)); pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
} if (pOutputCol->hasNull) {
} else if (pRight->num == 1) { int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
for (; i >= 0 && i < pLeft->num; i += step) { for (int32_t j = 0; j < numOfBitLen; ++j) {
sclMoveParamListData(pLeft, 1, i); pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) {
sclSetNull(pOut, i);
continue;
} }
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) * getVectorDoubleValueFnRight(pRight->data,0));
} }
} 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);
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
void vectorDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathDivide(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; SColumnInfoData *pOutputCol = pOut->columnData;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) { int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
return; int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
}
pLeft = &leftParam;
}
if (IS_VAR_DATA_TYPE(pRight->type)) {
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double));
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;
}
int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
if (pLeft->num == pRight->num) { double *output = (double *)pOutputCol->pData;
for (; i < pRight->num && i >= 0; i += step) { if (pLeft->numOfRows == pRight->numOfRows) { // check for the 0 value
sclMoveParamListData(pLeft, 1, i); for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
sclMoveParamListData(pRight, 1, i); *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data);
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, getVectorDoubleValueFnLeft(pLeft->data, i) / getVectorDoubleValueFnRight(pRight->data, i));
} }
} else if (pLeft->num == 1) {
for (; i >= 0 && i < pRight->num; i += step) {
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
sclSetNull(pOut, i); if (pOutputCol->hasNull) {
continue; int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
} for (int32_t j = 0; j < numOfBitLen; ++j) {
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
}
}
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data, 0) / getVectorDoubleValueFnRight(pRight->data,i)); } 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 = 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->num == 1) { } else if (pRight->numOfRows == 1) {
for (; i >= 0 && i < pLeft->num; i += step) { if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
sclMoveParamListData(pLeft, 1, i); // TODO set numOfRows NULL value
sclMoveParamListData(pOut, 1, i); } else {
for (; i >= 0 && i < pLeft->numOfRows; i += step, output += 1) {
if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) { *output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) / getVectorDoubleValueFnRight(pRightCol->pData, 0);
sclSetNull(pOut, i); }
continue; pOutputCol->hasNull = pLeftCol->hasNull;
if (pOutputCol->hasNull) {
memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(pLeft->numOfRows));
} }
SET_DOUBLE_VAL(pOut->data,getVectorDoubleValueFnLeft(pLeft->data,i) / getVectorDoubleValueFnRight(pRight->data,0));
} }
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
void vectorRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) { void vectorMathRemainder(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; SColumnInfoData *pOutputCol = pOut->columnData;
int32_t step = ((_ord) == TSDB_ORDER_ASC) ? 1 : -1; pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
double leftv = 0, rightv = 0;
SScalarParam leftParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pLeft->num};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_DOUBLE, .num = pRight->num};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(leftParam.num, sizeof(double));
if (NULL == leftParam.data) {
sclError("malloc %d failed", (int32_t)(leftParam.num * sizeof(double)));
return;
}
leftParam.orig.data = leftParam.data;
if (vectorConvertImpl(pLeft, &leftParam)) { int32_t i = ((_ord) == TSDB_ORDER_ASC)? 0 : TMAX(pLeft->numOfRows, pRight->numOfRows) - 1;
return; int32_t step = ((_ord) == TSDB_ORDER_ASC)? 1 : -1;
}
pLeft = &leftParam;
}
if (IS_VAR_DATA_TYPE(pRight->type)) {
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(double));
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;
}
int32_t leftConvert = 0, rightConvert = 0;
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeft->type); _getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRight->type); _getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
if (pLeft->num == pRight->num) { double *output = (double *)pOutputCol->pData;
for (; i < pRight->num && i >= 0; i += step) { double zero = 0.0;
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pRight, 1, i); if (pLeft->numOfRows == pRight->numOfRows) {
sclMoveParamListData(pOut, 1, i); for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
if (colDataIsNull_f(pLeftCol->nullbitmap, i) || colDataIsNull_f(pRightCol->nullbitmap, i)) {
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { colDataAppend(pOutputCol, i, NULL, true);
sclSetNull(pOut, i);
continue; continue;
} }
double v, u = 0.0; double lx = getVectorDoubleValueFnLeft(pLeftCol->pData, i);
GET_TYPED_DATA(v, double, pRight->type, pRight->data); double rx = getVectorDoubleValueFnRight(pRightCol->pData, i);
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) { if (compareDoubleVal(&zero, &rx)) {
sclSetNull(pOut, i); colDataAppend(pOutputCol, i, NULL, true);
continue; continue;
} }
GET_TYPED_DATA(leftv, double, pLeft->type, pLeft->data); *output = lx - ((int64_t)(lx / rx)) * rx;
GET_TYPED_DATA(rightv, double, pRight->type, pRight->data);
SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right);
} }
} else if (pLeft->num == 1) { } else if (pLeft->numOfRows == 1) {
double left = getVectorDoubleValueFnLeft(pLeft->data, 0); 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;
}
for (; i >= 0 && i < pRight->num; i += step) { double rx = getVectorDoubleValueFnRight(pRightCol->pData, i);
sclMoveParamListData(pRight, 1, i); if (compareDoubleVal(&zero, &rx)) {
sclMoveParamListData(pOut, 1, i); colDataAppend(pOutputCol, i, NULL, true);
continue;
if (sclIsNull(pLeft, 0) || sclIsNull(pRight, i)) { }
sclSetNull(pOut, i);
continue;
}
double v, u = 0.0; *output = lx - ((int64_t)(lx / rx)) * rx;
GET_TYPED_DATA(v, double, pRight->type, pRight->data);
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
sclSetNull(pOut, i);
continue;
} }
double right = getVectorDoubleValueFnRight(pRight->data, i);
SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right);
} }
} else if (pRight->num == 1) { } else if (pRight->numOfRows == 1) {
double right = getVectorDoubleValueFnRight(pRight->data, 0); 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;
}
for (; i >= 0 && i < pLeft->num; i += step) { double lx = getVectorDoubleValueFnLeft(pRightCol->pData, i);
sclMoveParamListData(pLeft, 1, i); if (compareDoubleVal(&zero, &lx)) {
sclMoveParamListData(pOut, 1, i); colDataAppend(pOutputCol, i, NULL, true);
continue;
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) { }
sclSetNull(pOut, i);
continue;
}
double v, u = 0.0; *output = lx - ((int64_t)(lx / rx)) * rx;
GET_TYPED_DATA(v, double, pRight->type, pRight->data);
if (getComparFunc(TSDB_DATA_TYPE_DOUBLE, 0)(&v, &u) == 0) {
sclSetNull(pOut, i);
continue;
} }
double left = getVectorDoubleValueFnLeft(pLeft->data, i);
SET_DOUBLE_VAL(pOut->data, left - ((int64_t)(left / right)) * right);
} }
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
#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, pLeftCol->info.type) || isNull(right, pRight->info.type)) {
setVardataNull(output, TSDB_DATA_TYPE_BINARY); setVardataNull(output, TSDB_DATA_TYPE_BINARY);
continue; continue;
} }
...@@ -1170,10 +796,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t ...@@ -1170,10 +796,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, pLeftCol->info.type) || isNull(right, pRight->info.type)) {
setVardataNull(output, TSDB_DATA_TYPE_BINARY); setVardataNull(output, TSDB_DATA_TYPE_BINARY);
continue; continue;
} }
...@@ -1182,10 +808,10 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t ...@@ -1182,10 +808,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, pLeftCol->info.type) || isNull(pRight->data, pRight->info.type)) {
SET_DOUBLE_NULL(output); SET_DOUBLE_NULL(output);
continue; continue;
} }
...@@ -1195,257 +821,182 @@ void vectorConcat(SScalarParam* pLeft, SScalarParam* pRight, void *out, int32_t ...@@ -1195,257 +821,182 @@ 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};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(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 {
pLeft = &leftParam; for (; i >= 0 && i < numOfRows; i += step, output += 1) {
} *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, 0);
if (IS_VAR_DATA_TYPE(pRight->type)) {
rightParam.data = taosMemoryCalloc(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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
_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) { int32_t leftConvert = 0, rightConvert = 0;
for (; i < pRight->num && i >= 0; i += step) { SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
sclMoveParamListData(pLeft, 1, i); SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
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); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
SET_BIGINT_VAL(pOut->data, leftv & rightv); int64_t *output = (int64_t *)pOutputCol->pData;
if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) & getVectorBigintValueFnRight(pRightCol->pData, i);
} }
} 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); pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
if (pOutputCol->hasNull) {
SET_BIGINT_VAL(pOut->data, leftv & rightv); int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
} for (int32_t j = 0; j < numOfBitLen; ++j) {
} else if (pRight->num == 1) { pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] & pRightCol->nullbitmap[j];
sclMoveParamListData(pRight, 1, 0);
GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data);
for (; i >= 0 && i < pLeft->num; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, 0)) {
sclSetNull(pOut, i);
continue;
} }
GET_TYPED_DATA(leftv, int64_t, pLeft->type, pLeft->data);
SET_BIGINT_VAL(pOut->data, leftv & rightv);
} }
} else if (pLeft->numOfRows == 1) {
vectorBitAndHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
} else if (pRight->numOfRows == 1) {
vectorBitAndHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
} }
sclFreeParam(&leftParam); doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&rightParam); doReleaseVec(pRightCol, rightConvert);
} }
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};
SScalarParam rightParam = {.type = TSDB_DATA_TYPE_BIGINT, .num = pRight->num};
if (IS_VAR_DATA_TYPE(pLeft->type)) {
leftParam.data = taosMemoryCalloc(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)) { int64_t *output = (int64_t *)pOutputCol->pData;
return;
} if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
pLeft = &leftParam; // TODO set numOfRows NULL value
} } else {
if (IS_VAR_DATA_TYPE(pRight->type)) { int64_t rx = getVectorBigintValueFnRight(pRightCol->pData, 0);
rightParam.data = taosMemoryCalloc(rightParam.num, sizeof(int64_t)); for (; i >= 0 && i < numOfRows; i += step, output += 1) {
if (NULL == rightParam.data) { *output = getVectorBigintValueFnLeft(pLeftCol->pData, i) | rx;
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;
} }
}
_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;
pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
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); int32_t leftConvert = 0, rightConvert = 0;
GET_TYPED_DATA(rightv, int64_t, pRight->type, pRight->data); SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
SET_BIGINT_VAL(pOut->data, leftv | rightv); _getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
} _getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
} 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 = 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];
}
} }
} 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);
} }
doReleaseVec(pLeftCol, leftConvert);
sclFreeParam(&leftParam); doReleaseVec(pRightCol, rightConvert);
sclFreeParam(&rightParam);
} }
void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) { void vectorCompareImpl(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord, int32_t optr) {
int32_t i = ((_ord) == TSDB_ORDER_ASC) ? 0 : TMAX(pLeft->num, pRight->num) - 1; int32_t 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;
__compar_fn_t fp = filterGetCompFunc(pLeft->type, optr); __compar_fn_t fp = filterGetCompFunc(GET_PARAM_TYPE(pLeft), optr);
bool res = false;
if (pLeft->num == pRight->num) {
for (; i < pRight->num && i >= 0; i += step) {
sclMoveParamListData(pLeft, 1, i);
sclMoveParamListData(pRight, 1, i);
sclMoveParamListData(pOut, 1, i);
if (sclIsNull(pLeft, i) || sclIsNull(pRight, i)) {
sclSetNull(pOut, i);
continue;
}
res = filterDoCompare(fp, optr, pLeft->data, pRight->data); pOut->numOfRows = TMAX(pLeft->numOfRows, pRight->numOfRows);
SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); if (pRight->pHashFilter != NULL) {
} for (; i >= 0 && i < pLeft->numOfRows; i += step) {
} else if (pLeft->num == 1) { if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*||
sclMoveParamListData(pLeft, 1, 0); colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) {
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; continue;
} }
char *pLeftData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRight->pHashFilter);
colDataAppend(pOut->columnData, i, (char *)&res, false);
}
return;
}
res = filterDoCompare(fp, optr, pLeft->data, pRight->data); if (pLeft->numOfRows == pRight->numOfRows) {
for (; i < pRight->numOfRows && i >= 0; i += step) {
if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) ||
colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)) {
continue; // TODO set null or ignore
}
SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); char *pLeftData = colDataGetData(pLeft->columnData, i);
char *pRightData = colDataGetData(pRight->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
colDataAppend(pOut->columnData, i, (char *)&res, false);
} }
} else if (pRight->num == 1) { } else if (pRight->numOfRows == 1) {
sclMoveParamListData(pRight, 1, 0); char *pRightData = colDataGetData(pRight->columnData, 0);
ASSERT(pLeft->pHashFilter == NULL);
for (; i >= 0 && i < pLeft->num; i += step) {
sclMoveParamListData(pLeft, 1, i); for (; i >= 0 && i < pLeft->numOfRows; i += step) {
sclMoveParamListData(pOut, 1, i); if (colDataIsNull(pLeft->columnData, pLeft->numOfRows, i, NULL) /*||
colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) {
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);
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
colDataAppend(pOut->columnData, i, (char *)&res, false);
}
} else if (pLeft->numOfRows == 1) {
char *pLeftData = colDataGetData(pLeft->columnData, 0);
for (; i >= 0 && i < pRight->numOfRows; i += step) {
if (colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL) /*||
colDataIsNull(pRight->columnData, pRight->numOfRows, i, NULL)*/) {
continue;
}
SET_TYPED_DATA(pOut->data, TSDB_DATA_TYPE_BOOL, res); char *pRightData = colDataGetData(pLeft->columnData, i);
bool res = filterDoCompare(fp, optr, pLeftData, pRightData);
colDataAppend(pOut->columnData, i, (char *)&res, false);
} }
} }
} }
...@@ -1459,21 +1010,19 @@ void vectorCompare(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut ...@@ -1459,21 +1010,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 +1076,44 @@ void vectorNotMatch(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOu ...@@ -1527,63 +1076,44 @@ 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);
} }
pOut->numOfRows = pLeft->numOfRows;
} }
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);
} }
pOut->numOfRows = pLeft->numOfRows;
} }
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:
...@@ -1622,6 +1152,4 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) { ...@@ -1622,6 +1152,4 @@ _bin_scalar_fn_t getBinScalarOperatorFn(int32_t binFunctionId) {
assert(0); assert(0);
return NULL; return NULL;
} }
} }
\ No newline at end of file
...@@ -269,7 +269,7 @@ TEST(constantTest, bigint_add_bigint) { ...@@ -269,7 +269,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);
} }
...@@ -285,7 +285,7 @@ TEST(constantTest, double_sub_bigint) { ...@@ -285,7 +285,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);
} }
...@@ -340,7 +340,6 @@ TEST(constantTest, int_or_binary) { ...@@ -340,7 +340,6 @@ TEST(constantTest, int_or_binary) {
nodesDestroyNode(res); nodesDestroyNode(res);
} }
TEST(constantTest, int_greater_double) { TEST(constantTest, int_greater_double) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV); scltMakeValueNode(&pLeft, TSDB_DATA_TYPE_INT, &scltLeftV);
...@@ -479,8 +478,6 @@ TEST(constantTest, int_not_equal_smallint2) { ...@@ -479,8 +478,6 @@ TEST(constantTest, int_not_equal_smallint2) {
nodesDestroyNode(res); nodesDestroyNode(res);
} }
TEST(constantTest, int_in_smallint1) { TEST(constantTest, int_in_smallint1) {
scltInitLogFile(); scltInitLogFile();
...@@ -851,7 +848,6 @@ TEST(constantTest, int_add_int_is_true2) { ...@@ -851,7 +848,6 @@ TEST(constantTest, int_add_int_is_true2) {
nodesDestroyNode(res); nodesDestroyNode(res);
} }
TEST(constantTest, int_greater_int_is_true1) { TEST(constantTest, int_greater_int_is_true1) {
SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL; SNode *pLeft = NULL, *pRight = NULL, *opNode = NULL, *res = NULL;
int32_t leftv = 1, rightv = 1; int32_t leftv = 1, rightv = 1;
...@@ -913,8 +909,6 @@ TEST(constantTest, greater_and_lower) { ...@@ -913,8 +909,6 @@ TEST(constantTest, greater_and_lower) {
nodesDestroyNode(res); nodesDestroyNode(res);
} }
TEST(columnTest, smallint_value_add_int_column) { TEST(columnTest, smallint_value_add_int_column) {
scltInitLogFile(); scltInitLogFile();
...@@ -967,7 +961,6 @@ TEST(columnTest, bigint_column_multi_binary_column) { ...@@ -967,7 +961,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));
...@@ -1271,7 +1264,6 @@ TEST(columnTest, binary_column_like_binary) { ...@@ -1271,7 +1264,6 @@ TEST(columnTest, binary_column_like_binary) {
nodesDestroyNode(opNode); nodesDestroyNode(opNode);
} }
TEST(columnTest, binary_column_is_true) { TEST(columnTest, binary_column_is_true) {
SNode *pLeft = NULL, *opNode = NULL; SNode *pLeft = NULL, *opNode = NULL;
char leftv[5][5]= {0}; char leftv[5][5]= {0};
...@@ -1286,7 +1278,7 @@ TEST(columnTest, binary_column_is_true) { ...@@ -1286,7 +1278,7 @@ TEST(columnTest, binary_column_is_true) {
} }
int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]); int32_t rowNum = sizeof(leftv)/sizeof(leftv[0]);
scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 3, rowNum, leftv); scltMakeColumnNode(&pLeft, &src, TSDB_DATA_TYPE_BINARY, 5, rowNum, leftv);
scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL); scltMakeOpNode(&opNode, OP_TYPE_IS_TRUE, TSDB_DATA_TYPE_BOOL, pLeft, NULL);
...@@ -1471,23 +1463,26 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t ...@@ -1471,23 +1463,26 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t
} }
} }
input->type = type; input->columnData = (SColumnInfoData*) taosMemoryCalloc(1, sizeof(SColumnInfoData));
input->num = num; input->numOfRows = num;
input->data = taosMemoryCalloc(num, bytes);
input->bytes = bytes; input->columnData->info = createColumnInfo(0, type, bytes);
blockDataEnsureColumnCapacity(input->columnData, num);
if (setVal) { if (setVal) {
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
memcpy(input->data + i * bytes, pVal, bytes); colDataAppend(input->columnData, i, (const char*) pVal, false);
} }
} else { } else {
memset(input->data, 0, num * bytes); // memset(input->data, 0, num * bytes);
} }
*pInput = input; *pInput = input;
} }
void scltDestroyDataBlock(SScalarParam *pInput) { void scltDestroyDataBlock(SScalarParam *pInput) {
taosMemoryFree(pInput->data); colDataDestroy(pInput->columnData);
taosMemoryFree(pInput->columnData);
taosMemoryFree(pInput); taosMemoryFree(pInput);
} }
...@@ -1500,25 +1495,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1500,25 +1495,25 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), val_tinyint); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
val_tinyint = -10; val_tinyint = -10;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), -val_tinyint); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -val_tinyint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1526,25 +1521,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1526,25 +1521,25 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//SMALLINT //SMALLINT
int16_t val_smallint = 10; int16_t val_smallint = 10;
type = TSDB_DATA_TYPE_SMALLINT; type = TSDB_DATA_TYPE_SMALLINT;
scltMakeDataBlock(&pInput, type, &val_smallint, 1, true); scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int16_t *)pOutput->data + i), val_smallint); ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
val_smallint = -10; val_smallint = -10;
scltMakeDataBlock(&pInput, type, &val_smallint, 1, true); scltMakeDataBlock(&pInput, type, &val_smallint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int16_t *)pOutput->data + i), -val_smallint); ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -val_smallint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1552,25 +1547,25 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1552,25 +1547,25 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//INT //INT
int32_t val_int = 10; int32_t val_int = 10;
type = TSDB_DATA_TYPE_INT; type = TSDB_DATA_TYPE_INT;
scltMakeDataBlock(&pInput, type, &val_int, 1, true); scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int32_t *)pOutput->data + i), val_int); ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
val_int = -10; val_int = -10;
scltMakeDataBlock(&pInput, type, &val_int, 1, true); scltMakeDataBlock(&pInput, type, &val_int, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int32_t *)pOutput->data + i), -val_int); ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -val_int);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1578,13 +1573,13 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1578,13 +1573,13 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//BIGINT //BIGINT
int64_t val_bigint = 10; int64_t val_bigint = 10;
type = TSDB_DATA_TYPE_BIGINT; type = TSDB_DATA_TYPE_BIGINT;
scltMakeDataBlock(&pInput, type, &val_bigint, 1, true); scltMakeDataBlock(&pInput, type, &val_bigint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int64_t *)pOutput->data + i), val_bigint); ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), val_bigint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1596,7 +1591,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1596,7 +1591,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int64_t *)pOutput->data + i), -val_bigint); ASSERT_EQ(*((int64_t *)colDataGetData(pOutput->columnData, i)), -val_bigint);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1604,29 +1599,29 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1604,29 +1599,29 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//FLOAT //FLOAT
float val_float = 10.15; float val_float = 10.15;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("float before ABS:%f\n", *(float *)pInput->data); PRINTF("float before ABS:%f\n", *(float *)pInput->data);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), val_float); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float);
PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
val_float = -10.15; val_float = -10.15;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("float before ABS:%f\n", *(float *)pInput->data); PRINTF("float before ABS:%f\n", *(float *)pInput->data);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), -val_float); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -val_float);
PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1634,13 +1629,13 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1634,13 +1629,13 @@ TEST(ScalarFunctionTest, absFunction_constant) {
//DOUBLE //DOUBLE
double val_double = 10.15; double val_double = 10.15;
type = TSDB_DATA_TYPE_DOUBLE; type = TSDB_DATA_TYPE_DOUBLE;
scltMakeDataBlock(&pInput, type, &val_double, 1, true); scltMakeDataBlock(&pInput, type, &val_double, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), val_double); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1652,7 +1647,7 @@ TEST(ScalarFunctionTest, absFunction_constant) { ...@@ -1652,7 +1647,7 @@ TEST(ScalarFunctionTest, absFunction_constant) {
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), -val_double); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -val_double);
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1671,15 +1666,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1671,15 +1666,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint + i; int8_t v = val_tinyint + i;
PRINTF("tiny_int before ABS:%d\n", *((int8_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("tiny_int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), val_tinyint + i); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), val_tinyint + i);
PRINTF("tiny_int after ABS:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1688,15 +1684,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1688,15 +1684,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint + i; int8_t v = val_tinyint + i;
PRINTF("tiny_int before ABS:%d\n", *((int8_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("tiny_int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), -(val_tinyint + i)); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), -(val_tinyint + i));
PRINTF("tiny_int after ABS:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after ABS:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1707,16 +1704,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1707,16 +1704,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int16_t *)pInput->data + i) = val_smallint + i; int16_t v = val_smallint + i;
PRINTF("small_int before ABS:%d\n", *((int16_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("small_int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int16_t *)pOutput->data + i), val_smallint + i); ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), val_smallint + i);
PRINTF("small_int after ABS:%d\n", *((int16_t *)pOutput->data + i)); PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1725,15 +1722,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1725,15 +1722,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int16_t *)pInput->data + i) = val_smallint + i; int16_t v = val_smallint + i;
PRINTF("small_int before ABS:%d\n", *((int16_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("small_int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int16_t *)pOutput->data + i), -(val_smallint + i)); ASSERT_EQ(*((int16_t *)colDataGetData(pOutput->columnData, i)), -(val_smallint + i));
PRINTF("small_int after ABS:%d\n", *((int16_t *)pOutput->data + i)); PRINTF("small_int after ABS:%d\n", *((int16_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1744,16 +1742,17 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1744,16 +1742,17 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int32_t *)pInput->data + i) = val_int + i; int32_t v = val_int + i;
PRINTF("int before ABS:%d\n", *((int32_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int32_t *)pOutput->data + i), val_int + i); ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), val_int + i);
PRINTF("int after ABS:%d\n", *((int32_t *)pOutput->data + i)); PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1762,15 +1761,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1762,15 +1761,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int32_t *)pInput->data + i) = val_int + i; int32_t v = val_int + i;
PRINTF("int before ABS:%d\n", *((int32_t *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("int before ABS:%d\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int32_t *)pOutput->data + i), -(val_int + i)); ASSERT_EQ(*((int32_t *)colDataGetData(pOutput->columnData, i)), -(val_int + i));
PRINTF("int after ABS:%d\n", *((int32_t *)pOutput->data + i)); PRINTF("int after ABS:%d\n", *((int32_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1781,15 +1781,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1781,15 +1781,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float + i; float v = val_float + i;
PRINTF("float before ABS:%f\n", *((float *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("float before ABS:%f\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), val_float + i); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), val_float + i);
PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1798,15 +1799,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1798,15 +1799,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float + i; float v = val_float + i;
PRINTF("float before ABS:%f\n", *((float *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("float before ABS:%f\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), -(val_float + i)); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), -(val_float + i));
PRINTF("float after ABS:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ABS:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1817,15 +1819,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1817,15 +1819,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((double *)pInput->data + i) = val_double + i; double v = val_double + i;
PRINTF("double before ABS:%f\n", *((double *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("double before ABS:%f\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), val_double + i); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), val_double + i);
PRINTF("double after ABS:%f\n", *((double *)pOutput->data + i)); PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1834,15 +1837,16 @@ TEST(ScalarFunctionTest, absFunction_column) { ...@@ -1834,15 +1837,16 @@ TEST(ScalarFunctionTest, absFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((double *)pInput->data + i) = val_double + i; double v = val_double + i;
PRINTF("double before ABS:%f\n", *((double *)pInput->data + i)); colDataAppend(pInput->columnData, i, (const char*) &v, false);
PRINTF("double before ABS:%f\n", v);
} }
code = absFunction(pInput, 1, pOutput); code = absFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), -(val_double + i)); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), -(val_double + i));
PRINTF("double after ABS:%f\n", *((double *)pOutput->data + i)); PRINTF("double after ABS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -1860,15 +1864,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) { ...@@ -1860,15 +1864,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data));
code = sinFunction(pInput, 1, pOutput); code = sinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after SIN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1876,15 +1880,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) { ...@@ -1876,15 +1880,15 @@ TEST(ScalarFunctionTest, sinFunction_constant) {
//FLOAT //FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before SIN:%f\n", *((float *)pInput->data)); PRINTF("float before SIN:%f\n", *((float *)pInput->data));
code = sinFunction(pInput, 1, pOutput); code = sinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after SIN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -1907,15 +1911,15 @@ TEST(ScalarFunctionTest, sinFunction_column) { ...@@ -1907,15 +1911,15 @@ TEST(ScalarFunctionTest, sinFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
PRINTF("tiny_int before SIN:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before SIN:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
} }
code = sinFunction(pInput, 1, pOutput); code = sinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after SIN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1926,15 +1930,15 @@ TEST(ScalarFunctionTest, sinFunction_column) { ...@@ -1926,15 +1930,15 @@ TEST(ScalarFunctionTest, sinFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
PRINTF("float before SIN:%f\n", *((float *)pInput->data + i)); PRINTF("float before SIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = sinFunction(pInput, 1, pOutput); code = sinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after SIN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after SIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -1952,15 +1956,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) { ...@@ -1952,15 +1956,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data));
code = cosFunction(pInput, 1, pOutput); code = cosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after COS:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -1968,15 +1972,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) { ...@@ -1968,15 +1972,15 @@ TEST(ScalarFunctionTest, cosFunction_constant) {
//FLOAT //FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before COS:%f\n", *((float *)pInput->data)); PRINTF("float before COS:%f\n", *((float *)pInput->data));
code = cosFunction(pInput, 1, pOutput); code = cosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after COS:%f\n", *((double *)pOutput->data + i)); PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -1997,15 +2001,15 @@ TEST(ScalarFunctionTest, cosFunction_column) { ...@@ -1997,15 +2001,15 @@ TEST(ScalarFunctionTest, cosFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
PRINTF("tiny_int before COS:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before COS:%d\n", *(int8_t *)colDataGetData(pInput->columnData, i));
} }
code = cosFunction(pInput, 1, pOutput); code = cosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after COS:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2016,15 +2020,15 @@ TEST(ScalarFunctionTest, cosFunction_column) { ...@@ -2016,15 +2020,15 @@ TEST(ScalarFunctionTest, cosFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
PRINTF("float before COS:%f\n", *((float *)pInput->data + i)); PRINTF("float before COS:%f\n", *(float *)colDataGetData(pInput->columnData, i));
} }
code = cosFunction(pInput, 1, pOutput); code = cosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after COS:%f\n", *((double *)pOutput->data + i)); PRINTF("float after COS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2042,15 +2046,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) { ...@@ -2042,15 +2046,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 13; int8_t val_tinyint = 13;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data));
code = tanFunction(pInput, 1, pOutput); code = tanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after TAN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2058,15 +2062,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) { ...@@ -2058,15 +2062,15 @@ TEST(ScalarFunctionTest, tanFunction_constant) {
//FLOAT //FLOAT
float val_float = 13.00; float val_float = 13.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before TAN:%f\n", *((float *)pInput->data)); PRINTF("float before TAN:%f\n", *((float *)pInput->data));
code = tanFunction(pInput, 1, pOutput); code = tanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after TAN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2087,15 +2091,15 @@ TEST(ScalarFunctionTest, tanFunction_column) { ...@@ -2087,15 +2091,15 @@ TEST(ScalarFunctionTest, tanFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
PRINTF("tiny_int before TAN:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before TAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = tanFunction(pInput, 1, pOutput); code = tanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after TAN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2106,15 +2110,15 @@ TEST(ScalarFunctionTest, tanFunction_column) { ...@@ -2106,15 +2110,15 @@ TEST(ScalarFunctionTest, tanFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; colDataAppend(pInput->columnData, i, (const char*) &val_float[i], false);
PRINTF("float before TAN:%f\n", *((float *)pInput->data + i)); PRINTF("float before TAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = tanFunction(pInput, 1, pOutput); code = tanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after TAN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after TAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2132,15 +2136,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) { ...@@ -2132,15 +2136,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data));
code = asinFunction(pInput, 1, pOutput); code = asinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after ASIN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2148,15 +2152,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) { ...@@ -2148,15 +2152,15 @@ TEST(ScalarFunctionTest, asinFunction_constant) {
//FLOAT //FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before ASIN:%f\n", *((float *)pInput->data)); PRINTF("float before ASIN:%f\n", *((float *)pInput->data));
code = asinFunction(pInput, 1, pOutput); code = asinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after ASIN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2178,15 +2182,15 @@ TEST(ScalarFunctionTest, asinFunction_column) { ...@@ -2178,15 +2182,15 @@ TEST(ScalarFunctionTest, asinFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; colDataAppend(pInput->columnData, i, (const char*) &val_tinyint[i], false);
PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before ASIN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = asinFunction(pInput, 1, pOutput); code = asinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after ASIN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2197,15 +2201,15 @@ TEST(ScalarFunctionTest, asinFunction_column) { ...@@ -2197,15 +2201,15 @@ TEST(ScalarFunctionTest, asinFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before ASIN:%f\n", *((float *)pInput->data + i)); PRINTF("float before ASIN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = asinFunction(pInput, 1, pOutput); code = asinFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after ASIN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ASIN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2223,15 +2227,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) { ...@@ -2223,15 +2227,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data));
code = acosFunction(pInput, 1, pOutput); code = acosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after ACOS:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2239,15 +2243,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) { ...@@ -2239,15 +2243,15 @@ TEST(ScalarFunctionTest, acosFunction_constant) {
//FLOAT //FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before ACOS:%f\n", *((float *)pInput->data)); PRINTF("float before ACOS:%f\n", *((float *)pInput->data));
code = acosFunction(pInput, 1, pOutput); code = acosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after ACOS:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2268,15 +2272,15 @@ TEST(ScalarFunctionTest, acosFunction_column) { ...@@ -2268,15 +2272,15 @@ TEST(ScalarFunctionTest, acosFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before ACOS:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = acosFunction(pInput, 1, pOutput); code = acosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after ACOS:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2287,15 +2291,15 @@ TEST(ScalarFunctionTest, acosFunction_column) { ...@@ -2287,15 +2291,15 @@ TEST(ScalarFunctionTest, acosFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before ACOS:%f\n", *((float *)pInput->data + i)); PRINTF("float before ACOS:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = acosFunction(pInput, 1, pOutput); code = acosFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after ACOS:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ACOS:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2313,15 +2317,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) { ...@@ -2313,15 +2317,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 1; int8_t val_tinyint = 1;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data));
code = atanFunction(pInput, 1, pOutput); code = atanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after ATAN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2329,15 +2333,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) { ...@@ -2329,15 +2333,15 @@ TEST(ScalarFunctionTest, atanFunction_constant) {
//FLOAT //FLOAT
float val_float = 1.00; float val_float = 1.00;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before ATAN:%f\n", *((float *)pInput->data)); PRINTF("float before ATAN:%f\n", *((float *)pInput->data));
code = atanFunction(pInput, 1, pOutput); code = atanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after ATAN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2358,15 +2362,15 @@ TEST(ScalarFunctionTest, atanFunction_column) { ...@@ -2358,15 +2362,15 @@ TEST(ScalarFunctionTest, atanFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before ATAN:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = atanFunction(pInput, 1, pOutput); code = atanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after ATAN:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2377,15 +2381,15 @@ TEST(ScalarFunctionTest, atanFunction_column) { ...@@ -2377,15 +2381,15 @@ TEST(ScalarFunctionTest, atanFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before ATAN:%f\n", *((float *)pInput->data + i)); PRINTF("float before ATAN:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = atanFunction(pInput, 1, pOutput); code = atanFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after ATAN:%f\n", *((double *)pOutput->data + i)); PRINTF("float after ATAN:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2402,15 +2406,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { ...@@ -2402,15 +2406,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data));
code = ceilFunction(pInput, 1, pOutput); code = ceilFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2418,15 +2422,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) { ...@@ -2418,15 +2422,15 @@ TEST(ScalarFunctionTest, ceilFunction_constant) {
//FLOAT //FLOAT
float val_float = 9.5; float val_float = 9.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("float before CEIL:%f\n", *((float *)pInput->data)); PRINTF("float before CEIL:%f\n", *((float *)pInput->data));
code = ceilFunction(pInput, 1, pOutput); code = ceilFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), (float)result); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
PRINTF("float after CEIL:%f\n", *((float *)pOutput->data + i)); PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2446,15 +2450,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) { ...@@ -2446,15 +2450,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before CEIL:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = ceilFunction(pInput, 1, pOutput); code = ceilFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after CEIL:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2465,15 +2469,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) { ...@@ -2465,15 +2469,15 @@ TEST(ScalarFunctionTest, ceilFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before CEIL:%f\n", *((float *)pInput->data + i)); PRINTF("float before CEIL:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = ceilFunction(pInput, 1, pOutput); code = ceilFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), result[i]); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after CEIL:%f\n", *((float *)pOutput->data + i)); PRINTF("float after CEIL:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2490,15 +2494,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) { ...@@ -2490,15 +2494,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data));
code = floorFunction(pInput, 1, pOutput); code = floorFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2506,15 +2510,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) { ...@@ -2506,15 +2510,15 @@ TEST(ScalarFunctionTest, floorFunction_constant) {
//FLOAT //FLOAT
float val_float = 10.5; float val_float = 10.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("float before FLOOR:%f\n", *((float *)pInput->data)); PRINTF("float before FLOOR:%f\n", *((float *)pInput->data));
code = floorFunction(pInput, 1, pOutput); code = floorFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), (float)result); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
PRINTF("float after FLOOR:%f\n", *((float *)pOutput->data + i)); PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2534,15 +2538,15 @@ TEST(ScalarFunctionTest, floorFunction_column) { ...@@ -2534,15 +2538,15 @@ TEST(ScalarFunctionTest, floorFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before FLOOR:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = floorFunction(pInput, 1, pOutput); code = floorFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after FLOOR:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2553,15 +2557,15 @@ TEST(ScalarFunctionTest, floorFunction_column) { ...@@ -2553,15 +2557,15 @@ TEST(ScalarFunctionTest, floorFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before FLOOR:%f\n", *((float *)pInput->data + i)); PRINTF("float before FLOOR:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = floorFunction(pInput, 1, pOutput); code = floorFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), result[i]); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after FLOOR:%f\n", *((float *)pOutput->data + i)); PRINTF("float after FLOOR:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2578,15 +2582,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) { ...@@ -2578,15 +2582,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 10; int8_t val_tinyint = 10;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data));
code = roundFunction(pInput, 1, pOutput); code = roundFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), (int8_t)result); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), (int8_t)result);
PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2594,15 +2598,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) { ...@@ -2594,15 +2598,15 @@ TEST(ScalarFunctionTest, roundFunction_constant) {
//FLOAT //FLOAT
float val_float = 9.5; float val_float = 9.5;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
PRINTF("float before ROUND:%f\n", *((float *)pInput->data)); PRINTF("float before ROUND:%f\n", *((float *)pInput->data));
code = roundFunction(pInput, 1, pOutput); code = roundFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), (float)result); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), (float)result);
PRINTF("float after ROUND:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2622,15 +2626,15 @@ TEST(ScalarFunctionTest, roundFunction_column) { ...@@ -2622,15 +2626,15 @@ TEST(ScalarFunctionTest, roundFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before ROUND:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = roundFunction(pInput, 1, pOutput); code = roundFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((int8_t *)pOutput->data + i), result[i]); ASSERT_EQ(*((int8_t *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)pOutput->data + i)); PRINTF("tiny_int after ROUND:%d\n", *((int8_t *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2641,15 +2645,15 @@ TEST(ScalarFunctionTest, roundFunction_column) { ...@@ -2641,15 +2645,15 @@ TEST(ScalarFunctionTest, roundFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, type, 0, rowNum, false); scltMakeDataBlock(&pOutput, type, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before ROUND:%f\n", *((float *)pInput->data + i)); PRINTF("float before ROUND:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = roundFunction(pInput, 1, pOutput); code = roundFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((float *)pOutput->data + i), result[i]); ASSERT_EQ(*((float *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after ROUND:%f\n", *((float *)pOutput->data + i)); PRINTF("float after ROUND:%f\n", *((float *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2667,15 +2671,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { ...@@ -2667,15 +2671,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) {
//TINYINT //TINYINT
int8_t val_tinyint = 25; int8_t val_tinyint = 25;
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
scltMakeDataBlock(&pInput, type, &val_tinyint, 1, true); scltMakeDataBlock(&pInput, type, &val_tinyint, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data)); PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data));
code = sqrtFunction(pInput, 1, pOutput); code = sqrtFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after SQRT:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2683,15 +2687,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) { ...@@ -2683,15 +2687,15 @@ TEST(ScalarFunctionTest, sqrtFunction_constant) {
//FLOAT //FLOAT
float val_float = 25.0; float val_float = 25.0;
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
scltMakeDataBlock(&pInput, type, &val_float, 1, true); scltMakeDataBlock(&pInput, type, &val_float, rowNum, true);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
PRINTF("float before SQRT:%f\n", *((float *)pInput->data)); PRINTF("float before SQRT:%f\n", *((float *)pInput->data));
code = sqrtFunction(pInput, 1, pOutput); code = sqrtFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after SQRT:%f\n", *((double *)pOutput->data + i)); PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2712,15 +2716,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { ...@@ -2712,15 +2716,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput->data + i) = val_tinyint[i]; *((int8_t *)colDataGetData(pInput->columnData, i)) = val_tinyint[i];
PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)pInput->data + i)); PRINTF("tiny_int before SQRT:%d\n", *((int8_t *)colDataGetData(pInput->columnData, i)));
} }
code = sqrtFunction(pInput, 1, pOutput); code = sqrtFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after SQRT:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
scltDestroyDataBlock(pOutput); scltDestroyDataBlock(pOutput);
...@@ -2731,15 +2735,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) { ...@@ -2731,15 +2735,15 @@ TEST(ScalarFunctionTest, sqrtFunction_column) {
scltMakeDataBlock(&pInput, type, 0, rowNum, false); scltMakeDataBlock(&pInput, type, 0, rowNum, false);
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput->data + i) = val_float[i]; *((float *)colDataGetData(pInput->columnData, i)) = val_float[i];
PRINTF("float before SQRT:%f\n", *((float *)pInput->data + i)); PRINTF("float before SQRT:%f\n", *((float *)colDataGetData(pInput->columnData, i)));
} }
code = sqrtFunction(pInput, 1, pOutput); code = sqrtFunction(pInput, 1, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after SQRT:%f\n", *((double *)pOutput->data + i)); PRINTF("float after SQRT:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(pInput); scltDestroyDataBlock(pInput);
...@@ -2760,7 +2764,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2760,7 +2764,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
int8_t val_tinyint[] = {27, 3}; int8_t val_tinyint[] = {27, 3};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, &val_tinyint[i], 1, true); scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2770,8 +2774,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2770,8 +2774,8 @@ TEST(ScalarFunctionTest, logFunction_constant) {
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2781,7 +2785,7 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2781,7 +2785,7 @@ TEST(ScalarFunctionTest, logFunction_constant) {
float val_float[] = {64.0, 4.0}; float val_float[] = {64.0, 4.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, &val_float[i], 1, true); scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2791,8 +2795,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2791,8 +2795,8 @@ TEST(ScalarFunctionTest, logFunction_constant) {
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2801,9 +2805,9 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2801,9 +2805,9 @@ TEST(ScalarFunctionTest, logFunction_constant) {
//TINYINT AND FLOAT //TINYINT AND FLOAT
int8_t param0 = 64; int8_t param0 = 64;
float param1 = 4.0; float param1 = 4.0;
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, 1, true); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true);
pInput[0] = *input[0]; pInput[0] = *input[0];
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, &param1, 1, true); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, &param1, rowNum, true);
pInput[1] = *input[1]; pInput[1] = *input[1];
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2812,8 +2816,8 @@ TEST(ScalarFunctionTest, logFunction_constant) { ...@@ -2812,8 +2816,8 @@ TEST(ScalarFunctionTest, logFunction_constant) {
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int,float after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
...@@ -2839,7 +2843,8 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -2839,7 +2843,8 @@ TEST(ScalarFunctionTest, logFunction_column) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
*((int8_t *)pInput[i].data + j) = val_tinyint[i][j]; colDataAppend(pInput[i].columnData, j, (const char*) &val_tinyint[i][j], false);
} }
PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), PRINTF("tiny_int before LOG:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0),
*((int8_t *)pInput[i].data + 1), *((int8_t *)pInput[i].data + 1),
...@@ -2850,8 +2855,8 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -2850,8 +2855,8 @@ TEST(ScalarFunctionTest, logFunction_column) {
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2864,19 +2869,19 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -2864,19 +2869,19 @@ TEST(ScalarFunctionTest, logFunction_column) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
*((float *)pInput[i].data + j) = val_float[i][j]; colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false);
} }
PRINTF("float before LOG:%f,%f,%f\n", *((float *)pInput[i].data + 0), PRINTF("float before LOG:%f,%f,%f\n", *((float *)colDataGetData(pInput[i], 0)),
*((float *)pInput[i].data + 1), *((float *)colDataGetData(pInput[i], 1)),
*((float *)pInput[i].data + 2)); *((float *)colDataGetData(pInput[i], 2)));
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2888,12 +2893,14 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -2888,12 +2893,14 @@ TEST(ScalarFunctionTest, logFunction_column) {
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
pInput[0] = *input[0]; pInput[0] = *input[0];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput[0].data + i) = param0[i]; colDataAppend(pInput[0].columnData, i, (const char*) &param0[i], false);
} }
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
pInput[1] = *input[1]; pInput[1] = *input[1];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput[1].data + i) = param1[i]; colDataAppend(pInput[1].columnData, i, (const char*) &param1[i], false);
} }
PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), PRINTF("tiny_int, float before LOG:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0),
*((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
...@@ -2903,8 +2910,8 @@ TEST(ScalarFunctionTest, logFunction_column) { ...@@ -2903,8 +2910,8 @@ TEST(ScalarFunctionTest, logFunction_column) {
code = logFunction(pInput, 2, pOutput); code = logFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int,float after LOG:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int,float after LOG:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
...@@ -2927,7 +2934,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2927,7 +2934,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
int8_t val_tinyint[] = {2, 4}; int8_t val_tinyint[] = {2, 4};
type = TSDB_DATA_TYPE_TINYINT; type = TSDB_DATA_TYPE_TINYINT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, &val_tinyint[i], 1, true); scltMakeDataBlock(&input[i], type, &val_tinyint[i], rowNum, true);
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2937,8 +2944,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2937,8 +2944,8 @@ TEST(ScalarFunctionTest, powFunction_constant) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2948,7 +2955,7 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2948,7 +2955,7 @@ TEST(ScalarFunctionTest, powFunction_constant) {
float val_float[] = {2.0, 4.0}; float val_float[] = {2.0, 4.0};
type = TSDB_DATA_TYPE_FLOAT; type = TSDB_DATA_TYPE_FLOAT;
for (int32_t i = 0; i < 2; ++i) { for (int32_t i = 0; i < 2; ++i) {
scltMakeDataBlock(&input[i], type, &val_float[i], 1, true); scltMakeDataBlock(&input[i], type, &val_float[i], rowNum, true);
pInput[i] = *input[i]; pInput[i] = *input[i];
} }
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2958,8 +2965,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2958,8 +2965,8 @@ TEST(ScalarFunctionTest, powFunction_constant) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("float after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -2968,9 +2975,9 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2968,9 +2975,9 @@ TEST(ScalarFunctionTest, powFunction_constant) {
//TINYINT AND FLOAT //TINYINT AND FLOAT
int8_t param0 = 2; int8_t param0 = 2;
float param1 = 4.0; float param1 = 4.0;
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, 1, true); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, &param0, rowNum, true);
pInput[0] = *input[0]; pInput[0] = *input[0];
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, &param1, 1, true); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, &param1, rowNum, true);
pInput[1] = *input[1]; pInput[1] = *input[1];
scltMakeDataBlock(&pOutput, otype, 0, rowNum, false); scltMakeDataBlock(&pOutput, otype, 0, rowNum, false);
...@@ -2979,8 +2986,8 @@ TEST(ScalarFunctionTest, powFunction_constant) { ...@@ -2979,8 +2986,8 @@ TEST(ScalarFunctionTest, powFunction_constant) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result);
PRINTF("tiny_int,float after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
...@@ -3006,7 +3013,8 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3006,7 +3013,8 @@ TEST(ScalarFunctionTest, powFunction_column) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
*((int8_t *)pInput[i].data + j) = val_tinyint[i][j]; colDataAppend(pInput[i].columnData, i, (const char*) &val_tinyint[i][j], false);
} }
PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0), PRINTF("tiny_int before POW:%d,%d,%d\n", *((int8_t *)pInput[i].data + 0),
*((int8_t *)pInput[i].data + 1), *((int8_t *)pInput[i].data + 1),
...@@ -3017,8 +3025,8 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3017,8 +3025,8 @@ TEST(ScalarFunctionTest, powFunction_column) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
...@@ -3032,7 +3040,7 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3032,7 +3040,7 @@ TEST(ScalarFunctionTest, powFunction_column) {
scltMakeDataBlock(&input[i], type, 0, rowNum, false); scltMakeDataBlock(&input[i], type, 0, rowNum, false);
pInput[i] = *input[i]; pInput[i] = *input[i];
for (int32_t j = 0; j < rowNum; ++j) { for (int32_t j = 0; j < rowNum; ++j) {
*((float *)pInput[i].data + j) = val_float[i][j]; colDataAppend(pInput[i].columnData, j, (const char*) &val_float[i][j], false);
} }
PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0), PRINTF("float before POW:%f,%f,%f\n", *((float *)pInput[i].data + 0),
*((float *)pInput[i].data + 1), *((float *)pInput[i].data + 1),
...@@ -3043,8 +3051,8 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3043,8 +3051,8 @@ TEST(ScalarFunctionTest, powFunction_column) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("float after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
scltDestroyDataBlock(input[1]); scltDestroyDataBlock(input[1]);
...@@ -3056,12 +3064,13 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3056,12 +3064,13 @@ TEST(ScalarFunctionTest, powFunction_column) {
scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false); scltMakeDataBlock(&input[0], TSDB_DATA_TYPE_TINYINT, 0, rowNum, false);
pInput[0] = *input[0]; pInput[0] = *input[0];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((int8_t *)pInput[0].data + i) = param0[i]; colDataAppend(pInput[0].columnData, i, (const char*) &param0[i], false);
} }
scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false); scltMakeDataBlock(&input[1], TSDB_DATA_TYPE_FLOAT, 0, rowNum, false);
pInput[1] = *input[1]; pInput[1] = *input[1];
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
*((float *)pInput[1].data + i) = param1[i]; colDataAppend(pInput[1].columnData, i, (const char*) &param1[i], false);
} }
PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0), PRINTF("tiny_int, float before POW:{%d,%f}, {%d,%f}, {%d,%f}\n", *((int8_t *)pInput[0].data + 0), *((float *)pInput[1].data + 0),
*((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1), *((int8_t *)pInput[0].data + 1), *((float *)pInput[1].data + 1),
...@@ -3071,8 +3080,8 @@ TEST(ScalarFunctionTest, powFunction_column) { ...@@ -3071,8 +3080,8 @@ TEST(ScalarFunctionTest, powFunction_column) {
code = powFunction(pInput, 2, pOutput); code = powFunction(pInput, 2, pOutput);
ASSERT_EQ(code, TSDB_CODE_SUCCESS); ASSERT_EQ(code, TSDB_CODE_SUCCESS);
for (int32_t i = 0; i < rowNum; ++i) { for (int32_t i = 0; i < rowNum; ++i) {
ASSERT_EQ(*((double *)pOutput->data + i), result[i]); ASSERT_EQ(*((double *)colDataGetData(pOutput->columnData, i)), result[i]);
PRINTF("tiny_int,float after POW:%f\n", *((double *)pOutput->data + i)); PRINTF("tiny_int,float after POW:%f\n", *((double *)colDataGetData(pOutput->columnData, i)));
} }
scltDestroyDataBlock(input[0]); scltDestroyDataBlock(input[0]);
......
...@@ -72,6 +72,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in ...@@ -72,6 +72,7 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
if (pTask->sinkType == TASK_SINK__TABLE) { if (pTask->sinkType == TASK_SINK__TABLE) {
// //
} else if (pTask->sinkType == TASK_SINK__SMA) { } else if (pTask->sinkType == TASK_SINK__SMA) {
pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes);
// //
} else if (pTask->sinkType == TASK_SINK__FETCH) { } else if (pTask->sinkType == TASK_SINK__FETCH) {
// //
...@@ -205,9 +206,16 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) { ...@@ -205,9 +206,16 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) {
if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1; if (tEncodeCStr(pEncoder, pTask->exec.qmsg) < 0) return -1;
} }
if (pTask->sinkType != TASK_SINK__NONE) { if (pTask->sinkType == TASK_SINK__TABLE) {
// TODO: wrap
if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1; if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__SMA) {
if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__FETCH) {
if (tEncodeI8(pEncoder, pTask->fetchSink.reserved) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__SHOW) {
if (tEncodeI8(pEncoder, pTask->showSink.reserved) < 0) return -1;
} else {
ASSERT(pTask->sinkType == TASK_SINK__NONE);
} }
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
...@@ -244,8 +252,16 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) { ...@@ -244,8 +252,16 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) {
if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1; if (tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg) < 0) return -1;
} }
if (pTask->sinkType != TASK_SINK__NONE) { if (pTask->sinkType == TASK_SINK__TABLE) {
if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1; if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__SMA) {
if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__FETCH) {
if (tDecodeI8(pDecoder, &pTask->fetchSink.reserved) < 0) return -1;
} else if (pTask->sinkType == TASK_SINK__SHOW) {
if (tDecodeI8(pDecoder, &pTask->showSink.reserved) < 0) return -1;
} else {
ASSERT(pTask->sinkType == TASK_SINK__NONE);
} }
if (pTask->dispatchType == TASK_DISPATCH__INPLACE) { if (pTask->dispatchType == TASK_DISPATCH__INPLACE) {
......
...@@ -8,6 +8,8 @@ target_sources(tdb ...@@ -8,6 +8,8 @@ target_sources(tdb
"src/db/tdbBtree.c" "src/db/tdbBtree.c"
"src/db/tdbDb.c" "src/db/tdbDb.c"
"src/db/tdbEnv.c" "src/db/tdbEnv.c"
"src/db/tdbTxn.c"
"src/db/tdbOs.c"
"src/page/tdbPage.c" "src/page/tdbPage.c"
"src/page/tdbPageL.c" "src/page/tdbPageL.c"
) )
......
...@@ -22,43 +22,6 @@ ...@@ -22,43 +22,6 @@
extern "C" { extern "C" {
#endif #endif
// typedef struct STDb TDB;
// typedef struct STDbEnv TENV;
// typedef struct STDbCurosr TDBC;
// typedef int32_t pgsz_t;
// typedef int32_t cachesz_t;
// typedef int (*TdbKeyCmprFn)(int keyLen1, const void *pKey1, int keyLen2, const void *pKey2);
// // TEVN
// int tdbEnvCreate(TENV **ppEnv, const char *rootDir);
// int tdbEnvOpen(TENV *ppEnv);
// int tdbEnvClose(TENV *pEnv);
// int tdbEnvSetCache(TENV *pEnv, pgsz_t pgSize, cachesz_t cacheSize);
// pgsz_t tdbEnvGetPageSize(TENV *pEnv);
// cachesz_t tdbEnvGetCacheSize(TENV *pEnv);
// int tdbEnvBeginTxn(TENV *pEnv);
// int tdbEnvCommit(TENV *pEnv);
// // TDB
// int tdbCreate(TDB **ppDb);
// int tdbOpen(TDB *pDb, const char *fname, const char *dbname, TENV *pEnv);
// int tdbClose(TDB *pDb);
// int tdbDrop(TDB *pDb);
// int tdbSetKeyLen(TDB *pDb, int klen);
// int tdbSetValLen(TDB *pDb, int vlen);
// int tdbSetDup(TDB *pDb, int dup);
// int tdbSetCmprFunc(TDB *pDb, TdbKeyCmprFn fn);
// int tdbGetKeyLen(TDB *pDb);
// int tdbGetValLen(TDB *pDb);
// int tdbGetDup(TDB *pDb);
// int tdbInsert(TDB *pDb, const void *pKey, int nKey, const void *pData, int nData);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -67,7 +67,7 @@ typedef struct { ...@@ -67,7 +67,7 @@ typedef struct {
u8 *pTmpSpace; u8 *pTmpSpace;
} SCellDecoder; } SCellDecoder;
static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst); static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst);
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeOpenImpl(SBTree *pBt);
static int tdbBtreeZeroPage(SPage *pPage, void *arg); static int tdbBtreeZeroPage(SPage *pPage, void *arg);
...@@ -75,10 +75,10 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg); ...@@ -75,10 +75,10 @@ static int tdbBtreeInitPage(SPage *pPage, void *arg);
static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell,
int *szCell); int *szCell);
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder);
static int tdbBtreeBalance(SBTC *pCur); static int tdbBtreeBalance(SBTC *pBtc);
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell); static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell);
static int tdbBtcMoveToNext(SBTC *pBtc); static int tdbBtcMoveToNext(SBTC *pBtc);
static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno); static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno);
static int tdbBtcMoveUpward(SBTC *pBtc); static int tdbBtcMoveUpward(SBTC *pBtc);
int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) {
...@@ -87,7 +87,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S ...@@ -87,7 +87,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S
*ppBt = NULL; *ppBt = NULL;
pBt = (SBTree *)calloc(1, sizeof(*pBt)); pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt));
if (pBt == NULL) { if (pBt == NULL) {
return -1; return -1;
} }
...@@ -121,7 +121,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S ...@@ -121,7 +121,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, S
// TODO: pBt->root // TODO: pBt->root
ret = tdbBtreeOpenImpl(pBt); ret = tdbBtreeOpenImpl(pBt);
if (ret < 0) { if (ret < 0) {
free(pBt); tdbOsFree(pBt);
return -1; return -1;
} }
...@@ -134,7 +134,7 @@ int tdbBtreeClose(SBTree *pBt) { ...@@ -134,7 +134,7 @@ int tdbBtreeClose(SBTree *pBt) {
return 0; return 0;
} }
int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, int vLen) { int tdbBtCursorInsert(SBTC *pBtc, const void *pKey, int kLen, const void *pVal, int vLen) {
int ret; int ret;
int idx; int idx;
SPager *pPager; SPager *pPager;
...@@ -143,20 +143,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, ...@@ -143,20 +143,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
int cret; int cret;
SBTree *pBt; SBTree *pBt;
ret = tdbBtCursorMoveTo(pCur, pKey, kLen, &cret); ret = tdbBtCursorMoveTo(pBtc, pKey, kLen, &cret);
if (ret < 0) { if (ret < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
} }
if (pCur->idx == -1) { if (pBtc->idx == -1) {
ASSERT(TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0); ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0);
idx = 0; idx = 0;
} else { } else {
if (cret > 0) { if (cret > 0) {
idx = pCur->idx + 1; idx = pBtc->idx + 1;
} else if (cret < 0) { } else if (cret < 0) {
idx = pCur->idx; idx = pBtc->idx;
} else { } else {
/* TODO */ /* TODO */
ASSERT(0); ASSERT(0);
...@@ -164,9 +164,9 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, ...@@ -164,9 +164,9 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
} }
// TODO: refact code here // TODO: refact code here
pBt = pCur->pBt; pBt = pBtc->pBt;
if (!pBt->pTmp) { if (!pBt->pTmp) {
pBt->pTmp = (u8 *)malloc(pBt->pageSize); pBt->pTmp = (u8 *)tdbOsMalloc(pBt->pageSize);
if (pBt->pTmp == NULL) { if (pBt->pTmp == NULL) {
return -1; return -1;
} }
...@@ -175,20 +175,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal, ...@@ -175,20 +175,20 @@ int tdbBtCursorInsert(SBTC *pCur, const void *pKey, int kLen, const void *pVal,
pCell = pBt->pTmp; pCell = pBt->pTmp;
// Encode the cell // Encode the cell
ret = tdbBtreeEncodeCell(pCur->pPage, pKey, kLen, pVal, vLen, pCell, &szCell); ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pVal, vLen, pCell, &szCell);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
// Insert the cell to the index // Insert the cell to the index
ret = tdbPageInsertCell(pCur->pPage, idx, pCell, szCell, 0); ret = tdbPageInsertCell(pBtc->pPage, idx, pCell, szCell, 0);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
// If page is overflow, balance the tree // If page is overflow, balance the tree
if (pCur->pPage->nOverflow > 0) { if (pBtc->pPage->nOverflow > 0) {
ret = tdbBtreeBalance(pCur); ret = tdbBtreeBalance(pBtc);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
...@@ -226,30 +226,30 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen ...@@ -226,30 +226,30 @@ int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen
return 0; return 0;
} }
static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) { static int tdbBtCursorMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
int ret; int ret;
SBTree *pBt; SBTree *pBt;
SPager *pPager; SPager *pPager;
pBt = pCur->pBt; pBt = pBtc->pBt;
pPager = pBt->pPager; pPager = pBt->pPager;
if (pCur->iPage < 0) { if (pBtc->iPage < 0) {
ASSERT(pCur->iPage == -1); ASSERT(pBtc->iPage == -1);
ASSERT(pCur->idx == -1); ASSERT(pBtc->idx == -1);
// Move from the root // Move from the root
ret = tdbPagerFetchPage(pPager, pBt->root, &(pCur->pPage), tdbBtreeInitPage, pBt); ret = tdbPagerFetchPage(pPager, pBt->root, &(pBtc->pPage), tdbBtreeInitPage, pBt);
if (ret < 0) { if (ret < 0) {
ASSERT(0); ASSERT(0);
return -1; return -1;
} }
pCur->iPage = 0; pBtc->iPage = 0;
if (TDB_PAGE_TOTAL_CELLS(pCur->pPage) == 0) { if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) {
// Current page is empty // Current page is empty
// ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pCur->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF)); // ASSERT(TDB_FLAG_IS(TDB_PAGE_FLAGS(pBtc->pPage), TDB_BTREE_ROOT | TDB_BTREE_LEAF));
return 0; return 0;
} }
...@@ -259,7 +259,7 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) ...@@ -259,7 +259,7 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst)
SPage *pPage; SPage *pPage;
SCellDecoder cd = {0}; SCellDecoder cd = {0};
pPage = pCur->pPage; pPage = pBtc->pPage;
nCells = TDB_PAGE_TOTAL_CELLS(pPage); nCells = TDB_PAGE_TOTAL_CELLS(pPage);
lidx = 0; lidx = 0;
ridx = nCells - 1; ridx = nCells - 1;
...@@ -297,22 +297,22 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst) ...@@ -297,22 +297,22 @@ static int tdbBtCursorMoveTo(SBTC *pCur, const void *pKey, int kLen, int *pCRst)
u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); u8 flags = TDB_BTREE_PAGE_GET_FLAGS(pPage);
u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags); u8 leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
if (leaf) { if (leaf) {
pCur->idx = midx; pBtc->idx = midx;
*pCRst = c; *pCRst = c;
break; break;
} else { } else {
if (c <= 0) { if (c <= 0) {
pCur->idx = midx; pBtc->idx = midx;
tdbBtcMoveDownward(pCur, cd.pgno); tdbBtcMoveDownward(pBtc, cd.pgno);
} else { } else {
pCur->idx = midx + 1; pBtc->idx = midx + 1;
if (midx == nCells - 1) { if (midx == nCells - 1) {
/* Move to right-most child */ /* Move to right-most child */
tdbBtcMoveDownward(pCur, ((SIntHdr *)pCur->pPage->pData)->pgno); tdbBtcMoveDownward(pBtc, ((SIntHdr *)pBtc->pPage->pData)->pgno);
} else { } else {
pCell = tdbPageGetCell(pPage, pCur->idx); pCell = tdbPageGetCell(pPage, pBtc->idx);
tdbBtreeDecodeCell(pPage, pCell, &cd); tdbBtreeDecodeCell(pPage, pCell, &cd);
tdbBtcMoveDownward(pCur, cd.pgno); tdbBtcMoveDownward(pBtc, cd.pgno);
} }
} }
} }
...@@ -550,7 +550,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ...@@ -550,7 +550,7 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) { if (sIdx + i < TDB_PAGE_TOTAL_CELLS(pParent)) {
pCell = tdbPageGetCell(pParent, sIdx + i); pCell = tdbPageGetCell(pParent, sIdx + i);
szDivCell[i] = tdbBtreeCellSize(pParent, pCell); szDivCell[i] = tdbBtreeCellSize(pParent, pCell);
pDivCell[i] = malloc(szDivCell[i]); pDivCell[i] = tdbOsMalloc(szDivCell[i]);
memcpy(pDivCell[i], pCell, szDivCell[i]); memcpy(pDivCell[i], pCell, szDivCell[i]);
} }
...@@ -740,13 +740,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ...@@ -740,13 +740,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
tdbBtreeDecodeCell(pPage, pCell, &cd); tdbBtreeDecodeCell(pPage, pCell, &cd);
// TODO: pCell here may be inserted as an overflow cell, handle it // TODO: pCell here may be inserted as an overflow cell, handle it
SCell *pNewCell = malloc(cd.kLen + 9); SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
int szNewCell; int szNewCell;
SPgno pgno; SPgno pgno;
pgno = TDB_PAGE_PGNO(pNews[iNew]); pgno = TDB_PAGE_PGNO(pNews[iNew]);
tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell); tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell);
tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0); tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
free(pNewCell); tdbOsFree(pNewCell);
} }
// move to next new page // move to next new page
...@@ -798,14 +798,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) { ...@@ -798,14 +798,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (pDivCell[i]) { if (pDivCell[i]) {
free(pDivCell[i]); tdbOsFree(pDivCell[i]);
} }
} }
return 0; return 0;
} }
static int tdbBtreeBalance(SBTC *pCur) { static int tdbBtreeBalance(SBTC *pBtc) {
int iPage; int iPage;
SPage *pParent; SPage *pParent;
SPage *pPage; SPage *pPage;
...@@ -816,8 +816,8 @@ static int tdbBtreeBalance(SBTC *pCur) { ...@@ -816,8 +816,8 @@ static int tdbBtreeBalance(SBTC *pCur) {
// Main loop to balance the BTree // Main loop to balance the BTree
for (;;) { for (;;) {
iPage = pCur->iPage; iPage = pBtc->iPage;
pPage = pCur->pPage; pPage = pBtc->pPage;
flags = TDB_BTREE_PAGE_GET_FLAGS(pPage); flags = TDB_BTREE_PAGE_GET_FLAGS(pPage);
leaf = TDB_BTREE_PAGE_IS_LEAF(flags); leaf = TDB_BTREE_PAGE_IS_LEAF(flags);
root = TDB_BTREE_PAGE_IS_ROOT(flags); root = TDB_BTREE_PAGE_IS_ROOT(flags);
...@@ -833,27 +833,27 @@ static int tdbBtreeBalance(SBTC *pCur) { ...@@ -833,27 +833,27 @@ static int tdbBtreeBalance(SBTC *pCur) {
// ignore the case of empty // ignore the case of empty
if (pPage->nOverflow == 0) break; if (pPage->nOverflow == 0) break;
ret = tdbBtreeBalanceDeeper(pCur->pBt, pPage, &(pCur->pgStack[1])); ret = tdbBtreeBalanceDeeper(pBtc->pBt, pPage, &(pBtc->pgStack[1]));
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
pCur->idx = 0; pBtc->idx = 0;
pCur->idxStack[0] = 0; pBtc->idxStack[0] = 0;
pCur->pgStack[0] = pCur->pPage; pBtc->pgStack[0] = pBtc->pPage;
pCur->iPage = 1; pBtc->iPage = 1;
pCur->pPage = pCur->pgStack[1]; pBtc->pPage = pBtc->pgStack[1];
} else { } else {
// Generalized balance step // Generalized balance step
pParent = pCur->pgStack[iPage - 1]; pParent = pBtc->pgStack[iPage - 1];
ret = tdbBtreeBalanceNonRoot(pCur->pBt, pParent, pCur->idxStack[pCur->iPage - 1]); ret = tdbBtreeBalanceNonRoot(pBtc->pBt, pParent, pBtc->idxStack[pBtc->iPage - 1]);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
} }
pCur->iPage--; pBtc->iPage--;
pCur->pPage = pCur->pgStack[pCur->iPage]; pBtc->pPage = pBtc->pgStack[pBtc->iPage];
} }
} }
...@@ -1050,11 +1050,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) { ...@@ -1050,11 +1050,11 @@ static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
#endif #endif
int tdbBtcOpen(SBTC *pCur, SBTree *pBt) { int tdbBtcOpen(SBTC *pBtc, SBTree *pBt) {
pCur->pBt = pBt; pBtc->pBt = pBt;
pCur->iPage = -1; pBtc->iPage = -1;
pCur->pPage = NULL; pBtc->pPage = NULL;
pCur->idx = -1; pBtc->idx = -1;
return 0; return 0;
} }
...@@ -1262,16 +1262,16 @@ int tdbBtcClose(SBTC *pBtc) { ...@@ -1262,16 +1262,16 @@ int tdbBtcClose(SBTC *pBtc) {
return 0; return 0;
} }
static int tdbBtcMoveDownward(SBTC *pCur, SPgno pgno) { static int tdbBtcMoveDownward(SBTC *pBtc, SPgno pgno) {
int ret; int ret;
pCur->pgStack[pCur->iPage] = pCur->pPage; pBtc->pgStack[pBtc->iPage] = pBtc->pPage;
pCur->idxStack[pCur->iPage] = pCur->idx; pBtc->idxStack[pBtc->iPage] = pBtc->idx;
pCur->iPage++; pBtc->iPage++;
pCur->pPage = NULL; pBtc->pPage = NULL;
pCur->idx = -1; pBtc->idx = -1;
ret = tdbPagerFetchPage(pCur->pBt->pPager, pgno, &pCur->pPage, tdbBtreeInitPage, pCur->pBt); ret = tdbPagerFetchPage(pBtc->pBt->pPager, pgno, &pBtc->pPage, tdbBtreeInitPage, pBtc->pBt);
if (ret < 0) { if (ret < 0) {
ASSERT(0); ASSERT(0);
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "tdbInt.h" #include "tdbInt.h"
struct STDB { struct STDB {
STEnv *pEnv; TENV *pEnv;
SBTree *pBt; SBTree *pBt;
}; };
...@@ -24,8 +24,8 @@ struct STDBC { ...@@ -24,8 +24,8 @@ struct STDBC {
SBTC btc; SBTC btc;
}; };
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb) { int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb) {
STDB *pDb; TDB *pDb;
SPager *pPager; SPager *pPager;
int ret; int ret;
char fFullName[TDB_FILENAME_LEN]; char fFullName[TDB_FILENAME_LEN];
...@@ -34,7 +34,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF ...@@ -34,7 +34,7 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
*ppDb = NULL; *ppDb = NULL;
pDb = (STDB *)calloc(1, sizeof(*pDb)); pDb = (TDB *)tdbOsCalloc(1, sizeof(*pDb));
if (pDb == NULL) { if (pDb == NULL) {
return -1; return -1;
} }
...@@ -63,17 +63,17 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF ...@@ -63,17 +63,17 @@ int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprF
return 0; return 0;
} }
int tdbDbClose(STDB *pDb) { int tdbDbClose(TDB *pDb) {
// TODO // TODO
return 0; return 0;
} }
int tdbDbDrop(STDB *pDb) { int tdbDbDrop(TDB *pDb) {
// TODO // TODO
return 0; return 0;
} }
int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) { int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen) {
SBTC btc; SBTC btc;
SBTC *pCur; SBTC *pCur;
int ret; int ret;
...@@ -92,16 +92,16 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v ...@@ -92,16 +92,16 @@ int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int v
return 0; return 0;
} }
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) { int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen); return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
} }
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) {
int ret; int ret;
STDBC *pDbc = NULL; TDBC *pDbc = NULL;
*ppDbc = NULL; *ppDbc = NULL;
pDbc = malloc(sizeof(*pDbc)); pDbc = (TDBC *)tdbOsMalloc(sizeof(*pDbc));
if (pDbc == NULL) { if (pDbc == NULL) {
return -1; return -1;
} }
...@@ -120,13 +120,13 @@ int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) { ...@@ -120,13 +120,13 @@ int tdbDbcOpen(STDB *pDb, STDBC **ppDbc) {
return 0; return 0;
} }
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen); return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen);
} }
int tdbDbcClose(STDBC *pDbc) { int tdbDbcClose(TDBC *pDbc) {
if (pDbc) { if (pDbc) {
free(pDbc); tdbOsFree(pDbc);
} }
return 0; return 0;
......
...@@ -15,24 +15,24 @@ ...@@ -15,24 +15,24 @@
#include "tdbInt.h" #include "tdbInt.h"
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) { int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) {
STEnv *pEnv; TENV *pEnv;
int dsize; int dsize;
int zsize; int zsize;
u8 *pPtr; u8 *pPtr;
int ret; int ret;
*ppEnv = NULL; *ppEnv = NULL;
dsize = strlen(rootDir); dsize = strlen(rootDir);
zsize = sizeof(*pEnv) + dsize * 2 + strlen(TDB_JOURNAL_NAME) + 3; zsize = sizeof(*pEnv) + dsize * 2 + strlen(TDB_JOURNAL_NAME) + 3;
pPtr = (uint8_t *)calloc(1, zsize); pPtr = (uint8_t *)tdbOsCalloc(1, zsize);
if (pPtr == NULL) { if (pPtr == NULL) {
return -1; return -1;
} }
pEnv = (STEnv *)pPtr; pEnv = (TENV *)pPtr;
pPtr += sizeof(*pEnv); pPtr += sizeof(*pEnv);
// pEnv->rootDir // pEnv->rootDir
pEnv->rootDir = pPtr; pEnv->rootDir = pPtr;
...@@ -59,12 +59,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv) ...@@ -59,12 +59,12 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv)
return 0; return 0;
} }
int tdbEnvClose(STEnv *pEnv) { int tdbEnvClose(TENV *pEnv) {
// TODO // TODO
return 0; return 0;
} }
SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname) { SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) {
// TODO // TODO
return NULL; return NULL;
} }
\ No newline at end of file
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdbInt.h"
#ifndef TDB_FOR_TDENGINE
// tdbOsRead
i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes) {
i64 nRead = 0;
i64 iRead = 0;
u8 *pBuf = (u8 *)pData;
while (nBytes > 0) {
iRead = read(fd, pBuf, nBytes);
if (iRead < 0) {
if (errno == EINTR) {
continue;
} else {
return -1;
}
} else if (iRead == 0) {
break;
}
nRead += iRead;
pBuf += iRead;
nBytes -= iRead;
}
return nRead;
}
// tdbOsPRead
i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset) {
i64 nRead = 0;
i64 iRead = 0;
i64 iOffset = offset;
u8 *pBuf = (u8 *)pData;
while (nBytes > 0) {
iRead = pread(fd, pBuf, nBytes, iOffset);
if (iRead < 0) {
if (errno == EINTR) {
continue;
} else {
return -1;
}
} else if (iRead == 0) {
break;
}
nRead += iRead;
pBuf += iRead;
iOffset += iRead;
nBytes -= iRead;
}
return nRead;
}
// tdbOsWrite
i64 tdbOsWrite(tdb_fd_t fd, const void *pData, i64 nBytes) {
i64 nWrite = 0;
i64 iWrite = 0;
u8 *pBuf = (u8 *)pData;
while (nBytes > 0) {
iWrite = write(fd, pBuf, nBytes);
if (iWrite < 0) {
if (errno == EINTR) {
continue;
}
return -1;
}
nWrite += iWrite;
pBuf += iWrite;
nBytes -= iWrite;
}
return nWrite;
}
#endif
\ No newline at end of file
...@@ -15,16 +15,16 @@ ...@@ -15,16 +15,16 @@
#include "tdbInt.h" #include "tdbInt.h"
struct SPCache { struct SPCache {
int pageSize; int pageSize;
int cacheSize; int cacheSize;
pthread_mutex_t mutex; tdb_mutex_t mutex;
int nFree; int nFree;
SPage *pFree; SPage *pFree;
int nPage; int nPage;
int nHash; int nHash;
SPage **pgHash; SPage **pgHash;
int nRecyclable; int nRecyclable;
SPage lru; SPage lru;
}; };
#define PCACHE_PAGE_HASH(pPgid) \ #define PCACHE_PAGE_HASH(pPgid) \
...@@ -63,7 +63,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { ...@@ -63,7 +63,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
void *pPtr; void *pPtr;
SPage *pPgHdr; SPage *pPgHdr;
pCache = (SPCache *)calloc(1, sizeof(*pCache)); pCache = (SPCache *)tdbOsCalloc(1, sizeof(*pCache));
if (pCache == NULL) { if (pCache == NULL) {
return -1; return -1;
} }
...@@ -72,7 +72,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { ...@@ -72,7 +72,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
pCache->cacheSize = cacheSize; pCache->cacheSize = cacheSize;
if (tdbPCacheOpenImpl(pCache) < 0) { if (tdbPCacheOpenImpl(pCache) < 0) {
free(pCache); tdbOsFree(pCache);
return -1; return -1;
} }
...@@ -116,13 +116,13 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) { ...@@ -116,13 +116,13 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage) {
} }
} }
static void tdbPCacheInitLock(SPCache *pCache) { pthread_mutex_init(&(pCache->mutex), NULL); } static void tdbPCacheInitLock(SPCache *pCache) { tdbMutexInit(&(pCache->mutex), NULL); }
static void tdbPCacheClearLock(SPCache *pCache) { pthread_mutex_destroy(&(pCache->mutex)); } static void tdbPCacheClearLock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); }
static void tdbPCacheLock(SPCache *pCache) { pthread_mutex_lock(&(pCache->mutex)); } static void tdbPCacheLock(SPCache *pCache) { tdbMutexLock(&(pCache->mutex)); }
static void tdbPCacheUnlock(SPCache *pCache) { pthread_mutex_unlock(&(pCache->mutex)); } static void tdbPCacheUnlock(SPCache *pCache) { tdbMutexDestroy(&(pCache->mutex)); }
static bool tdbPCacheLocked(SPCache *pCache) { static bool tdbPCacheLocked(SPCache *pCache) {
assert(0); assert(0);
...@@ -268,7 +268,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { ...@@ -268,7 +268,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
// Open the hash table // Open the hash table
pCache->nPage = 0; pCache->nPage = 0;
pCache->nHash = pCache->cacheSize; pCache->nHash = pCache->cacheSize;
pCache->pgHash = (SPage **)calloc(pCache->nHash, sizeof(SPage *)); pCache->pgHash = (SPage **)tdbOsCalloc(pCache->nHash, sizeof(SPage *));
if (pCache->pgHash == NULL) { if (pCache->pgHash == NULL) {
// TODO // TODO
return -1; return -1;
......
...@@ -20,14 +20,12 @@ struct SPager { ...@@ -20,14 +20,12 @@ struct SPager {
char *jFileName; char *jFileName;
int pageSize; int pageSize;
uint8_t fid[TDB_FILE_ID_LEN]; uint8_t fid[TDB_FILE_ID_LEN];
int fd; tdb_fd_t fd;
int jfd; tdb_fd_t jfd;
SPCache *pCache; SPCache *pCache;
SPgno dbFileSize; SPgno dbFileSize;
SPgno dbOrigSize; SPgno dbOrigSize;
int nDirty;
SPage *pDirty; SPage *pDirty;
SPage *pDirtyTail;
u8 inTran; u8 inTran;
}; };
...@@ -46,6 +44,8 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct") ...@@ -46,6 +44,8 @@ TDB_STATIC_ASSERT(sizeof(SFileHdr) == 128, "Size of file header is not correct")
static int tdbPagerReadPage(SPager *pPager, SPage *pPage); static int tdbPagerReadPage(SPager *pPager, SPage *pPage);
static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno); static int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg); static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage *, void *), void *arg);
static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage);
static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage);
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
uint8_t *pPtr; uint8_t *pPtr;
...@@ -60,7 +60,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { ...@@ -60,7 +60,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
zsize = sizeof(*pPager) /* SPager */ zsize = sizeof(*pPager) /* SPager */
+ fsize + 1 /* dbFileName */ + fsize + 1 /* dbFileName */
+ fsize + 8 + 1; /* jFileName */ + fsize + 8 + 1; /* jFileName */
pPtr = (uint8_t *)calloc(1, zsize); pPtr = (uint8_t *)tdbOsCalloc(1, zsize);
if (pPtr == NULL) { if (pPtr == NULL) {
return -1; return -1;
} }
...@@ -80,7 +80,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { ...@@ -80,7 +80,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
// pPager->pCache // pPager->pCache
pPager->pCache = pCache; pPager->pCache = pCache;
pPager->fd = open(pPager->dbFileName, O_RDWR | O_CREAT, 0755); pPager->fd = tdbOsOpen(pPager->dbFileName, TDB_O_CREAT | TDB_O_RDWR, 0755);
if (pPager->fd < 0) { if (pPager->fd < 0) {
return -1; return -1;
} }
...@@ -90,7 +90,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { ...@@ -90,7 +90,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
return -1; return -1;
} }
pPager->jfd = -1; // pPager->jfd = -1;
pPager->pageSize = tdbPCacheGetPageSize(pCache); pPager->pageSize = tdbPCacheGetPageSize(pCache);
*ppPager = pPager; *ppPager = pPager;
...@@ -140,14 +140,25 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) { ...@@ -140,14 +140,25 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
} }
} }
if (pPage->isDirty == 0) { if (pPage->isDirty) return 0;
pPage->isDirty = 1;
// TODO: add the page to the dirty list
// TODO: write the page to the journal // Set page as dirty
if (1 /*actually load from the file*/) { pPage->isDirty = 1;
// Add page to dirty list
// TODO: sort the list according to the page number
pPage->pDirtyNext = pPager->pDirty;
pPager->pDirty = pPage;
// Write page to journal
if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize) {
ret = tdbPagerWritePageToJournal(pPager, pPage);
if (ret < 0) {
ASSERT(0);
return -1;
} }
} }
return 0; return 0;
} }
...@@ -157,7 +168,7 @@ int tdbPagerBegin(SPager *pPager) { ...@@ -157,7 +168,7 @@ int tdbPagerBegin(SPager *pPager) {
} }
// Open the journal // Open the journal
pPager->jfd = open(pPager->jFileName, O_RDWR | O_CREAT, 0755); pPager->jfd = tdbOsOpen(pPager->jFileName, TDB_O_CREAT | TDB_O_RDWR, 0755);
if (pPager->jfd < 0) { if (pPager->jfd < 0) {
return -1; return -1;
} }
...@@ -170,7 +181,37 @@ int tdbPagerBegin(SPager *pPager) { ...@@ -170,7 +181,37 @@ int tdbPagerBegin(SPager *pPager) {
} }
int tdbPagerCommit(SPager *pPager) { int tdbPagerCommit(SPager *pPager) {
// TODO SPage *pPage;
int ret;
// Begin commit
{
// TODO: Sync the journal file (Here or when write ?)
}
for (;;) {
pPage = pPager->pDirty;
if (pPage == NULL) break;
ret = tdbPagerWritePageToDB(pPager, pPage);
if (ret < 0) {
ASSERT(0);
return -1;
}
pPager->pDirty = pPage->pDirtyNext;
pPage->pDirtyNext = NULL;
// TODO: release the page
}
tdbOsFSync(pPager->fd);
tdbOsClose(pPager->jfd);
tdbOsRemove(pPager->jFileName);
// pPager->jfd = -1;
return 0; return 0;
} }
...@@ -181,7 +222,7 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) { ...@@ -181,7 +222,7 @@ static int tdbPagerReadPage(SPager *pPager, SPage *pPage) {
ASSERT(memcmp(pPager->fid, pPage->pgid.fileid, TDB_FILE_ID_LEN) == 0); ASSERT(memcmp(pPager->fid, pPage->pgid.fileid, TDB_FILE_ID_LEN) == 0);
offset = (pPage->pgid.pgno - 1) * (i64)(pPager->pageSize); offset = (pPage->pgid.pgno - 1) * (i64)(pPager->pageSize);
ret = tdbPRead(pPager->fd, pPage->pData, pPager->pageSize, offset); ret = tdbOsPRead(pPager->fd, pPage->pData, pPager->pageSize, offset);
if (ret < 0) { if (ret < 0) {
// TODO: handle error // TODO: handle error
return -1; return -1;
...@@ -255,9 +296,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage ...@@ -255,9 +296,7 @@ int tdbPagerNewPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage
return 0; return 0;
} }
void tdbPagerReturnPage(SPager *pPager, SPage *pPage) { void tdbPagerReturnPage(SPager *pPager, SPage *pPage) { tdbPCacheRelease(pPager->pCache, pPage); }
tdbPCacheRelease(pPager->pCache, pPage);
}
static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) { static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) {
// TODO: Allocate a page from the free list // TODO: Allocate a page from the free list
...@@ -328,5 +367,44 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage ...@@ -328,5 +367,44 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
return -1; return -1;
} }
return 0;
}
// ---------------------------- Journal manipulation
static int tdbPagerWritePageToJournal(SPager *pPager, SPage *pPage) {
int ret;
SPgno pgno;
pgno = TDB_PAGE_PGNO(pPage);
ret = tdbOsWrite(pPager->jfd, &pgno, sizeof(pgno));
if (ret < 0) {
return -1;
}
ret = tdbOsWrite(pPager->jfd, pPage->pData, pPage->pageSize);
if (ret < 0) {
return -1;
}
return 0;
}
static int tdbPagerWritePageToDB(SPager *pPager, SPage *pPage) {
i64 offset;
int ret;
offset = pPage->pageSize * TDB_PAGE_PGNO(pPage);
if (tdbOsLSeek(pPager->fd, offset, SEEK_SET) < 0) {
ASSERT(0);
return -1;
}
ret = tdbOsWrite(pPager->fd, pPage->pData, pPage->pageSize);
if (ret < 0) {
ASSERT(0);
return -1;
}
return 0; return 0;
} }
\ No newline at end of file
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdbInt.h"
int tdbTxnBegin(TENV *pEnv) {
// TODO
return 0;
}
int tdbTxnCommit(TENV *pEnv) {
// TODO
return 0;
}
int tdbTxnRollback(TENV *pEnv) {
// TODO
return 0;
}
\ No newline at end of file
...@@ -31,62 +31,4 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) { ...@@ -31,62 +31,4 @@ int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
} }
return 0; return 0;
}
// int tdbCheckFileAccess(const char *pathname, int mode) {
// int flags = 0;
// if (mode & TDB_F_OK) {
// flags |= F_OK;
// }
// if (mode & TDB_R_OK) {
// flags |= R_OK;
// }
// if (mode & TDB_W_OK) {
// flags |= W_OK;
// }
// return access(pathname, flags);
// }
int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize) {
struct stat st;
int ret;
int64_t file_size = 0;
ret = taosStatFile(fname, &file_size, NULL);
if (ret != 0) {
return -1;
}
ASSERT(file_size % pgSize == 0);
*pSize = file_size / pgSize;
return 0;
}
int tdbPRead(int fd, void *pData, int count, i64 offset) {
void *pBuf;
int nbytes;
i64 ioffset;
int iread;
pBuf = pData;
nbytes = count;
ioffset = offset;
while (nbytes > 0) {
iread = pread(fd, pBuf, nbytes, ioffset);
if (iread < 0) {
/* TODO */
} else if (iread == 0) {
return (count - iread);
}
nbytes = nbytes - iread;
pBuf = (void *)((u8 *)pBuf + iread);
ioffset += iread;
}
return count;
} }
\ No newline at end of file
...@@ -20,20 +20,20 @@ ...@@ -20,20 +20,20 @@
extern "C" { extern "C" {
#endif #endif
typedef struct STDB STDB; typedef struct STDB TDB;
typedef struct STDBC STDBC; typedef struct STDBC TDBC;
// STDB // TDB
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, STEnv *pEnv, STDB **ppDb); int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb);
int tdbDbClose(STDB *pDb); int tdbDbClose(TDB *pDb);
int tdbDbDrop(STDB *pDb); int tdbDbDrop(TDB *pDb);
int tdbDbInsert(STDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen); int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen);
int tdbDbGet(STDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen); int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
// STDBC // TDBC
int tdbDbcOpen(STDB *pDb, STDBC **ppDbc); int tdbDbcOpen(TDB *pDb, TDBC **ppDbc);
int tdbDbNext(STDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
int tdbDbcClose(STDBC *pDbc); int tdbDbcClose(TDBC *pDbc);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -21,16 +21,16 @@ extern "C" { ...@@ -21,16 +21,16 @@ extern "C" {
#endif #endif
typedef struct STEnv { typedef struct STEnv {
char * rootDir; char *rootDir;
char * jfname; char *jfname;
int jfd; int jfd;
SPCache *pCache; SPCache *pCache;
} STEnv; } TENV;
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, STEnv **ppEnv); int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv);
int tdbEnvClose(STEnv *pEnv); int tdbEnvClose(TENV *pEnv);
SPager *tdbEnvGetPager(STEnv *pEnv, const char *fname); SPager *tdbEnvGetPager(TENV *pEnv, const char *fname);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -16,10 +16,9 @@ ...@@ -16,10 +16,9 @@
#ifndef _TD_TDB_INTERNAL_H_ #ifndef _TD_TDB_INTERNAL_H_
#define _TD_TDB_INTERNAL_H_ #define _TD_TDB_INTERNAL_H_
#include "tlist.h" #include "os.h"
#include "tlockfree.h"
// #include "tdb.h" #include "tdb.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
...@@ -51,18 +50,18 @@ typedef u32 SPgno; ...@@ -51,18 +50,18 @@ typedef u32 SPgno;
// fileid // fileid
#define TDB_FILE_ID_LEN 24 #define TDB_FILE_ID_LEN 24
// pgid_t // SPgid
typedef struct { typedef struct {
uint8_t fileid[TDB_FILE_ID_LEN]; uint8_t fileid[TDB_FILE_ID_LEN];
SPgno pgno; SPgno pgno;
} pgid_t, SPgid; } SPgid;
#define TDB_IVLD_PGID (pgid_t){0, TDB_IVLD_PGNO}; #define TDB_IVLD_PGID (SPgid){0, TDB_IVLD_PGNO};
static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
pgid_t *pgid1 = (pgid_t *)p1; SPgid *pgid1 = (SPgid *)p1;
pgid_t *pgid2 = (pgid_t *)p2; SPgid *pgid2 = (SPgid *)p2;
int rcode; int rcode;
rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN); rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN);
if (rcode) { if (rcode) {
...@@ -95,10 +94,6 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) { ...@@ -95,10 +94,6 @@ static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
// tdb_log // tdb_log
#define tdbError(var) #define tdbError(var)
typedef TD_DLIST(STDB) STDbList;
typedef TD_DLIST(SPgFile) SPgFileList;
typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
#define TERR_A(val, op, flag) \ #define TERR_A(val, op, flag) \
do { \ do { \
if (((val) = (op)) != 0) { \ if (((val) = (op)) != 0) { \
...@@ -115,19 +110,6 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode; ...@@ -115,19 +110,6 @@ typedef TD_DLIST_NODE(SPgFile) SPgFileListNode;
#define TDB_VARIANT_LEN ((int)-1) #define TDB_VARIANT_LEN ((int)-1)
// page payload format
// <keyLen> + <valLen> + [key] + [value]
#define TDB_DECODE_PAYLOAD(pPayload, keyLen, pKey, valLen, pVal) \
do { \
if ((keyLen) == TDB_VARIANT_LEN) { \
/* TODO: decode the keyLen */ \
} \
if ((valLen) == TDB_VARIANT_LEN) { \
/* TODO: decode the valLen */ \
} \
/* TODO */ \
} while (0)
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2); typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
#define TDB_JOURNAL_NAME "tdb.journal" #define TDB_JOURNAL_NAME "tdb.journal"
...@@ -148,6 +130,8 @@ typedef struct SPager SPager; ...@@ -148,6 +130,8 @@ typedef struct SPager SPager;
typedef struct SPCache SPCache; typedef struct SPCache SPCache;
typedef struct SPage SPage; typedef struct SPage SPage;
#include "tdbOs.h"
#include "tdbUtil.h" #include "tdbUtil.h"
#include "tdbPCache.h" #include "tdbPCache.h"
...@@ -162,6 +146,8 @@ typedef struct SPage SPage; ...@@ -162,6 +146,8 @@ typedef struct SPage SPage;
#include "tdbPage.h" #include "tdbPage.h"
#include "tdbTxn.h"
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TDB_OS_H_
#define _TDB_OS_H_
#ifdef __cplusplus
extern "C" {
#endif
// TODO: use cmake to control the option
#define TDB_FOR_TDENGINE
#ifdef TDB_FOR_TDENGINE
// For memory -----------------
#define tdbOsMalloc taosMemoryMalloc
#define tdbOsCalloc taosMemoryCalloc
#define tdbOsRealloc taosMemoryRealloc
#define tdbOsFree taosMemoryFree
// For file and directory -----------------
/* file */
typedef TdFilePtr tdb_fd_t;
#define TDB_O_CREAT TD_FILE_CTEATE
#define TDB_O_WRITE TD_FILE_WRITE
#define TDB_O_READ TD_FILE_READ
#define TDB_O_TRUNC TD_FILE_TRUNC
#define TDB_O_APPEND TD_FILE_APPEND
#define TDB_O_RDWR (TD_FILE_WRITE) | (TD_FILE_READ)
#define tdbOsOpen(PATH, OPTION, MODE) taosOpenFile((PATH), (OPTION))
#define tdbOsClose(FD) taosCloseFile(&(FD))
#define tdbOsRead taosReadFile
#define tdbOsPRead taosPReadFile
#define tdbOsWrite taosWriteFile
#define tdbOsFSync taosFsyncFile
#define tdbOsLSeek taosLSeekFile
#define tdbOsRemove remove
/* directory */
#define tdbOsMkdir taosMkDir
#define tdbOsRmdir taosRemoveDir
// For threads and lock -----------------
/* spin lock */
typedef TdThreadSpinlock tdb_spinlock_t;
#define tdbSpinlockInit taosThreadSpinInit
#define tdbSpinlockDestroy taosThreadSpinDestroy
#define tdbSpinlockLock taosThreadSpinLock
#define tdbSpinlockUnlock taosThreadSpinUnlock
#define tdbSpinlockTrylock pthread_spin_trylock
/* mutex lock */
typedef TdThreadMutex tdb_mutex_t;
#define tdbMutexInit taosThreadMutexInit
#define tdbMutexDestroy taosThreadMutexDestroy
#define tdbMutexLock taosThreadMutexLock
#define tdbMutexUnlock taosThreadMutexUnlock
#else
// For memory -----------------
#define tdbOsMalloc malloc
#define tdbOsCalloc calloc
#define tdbOsRealloc realloc
#define tdbOsFree free
// For file and directory -----------------
/* file */
typedef int tdb_fd_t;
#define TDB_O_CREAT O_CREAT
#define TDB_O_WRITE O_WRONLY
#define TDB_O_READ O_RDONLY
#define TDB_O_TRUNC O_TRUNC
#define TDB_O_APPEND O_APPEND
#define TDB_O_RDWR O_RDWR
#define tdbOsOpen(PATH, OPTION, MODE) open((PATH), (OPTION), (MODE))
#define tdbOsClose close
i64 tdbOsRead(tdb_fd_t fd, void *pData, i64 nBytes);
i64 tdbOsPRead(tdb_fd_t fd, void *pData, i64 nBytes, i64 offset);
i64 tdbOsWrite(tdb_fd_t fd, const void *pData, i64 nBytes);
#define tdbOsFSync fsync
#define tdbOsLSeek lseek
#define tdbOsRemove remove
/* directory */
#define tdbOsMkdir mkdir
#define tdbOsRmdir rmdir
// For threads and lock -----------------
/* spin lock */
typedef pthread_spinlock_t tdb_spinlock_t;
#define tdbSpinlockInit pthread_spin_init
#define tdbSpinlockDestroy pthread_spin_destroy
#define tdbSpinlockLock pthread_spin_lock
#define tdbSpinlockUnlock pthread_spin_unlock
#define tdbSpinlockTrylock pthread_spin_trylock
/* mutex lock */
typedef pthread_mutex_t tdb_mutex_t;
#define tdbMutexInit pthread_mutex_init
#define tdbMutexDestroy pthread_mutex_destroy
#define tdbMutexLock pthread_mutex_lock
#define tdbMutexUnlock pthread_mutex_unlock
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TDB_OS_H_*/
\ No newline at end of file
...@@ -53,10 +53,10 @@ typedef struct __attribute__((__packed__)) { ...@@ -53,10 +53,10 @@ typedef struct __attribute__((__packed__)) {
} SPageFtr; } SPageFtr;
struct SPage { struct SPage {
pthread_spinlock_t lock; tdb_spinlock_t lock;
int pageSize; int pageSize;
u8 *pData; u8 *pData;
SPageMethods *pPageMethods; SPageMethods *pPageMethods;
// Fields below used by pager and am // Fields below used by pager and am
u8 *pPageHdr; u8 *pPageHdr;
u8 *pCellIdx; u8 *pCellIdx;
...@@ -80,21 +80,21 @@ struct SPage { ...@@ -80,21 +80,21 @@ struct SPage {
#define P_LOCK_BUSY 1 #define P_LOCK_BUSY 1
#define P_LOCK_FAIL -1 #define P_LOCK_FAIL -1
#define TDB_INIT_PAGE_LOCK(pPage) pthread_spin_init(&((pPage)->lock), 0) #define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
#define TDB_DESTROY_PAGE_LOCK(pPage) pthread_spin_destroy(&((pPage)->lock)) #define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock))
#define TDB_LOCK_PAGE(pPage) pthread_spin_lock(&((pPage)->lock)) #define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock))
#define TDB_UNLOCK_PAGE(pPage) pthread_spin_unlock(&((pPage)->lock)) #define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock))
#define TDB_TRY_LOCK_PAGE(pPage) \ #define TDB_TRY_LOCK_PAGE(pPage) \
({ \ ({ \
int ret; \ int ret; \
if (pthread_spin_trylock(&((pPage)->lock)) == 0) { \ if (tdbSpinlockTrylock(&((pPage)->lock)) == 0) { \
ret = P_LOCK_SUCC; \ ret = P_LOCK_SUCC; \
} else if (errno == EBUSY) { \ } else if (errno == EBUSY) { \
ret = P_LOCK_BUSY; \ ret = P_LOCK_BUSY; \
} else { \ } else { \
ret = P_LOCK_FAIL; \ ret = P_LOCK_FAIL; \
} \ } \
ret; \ ret; \
}) })
// APIs // APIs
......
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TDB_TXN_H_
#define _TDB_TXN_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef struct STxn STXN;
struct STxn {
u64 txnId;
void *(*xMalloc)(void *, int);
void *xArg;
};
int tdbTxnBegin(TENV *pEnv);
int tdbTxnCommit(TENV *pEnv);
int tdbTxnRollback(TENV *pEnv);
#ifdef __cplusplus
}
#endif
#endif /*_TDB_TXN_H_*/
\ No newline at end of file
...@@ -30,46 +30,37 @@ extern "C" { ...@@ -30,46 +30,37 @@ extern "C" {
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique); int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
// #define TDB_F_OK 0x1 #define TDB_REALLOC(PTR, SIZE) \
// #define TDB_R_OK 0x2 ({ \
// #define TDB_W_OK 0x4 void *nPtr; \
// int tdbCheckFileAccess(const char *pathname, int mode); if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \
nPtr = tdbOsRealloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \
int tdbGetFileSize(const char *fname, int pgSize, SPgno *pSize); if (nPtr) { \
((int *)nPtr)[0] = (SIZE); \
int tdbPRead(int fd, void *pData, int count, i64 offset); nPtr = (char *)nPtr + sizeof(int); \
} \
#define TDB_REALLOC(PTR, SIZE) \ } else { \
({ \ nPtr = (PTR); \
void *nPtr; \ } \
if ((PTR) == NULL || ((int *)(PTR))[-1] < (SIZE)) { \ nPtr; \
nPtr = realloc((PTR) ? (char *)(PTR) - sizeof(int) : NULL, (SIZE) + sizeof(int)); \
if (nPtr) { \
((int *)nPtr)[0] = (SIZE); \
nPtr = (char *)nPtr + sizeof(int); \
} \
} else { \
nPtr = (PTR); \
} \
nPtr; \
}) })
#define TDB_FREE(PTR) \ #define TDB_FREE(PTR) \
do { \ do { \
if (PTR) { \ if (PTR) { \
free((char *)(PTR) - sizeof(int)); \ tdbOsFree((char *)(PTR) - sizeof(int)); \
} \ } \
} while (0) } while (0)
static inline void *tdbOsMalloc(void *arg, size_t size) { static inline void *tdbDefaultMalloc(void *arg, size_t size) {
void *ptr; void *ptr;
ptr = malloc(size); ptr = tdbOsMalloc(size);
return ptr; return ptr;
} }
static inline void tdbOsFree(void *arg, void *ptr) { free(ptr); } static inline void tdbDefaultFree(void *arg, void *ptr) { tdbOsFree(ptr); }
static inline int tdbPutVarInt(u8 *p, int v) { static inline int tdbPutVarInt(u8 *p, int v) {
int n = 0; int n = 0;
......
...@@ -48,7 +48,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t) ...@@ -48,7 +48,7 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
*ppPage = NULL; *ppPage = NULL;
size = pageSize + sizeof(*pPage); size = pageSize + sizeof(*pPage);
if (xMalloc == NULL) { if (xMalloc == NULL) {
xMalloc = tdbOsMalloc; xMalloc = tdbDefaultMalloc;
} }
ptr = (u8 *)((*xMalloc)(arg, size)); ptr = (u8 *)((*xMalloc)(arg, size));
...@@ -76,7 +76,7 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) ...@@ -76,7 +76,7 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg)
u8 *ptr; u8 *ptr;
if (!xFree) { if (!xFree) {
xFree = tdbOsFree; xFree = tdbDefaultFree;
} }
ptr = pPage->pData; ptr = pPage->pData;
...@@ -144,7 +144,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl ...@@ -144,7 +144,7 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
} }
// TODO: here has memory leak // TODO: here has memory leak
pNewCell = (SCell *)malloc(szCell); pNewCell = (SCell *)tdbOsMalloc(szCell);
memcpy(pNewCell, pCell, szCell); memcpy(pNewCell, pCell, szCell);
pPage->apOvfl[iOvfl] = pNewCell; pPage->apOvfl[iOvfl] = pNewCell;
...@@ -372,11 +372,11 @@ static int tdbPageDefragment(SPage *pPage) { ...@@ -372,11 +372,11 @@ static int tdbPageDefragment(SPage *pPage) {
int idx; int idx;
int iCell; int iCell;
ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree);
nFree = TDB_PAGE_NFREE(pPage); nFree = TDB_PAGE_NFREE(pPage);
nCells = TDB_PAGE_NCELLS(pPage); nCells = TDB_PAGE_NCELLS(pPage);
ASSERT(pPage->pFreeEnd - pPage->pFreeStart < nFree);
// Loop to compact the page content // Loop to compact the page content
// Here we use an O(n^2) algorithm to do the job since // Here we use an O(n^2) algorithm to do the job since
// this is a low frequency job. // this is a low frequency job.
......
...@@ -11,7 +11,7 @@ typedef struct SPoolMem { ...@@ -11,7 +11,7 @@ typedef struct SPoolMem {
} SPoolMem; } SPoolMem;
static SPoolMem *openPool() { static SPoolMem *openPool() {
SPoolMem *pPool = (SPoolMem *)malloc(sizeof(*pPool)); SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool));
pPool->prev = pPool->next = pPool; pPool->prev = pPool->next = pPool;
pPool->size = 0; pPool->size = 0;
...@@ -31,20 +31,22 @@ static void closePool(SPoolMem *pPool) { ...@@ -31,20 +31,22 @@ static void closePool(SPoolMem *pPool) {
pMem->prev->next = pMem->next; pMem->prev->next = pMem->next;
pPool->size -= pMem->size; pPool->size -= pMem->size;
free(pMem); tdbOsFree(pMem);
} while (1); } while (1);
assert(pPool->size == 0); assert(pPool->size == 0);
free(pPool); tdbOsFree(pPool);
} }
#define clearPool closePool
static void *poolMalloc(void *arg, int size) { static void *poolMalloc(void *arg, int size) {
void *ptr = NULL; void *ptr = NULL;
SPoolMem *pPool = (SPoolMem *)arg; SPoolMem *pPool = (SPoolMem *)arg;
SPoolMem *pMem; SPoolMem *pMem;
pMem = (SPoolMem *)malloc(sizeof(*pMem) + size); pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
if (pMem == NULL) { if (pMem == NULL) {
assert(0); assert(0);
} }
...@@ -71,7 +73,7 @@ static void poolFree(void *arg, void *ptr) { ...@@ -71,7 +73,7 @@ static void poolFree(void *arg, void *ptr) {
pMem->prev->next = pMem->next; pMem->prev->next = pMem->next;
pPool->size -= pMem->size; pPool->size -= pMem->size;
free(pMem); tdbOsFree(pMem);
} }
static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) { static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
...@@ -113,10 +115,10 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in ...@@ -113,10 +115,10 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in
TEST(tdb_test, simple_test) { TEST(tdb_test, simple_test) {
int ret; int ret;
STEnv *pEnv; TENV *pEnv;
STDB *pDb; TDB *pDb;
FKeyComparator compFunc; FKeyComparator compFunc;
int nData = 10000000; int nData = 1000000;
// Open Env // Open Env
ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv); ret = tdbEnvOpen("tdb", 4096, 256000, &pEnv);
...@@ -132,13 +134,34 @@ TEST(tdb_test, simple_test) { ...@@ -132,13 +134,34 @@ TEST(tdb_test, simple_test) {
char val[64]; char val[64];
{ // Insert some data { // Insert some data
int i = 1;
SPoolMem *pPool;
int memPoolCapacity = 16 * 1024;
pPool = openPool();
tdbTxnBegin(pEnv);
for (;;) {
if (i > nData) break;
for (int i = 1; i <= nData; i++) {
sprintf(key, "key%d", i); sprintf(key, "key%d", i);
sprintf(val, "value%d", i); sprintf(val, "value%d", i);
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val)); ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val));
GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(ret, 0);
if (pPool->size >= memPoolCapacity) {
tdbTxnCommit(pEnv);
clearPool(pPool);
tdbTxnBegin(pEnv);
}
i++;
} }
closePool(pPool);
} }
{ // Query the data { // Query the data
...@@ -160,11 +183,11 @@ TEST(tdb_test, simple_test) { ...@@ -160,11 +183,11 @@ TEST(tdb_test, simple_test) {
} }
{ // Iterate to query the DB data { // Iterate to query the DB data
STDBC *pDBC; TDBC *pDBC;
void *pKey = NULL; void *pKey = NULL;
void *pVal = NULL; void *pVal = NULL;
int vLen, kLen; int vLen, kLen;
int count = 0; int count = 0;
ret = tdbDbcOpen(pDb, &pDBC); ret = tdbDbcOpen(pDb, &pDBC);
GTEST_ASSERT_EQ(ret, 0); GTEST_ASSERT_EQ(ret, 0);
......
...@@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -156,14 +156,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
...@@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -176,14 +176,14 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryMalloc(12); val1.val = taosMemoryMalloc(12);
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
key++; key++;
...@@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -198,7 +198,7 @@ TEST_F(TransCtxEnv, mergeTest) {
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx)); STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
transCtxInit(src); transCtxInit(src);
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryCalloc(1, 11); val1.val = taosMemoryCalloc(1, 11);
memcpy(val1.val, val.c_str(), val.size()); memcpy(val1.val, val.c_str(), val.size());
...@@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) { ...@@ -206,7 +206,7 @@ TEST_F(TransCtxEnv, mergeTest) {
key++; key++;
} }
{ {
STransCtxVal val1 = {.val = NULL, .freeFunc = taosMemoryFree}; STransCtxVal val1 = {.val = NULL, .clone = NULL, .freeFunc = taosMemoryFree};
val1.val = taosMemoryCalloc(1, 11); val1.val = taosMemoryCalloc(1, 11);
memcpy(val1.val, val.c_str(), val.size()); memcpy(val1.val, val.c_str(), val.size());
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1)); taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
......
...@@ -13,6 +13,9 @@ find_path(IconvApiIncludes iconv.h PATHS) ...@@ -13,6 +13,9 @@ find_path(IconvApiIncludes iconv.h PATHS)
if(NOT IconvApiIncludes) if(NOT IconvApiIncludes)
add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV) add_definitions(-DDISALLOW_NCHAR_WITHOUT_ICONV)
endif () endif ()
if(USE_TD_MEMORY)
add_definitions(-DUSE_TD_MEMORY)
endif ()
target_link_libraries( target_link_libraries(
os pthread dl rt m os pthread dl rt m
) )
...@@ -14,17 +14,17 @@ ...@@ -14,17 +14,17 @@
*/ */
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#include <malloc.h>
#include "os.h" #include "os.h"
#define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S') #define TD_MEMORY_SYMBOL ('T'<<24|'A'<<16|'O'<<8|'S')
#define TD_MEMORY_STACK_TRACE_DEPTH 10 #define TD_MEMORY_STACK_TRACE_DEPTH 10
typedef struct TdMemoryInfo typedef struct TdMemoryInfo {
{
int32_t symbol; int32_t symbol;
int32_t memorySize;
void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX
int32_t memorySize;
} *TdMemoryInfoPtr , TdMemoryInfo; } *TdMemoryInfoPtr , TdMemoryInfo;
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
...@@ -32,6 +32,7 @@ typedef struct TdMemoryInfo ...@@ -32,6 +32,7 @@ typedef struct TdMemoryInfo
#else #else
#include<execinfo.h> #include<execinfo.h>
#define STACKCALL __attribute__((regparm(1), noinline)) #define STACKCALL __attribute__((regparm(1), noinline))
void **STACKCALL taosGetEbp(void) { void **STACKCALL taosGetEbp(void) {
void **ebp = NULL; void **ebp = NULL;
...@@ -41,6 +42,7 @@ void **STACKCALL taosGetEbp(void) { ...@@ -41,6 +42,7 @@ void **STACKCALL taosGetEbp(void) {
: "memory"); /* not affect register */ : "memory"); /* not affect register */
return (void **)(*ebp); return (void **)(*ebp);
} }
int32_t taosBackTrace(void **buffer, int32_t size) { int32_t taosBackTrace(void **buffer, int32_t size) {
int32_t frame = 0; int32_t frame = 0;
void **ebp; void **ebp;
...@@ -59,6 +61,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { ...@@ -59,6 +61,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
} }
return frame; return frame;
} }
#endif #endif
// char **taosBackTraceSymbols(int32_t *size) { // char **taosBackTraceSymbols(int32_t *size) {
...@@ -68,6 +71,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) { ...@@ -68,6 +71,7 @@ int32_t taosBackTrace(void **buffer, int32_t size) {
// } // }
void *taosMemoryMalloc(int32_t size) { void *taosMemoryMalloc(int32_t size) {
#ifdef USE_TD_MEMORY
void *tmp = malloc(size + sizeof(TdMemoryInfo)); void *tmp = malloc(size + sizeof(TdMemoryInfo));
if (tmp == NULL) return NULL; if (tmp == NULL) return NULL;
...@@ -77,9 +81,13 @@ void *taosMemoryMalloc(int32_t size) { ...@@ -77,9 +81,13 @@ void *taosMemoryMalloc(int32_t size) {
taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH);
return (char*)tmp + sizeof(TdMemoryInfo); return (char*)tmp + sizeof(TdMemoryInfo);
#else
return malloc(size);
#endif
} }
void *taosMemoryCalloc(int32_t num, int32_t size) { void *taosMemoryCalloc(int32_t num, int32_t size) {
#ifdef USE_TD_MEMORY
int32_t memorySize = num * size; int32_t memorySize = num * size;
char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1); char *tmp = calloc(memorySize + sizeof(TdMemoryInfo), 1);
if (tmp == NULL) return NULL; if (tmp == NULL) return NULL;
...@@ -90,9 +98,13 @@ void *taosMemoryCalloc(int32_t num, int32_t size) { ...@@ -90,9 +98,13 @@ void *taosMemoryCalloc(int32_t num, int32_t size) {
taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH); taosBackTrace(pTdMemoryInfo->stackTrace,TD_MEMORY_STACK_TRACE_DEPTH);
return (char*)tmp + sizeof(TdMemoryInfo); return (char*)tmp + sizeof(TdMemoryInfo);
#else
return calloc(num, size);
#endif
} }
void *taosMemoryRealloc(void *ptr, int32_t size) { void *taosMemoryRealloc(void *ptr, int32_t size) {
#ifdef USE_TD_MEMORY
if (ptr == NULL) return taosMemoryMalloc(size); if (ptr == NULL) return taosMemoryMalloc(size);
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
...@@ -108,9 +120,13 @@ void *taosMemoryRealloc(void *ptr, int32_t size) { ...@@ -108,9 +120,13 @@ void *taosMemoryRealloc(void *ptr, int32_t size) {
((TdMemoryInfoPtr)tmp)->memorySize = size; ((TdMemoryInfoPtr)tmp)->memorySize = size;
return (char*)tmp + sizeof(TdMemoryInfo); return (char*)tmp + sizeof(TdMemoryInfo);
#else
return realloc(ptr, size);
#endif
} }
void taosMemoryFree(const void *ptr) { void taosMemoryFree(const void *ptr) {
#ifdef USE_TD_MEMORY
if (ptr == NULL) return; if (ptr == NULL) return;
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
...@@ -121,13 +137,20 @@ void taosMemoryFree(const void *ptr) { ...@@ -121,13 +137,20 @@ void taosMemoryFree(const void *ptr) {
} else { } else {
free((void*)ptr); free((void*)ptr);
} }
#else
return free((void*)ptr);
#endif
} }
int32_t taosMemorySize(void *ptr) { int32_t taosMemorySize(void *ptr) {
#ifdef USE_TD_MEMORY
if (ptr == NULL) return 0; if (ptr == NULL) return 0;
TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo)); TdMemoryInfoPtr pTdMemoryInfo = (TdMemoryInfoPtr)((char*)ptr - sizeof(TdMemoryInfo));
assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL); assert(pTdMemoryInfo->symbol == TD_MEMORY_SYMBOL);
return pTdMemoryInfo->memorySize; return pTdMemoryInfo->memorySize;
#else
return malloc_usable_size(ptr);
#endif
} }
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
# ---- db # ---- db
./test.sh -f tsim/db/basic1.sim ./test.sh -f tsim/db/basic1.sim
./test.sh -f tsim/db/basic2.sim
./test.sh -f tsim/db/basic3.sim
./test.sh -f tsim/db/basic6.sim ./test.sh -f tsim/db/basic6.sim
./test.sh -f tsim/db/basic7.sim ./test.sh -f tsim/db/basic7.sim
./test.sh -f tsim/db/error1.sim ./test.sh -f tsim/db/error1.sim
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sleep 2000
$loop_cnt = 0
check_dnode_ready:
$loop_cnt = $loop_cnt + 1
sleep 200
if $loop_cnt == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05
if $data00 != 1 then
return -1
endi
if $data04 != ready then
goto check_dnode_ready
endi
sql connect sql connect
print =============== create database d1 print =============== create database d1
...@@ -13,7 +30,10 @@ sql create table t3 (ts timestamp, i int); ...@@ -13,7 +30,10 @@ sql create table t3 (ts timestamp, i int);
sql create table t4 (ts timestamp, i int); sql create table t4 (ts timestamp, i int);
sql show databases sql show databases
if $rows != 1 then print rows: $rows
print $data00 $data01 $data02 $data03
print $data10 $data11 $data12 $data13
if $rows != 2 then
return -1 return -1
endi endi
...@@ -21,13 +41,13 @@ if $data00 != d1 then ...@@ -21,13 +41,13 @@ if $data00 != d1 then
return -1 return -1
endi endi
if $data02 != 4 then if $data02 != 2 then # vgroups
return -1 return -1
endi endi
if $data03 != 1 then #if $data03 != 4 then # ntables
return -1 # return -1
endi #endi
sql show tables sql show tables
if $rows != 4 then if $rows != 4 then
...@@ -42,7 +62,7 @@ sql create table t2 (ts timestamp, i int); ...@@ -42,7 +62,7 @@ sql create table t2 (ts timestamp, i int);
sql create table t3 (ts timestamp, i int); sql create table t3 (ts timestamp, i int);
sql show databases sql show databases
if $rows != 2 then if $rows != 3 then
return -1 return -1
endi endi
......
system sh/stop_dnodes.sh system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1 system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
sleep 2000
$loop_cnt = 0
check_dnode_ready:
$loop_cnt = $loop_cnt + 1
sleep 200
if $loop_cnt == 10 then
print ====> dnode not ready!
return -1
endi
sql show dnodes
print ===> $rows $data00 $data01 $data02 $data03 $data04 $data05
if $data00 != 1 then
return -1
endi
if $data04 != ready then
goto check_dnode_ready
endi
sql connect sql connect
print =============== create database d1 print =============== create database d1
...@@ -12,7 +29,7 @@ sql create table d1.t3 (ts timestamp, i int); ...@@ -12,7 +29,7 @@ sql create table d1.t3 (ts timestamp, i int);
sql create table d1.t4 (ts timestamp, i int); sql create table d1.t4 (ts timestamp, i int);
sql show databases sql show databases
if $rows != 1 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -20,13 +37,13 @@ if $data00 != d1 then ...@@ -20,13 +37,13 @@ if $data00 != d1 then
return -1 return -1
endi endi
if $data02 != 4 then if $data02 != 2 then
return -1 return -1
endi endi
if $data03 != 1 then #if $data03 != 4 then
return -1 # return -1
endi #endi
sql show d1.tables sql show d1.tables
if $rows != 4 then if $rows != 4 then
...@@ -40,7 +57,7 @@ sql create table d2.t2 (ts timestamp, i int); ...@@ -40,7 +57,7 @@ sql create table d2.t2 (ts timestamp, i int);
sql create table d2.t3 (ts timestamp, i int); sql create table d2.t3 (ts timestamp, i int);
sql show databases sql show databases
if $rows != 2 then if $rows != 3 then
return -1 return -1
endi endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册