[td-13039] refactor.

This commit is contained in:
Haojun Liao 2022-03-09 10:22:53 +08:00
parent cde4c9a79f
commit 459b0ef442
20 changed files with 895 additions and 945 deletions

View File

@ -56,8 +56,9 @@ typedef struct SColumnDataAgg {
typedef struct SDataBlockInfo { typedef struct SDataBlockInfo {
STimeWindow window; STimeWindow window;
int32_t rows; int32_t rows;
int32_t tupleSize;
int32_t numOfCols; int32_t numOfCols;
int64_t uid; union {int64_t uid; int64_t blockId;};
} SDataBlockInfo; } SDataBlockInfo;
typedef struct SConstantItem { typedef struct SConstantItem {
@ -108,7 +109,7 @@ static FORCE_INLINE int32_t tEncodeDataBlock(void** buf, const SSDataBlock* pBlo
SColumnInfoData* pColData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i); SColumnInfoData* pColData = (SColumnInfoData*)taosArrayGet(pBlock->pDataBlock, i);
tlen += taosEncodeFixedI16(buf, pColData->info.colId); tlen += taosEncodeFixedI16(buf, pColData->info.colId);
tlen += taosEncodeFixedI16(buf, pColData->info.type); tlen += taosEncodeFixedI16(buf, pColData->info.type);
tlen += taosEncodeFixedI16(buf, pColData->info.bytes); tlen += taosEncodeFixedI32(buf, pColData->info.bytes);
int32_t colSz = rows * pColData->info.bytes; int32_t colSz = rows * pColData->info.bytes;
tlen += taosEncodeBinary(buf, pColData->pData, colSz); tlen += taosEncodeBinary(buf, pColData->pData, colSz);
} }
@ -127,7 +128,7 @@ static FORCE_INLINE void* tDecodeDataBlock(const void* buf, SSDataBlock* pBlock)
SColumnInfoData data = {0}; SColumnInfoData data = {0};
buf = taosDecodeFixedI16(buf, &data.info.colId); buf = taosDecodeFixedI16(buf, &data.info.colId);
buf = taosDecodeFixedI16(buf, &data.info.type); buf = taosDecodeFixedI16(buf, &data.info.type);
buf = taosDecodeFixedI16(buf, &data.info.bytes); buf = taosDecodeFixedI32(buf, &data.info.bytes);
int32_t colSz = pBlock->info.rows * data.info.bytes; int32_t colSz = pBlock->info.rows * data.info.bytes;
buf = taosDecodeBinary(buf, (void**)&data.pData, colSz); buf = taosDecodeBinary(buf, (void**)&data.pData, colSz);
taosArrayPush(pBlock->pDataBlock, &data); taosArrayPush(pBlock->pDataBlock, &data);
@ -212,10 +213,23 @@ static FORCE_INLINE void tDeleteSMqConsumeRsp(SMqConsumeRsp* pRsp) {
//====================================================================================================================== //======================================================================================================================
// the following structure shared by parser and executor // the following structure shared by parser and executor
typedef struct SColumn { typedef struct SColumn {
union {
uint64_t uid; uint64_t uid;
int64_t dataBlockId;
};
char name[TSDB_COL_NAME_LEN]; char name[TSDB_COL_NAME_LEN];
int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string) int8_t flag; // column type: normal column, tag, or user-input column (integer/float/string)
SColumnInfo info; union {
int16_t colId;
int16_t slotId;
};
int16_t type;
int32_t bytes;
uint8_t precision;
uint8_t scale;
// SColumnInfo info;
} SColumn; } SColumn;
typedef struct SLimit { typedef struct SLimit {
@ -233,20 +247,23 @@ typedef struct SGroupbyExpr {
bool groupbyTag; // group by tag or column bool groupbyTag; // group by tag or column
} SGroupbyExpr; } SGroupbyExpr;
// the structure for sql function in select clause typedef struct SFunctParam {
typedef struct SSqlExpr { int32_t type;
char token[TSDB_COL_NAME_LEN]; // original token SColumn *pCol;
SSchema resSchema; SVariant param;
} SFunctParam;
int32_t numOfCols; // the structure for sql function in select clause
SColumn* pColumns; // data columns that are required by query typedef struct SExprBasicInfo {
int32_t interBytes; // inter result buffer size SSchema resSchema; // TODO refactor
int32_t interBytes; // inter result buffer size, TODO remove it
int16_t numOfParams; // argument value of each function int16_t numOfParams; // argument value of each function
SVariant param[3]; // parameters are not more than 3 SFunctParam *pParam;
} SSqlExpr; // SVariant param[3]; // parameters are not more than 3
} SExprBasicInfo;
typedef struct SExprInfo { typedef struct SExprInfo {
struct SSqlExpr base; struct SExprBasicInfo base;
struct tExprNode *pExpr; struct tExprNode *pExpr;
} SExprInfo; } SExprInfo;

View File

@ -94,8 +94,8 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock);
int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows); int32_t colDataGetLength(const SColumnInfoData* pColumnInfoData, int32_t numOfRows);
void colDataTrim(SColumnInfoData* pColumnInfoData); void colDataTrim(SColumnInfoData* pColumnInfoData);
size_t colDataGetNumOfCols(const SSDataBlock* pBlock); size_t blockDataGetNumOfCols(const SSDataBlock* pBlock);
size_t colDataGetNumOfRows(const SSDataBlock* pBlock); size_t blockDataGetNumOfRows(const SSDataBlock* pBlock);
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc); int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex, int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,

View File

@ -425,8 +425,9 @@ typedef struct {
}; };
int16_t type; int16_t type;
int16_t bytes; int32_t bytes;
SColumnFilterList flist; uint8_t precision;
uint8_t scale;
} SColumnInfo; } SColumnInfo;
typedef struct { typedef struct {
@ -456,57 +457,6 @@ typedef struct {
int64_t offset; int64_t offset;
} SInterval; } SInterval;
typedef struct {
SMsgHead head;
char version[TSDB_VERSION_LEN];
bool stableQuery; // super table query or not
bool topBotQuery; // TODO used bitwise flag
bool interpQuery; // interp query or not
bool groupbyColumn; // denote if this is a groupby normal column query
bool hasTagResults; // if there are tag values in final result or not
bool timeWindowInterpo; // if the time window start/end required interpolation
bool queryBlockDist; // if query data block distribution
bool stabledev; // super table stddev query
bool tsCompQuery; // is tscomp query
bool simpleAgg;
bool pointInterpQuery; // point interpolation query
bool needReverseScan; // need reverse scan
bool stateWindow; // state window flag
STimeWindow window;
int32_t numOfTables;
int16_t order;
int16_t orderColId;
int16_t numOfCols; // the number of columns will be load from vnode
SInterval interval;
// SSessionWindow sw; // session window
int16_t tagCondLen; // tag length in current query
int16_t colCondLen; // column length in current query
int16_t numOfGroupCols; // num of group by columns
int16_t orderByIdx;
int16_t orderType; // used in group by xx order by xxx
int64_t vgroupLimit; // limit the number of rows for each table, used in order by + limit in stable projection query.
int16_t prjOrder; // global order in super table projection query.
int64_t limit;
int64_t offset;
int32_t queryType; // denote another query process
int16_t numOfOutput; // final output columns numbers
int16_t fillType; // interpolate type
int64_t fillVal; // default value array list
int32_t secondStageOutput;
STsBufInfo tsBuf; // tsBuf info
int32_t numOfTags; // number of tags columns involved
int32_t sqlstrLen; // sql query string
int32_t prevResultLen; // previous result length
int32_t numOfOperator;
int32_t tableScanOperator; // table scan operator. -1 means no scan operator
int32_t udfNum; // number of udf function
int32_t udfContentOffset;
int32_t udfContentLen;
SColumnInfo tableCols[];
} SQueryTableReq;
typedef struct { typedef struct {
int32_t code; int32_t code;
} SQueryTableRsp; } SQueryTableRsp;

View File

@ -20,9 +20,30 @@
extern "C" { extern "C" {
#endif #endif
#include "tbuffer.h"
#include "tcommon.h" #include "tcommon.h"
#include "tvariant.h" #include "tvariant.h"
#include "tbuffer.h"
struct SqlFunctionCtx;
struct SResultRowEntryInfo;
typedef struct SFunctionNode SFunctionNode;
typedef struct SFuncExecEnv {
int32_t calcMemSize;
} SFuncExecEnv;
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx);
typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
typedef struct SFuncExecFuncs {
FExecGetEnv getEnv;
FExecInit init;
FExecProcess process;
FExecFinalize finalize;
} SFuncExecFuncs;
#define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results #define MAX_INTERVAL_TIME_WINDOW 1000000 // maximum allowed time windows in final results
@ -118,57 +139,58 @@ typedef struct SExtTagsInfo {
} SExtTagsInfo; } SExtTagsInfo;
typedef struct SResultDataInfo { typedef struct SResultDataInfo {
int16_t precision;
int16_t scale;
int16_t type; int16_t type;
int16_t bytes; int16_t bytes;
int32_t intermediateBytes; int32_t interBufSize;
} SResultDataInfo; } SResultDataInfo;
#define GET_RES_INFO(ctx) ((ctx)->resultInfo) #define GET_RES_INFO(ctx) ((ctx)->resultInfo)
typedef struct SFunctionFpSet { typedef struct SInputColumnInfoData {
bool (*init)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment int32_t totalRows; // total rows in current columnar data
void (*addInput)(struct SqlFunctionCtx *pCtx); int32_t startRowIndex; // handle started row index
int32_t numOfRows; // the number of rows needs to be handled
// finalizer must be called after all exec has been executed to generated final result. int32_t numOfInputCols; // PTS is not included
void (*finalize)(struct SqlFunctionCtx *pCtx); bool colDataAggIsSet;// if agg is set or not
void (*combine)(struct SqlFunctionCtx *pCtx); SColumnInfoData *pPTS; // primary timestamp column
} SFunctionFpSet; SColumnInfoData **pData;
SColumnDataAgg **pColumnDataAgg;
extern SFunctionFpSet fpSet[1]; } SInputColumnInfoData;
// sql function runtime context // sql function runtime context
typedef struct SqlFunctionCtx { typedef struct SqlFunctionCtx {
int32_t startRow; SInputColumnInfoData input;
int32_t size; // number of rows
SColumnInfoData* pInput;
uint32_t order; // asc|desc
int16_t inputType;
int16_t inputBytes;
SResultDataInfo resDataInfo; SResultDataInfo resDataInfo;
bool hasNull; // null value exist in current block uint32_t order; // asc|desc
bool requireNull; // require null in some function ////////////////////////////////////////////////////////////////
int32_t startRow; // start row index
int32_t size; // handled processed row number
SColumnInfoData* pInput;
SColumnDataAgg agg;
int16_t inputType; // TODO remove it
int16_t inputBytes; // TODO remove it
bool hasNull; // null value exist in current block, TODO remove it
bool requireNull; // require null in some function, TODO remove it
int32_t columnIndex; // TODO remove it
uint8_t currentStage; // record current running step, default: 0
bool isAggSet;
/////////////////////////////////////////////////////////////////
bool stableQuery; bool stableQuery;
int16_t functionId; // function id int16_t functionId; // function id
char * pOutput; // final result output buffer, point to sdata->data char * pOutput; // final result output buffer, point to sdata->data
uint8_t currentStage; // record current running step, default: 0
int64_t startTs; // timestamp range of current query when function is executed on a specific data block int64_t startTs; // timestamp range of current query when function is executed on a specific data block
int32_t numOfParams; int32_t numOfParams;
SVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param SVariant param[4]; // input parameter, e.g., top(k, 20), the number of results for top query is kept in param
int64_t *ptsList; // corresponding timestamp array list int64_t *ptsList; // corresponding timestamp array list
void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/ void *ptsOutputBuf; // corresponding output buffer for timestamp of each result, e.g., top/bottom*/
SVariant tag; SVariant tag;
bool isAggSet;
SColumnDataAgg agg;
struct SResultRowEntryInfo *resultInfo; struct SResultRowEntryInfo *resultInfo;
SExtTagsInfo tagInfo; SExtTagsInfo tagInfo;
SPoint1 start; SPoint1 start;
SPoint1 end; SPoint1 end;
SFuncExecFuncs fpSet;
int32_t columnIndex;
SFunctionFpSet* fpSet;
} SqlFunctionCtx; } SqlFunctionCtx;
enum { enum {
@ -194,9 +216,10 @@ typedef struct tExprNode {
struct SVariant *pVal; // value node struct SVariant *pVal; // value node
struct {// function node struct {// function node
char functionName[FUNCTIONS_NAME_MAX_LENGTH]; char functionName[FUNCTIONS_NAME_MAX_LENGTH]; // todo refactor
int32_t functionId;
int32_t num; int32_t num;
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.
@ -207,7 +230,6 @@ typedef struct tExprNode {
}; };
} tExprNode; } tExprNode;
//TODO create?
void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree); void exprTreeToBinary(SBufferWriter* bw, tExprNode* pExprTree);
void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)); void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *));
@ -294,7 +316,7 @@ tExprNode* exprdup(tExprNode* pTree);
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num); void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num);
void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell); void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell);
int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num); int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock);
bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry); bool isRowEntryCompleted(struct SResultRowEntryInfo* pEntry);
bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry); bool isRowEntryInitialized(struct SResultRowEntryInfo* pEntry);

View File

@ -102,22 +102,6 @@ struct SqlFunctionCtx;
struct SResultRowEntryInfo; struct SResultRowEntryInfo;
struct STimeWindow; struct STimeWindow;
typedef struct SFuncExecEnv {
int32_t calcMemSize;
} SFuncExecEnv;
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
typedef bool (*FExecInit)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
typedef void (*FExecProcess)(struct SqlFunctionCtx *pCtx);
typedef void (*FExecFinalize)(struct SqlFunctionCtx *pCtx);
typedef struct SFuncExecFuncs {
FExecGetEnv getEnv;
FExecInit init;
FExecProcess process;
FExecFinalize finalize;
} SFuncExecFuncs;
typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput); typedef int32_t (*FScalarExecProcess)(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
typedef struct SScalarFuncExecFuncs { typedef struct SScalarFuncExecFuncs {

View File

@ -435,11 +435,11 @@ static int32_t hbCreateThread() {
pthread_attr_init(&thAttr); pthread_attr_init(&thAttr);
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) { // if (pthread_create(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
terrno = TAOS_SYSTEM_ERROR(errno); // terrno = TAOS_SYSTEM_ERROR(errno);
return -1; // return -1;
} // }
pthread_attr_destroy(&thAttr); // pthread_attr_destroy(&thAttr);
return 0; return 0;
} }

View File

@ -53,7 +53,7 @@ TEST(testCase, driverInit_Test) {
// taos_init(); // taos_init();
} }
#if 1 #if 0
TEST(testCase, connect_Test) { TEST(testCase, connect_Test) {
// taos_options(TSDB_OPTION_CONFIGDIR, "/home/ubuntu/first/cfg"); // taos_options(TSDB_OPTION_CONFIGDIR, "/home/ubuntu/first/cfg");
@ -571,15 +571,15 @@ TEST(testCase, projection_query_tables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr); ASSERT_NE(pConn, nullptr);
TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2"); // TAOS_RES* pRes = taos_query(pConn, "create database if not exists abc1 vgroups 2");
if (taos_errno(pRes) != 0) { // if (taos_errno(pRes) != 0) {
printf("error in create db, reason:%s\n", taos_errstr(pRes)); // printf("error in create db, reason:%s\n", taos_errstr(pRes));
} // }
taos_free_result(pRes); // taos_free_result(pRes);
pRes = taos_query(pConn, "use abc1"); TAOS_RES* pRes = taos_query(pConn, "use abc1");
taos_free_result(pRes); taos_free_result(pRes);
#if 0
pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)"); pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
printf("failed to create table tu, reason:%s\n", taos_errstr(pRes)); printf("failed to create table tu, reason:%s\n", taos_errstr(pRes));
@ -592,7 +592,7 @@ TEST(testCase, projection_query_tables) {
} }
taos_free_result(pRes); taos_free_result(pRes);
for(int32_t i = 0; i < 10000000; ++i) { for(int32_t i = 0; i < 10000; ++i) {
char sql[512] = {0}; char sql[512] = {0};
sprintf(sql, "insert into tu values(now+%da, %d)", i, i); sprintf(sql, "insert into tu values(now+%da, %d)", i, i);
TAOS_RES* p = taos_query(pConn, sql); TAOS_RES* p = taos_query(pConn, sql);
@ -602,8 +602,9 @@ TEST(testCase, projection_query_tables) {
taos_free_result(p); taos_free_result(p);
} }
#endif
pRes = taos_query(pConn, "select * from tu"); pRes = taos_query(pConn, "select count(ts) from tu");
if (taos_errno(pRes) != 0) { if (taos_errno(pRes) != 0) {
printf("failed to select from table, reason:%s\n", taos_errstr(pRes)); printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
taos_free_result(pRes); taos_free_result(pRes);
@ -623,8 +624,8 @@ TEST(testCase, projection_query_tables) {
taos_free_result(pRes); taos_free_result(pRes);
taos_close(pConn); taos_close(pConn);
} }
#if 0
#if 0
TEST(testCase, projection_query_stables) { TEST(testCase, projection_query_stables) {
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
ASSERT_NE(pConn, nullptr); ASSERT_NE(pConn, nullptr);

View File

@ -239,7 +239,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, co
return numOfRow1 + numOfRow2; return numOfRow1 + numOfRow2;
} }
size_t colDataGetNumOfCols(const SSDataBlock* pBlock) { size_t blockDataGetNumOfCols(const SSDataBlock* pBlock) {
ASSERT(pBlock); ASSERT(pBlock);
size_t constantCols = (pBlock->pConstantList != NULL)? taosArrayGetSize(pBlock->pConstantList):0; size_t constantCols = (pBlock->pConstantList != NULL)? taosArrayGetSize(pBlock->pConstantList):0;
@ -247,7 +247,7 @@ size_t colDataGetNumOfCols(const SSDataBlock* pBlock) {
return pBlock->info.numOfCols; return pBlock->info.numOfCols;
} }
size_t colDataGetNumOfRows(const SSDataBlock* pBlock) { size_t blockDataGetNumOfRows(const SSDataBlock* pBlock) {
return pBlock->info.rows; return pBlock->info.rows;
} }

View File

@ -160,8 +160,8 @@ TEST(testCase, Datablock_test) {
printf("binary column length:%d\n", *(int32_t*) p1->pData); printf("binary column length:%d\n", *(int32_t*) p1->pData);
ASSERT_EQ(colDataGetNumOfCols(b), 2); ASSERT_EQ(blockDataGetNumOfCols(b), 2);
ASSERT_EQ(colDataGetNumOfRows(b), 40); ASSERT_EQ(blockDataGetNumOfRows(b), 40);
char* pData = colDataGetData(p1, 3); char* pData = colDataGetData(p1, 3);
printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData)); printf("the second row of binary:%s, length:%d\n", (char*)varDataVal(pData), varDataLen(pData));

View File

@ -13,18 +13,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <tdatablock.h>
#include "os.h"
#include "talgo.h"
#include "tcompare.h"
#include "tdataformat.h"
#include "texception.h"
#include "tsdb.h" #include "tsdb.h"
#include "tsdbDef.h" #include "tsdbDef.h"
#include "tsdbFS.h" #include "tsdbFS.h"
#include "tsdbLog.h" #include "tsdbLog.h"
#include "tsdbReadImpl.h" #include "tsdbReadImpl.h"
#include "ttime.h"
#include "texception.h"
#include "os.h"
#include "talgo.h"
#include "tcompare.h"
#include "tdataformat.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "ttime.h"
#include "taosdef.h" #include "taosdef.h"
#include "tlosertree.h" #include "tlosertree.h"
@ -1472,6 +1473,8 @@ static int32_t doCopyRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle, int32_t
return numOfRows + num; return numOfRows + num;
} }
// TODO fix bug for reverse copy data
// TODO handle the null data
// Note: row1 always has high priority // Note: row1 always has high priority
static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, STSRow* row1, static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacity, int32_t numOfRows, STSRow* row1,
STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2, STSRow* row2, int32_t numOfCols, uint64_t uid, STSchema* pSchema1, STSchema* pSchema2,
@ -1515,7 +1518,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
} }
} }
int32_t i = 0, j = 0, k = 0; int32_t i = 0, j = 0, k = 0;
while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) { while(i < numOfCols && (j < numOfColsOfRow1 || k < numOfColsOfRow2)) {
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
@ -1586,7 +1588,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
tdSKvRowGetVal(row, colId, offset, chosen_itr, &sVal); tdSKvRowGetVal(row, colId, offset, chosen_itr, &sVal);
} }
if (colId == pColInfo->info.colId) { if (colId == pColInfo->info.colId) {
if (tdValTypeIsNorm(sVal.valType)) { if (tdValTypeIsNorm(sVal.valType)) {
switch (pColInfo->info.type) { switch (pColInfo->info.type) {
@ -1594,7 +1595,6 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
case TSDB_DATA_TYPE_NCHAR: case TSDB_DATA_TYPE_NCHAR:
memcpy(pData, sVal.val, varDataTLen(sVal.val)); memcpy(pData, sVal.val, varDataTLen(sVal.val));
break; break;
case TSDB_DATA_TYPE_NULL:
case TSDB_DATA_TYPE_BOOL: case TSDB_DATA_TYPE_BOOL:
case TSDB_DATA_TYPE_TINYINT: case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
@ -1625,11 +1625,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
memcpy(pData, sVal.val, pColInfo->info.bytes); memcpy(pData, sVal.val, pColInfo->info.bytes);
} }
} else if (forceSetNull) { } else if (forceSetNull) {
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { colDataAppend(pColInfo, numOfRows, NULL, true);
setVardataNull(pData, pColInfo->info.type);
} else {
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
}
} }
i++; i++;
@ -1640,11 +1636,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
} }
} else { } else {
if(forceSetNull) { if(forceSetNull) {
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) { colDataAppend(pColInfo, numOfRows, NULL, true);
setVardataNull(pData, pColInfo->info.type);
} else {
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
}
} }
i++; i++;
} }
@ -1653,18 +1645,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
if(forceSetNull) { if(forceSetNull) {
while (i < numOfCols) { // the remain columns are all null data while (i < numOfCols) { // the remain columns are all null data
SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i); SColumnInfoData* pColInfo = taosArrayGet(pTsdbReadHandle->pColumns, i);
if (ASCENDING_TRAVERSE(pTsdbReadHandle->order)) { colDataAppend(pColInfo, numOfRows, NULL, true);
pData = (char*)pColInfo->pData + numOfRows * pColInfo->info.bytes;
} else {
pData = (char*)pColInfo->pData + (capacity - numOfRows - 1) * pColInfo->info.bytes;
}
if (pColInfo->info.type == TSDB_DATA_TYPE_BINARY || pColInfo->info.type == TSDB_DATA_TYPE_NCHAR) {
setVardataNull(pData, pColInfo->info.type);
} else {
setNull(pData, pColInfo->info.type, pColInfo->info.bytes);
}
i++; i++;
} }
} }

View File

@ -111,7 +111,6 @@ void clearResultRow(struct STaskRuntimeEnv* pRuntimeEnv, SResultRow* pResultR
struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset); struct SResultRowEntryInfo* getResultCell(const SResultRow* pRow, int32_t index, int32_t* offset);
void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr); void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr);
void* freeColumnInfo(SColumnInfo* pColumnInfo, int32_t numOfCols);
int32_t getRowNumForMultioutput(struct STaskAttr* pQueryAttr, bool topBottomQuery, bool stable); int32_t getRowNumForMultioutput(struct STaskAttr* pQueryAttr, bool topBottomQuery, bool stable);
static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) { static FORCE_INLINE SResultRow *getResultRow(SResultRowInfo *pResultRowInfo, int32_t slot) {

View File

@ -362,8 +362,8 @@ typedef struct STaskParam {
char* tbnameCond; char* tbnameCond;
char* prevResult; char* prevResult;
SArray* pTableIdList; SArray* pTableIdList;
SSqlExpr** pExpr; SExprBasicInfo** pExpr;
SSqlExpr** pSecExpr; SExprBasicInfo** pSecExpr;
SExprInfo* pExprs; SExprInfo* pExprs;
SExprInfo* pSecExprs; SExprInfo* pSecExprs;
@ -448,7 +448,6 @@ 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;
uint32_t resRowSize;
int32_t capacity; int32_t capacity;
} SOptrBasicInfo; } SOptrBasicInfo;
@ -617,8 +616,8 @@ SOperatorInfo* createExchangeOperatorInfo(const SArray* pSources, const SArray*
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo); int32_t repeatTime, int32_t reverseTime, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv); SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo); SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo); SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SArray* pExprInfo, SExecTaskInfo* pTaskInfo);
SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream); SOperatorInfo* createLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream);
@ -650,8 +649,6 @@ SOperatorInfo* createStatewindowOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOper
int32_t numOfOutput); int32_t numOfOutput);
SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr, SOperatorInfo* createSLimitOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
int32_t numOfOutput, void* merger, bool multigroupResult); int32_t numOfOutput, void* merger, bool multigroupResult);
SOperatorInfo* createFilterOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream, SExprInfo* pExpr,
int32_t numOfOutput, SColumnInfo* pCols, int32_t numOfFilter);
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema, SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOfDownstream, SSchema* pSchema,
int32_t numOfOutput); int32_t numOfOutput);
@ -676,16 +673,8 @@ void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOf
void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity); void clearOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity);
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput); void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
int32_t createQueryFunc(SQueriedTableInfo* pTableInfo, int32_t numOfOutput, SExprInfo** pExprInfo, SSqlExpr** pExprMsg,
SColumnInfo* pTagCols, int32_t queryType, void* pMsg, struct SUdfInfo* pUdfInfo);
int32_t createIndirectQueryFuncExprFromMsg(SQueryTableReq* pQueryMsg, int32_t numOfOutput, SExprInfo** pExprInfo,
SSqlExpr** pExpr, SExprInfo* prevExpr, struct SUdfInfo* pUdfInfo);
int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters); int32_t createQueryFilter(char* data, uint16_t len, SFilterInfo** pFilters);
SGroupbyExpr* createGroupbyExprFromMsg(SQueryTableReq* pQueryMsg, SColIndex* pColIndex, int32_t* code);
int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, STaskParam* param, char* start, int32_t initQInfo(STsBufInfo* pTsBufInfo, void* tsdb, void* sourceOptr, SQInfo* pQInfo, STaskParam* param, char* start,
int32_t prevResultLen, void* merger); int32_t prevResultLen, void* merger);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_BUILTINSIMPL_H
#define TDENGINE_BUILTINSIMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "function.h"
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
void functionFinalizer(SqlFunctionCtx *pCtx);
bool getCountFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void countFunction(SqlFunctionCtx *pCtx);
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
void sumFunction(SqlFunctionCtx *pCtx);
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_BUILTINSIMPL_H

View File

@ -83,9 +83,7 @@ static FORCE_INLINE void initResultRowEntry(SResultRowEntryInfo *pResInfo, int32
pResInfo->initialized = true; // the this struct has been initialized flag pResInfo->initialized = true; // the this struct has been initialized flag
pResInfo->complete = false; pResInfo->complete = false;
pResInfo->hasResult = false;
pResInfo->numOfRes = 0; pResInfo->numOfRes = 0;
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen); memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
} }

View File

@ -14,7 +14,9 @@
*/ */
#include "builtins.h" #include "builtins.h"
#include "builtinsimpl.h"
#include "taoserror.h" #include "taoserror.h"
#include "tdatablock.h"
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc); int32_t stubCheckAndGetResultType(SFunctionNode* pFunc);
@ -24,20 +26,20 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.type = FUNCTION_TYPE_COUNT, .type = FUNCTION_TYPE_COUNT,
.classification = FUNC_MGT_AGG_FUNC, .classification = FUNC_MGT_AGG_FUNC,
.checkFunc = stubCheckAndGetResultType, .checkFunc = stubCheckAndGetResultType,
.getEnvFunc = NULL, .getEnvFunc = getCountFuncEnv,
.initFunc = NULL, .initFunc = functionSetup,
.processFunc = NULL, .processFunc = countFunction,
.finalizeFunc = NULL .finalizeFunc = functionFinalizer
}, },
{ {
.name = "sum", .name = "sum",
.type = FUNCTION_TYPE_SUM, .type = FUNCTION_TYPE_SUM,
.classification = FUNC_MGT_AGG_FUNC, .classification = FUNC_MGT_AGG_FUNC,
.checkFunc = stubCheckAndGetResultType, .checkFunc = stubCheckAndGetResultType,
.getEnvFunc = NULL, .getEnvFunc = getSumFuncEnv,
.initFunc = NULL, .initFunc = functionSetup,
.processFunc = NULL, .processFunc = sumFunction,
.finalizeFunc = NULL .finalizeFunc = functionFinalizer
}, },
{ {
.name = "concat", .name = "concat",
@ -54,5 +56,11 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
const int funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition)); const int funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) { int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
switch(pFunc->funcType) {
case FUNCTION_TYPE_COUNT: pFunc->node.resType = (SDataType){.bytes = sizeof(int64_t), .type = TSDB_DATA_TYPE_BIGINT};break;
default:
break;
}
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }

View File

@ -0,0 +1,192 @@
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "builtinsimpl.h"
#include "taggfunction.h"
#include "tdatablock.h"
#define SET_VAL(_info, numOfElem, res) \
do { \
if ((numOfElem) <= 0) { \
break; \
} \
(_info)->numOfRes = (res); \
(_info)->hasResult = DATA_SET_FLAG; \
} while (0)
typedef struct SSumRes {
// int8_t hasResult;
union {
int64_t isum;
uint64_t usum;
double dsum;
};
} SSumRes;
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
if (pResultInfo->initialized) {
return false;
}
if (pCtx->pOutput != NULL) {
memset(pCtx->pOutput, 0, (size_t)pCtx->resDataInfo.bytes);
}
initResultRowEntry(pResultInfo, pCtx->resDataInfo.interBufSize);
return true;
}
static void doFinalizer(SResultRowEntryInfo* pResInfo) { cleanupResultRowEntry(pResInfo); }
void functionFinalizer(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult != DATA_SET_FLAG) {
// setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
}
doFinalizer(pResInfo);
}
bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
pEnv->calcMemSize = sizeof(int64_t);
return true;
}
/*
* count function does need the finalize, if data is missing, the default value, which is 0, is used
* count function does not use the pCtx->interResBuf to keep the intermediate buffer
*/
void countFunction(SqlFunctionCtx *pCtx) {
int32_t numOfElem = 0;
/*
* 1. column data missing (schema modified) causes pCtx->hasNull == true. pCtx->isAggSet == true;
* 2. for general non-primary key columns, pCtx->hasNull may be true or false, pCtx->isAggSet == true;
* 3. for primary key column, pCtx->hasNull always be false, pCtx->isAggSet == false;
*/
SInputColumnInfoData* pInput = &pCtx->input;
SColumnInfoData* pInputCol = pInput->pData[0];
if (pInput->colDataAggIsSet && pInput->totalRows == pInput->numOfRows) {
numOfElem = pInput->numOfRows - pInput->pColumnDataAgg[0]->numOfNull;
ASSERT(numOfElem >= 0);
} else {
if (pInputCol->hasNull) {
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
if (colDataIsNull(pInputCol, pInput->totalRows, i, NULL)) {
continue;
}
numOfElem += 1;
}
} else {
//when counting on the primary time stamp column and no statistics data is presented, use the size value directly.
numOfElem = pInput->numOfRows;
}
}
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
*((int64_t *)buf) += numOfElem;
SET_VAL(pResInfo, numOfElem, 1);
}
#define LIST_ADD_N(_res, _col, _start, _rows, _t, numOfElem) \
do { \
_t *d = (_t *)(_col->pData); \
for (int32_t i = (_start); i < (_rows) + (_start); ++i) { \
if (((_col)->hasNull) && colDataIsNull_f((_col)->nullbitmap, i)) { \
continue; \
}; \
(_res) += (d)[i]; \
(numOfElem)++; \
} \
} while (0)
static void do_sum(SqlFunctionCtx *pCtx) {
int32_t numOfElem = 0;
// Only the pre-computing information loaded and actual data does not loaded
SInputColumnInfoData* pInput = &pCtx->input;
SColumnDataAgg *pAgg = pInput->pColumnDataAgg[0];
int32_t type = pInput->pData[0]->info.type;
if (pInput->colDataAggIsSet) {
numOfElem = pInput->numOfRows - pAgg->numOfNull;
ASSERT(numOfElem >= 0);
SSumRes* pSumInfo = (SSumRes*) pCtx->pOutput;
if (IS_SIGNED_NUMERIC_TYPE(type)) {
pSumInfo->isum += pAgg->sum;
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
pSumInfo->usum += pAgg->sum;
} else if (IS_FLOAT_TYPE(type)) {
pSumInfo->dsum += GET_DOUBLE_VAL((const char*)&(pAgg->sum));
}
} else { // computing based on the true data block
SColumnInfoData* pCol = pInput->pData[0];
int32_t start = pInput->startRowIndex;
int32_t numOfRows = pInput->numOfRows;
SSumRes* pSum = (SSumRes*) pCtx->pOutput;
if (IS_SIGNED_NUMERIC_TYPE(pCtx->inputType)) {
if (pCtx->inputType == TSDB_DATA_TYPE_TINYINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int8_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_SMALLINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int16_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_INT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int32_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) {
LIST_ADD_N(pSum->isum, pCol, start, numOfRows, int64_t, numOfElem);
}
} else if (IS_UNSIGNED_NUMERIC_TYPE(pCtx->inputType)) {
if (pCtx->inputType == TSDB_DATA_TYPE_UTINYINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint8_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_USMALLINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint16_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint32_t, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_UBIGINT) {
LIST_ADD_N(pSum->usum, pCol, start, numOfRows, uint64_t, numOfElem);
}
} else if (pCtx->inputType == TSDB_DATA_TYPE_DOUBLE) {
LIST_ADD_N(pSum->dsum, pCol, start, numOfRows, double, numOfElem);
} else if (pCtx->inputType == TSDB_DATA_TYPE_FLOAT) {
LIST_ADD_N(pSum->dsum, pCol, start, numOfRows, float, numOfElem);
}
}
// data in the check operation are all null, not output
SET_VAL(GET_RES_INFO(pCtx), numOfElem, 1);
}
bool getSumFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
pEnv->calcMemSize = sizeof(SSumRes);
return true;
}
void sumFunction(SqlFunctionCtx *pCtx) {
do_sum(pCtx);
// keep the result data in output buffer, not in the intermediate buffer
// SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
// if (pResInfo->hasResult == DATA_SET_FLAG) {
// set the flag for super table query
// SSumRes *pSum = (SSumRes *)pCtx->pOutput;
// pSum->hasResult = DATA_SET_FLAG;
// }
}

View File

@ -26,19 +26,27 @@ typedef struct SFuncMgtService {
} SFuncMgtService; } SFuncMgtService;
static SFuncMgtService gFunMgtService; static SFuncMgtService gFunMgtService;
static pthread_once_t functionHashTableInit = PTHREAD_ONCE_INIT;
static int32_t initFunctionCode = 0;
// todo refactor static void doInitFunctionHashTable() {
int32_t fmFuncMgtInit() {
gFunMgtService.pFuncNameHashTable = taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); gFunMgtService.pFuncNameHashTable = taosHashInit(funcMgtBuiltinsNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
if (NULL == gFunMgtService.pFuncNameHashTable) { if (NULL == gFunMgtService.pFuncNameHashTable) {
return TSDB_CODE_FAILED; initFunctionCode = TSDB_CODE_FAILED;
return;
} }
for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) { for (int32_t i = 0; i < funcMgtBuiltinsNum; ++i) {
if (TSDB_CODE_SUCCESS != taosHashPut(gFunMgtService.pFuncNameHashTable, funcMgtBuiltins[i].name, strlen(funcMgtBuiltins[i].name), &i, sizeof(int32_t))) { if (TSDB_CODE_SUCCESS != taosHashPut(gFunMgtService.pFuncNameHashTable, funcMgtBuiltins[i].name, strlen(funcMgtBuiltins[i].name), &i, sizeof(int32_t))) {
return TSDB_CODE_FAILED; initFunctionCode = TSDB_CODE_FAILED;
return;
} }
} }
return TSDB_CODE_SUCCESS; }
int32_t fmFuncMgtInit() {
pthread_once(&functionHashTableInit, doInitFunctionHashTable);
return initFunctionCode;
} }
int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) { int32_t fmGetFuncInfo(const char* pFuncName, int32_t* pFuncId, int32_t* pFuncType) {

View File

@ -16,10 +16,10 @@
#include "os.h" #include "os.h"
#include "taosdef.h" #include "taosdef.h"
#include "tmsg.h" #include "tmsg.h"
#include "tglobal.h"
#include "thash.h" #include "thash.h"
#include "ttypes.h" #include "ttypes.h"
#include "function.h"
#include "taggfunction.h" #include "taggfunction.h"
#include "tfill.h" #include "tfill.h"
#include "thistogram.h" #include "thistogram.h"
@ -200,27 +200,47 @@ void cleanupResultRowEntry(struct SResultRowEntryInfo* pCell) {
pCell->initialized = false; pCell->initialized = false;
} }
int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num) { int32_t getNumOfResult(SqlFunctionCtx* pCtx, int32_t num, SSDataBlock* pResBlock) {
int32_t maxOutput = 0; int32_t maxRows = 0;
for (int32_t j = 0; j < num; ++j) { for (int32_t j = 0; j < num; ++j) {
#if 0
int32_t id = pCtx[j].functionId; int32_t id = pCtx[j].functionId;
/* /*
* ts, tag, tagprj function can not decide the output number of current query * ts, tag, tagprj function can not decide the output number of current query
* the number of output result is decided by main output * the number of output result is decided by main output
*/ */
if (/*hasMainFunction && */(id == FUNCTION_TS || id == FUNCTION_TAG || id == FUNCTION_TAGPRJ)) { if (id == FUNCTION_TS || id == FUNCTION_TAG || id == FUNCTION_TAGPRJ) {
continue; continue;
} }
#endif
SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[j]); SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[j]);
if (pResInfo != NULL && maxOutput < pResInfo->numOfRes) { if (pResInfo != NULL && maxRows < pResInfo->numOfRes) {
maxOutput = pResInfo->numOfRes; maxRows = pResInfo->numOfRes;
} }
} }
assert(maxOutput >= 0); assert(maxRows >= 0);
return maxOutput;
blockDataEnsureCapacity(pResBlock, maxRows);
for(int32_t i = 0; i < num; ++i) {
SColumnInfoData* pCol = taosArrayGet(pResBlock->pDataBlock, i);
SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[i]);
if (!pResInfo->hasResult) {
for(int32_t j = 0; j < pResInfo->numOfRes; ++j) {
colDataAppend(pCol, j, NULL, true); // TODO add set null data api
}
} else {
for (int32_t j = 0; j < pResInfo->numOfRes; ++j) {
colDataAppend(pCol, j, GET_ROWCELL_INTERBUF(pResInfo), false);
}
}
}
pResBlock->info.rows = maxRows;
return maxRows;
} }
void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num) { void resetResultRowEntryResult(SqlFunctionCtx* pCtx, int32_t num) {
@ -254,9 +274,9 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
pInfo->bytes = (int16_t)dataBytes; pInfo->bytes = (int16_t)dataBytes;
if (functionId == FUNCTION_INTERP) { if (functionId == FUNCTION_INTERP) {
pInfo->intermediateBytes = sizeof(SInterpInfoDetail); pInfo->interBufSize = sizeof(SInterpInfoDetail);
} else { } else {
pInfo->intermediateBytes = 0; pInfo->interBufSize = 0;
} }
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
@ -266,42 +286,42 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == FUNCTION_TID_TAG) { // todo use struct if (functionId == FUNCTION_TID_TAG) { // todo use struct
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE); pInfo->bytes = (int16_t)(dataBytes + sizeof(int16_t) + sizeof(int64_t) + sizeof(int32_t) + sizeof(int32_t) + VARSTR_HEADER_SIZE);
pInfo->intermediateBytes = 0; pInfo->interBufSize = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == FUNCTION_BLKINFO) { if (functionId == FUNCTION_BLKINFO) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = 16384; pInfo->bytes = 16384;
pInfo->intermediateBytes = 0; pInfo->interBufSize = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == FUNCTION_COUNT) { if (functionId == FUNCTION_COUNT) {
pInfo->type = TSDB_DATA_TYPE_BIGINT; pInfo->type = TSDB_DATA_TYPE_BIGINT;
pInfo->bytes = sizeof(int64_t); pInfo->bytes = sizeof(int64_t);
pInfo->intermediateBytes = 0; pInfo->interBufSize = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == FUNCTION_ARITHM) { if (functionId == FUNCTION_ARITHM) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = 0; pInfo->interBufSize = 0;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == FUNCTION_TS_COMP) { if (functionId == FUNCTION_TS_COMP) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = 1; // this results is compressed ts data, only one byte pInfo->bytes = 1; // this results is compressed ts data, only one byte
pInfo->intermediateBytes = POINTER_BYTES; pInfo->interBufSize = POINTER_BYTES;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
if (functionId == FUNCTION_DERIVATIVE) { if (functionId == FUNCTION_DERIVATIVE) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); // this results is compressed ts data, only one byte pInfo->bytes = sizeof(double); // this results is compressed ts data, only one byte
pInfo->intermediateBytes = sizeof(SDerivInfo); pInfo->interBufSize = sizeof(SDerivInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -310,11 +330,11 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
// if (pUdfInfo->bufSize > 0) { // if (pUdfInfo->bufSize > 0) {
// pInfo->type = TSDB_DATA_TYPE_BINARY; // pInfo->type = TSDB_DATA_TYPE_BINARY;
// pInfo->bytes = pUdfInfo->bufSize; // pInfo->bytes = pUdfInfo->bufSize;
// pInfo->intermediateBytes = pInfo->bytes; // pInfo->interBufSize = pInfo->bytes;
// } else { // } else {
// pInfo->type = pUdfInfo->resType; // pInfo->type = pUdfInfo->resType;
// pInfo->bytes = pUdfInfo->resBytes; // pInfo->bytes = pUdfInfo->resBytes;
// pInfo->intermediateBytes = pInfo->bytes; // pInfo->interBufSize = pInfo->bytes;
// } // }
// //
// return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
@ -323,54 +343,54 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == FUNCTION_MIN || functionId == FUNCTION_MAX) { if (functionId == FUNCTION_MIN || functionId == FUNCTION_MAX) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = (int16_t)(dataBytes + DATA_SET_FLAG_SIZE); pInfo->bytes = (int16_t)(dataBytes + DATA_SET_FLAG_SIZE);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_SUM) { } else if (functionId == FUNCTION_SUM) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = sizeof(SSumInfo); pInfo->bytes = sizeof(SSumInfo);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_AVG) { } else if (functionId == FUNCTION_AVG) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = sizeof(SAvgInfo); pInfo->bytes = sizeof(SAvgInfo);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId >= FUNCTION_RATE && functionId <= FUNCTION_IRATE) { } else if (functionId >= FUNCTION_RATE && functionId <= FUNCTION_IRATE) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(SRateInfo); pInfo->bytes = sizeof(SRateInfo);
pInfo->intermediateBytes = sizeof(SRateInfo); pInfo->interBufSize = sizeof(SRateInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM) { } else if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = (int16_t)(sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param); pInfo->bytes = (int16_t)(sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_SPREAD) { } else if (functionId == FUNCTION_SPREAD) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = sizeof(SSpreadInfo); pInfo->bytes = sizeof(SSpreadInfo);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_APERCT) { } else if (functionId == FUNCTION_APERCT) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1) + sizeof(SHistogramInfo) + sizeof(SAPercentileInfo); pInfo->bytes = sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1) + sizeof(SHistogramInfo) + sizeof(SAPercentileInfo);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_LAST_ROW) { } else if (functionId == FUNCTION_LAST_ROW) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = (int16_t)(sizeof(SLastrowInfo) + dataBytes); pInfo->bytes = (int16_t)(sizeof(SLastrowInfo) + dataBytes);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_TWA) { } else if (functionId == FUNCTION_TWA) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(STwaInfo); pInfo->bytes = sizeof(STwaInfo);
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
} }
@ -385,18 +405,18 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
} }
pInfo->bytes = sizeof(int64_t); pInfo->bytes = sizeof(int64_t);
pInfo->intermediateBytes = sizeof(SSumInfo); pInfo->interBufSize = sizeof(SSumInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_APERCT) { } else if (functionId == FUNCTION_APERCT) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = pInfo->interBufSize =
sizeof(SAPercentileInfo) + sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1); sizeof(SAPercentileInfo) + sizeof(SHistogramInfo) + sizeof(SHistBin) * (MAX_HISTOGRAM_BIN + 1);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else if (functionId == FUNCTION_TWA) { } else if (functionId == FUNCTION_TWA) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = sizeof(STwaInfo); pInfo->interBufSize = sizeof(STwaInfo);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
@ -405,9 +425,9 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
// pInfo->bytes = pUdfInfo->resBytes; // pInfo->bytes = pUdfInfo->resBytes;
// //
// if (pUdfInfo->bufSize > 0) { // if (pUdfInfo->bufSize > 0) {
// pInfo->intermediateBytes = pUdfInfo->bufSize; // pInfo->interBufSize = pUdfInfo->bufSize;
// } else { // } else {
// pInfo->intermediateBytes = pInfo->bytes; // pInfo->interBufSize = pInfo->bytes;
// } // }
// //
// return TSDB_CODE_SUCCESS; // return TSDB_CODE_SUCCESS;
@ -416,39 +436,39 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
if (functionId == FUNCTION_AVG) { if (functionId == FUNCTION_AVG) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = sizeof(SAvgInfo); pInfo->interBufSize = sizeof(SAvgInfo);
} else if (functionId >= FUNCTION_RATE && functionId <= FUNCTION_IRATE) { } else if (functionId >= FUNCTION_RATE && functionId <= FUNCTION_IRATE) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = sizeof(SRateInfo); pInfo->interBufSize = sizeof(SRateInfo);
} else if (functionId == FUNCTION_STDDEV) { } else if (functionId == FUNCTION_STDDEV) {
pInfo->type = TSDB_DATA_TYPE_DOUBLE; pInfo->type = TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = sizeof(SStddevInfo); pInfo->interBufSize = sizeof(SStddevInfo);
} else if (functionId == FUNCTION_MIN || functionId == FUNCTION_MAX) { } else if (functionId == FUNCTION_MIN || functionId == FUNCTION_MAX) {
pInfo->type = (int16_t)dataType; pInfo->type = (int16_t)dataType;
pInfo->bytes = (int16_t)dataBytes; pInfo->bytes = (int16_t)dataBytes;
pInfo->intermediateBytes = dataBytes + DATA_SET_FLAG_SIZE; pInfo->interBufSize = dataBytes + DATA_SET_FLAG_SIZE;
} else if (functionId == FUNCTION_FIRST || functionId == FUNCTION_LAST) { } else if (functionId == FUNCTION_FIRST || functionId == FUNCTION_LAST) {
pInfo->type = (int16_t)dataType; pInfo->type = (int16_t)dataType;
pInfo->bytes = (int16_t)dataBytes; pInfo->bytes = (int16_t)dataBytes;
pInfo->intermediateBytes = (int16_t)(dataBytes + sizeof(SFirstLastInfo)); pInfo->interBufSize = (int16_t)(dataBytes + sizeof(SFirstLastInfo));
} else if (functionId == FUNCTION_SPREAD) { } else if (functionId == FUNCTION_SPREAD) {
pInfo->type = (int16_t)TSDB_DATA_TYPE_DOUBLE; pInfo->type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = sizeof(double); pInfo->bytes = sizeof(double);
pInfo->intermediateBytes = sizeof(SSpreadInfo); pInfo->interBufSize = sizeof(SSpreadInfo);
} else if (functionId == FUNCTION_PERCT) { } else if (functionId == FUNCTION_PERCT) {
pInfo->type = (int16_t)TSDB_DATA_TYPE_DOUBLE; pInfo->type = (int16_t)TSDB_DATA_TYPE_DOUBLE;
pInfo->bytes = (int16_t)sizeof(double); pInfo->bytes = (int16_t)sizeof(double);
pInfo->intermediateBytes = (int16_t)sizeof(SPercentileInfo); pInfo->interBufSize = (int16_t)sizeof(SPercentileInfo);
} else if (functionId == FUNCTION_LEASTSQR) { } else if (functionId == FUNCTION_LEASTSQR) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = TMAX(AVG_FUNCTION_INTER_BUFFER_SIZE, sizeof(SLeastsquaresInfo)); // string pInfo->bytes = TMAX(AVG_FUNCTION_INTER_BUFFER_SIZE, sizeof(SLeastsquaresInfo)); // string
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
} else if (functionId == FUNCTION_FIRST_DST || functionId == FUNCTION_LAST_DST) { } else if (functionId == FUNCTION_FIRST_DST || functionId == FUNCTION_LAST_DST) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = (int16_t)(dataBytes + sizeof(SFirstLastInfo)); pInfo->bytes = (int16_t)(dataBytes + sizeof(SFirstLastInfo));
pInfo->intermediateBytes = pInfo->bytes; pInfo->interBufSize = pInfo->bytes;
} else if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM) { } else if (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM) {
pInfo->type = (int16_t)dataType; pInfo->type = (int16_t)dataType;
pInfo->bytes = (int16_t)dataBytes; pInfo->bytes = (int16_t)dataBytes;
@ -456,15 +476,15 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
size_t size = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param; size_t size = sizeof(STopBotInfo) + (sizeof(tValuePair) + POINTER_BYTES + extLength) * param;
// the output column may be larger than sizeof(STopBotInfo) // the output column may be larger than sizeof(STopBotInfo)
pInfo->intermediateBytes = (int32_t)size; pInfo->interBufSize = (int32_t)size;
} else if (functionId == FUNCTION_LAST_ROW) { } else if (functionId == FUNCTION_LAST_ROW) {
pInfo->type = (int16_t)dataType; pInfo->type = (int16_t)dataType;
pInfo->bytes = (int16_t)dataBytes; pInfo->bytes = (int16_t)dataBytes;
pInfo->intermediateBytes = dataBytes; pInfo->interBufSize = dataBytes;
} else if (functionId == FUNCTION_STDDEV_DST) { } else if (functionId == FUNCTION_STDDEV_DST) {
pInfo->type = TSDB_DATA_TYPE_BINARY; pInfo->type = TSDB_DATA_TYPE_BINARY;
pInfo->bytes = sizeof(SStddevdstInfo); pInfo->bytes = sizeof(SStddevdstInfo);
pInfo->intermediateBytes = (pInfo->bytes); pInfo->interBufSize = (pInfo->bytes);
} else { } else {
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
@ -479,7 +499,7 @@ static bool function_setup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInf
} }
memset(pCtx->pOutput, 0, (size_t)pCtx->resDataInfo.bytes); memset(pCtx->pOutput, 0, (size_t)pCtx->resDataInfo.bytes);
initResultRowEntry(pResultInfo, pCtx->resDataInfo.intermediateBytes); initResultRowEntry(pResultInfo, pCtx->resDataInfo.interBufSize);
return true; return true;
} }
@ -492,9 +512,9 @@ static bool function_setup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInf
*/ */
static void function_finalizer(SqlFunctionCtx *pCtx) { static void function_finalizer(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult != DATA_SET_FLAG) { // if (pResInfo->hasResult != DATA_SET_FLAG) { // TODO set the correct null value
setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); // setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
} // }
doFinalizer(pCtx); doFinalizer(pCtx);
} }
@ -530,7 +550,7 @@ static void count_function(SqlFunctionCtx *pCtx) {
} }
if (numOfElem > 0) { if (numOfElem > 0) {
GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; // GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG;
} }
*((int64_t *)pCtx->pOutput) += numOfElem; *((int64_t *)pCtx->pOutput) += numOfElem;
@ -694,7 +714,7 @@ static void do_sum(SqlFunctionCtx *pCtx) {
SET_VAL(pCtx, notNullElems, 1); SET_VAL(pCtx, notNullElems, 1);
if (notNullElems > 0) { if (notNullElems > 0) {
GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; // GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG;
} }
} }
@ -703,11 +723,11 @@ static void sum_function(SqlFunctionCtx *pCtx) {
// keep the result data in output buffer, not in the intermediate buffer // keep the result data in output buffer, not in the intermediate buffer
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult == DATA_SET_FLAG && pCtx->stableQuery) { // if (pResInfo->hasResult == DATA_SET_FLAG && pCtx->stableQuery) {
// set the flag for super table query // set the flag for super table query
SSumInfo *pSum = (SSumInfo *)pCtx->pOutput; SSumInfo *pSum = (SSumInfo *)pCtx->pOutput;
pSum->hasResult = DATA_SET_FLAG; pSum->hasResult = DATA_SET_FLAG;
} // }
} }
static void sum_func_merge(SqlFunctionCtx *pCtx) { static void sum_func_merge(SqlFunctionCtx *pCtx) {
@ -738,7 +758,7 @@ static void sum_func_merge(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (notNullElems > 0) { if (notNullElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -876,7 +896,7 @@ static void avg_function(SqlFunctionCtx *pCtx) {
pAvgInfo->num += notNullElems; pAvgInfo->num += notNullElems;
if (notNullElems > 0) { if (notNullElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
// keep the data into the final output buffer for super table query since this execution may be the last one // keep the data into the final output buffer for super table query since this execution may be the last one
@ -1192,7 +1212,7 @@ static void min_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
// set the flag for super table query // set the flag for super table query
if (pCtx->stableQuery) { if (pCtx->stableQuery) {
@ -1209,7 +1229,7 @@ static void max_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
// set the flag for super table query // set the flag for super table query
if (pCtx->stableQuery) { if (pCtx->stableQuery) {
@ -1310,7 +1330,7 @@ static void min_func_merge(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (notNullElems > 0) { if (notNullElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -1321,7 +1341,7 @@ static void max_func_merge(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (numOfElem > 0) { if (numOfElem > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -1602,7 +1622,7 @@ static void first_function(SqlFunctionCtx *pCtx) {
} }
SResultRowEntryInfo *pInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pInfo = GET_RES_INFO(pCtx);
pInfo->hasResult = DATA_SET_FLAG; // pInfo->hasResult = DATA_SET_FLAG;
pInfo->complete = true; pInfo->complete = true;
notNullElems++; notNullElems++;
@ -1652,7 +1672,7 @@ static void first_dist_function(SqlFunctionCtx *pCtx) {
first_data_assign_impl(pCtx, data, i); first_data_assign_impl(pCtx, data, i);
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
notNullElems++; notNullElems++;
break; break;
@ -1680,7 +1700,7 @@ static void first_dist_func_merge(SqlFunctionCtx *pCtx) {
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; // GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG;
} }
////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////
@ -1712,7 +1732,7 @@ static void last_function(SqlFunctionCtx *pCtx) {
TSKEY ts = pCtx->ptsList ? GET_TS_DATA(pCtx, i) : 0; TSKEY ts = pCtx->ptsList ? GET_TS_DATA(pCtx, i) : 0;
DO_UPDATE_TAG_COLUMNS(pCtx, ts); DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
pResInfo->complete = true; // set query completed on this column pResInfo->complete = true; // set query completed on this column
notNullElems++; notNullElems++;
break; break;
@ -1727,13 +1747,13 @@ static void last_function(SqlFunctionCtx *pCtx) {
TSKEY ts = pCtx->ptsList ? GET_TS_DATA(pCtx, i) : 0; TSKEY ts = pCtx->ptsList ? GET_TS_DATA(pCtx, i) : 0;
char* buf = GET_ROWCELL_INTERBUF(pResInfo); char* buf = GET_ROWCELL_INTERBUF(pResInfo);
if (pResInfo->hasResult != DATA_SET_FLAG || (*(TSKEY*)buf) < ts) { // if (pResInfo->hasResult != DATA_SET_FLAG || (*(TSKEY*)buf) < ts) {
pResInfo->hasResult = DATA_SET_FLAG; // //pResInfo->hasResult = DATA_SET_FLAG;
memcpy(pCtx->pOutput, data, pCtx->inputBytes); // memcpy(pCtx->pOutput, data, pCtx->inputBytes);
//
*(TSKEY*)buf = ts; // *(TSKEY*)buf = ts;
DO_UPDATE_TAG_COLUMNS(pCtx, ts); // DO_UPDATE_TAG_COLUMNS(pCtx, ts);
} // }
notNullElems++; notNullElems++;
break; break;
@ -1782,7 +1802,7 @@ static void last_dist_function(SqlFunctionCtx *pCtx) {
last_data_assign_impl(pCtx, data, i); last_data_assign_impl(pCtx, data, i);
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
notNullElems++; notNullElems++;
break; break;
@ -1817,7 +1837,7 @@ static void last_dist_func_merge(SqlFunctionCtx *pCtx) {
} }
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; // GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG;
} }
////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////
@ -1832,7 +1852,7 @@ static void last_row_function(SqlFunctionCtx *pCtx) {
assignVal(pCtx->pOutput, pData + (pCtx->size - 1) * pCtx->inputBytes, pCtx->inputBytes, pCtx->inputType); assignVal(pCtx->pOutput, pData + (pCtx->size - 1) * pCtx->inputBytes, pCtx->inputBytes, pCtx->inputType);
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
// set the result to final result buffer in case of super table query // set the result to final result buffer in case of super table query
if (pCtx->stableQuery) { if (pCtx->stableQuery) {
@ -1852,10 +1872,10 @@ static void last_row_function(SqlFunctionCtx *pCtx) {
static void last_row_finalizer(SqlFunctionCtx *pCtx) { static void last_row_finalizer(SqlFunctionCtx *pCtx) {
// do nothing at the first stage // do nothing at the first stage
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
if (pResInfo->hasResult != DATA_SET_FLAG) { // if (pResInfo->hasResult != DATA_SET_FLAG) {
setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); // setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
return; // return;
} // }
GET_RES_INFO(pCtx)->numOfRes = 1; GET_RES_INFO(pCtx)->numOfRes = 1;
doFinalizer(pCtx); doFinalizer(pCtx);
@ -2248,7 +2268,7 @@ static void top_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -2271,7 +2291,7 @@ static void top_func_merge(SqlFunctionCtx *pCtx) {
if (pOutput->num > 0) { if (pOutput->num > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -2305,7 +2325,7 @@ static void bottom_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -2328,7 +2348,7 @@ static void bottom_func_merge(SqlFunctionCtx *pCtx) {
if (pOutput->num > 0) { if (pOutput->num > 0) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -2338,7 +2358,7 @@ static void top_bottom_func_finalizer(SqlFunctionCtx *pCtx) {
// data in temporary list is less than the required number of results, not enough qualified number of results // data in temporary list is less than the required number of results, not enough qualified number of results
STopBotInfo *pRes = GET_ROWCELL_INTERBUF(pResInfo); STopBotInfo *pRes = GET_ROWCELL_INTERBUF(pResInfo);
if (pRes->num == 0) { // no result if (pRes->num == 0) { // no result
assert(pResInfo->hasResult != DATA_SET_FLAG); // assert(pResInfo->hasResult != DATA_SET_FLAG);
// TODO: // TODO:
} }
@ -2457,7 +2477,7 @@ static void percentile_function(SqlFunctionCtx *pCtx) {
} }
SET_VAL(pCtx, notNullElems, 1); SET_VAL(pCtx, notNullElems, 1);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
static void percentile_finalizer(SqlFunctionCtx *pCtx) { static void percentile_finalizer(SqlFunctionCtx *pCtx) {
@ -2538,7 +2558,7 @@ static void apercentile_function(SqlFunctionCtx *pCtx) {
SET_VAL(pCtx, notNullElems, 1); SET_VAL(pCtx, notNullElems, 1);
if (notNullElems > 0) { if (notNullElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
} }
@ -2568,7 +2588,7 @@ static void apercentile_func_merge(SqlFunctionCtx *pCtx) {
} }
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
SET_VAL(pCtx, 1, 1); SET_VAL(pCtx, 1, 1);
} }
@ -2579,18 +2599,18 @@ static void apercentile_finalizer(SqlFunctionCtx *pCtx) {
SAPercentileInfo *pOutput = GET_ROWCELL_INTERBUF(pResInfo); SAPercentileInfo *pOutput = GET_ROWCELL_INTERBUF(pResInfo);
if (pCtx->currentStage == MERGE_STAGE) { if (pCtx->currentStage == MERGE_STAGE) {
if (pResInfo->hasResult == DATA_SET_FLAG) { // check for null // if (pResInfo->hasResult == DATA_SET_FLAG) { // check for null
assert(pOutput->pHisto->numOfElems > 0); // assert(pOutput->pHisto->numOfElems > 0);
//
double ratio[] = {v}; // double ratio[] = {v};
double *res = tHistogramUniform(pOutput->pHisto, ratio, 1); // double *res = tHistogramUniform(pOutput->pHisto, ratio, 1);
//
memcpy(pCtx->pOutput, res, sizeof(double)); // memcpy(pCtx->pOutput, res, sizeof(double));
free(res); // free(res);
} else { // } else {
setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); // setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
return; // return;
} // }
} else { } else {
if (pOutput->pHisto->numOfElems > 0) { if (pOutput->pHisto->numOfElems > 0) {
double ratio[] = {v}; double ratio[] = {v};
@ -2718,7 +2738,7 @@ static void leastsquares_function(SqlFunctionCtx *pCtx) {
pInfo->num += numOfElem; pInfo->num += numOfElem;
if (pInfo->num > 0) { if (pInfo->num > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
SET_VAL(pCtx, numOfElem, 1); SET_VAL(pCtx, numOfElem, 1);
@ -3356,7 +3376,7 @@ static void spread_function(SqlFunctionCtx *pCtx) {
SET_VAL(pCtx, numOfElems, 1); SET_VAL(pCtx, numOfElems, 1);
if (numOfElems > 0) { if (numOfElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
pInfo->hasResult = DATA_SET_FLAG; pInfo->hasResult = DATA_SET_FLAG;
} }
@ -3384,7 +3404,7 @@ void spread_func_merge(SqlFunctionCtx *pCtx) {
pCtx->param[3].d = pData->max; pCtx->param[3].d = pData->max;
} }
GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG; // GET_RES_INFO(pCtx)->hasResult = DATA_SET_FLAG;
} }
void spread_function_finalizer(SqlFunctionCtx *pCtx) { void spread_function_finalizer(SqlFunctionCtx *pCtx) {
@ -3397,10 +3417,10 @@ void spread_function_finalizer(SqlFunctionCtx *pCtx) {
if (pCtx->currentStage == MERGE_STAGE) { if (pCtx->currentStage == MERGE_STAGE) {
assert(pCtx->inputType == TSDB_DATA_TYPE_BINARY); assert(pCtx->inputType == TSDB_DATA_TYPE_BINARY);
if (pResInfo->hasResult != DATA_SET_FLAG) { // if (pResInfo->hasResult != DATA_SET_FLAG) {
setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes); // setNull(pCtx->pOutput, pCtx->resDataInfo.type, pCtx->resDataInfo.bytes);
return; // return;
} // }
SET_DOUBLE_VAL((double *)pCtx->pOutput, pCtx->param[3].d - pCtx->param[0].d); SET_DOUBLE_VAL((double *)pCtx->pOutput, pCtx->param[3].d - pCtx->param[0].d);
} else { } else {
@ -3708,7 +3728,7 @@ static void twa_function(SqlFunctionCtx *pCtx) {
SET_VAL(pCtx, notNullElems, 1); SET_VAL(pCtx, notNullElems, 1);
if (notNullElems > 0) { if (notNullElems > 0) {
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
if (pCtx->stableQuery) { if (pCtx->stableQuery) {
@ -3726,7 +3746,7 @@ void twa_function_copy(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
memcpy(GET_ROWCELL_INTERBUF(pResInfo), pCtx->pInput, (size_t)pCtx->inputBytes); memcpy(GET_ROWCELL_INTERBUF(pResInfo), pCtx->pInput, (size_t)pCtx->inputBytes);
pResInfo->hasResult = ((STwaInfo *)pCtx->pInput)->hasResult; // pResInfo->hasResult = ((STwaInfo *)pCtx->pInput)->hasResult;
} }
void twa_function_finalizer(SqlFunctionCtx *pCtx) { void twa_function_finalizer(SqlFunctionCtx *pCtx) {
@ -3738,7 +3758,7 @@ void twa_function_finalizer(SqlFunctionCtx *pCtx) {
return; return;
} }
assert(pInfo->win.ekey == pInfo->p.key && pInfo->hasResult == pResInfo->hasResult); // assert(pInfo->win.ekey == pInfo->p.key && pInfo->hasResult == pResInfo->hasResult);
if (pInfo->win.ekey == pInfo->win.skey) { if (pInfo->win.ekey == pInfo->win.skey) {
SET_DOUBLE_VAL((double *)pCtx->pOutput, pInfo->p.val); SET_DOUBLE_VAL((double *)pCtx->pOutput, pInfo->p.val);
} else { } else {
@ -3948,7 +3968,7 @@ static void ts_comp_function(SqlFunctionCtx *pCtx) {
} }
SET_VAL(pCtx, pCtx->size, 1); SET_VAL(pCtx, pCtx->size, 1);
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
static void ts_comp_finalize(SqlFunctionCtx *pCtx) { static void ts_comp_finalize(SqlFunctionCtx *pCtx) {
@ -4069,7 +4089,7 @@ static void rate_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
pRateInfo->hasResult = DATA_SET_FLAG; pRateInfo->hasResult = DATA_SET_FLAG;
pResInfo->hasResult = DATA_SET_FLAG; // pResInfo->hasResult = DATA_SET_FLAG;
} }
// keep the data into the final output buffer for super table query since this execution may be the last one // keep the data into the final output buffer for super table query since this execution may be the last one
@ -4083,7 +4103,7 @@ static void rate_func_copy(SqlFunctionCtx *pCtx) {
SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx); SResultRowEntryInfo *pResInfo = GET_RES_INFO(pCtx);
memcpy(GET_ROWCELL_INTERBUF(pResInfo), pCtx->pInput, (size_t)pCtx->inputBytes); memcpy(GET_ROWCELL_INTERBUF(pResInfo), pCtx->pInput, (size_t)pCtx->inputBytes);
pResInfo->hasResult = ((SRateInfo*)pCtx->pInput)->hasResult; // pResInfo->hasResult = ((SRateInfo*)pCtx->pInput)->hasResult;
} }
static void rate_finalizer(SqlFunctionCtx *pCtx) { static void rate_finalizer(SqlFunctionCtx *pCtx) {
@ -4099,7 +4119,7 @@ static void rate_finalizer(SqlFunctionCtx *pCtx) {
// cannot set the numOfIteratedElems again since it is set during previous iteration // cannot set the numOfIteratedElems again since it is set during previous iteration
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
doFinalizer(pCtx); doFinalizer(pCtx);
} }
@ -4139,7 +4159,7 @@ static void irate_function(SqlFunctionCtx *pCtx) {
if (notNullElems > 0) { if (notNullElems > 0) {
pRateInfo->hasResult = DATA_SET_FLAG; pRateInfo->hasResult = DATA_SET_FLAG;
pResInfo->hasResult = DATA_SET_FLAG; // pResInfo->hasResult = DATA_SET_FLAG;
} }
// keep the data into the final output buffer for super table query since this execution may be the last one // keep the data into the final output buffer for super table query since this execution may be the last one
@ -4197,7 +4217,7 @@ static void blockInfo_func(SqlFunctionCtx* pCtx) {
memcpy(pCtx->pOutput, pCtx->pInput, sizeof(int32_t) + len); memcpy(pCtx->pOutput, pCtx->pInput, sizeof(int32_t) + len);
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlockDist* pSrc) { static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlockDist* pSrc) {
@ -4211,10 +4231,10 @@ static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlock
pDist->totalSize += pSrc->totalSize; pDist->totalSize += pSrc->totalSize;
pDist->totalRows += pSrc->totalRows; pDist->totalRows += pSrc->totalRows;
if (pResInfo->hasResult == DATA_SET_FLAG) { // if (pResInfo->hasResult == DATA_SET_FLAG) {
pDist->maxRows = TMAX(pDist->maxRows, pSrc->maxRows); // pDist->maxRows = TMAX(pDist->maxRows, pSrc->maxRows);
pDist->minRows = TMIN(pDist->minRows, pSrc->minRows); // pDist->minRows = TMIN(pDist->minRows, pSrc->minRows);
} else { // } else {
pDist->maxRows = pSrc->maxRows; pDist->maxRows = pSrc->maxRows;
pDist->minRows = pSrc->minRows; pDist->minRows = pSrc->minRows;
@ -4224,7 +4244,7 @@ static void mergeTableBlockDist(SResultRowEntryInfo* pResInfo, const STableBlock
} }
pDist->dataBlockInfos = taosArrayInit(maxSteps, sizeof(SFileBlockInfo)); pDist->dataBlockInfos = taosArrayInit(maxSteps, sizeof(SFileBlockInfo));
taosArraySetSize(pDist->dataBlockInfos, maxSteps); taosArraySetSize(pDist->dataBlockInfos, maxSteps);
} // }
size_t steps = taosArrayGetSize(pSrc->dataBlockInfos); size_t steps = taosArrayGetSize(pSrc->dataBlockInfos);
for (int32_t i = 0; i < steps; ++i) { for (int32_t i = 0; i < steps; ++i) {
@ -4243,7 +4263,7 @@ void block_func_merge(SqlFunctionCtx* pCtx) {
taosArrayDestroy(info.dataBlockInfos); taosArrayDestroy(info.dataBlockInfos);
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
} }
void getPercentiles(STableBlockDist *pTableBlockDist, int64_t totalBlocks, int32_t numOfPercents, void getPercentiles(STableBlockDist *pTableBlockDist, int64_t totalBlocks, int32_t numOfPercents,
@ -4354,7 +4374,7 @@ void blockinfo_func_finalizer(SqlFunctionCtx* pCtx) {
// cannot set the numOfIteratedElems again since it is set during previous iteration // cannot set the numOfIteratedElems again since it is set during previous iteration
pResInfo->numOfRes = 1; pResInfo->numOfRes = 1;
pResInfo->hasResult = DATA_SET_FLAG; //pResInfo->hasResult = DATA_SET_FLAG;
doFinalizer(pCtx); doFinalizer(pCtx);
} }
@ -4381,24 +4401,6 @@ int32_t functionCompatList[] = {
6, 8, 7, 6, 8, 7,
}; };
//typedef struct SFunctionFpSet {
// bool (*init)(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo); // setup the execute environment
// void (*addInput)(struct SqlFunctionCtx *pCtx);
//
// // finalizer must be called after all exec has been executed to generated final result.
// void (*finalize)(struct SqlFunctionCtx *pCtx);
// void (*combine)(struct SqlFunctionCtx *pCtx);
//} SFunctionFpSet;
SFunctionFpSet fpSet[1] = {
{
.init = function_setup,
.addInput = count_function,
.finalize = doFinalizer,
.combine = count_func_merge,
},
};
SAggFunctionInfo aggFunc[35] = {{ SAggFunctionInfo aggFunc[35] = {{
// 0, count function does not invoke the finalize function // 0, count function does not invoke the finalize function
"count", "count",

View File

@ -543,7 +543,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co
pFillCol[i].col.offset = offset; pFillCol[i].col.offset = offset;
pFillCol[i].col.colId = pExprInfo->base.resSchema.colId; pFillCol[i].col.colId = pExprInfo->base.resSchema.colId;
pFillCol[i].tagIndex = -2; pFillCol[i].tagIndex = -2;
pFillCol[i].flag = pExprInfo->base.pColumns->flag; // always be the normal column for table query pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query
// pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId; // pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
pFillCol[i].fillVal.i = fillVal[i]; pFillCol[i].fillVal.i = fillVal[i];