Merge pull request #11043 from taosdata/feature/3.0_liaohj
Feature/3.0 liaohj
This commit is contained in:
commit
ddfcac1951
|
@ -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);
|
||||||
|
|
||||||
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) {
|
||||||
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
|
||||||
((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);
|
||||||
|
|
|
@ -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 {
|
||||||
SPoint1 start;
|
SPoint1 start;
|
||||||
SPoint1 end;
|
SPoint1 end;
|
||||||
SFuncExecFuncs fpSet;
|
SFuncExecFuncs fpSet;
|
||||||
|
SScalarFuncExecFuncs sfp;
|
||||||
} SqlFunctionCtx;
|
} SqlFunctionCtx;
|
||||||
|
|
||||||
enum {
|
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 {
|
||||||
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 {
|
||||||
// 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 {
|
||||||
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;
|
||||||
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);
|
||||||
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);
|
||||||
|
|
|
@ -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,42 @@ 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);
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) {
|
||||||
assert(pRequest != NULL);
|
assert(pRequest != NULL);
|
||||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||||
|
|
||||||
|
@ -555,17 +590,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 +671,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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
|
||||||
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;
|
||||||
|
@ -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)
|
||||||
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)
|
||||||
|
|
||||||
// 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*
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
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*
|
||||||
|
|
||||||
// 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*
|
||||||
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*
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) {
|
||||||
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) {
|
||||||
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 {
|
||||||
#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" {
|
||||||
#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 @@
|
||||||
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);
|
||||||
|
|
|
@ -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) {
|
||||||
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
|
||||||
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
|
||||||
|
|
||||||
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) {
|
||||||
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)
|
||||||
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
|
||||||
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 @@
|
||||||
#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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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 = vectorConvertImpl(&in, &out);
|
code = doConvertDataType(valueNode, &out);
|
||||||
if (code) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
sclError("convert from %d to %d failed", in.type, out.type);
|
// sclError("convert data from %d to %d failed", in.type, out.type);
|
||||||
SCL_ERR_JRET(code);
|
SCL_ERR_JRET(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_VAR_DATA_TYPE(type)) {
|
if (IS_VAR_DATA_TYPE(type)) {
|
||||||
len = varDataLen(out.data);
|
len = varDataLen(out.columnData->pData);
|
||||||
buf = varDataVal(out.data);
|
buf = varDataVal(out.columnData->pData);
|
||||||
} else {
|
} else {
|
||||||
len = tDataTypes[type].bytes;
|
len = tDataTypes[type].bytes;
|
||||||
buf = out.data;
|
buf = out.columnData->pData;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf = nodesGetValueFromNode(valueNode);
|
buf = nodesGetValueFromNode(valueNode);
|
||||||
|
@ -63,11 +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) {
|
||||||
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,31 +124,22 @@ 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);
|
||||||
|
taosMemoryFreeClear(param->columnData);
|
||||||
|
}
|
||||||
|
|
||||||
if (!param->dataInBlock) {
|
if (param->pHashFilter != NULL) {
|
||||||
if (SCL_DATA_TYPE_DUMMY_HASH == param->type) {
|
taosHashCleanup(param->pHashFilter);
|
||||||
taosHashCleanup((SHashObj *)param->orig.data);
|
|
||||||
} else {
|
|
||||||
taosMemoryFreeClear(param->orig.data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) {
|
int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) {
|
||||||
if (TSDB_DATA_TYPE_NULL == pNode->node.resType.type) {
|
if (TSDB_DATA_TYPE_NULL == pNode->node.resType.type) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -155,7 +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
|
||||||
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, ¶m->data));
|
|
||||||
param->data = nodesGetValueFromNode(valueNode);
|
|
||||||
param->orig.data = param->data;
|
|
||||||
param->num = 1;
|
|
||||||
param->type = valueNode->node.resType.type;
|
|
||||||
param->bytes = valueNode->node.resType.bytes;
|
|
||||||
if (TSDB_DATA_TYPE_NULL == param->type) {
|
|
||||||
sclSetNull(param, 0);
|
|
||||||
}
|
|
||||||
param->dataInBlock = false;
|
|
||||||
|
|
||||||
|
param->numOfRows = 1;
|
||||||
|
param->columnData = createColumnInfoData(&valueNode->node.resType, 1);
|
||||||
|
if (TSDB_DATA_TYPE_NULL == valueNode->node.resType.type) {
|
||||||
|
colDataAppend(param->columnData, 0, NULL, true);
|
||||||
|
} else {
|
||||||
|
colDataAppend(param->columnData, 0, nodesGetValueFromNode(valueNode), false);
|
||||||
|
}
|
||||||
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(¶m->data, node, nodeList->dataType.type));
|
SCL_ERR_RET(scalarGenerateSetFromList((void**) ¶m->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
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
SCL_ERR_JRET(sclInitParam(cell->pNode, ¶mList[i], ctx, rowNum));
|
SCL_ERR_JRET(sclInitParam(cell->pNode, ¶mList[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
|
||||||
}
|
}
|
||||||
|
|
||||||
*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
|
||||||
int32_t rowNum = 0;
|
int32_t rowNum = 0;
|
||||||
SCL_ERR_RET(sclInitParamList(¶ms, node->pParameterList, ctx, &rowNum));
|
SCL_ERR_RET(sclInitParamList(¶ms, 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,27 +348,23 @@ 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(¶ms, node->pParameterList, ctx, &rowNum));
|
SCL_ERR_RET(sclInitParamList(¶ms, 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;
|
||||||
|
@ -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
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
SCL_ERR_RET(sclInitOperatorParams(¶ms, node, ctx, &rowNum));
|
SCL_ERR_RET(sclInitOperatorParams(¶ms, 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
|
||||||
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(¶ms[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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
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) {
|
||||||
|
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,106 +1,118 @@
|
||||||
#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: {
|
case TSDB_DATA_TYPE_TINYINT: {
|
||||||
double v;
|
int8_t *in = (int8_t *)pInputData->pData;
|
||||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
int8_t *out = (int8_t *)pOutputData->pData;
|
||||||
double result;
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
result = (v > 0) ? v : -v;
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
out[i] = (in[i] > 0)? in[i] : -in[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_TINYINT: {
|
case TSDB_DATA_TYPE_SMALLINT: {
|
||||||
int8_t v;
|
int16_t *in = (int16_t *)pInputData->pData;
|
||||||
GET_TYPED_DATA(v, int8_t, pInput->type, input);
|
int16_t *out = (int16_t *)pOutputData->pData;
|
||||||
int8_t result;
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
result = (v > 0) ? v : -v;
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
out[i] = (in[i] > 0)? in[i] : -in[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_SMALLINT: {
|
case TSDB_DATA_TYPE_INT: {
|
||||||
int16_t v;
|
int32_t *in = (int32_t *)pInputData->pData;
|
||||||
GET_TYPED_DATA(v, int16_t, pInput->type, input);
|
int32_t *out = (int32_t *)pOutputData->pData;
|
||||||
int16_t result;
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
result = (v > 0) ? v : -v;
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
out[i] = (in[i] > 0)? in[i] : -in[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_INT: {
|
case TSDB_DATA_TYPE_BIGINT: {
|
||||||
int32_t v;
|
int64_t *in = (int64_t *)pInputData->pData;
|
||||||
GET_TYPED_DATA(v, int32_t, pInput->type, input);
|
int64_t *out = (int64_t *)pOutputData->pData;
|
||||||
int32_t result;
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
result = (v > 0) ? v : -v;
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
break;
|
continue;
|
||||||
|
}
|
||||||
|
out[i] = (in[i] > 0)? in[i] : -in[i];
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_BIGINT: {
|
default: {
|
||||||
int64_t v;
|
colDataAssign(pOutputData, pInputData, pInput->numOfRows);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
default: {
|
|
||||||
memcpy(output, input, pInput->bytes);
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
output = pOutput->data + i * pOutput->bytes;
|
|
||||||
|
|
||||||
if (isNull(input, pInput->type)) {
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
setNull(output, pOutput->type, pOutput->bytes);
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
continue;
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
out[i] = f1(in[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
double v;
|
case TSDB_DATA_TYPE_DOUBLE: {
|
||||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
double *in = (double *)pInputData->pData;
|
||||||
double result = sin(v);
|
double *out = (double *)pOutputData->pData;
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
|
||||||
}
|
for (int32_t i = 0; i < pInput->numOfRows; ++i) {
|
||||||
|
if (colDataIsNull_f(pInputData->nullbitmap, i)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
colDataSetNull_f(pOutputData->nullbitmap, i);
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
out[i] = d1(in[i]);
|
||||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
}
|
||||||
return TSDB_CODE_FAILED;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
pOutput->type = TSDB_DATA_TYPE_DOUBLE;
|
default: {
|
||||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
colDataAssign(pOutputData, pInputData, pInput->numOfRows);
|
||||||
|
}
|
||||||
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 = cos(v);
|
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
|
||||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
|
||||||
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) {
|
|
||||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
|
||||||
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) {
|
|
||||||
if (inputNum != 1 || !IS_NUMERIC_TYPE(pInput->type)) {
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pOutput->numOfRows = pInput->numOfRows;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t atanFunction(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;
|
int32_t sinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
pOutput->bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, sin);
|
||||||
|
}
|
||||||
|
|
||||||
char *input = NULL, *output = NULL;
|
int32_t cosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
for (int32_t i = 0; i < pOutput->num; ++i) {
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, cos);
|
||||||
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)) {
|
int32_t tanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
setNull(output, pOutput->type, pOutput->bytes);
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, tan);
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
double v;
|
int32_t asinFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
GET_TYPED_DATA(v, double, pInput->type, input);
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, asin);
|
||||||
double result = atan(v);
|
}
|
||||||
SET_TYPED_DATA(output, pOutput->type, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
int32_t acosFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, acos);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t sqrtFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||||
|
return doScalarFunctionUnique(pInput, inputNum, pOutput, sqrt);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -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) {
|
||||||
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) {
|
||||||
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) {
|
||||||
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));
|
||||||
|
|
|
@ -21,11 +21,10 @@
|
||||||
|
|
||||||
#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;
|
||||||
void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX
|
|
||||||
int32_t memorySize;
|
int32_t memorySize;
|
||||||
|
void *stackTrace[TD_MEMORY_STACK_TRACE_DEPTH]; // gdb: disassemble /m 0xXXX
|
||||||
} *TdMemoryInfoPtr , TdMemoryInfo;
|
} *TdMemoryInfoPtr , TdMemoryInfo;
|
||||||
|
|
||||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||||
|
|
Loading…
Reference in New Issue