Merge remote-tracking branch 'origin/3.0' into feature/qnode
This commit is contained in:
commit
c9b43b2924
|
@ -163,12 +163,13 @@ void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) {
|
|||
printf("subscribe err\n");
|
||||
return;
|
||||
}
|
||||
/*int32_t cnt = 0;*/
|
||||
int32_t cnt = 0;
|
||||
/*clock_t startTime = clock();*/
|
||||
while (running) {
|
||||
tmq_message_t* tmqmessage = tmq_consumer_poll(tmq, 500);
|
||||
if (tmqmessage) {
|
||||
/*cnt++;*/
|
||||
cnt++;
|
||||
printf("get data\n");
|
||||
msg_process(tmqmessage);
|
||||
tmq_message_destroy(tmqmessage);
|
||||
/*} else {*/
|
||||
|
|
|
@ -57,6 +57,8 @@ typedef enum {
|
|||
TD_ROW_PARTIAL_UPDATE = 2,
|
||||
} TDUpdateConfig;
|
||||
|
||||
#define TD_SUPPORT_UPDATE(u) ((u) > 0)
|
||||
|
||||
typedef enum {
|
||||
TSDB_STATIS_OK = 0, // statis part exist and load successfully
|
||||
TSDB_STATIS_NONE = 1, // statis part not exist
|
||||
|
|
|
@ -222,7 +222,7 @@ typedef struct SFunctParam {
|
|||
// the structure for sql function in select clause
|
||||
typedef struct SResSchame {
|
||||
int8_t type;
|
||||
int32_t colId;
|
||||
int32_t slotId;
|
||||
int32_t bytes;
|
||||
int32_t precision;
|
||||
int32_t scale;
|
||||
|
|
|
@ -136,7 +136,8 @@ static FORCE_INLINE void colDataAppendInt8(SColumnInfoData* pColumnInfoData, uin
|
|||
}
|
||||
|
||||
static FORCE_INLINE void colDataAppendInt16(SColumnInfoData* pColumnInfoData, uint32_t currentRow, int16_t* v) {
|
||||
ASSERT(pColumnInfoData->info.type == TSDB_DATA_TYPE_SMALLINT || pColumnInfoData->info.type == TSDB_DATA_TYPE_USMALLINT);
|
||||
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;
|
||||
}
|
||||
|
@ -210,6 +211,10 @@ SSDataBlock* createOneDataBlock(const SSDataBlock* pDataBlock);
|
|||
|
||||
void blockDebugShowData(const SArray* dataBlocks);
|
||||
|
||||
static FORCE_INLINE int32_t blockEstimateEncodeSize(const SSDataBlock* pBlock) {
|
||||
return blockDataGetSerialMetaSize(pBlock) + (int32_t)ceil(blockDataGetSerialRowSize(pBlock) * pBlock->info.rows);
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data,
|
||||
int8_t compressed) {
|
||||
int32_t colSize = colDataGetLength(pColRes, numOfRows);
|
||||
|
|
|
@ -482,7 +482,7 @@ void tdResetDataCols(SDataCols *pCols);
|
|||
int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
|
||||
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
|
||||
SDataCols *tdFreeDataCols(SDataCols *pCols);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool forceSetNull, TDRowVerT maxVer);
|
||||
|
||||
// ----------------- K-V data row structure
|
||||
/* |<-------------------------------------- len -------------------------------------------->|
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "tarray.h"
|
||||
#include "tdef.h"
|
||||
#include "tconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -129,6 +130,7 @@ void taosCfgDynamicOptions(const char *option, const char *value);
|
|||
void taosAddDataDir(int32_t index, char *v1, int32_t level, int32_t primary);
|
||||
|
||||
struct SConfig *taosGetCfg();
|
||||
int32_t taosAddClientLogCfg(SConfig *pCfg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -260,6 +260,7 @@ typedef struct {
|
|||
|
||||
typedef struct SSchema {
|
||||
int8_t type;
|
||||
int8_t index; // default is 0, not index created
|
||||
col_id_t colId;
|
||||
int32_t bytes;
|
||||
char name[TSDB_COL_NAME_LEN];
|
||||
|
|
|
@ -230,7 +230,7 @@ static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowVa
|
|||
static FORCE_INLINE int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
|
||||
bool isCopyVarData, int8_t colType, int16_t colIdx, int32_t offset,
|
||||
col_id_t colId);
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull);
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
|
|
|
@ -27,6 +27,7 @@ extern "C" {
|
|||
typedef int32_t VarDataOffsetT;
|
||||
typedef uint32_t TDRowLenT;
|
||||
typedef uint8_t TDRowValT;
|
||||
typedef uint64_t TDRowVerT;
|
||||
typedef int16_t col_id_t;
|
||||
typedef int8_t col_type_t;
|
||||
typedef int32_t col_bytes_t;
|
||||
|
@ -141,6 +142,43 @@ typedef struct {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define NUM_TO_STRING(_inputType, _input, _outputBytes, _output) \
|
||||
do { \
|
||||
switch (_inputType) { \
|
||||
case TSDB_DATA_TYPE_TINYINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int8_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UTINYINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint8_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_SMALLINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int16_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_USMALLINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%d", *(uint16_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: \
|
||||
case TSDB_DATA_TYPE_BIGINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%" PRId64, *(int64_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UBIGINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%" PRIu64, *(uint64_t *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_FLOAT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(float *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_DOUBLE: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%f", *(double *)(_input)); \
|
||||
break; \
|
||||
case TSDB_DATA_TYPE_UINT: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%u", *(uint32_t *)(_input)); \
|
||||
break; \
|
||||
default: \
|
||||
snprintf(_output, (int32_t)(_outputBytes), "%d", *(int32_t *)(_input)); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define IS_SIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_TINYINT && (_t) <= TSDB_DATA_TYPE_BIGINT)
|
||||
#define IS_UNSIGNED_NUMERIC_TYPE(_t) ((_t) >= TSDB_DATA_TYPE_UTINYINT && (_t) <= TSDB_DATA_TYPE_UBIGINT)
|
||||
#define IS_FLOAT_TYPE(_t) ((_t) == TSDB_DATA_TYPE_FLOAT || (_t) == TSDB_DATA_TYPE_DOUBLE)
|
||||
|
|
|
@ -135,8 +135,17 @@ bool fmIsTimeorderFunc(int32_t funcId);
|
|||
bool fmIsPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsWindowPseudoColumnFunc(int32_t funcId);
|
||||
bool fmIsWindowClauseFunc(int32_t funcId);
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
|
||||
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
|
||||
|
||||
int32_t fmFuncScanType(int32_t funcId);
|
||||
typedef enum EFuncDataRequired {
|
||||
FUNC_DATA_REQUIRED_ALL_NEEDED = 1,
|
||||
FUNC_DATA_REQUIRED_STATIS_NEEDED,
|
||||
FUNC_DATA_REQUIRED_NO_NEEDED,
|
||||
FUNC_DATA_REQUIRED_DISCARD
|
||||
} EFuncDataRequired;
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
|
||||
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
|
||||
|
|
|
@ -78,6 +78,9 @@ typedef struct {
|
|||
typedef struct {
|
||||
float uptime; // day
|
||||
int8_t has_mnode;
|
||||
int8_t has_qnode;
|
||||
int8_t has_snode;
|
||||
int8_t has_bnode;
|
||||
SMonDiskDesc logdir;
|
||||
SMonDiskDesc tempdir;
|
||||
} SMonDnodeInfo;
|
||||
|
@ -134,8 +137,8 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int32_t expire_time;
|
||||
int32_t timeseries_used;
|
||||
int32_t timeseries_total;
|
||||
int64_t timeseries_used;
|
||||
int64_t timeseries_total;
|
||||
} SMonGrantInfo;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -216,6 +216,7 @@ SNodeList* nodesMakeList();
|
|||
int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListStrictAppend(SNodeList* pList, SNodeptr pNode);
|
||||
int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode);
|
||||
int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode);
|
||||
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||
int32_t nodesListStrictAppendList(SNodeList* pTarget, SNodeList* pSrc);
|
||||
int32_t nodesListPushFront(SNodeList* pList, SNodeptr pNode);
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct SLogicNode {
|
|||
SNode* pConditions;
|
||||
SNodeList* pChildren;
|
||||
struct SLogicNode* pParent;
|
||||
int32_t optimizedFlag;
|
||||
} SLogicNode;
|
||||
|
||||
typedef enum EScanType {
|
||||
|
@ -50,6 +51,8 @@ typedef struct SScanLogicNode {
|
|||
SName tableName;
|
||||
bool showRewrite;
|
||||
double ratio;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int32_t dataRequired;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -84,6 +87,7 @@ typedef struct SVnodeModifLogicNode {
|
|||
typedef struct SExchangeLogicNode {
|
||||
SLogicNode node;
|
||||
int32_t srcGroupId;
|
||||
uint8_t precision;
|
||||
} SExchangeLogicNode;
|
||||
|
||||
typedef enum EWindowType {
|
||||
|
@ -163,7 +167,7 @@ typedef struct SDataBlockDescNode {
|
|||
SNodeList* pSlots;
|
||||
int32_t totalRowSize;
|
||||
int32_t outputRowSize;
|
||||
int16_t precision;
|
||||
uint8_t precision;
|
||||
} SDataBlockDescNode;
|
||||
|
||||
typedef struct SPhysiNode {
|
||||
|
@ -195,20 +199,13 @@ typedef struct SSystemTableScanPhysiNode {
|
|||
int32_t accountId;
|
||||
} SSystemTableScanPhysiNode;
|
||||
|
||||
typedef enum EScanRequired {
|
||||
SCAN_REQUIRED_DATA_NO_NEEDED = 1,
|
||||
SCAN_REQUIRED_DATA_STATIS_NEEDED,
|
||||
SCAN_REQUIRED_DATA_ALL_NEEDED,
|
||||
SCAN_REQUIRED_DATA_DISCARD,
|
||||
} EScanRequired;
|
||||
|
||||
typedef struct STableScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
STimeWindow scanRange;
|
||||
double ratio;
|
||||
EScanRequired scanRequired;
|
||||
SNodeList* pScanReferFuncs;
|
||||
int32_t dataRequired;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
} STableScanPhysiNode;
|
||||
|
||||
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||
|
@ -253,11 +250,11 @@ typedef struct SWinodwPhysiNode {
|
|||
SPhysiNode node;
|
||||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||
SNodeList* pFuncs;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
} SWinodwPhysiNode;
|
||||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
SWinodwPhysiNode window;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
|
|
|
@ -190,6 +190,7 @@ typedef struct SLimitNode {
|
|||
|
||||
typedef struct SStateWindowNode {
|
||||
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pExpr;
|
||||
} SStateWindowNode;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tcommon.h"
|
||||
#include "nodes.h"
|
||||
#include "tcommon.h"
|
||||
|
||||
typedef struct SFilterInfo SFilterInfo;
|
||||
typedef int32_t (*filer_get_col_from_id)(void *, int32_t, void **);
|
||||
|
@ -31,18 +31,18 @@ enum {
|
|||
FLT_OPTION_NEED_UNIQE = 4,
|
||||
};
|
||||
|
||||
typedef struct SFilterColumnParam{
|
||||
typedef struct SFilterColumnParam {
|
||||
int32_t numOfCols;
|
||||
SArray* pDataBlock;
|
||||
SArray *pDataBlock;
|
||||
} SFilterColumnParam;
|
||||
|
||||
extern int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pinfo, uint32_t options);
|
||||
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t** p, SColumnDataAgg *statis, int16_t numOfCols);
|
||||
extern bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, int8_t **p, SColumnDataAgg *statis, int16_t numOfCols);
|
||||
extern int32_t filterSetDataFromSlotId(SFilterInfo *info, void *param);
|
||||
extern int32_t filterSetDataFromColId(SFilterInfo *info, void *param);
|
||||
extern int32_t filterGetTimeRange(SNode *pNode, STimeWindow *win, bool *isStrict);
|
||||
extern int32_t filterConverNcharColumns(SFilterInfo* pFilterInfo, int32_t rows, bool *gotNchar);
|
||||
extern int32_t filterFreeNcharColumns(SFilterInfo* pFilterInfo);
|
||||
extern int32_t filterConverNcharColumns(SFilterInfo *pFilterInfo, int32_t rows, bool *gotNchar);
|
||||
extern int32_t filterFreeNcharColumns(SFilterInfo *pFilterInfo);
|
||||
extern void filterFreeInfo(SFilterInfo *info);
|
||||
extern bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows);
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ int32_t ltrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut
|
|||
int32_t rtrimFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
/* Conversion functions */
|
||||
int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
||||
int32_t winStartTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
|
|
@ -44,7 +44,7 @@ extern "C" {
|
|||
|
||||
typedef struct TdFile *TdFilePtr;
|
||||
|
||||
#define TD_FILE_CTEATE 0x0001
|
||||
#define TD_FILE_CREATE 0x0001
|
||||
#define TD_FILE_WRITE 0x0002
|
||||
#define TD_FILE_READ 0x0004
|
||||
#define TD_FILE_TRUNC 0x0008
|
||||
|
|
|
@ -39,7 +39,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen);
|
|||
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen);
|
||||
int32_t taosGetCpuInfo(char *cpuModel, int32_t maxLen, float *numOfCores);
|
||||
int32_t taosGetCpuCores(float *numOfCores);
|
||||
int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
||||
void taosGetCpuUsage(double *cpu_system, double *cpu_engine);
|
||||
int32_t taosGetTotalMemory(int64_t *totalKB);
|
||||
int32_t taosGetProcMemory(int64_t *usedKB);
|
||||
int32_t taosGetSysMemory(int64_t *usedKB);
|
||||
|
|
|
@ -597,6 +597,8 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_ROLLUP_OPTION TAOS_DEF_ERROR_CODE(0, 0x2622)
|
||||
#define TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION TAOS_DEF_ERROR_CODE(0, 0x2623)
|
||||
#define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624)
|
||||
#define TSDB_CODE_PAR_INVALID_OPTION_UNIT TAOS_DEF_ERROR_CODE(0, 0x2625)
|
||||
#define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -188,7 +188,24 @@ typedef struct SRequestSendRecvBody {
|
|||
|
||||
#define ERROR_MSG_BUF_DEFAULT_SIZE 512
|
||||
|
||||
enum {
|
||||
RES_TYPE__QUERY = 1,
|
||||
RES_TYPE__TMQ,
|
||||
};
|
||||
|
||||
#define TD_RES_QUERY(res) (*(int8_t*)res == RES_TYPE__QUERY)
|
||||
#define TD_RES_TMQ(res) (*(int8_t*)res == RES_TYPE__TMQ)
|
||||
|
||||
typedef struct SMqRspObj {
|
||||
int8_t resType;
|
||||
char* topic;
|
||||
void* vg;
|
||||
SArray* res; // SArray<SReqResultInfo>
|
||||
int32_t resIter;
|
||||
} SMqRspObj;
|
||||
|
||||
typedef struct SRequestObj {
|
||||
int8_t resType; // query or tmq
|
||||
uint64_t requestId;
|
||||
int32_t type; // request type
|
||||
STscObj* pTscObj;
|
||||
|
@ -205,6 +222,25 @@ typedef struct SRequestObj {
|
|||
SRequestSendRecvBody body;
|
||||
} SRequestObj;
|
||||
|
||||
static FORCE_INLINE SReqResultInfo* tmqGetCurResInfo(TAOS_RES* res) {
|
||||
SMqRspObj* msg = (SMqRspObj*)res;
|
||||
int32_t resIter = msg->resIter == -1 ? 0 : msg->resIter;
|
||||
return (SReqResultInfo*)taosArrayGet(msg->res, resIter);
|
||||
}
|
||||
|
||||
static FORCE_INLINE SReqResultInfo* tmqGetNextResInfo(TAOS_RES* res) {
|
||||
SMqRspObj* msg = (SMqRspObj*)res;
|
||||
if (++msg->resIter < taosArrayGetSize(msg->res)) {
|
||||
return (SReqResultInfo*)taosArrayGet(msg->res, msg->resIter);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static FORCE_INLINE SReqResultInfo* tscGetCurResInfo(TAOS_RES* res) {
|
||||
if (TD_RES_QUERY(res)) return &(((SRequestObj*)res)->body.resInfo);
|
||||
return tmqGetCurResInfo(res);
|
||||
}
|
||||
|
||||
extern SAppInfo appInfo;
|
||||
extern int32_t clientReqRefPool;
|
||||
extern int32_t clientConnRefPool;
|
||||
|
@ -244,14 +280,17 @@ void initMsgHandleFp();
|
|||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port);
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr);
|
||||
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
|
||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery);
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4);
|
||||
void doSetOneRowPtr(SReqResultInfo* pResultInfo);
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows,
|
||||
bool convertUcs4);
|
||||
void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4);
|
||||
|
||||
// --- heartbeat
|
||||
// global, called by mgmt
|
||||
|
|
|
@ -177,6 +177,7 @@ void *createRequest(STscObj *pObj, __taos_async_fn_t fp, void *param, int32_t ty
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pRequest->resType = RES_TYPE__QUERY;
|
||||
pRequest->pDb = getDbOfConnection(pObj);
|
||||
pRequest->requestId = generateRequestId();
|
||||
pRequest->metric.start = taosGetTimestampUs();
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
static int32_t initEpSetFromCfg(const char* firstEp, const char* secondEp, SCorEpSet* pEpSet);
|
||||
static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest);
|
||||
static void destroySendMsgInfo(SMsgSendInfo* pMsgBody);
|
||||
static int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp);
|
||||
|
||||
static bool stringLengthCheck(const char* str, size_t maxsize) {
|
||||
if (str == NULL) {
|
||||
|
@ -42,7 +41,6 @@ static char* getClusterKey(const char* user, const char* auth, const char* ip, i
|
|||
|
||||
static STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __taos_async_fn_t fp, void* param,
|
||||
SAppInstInfo* pAppInfo);
|
||||
static void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t numOfCols);
|
||||
|
||||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port) {
|
||||
|
@ -176,7 +174,7 @@ int32_t execLocalCmd(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
SRetrieveTableRsp* pRsp = NULL;
|
||||
int32_t code = qExecCommand(pQuery->pRoot, &pRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pRsp) {
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp);
|
||||
code = setQueryResultFromRsp(&pRequest->body.resInfo, pRsp, false);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -211,13 +209,11 @@ int32_t execDdlQuery(SRequestObj* pRequest, SQuery* pQuery) {
|
|||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList) {
|
||||
pRequest->type = pQuery->msgType;
|
||||
SPlanContext cxt = {
|
||||
.queryId = pRequest->requestId,
|
||||
SPlanContext cxt = {.queryId = pRequest->requestId,
|
||||
.acctId = pRequest->pTscObj->acctId,
|
||||
.mgmtEpSet = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp),
|
||||
.pAstRoot = pQuery->pRoot,
|
||||
.showRewrite = pQuery->showRewrite
|
||||
};
|
||||
.showRewrite = pQuery->showRewrite};
|
||||
int32_t code = qCreateQueryPlan(&cxt, pPlan, pNodeList);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
|
@ -254,7 +250,8 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList
|
|||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, &res);
|
||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
||||
pRequest->metric.start, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
if (pRequest->body.queryJob != 0) {
|
||||
schedulerFreeJob(pRequest->body.queryJob);
|
||||
|
@ -320,7 +317,7 @@ SRequestObj* execQueryImpl(STscObj* pTscObj, const char* sql, int sqlLen) {
|
|||
}
|
||||
|
||||
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
||||
SCatalog *pCatalog = NULL;
|
||||
SCatalog* pCatalog = NULL;
|
||||
int32_t code = 0;
|
||||
int32_t dbNum = taosArrayGetSize(pRequest->dbList);
|
||||
int32_t tblNum = taosArrayGetSize(pRequest->tableList);
|
||||
|
@ -337,7 +334,7 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
|||
SEpSet epset = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
|
||||
|
||||
for (int32_t i = 0; i < dbNum; ++i) {
|
||||
char *dbFName = taosArrayGet(pRequest->dbList, i);
|
||||
char* dbFName = taosArrayGet(pRequest->dbList, i);
|
||||
|
||||
code = catalogRefreshDBVgInfo(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, dbFName);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -346,7 +343,7 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
|||
}
|
||||
|
||||
for (int32_t i = 0; i < tblNum; ++i) {
|
||||
SName *tableName = taosArrayGet(pRequest->tableList, i);
|
||||
SName* tableName = taosArrayGet(pRequest->tableList, i);
|
||||
|
||||
code = catalogRefreshTableMeta(pCatalog, pTscObj->pAppInfo->pTransporter, &epset, tableName, -1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -357,7 +354,6 @@ int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest) {
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
SRequestObj* execQuery(STscObj* pTscObj, const char* sql, int sqlLen) {
|
||||
SRequestObj* pRequest = NULL;
|
||||
int32_t retryNum = 0;
|
||||
|
@ -509,7 +505,8 @@ static void destroySendMsgInfo(SMsgSendInfo* pMsgBody) {
|
|||
}
|
||||
|
||||
bool persistConnForSpecificMsg(void* parenct, tmsg_t msgType) {
|
||||
return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP || msgType == TDMT_VND_QUERY_HEARTBEAT_RSP;
|
||||
return msgType == TDMT_VND_QUERY_RSP || msgType == TDMT_VND_FETCH_RSP || msgType == TDMT_VND_RES_READY_RSP ||
|
||||
msgType == TDMT_VND_QUERY_HEARTBEAT_RSP;
|
||||
}
|
||||
|
||||
void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
||||
|
@ -536,10 +533,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
|
|||
int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start;
|
||||
if (pMsg->code == TSDB_CODE_SUCCESS) {
|
||||
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%" PRIx64, pRequest->self,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId);
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId);
|
||||
} else {
|
||||
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%" PRIx64, pRequest->self,
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed/1000, pRequest->requestId);
|
||||
TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed / 1000, pRequest->requestId);
|
||||
}
|
||||
|
||||
taosReleaseRef(clientReqRefPool, pSendInfo->requestObjRefId);
|
||||
|
@ -590,7 +587,7 @@ TAOS* taos_connect_l(const char* ip, int ipLen, const char* user, int userLen, c
|
|||
return taos_connect(ipStr, userStr, passStr, dbStr, port);
|
||||
}
|
||||
|
||||
static void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
|
||||
void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
|
||||
for (int32_t i = 0; i < pResultInfo->numOfCols; ++i) {
|
||||
SResultColumn* pCol = &pResultInfo->pCol[i];
|
||||
|
||||
|
@ -616,7 +613,7 @@ static void doSetOneRowPtr(SReqResultInfo* pResultInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) {
|
||||
void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr, bool convertUcs4) {
|
||||
assert(pRequest != NULL);
|
||||
SReqResultInfo* pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
|
@ -637,7 +634,7 @@ void* doFetchRow(SRequestObj* pRequest, bool setupOneRowPtr) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData);
|
||||
pRequest->code = setQueryResultFromRsp(&pRequest->body.resInfo, (SRetrieveTableRsp*)pResInfo->pData, convertUcs4);
|
||||
if (pRequest->code != TSDB_CODE_SUCCESS) {
|
||||
pResultInfo->numOfRows = 0;
|
||||
return NULL;
|
||||
|
@ -735,7 +732,43 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) {
|
||||
static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int32_t numOfCols, int32_t* colLength) {
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
int32_t type = pResultInfo->fields[i].type;
|
||||
int32_t bytes = pResultInfo->fields[i].bytes;
|
||||
|
||||
if (type == TSDB_DATA_TYPE_NCHAR && colLength[i] > 0) {
|
||||
char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]);
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pResultInfo->convertBuf[i] = p;
|
||||
|
||||
SResultColumn* pCol = &pResultInfo->pCol[i];
|
||||
for (int32_t j = 0; j < numOfRows; ++j) {
|
||||
if (pCol->offset[j] != -1) {
|
||||
char* pStart = pCol->offset[j] + pCol->pData;
|
||||
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p));
|
||||
ASSERT(len <= bytes);
|
||||
|
||||
varDataSetLen(p, len);
|
||||
pCol->offset[j] = (p - pResultInfo->convertBuf[i]);
|
||||
p += (len + VARSTR_HEADER_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i];
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i].pData;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows,
|
||||
bool convertUcs4) {
|
||||
assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL);
|
||||
if (numOfRows == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -767,37 +800,11 @@ int32_t setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32
|
|||
}
|
||||
|
||||
// convert UCS4-LE encoded character to native multi-bytes character in current data block.
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
int32_t type = pResultInfo->fields[i].type;
|
||||
int32_t bytes = pResultInfo->fields[i].bytes;
|
||||
|
||||
if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
char* p = taosMemoryRealloc(pResultInfo->convertBuf[i], colLength[i]);
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pResultInfo->convertBuf[i] = p;
|
||||
|
||||
SResultColumn* pCol = &pResultInfo->pCol[i];
|
||||
for (int32_t j = 0; j < numOfRows; ++j) {
|
||||
if (pCol->offset[j] != -1) {
|
||||
pStart = pCol->offset[j] + pCol->pData;
|
||||
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(pStart), varDataLen(pStart), varDataVal(p));
|
||||
ASSERT(len <= bytes);
|
||||
|
||||
varDataSetLen(p, len);
|
||||
pCol->offset[j] = (p - pResultInfo->convertBuf[i]);
|
||||
p += (len + VARSTR_HEADER_SIZE);
|
||||
}
|
||||
if (convertUcs4) {
|
||||
code = doConvertUCS4(pResultInfo, numOfRows, numOfCols, colLength);
|
||||
}
|
||||
|
||||
pResultInfo->pCol[i].pData = pResultInfo->convertBuf[i];
|
||||
pResultInfo->row[i] = pResultInfo->pCol[i].pData;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return code;
|
||||
}
|
||||
|
||||
char* getDbOfConnection(STscObj* pObj) {
|
||||
|
@ -829,7 +836,7 @@ void resetConnectDB(STscObj* pTscObj) {
|
|||
taosThreadMutexUnlock(&pTscObj->mutex);
|
||||
}
|
||||
|
||||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp) {
|
||||
int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableRsp* pRsp, bool convertUcs4) {
|
||||
assert(pResultInfo != NULL && pRsp != NULL);
|
||||
|
||||
pResultInfo->pRspMsg = (const char*)pRsp;
|
||||
|
@ -842,5 +849,6 @@ int32_t setQueryResultFromRsp(SReqResultInfo* pResultInfo, const SRetrieveTableR
|
|||
|
||||
// TODO handle the compressed case
|
||||
pResultInfo->totalRows += pResultInfo->numOfRows;
|
||||
return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows);
|
||||
return setResultDataPtr(pResultInfo, pResultInfo->fields, pResultInfo->numOfCols, pResultInfo->numOfRows,
|
||||
convertUcs4);
|
||||
}
|
||||
|
|
|
@ -135,8 +135,7 @@ int taos_field_count(TAOS_RES *res) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
SReqResultInfo *pResInfo = &pRequest->body.resInfo;
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
return pResInfo->numOfCols;
|
||||
}
|
||||
|
||||
|
@ -147,7 +146,7 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SReqResultInfo *pResInfo = &(((SRequestObj *)res)->body.resInfo);
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
return pResInfo->userFields;
|
||||
}
|
||||
|
||||
|
@ -164,13 +163,36 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (TD_RES_QUERY(res)) {
|
||||
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 NULL;
|
||||
}
|
||||
|
||||
return doFetchRow(pRequest, true);
|
||||
return doFetchRow(pRequest, true, true);
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SMqRspObj *msg = ((SMqRspObj *)res);
|
||||
SReqResultInfo *pResultInfo = taosArrayGet(msg->res, msg->resIter);
|
||||
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
|
||||
if (pResultInfo->row == NULL) {
|
||||
msg->resIter++;
|
||||
pResultInfo = taosArrayGet(msg->res, msg->resIter);
|
||||
doSetOneRowPtr(pResultInfo);
|
||||
pResultInfo->current += 1;
|
||||
}
|
||||
|
||||
return pResultInfo->row;
|
||||
|
||||
} else {
|
||||
// assert to avoid uninitialization error
|
||||
ASSERT(0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
|
||||
|
@ -262,12 +284,12 @@ int *taos_fetch_lengths(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return ((SRequestObj *)res)->body.resInfo.length;
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
return pResInfo->length;
|
||||
}
|
||||
|
||||
TAOS_ROW *taos_result_block(TAOS_RES *res) {
|
||||
SRequestObj* pRequest = (SRequestObj*) res;
|
||||
if (pRequest == NULL) {
|
||||
if (res == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -276,7 +298,8 @@ TAOS_ROW *taos_result_block(TAOS_RES *res) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return &pRequest->body.resInfo.row;
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
return &pResInfo->row;
|
||||
}
|
||||
|
||||
// todo intergrate with tDataTypes
|
||||
|
@ -315,7 +338,7 @@ const char *taos_data_type(int type) {
|
|||
const char *taos_get_client_info() { return version; }
|
||||
|
||||
int taos_affected_rows(TAOS_RES *res) {
|
||||
if (res == NULL) {
|
||||
if (res == NULL || TD_RES_TMQ(res)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -325,12 +348,17 @@ int taos_affected_rows(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
int taos_result_precision(TAOS_RES *res) {
|
||||
SRequestObj* pRequest = (SRequestObj*) res;
|
||||
if (pRequest == NULL) {
|
||||
if (res == NULL) {
|
||||
return TSDB_TIME_PRECISION_MILLI;
|
||||
}
|
||||
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
return pRequest->body.resInfo.precision;
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *info = tmqGetCurResInfo(res);
|
||||
return info->precision;
|
||||
}
|
||||
return TSDB_TIME_PRECISION_MILLI;
|
||||
}
|
||||
|
||||
int taos_select_db(TAOS *taos, const char *db) {
|
||||
|
@ -372,31 +400,29 @@ void taos_stop_query(TAOS_RES *res) {
|
|||
}
|
||||
|
||||
bool taos_is_null(TAOS_RES *res, int32_t row, int32_t col) {
|
||||
SRequestObj *pRequestObj = res;
|
||||
SReqResultInfo *pResultInfo = &pRequestObj->body.resInfo;
|
||||
SReqResultInfo *pResultInfo = tscGetCurResInfo(res);
|
||||
if (col >= pResultInfo->numOfCols || col < 0 || row >= pResultInfo->numOfRows || row < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
SResultColumn *pCol = &pRequestObj->body.resInfo.pCol[col];
|
||||
SResultColumn *pCol = &pResultInfo->pCol[col];
|
||||
return colDataIsNull_f(pCol->nullbitmap, row);
|
||||
}
|
||||
|
||||
bool taos_is_update_query(TAOS_RES *res) {
|
||||
return taos_num_fields(res) == 0;
|
||||
}
|
||||
bool taos_is_update_query(TAOS_RES *res) { return taos_num_fields(res) == 0; }
|
||||
|
||||
int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) {
|
||||
int32_t numOfRows = 0;
|
||||
/*int32_t code = */taos_fetch_block_s(res, &numOfRows, rows);
|
||||
/*int32_t code = */ taos_fetch_block_s(res, &numOfRows, rows);
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
if (pRequest == NULL) {
|
||||
int taos_fetch_block_s(TAOS_RES *res, int *numOfRows, TAOS_ROW *rows) {
|
||||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (TD_RES_QUERY(res)) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
|
||||
(*rows) = NULL;
|
||||
(*numOfRows) = 0;
|
||||
|
@ -406,7 +432,7 @@ int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
doFetchRow(pRequest, false);
|
||||
doFetchRow(pRequest, false, true);
|
||||
|
||||
// TODO refactor
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
@ -415,47 +441,74 @@ int taos_fetch_block_s(TAOS_RES *res, int* numOfRows, TAOS_ROW *rows) {
|
|||
(*rows) = pResultInfo->row;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
return pRequest->code;
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
|
||||
if (pResultInfo == NULL) return -1;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*rows) = pResultInfo->row;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
return 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int taos_fetch_raw_block(TAOS_RES *res, int* numOfRows, void** pData) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
if (pRequest == NULL) {
|
||||
int taos_fetch_raw_block(TAOS_RES *res, int *numOfRows, void **pData) {
|
||||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (TD_RES_QUERY(res)) {
|
||||
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);
|
||||
doFetchRow(pRequest, false, false);
|
||||
|
||||
SReqResultInfo *pResultInfo = &pRequest->body.resInfo;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void*) pResultInfo->pData;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
|
||||
return 0;
|
||||
|
||||
} else if (TD_RES_TMQ(res)) {
|
||||
SReqResultInfo *pResultInfo = tmqGetNextResInfo(res);
|
||||
if (pResultInfo == NULL) return -1;
|
||||
|
||||
pResultInfo->current = pResultInfo->numOfRows;
|
||||
(*numOfRows) = pResultInfo->numOfRows;
|
||||
(*pData) = (void *)pResultInfo->pData;
|
||||
return 0;
|
||||
|
||||
} else {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int *taos_get_column_data_offset(TAOS_RES *res, int columnIndex) {
|
||||
SRequestObj *pRequest = (SRequestObj *)res;
|
||||
if (pRequest == NULL) {
|
||||
if (res == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t numOfFields = taos_num_fields(pRequest);
|
||||
int32_t numOfFields = taos_num_fields(res);
|
||||
if (columnIndex < 0 || columnIndex >= numOfFields || numOfFields == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
TAOS_FIELD* pField = &pRequest->body.resInfo.userFields[columnIndex];
|
||||
SReqResultInfo *pResInfo = tscGetCurResInfo(res);
|
||||
TAOS_FIELD *pField = &pResInfo->userFields[columnIndex];
|
||||
if (!IS_VAR_DATA_TYPE(pField->type)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pRequest->body.resInfo.pCol[columnIndex].offset;
|
||||
return pResInfo->pCol[columnIndex].offset;
|
||||
}
|
||||
|
||||
int taos_validate_sql(TAOS *taos, const char *sql) { return true; }
|
||||
|
@ -485,7 +538,8 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
|||
// TODO
|
||||
}
|
||||
|
||||
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char* topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp, void *param, int interval) {
|
||||
TAOS_SUB *taos_subscribe(TAOS *taos, int restart, const char *topic, const char *sql, TAOS_SUBSCRIBE_CALLBACK fp,
|
||||
void *param, int interval) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
@ -564,7 +618,7 @@ int taos_stmt_num_params(TAOS_STMT *stmt, int *nums) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int taos_stmt_add_batch(TAOS_STMT* stmt) {
|
||||
int taos_stmt_add_batch(TAOS_STMT *stmt) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
@ -574,7 +628,7 @@ TAOS_RES *taos_stmt_use_result(TAOS_STMT *stmt) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind) {
|
||||
int taos_stmt_bind_param_batch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind) {
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ int32_t processRetrieveMnodeRsp(void* param, const SDataBuf* pMsg, int32_t code)
|
|||
pResInfo->completed = pRetrieve->completed;
|
||||
|
||||
pResInfo->current = 0;
|
||||
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
|
||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
|
||||
pRetrieve->completed, pRequest->body.showInfo.execId);
|
||||
|
@ -225,7 +225,7 @@ int32_t processRetrieveVndRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
pResInfo->pData = pFetchRsp->data;
|
||||
|
||||
pResInfo->current = 0;
|
||||
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
// setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
|
||||
|
||||
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pFetchRsp->numOfRows,
|
||||
pFetchRsp->completed, pRequest->body.showInfo.execId);
|
||||
|
|
|
@ -17,25 +17,19 @@
|
|||
#include "clientLog.h"
|
||||
#include "parser.h"
|
||||
#include "planner.h"
|
||||
#include "scheduler.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tmsgtype.h"
|
||||
#include "tpagedbuf.h"
|
||||
#include "tqueue.h"
|
||||
#include "tref.h"
|
||||
|
||||
typedef struct {
|
||||
int32_t curBlock;
|
||||
int32_t curRow;
|
||||
void** uData;
|
||||
} SMqRowIter;
|
||||
|
||||
struct tmq_message_t {
|
||||
SMqPollRsp msg;
|
||||
char* topic;
|
||||
void* vg;
|
||||
SMqRowIter iter;
|
||||
SArray* res; // SArray<SReqResultInfo>
|
||||
int32_t resIter;
|
||||
};
|
||||
|
||||
struct tmq_list_t {
|
||||
|
@ -849,7 +843,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
if (msgEpoch < tmqEpoch) {
|
||||
/*printf("discard rsp epoch %d, current epoch %d\n", msgEpoch, tmqEpoch);*/
|
||||
/*tsem_post(&tmq->rspSem);*/
|
||||
tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch, tmqEpoch);
|
||||
tscWarn("msg discard from vg %d since from earlier epoch, rsp epoch %d, current epoch %d", pParam->vgId, msgEpoch,
|
||||
tmqEpoch);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -886,8 +881,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
memcpy(pRsp, pMsg->pData, sizeof(SMqRspHead));
|
||||
tDecodeSMqPollRsp(POINTER_SHIFT(pMsg->pData, sizeof(SMqRspHead)), &pRsp->msg);
|
||||
pRsp->iter.curBlock = 0;
|
||||
pRsp->iter.curRow = 0;
|
||||
/*pRsp->iter.curBlock = 0;*/
|
||||
/*pRsp->iter.curRow = 0;*/
|
||||
// TODO: alloc mem
|
||||
/*pRsp->*/
|
||||
/*printf("rsp commit off:%ld rsp off:%ld has data:%d\n", pRsp->committedOffset, pRsp->rspOffset, pRsp->numOfTopics);*/
|
||||
|
@ -899,8 +894,8 @@ int32_t tmqPollCb(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
}
|
||||
#endif
|
||||
|
||||
tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pParam->pVg->vgId, pRsp->msg.reqOffset,
|
||||
pRsp->msg.rspOffset);
|
||||
tscDebug("consumer %ld recv poll: vg %d, req offset %ld, rsp offset %ld", tmq->consumerId, pParam->pVg->vgId,
|
||||
pRsp->msg.reqOffset, pRsp->msg.rspOffset);
|
||||
|
||||
pRsp->vg = pParam->pVg;
|
||||
taosWriteQitem(tmq->mqueue, pRsp);
|
||||
|
@ -921,7 +916,8 @@ bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqCMGetSubEpRsp* pRsp) {
|
|||
bool set = false;
|
||||
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||
char vgKey[TSDB_TOPIC_FNAME_LEN + 22];
|
||||
tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch, topicNumGet);
|
||||
tscDebug("consumer %ld update ep epoch %d to epoch %d, topic num: %d", tmq->consumerId, tmq->epoch, epoch,
|
||||
topicNumGet);
|
||||
SArray* newTopics = taosArrayInit(topicNumGet, sizeof(SMqClientTopic));
|
||||
if (newTopics == NULL) {
|
||||
return false;
|
||||
|
@ -1289,7 +1285,8 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t blockingTime) {
|
|||
int64_t transporterId = 0;
|
||||
/*printf("send poll\n");*/
|
||||
atomic_add_fetch_32(&tmq->waitingRequest, 1);
|
||||
tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId, pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId);
|
||||
tscDebug("consumer %ld send poll to %s : vg %d, epoch %d, req offset %ld, reqId %lu", tmq->consumerId,
|
||||
pTopic->topicName, pVg->vgId, tmq->epoch, pVg->currentOffset, pReq->reqId);
|
||||
/*printf("send vg %d %ld\n", pVg->vgId, pVg->currentOffset);*/
|
||||
asyncSendMsgToServer(tmq->pTscObj->pAppInfo->pTransporter, &pVg->epSet, &transporterId, sendInfo);
|
||||
pVg->pollCnt++;
|
||||
|
@ -1566,30 +1563,4 @@ const char* tmq_err2str(tmq_resp_err_t err) {
|
|||
return "fail";
|
||||
}
|
||||
|
||||
TAOS_ROW tmq_get_row(tmq_message_t* message) {
|
||||
SMqPollRsp* rsp = &message->msg;
|
||||
while (1) {
|
||||
if (message->iter.curBlock < taosArrayGetSize(rsp->pBlockData)) {
|
||||
SSDataBlock* pBlock = taosArrayGet(rsp->pBlockData, message->iter.curBlock);
|
||||
if (message->iter.curRow < pBlock->info.rows) {
|
||||
for (int i = 0; i < pBlock->info.numOfCols; i++) {
|
||||
SColumnInfoData* pData = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (colDataIsNull_s(pData, message->iter.curRow))
|
||||
message->iter.uData[i] = NULL;
|
||||
else {
|
||||
message->iter.uData[i] = colDataGetData(pData, message->iter.curRow);
|
||||
}
|
||||
}
|
||||
message->iter.curRow++;
|
||||
return message->iter.uData;
|
||||
} else {
|
||||
message->iter.curBlock++;
|
||||
message->iter.curRow = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
char* tmq_get_topic_name(tmq_message_t* message) { return "not implemented yet"; }
|
||||
|
|
|
@ -411,6 +411,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
|
|||
#endif
|
||||
|
||||
pCols->numOfRows = 0;
|
||||
pCols->bitmapMode = 0;
|
||||
pCols->numOfCols = schemaNCols(pSchema);
|
||||
|
||||
for (i = 0; i < schemaNCols(pSchema); ++i) {
|
||||
|
|
|
@ -256,7 +256,7 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t taosAddClientLogCfg(SConfig *pCfg) {
|
||||
int32_t taosAddClientLogCfg(SConfig *pCfg) {
|
||||
if (cfgAddDir(pCfg, "configDir", configDir, 1) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "scriptDir", configDir, 1) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "logDir", tsLogDir, 1) != 0) return -1;
|
||||
|
|
|
@ -419,6 +419,7 @@ int32_t tSerializeSVCreateTbReq(void **buf, SVCreateTbReq *pReq) {
|
|||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.nTagCols);
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) {
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].type);
|
||||
tlen += taosEncodeFixedI8(buf, pReq->stbCfg.pTagSchema[i].index);
|
||||
tlen += taosEncodeFixedI16(buf, pReq->stbCfg.pTagSchema[i].colId);
|
||||
tlen += taosEncodeFixedI32(buf, pReq->stbCfg.pTagSchema[i].bytes);
|
||||
tlen += taosEncodeString(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
|
@ -489,6 +490,7 @@ void *tDeserializeSVCreateTbReq(void *buf, SVCreateTbReq *pReq) {
|
|||
pReq->stbCfg.pTagSchema = (SSchema *)taosMemoryMalloc(pReq->stbCfg.nTagCols * sizeof(SSchema));
|
||||
for (col_id_t i = 0; i < pReq->stbCfg.nTagCols; ++i) {
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].type));
|
||||
buf = taosDecodeFixedI8(buf, &(pReq->stbCfg.pTagSchema[i].index));
|
||||
buf = taosDecodeFixedI16(buf, &pReq->stbCfg.pTagSchema[i].colId);
|
||||
buf = taosDecodeFixedI32(buf, &pReq->stbCfg.pTagSchema[i].bytes);
|
||||
buf = taosDecodeStringTo(buf, pReq->stbCfg.pTagSchema[i].name);
|
||||
|
@ -2100,7 +2102,7 @@ void tFreeSUseDbBatchRsp(SUseDbBatchRsp *pRsp) {
|
|||
taosArrayDestroy(pRsp->pArray);
|
||||
}
|
||||
|
||||
int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) {
|
||||
int32_t tSerializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
|
@ -2113,7 +2115,7 @@ int32_t tSerializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) {
|
|||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) {
|
||||
int32_t tDeserializeSDbCfgReq(void *buf, int32_t bufLen, SDbCfgReq *pReq) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
|
@ -2125,7 +2127,7 @@ int32_t tDeserializeSDbCfgReq(void* buf, int32_t bufLen, SDbCfgReq* pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) {
|
||||
int32_t tSerializeSDbCfgRsp(void *buf, int32_t bufLen, const SDbCfgRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
|
@ -2156,7 +2158,7 @@ int32_t tSerializeSDbCfgRsp(void* buf, int32_t bufLen, const SDbCfgRsp* pRsp) {
|
|||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) {
|
||||
int32_t tDeserializeSDbCfgRsp(void *buf, int32_t bufLen, SDbCfgRsp *pRsp) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
|
@ -2187,7 +2189,7 @@ int32_t tDeserializeSDbCfgRsp(void* buf, int32_t bufLen, SDbCfgRsp* pRsp) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) {
|
||||
int32_t tSerializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
|
@ -2200,7 +2202,7 @@ int32_t tSerializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq)
|
|||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq) {
|
||||
int32_t tDeserializeSUserIndexReq(void *buf, int32_t bufLen, SUserIndexReq *pReq) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
|
@ -2212,7 +2214,7 @@ int32_t tDeserializeSUserIndexReq(void* buf, int32_t bufLen, SUserIndexReq* pReq
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp* pRsp) {
|
||||
int32_t tSerializeSUserIndexRsp(void *buf, int32_t bufLen, const SUserIndexRsp *pRsp) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
||||
|
@ -2229,7 +2231,7 @@ int32_t tSerializeSUserIndexRsp(void* buf, int32_t bufLen, const SUserIndexRsp*
|
|||
return tlen;
|
||||
}
|
||||
|
||||
int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp) {
|
||||
int32_t tDeserializeSUserIndexRsp(void *buf, int32_t bufLen, SUserIndexRsp *pRsp) {
|
||||
SCoder decoder = {0};
|
||||
tCoderInit(&decoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_DECODER);
|
||||
|
||||
|
@ -2245,7 +2247,6 @@ int32_t tDeserializeSUserIndexRsp(void* buf, int32_t bufLen, SUserIndexRsp* pRsp
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t tSerializeSShowReq(void *buf, int32_t bufLen, SShowReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
|
|
@ -385,7 +385,6 @@ int tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int
|
|||
pCol->len += pCol->bytes;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
|
||||
tdSetBitmapValType(pCol->pBitmap, numOfRows, valType, bitmapMode);
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -486,7 +485,7 @@ static int32_t tdAppendKvRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols
|
|||
* @param pCols
|
||||
* @param forceSetNull
|
||||
*/
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) {
|
||||
int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCols) {
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
return tdAppendTpRowToDataCol(pRow, pSchema, pCols);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
|
@ -497,7 +496,7 @@ int32_t tdAppendSTSRowToDataCol(STSRow *pRow, STSchema *pSchema, SDataCols *pCol
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull) {
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull, TDRowVerT maxVer) {
|
||||
ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows);
|
||||
ASSERT(target->numOfCols == source->numOfCols);
|
||||
int offset = 0;
|
||||
|
@ -510,6 +509,7 @@ int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *
|
|||
|
||||
if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
// TODO: filter the maxVer
|
||||
for (int i = 0; i < rowsToMerge; i++) {
|
||||
for (int j = 0; j < source->numOfCols; j++) {
|
||||
if (source->cols[j].len > 0 || target->cols[j].len > 0) {
|
||||
|
@ -555,9 +555,9 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
|
|||
// TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2);
|
||||
|
||||
ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
|
||||
// TODO: filter the maxVer
|
||||
if (key1 < key2) {
|
||||
for (int i = 0; i < src1->numOfCols; i++) {
|
||||
for (int i = 0; i < src1->numOfCols; ++i) {
|
||||
ASSERT(target->cols[i].type == src1->cols[i].type);
|
||||
if (src1->cols[i].len > 0 || target->cols[i].len > 0) {
|
||||
SCellVal sVal = {0};
|
||||
|
@ -568,12 +568,12 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
|
|||
}
|
||||
}
|
||||
|
||||
target->numOfRows++;
|
||||
(*iter1)++;
|
||||
++target->numOfRows;
|
||||
++(*iter1);
|
||||
} else if (key1 >= key2) {
|
||||
// if ((key1 > key2) || (key1 == key2 && !TKEY_IS_DELETED(tkey2))) {
|
||||
if ((key1 > key2) || (key1 == key2)) {
|
||||
for (int i = 0; i < src2->numOfCols; i++) {
|
||||
// TODO: filter the maxVer
|
||||
if ((key1 > key2) || ((key1 == key2) && !TKEY_IS_DELETED(key2))) {
|
||||
for (int i = 0; i < src2->numOfCols; ++i) {
|
||||
SCellVal sVal = {0};
|
||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||
if (tdGetColDataOfRow(&sVal, src2->cols + i, *iter2, src2->bitmapMode) < 0) {
|
||||
|
@ -590,11 +590,11 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
|
|||
dataColSetNullAt(&target->cols[i], target->numOfRows, true, target->bitmapMode);
|
||||
}
|
||||
}
|
||||
target->numOfRows++;
|
||||
++target->numOfRows;
|
||||
}
|
||||
|
||||
(*iter2)++;
|
||||
if (key1 == key2) (*iter1)++;
|
||||
++(*iter2);
|
||||
if (key1 == key2) ++(*iter1);
|
||||
}
|
||||
|
||||
ASSERT(target->numOfRows <= target->maxPoints);
|
||||
|
|
|
@ -39,7 +39,7 @@ STSBuf* tsBufCreate(bool autoDelete, int32_t order) {
|
|||
|
||||
taosGetTmpfilePath(tsTempDir, "join", pTSBuf->path);
|
||||
// pTSBuf->pFile = fopen(pTSBuf->path, "wb+");
|
||||
pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
pTSBuf->pFile = taosOpenFile(pTSBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
|
||||
if (pTSBuf->pFile == NULL) {
|
||||
taosMemoryFree(pTSBuf);
|
||||
return NULL;
|
||||
|
|
|
@ -1031,10 +1031,15 @@ char * taosVariantGet(SVariant *pVar, int32_t type) {
|
|||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
return (char *)&pVar->i;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
return (char *)&pVar->u;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
return (char *)&pVar->d;
|
||||
|
|
|
@ -58,7 +58,7 @@ int32_t bmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to create bnode since %s, input:%d cur:%d", terrstr(), createReq.dnodeId, pDnode->dnodeId);
|
||||
return -1;
|
||||
} else {
|
||||
return bmOpen(pWrapper);
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@ int32_t bmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to drop bnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return bmDrop(pWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ int32_t dmWriteFile(SDnodeMgmt *pMgmt) {
|
|||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%sdnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
dError("failed to write %s since %s", file, strerror(errno));
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
|
|
@ -25,11 +25,10 @@ static void dmGetMonitorBasicInfo(SDnode *pDnode, SMonBasicInfo *pInfo) {
|
|||
|
||||
static void dmGetMonitorDnodeInfo(SDnode *pDnode, SMonDnodeInfo *pInfo) {
|
||||
pInfo->uptime = (taosGetTimestampMs() - pDnode->rebootTime) / (86400000.0f);
|
||||
SMgmtWrapper *pWrapper = dndAcquireWrapper(pDnode, MNODE);
|
||||
if (pWrapper != NULL) {
|
||||
pInfo->has_mnode = pWrapper->required;
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
pInfo->has_mnode = pDnode->wrappers[MNODE].required;
|
||||
pInfo->has_qnode = pDnode->wrappers[QNODE].required;
|
||||
pInfo->has_snode = pDnode->wrappers[SNODE].required;
|
||||
pInfo->has_bnode = pDnode->wrappers[BNODE].required;
|
||||
tstrncpy(pInfo->logdir.name, tsLogDir, sizeof(pInfo->logdir.name));
|
||||
pInfo->logdir.size = tsLogSpace.size;
|
||||
tstrncpy(pInfo->tempdir.name, tsTempDir, sizeof(pInfo->tempdir.name));
|
||||
|
@ -65,7 +64,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
bool getFromAPI = !tsMultiProcess;
|
||||
pWrapper = &pDnode->wrappers[MNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) != 0) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
mmGetMonitorInfo(pWrapper, &mmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
@ -82,7 +81,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[VNODES];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) != 0) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
vmGetMonitorInfo(pWrapper, &vmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
@ -99,7 +98,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[QNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) != 0) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
qmGetMonitorInfo(pWrapper, &qmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
@ -116,7 +115,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[SNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) != 0) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
smGetMonitorInfo(pWrapper, &smInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
@ -133,7 +132,7 @@ void dmSendMonitorReport(SDnode *pDnode) {
|
|||
|
||||
pWrapper = &pDnode->wrappers[BNODE];
|
||||
if (getFromAPI) {
|
||||
if (dndMarkWrapper(pWrapper) != 0) {
|
||||
if (dndMarkWrapper(pWrapper) == 0) {
|
||||
bmGetMonitorInfo(pWrapper, &bmInfo);
|
||||
dndReleaseWrapper(pWrapper);
|
||||
}
|
||||
|
|
|
@ -126,6 +126,7 @@ typedef struct SDnode {
|
|||
int32_t numOfDisks;
|
||||
uint16_t serverPort;
|
||||
bool dropped;
|
||||
EProcType procType;
|
||||
EDndType ntype;
|
||||
EDndStatus status;
|
||||
EDndEvent event;
|
||||
|
|
|
@ -27,46 +27,42 @@ static bool dndRequireNode(SMgmtWrapper *pWrapper) {
|
|||
return required;
|
||||
}
|
||||
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
static int32_t dndInitNodeProc(SMgmtWrapper *pWrapper) {
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (pWrapper->ntype == VNODES) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (pWrapper->ntype == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (pWrapper->ntype == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (pWrapper->ntype == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (pWrapper->ntype == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
if (taosCreateShm(&pWrapper->shm, pWrapper->ntype, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||
dDebug("node:%s, mgmt start to close", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->pProc) {
|
||||
taosProcCleanup(pWrapper->pProc);
|
||||
pWrapper->pProc = NULL;
|
||||
}
|
||||
dDebug("node:%s, mgmt has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
|
||||
static int32_t dndNewProc(SMgmtWrapper *pWrapper, EDndType n) {
|
||||
static int32_t dndNewNodeProc(SMgmtWrapper *pWrapper, EDndType n) {
|
||||
char tstr[8] = {0};
|
||||
char *args[6] = {0};
|
||||
snprintf(tstr, sizeof(tstr), "%d", n);
|
||||
|
@ -88,6 +84,86 @@ static int32_t dndNewProc(SMgmtWrapper *pWrapper, EDndType n) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndRunNodeProc(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->ntype == NODE_MAX) {
|
||||
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||
} else {
|
||||
if (dndNewNodeProc(pWrapper, pWrapper->ntype) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dndOpenNodeImp(SMgmtWrapper *pWrapper) {
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((*pWrapper->fp.openFp)(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
dDebug("node:%s, has been opened", pWrapper->name);
|
||||
pWrapper->deployed = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t dndOpenNode(SMgmtWrapper *pWrapper) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
if (pDnode->procType == PROC_SINGLE) {
|
||||
return dndOpenNodeImp(pWrapper);
|
||||
} else if (pDnode->procType == PROC_PARENT) {
|
||||
if (dndInitNodeProc(pWrapper) != 0) return -1;
|
||||
if (dndWriteShmFile(pDnode) != 0) return -1;
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dndCloseNodeImp(SMgmtWrapper *pWrapper) {
|
||||
dDebug("node:%s, mgmt start to close", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
taosWLockLatch(&pWrapper->latch);
|
||||
if (pWrapper->deployed) {
|
||||
(*pWrapper->fp.closeFp)(pWrapper);
|
||||
pWrapper->deployed = false;
|
||||
}
|
||||
taosWUnLockLatch(&pWrapper->latch);
|
||||
|
||||
while (pWrapper->refCount > 0) {
|
||||
taosMsleep(10);
|
||||
}
|
||||
|
||||
if (pWrapper->pProc) {
|
||||
taosProcCleanup(pWrapper->pProc);
|
||||
pWrapper->pProc = NULL;
|
||||
}
|
||||
dDebug("node:%s, mgmt has been closed", pWrapper->name);
|
||||
}
|
||||
|
||||
void dndCloseNode(SMgmtWrapper *pWrapper) {
|
||||
if (pWrapper->pDnode->procType == PROC_PARENT) {
|
||||
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
|
||||
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
|
||||
taosKillProc(pWrapper->procId);
|
||||
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
|
||||
taosWaitProc(pWrapper->procId);
|
||||
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
|
||||
}
|
||||
}
|
||||
dndCloseNodeImp(pWrapper);
|
||||
}
|
||||
|
||||
static void dndProcessProcHandle(void *handle) {
|
||||
dWarn("handle:%p, the child process dies and send an offline rsp", handle);
|
||||
SRpcMsg rpcMsg = {.handle = handle, .code = TSDB_CODE_NODE_OFFLINE};
|
||||
|
@ -96,13 +172,14 @@ static void dndProcessProcHandle(void *handle) {
|
|||
|
||||
static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in single process");
|
||||
pDnode->procType = PROC_SINGLE;
|
||||
|
||||
for (EDndType n = DNODE; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -136,8 +213,10 @@ static int32_t dndRunInSingleProcess(SDnode *pDnode) {
|
|||
|
||||
static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
||||
dInfo("dnode run in parent process");
|
||||
pDnode->procType = PROC_PARENT;
|
||||
|
||||
SMgmtWrapper *pDWrapper = &pDnode->wrappers[DNODE];
|
||||
if (dndOpenNode(pDWrapper) != 0) {
|
||||
if (dndOpenNodeImp(pDWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pDWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -146,36 +225,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
|||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
int32_t shmsize = tsMnodeShmSize;
|
||||
if (n == VNODES) {
|
||||
shmsize = tsVnodeShmSize;
|
||||
} else if (n == QNODE) {
|
||||
shmsize = tsQnodeShmSize;
|
||||
} else if (n == SNODE) {
|
||||
shmsize = tsSnodeShmSize;
|
||||
} else if (n == MNODE) {
|
||||
shmsize = tsMnodeShmSize;
|
||||
} else if (n == BNODE) {
|
||||
shmsize = tsBnodeShmSize;
|
||||
} else {
|
||||
}
|
||||
|
||||
if (taosCreateShm(&pWrapper->shm, n, shmsize) != 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(terrno);
|
||||
dError("node:%s, failed to create shm size:%d since %s", pWrapper->name, shmsize, terrstr());
|
||||
return -1;
|
||||
}
|
||||
dInfo("node:%s, shm:%d is created, size:%d", pWrapper->name, pWrapper->shm.id, shmsize);
|
||||
|
||||
SProcCfg cfg = dndGenProcCfg(pWrapper);
|
||||
cfg.isChild = false;
|
||||
pWrapper->procType = PROC_PARENT;
|
||||
pWrapper->pProc = taosProcInit(&cfg);
|
||||
if (pWrapper->pProc == NULL) {
|
||||
dError("node:%s, failed to create proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
if (dndInitNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
if (dndWriteShmFile(pDnode) != 0) {
|
||||
|
@ -186,19 +236,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
|||
for (EDndType n = DNODE + 1; n < NODE_MAX; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
|
||||
if (pDnode->ntype == NODE_MAX) {
|
||||
dInfo("node:%s, should be started manually", pWrapper->name);
|
||||
} else {
|
||||
if (dndNewProc(pWrapper, n) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (taosProcRun(pWrapper->pProc) != 0) {
|
||||
dError("node:%s, failed to run proc since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
if (dndRunNodeProc(pWrapper) != 0) return -1;
|
||||
}
|
||||
|
||||
dndSetStatus(pDnode, DND_STAT_RUNNING);
|
||||
|
@ -239,7 +277,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
|||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
taosProcCloseHandles(pWrapper->pProc, dndProcessProcHandle);
|
||||
dndNewProc(pWrapper, n);
|
||||
dndNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -253,6 +291,7 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
|
|||
static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[pDnode->ntype];
|
||||
dInfo("%s run in child process", pWrapper->name);
|
||||
pDnode->procType = PROC_CHILD;
|
||||
|
||||
pWrapper->required = dndRequireNode(pWrapper);
|
||||
if (!pWrapper->required) {
|
||||
|
@ -264,7 +303,7 @@ static int32_t dndRunInChildProcess(SDnode *pDnode) {
|
|||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
pWrapper->procType = PROC_CHILD;
|
||||
|
||||
if (dndOpenNode(pWrapper) != 0) {
|
||||
if (dndOpenNodeImp(pWrapper) != 0) {
|
||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ int32_t dndWriteFile(SMgmtWrapper *pWrapper, bool deployed) {
|
|||
snprintf(file, sizeof(file), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", pWrapper->path, TD_DIRSEP, pWrapper->name);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
|
@ -121,7 +121,7 @@ TdFilePtr dndCheckRunning(const char *dataDir) {
|
|||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to lock file:%s since %s", filepath, terrstr());
|
||||
|
@ -218,7 +218,7 @@ int32_t dndWriteShmFile(SDnode *pDnode) {
|
|||
snprintf(file, sizeof(file), "%s%s.shmfile.bak", pDnode->dataDir, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%s.shmfile", pDnode->dataDir, TD_DIRSEP);
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open file:%s since %s", file, terrstr());
|
||||
|
|
|
@ -109,7 +109,7 @@ int32_t mmWriteFile(SMnodeMgmt *pMgmt, bool deployed) {
|
|||
char file[PATH_MAX];
|
||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
|
|
|
@ -80,6 +80,7 @@ int32_t mmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to drop mnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return mmDrop(pWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ int32_t qmProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to create qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return qmOpen(pWrapper);
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,6 +77,7 @@ int32_t qmProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to drop qnode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
// dndCloseNode(pWrapper);
|
||||
return qmDrop(pWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ static void qmProcessMonitorQueue(SQueueInfo *pInfo, SNodeMsg *pMsg) {
|
|||
SRpcMsg *pRpc = &pMsg->rpcMsg;
|
||||
int32_t code = -1;
|
||||
|
||||
if (pMsg->rpcMsg.msgType == TDMT_MON_SM_INFO) {
|
||||
if (pMsg->rpcMsg.msgType == TDMT_MON_QM_INFO) {
|
||||
code = qmProcessGetMonQmInfoReq(pMgmt->pWrapper, pMsg);
|
||||
} else {
|
||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||
|
|
|
@ -58,7 +58,7 @@ int32_t smProcessCreateReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
dError("failed to create snode since %s", terrstr());
|
||||
return -1;
|
||||
} else {
|
||||
return smOpen(pWrapper);
|
||||
return dndOpenNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,6 +78,7 @@ int32_t smProcessDropReq(SMgmtWrapper *pWrapper, SNodeMsg *pMsg) {
|
|||
return -1;
|
||||
} else {
|
||||
return smDrop(pWrapper);
|
||||
// return dndCloseNode(pWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -154,7 +154,7 @@ int32_t vmWriteVnodesToFile(SVnodesMgmt *pMgmt) {
|
|||
snprintf(file, sizeof(file), "%s%svnodes.json.bak", pMgmt->path, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write %s since %s", file, terrstr());
|
||||
|
|
|
@ -38,7 +38,7 @@ class MndTestTrans : public ::testing::Test {
|
|||
|
||||
test.ServerStop();
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
int32_t writeLen = taosWriteFile(pFile, buffer, readLen);
|
||||
if (writeLen < 0 || writeLen == readLen) {
|
||||
ASSERT(1);
|
||||
|
|
|
@ -232,7 +232,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
|||
mDebug("start to write file:%s, current ver:%" PRId64 ", commit ver:%" PRId64, curfile, pSdb->curVer,
|
||||
pSdb->lastCommitVer);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
mError("failed to open file:%s for write since %s", tmpfile, terrstr());
|
||||
|
|
|
@ -55,6 +55,8 @@ target_include_directories(
|
|||
vnode
|
||||
PUBLIC "inc"
|
||||
PRIVATE "src/inc"
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/libs/scalar"
|
||||
|
||||
)
|
||||
target_link_libraries(
|
||||
vnode
|
||||
|
@ -69,6 +71,7 @@ target_link_libraries(
|
|||
PUBLIC scheduler
|
||||
PUBLIC tdb
|
||||
#PUBLIC bdb
|
||||
#PUBLIC scalar
|
||||
PUBLIC transport
|
||||
PUBLIC stream
|
||||
)
|
||||
|
|
|
@ -95,7 +95,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
|
|||
tqError("failed to create dir:%s since %s ", name, terrstr());
|
||||
}
|
||||
strcat(name, "/" TQ_IDX_NAME);
|
||||
TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ);
|
||||
TdFilePtr pIdxFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ);
|
||||
if (pIdxFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tqError("failed to open file:%s since %s ", name, terrstr());
|
||||
|
@ -113,7 +113,7 @@ STqMetaStore* tqStoreOpen(STQ* pTq, const char* path, FTqSerialize serializer, F
|
|||
|
||||
strcpy(name, path);
|
||||
strcat(name, "/" TQ_META_NAME);
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_READ);
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
tqError("failed to open file:%s since %s", name, terrstr());
|
||||
|
|
|
@ -1298,7 +1298,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
int32_t tBitmaps = 0;
|
||||
int32_t tBitmapsLen = 0;
|
||||
if ((ncol != 0) && !TD_COL_ROWS_NORM(pBlockCol)) {
|
||||
tBitmaps = sBitmaps;
|
||||
tBitmaps = isSuper ? sBitmaps : nBitmaps;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1678,10 +1678,11 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget, true);
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
#if 0
|
||||
if (update != TD_ROW_OVERWRITE_UPDATE) {
|
||||
// copy disk data
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
|
@ -1706,6 +1707,43 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
}
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
#endif
|
||||
// copy disk data
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
// TODO: tdAppendValToDataCol may fail
|
||||
tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints,
|
||||
pTarget->bitmapMode);
|
||||
}
|
||||
|
||||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
// copy mem data(Multi-Version)
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
// TODO: merge with Multi-Version
|
||||
STSRow *curRow = row;
|
||||
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
STSRow *nextRow = tsdbNextIterRow(pCommitIter->pIter);
|
||||
|
||||
if (key2 < TD_ROW_KEY(nextRow)) {
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
} else {
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget);
|
||||
}
|
||||
// TODO: merge with Multi-Version
|
||||
} else {
|
||||
++pTarget->numOfRows;
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
}
|
||||
}
|
||||
|
||||
if (pTarget->numOfRows >= maxRows) break;
|
||||
|
|
|
@ -416,7 +416,7 @@ static int tsdbSaveFSStatus(STsdb *pRepo, SFSStatus *pStatus) {
|
|||
tsdbGetTxnFname(pRepo, TSDB_TXN_TEMP_FILE, tfname);
|
||||
tsdbGetTxnFname(pRepo, TSDB_TXN_CURR_FILE, cfname);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(tfname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
|
|
@ -360,7 +360,7 @@ static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) {
|
|||
int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T fType) {
|
||||
ASSERT(pDFile->info.size == 0 && pDFile->info.magic == TSDB_FILE_INIT_MAGIC);
|
||||
|
||||
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pDFile->pFile == NULL) {
|
||||
if (errno == ENOENT) {
|
||||
// Try to create directory recursively
|
||||
|
@ -371,7 +371,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T
|
|||
}
|
||||
taosMemoryFreeClear(s);
|
||||
|
||||
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
pDFile->pFile = taosOpenFile(TSDB_FILE_FULL_NAME(pDFile), TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pDFile->pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
|
|
@ -475,7 +475,7 @@ static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema *
|
|||
}
|
||||
}
|
||||
|
||||
tdAppendSTSRowToDataCol(row, *ppSchema, pCols, true);
|
||||
tdAppendSTSRowToDataCol(row, *ppSchema, pCols);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -263,8 +263,9 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
|||
for (int i = 1; i < pBlock->numOfSubBlocks; i++) {
|
||||
iBlock++;
|
||||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
update != TD_ROW_PARTIAL_UPDATE) < 0)
|
||||
update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -293,8 +294,9 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
for (int i = 1; i < pBlock->numOfSubBlocks; i++) {
|
||||
iBlock++;
|
||||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
update != TD_ROW_PARTIAL_UPDATE) < 0)
|
||||
update != TD_ROW_PARTIAL_UPDATE, UINT64_MAX) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -304,6 +306,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
if (pDataCol->bitmap) {
|
||||
ASSERT(pDataCol->colId != PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
tdMergeBitmap(pDataCol->pBitmap, TD_BITMAP_BYTES(pReadh->pDCols[0]->numOfRows), pDataCol->pBitmap);
|
||||
tdDataColsSetBitmapI(pReadh->pDCols[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -639,7 +639,7 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:{
|
||||
SIntervalPhysiNode *pIntNode = (SIntervalPhysiNode *)pNode;
|
||||
EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->pTspk));
|
||||
EXPLAIN_ROW_NEW(level, EXPLAIN_INTERVAL_FORMAT, nodesGetNameFromColumnNode(pIntNode->window.pTspk));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_LEFT_PARENTHESIS_FORMAT);
|
||||
if (pResNode->pExecInfo) {
|
||||
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||
|
|
|
@ -232,9 +232,11 @@ typedef struct STaskAttr {
|
|||
} STaskAttr;
|
||||
|
||||
struct SOperatorInfo;
|
||||
struct SAggSupporter;
|
||||
struct SOptrBasicInfo;
|
||||
|
||||
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, char **result, int32_t *length);
|
||||
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, char *result, int32_t length);
|
||||
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char **result, int32_t *length);
|
||||
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char *result, int32_t length);
|
||||
|
||||
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
|
||||
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup);
|
||||
|
@ -409,7 +411,7 @@ typedef struct STableScanInfo {
|
|||
SResultRowInfo* pResultRowInfo;
|
||||
int32_t* rowCellInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
SSDataBlock block;
|
||||
SSDataBlock* pResBlock;
|
||||
SArray* pColMatchInfo;
|
||||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
|
@ -567,6 +569,9 @@ typedef struct SGroupbyOperatorInfo {
|
|||
int32_t groupKeyLen; // total group by column width
|
||||
SGroupResInfo groupResInfo;
|
||||
SAggSupporter aggSup;
|
||||
SExprInfo* pScalarExprInfo;
|
||||
int32_t numOfScalarExpr;// the number of scalar expression in group operator
|
||||
SqlFunctionCtx*pScalarFuncCtx;
|
||||
} SGroupbyOperatorInfo;
|
||||
|
||||
typedef struct SDataGroupInfo {
|
||||
|
@ -672,7 +677,7 @@ void operatorDummyCloseFn(void* param, int32_t numOfCols);
|
|||
int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num);
|
||||
int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey);
|
||||
void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset);
|
||||
void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, int32_t* rowCellOffset);
|
||||
void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset);
|
||||
void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order);
|
||||
int32_t setGroupResultOutputBuf_rv(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type,
|
||||
|
@ -683,12 +688,11 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
uint64_t* total, SArray* pColList);
|
||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity);
|
||||
SSDataBlock* loadNextDataBlock(void* param);
|
||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset);
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime,
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SNode* pCondition, SExecTaskInfo* pTaskInfo);
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock,
|
||||
SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
@ -702,8 +706,8 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataB
|
|||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlot,
|
||||
const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock,
|
||||
SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList,
|
||||
SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
@ -727,6 +731,8 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pdownstream, int32_t numOf
|
|||
int32_t numOfOutput);
|
||||
#endif
|
||||
|
||||
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList);
|
||||
|
||||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order);
|
||||
|
||||
void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
@ -753,6 +759,9 @@ void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
|
|||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model);
|
||||
int32_t getOperatorExplainExecInfo(SOperatorInfo *operatorInfo, SExplainExecInfo **pRes, int32_t *capacity, int32_t *resNum);
|
||||
|
||||
bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length);
|
||||
void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -92,9 +92,7 @@ static bool allocBuf(SDataDispatchHandle* pDispatcher, const SInputData* pInput,
|
|||
return false;
|
||||
}
|
||||
|
||||
// NOTE: there are four bytes of an integer more than the required buffer space.
|
||||
// struct size + data payload + length for each column + bitmap length
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockDataGetSerialMetaSize(pInput->pData) + blockDataGetSize(pInput->pData);
|
||||
pBuf->allocSize = sizeof(SRetrieveTableRsp) + blockEstimateEncodeSize(pInput->pData);
|
||||
|
||||
pBuf->pData = taosMemoryMalloc(pBuf->allocSize);
|
||||
if (pBuf->pData == NULL) {
|
||||
|
|
|
@ -234,9 +234,8 @@ int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) {
|
|||
|
||||
void operatorDummyCloseFn(void* param, int32_t numOfCols) {}
|
||||
|
||||
static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType,
|
||||
SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset);
|
||||
|
||||
static int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo,
|
||||
int32_t orderType, int32_t* rowCellOffset);
|
||||
static void initCtxOutputBuffer(SqlFunctionCtx* pCtx, int32_t size);
|
||||
static void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst,
|
||||
int64_t keyLast, STimeWindow* win);
|
||||
|
@ -300,10 +299,6 @@ SSDataBlock* createOutputBuf_rv1(SDataBlockDescNode* pNode) {
|
|||
}
|
||||
|
||||
taosArrayPush(pBlock->pDataBlock, &idata);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(idata.info.type)) {
|
||||
pBlock->info.hasVarCol = true;
|
||||
}
|
||||
}
|
||||
|
||||
return pBlock;
|
||||
|
@ -363,7 +358,7 @@ static void prepareResultListBuffer(SResultRowInfo* pResultRowInfo, jmp_buf env)
|
|||
pResultRowInfo->pPosition = taosMemoryRealloc(pResultRowInfo->pPosition, newCapacity * sizeof(SResultRowPosition));
|
||||
|
||||
int32_t inc = (int32_t)newCapacity - pResultRowInfo->capacity;
|
||||
memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition));
|
||||
memset(&pResultRowInfo->pPosition[pResultRowInfo->capacity], 0, sizeof(SResultRowPosition) * inc);
|
||||
pResultRowInfo->capacity = (int32_t)newCapacity;
|
||||
}
|
||||
|
||||
|
@ -419,7 +414,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId,
|
|||
pData = getBufPage(pResultBuf, getPageId(pi));
|
||||
pageId = getPageId(pi);
|
||||
|
||||
if (pData->num + interBufSize + sizeof(SResultRow) > getBufPageSize(pResultBuf)) {
|
||||
if (pData->num + interBufSize > getBufPageSize(pResultBuf)) {
|
||||
// release current page first, and prepare the next one
|
||||
releaseBufPageInfo(pResultBuf, pi);
|
||||
|
||||
|
@ -439,7 +434,7 @@ SResultRow* getNewResultRow_rv(SDiskbasedBuf* pResultBuf, int64_t tableGroupId,
|
|||
pResultRow->pageId = pageId;
|
||||
pResultRow->offset = (int32_t)pData->num;
|
||||
|
||||
pData->num += interBufSize + sizeof(SResultRow);
|
||||
pData->num += interBufSize;
|
||||
|
||||
return pResultRow;
|
||||
}
|
||||
|
@ -507,7 +502,7 @@ static SResultRow* doSetResultOutBufByKey_rv(SDiskbasedBuf* pResultBuf, SResultR
|
|||
|
||||
// add a new result set for a new group
|
||||
SResultRowPosition pos = {.pageId = pResult->pageId, .offset = pResult->offset};
|
||||
taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, POINTER_BYTES);
|
||||
taosHashPut(pSup->pResultRowHashTable, pSup->keyBuf, GET_RES_WINDOW_KEY_LEN(bytes), &pos, sizeof(SResultRowPosition));
|
||||
SResultRowCell cell = {.groupId = tableGroupId, .pos = pos};
|
||||
taosArrayPush(pSup->pResultRowArrayList, &cell);
|
||||
} else {
|
||||
|
@ -1072,9 +1067,9 @@ static void doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx,
|
|||
pCtx[i].size = pBlock->info.rows;
|
||||
pCtx[i].currentStage = MAIN_SCAN;
|
||||
|
||||
SExprInfo expr = pOperator->pExpr[i];
|
||||
for (int32_t j = 0; j < expr.base.numOfParams; ++j) {
|
||||
SFunctParam *pFuncParam = &expr.base.pParam[j];
|
||||
SExprInfo* pOneExpr = &pOperator->pExpr[i];
|
||||
for (int32_t j = 0; j < pOneExpr->base.numOfParams; ++j) {
|
||||
SFunctParam *pFuncParam = &pOneExpr->base.pParam[j];
|
||||
if (pFuncParam->type == FUNC_PARAM_TYPE_COLUMN) {
|
||||
int32_t slotId = pFuncParam->pCol->slotId;
|
||||
pCtx[i].input.pData[j] = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
@ -1149,19 +1144,21 @@ static void setPseudoOutputColInfo(SSDataBlock* pResult, SqlFunctionCtx* pCtx, S
|
|||
}
|
||||
}
|
||||
|
||||
static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
||||
int32_t numOfOutput, SArray* pPseudoList) {
|
||||
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList) {
|
||||
setPseudoOutputColInfo(pResult, pCtx, pPseudoList);
|
||||
pResult->info.groupId = pSrcBlock->info.groupId;
|
||||
|
||||
for (int32_t k = 0; k < numOfOutput; ++k) {
|
||||
int32_t outputSlotId = pExpr[k].base.resSchema.slotId;
|
||||
SqlFunctionCtx* pfCtx = &pCtx[k];
|
||||
|
||||
if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k);
|
||||
colDataAssign(pColInfoData, pCtx[k].input.pData[0], pCtx[k].input.numOfRows);
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows);
|
||||
|
||||
pResult->info.rows = pSrcBlock->info.rows;
|
||||
} else if (pExpr[k].pExpr->nodeType == QUERY_NODE_VALUE) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, k);
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
for (int32_t i = 0; i < pSrcBlock->info.rows; ++i) {
|
||||
colDataAppend(pColInfoData, i, taosVariantGet(&pExpr[k].base.pParam[0].param, pExpr[k].base.pParam[0].param.nType), TSDB_DATA_TYPE_NULL == pExpr[k].base.pParam[0].param.nType);
|
||||
}
|
||||
|
@ -1171,40 +1168,40 @@ static void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSData
|
|||
taosArrayPush(pBlockList, &pSrcBlock);
|
||||
|
||||
SScalarParam dest = {0};
|
||||
dest.columnData = taosArrayGet(pResult->pDataBlock, k);
|
||||
dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
|
||||
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[k].functionId));
|
||||
ASSERT(!fmIsAggFunc(pfCtx->functionId));
|
||||
|
||||
if (fmIsPseudoColumnFunc(pCtx[k].functionId)) {
|
||||
if (fmIsPseudoColumnFunc(pfCtx->functionId)) {
|
||||
// do nothing
|
||||
} else if (fmIsNonstandardSQLFunc(pCtx[k].functionId)) {
|
||||
} else if (fmIsNonstandardSQLFunc(pfCtx->functionId)) {
|
||||
// todo set the correct timestamp column
|
||||
pCtx[k].input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1);
|
||||
pfCtx->input.pPTS = taosArrayGet(pSrcBlock->pDataBlock, 1);
|
||||
|
||||
SResultRowEntryInfo *pResInfo = GET_RES_INFO(&pCtx[k]);
|
||||
pCtx[k].fpSet.init(&pCtx[k], pResInfo);
|
||||
pfCtx->fpSet.init(&pCtx[k], pResInfo);
|
||||
|
||||
pCtx[k].pOutput = taosArrayGet(pResult->pDataBlock, k);
|
||||
pCtx[k].offset = pResult->info.rows; // set the start offset
|
||||
pfCtx->pOutput = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
pfCtx->offset = pResult->info.rows; // set the start offset
|
||||
|
||||
if (taosArrayGetSize(pPseudoList) > 0) {
|
||||
int32_t* outputColIndex = taosArrayGet(pPseudoList, 0);
|
||||
pCtx[k].pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput;
|
||||
pfCtx->pTsOutput = (SColumnInfoData*)pCtx[*outputColIndex].pOutput;
|
||||
}
|
||||
|
||||
int32_t numOfRows = pCtx[k].fpSet.process(&pCtx[k]);
|
||||
int32_t numOfRows = pfCtx->fpSet.process(pfCtx);
|
||||
pResult->info.rows += numOfRows;
|
||||
} else {
|
||||
SArray* pBlockList = taosArrayInit(4, POINTER_BYTES);
|
||||
taosArrayPush(pBlockList, &pSrcBlock);
|
||||
|
||||
SScalarParam dest = {0};
|
||||
dest.columnData = taosArrayGet(pResult->pDataBlock, k);
|
||||
dest.columnData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
|
||||
scalarCalculate((SNode*)pExpr[k].pExpr->_function.pFunctNode, pBlockList, &dest);
|
||||
pResult->info.rows = dest.numOfRows;
|
||||
|
@ -1814,7 +1811,7 @@ static int32_t setCtxTagColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) {
|
||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset) {
|
||||
SqlFunctionCtx* pFuncCtx = (SqlFunctionCtx*)taosMemoryCalloc(numOfOutput, sizeof(SqlFunctionCtx));
|
||||
if (pFuncCtx == NULL) {
|
||||
return NULL;
|
||||
|
@ -1855,7 +1852,7 @@ static SqlFunctionCtx* createSqlFunctionCtx_rv(SExprInfo* pExprInfo, int32_t num
|
|||
pCtx->input.pData = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES);
|
||||
pCtx->input.pColumnDataAgg = taosMemoryCalloc(pFunct->numOfParams, POINTER_BYTES);
|
||||
|
||||
pCtx->pTsOutput = NULL;//taosArrayInit(4, POINTER_BYTES);
|
||||
pCtx->pTsOutput = NULL;
|
||||
pCtx->resDataInfo.bytes = pFunct->resSchema.bytes;
|
||||
pCtx->resDataInfo.type = pFunct->resSchema.type;
|
||||
pCtx->order = TSDB_ORDER_ASC;
|
||||
|
@ -3334,8 +3331,7 @@ void setIntervalQueryRange(STaskRuntimeEnv* pRuntimeEnv, TSKEY key) {
|
|||
* @param pQInfo
|
||||
* @param result
|
||||
*/
|
||||
static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType,
|
||||
SSDataBlock* pBlock, int32_t rowCapacity, int32_t* rowCellOffset) {
|
||||
int32_t doCopyToSDataBlock(SSDataBlock* pBlock, int32_t rowCapacity, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t orderType, int32_t* rowCellOffset) {
|
||||
int32_t numOfRows = getNumOfTotalRes(pGroupResInfo);
|
||||
int32_t numOfResult = pBlock->info.rows; // there are already exists result rows
|
||||
|
||||
|
@ -3374,7 +3370,9 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI
|
|||
pGroupResInfo->index += 1;
|
||||
|
||||
for (int32_t j = 0; j < pBlock->info.numOfCols; ++j) {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, j);
|
||||
int32_t slotId = pExprInfo[j].base.resSchema.slotId;
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
SResultRowEntryInfo* pEntryInfo = getResultCell(pRow, j, rowCellOffset);
|
||||
|
||||
char* in = GET_ROWCELL_INTERBUF(pEntryInfo);
|
||||
|
@ -3395,7 +3393,7 @@ static int32_t doCopyToSDataBlock(SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResI
|
|||
return 0;
|
||||
}
|
||||
|
||||
void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock* pBlock, int32_t rowCapacity,
|
||||
void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf,
|
||||
int32_t* rowCellOffset) {
|
||||
assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup);
|
||||
|
||||
|
@ -3405,7 +3403,7 @@ void toSDatablock(SGroupResInfo* pGroupResInfo, SDiskbasedBuf* pBuf, SSDataBlock
|
|||
}
|
||||
|
||||
int32_t orderType = TSDB_ORDER_ASC;
|
||||
doCopyToSDataBlock(pBuf, pGroupResInfo, orderType, pBlock, rowCapacity, rowCellOffset);
|
||||
doCopyToSDataBlock(pBlock, rowCapacity, pExprInfo, pBuf, pGroupResInfo, orderType, rowCellOffset);
|
||||
|
||||
// add condition (pBlock->info.rows >= 1) just to runtime happy
|
||||
blockDataUpdateTsWindow(pBlock);
|
||||
|
@ -4442,32 +4440,6 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* createResultDataBlock(const SArray* pExprInfo) {
|
||||
SSDataBlock* pResBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||
if (pResBlock == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t numOfCols = taosArrayGetSize(pExprInfo);
|
||||
pResBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
SArray* pResult = pResBlock->pDataBlock;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData colInfoData = {0};
|
||||
SExprInfo* p = taosArrayGetP(pExprInfo, i);
|
||||
|
||||
SResSchema* pSchema = &p->base.resSchema;
|
||||
colInfoData.info.type = pSchema->type;
|
||||
colInfoData.info.colId = pSchema->colId;
|
||||
colInfoData.info.bytes = pSchema->bytes;
|
||||
colInfoData.info.scale = pSchema->scale;
|
||||
colInfoData.info.precision = pSchema->precision;
|
||||
taosArrayPush(pResult, &colInfoData);
|
||||
}
|
||||
|
||||
return pResBlock;
|
||||
}
|
||||
|
||||
static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey);
|
||||
static void cleanupAggSup(SAggSupporter* pAggSup);
|
||||
|
||||
|
@ -4781,7 +4753,7 @@ static int32_t initGroupCol(SExprInfo* pExprInfo, int32_t numOfCols, SArray* pGr
|
|||
SColumn* pCol = taosArrayGet(pGroupInfo, i);
|
||||
for (int32_t j = 0; j < numOfCols; ++j) {
|
||||
SExprInfo* pe = &pExprInfo[j];
|
||||
if (pe->base.resSchema.colId == pCol->colId) {
|
||||
if (pe->base.resSchema.slotId == pCol->colId) {
|
||||
taosArrayPush(plist, pCol);
|
||||
taosArrayPush(pInfo->groupInfo, &j);
|
||||
len += pCol->bytes;
|
||||
|
@ -4820,7 +4792,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t
|
|||
goto _error;
|
||||
}
|
||||
|
||||
pInfo->binfo.pCtx = createSqlFunctionCtx_rv(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset);
|
||||
pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, num, &pInfo->binfo.rowCellInfoOffset);
|
||||
initResultRowInfo(&pInfo->binfo.resultRowInfo, (int32_t)1);
|
||||
|
||||
if (pInfo->binfo.pCtx == NULL || pInfo->binfo.pRes == NULL) {
|
||||
|
@ -4979,6 +4951,21 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
|||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order);
|
||||
doAggregateImpl(pOperator, 0, pInfo->pCtx);
|
||||
|
||||
#if 0 // test for encode/decode result info
|
||||
if(pOperator->encodeResultRow){
|
||||
char *result = NULL;
|
||||
int32_t length = 0;
|
||||
SAggSupporter *pSup = &pAggInfo->aggSup;
|
||||
pOperator->encodeResultRow(pOperator, pSup, pInfo, &result, &length);
|
||||
taosHashClear(pSup->pResultRowHashTable);
|
||||
pInfo->resultRowInfo.size = 0;
|
||||
pOperator->decodeResultRow(pOperator, pSup, pInfo, result, length);
|
||||
if(result){
|
||||
taosMemoryFree(result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
finalizeQueryResult(pInfo->pCtx, pOperator->numOfOutput);
|
||||
|
@ -5007,24 +4994,33 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator, bool* newgroup)
|
|||
return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL;
|
||||
}
|
||||
|
||||
static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t* length) {
|
||||
SAggOperatorInfo* pAggInfo = pOperator->info;
|
||||
SAggSupporter* pSup = &pAggInfo->aggSup;
|
||||
|
||||
void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length) {
|
||||
int32_t size = taosHashGetSize(pSup->pResultRowHashTable);
|
||||
size_t keyLen = POINTER_BYTES; // estimate the key length
|
||||
size_t keyLen = sizeof(uint64_t) * 2; // estimate the key length
|
||||
int32_t totalSize = sizeof(int32_t) + size * (sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize);
|
||||
*result = taosMemoryCalloc(1, totalSize);
|
||||
if (*result == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return;
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
*(int32_t*)(*result) = size;
|
||||
int32_t offset = sizeof(int32_t);
|
||||
|
||||
// prepare memory
|
||||
SResultRowPosition* pos = &pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.curPos];
|
||||
void* pPage = getBufPage(pSup->pResultBuf, pos->pageId);
|
||||
SResultRow* pRow = (SResultRow*)((char*)pPage + pos->offset);
|
||||
setBufPageDirty(pPage, true);
|
||||
releaseBufPage(pSup->pResultBuf, pPage);
|
||||
|
||||
void* pIter = taosHashIterate(pSup->pResultRowHashTable, NULL);
|
||||
while (pIter) {
|
||||
void* key = taosHashGetKey(pIter, &keyLen);
|
||||
SResultRow** p1 = (SResultRow**)pIter;
|
||||
SResultRowPosition* p1 = (SResultRowPosition*)pIter;
|
||||
|
||||
pPage = (SFilePage*) getBufPage(pSup->pResultBuf, p1->pageId);
|
||||
pRow = (SResultRow*)((char*)pPage + p1->offset);
|
||||
setBufPageDirty(pPage, true);
|
||||
releaseBufPage(pSup->pResultBuf, pPage);
|
||||
|
||||
// recalculate the result size
|
||||
int32_t realTotalSize = offset + sizeof(int32_t) + keyLen + sizeof(int32_t) + pSup->resultRowSize;
|
||||
|
@ -5034,7 +5030,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t*
|
|||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(*result);
|
||||
*result = NULL;
|
||||
return;
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_OUT_OF_MEMORY);
|
||||
} else {
|
||||
*result = tmp;
|
||||
}
|
||||
|
@ -5048,7 +5044,7 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t*
|
|||
// save value
|
||||
*(int32_t*)(*result + offset) = pSup->resultRowSize;
|
||||
offset += sizeof(int32_t);
|
||||
memcpy(*result + offset, *p1, pSup->resultRowSize);
|
||||
memcpy(*result + offset, pRow, pSup->resultRowSize);
|
||||
offset += pSup->resultRowSize;
|
||||
|
||||
pIter = taosHashIterate(pSup->pResultRowHashTable, pIter);
|
||||
|
@ -5060,15 +5056,11 @@ static void aggEncodeResultRow(SOperatorInfo* pOperator, char** result, int32_t*
|
|||
return;
|
||||
}
|
||||
|
||||
static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t length) {
|
||||
bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length) {
|
||||
if (!result || length <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SAggOperatorInfo* pAggInfo = pOperator->info;
|
||||
SAggSupporter* pSup = &pAggInfo->aggSup;
|
||||
SOptrBasicInfo* pInfo = &pAggInfo->binfo;
|
||||
|
||||
// int32_t size = taosHashGetSize(pSup->pResultRowHashTable);
|
||||
int32_t count = *(int32_t*)(result);
|
||||
|
||||
|
@ -5080,17 +5072,16 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l
|
|||
uint64_t tableGroupId = *(uint64_t*)(result + offset);
|
||||
SResultRow* resultRow = getNewResultRow_rv(pSup->pResultBuf, tableGroupId, pSup->resultRowSize);
|
||||
if (!resultRow) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
return false;
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT);
|
||||
}
|
||||
// add a new result set for a new group
|
||||
taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &resultRow, POINTER_BYTES);
|
||||
SResultRowPosition pos = {.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||
taosHashPut(pSup->pResultRowHashTable, result + offset, keyLen, &pos, sizeof(SResultRowPosition));
|
||||
|
||||
offset += keyLen;
|
||||
int32_t valueLen = *(int32_t*)(result + offset);
|
||||
if (valueLen != pSup->resultRowSize) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
return false;
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT);
|
||||
}
|
||||
offset += sizeof(int32_t);
|
||||
int32_t pageId = resultRow->pageId;
|
||||
|
@ -5101,13 +5092,13 @@ static bool aggDecodeResultRow(SOperatorInfo* pOperator, char* result, int32_t l
|
|||
offset += valueLen;
|
||||
|
||||
initResultRow(resultRow);
|
||||
pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] =
|
||||
(SResultRowPosition){.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||
prepareResultListBuffer(&pInfo->resultRowInfo, pOperator->pTaskInfo->env);
|
||||
pInfo->resultRowInfo.curPos = pInfo->resultRowInfo.size;
|
||||
pInfo->resultRowInfo.pPosition[pInfo->resultRowInfo.size++] = (SResultRowPosition) {.pageId = resultRow->pageId, .offset = resultRow->offset};
|
||||
}
|
||||
|
||||
if (offset != length) {
|
||||
terrno = TSDB_CODE_TSC_INVALID_INPUT;
|
||||
return false;
|
||||
longjmp(pOperator->pTaskInfo->env, TSDB_CODE_TSC_INVALID_INPUT);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -5122,9 +5113,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro
|
|||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity,
|
||||
pAggInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset);
|
||||
if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
@ -5173,8 +5162,7 @@ static SSDataBlock* doMultiTableAggregate(SOperatorInfo* pOperator, bool* newgro
|
|||
updateNumOfRowsInResultRows(pInfo->pCtx, pOperator->numOfOutput, &pInfo->resultRowInfo, pInfo->rowCellInfoOffset);
|
||||
|
||||
initGroupResInfo(&pAggInfo->groupResInfo, &pInfo->resultRowInfo);
|
||||
toSDatablock(&pAggInfo->groupResInfo, pAggInfo->pResultBuf, pInfo->pRes, pAggInfo->binfo.capacity,
|
||||
pAggInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pInfo->pRes, pAggInfo->binfo.capacity, &pAggInfo->groupResInfo, pOperator->pExpr, pAggInfo->pResultBuf, pAggInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
if (pInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pAggInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
|
@ -5189,6 +5177,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator, bool* newgroup)
|
|||
|
||||
SSDataBlock* pRes = pInfo->pRes;
|
||||
blockDataCleanup(pRes);
|
||||
|
||||
#if 0
|
||||
if (pProjectInfo->existDataBlock) { // TODO refactor
|
||||
SSDataBlock* pBlock = pProjectInfo->existDataBlock;
|
||||
|
@ -5333,6 +5322,21 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
|
|||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order);
|
||||
hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0);
|
||||
|
||||
#if 0 // test for encode/decode result info
|
||||
if(pOperator->encodeResultRow){
|
||||
char *result = NULL;
|
||||
int32_t length = 0;
|
||||
SAggSupporter *pSup = &pInfo->aggSup;
|
||||
pOperator->encodeResultRow(pOperator, pSup, &pInfo->binfo, &result, &length);
|
||||
taosHashClear(pSup->pResultRowHashTable);
|
||||
pInfo->binfo.resultRowInfo.size = 0;
|
||||
pOperator->decodeResultRow(pOperator, pSup, &pInfo->binfo, result, length);
|
||||
if(result){
|
||||
taosMemoryFree(result);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
closeAllResultRows(&pInfo->binfo.resultRowInfo);
|
||||
|
@ -5362,8 +5366,7 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator, bool* newgro
|
|||
}
|
||||
|
||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity);
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity,
|
||||
pInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
|
@ -5381,8 +5384,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup
|
|||
}
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity,
|
||||
pInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset);
|
||||
if (pInfo->binfo.pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
@ -5417,8 +5419,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo *pOperator, bool* newgroup
|
|||
|
||||
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pInfo->binfo.capacity);
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pInfo->binfo.pRes, pInfo->binfo.capacity,
|
||||
pInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pInfo->binfo.pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
ASSERT(pInfo->binfo.pRes->info.rows > 0);
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
|
@ -5663,7 +5664,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset);
|
||||
toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset);
|
||||
if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
|
@ -5695,7 +5696,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
|
||||
initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo);
|
||||
blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity);
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset);
|
||||
toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset);
|
||||
if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
}
|
||||
|
@ -5712,7 +5713,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup)
|
|||
SOptrBasicInfo* pBInfo = &pInfo->binfo;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset);
|
||||
toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset);
|
||||
if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
return NULL;
|
||||
|
@ -5744,7 +5745,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup)
|
|||
|
||||
initGroupResInfo(&pInfo->groupResInfo, &pBInfo->resultRowInfo);
|
||||
blockDataEnsureCapacity(pBInfo->pRes, pBInfo->capacity);
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pBInfo->pRes, pBInfo->capacity, pBInfo->rowCellInfoOffset);
|
||||
toSDatablock(pBInfo->pRes, pBInfo->capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pBInfo->rowCellInfoOffset);
|
||||
if (pBInfo->pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
}
|
||||
|
@ -5752,7 +5753,6 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator, bool* newgroup)
|
|||
return pBInfo->pRes->info.rows == 0 ? NULL : pBInfo->pRes;
|
||||
}
|
||||
|
||||
|
||||
static void doHandleRemainBlockForNewGroupImpl(SFillOperatorInfo* pInfo, SResultInfo* pResultInfo, bool* newgroup,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
pInfo->totalInputRows = pInfo->existNewGroupBlock->info.rows;
|
||||
|
@ -5924,7 +5924,7 @@ static void cleanupAggSup(SAggSupporter* pAggSup) {
|
|||
|
||||
int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey) {
|
||||
pBasicInfo->pCtx = createSqlFunctionCtx_rv(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset);
|
||||
pBasicInfo->pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pBasicInfo->rowCellInfoOffset);
|
||||
pBasicInfo->pRes = pResultBlock;
|
||||
pBasicInfo->capacity = numOfRows;
|
||||
|
||||
|
@ -6218,6 +6218,8 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pOperator->getNextFn = doBuildIntervalResult;
|
||||
pOperator->getStreamResFn= doStreamIntervalAgg;
|
||||
pOperator->closeFn = destroyIntervalOperatorInfo;
|
||||
pOperator->encodeResultRow = aggEncodeResultRow;
|
||||
pOperator->decodeResultRow = aggDecodeResultRow;
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -6287,6 +6289,8 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf
|
|||
pOperator->info = pInfo;
|
||||
pOperator->getNextFn = doStateWindowAgg;
|
||||
pOperator->closeFn = destroyStateWindowOperatorInfo;
|
||||
pOperator->encodeResultRow = aggEncodeResultRow;
|
||||
pOperator->decodeResultRow = aggDecodeResultRow;
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -6327,6 +6331,8 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo
|
|||
pOperator->info = pInfo;
|
||||
pOperator->getNextFn = doSessionWindowAgg;
|
||||
pOperator->closeFn = destroySWindowOperatorInfo;
|
||||
pOperator->encodeResultRow = aggEncodeResultRow;
|
||||
pOperator->decodeResultRow = aggDecodeResultRow;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
|
@ -6347,8 +6353,6 @@ SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntim
|
|||
SExprInfo* pExpr, int32_t numOfOutput) {
|
||||
STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo));
|
||||
|
||||
// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
|
||||
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
|
||||
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
|
||||
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
|
@ -6371,14 +6375,13 @@ SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRun
|
|||
SExprInfo* pExpr, int32_t numOfOutput) {
|
||||
STableIntervalOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(STableIntervalOperatorInfo));
|
||||
|
||||
// pInfo->binfo.pCtx = createSqlFunctionCtx(pRuntimeEnv, pExpr, numOfOutput, &pInfo->binfo.rowCellInfoOffset);
|
||||
// pInfo->binfo.pRes = createOutputBuf(pExpr, numOfOutput, pResultInfo->capacity);
|
||||
initResultRowInfo(&pInfo->binfo.resultRowInfo, 8);
|
||||
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
pOperator->name = "AllMultiTableTimeIntervalOperator";
|
||||
// pOperator->operatorType = OP_AllMultiTableTimeInterval;
|
||||
pOperator->blockingOptr = true;
|
||||
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
|
@ -6646,45 +6649,13 @@ bool validateExprColumnInfo(SQueriedTableInfo* pTableInfo, SExprBasicInfo* pExpr
|
|||
return j != INT32_MIN;
|
||||
}
|
||||
|
||||
static int32_t deserializeColFilterInfo(SColumnFilterInfo* pColFilters, int16_t numOfFilters, char** pMsg) {
|
||||
for (int32_t f = 0; f < numOfFilters; ++f) {
|
||||
SColumnFilterInfo* pFilterMsg = (SColumnFilterInfo*)(*pMsg);
|
||||
|
||||
SColumnFilterInfo* pColFilter = &pColFilters[f];
|
||||
pColFilter->filterstr = htons(pFilterMsg->filterstr);
|
||||
|
||||
(*pMsg) += sizeof(SColumnFilterInfo);
|
||||
|
||||
if (pColFilter->filterstr) {
|
||||
pColFilter->len = htobe64(pFilterMsg->len);
|
||||
|
||||
pColFilter->pz =
|
||||
(int64_t)taosMemoryCalloc(1, (size_t)(pColFilter->len + 1 * TSDB_NCHAR_SIZE)); // note: null-terminator
|
||||
if (pColFilter->pz == 0) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
memcpy((void*)pColFilter->pz, (*pMsg), (size_t)pColFilter->len);
|
||||
(*pMsg) += (pColFilter->len + 1);
|
||||
} else {
|
||||
pColFilter->lowerBndi = htobe64(pFilterMsg->lowerBndi);
|
||||
pColFilter->upperBndi = htobe64(pFilterMsg->upperBndi);
|
||||
}
|
||||
|
||||
pColFilter->lowerRelOptr = htons(pFilterMsg->lowerRelOptr);
|
||||
pColFilter->upperRelOptr = htons(pFilterMsg->upperRelOptr);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SResSchema createResSchema(int32_t type, int32_t bytes, int32_t slotId, int32_t scale, int32_t precision,
|
||||
const char* name) {
|
||||
SResSchema s = {0};
|
||||
s.scale = scale;
|
||||
s.type = type;
|
||||
s.bytes = bytes;
|
||||
s.colId = slotId;
|
||||
s.slotId = slotId;
|
||||
s.precision = precision;
|
||||
strncpy(s.name, name, tListLen(s.name));
|
||||
|
||||
|
@ -6726,7 +6697,7 @@ SExprInfo* createExprInfo(SNodeList* pNodeList, SNodeList* pGroupKeys, int32_t*
|
|||
pTargetNode = (STargetNode*)nodesListGetNode(pGroupKeys, i - numOfFuncs);
|
||||
}
|
||||
|
||||
SExprInfo* pExp = &pExprs[pTargetNode->slotId];
|
||||
SExprInfo* pExp = &pExprs[i];
|
||||
|
||||
pExp->pExpr = taosMemoryCalloc(1, sizeof(tExprNode));
|
||||
pExp->pExpr->_function.num = 1;
|
||||
|
@ -6846,8 +6817,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
int32_t numOfCols = 0;
|
||||
tsdbReaderT pDataReader = doCreateDataReader((STableScanPhysiNode*)pPhyNode, pHandle, pTableGroupInfo, (uint64_t)queryId, taskId);
|
||||
SArray* pColList = extractColMatchInfo(pScanPhyNode->pScanCols, pScanPhyNode->node.pOutputDataBlockDesc, &numOfCols);
|
||||
SSDataBlock* pResBlock = createOutputBuf_rv1(pScanPhyNode->node.pOutputDataBlockDesc);
|
||||
|
||||
return createTableScanOperatorInfo(pDataReader, pScanPhyNode->order, numOfCols, pScanPhyNode->count,
|
||||
pScanPhyNode->reverse, pColList, pScanPhyNode->node.pConditions, pTaskInfo);
|
||||
pScanPhyNode->reverse, pColList, pResBlock, pScanPhyNode->node.pConditions, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode;
|
||||
SSDataBlock* pResBlock = createOutputBuf_rv1(pExchange->node.pOutputDataBlockDesc);
|
||||
|
@ -6902,9 +6875,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SExprInfo* pExprInfo = createExprInfo(pAggNode->pAggFuncs, pAggNode->pGroupKeys, &num);
|
||||
SSDataBlock* pResBlock = createOutputBuf_rv1(pPhyNode->pOutputDataBlockDesc);
|
||||
|
||||
SExprInfo* pScalarExprInfo = NULL;
|
||||
int32_t numOfScalarExpr = 0;
|
||||
if (pAggNode->pGroupKeys != NULL) {
|
||||
SArray* pColList = extractColumnInfo(pAggNode->pGroupKeys);
|
||||
return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pTaskInfo, NULL);
|
||||
if (pAggNode->pExprs != NULL) {
|
||||
pScalarExprInfo = createExprInfo(pAggNode->pExprs, NULL, &numOfScalarExpr);
|
||||
}
|
||||
|
||||
return createGroupOperatorInfo(op, pExprInfo, num, pResBlock, pColList, pAggNode->node.pConditions, pScalarExprInfo, numOfScalarExpr, pTaskInfo, NULL);
|
||||
} else {
|
||||
return createAggregateOperatorInfo(op, pExprInfo, num, pResBlock, pTaskInfo, pTableGroupInfo);
|
||||
}
|
||||
|
@ -6923,7 +6902,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
.precision = pIntervalPhyNode->precision
|
||||
};
|
||||
|
||||
int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->pTspk)->slotId;
|
||||
int32_t primaryTsSlotId = ((SColumnNode*) pIntervalPhyNode->window.pTspk)->slotId;
|
||||
return createIntervalOperatorInfo(op, pExprInfo, num, pResBlock, &interval, primaryTsSlotId, pTableGroupInfo, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SORT == type) {
|
||||
SSortPhysiNode* pSortPhyNode = (SSortPhysiNode*)pPhyNode;
|
||||
|
@ -7151,10 +7130,15 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
}
|
||||
|
||||
*numOfOutputCols = 0;
|
||||
|
||||
int32_t num = LIST_LENGTH(pOutputNodeList->pSlots);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SSlotDescNode* pNode = (SSlotDescNode*)nodesListGetNode(pOutputNodeList->pSlots, i);
|
||||
// todo: add reserve flag check
|
||||
if (pNode->slotId >= numOfCols) { // it is a column reserved for the arithmetic expression calculation
|
||||
(*numOfOutputCols) += 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
SColMatchInfo* info = taosArrayGet(pList, pNode->slotId);
|
||||
if (pNode->output) {
|
||||
(*numOfOutputCols) += 1;
|
||||
|
|
|
@ -166,7 +166,7 @@ static int32_t buildGroupKeys(void* pKey, const SArray* pGroupColVals) {
|
|||
// assign the group keys or user input constant values if required
|
||||
static void doAssignGroupKeys(SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t totalRows, int32_t rowIndex) {
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
if (pCtx[i].functionId == -1) {
|
||||
if (pCtx[i].functionId == -1) { // select count(*),key from t group by key.
|
||||
SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(&pCtx[i]);
|
||||
|
||||
SColumnInfoData* pColInfoData = pCtx[i].input.pData[0];
|
||||
|
@ -265,7 +265,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset);
|
||||
if (pRes->info.rows == 0 || !hasRemainDataInCurrentGroup(&pInfo->groupResInfo)) {
|
||||
pOperator->status = OP_EXEC_DONE;
|
||||
}
|
||||
|
@ -285,6 +285,12 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order);
|
||||
|
||||
// there is an scalar expression that needs to be calculated before apply the group aggregation.
|
||||
if (pInfo->pScalarExprInfo != NULL) {
|
||||
projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL);
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
doHashGroupbyAgg(pOperator, pBlock);
|
||||
}
|
||||
|
@ -305,7 +311,7 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
initGroupResInfo(&pInfo->groupResInfo, &pInfo->binfo.resultRowInfo);
|
||||
|
||||
while(1) {
|
||||
toSDatablock(&pInfo->groupResInfo, pInfo->aggSup.pResultBuf, pRes, pInfo->binfo.capacity, pInfo->binfo.rowCellInfoOffset);
|
||||
toSDatablock(pRes, pInfo->binfo.capacity, &pInfo->groupResInfo, pOperator->pExpr, pInfo->aggSup.pResultBuf, pInfo->binfo.rowCellInfoOffset);
|
||||
doFilter(pInfo->pCondition, pRes);
|
||||
|
||||
bool hasRemain = hasRemainDataInCurrentGroup(&pInfo->groupResInfo);
|
||||
|
@ -322,8 +328,8 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
return (pRes->info.rows == 0)? NULL:pRes;
|
||||
}
|
||||
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition, SExecTaskInfo* pTaskInfo,
|
||||
const STableGroupInfo* pTableGroupInfo) {
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList,
|
||||
SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo) {
|
||||
SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pInfo == NULL || pOperator == NULL) {
|
||||
|
@ -333,6 +339,11 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
|||
pInfo->pGroupCols = pGroupColList;
|
||||
pInfo->pCondition = pCondition;
|
||||
|
||||
pInfo->pScalarExprInfo = pScalarExprInfo;
|
||||
pInfo->numOfScalarExpr = numOfScalarExpr;
|
||||
pInfo->pScalarFuncCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
|
||||
int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
@ -352,6 +363,8 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
|||
pOperator->_openFn = operatorDummyOpenFn;
|
||||
pOperator->getNextFn = hashGroupbyAggregate;
|
||||
pOperator->closeFn = destroyGroupOperatorInfo;
|
||||
pOperator->encodeResultRow = aggEncodeResultRow;
|
||||
pOperator->decodeResultRow = aggDecodeResultRow;
|
||||
|
||||
code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
|
|
@ -113,7 +113,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
SSDataBlock* pBlock = &pTableScanInfo->block;
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo;
|
||||
|
||||
*newgroup = false;
|
||||
|
@ -218,7 +218,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
}
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
|
||||
int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo,
|
||||
int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock,
|
||||
SNode* pCondition, SExecTaskInfo* pTaskInfo) {
|
||||
assert(repeatTime > 0);
|
||||
|
||||
|
@ -232,12 +232,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->block.pDataBlock = taosArrayInit(numOfOutput, sizeof(SColumnInfoData));
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
SColumnInfoData idata = {0};
|
||||
taosArrayPush(pInfo->block.pDataBlock, &idata);
|
||||
}
|
||||
|
||||
pInfo->pResBlock = pResBlock;
|
||||
pInfo->pFilterNode = pCondition;
|
||||
pInfo->dataReader = pTsdbReadHandle;
|
||||
pInfo->times = repeatTime;
|
||||
|
@ -312,7 +307,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
tsdbGetFileBlocksDistInfo(pTableScanInfo->dataReader, &tableBlockDist);
|
||||
tableBlockDist.numOfRowsInMemTable = (int32_t) tsdbGetNumOfRowsInMemTable(pTableScanInfo->dataReader);
|
||||
|
||||
SSDataBlock* pBlock = &pTableScanInfo->block;
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
pBlock->info.rows = 1;
|
||||
pBlock->info.numOfCols = 1;
|
||||
|
||||
|
@ -343,13 +338,13 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo*
|
|||
}
|
||||
|
||||
pInfo->dataReader = dataReader;
|
||||
pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||
// pInfo->block.pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||
|
||||
SColumnInfoData infoData = {0};
|
||||
infoData.info.type = TSDB_DATA_TYPE_BINARY;
|
||||
infoData.info.bytes = 1024;
|
||||
infoData.info.colId = 0;
|
||||
taosArrayPush(pInfo->block.pDataBlock, &infoData);
|
||||
// taosArrayPush(pInfo->block.pDataBlock, &infoData);
|
||||
|
||||
pOperator->name = "DataBlockInfoScanOperator";
|
||||
// pOperator->operatorType = OP_TableBlockInfoScan;
|
||||
|
|
|
@ -35,16 +35,20 @@ extern "C" {
|
|||
#define FUNC_MGT_TIMEORDER_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(6)
|
||||
#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7)
|
||||
#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8)
|
||||
#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9)
|
||||
#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10)
|
||||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
typedef int32_t (*FCheckAndGetResultType)(SFunctionNode* pFunc);
|
||||
typedef EFuncDataRequired (*FFuncDataRequired)(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
|
||||
typedef struct SBuiltinFuncDefinition {
|
||||
char name[FUNCTION_NAME_MAX_LENGTH];
|
||||
EFunctionType type;
|
||||
uint64_t classification;
|
||||
FCheckAndGetResultType checkFunc;
|
||||
FFuncDataRequired dataRequiredFunc;
|
||||
FExecGetEnv getEnvFunc;
|
||||
FExecInit initFunc;
|
||||
FExecProcess processFunc;
|
||||
|
|
|
@ -21,10 +21,12 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
bool functionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
void functionFinalize(SqlFunctionCtx *pCtx);
|
||||
|
||||
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t countFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
|
|
|
@ -19,14 +19,15 @@
|
|||
#include "taoserror.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc);
|
||||
int32_t checkAndGetResultType(SFunctionNode* pFunc);
|
||||
|
||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||
{
|
||||
.name = "count",
|
||||
.type = FUNCTION_TYPE_COUNT,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.dataRequiredFunc = countDataRequired,
|
||||
.getEnvFunc = getCountFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = countFunction,
|
||||
|
@ -36,7 +37,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "sum",
|
||||
.type = FUNCTION_TYPE_SUM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getSumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = sumFunction,
|
||||
|
@ -46,7 +47,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "min",
|
||||
.type = FUNCTION_TYPE_MIN,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minFunctionSetup,
|
||||
.processFunc = minFunction,
|
||||
|
@ -56,7 +57,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "max",
|
||||
.type = FUNCTION_TYPE_MAX,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -66,7 +67,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "stddev",
|
||||
.type = FUNCTION_TYPE_STDDEV,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getStddevFuncEnv,
|
||||
.initFunc = stddevFunctionSetup,
|
||||
.processFunc = stddevFunction,
|
||||
|
@ -76,7 +77,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "percentile",
|
||||
.type = FUNCTION_TYPE_PERCENTILE,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getPercentileFuncEnv,
|
||||
.initFunc = percentileFunctionSetup,
|
||||
.processFunc = percentileFunction,
|
||||
|
@ -86,7 +87,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "apercentile",
|
||||
.type = FUNCTION_TYPE_APERCENTILE,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -96,7 +97,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "top",
|
||||
.type = FUNCTION_TYPE_TOP,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -106,7 +107,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "bottom",
|
||||
.type = FUNCTION_TYPE_BOTTOM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -116,7 +117,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "spread",
|
||||
.type = FUNCTION_TYPE_SPREAD,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -126,7 +127,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "last_row",
|
||||
.type = FUNCTION_TYPE_LAST_ROW,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -136,7 +137,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "first",
|
||||
.type = FUNCTION_TYPE_FIRST,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = firstFunction,
|
||||
|
@ -146,7 +147,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "last",
|
||||
.type = FUNCTION_TYPE_LAST,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = lastFunction,
|
||||
|
@ -156,7 +157,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "diff",
|
||||
.type = FUNCTION_TYPE_DIFF,
|
||||
.classification = FUNC_MGT_NONSTANDARD_SQL_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getDiffFuncEnv,
|
||||
.initFunc = diffFunctionSetup,
|
||||
.processFunc = diffFunction,
|
||||
|
@ -166,7 +167,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "abs",
|
||||
.type = FUNCTION_TYPE_ABS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = absFunction,
|
||||
|
@ -176,7 +177,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "log",
|
||||
.type = FUNCTION_TYPE_LOG,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = logFunction,
|
||||
|
@ -186,7 +187,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "pow",
|
||||
.type = FUNCTION_TYPE_POW,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = powFunction,
|
||||
|
@ -196,7 +197,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "sqrt",
|
||||
.type = FUNCTION_TYPE_SQRT,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sqrtFunction,
|
||||
|
@ -206,7 +207,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "ceil",
|
||||
.type = FUNCTION_TYPE_CEIL,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = ceilFunction,
|
||||
|
@ -216,7 +217,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "floor",
|
||||
.type = FUNCTION_TYPE_FLOOR,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = floorFunction,
|
||||
|
@ -226,7 +227,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "round",
|
||||
.type = FUNCTION_TYPE_ROUND,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = roundFunction,
|
||||
|
@ -236,7 +237,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "sin",
|
||||
.type = FUNCTION_TYPE_SIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = sinFunction,
|
||||
|
@ -246,7 +247,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "cos",
|
||||
.type = FUNCTION_TYPE_COS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = cosFunction,
|
||||
|
@ -256,7 +257,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "tan",
|
||||
.type = FUNCTION_TYPE_TAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = tanFunction,
|
||||
|
@ -266,7 +267,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "asin",
|
||||
.type = FUNCTION_TYPE_ASIN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = asinFunction,
|
||||
|
@ -276,7 +277,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "acos",
|
||||
.type = FUNCTION_TYPE_ACOS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = acosFunction,
|
||||
|
@ -286,7 +287,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "atan",
|
||||
.type = FUNCTION_TYPE_ATAN,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = atanFunction,
|
||||
|
@ -296,7 +297,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "length",
|
||||
.type = FUNCTION_TYPE_LENGTH,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = lengthFunction,
|
||||
|
@ -306,7 +307,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "char_length",
|
||||
.type = FUNCTION_TYPE_CHAR_LENGTH,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = charLengthFunction,
|
||||
|
@ -316,7 +317,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "concat",
|
||||
.type = FUNCTION_TYPE_CONCAT,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = concatFunction,
|
||||
|
@ -326,7 +327,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "concat_ws",
|
||||
.type = FUNCTION_TYPE_CONCAT_WS,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = concatWsFunction,
|
||||
|
@ -336,7 +337,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "lower",
|
||||
.type = FUNCTION_TYPE_LOWER,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = lowerFunction,
|
||||
|
@ -346,7 +347,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "upper",
|
||||
.type = FUNCTION_TYPE_UPPER,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = upperFunction,
|
||||
|
@ -356,7 +357,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "ltrim",
|
||||
.type = FUNCTION_TYPE_LTRIM,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = ltrimFunction,
|
||||
|
@ -366,7 +367,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "rtrim",
|
||||
.type = FUNCTION_TYPE_RTRIM,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = rtrimFunction,
|
||||
|
@ -376,7 +377,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "substr",
|
||||
.type = FUNCTION_TYPE_SUBSTR,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_STRING_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = substrFunction,
|
||||
|
@ -386,17 +387,17 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "cast",
|
||||
.type = FUNCTION_TYPE_CAST,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.sprocessFunc = castFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_rowts",
|
||||
.type = FUNCTION_TYPE_ROWTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
|
@ -406,7 +407,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "tbname",
|
||||
.type = FUNCTION_TYPE_TBNAME,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
|
@ -416,7 +417,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "_qstartts",
|
||||
.type = FUNCTION_TYPE_QSTARTTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qStartTsFunction,
|
||||
|
@ -426,7 +427,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "_qendts",
|
||||
.type = FUNCTION_TYPE_QENDTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = qEndTsFunction,
|
||||
|
@ -436,7 +437,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "_wstartts",
|
||||
.type = FUNCTION_TYPE_WSTARTTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winStartTsFunction,
|
||||
|
@ -446,7 +447,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "_wendts",
|
||||
.type = FUNCTION_TYPE_QENDTS,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winEndTsFunction,
|
||||
|
@ -456,7 +457,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "_wduration",
|
||||
.type = FUNCTION_TYPE_WDURATION,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_WINDOW_PC_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winDurFunction,
|
||||
|
@ -466,7 +467,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "now",
|
||||
.type = FUNCTION_TYPE_NOW,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC | FUNC_MGT_DATETIME_FUNC,
|
||||
.checkFunc = stubCheckAndGetResultType,
|
||||
.checkFunc = checkAndGetResultType,
|
||||
.getEnvFunc = getTimePseudoFuncEnv,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = winDurFunction,
|
||||
|
@ -476,7 +477,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
|
||||
const int32_t funcMgtBuiltinsNum = (sizeof(funcMgtBuiltins) / sizeof(SBuiltinFuncDefinition));
|
||||
|
||||
int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
|
||||
int32_t checkAndGetResultType(SFunctionNode* pFunc) {
|
||||
switch(pFunc->funcType) {
|
||||
case FUNCTION_TYPE_WDURATION:
|
||||
case FUNCTION_TYPE_COUNT: {
|
||||
|
@ -599,7 +600,13 @@ int32_t stubCheckAndGetResultType(SFunctionNode* pFunc) {
|
|||
break;
|
||||
}
|
||||
case FUNCTION_TYPE_CAST: {
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT };
|
||||
//type
|
||||
SValueNode* pParam = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
int32_t paraType = pParam->datum.i;
|
||||
//bytes
|
||||
pParam = nodesListGetNode(pFunc->pParameterList, 2);
|
||||
int32_t paraBytes = pParam->datum.i;
|
||||
pFunc->node.resType = (SDataType) { .bytes = paraBytes, .type = paraType};
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,14 @@ void functionFinalize(SqlFunctionCtx *pCtx) {
|
|||
pResInfo->isNullRes = (pResInfo->numOfRes == 0)? 1:0;
|
||||
}
|
||||
|
||||
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) {
|
||||
return FUNC_DATA_REQUIRED_NO_NEEDED;
|
||||
}
|
||||
return FUNC_DATA_REQUIRED_STATIS_NEEDED;
|
||||
}
|
||||
|
||||
bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(int64_t);
|
||||
return true;
|
||||
|
@ -212,6 +220,9 @@ bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
|||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*((uint8_t *)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
*((int8_t*)buf) = 0;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -255,6 +266,9 @@ bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(((double *)buf), DBL_MAX);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
*((int8_t*)buf) = 1;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
@ -385,8 +399,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
|||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) {
|
||||
LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
LOOPCHECK_N(*(int16_t*) buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
|
|
|
@ -76,6 +76,16 @@ int32_t fmGetFuncResultType(SFunctionNode* pFunc) {
|
|||
return funcMgtBuiltins[pFunc->funcId].checkFunc(pFunc);
|
||||
}
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
}
|
||||
if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
}
|
||||
return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow);
|
||||
}
|
||||
|
||||
int32_t fmGetFuncExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -120,6 +130,13 @@ bool fmIsNonstandardSQLFunc(int32_t funcId) {
|
|||
return isSpecificClassifyFunc(funcId, FUNC_MGT_NONSTANDARD_SQL_FUNC);
|
||||
}
|
||||
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED);
|
||||
}
|
||||
|
||||
bool fmIsDynamicScanOptimizedFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED);
|
||||
}
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
void* m = gFunMgtService.pFuncNameHashTable;
|
||||
|
|
|
@ -541,7 +541,7 @@ struct SFillColInfo* createFillColInfo(SExprInfo* pExpr, int32_t numOfOutput, co
|
|||
pFillCol[i].col.bytes = pExprInfo->base.resSchema.bytes;
|
||||
pFillCol[i].col.type = (int8_t)pExprInfo->base.resSchema.type;
|
||||
pFillCol[i].col.offset = offset;
|
||||
pFillCol[i].col.colId = pExprInfo->base.resSchema.colId;
|
||||
pFillCol[i].col.colId = pExprInfo->base.resSchema.slotId;
|
||||
pFillCol[i].tagIndex = -2;
|
||||
pFillCol[i].flag = pExprInfo->base.pParam[0].pCol->flag; // always be the normal column for table query
|
||||
// pFillCol[i].functionId = pExprInfo->pExpr->_function.functionId;
|
||||
|
|
|
@ -92,7 +92,7 @@ WriterCtx* writerCtxCreate(WriterType type, const char* path, bool readOnly, int
|
|||
ctx->file.readOnly = readOnly;
|
||||
if (readOnly == false) {
|
||||
// ctx->file.pFile = open(path, O_WRONLY | O_CREAT | O_APPEND, S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
ctx->file.pFile = taosOpenFile(path, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
taosFtruncateFile(ctx->file.pFile, 0);
|
||||
int64_t file_size;
|
||||
taosStatFile(path, &file_size, NULL);
|
||||
|
|
|
@ -375,6 +375,9 @@ static void monGenDnodeJson(SMonInfo *pMonitor) {
|
|||
tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes);
|
||||
tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum);
|
||||
tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode);
|
||||
tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode);
|
||||
tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode);
|
||||
tjsonAddDoubleToObject(pJson, "has_bnode", pInfo->has_bnode);
|
||||
}
|
||||
|
||||
static void monGenDiskJson(SMonInfo *pMonitor) {
|
||||
|
@ -530,7 +533,7 @@ void monSendReport() {
|
|||
if (pCont != NULL) {
|
||||
EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT;
|
||||
if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) {
|
||||
uError("failed to send monitor msg since %s", terrstr());
|
||||
uError("failed to send monitor msg");
|
||||
}
|
||||
taosMemoryFree(pCont);
|
||||
}
|
||||
|
|
|
@ -194,9 +194,9 @@ int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) {
|
|||
if (tDecodeCStrTo(decoder, desc.database_name) < 0) return -1;
|
||||
if (tDecodeCStrTo(decoder, desc.status) < 0) return -1;
|
||||
for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) {
|
||||
SMonVnodeDesc vdesc = {0};
|
||||
if (tDecodeI32(decoder, &vdesc.dnode_id) < 0) return -1;
|
||||
if (tDecodeCStrTo(decoder, vdesc.vnode_role) < 0) return -1;
|
||||
SMonVnodeDesc *pVDesc = &desc.vnodes[j];
|
||||
if (tDecodeI32(decoder, &pVDesc->dnode_id) < 0) return -1;
|
||||
if (tDecodeCStrTo(decoder, pVDesc->vnode_role) < 0) return -1;
|
||||
}
|
||||
taosArrayPush(pInfo->vgroups, &desc);
|
||||
}
|
||||
|
@ -205,15 +205,15 @@ int32_t tDecodeSMonVgroupInfo(SCoder *decoder, SMonVgroupInfo *pInfo) {
|
|||
|
||||
int32_t tEncodeSMonGrantInfo(SCoder *encoder, const SMonGrantInfo *pInfo) {
|
||||
if (tEncodeI32(encoder, pInfo->expire_time) < 0) return -1;
|
||||
if (tEncodeI32(encoder, pInfo->timeseries_used) < 0) return -1;
|
||||
if (tEncodeI32(encoder, pInfo->timeseries_total) < 0) return -1;
|
||||
if (tEncodeI64(encoder, pInfo->timeseries_used) < 0) return -1;
|
||||
if (tEncodeI64(encoder, pInfo->timeseries_total) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSMonGrantInfo(SCoder *decoder, SMonGrantInfo *pInfo) {
|
||||
if (tDecodeI32(decoder, &pInfo->expire_time) < 0) return -1;
|
||||
if (tDecodeI32(decoder, &pInfo->timeseries_used) < 0) return -1;
|
||||
if (tDecodeI32(decoder, &pInfo->timeseries_total) < 0) return -1;
|
||||
if (tDecodeI64(decoder, &pInfo->timeseries_used) < 0) return -1;
|
||||
if (tDecodeI64(decoder, &pInfo->timeseries_total) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ const char* nodesNodeName(ENodeType type) {
|
|||
case QUERY_NODE_TARGET:
|
||||
return "Target";
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return "TupleDesc";
|
||||
return "DataBlockDesc";
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return "SlotDesc";
|
||||
case QUERY_NODE_COLUMN_DEF:
|
||||
|
@ -723,6 +723,9 @@ static int32_t jsonToPhysiTagScanNode(const SJson* pJson, void* pObj) {
|
|||
static const char* jkTableScanPhysiPlanScanFlag = "ScanFlag";
|
||||
static const char* jkTableScanPhysiPlanStartKey = "StartKey";
|
||||
static const char* jkTableScanPhysiPlanEndKey = "EndKey";
|
||||
static const char* jkTableScanPhysiPlanRatio = "Ratio";
|
||||
static const char* jkTableScanPhysiPlanDataRequired = "DataRequired";
|
||||
static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs";
|
||||
|
||||
static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj;
|
||||
|
@ -737,6 +740,15 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanEndKey, pNode->scanRange.ekey);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddDoubleToObject(pJson, jkTableScanPhysiPlanRatio, pNode->ratio);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkTableScanPhysiPlanDynamicScanFuncs, pNode->pDynamicScanFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -754,6 +766,15 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetBigIntValue(pJson, jkTableScanPhysiPlanEndKey, &pNode->scanRange.ekey);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetDoubleValue(pJson, jkTableScanPhysiPlanRatio, &pNode->ratio);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanDataRequired, pNode->dataRequired);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1060,6 +1081,7 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
|||
|
||||
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
||||
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
||||
static const char* jkWindowPhysiPlanTsPk = "TsPk";
|
||||
|
||||
static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SWinodwPhysiNode* pNode = (const SWinodwPhysiNode*)pObj;
|
||||
|
@ -1071,6 +1093,9 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkWindowPhysiPlanFuncs, pNode->pFuncs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1085,6 +1110,9 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkWindowPhysiPlanFuncs, &pNode->pFuncs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1095,7 +1123,6 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding";
|
|||
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
|
||||
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
|
||||
static const char* jkIntervalPhysiPlanFill = "Fill";
|
||||
static const char* jkIntervalPhysiPlanTsPk = "TsPk";
|
||||
static const char* jkIntervalPhysiPlanPrecision = "Precision";
|
||||
|
||||
static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
||||
|
@ -1120,9 +1147,6 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision);
|
||||
}
|
||||
|
@ -1152,9 +1176,6 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision);
|
||||
}
|
||||
|
@ -2291,7 +2312,7 @@ static int32_t jsonToDataBlockDescNode(const SJson* pJson, void* pObj) {
|
|||
code = jsonToNodeList(pJson, jkDataBlockDescSlots, &pNode->pSlots);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetSmallIntValue(pJson, jkDataBlockPrecision, &pNode->precision);
|
||||
code = tjsonGetUTinyIntValue(pJson, jkDataBlockPrecision, &pNode->precision);
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -2767,6 +2788,7 @@ int32_t nodesStringToList(const char* pStr, SNodeList** pList) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int32_t code = jsonToNodeListImpl(pJson, pList);
|
||||
tjsonDelete(pJson);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(*pList);
|
||||
terrno = code;
|
||||
|
|
|
@ -77,9 +77,14 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
|
|||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
res = walkNode(((SOrderByExprNode*)pNode)->pExpr, order, walker, pContext);
|
||||
break;
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
res = walkNode(((SStateWindowNode*)pNode)->pExpr, order, walker, pContext);
|
||||
case QUERY_NODE_STATE_WINDOW: {
|
||||
SStateWindowNode* pState = (SStateWindowNode*)pNode;
|
||||
res = walkNode(pState->pExpr, order, walker, pContext);
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = walkNode(pState->pCol, order, walker, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_SESSION_WINDOW: {
|
||||
SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
|
||||
res = walkNode(pSession->pCol, order, walker, pContext);
|
||||
|
@ -211,12 +216,22 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
|
|||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
res = rewriteNode(&(((SOrderByExprNode*)pNode)->pExpr), order, rewriter, pContext);
|
||||
break;
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
res = rewriteNode(&(((SStateWindowNode*)pNode)->pExpr), order, rewriter, pContext);
|
||||
case QUERY_NODE_STATE_WINDOW: {
|
||||
SStateWindowNode* pState = (SStateWindowNode*)pNode;
|
||||
res = rewriteNode(&pState->pExpr, order, rewriter, pContext);
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&pState->pCol, order, rewriter, pContext);
|
||||
}
|
||||
break;
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
res = rewriteNode(&(((SSessionWindowNode*)pNode)->pCol), order, rewriter, pContext);
|
||||
}
|
||||
case QUERY_NODE_SESSION_WINDOW: {
|
||||
SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
|
||||
res = rewriteNode(&pSession->pCol, order, rewriter, pContext);
|
||||
if (DEAL_RES_ERROR != res) {
|
||||
res = rewriteNode(&pSession->pGap, order, rewriter, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_INTERVAL_WINDOW: {
|
||||
SIntervalWindowNode* pInterval = (SIntervalWindowNode*)pNode;
|
||||
res = rewriteNode(&(pInterval->pInterval), order, rewriter, pContext);
|
||||
|
|
|
@ -252,6 +252,7 @@ static void destroyWinodwPhysiNode(SWinodwPhysiNode* pNode) {
|
|||
destroyPhysiNode((SPhysiNode*)pNode);
|
||||
nodesDestroyList(pNode->pExprs);
|
||||
nodesDestroyList(pNode->pFuncs);
|
||||
nodesDestroyNode(pNode->pTspk);
|
||||
}
|
||||
|
||||
static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
|
||||
|
@ -593,7 +594,6 @@ void nodesDestroyNode(SNodeptr pNode) {
|
|||
SIntervalPhysiNode* pPhyNode = (SIntervalPhysiNode*)pNode;
|
||||
destroyWinodwPhysiNode((SWinodwPhysiNode*)pPhyNode);
|
||||
nodesDestroyNode(pPhyNode->pFill);
|
||||
nodesDestroyNode(pPhyNode->pTspk);
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -694,6 +694,17 @@ int32_t nodesListMakeAppend(SNodeList** pList, SNodeptr pNode) {
|
|||
return nodesListAppend(*pList, pNode);
|
||||
}
|
||||
|
||||
int32_t nodesListMakeStrictAppend(SNodeList** pList, SNodeptr pNode) {
|
||||
if (NULL == *pList) {
|
||||
*pList = nodesMakeList();
|
||||
if (NULL == *pList) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return nodesListStrictAppend(*pList, pNode);
|
||||
}
|
||||
|
||||
int32_t nodesListAppendList(SNodeList* pTarget, SNodeList* pSrc) {
|
||||
if (NULL == pTarget || NULL == pSrc) {
|
||||
return TSDB_CODE_FAILED;
|
||||
|
|
|
@ -257,13 +257,20 @@ SNodeList* addValueNodeFromTypeToList(SAstCreateContext* pCxt, SDataType dataTyp
|
|||
char buf[64] = {0};
|
||||
//add value node for type
|
||||
snprintf(buf, sizeof(buf), "%u", dataType.type);
|
||||
SToken token = {.type = TSDB_DATA_TYPE_TINYINT, .n = strlen(buf), .z = buf};
|
||||
SToken token = {.type = TSDB_DATA_TYPE_SMALLINT, .n = strlen(buf), .z = buf};
|
||||
SNode* pNode = createValueNode(pCxt, token.type, &token);
|
||||
addNodeToList(pCxt, pList, pNode);
|
||||
|
||||
//add value node for bytes
|
||||
memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, sizeof(buf), "%u", dataType.bytes);
|
||||
int32_t bytes;
|
||||
if (IS_VAR_DATA_TYPE(dataType.type)) {
|
||||
bytes = (dataType.type == TSDB_DATA_TYPE_NCHAR) ? dataType.bytes * TSDB_NCHAR_SIZE : dataType.bytes;
|
||||
bytes += VARSTR_HEADER_SIZE;
|
||||
} else {
|
||||
bytes = dataType.bytes;
|
||||
}
|
||||
snprintf(buf, sizeof(buf), "%d", bytes);
|
||||
token.type = TSDB_DATA_TYPE_BIGINT;
|
||||
token.n = strlen(buf);
|
||||
token.z = buf;
|
||||
|
@ -458,6 +465,13 @@ SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap
|
|||
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
|
||||
SStateWindowNode* state = (SStateWindowNode*)nodesMakeNode(QUERY_NODE_STATE_WINDOW);
|
||||
CHECK_OUT_OF_MEM(state);
|
||||
state->pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
if (NULL == state->pCol) {
|
||||
nodesDestroyNode(state);
|
||||
CHECK_OUT_OF_MEM(state->pCol);
|
||||
}
|
||||
((SColumnNode*)state->pCol)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(((SColumnNode*)state->pCol)->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
state->pExpr = pExpr;
|
||||
return (SNode*)state;
|
||||
}
|
||||
|
@ -587,34 +601,6 @@ SNode* createDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
static bool checkAndSetKeepOption(SAstCreateContext* pCxt, SNodeList* pKeep, int32_t* pKeep0, int32_t* pKeep1, int32_t* pKeep2) {
|
||||
int32_t numOfKeep = LIST_LENGTH(pKeep);
|
||||
if (numOfKeep > 3 || numOfKeep < 1) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid number of keep options");
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t daysToKeep0 = strtol(((SValueNode*)nodesListGetNode(pKeep, 0))->literal, NULL, 10);
|
||||
int32_t daysToKeep1 = numOfKeep > 1 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 1))->literal, NULL, 10) : daysToKeep0;
|
||||
int32_t daysToKeep2 = numOfKeep > 2 ? strtol(((SValueNode*)nodesListGetNode(pKeep, 2))->literal, NULL, 10) : daysToKeep1;
|
||||
if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP ||
|
||||
daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen,
|
||||
"invalid option keep: %d, %d, %d valid range: [%d, %d]", daysToKeep0, daysToKeep1, daysToKeep2, TSDB_MIN_KEEP, TSDB_MAX_KEEP);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!((daysToKeep0 <= daysToKeep1) && (daysToKeep1 <= daysToKeep2))) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "invalid keep value, should be keep0 <= keep1 <= keep2");
|
||||
return false;
|
||||
}
|
||||
|
||||
*pKeep0 = daysToKeep0;
|
||||
*pKeep1 = daysToKeep1;
|
||||
*pKeep2 = daysToKeep2;
|
||||
return true;
|
||||
}
|
||||
|
||||
SNode* setDatabaseAlterOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) {
|
||||
switch (pAlterOption->type) {
|
||||
case DB_OPTION_BLOCKS:
|
||||
|
|
|
@ -45,7 +45,7 @@ static EDealRes calcConstOperator(SOperatorNode** pNode, void* pContext) {
|
|||
|
||||
static EDealRes calcConstFunction(SFunctionNode** pNode, void* pContext) {
|
||||
SFunctionNode* pFunc = *pNode;
|
||||
if (fmIsPseudoColumnFunc(pFunc->funcId)) {
|
||||
if (!fmIsScalarFunc(pFunc->funcId)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
SNode* pParam = NULL;
|
||||
|
@ -61,6 +61,7 @@ static EDealRes calcConstLogicCond(SLogicConditionNode** pNode, void* pContext)
|
|||
SLogicConditionNode* pCond = *pNode;
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pCond->pParameterList) {
|
||||
// todo calc "true and c1 > 10"
|
||||
if (QUERY_NODE_VALUE != nodeType(pParam)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -605,6 +605,12 @@ typedef struct SMemParam {
|
|||
static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param) {
|
||||
SMemParam* pa = (SMemParam*)param;
|
||||
SRowBuilder* rb = pa->rb;
|
||||
|
||||
if (value == NULL) { // it is a null data
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset, pa->colIdx);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
|
||||
const char* rowEnd = tdRowEnd(rb->pBuf);
|
||||
STR_WITH_SIZE_TO_VARSTR(rowEnd, value, len);
|
||||
|
@ -621,14 +627,9 @@ static FORCE_INLINE int32_t MemRowAppend(SMsgBuf* pMsgBuf, const void* value, in
|
|||
varDataSetLen(rowEnd, output);
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, rowEnd, false, pa->toffset, pa->colIdx);
|
||||
} else {
|
||||
if (value == NULL) { // it is a null data
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NULL, value, false, pa->toffset,
|
||||
pa->colIdx);
|
||||
} else {
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset,
|
||||
pa->colIdx);
|
||||
}
|
||||
tdAppendColValToRow(rb, pa->schema->colId, pa->schema->type, TD_VTYPE_NORM, value, false, pa->toffset, pa->colIdx);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "parUtil.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : ((SValueNode*)(pVal))->datum.i)
|
||||
#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal)))
|
||||
|
||||
typedef struct STranslateContext {
|
||||
SParseContext* pParseCxt;
|
||||
|
@ -380,6 +380,7 @@ static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
|
|||
|
||||
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
||||
uint8_t precision = (NULL != pCxt->pCurrStmt ? pCxt->pCurrStmt->precision : pVal->node.resType.precision);
|
||||
pVal->node.resType.precision = precision;
|
||||
if (pVal->isDuration) {
|
||||
if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, precision) !=
|
||||
TSDB_CODE_SUCCESS) {
|
||||
|
@ -452,6 +453,9 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
} else {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_BOOL;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_BOOL].bytes;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
@ -1041,6 +1045,27 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int64_t getUnitPerMinute(uint8_t precision) {
|
||||
switch (precision) {
|
||||
case TSDB_TIME_PRECISION_MILLI:
|
||||
return MILLISECOND_PER_MINUTE;
|
||||
case TSDB_TIME_PRECISION_MICRO:
|
||||
return MILLISECOND_PER_MINUTE * 1000L;
|
||||
case TSDB_TIME_PRECISION_NANO:
|
||||
return NANOSECOND_PER_MINUTE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return MILLISECOND_PER_MINUTE;
|
||||
}
|
||||
|
||||
static int64_t getBigintFromValueNode(SValueNode* pVal) {
|
||||
if (pVal->isDuration) {
|
||||
return pVal->datum.i / getUnitPerMinute(pVal->node.resType.precision);
|
||||
}
|
||||
return pVal->datum.i;
|
||||
}
|
||||
|
||||
static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbReq* pReq) {
|
||||
if (NULL != pRetentions) {
|
||||
pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions), sizeof(SRetention));
|
||||
|
@ -1098,7 +1123,10 @@ static int32_t checkRangeOption(STranslateContext* pCxt, const char* pName, SVal
|
|||
if (DEAL_RES_ERROR == translateValue(pCxt, pVal)) {
|
||||
return pCxt->errCode;
|
||||
}
|
||||
int64_t val = pVal->datum.i;
|
||||
if (pVal->isDuration && (TIME_UNIT_MINUTE != pVal->unit && TIME_UNIT_HOUR != pVal->unit && TIME_UNIT_DAY != pVal->unit)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_OPTION_UNIT, pName, pVal->unit);
|
||||
}
|
||||
int64_t val = getBigintFromValueNode(pVal);
|
||||
if (val < minVal || val > maxVal) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_RANGE_OPTION, pName, val, minVal, maxVal);
|
||||
}
|
||||
|
@ -1187,9 +1215,18 @@ static int32_t checkKeepOption(STranslateContext* pCxt, SNodeList* pKeep) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t daysToKeep0 = ((SValueNode*)nodesListGetNode(pKeep, 0))->datum.i;
|
||||
int32_t daysToKeep1 = ((SValueNode*)nodesListGetNode(pKeep, 1))->datum.i;
|
||||
int32_t daysToKeep2 = ((SValueNode*)nodesListGetNode(pKeep, 2))->datum.i;
|
||||
SValueNode* pKeep0 = (SValueNode*)nodesListGetNode(pKeep, 0);
|
||||
SValueNode* pKeep1 = (SValueNode*)nodesListGetNode(pKeep, 1);
|
||||
SValueNode* pKeep2 = (SValueNode*)nodesListGetNode(pKeep, 2);
|
||||
if ((pKeep0->isDuration && (TIME_UNIT_MINUTE != pKeep0->unit && TIME_UNIT_HOUR != pKeep0->unit && TIME_UNIT_DAY != pKeep0->unit)) ||
|
||||
(pKeep1->isDuration && (TIME_UNIT_MINUTE != pKeep1->unit && TIME_UNIT_HOUR != pKeep1->unit && TIME_UNIT_DAY != pKeep1->unit)) ||
|
||||
(pKeep2->isDuration && (TIME_UNIT_MINUTE != pKeep2->unit && TIME_UNIT_HOUR != pKeep2->unit && TIME_UNIT_DAY != pKeep2->unit))) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_UNIT, pKeep0->unit, pKeep1->unit, pKeep2->unit);
|
||||
}
|
||||
|
||||
int32_t daysToKeep0 = getBigintFromValueNode(pKeep0);
|
||||
int32_t daysToKeep1 = getBigintFromValueNode(pKeep1);
|
||||
int32_t daysToKeep2 = getBigintFromValueNode(pKeep2);
|
||||
if (daysToKeep0 < TSDB_MIN_KEEP || daysToKeep1 < TSDB_MIN_KEEP || daysToKeep2 < TSDB_MIN_KEEP ||
|
||||
daysToKeep0 > TSDB_MAX_KEEP || daysToKeep1 > TSDB_MAX_KEEP || daysToKeep2 > TSDB_MAX_KEEP) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_KEEP_VALUE, daysToKeep0, daysToKeep1, daysToKeep2,
|
||||
|
@ -1240,8 +1277,7 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, SDatabaseOptions* p
|
|||
code = checkRangeOption(pCxt, "compression", pOptions->pCompressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code =
|
||||
checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
|
||||
code = checkRangeOption(pCxt, "daysPerFile", pOptions->pDaysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkRangeOption(pCxt, "fsyncPeriod", pOptions->pFsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
|
||||
|
|
|
@ -62,35 +62,39 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
case TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL:
|
||||
return "This interval value is too small : %s";
|
||||
case TSDB_CODE_PAR_DB_NOT_SPECIFIED:
|
||||
return "db not specified";
|
||||
return "Database not specified";
|
||||
case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME:
|
||||
return "Invalid identifier name : %s";
|
||||
case TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR:
|
||||
return "corresponding super table not in this db";
|
||||
return "Corresponding super table not in this db";
|
||||
case TSDB_CODE_PAR_INVALID_RANGE_OPTION:
|
||||
return "invalid option %s: %"PRId64" valid range: [%d, %d]";
|
||||
return "Invalid option %s: %"PRId64" valid range: [%d, %d]";
|
||||
case TSDB_CODE_PAR_INVALID_STR_OPTION:
|
||||
return "invalid option %s: %s";
|
||||
return "Invalid option %s: %s";
|
||||
case TSDB_CODE_PAR_INVALID_ENUM_OPTION:
|
||||
return "invalid option %s: %"PRId64", only %d, %d allowed";
|
||||
return "Invalid option %s: %"PRId64", only %d, %d allowed";
|
||||
case TSDB_CODE_PAR_INVALID_TTL_OPTION:
|
||||
return "invalid option ttl: %"PRId64", should be greater than or equal to %d";
|
||||
return "Invalid option ttl: %"PRId64", should be greater than or equal to %d";
|
||||
case TSDB_CODE_PAR_INVALID_KEEP_NUM:
|
||||
return "invalid number of keep options";
|
||||
return "Invalid number of keep options";
|
||||
case TSDB_CODE_PAR_INVALID_KEEP_ORDER:
|
||||
return "invalid keep value, should be keep0 <= keep1 <= keep2";
|
||||
return "Invalid keep value, should be keep0 <= keep1 <= keep2";
|
||||
case TSDB_CODE_PAR_INVALID_KEEP_VALUE:
|
||||
return "invalid option keep: %d, %d, %d valid range: [%d, %d]";
|
||||
return "Invalid option keep: %d, %d, %d valid range: [%d, %d]";
|
||||
case TSDB_CODE_PAR_INVALID_COMMENT_OPTION:
|
||||
return "invalid option comment, length cannot exceed %d";
|
||||
return "Invalid option comment, length cannot exceed %d";
|
||||
case TSDB_CODE_PAR_INVALID_F_RANGE_OPTION:
|
||||
return "invalid option %s: %f valid range: [%d, %d]";
|
||||
return "Invalid option %s: %f valid range: [%d, %d]";
|
||||
case TSDB_CODE_PAR_INVALID_ROLLUP_OPTION:
|
||||
return "invalid option rollup: only one function is allowed";
|
||||
return "Invalid option rollup: only one function is allowed";
|
||||
case TSDB_CODE_PAR_INVALID_RETENTIONS_OPTION:
|
||||
return "invalid option retentions";
|
||||
return "Invalid option retentions";
|
||||
case TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST:
|
||||
return "GROUP BY and WINDOW-clause can't be used together";
|
||||
case TSDB_CODE_PAR_INVALID_OPTION_UNIT:
|
||||
return "Invalid option %s unit: %c, only m, h, d allowed";
|
||||
case TSDB_CODE_PAR_INVALID_KEEP_UNIT:
|
||||
return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
|
|
@ -226,6 +226,16 @@ TEST_F(ParserTest, selectExpression) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, selectCondition) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("SELECT c1 FROM t1 where ts in (true, false)");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT * FROM t1 where c1 > 10 and c1 is not null");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, selectPseudoColumn) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
|
|
|
@ -200,6 +200,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
|
||||
pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
|
||||
pScan->ratio = pRealTable->ratio;
|
||||
pScan->dataRequired = FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
|
||||
// set columns to scan
|
||||
SNodeList* pCols = NULL;
|
||||
|
@ -488,6 +489,12 @@ static int32_t createWindowLogicNodeByState(SLogicPlanContext* pCxt, SStateWindo
|
|||
pWindow->winType = WINDOW_TYPE_STATE;
|
||||
pWindow->pStateExpr = nodesCloneNode(pState->pExpr);
|
||||
|
||||
pWindow->pTspk = nodesCloneNode(pState->pCol);
|
||||
if (NULL == pWindow->pTspk) {
|
||||
nodesDestroyNode(pWindow);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||
}
|
||||
|
||||
|
@ -500,6 +507,12 @@ static int32_t createWindowLogicNodeBySession(SLogicPlanContext* pCxt, SSessionW
|
|||
pWindow->winType = WINDOW_TYPE_SESSION;
|
||||
pWindow->sessionGap = ((SValueNode*)pSession->pGap)->datum.i;
|
||||
|
||||
pWindow->pTspk = nodesCloneNode(pSession->pCol);
|
||||
if (NULL == pWindow->pTspk) {
|
||||
nodesDestroyNode(pWindow);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return createWindowLogicNodeFinalize(pCxt, pSelect, pWindow, pLogicNode);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,159 @@
|
|||
*/
|
||||
|
||||
#include "planInt.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
||||
#define OPTIMIZE_FLAG_MASK(n) (1 << n)
|
||||
|
||||
#define OPTIMIZE_FLAG_OSD OPTIMIZE_FLAG_MASK(0)
|
||||
|
||||
#define OPTIMIZE_FLAG_SET_MASK(val, mask) (val) |= (mask)
|
||||
#define OPTIMIZE_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
typedef struct SOptimizeContext {
|
||||
bool optimized;
|
||||
} SOptimizeContext;
|
||||
|
||||
typedef int32_t (*FMatch)(SOptimizeContext* pCxt, SLogicNode* pLogicNode);
|
||||
typedef int32_t (*FOptimize)(SOptimizeContext* pCxt, SLogicNode* pLogicNode);
|
||||
|
||||
typedef struct SOptimizeRule {
|
||||
char* pName;
|
||||
FOptimize optimizeFunc;
|
||||
} SOptimizeRule;
|
||||
|
||||
typedef struct SOsdInfo {
|
||||
SScanLogicNode* pScan;
|
||||
SNodeList* pSdrFuncs;
|
||||
SNodeList* pDsoFuncs;
|
||||
} SOsdInfo;
|
||||
|
||||
static bool osdMayBeOptimized(SLogicNode* pNode) {
|
||||
if (OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_OSD)) {
|
||||
return false;
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN != nodeType(pNode)) {
|
||||
return false;
|
||||
}
|
||||
if (NULL == pNode->pParent ||
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static SLogicNode* osdFindPossibleScanNode(SLogicNode* pNode) {
|
||||
if (osdMayBeOptimized(pNode)) {
|
||||
return pNode;
|
||||
}
|
||||
SNode* pChild;
|
||||
FOREACH(pChild, pNode->pChildren) {
|
||||
SLogicNode* pScanNode = osdFindPossibleScanNode((SLogicNode*)pChild);
|
||||
if (NULL != pScanNode) {
|
||||
return pScanNode;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SNodeList* osdGetAllFuncs(SLogicNode* pNode) {
|
||||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return ((SWindowLogicNode*)pNode)->pFuncs;
|
||||
case QUERY_NODE_LOGIC_PLAN_AGG:
|
||||
return ((SAggLogicNode*)pNode)->pAggFuncs;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t osdGetRelatedFuncs(SScanLogicNode* pScan, SNodeList** pSdrFuncs, SNodeList** pDsoFuncs) {
|
||||
SNodeList* pAllFuncs = osdGetAllFuncs(pScan->node.pParent);
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pAllFuncs) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (fmIsSpecialDataRequiredFunc(((SFunctionNode*)pFunc)->funcId)) {
|
||||
code = nodesListMakeStrictAppend(pSdrFuncs, nodesCloneNode(pFunc));
|
||||
} else if (fmIsDynamicScanOptimizedFunc(((SFunctionNode*)pFunc)->funcId)) {
|
||||
code = nodesListMakeStrictAppend(pDsoFuncs, nodesCloneNode(pFunc));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(*pSdrFuncs);
|
||||
nodesDestroyList(*pDsoFuncs);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo* pInfo) {
|
||||
pInfo->pScan = (SScanLogicNode*)osdFindPossibleScanNode(pLogicNode);
|
||||
if (NULL == pInfo->pScan) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
return osdGetRelatedFuncs(pInfo->pScan, &pInfo->pSdrFuncs, &pInfo->pDsoFuncs);
|
||||
}
|
||||
|
||||
static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) {
|
||||
switch (l) {
|
||||
case FUNC_DATA_REQUIRED_ALL_NEEDED:
|
||||
return l;
|
||||
case FUNC_DATA_REQUIRED_STATIS_NEEDED:
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED == r ? r : l;
|
||||
case FUNC_DATA_REQUIRED_NO_NEEDED:
|
||||
return FUNC_DATA_REQUIRED_DISCARD == r ? l : r;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static int32_t osdGetDataRequired(SNodeList* pFuncs) {
|
||||
if (NULL == pFuncs) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
}
|
||||
EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_DISCARD;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pFuncs) {
|
||||
dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL));
|
||||
}
|
||||
return dataRequired;
|
||||
}
|
||||
|
||||
static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) {
|
||||
SOsdInfo info = {0};
|
||||
int32_t code = osdMatch(pCxt, pLogicNode, &info);
|
||||
if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) {
|
||||
info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs);
|
||||
info.pScan->pDynamicScanFuncs = info.pDsoFuncs;
|
||||
OPTIMIZE_FLAG_SET_MASK(info.pScan->node.optimizedFlag, OPTIMIZE_FLAG_OSD);
|
||||
pCxt->optimized = true;
|
||||
}
|
||||
nodesDestroyList(info.pSdrFuncs);
|
||||
return code;
|
||||
}
|
||||
|
||||
static const SOptimizeRule optimizeRuleSet[] = {
|
||||
{ .pName = "OptimizeScanData", .optimizeFunc = osdOptimize }
|
||||
};
|
||||
|
||||
static const int32_t optimizeRuleNum = (sizeof(optimizeRuleSet) / sizeof(SOptimizeRule));
|
||||
|
||||
static int32_t applyOptimizeRule(SLogicNode* pLogicNode) {
|
||||
SOptimizeContext cxt = { .optimized = false };
|
||||
do {
|
||||
cxt.optimized = false;
|
||||
for (int32_t i = 0; i < optimizeRuleNum; ++i) {
|
||||
int32_t code = optimizeRuleSet[i].optimizeFunc(&cxt, pLogicNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
} while (cxt.optimized);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t optimizeLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode) {
|
||||
return applyOptimizeRule(pLogicNode);
|
||||
}
|
||||
|
|
|
@ -316,7 +316,18 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) {
|
||||
static uint8_t getPrecision(SNodeList* pChildren) {
|
||||
if (1 == LIST_LENGTH(pChildren)) {
|
||||
return (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision;
|
||||
} else if (2 == LIST_LENGTH(pChildren)) {
|
||||
uint8_t lp = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc)->precision;
|
||||
uint8_t rp = (((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc)->precision;
|
||||
return (lp > rp ? rp : lp);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, uint8_t precision, SLogicNode* pLogicNode, ENodeType type) {
|
||||
SPhysiNode* pPhysiNode = (SPhysiNode*)nodesMakeNode(type);
|
||||
if (NULL == pPhysiNode) {
|
||||
return NULL;
|
||||
|
@ -327,6 +338,7 @@ static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
nodesDestroyNode(pPhysiNode);
|
||||
return NULL;
|
||||
}
|
||||
pPhysiNode->pOutputDataBlockDesc->precision = precision;
|
||||
return pPhysiNode;
|
||||
}
|
||||
|
||||
|
@ -405,7 +417,7 @@ static void vgroupInfoToNodeAddr(const SVgroupInfo* vg, SQueryNodeAddr* pNodeAdd
|
|||
}
|
||||
|
||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
STagScanPhysiNode* pTagScan = (STagScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
if (NULL == pTagScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -413,7 +425,7 @@ static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SScanLogicNode* p
|
|||
}
|
||||
|
||||
static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
STableScanPhysiNode* pTableScan = (STableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN);
|
||||
if (NULL == pTableScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -425,12 +437,18 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
taosArrayPush(pCxt->pExecNodeList, &pSubplan->execNode);
|
||||
pSubplan->execNodeStat.tableNum = pScanLogicNode->pVgroupList->vgroups[0].numOfTable;
|
||||
tNameGetFullDbName(&pScanLogicNode->tableName, pSubplan->dbFName);
|
||||
pTableScan->dataRequired = pScanLogicNode->dataRequired;
|
||||
pTableScan->pDynamicScanFuncs = nodesCloneList(pScanLogicNode->pDynamicScanFuncs);
|
||||
if (NULL != pScanLogicNode->pDynamicScanFuncs && NULL == pTableScan->pDynamicScanFuncs) {
|
||||
nodesDestroyNode(pTableScan);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
SSystemTableScanPhysiNode* pScan = (SSystemTableScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -451,7 +469,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan*
|
|||
}
|
||||
|
||||
static int32_t createStreamScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pScanLogicNode->pMeta->tableInfo.precision, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -515,7 +533,7 @@ static int32_t createJoinOutputCols(SPhysiPlanContext* pCxt, SDataBlockDescNode*
|
|||
}
|
||||
|
||||
static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode, SPhysiNode** pPhyNode) {
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
SJoinPhysiNode* pJoin = (SJoinPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -656,7 +674,7 @@ static int32_t rewritePrecalcExpr(SPhysiPlanContext* pCxt, SNode* pNode, SNodeLi
|
|||
}
|
||||
|
||||
static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SAggLogicNode* pAggLogicNode, SPhysiNode** pPhyNode) {
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
SAggPhysiNode* pAgg = (SAggPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pAggLogicNode, QUERY_NODE_PHYSICAL_PLAN_AGG);
|
||||
if (NULL == pAgg) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -710,7 +728,7 @@ static int32_t createAggPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
|||
}
|
||||
|
||||
static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SProjectLogicNode* pProjectLogicNode, SPhysiNode** pPhyNode) {
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
SProjectPhysiNode* pProject = (SProjectPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pProjectLogicNode, QUERY_NODE_PHYSICAL_PLAN_PROJECT);
|
||||
if (NULL == pProject) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -738,7 +756,7 @@ static int32_t createProjectPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChild
|
|||
}
|
||||
|
||||
static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -749,7 +767,7 @@ static int32_t doCreateExchangePhysiNode(SPhysiPlanContext* pCxt, SExchangeLogic
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t createStreamScanPhysiNodeByExchange(SPhysiPlanContext* pCxt, SExchangeLogicNode* pExchangeLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
SStreamScanPhysiNode* pScan = (SStreamScanPhysiNode*)makePhysiNode(pCxt, pExchangeLogicNode->precision, (SLogicNode*)pExchangeLogicNode, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN);
|
||||
if (NULL == pScan) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -803,6 +821,10 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pWindow->pTspk);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pFuncs) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFuncs, &pWindow->pFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -820,7 +842,7 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
|
||||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
if (NULL == pInterval) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -838,18 +860,11 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SDataBlockDescNode* pChildTupe = (((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc);
|
||||
int32_t code = setNodeSlotId(pCxt, pChildTupe->dataBlockId, -1, pWindowLogicNode->pTspk, &pInterval->pTspk);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(pInterval);
|
||||
return code;
|
||||
}
|
||||
|
||||
return createWindowPhysiNodeFinalize(pCxt, pChildren, &pInterval->window, pWindowLogicNode, pPhyNode);
|
||||
}
|
||||
|
||||
static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
SSessionWinodwPhysiNode* pSession = (SSessionWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW);
|
||||
if (NULL == pSession) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -860,7 +875,7 @@ static int32_t createSessionWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
|
||||
static int32_t createStateWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
||||
SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW);
|
||||
if (NULL == pState) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -908,7 +923,7 @@ static int32_t createWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildr
|
|||
}
|
||||
|
||||
static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SSortLogicNode* pSortLogicNode, SPhysiNode** pPhyNode) {
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
SSortPhysiNode* pSort = (SSortPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pSortLogicNode, QUERY_NODE_PHYSICAL_PLAN_SORT);
|
||||
if (NULL == pSort) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -947,7 +962,7 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
}
|
||||
|
||||
static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SPartitionLogicNode* pPartLogicNode, SPhysiNode** pPhyNode) {
|
||||
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
||||
SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)makePhysiNode(pCxt, getPrecision(pChildren), (SLogicNode*)pPartLogicNode, QUERY_NODE_PHYSICAL_PLAN_PARTITION);
|
||||
if (NULL == pPart) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -1229,6 +1244,7 @@ static void setExplainInfo(SPlanContext* pCxt, SQueryPlan* pPlan) {
|
|||
SExplainStmt* pStmt = (SExplainStmt*)pCxt->pAstRoot;
|
||||
pPlan->explainInfo.mode = pStmt->analyze ? EXPLAIN_MODE_ANALYZE : EXPLAIN_MODE_STATIC;
|
||||
pPlan->explainInfo.verbose = pStmt->pOptions->verbose;
|
||||
pPlan->explainInfo.ratio = pStmt->pOptions->ratio;
|
||||
} else {
|
||||
pPlan->explainInfo.mode = EXPLAIN_MODE_DISABLE;
|
||||
}
|
||||
|
|
|
@ -23,18 +23,14 @@
|
|||
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
typedef struct SSplitContext {
|
||||
int32_t errCode;
|
||||
int32_t groupId;
|
||||
bool match;
|
||||
void* pInfo;
|
||||
bool split;
|
||||
} SSplitContext;
|
||||
|
||||
typedef int32_t (*FMatch)(SSplitContext* pCxt, SLogicSubplan* pSubplan);
|
||||
typedef int32_t (*FSplit)(SSplitContext* pCxt);
|
||||
typedef int32_t (*FSplit)(SSplitContext* pCxt, SLogicSubplan* pSubplan);
|
||||
|
||||
typedef struct SSplitRule {
|
||||
char* pName;
|
||||
FMatch matchFunc;
|
||||
FSplit splitFunc;
|
||||
} SSplitRule;
|
||||
|
||||
|
@ -58,30 +54,25 @@ static SLogicNode* stsMatchByNode(SLogicNode* pNode) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int32_t stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||
if (SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static void stsFindSplitNode(SLogicSubplan* pSubplan, SStsInfo* pInfo) {
|
||||
SLogicNode* pSplitNode = stsMatchByNode(pSubplan->pNode);
|
||||
if (NULL != pSplitNode) {
|
||||
SStsInfo* pInfo = taosMemoryCalloc(1, sizeof(SStsInfo));
|
||||
if (NULL == pInfo) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pInfo->pScan = (SScanLogicNode*)pSplitNode;
|
||||
pInfo->pSubplan = pSubplan;
|
||||
pCxt->pInfo = pInfo;
|
||||
pCxt->match = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
static void stsMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, SStsInfo* pInfo) {
|
||||
if (!SPLIT_FLAG_TEST_MASK(pSubplan->splitFlag, SPLIT_FLAG_STS)) {
|
||||
stsFindSplitNode(pSubplan, pInfo);
|
||||
}
|
||||
SNode* pChild;
|
||||
FOREACH(pChild, pSubplan->pChildren) {
|
||||
int32_t code = stsMatch(pCxt, (SLogicSubplan*)pChild);
|
||||
if (TSDB_CODE_SUCCESS != code || pCxt->match) {
|
||||
return code;
|
||||
stsMatch(pCxt, (SLogicSubplan*)pChild, pInfo);
|
||||
if (NULL != pInfo->pScan) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
return;
|
||||
}
|
||||
|
||||
static SLogicSubplan* stsCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan) {
|
||||
|
@ -103,6 +94,7 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pExchange->srcGroupId = pCxt->groupId;
|
||||
pExchange->precision = pScan->pMeta->tableInfo.precision;
|
||||
pExchange->node.pTargets = nodesCloneList(pScan->node.pTargets);
|
||||
if (NULL == pExchange->node.pTargets) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -127,46 +119,44 @@ static int32_t stsCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t stsSplit(SSplitContext* pCxt) {
|
||||
SStsInfo* pInfo = pCxt->pInfo;
|
||||
if (NULL == pInfo->pSubplan->pChildren) {
|
||||
pInfo->pSubplan->pChildren = nodesMakeList();
|
||||
if (NULL == pInfo->pSubplan->pChildren) {
|
||||
static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||
SStsInfo info = {0};
|
||||
stsMatch(pCxt, pSubplan, &info);
|
||||
if (NULL == info.pScan) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (NULL == info.pSubplan->pChildren) {
|
||||
info.pSubplan->pChildren = nodesMakeList();
|
||||
if (NULL == info.pSubplan->pChildren) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
int32_t code = nodesListStrictAppend(pInfo->pSubplan->pChildren, stsCreateScanSubplan(pCxt, pInfo->pScan));
|
||||
int32_t code = nodesListStrictAppend(info.pSubplan->pChildren, stsCreateScanSubplan(pCxt, info.pScan));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = stsCreateExchangeNode(pCxt, pInfo->pSubplan, pInfo->pScan);
|
||||
code = stsCreateExchangeNode(pCxt, info.pSubplan, info.pScan);
|
||||
}
|
||||
++(pCxt->groupId);
|
||||
taosMemoryFreeClear(pCxt->pInfo);
|
||||
pCxt->split = true;
|
||||
return code;
|
||||
}
|
||||
|
||||
static const SSplitRule splitRuleSet[] = {
|
||||
{ .pName = "SuperTableScan", .matchFunc = stsMatch, .splitFunc = stsSplit }
|
||||
{ .pName = "SuperTableScan", .splitFunc = stsSplit }
|
||||
};
|
||||
|
||||
static const int32_t splitRuleNum = (sizeof(splitRuleSet) / sizeof(SSplitRule));
|
||||
|
||||
static int32_t applySplitRule(SLogicSubplan* pSubplan) {
|
||||
SSplitContext cxt = { .errCode = TSDB_CODE_SUCCESS, .groupId = pSubplan->id.groupId + 1, .match = false, .pInfo = NULL };
|
||||
bool split = false;
|
||||
SSplitContext cxt = { .groupId = pSubplan->id.groupId + 1, .split = false };
|
||||
do {
|
||||
split = false;
|
||||
cxt.split = false;
|
||||
for (int32_t i = 0; i < splitRuleNum; ++i) {
|
||||
cxt.match = false;
|
||||
int32_t code = splitRuleSet[i].matchFunc(&cxt, pSubplan);
|
||||
if (TSDB_CODE_SUCCESS == code && cxt.match) {
|
||||
code = splitRuleSet[i].splitFunc(&cxt);
|
||||
split = true;
|
||||
}
|
||||
int32_t code = splitRuleSet[i].splitFunc(&cxt, pSubplan);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
} while (split);
|
||||
} while (cxt.split);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -177,14 +177,14 @@ TEST_F(PlannerTest, groupBy) {
|
|||
bind("SELECT count(*) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
ASSERT_TRUE(run());
|
||||
// bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
// ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
ASSERT_TRUE(run());
|
||||
// bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
// ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
ASSERT_TRUE(run());
|
||||
// bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
// ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, subquery) {
|
||||
|
|
|
@ -1748,7 +1748,6 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
|
|||
SFilterField* fi = right;
|
||||
|
||||
SValueNode* var = (SValueNode *)fi->desc;
|
||||
|
||||
if (var == NULL) {
|
||||
assert(fi->data != NULL);
|
||||
continue;
|
||||
|
@ -1767,13 +1766,18 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
|
|||
}
|
||||
|
||||
SDataType *dType = &var->node.resType;
|
||||
size_t bytes = 0;
|
||||
|
||||
if (type == TSDB_DATA_TYPE_BINARY) {
|
||||
size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE;
|
||||
fi->data = taosMemoryCalloc(1, len + 1 + VARSTR_HEADER_SIZE);
|
||||
bytes = len + 1 + VARSTR_HEADER_SIZE;
|
||||
|
||||
fi->data = taosMemoryCalloc(1, bytes);
|
||||
} else if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
size_t len = (dType->type == TSDB_DATA_TYPE_BINARY || dType->type == TSDB_DATA_TYPE_NCHAR) ? dType->bytes : MAX_NUM_STR_SIZE;
|
||||
fi->data = taosMemoryCalloc(1, (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
||||
bytes = (len + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE;
|
||||
|
||||
fi->data = taosMemoryCalloc(1, bytes);
|
||||
} else if (type != TSDB_DATA_TYPE_JSON){
|
||||
if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { //TIME RANGE
|
||||
/*
|
||||
|
@ -1797,8 +1801,11 @@ int32_t fltInitValFieldData(SFilterInfo *info) {
|
|||
} else {
|
||||
SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))};
|
||||
out.columnData->info.type = type;
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
out.columnData->info.bytes = bytes;
|
||||
} else {
|
||||
out.columnData->info.bytes = tDataTypes[type].bytes;
|
||||
ASSERT(!IS_VAR_DATA_TYPE(type));
|
||||
}
|
||||
|
||||
// todo refactor the convert
|
||||
int32_t code = doConvertDataType(var, &out);
|
||||
|
@ -2985,13 +2992,13 @@ bool filterExecuteImplMisc(void *pinfo, int32_t numOfRows, int8_t** p, SColumnDa
|
|||
for (int32_t i = 0; i < numOfRows; ++i) {
|
||||
uint32_t uidx = info->groups[0].unitIdxs[0];
|
||||
void *colData = colDataGetData((SColumnInfoData *)info->cunits[uidx].colData, i);
|
||||
if (colData == NULL || colDataIsNull((SColumnInfoData *)info->cunits[uidx].colData, 0, i, NULL)) {
|
||||
if (colData == NULL || colDataIsNull_s((SColumnInfoData *)info->cunits[uidx].colData, i)) {
|
||||
(*p)[i] = 0;
|
||||
all = false;
|
||||
continue;
|
||||
}
|
||||
// match/nmatch for nchar type need convert from ucs4 to mbs
|
||||
|
||||
// match/nmatch for nchar type need convert from ucs4 to mbs
|
||||
if(info->cunits[uidx].dataType == TSDB_DATA_TYPE_NCHAR && (info->cunits[uidx].optr == OP_TYPE_MATCH || info->cunits[uidx].optr == OP_TYPE_NMATCH)){
|
||||
char *newColData = taosMemoryCalloc(info->cunits[uidx].dataSize * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE, 1);
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4*)varDataVal(colData), varDataLen(colData), varDataVal(newColData));
|
||||
|
@ -3222,19 +3229,13 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) {
|
|||
info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags));
|
||||
|
||||
filterDumpInfoToString(info, "Final", 0);
|
||||
|
||||
return code;
|
||||
|
||||
_return:
|
||||
|
||||
qInfo("init from node failed, code:%d", code);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32_t numOfCols, int32_t numOfRows) {
|
||||
if (FILTER_EMPTY_RES(info)) {
|
||||
return false;
|
||||
|
|
|
@ -46,7 +46,6 @@ int32_t doConvertDataType(SValueNode* pValueNode, SScalarParam* out) {
|
|||
colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false);
|
||||
|
||||
colInfoDataEnsureCapacity(out->columnData, 1);
|
||||
|
||||
int32_t code = vectorConvertImpl(&in, out);
|
||||
sclFreeParam(&in);
|
||||
|
||||
|
|
|
@ -647,6 +647,159 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum!= 3) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int16_t inputType = pInput[0].columnData->info.type;
|
||||
int16_t outputType = *(int16_t *)pInput[1].columnData->pData;
|
||||
if (outputType != TSDB_DATA_TYPE_BIGINT && outputType != TSDB_DATA_TYPE_UBIGINT &&
|
||||
outputType != TSDB_DATA_TYPE_VARCHAR && outputType != TSDB_DATA_TYPE_NCHAR &&
|
||||
outputType != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int64_t outputLen = *(int64_t *)pInput[2].columnData->pData;
|
||||
|
||||
char *input = NULL;
|
||||
char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1);
|
||||
char *output = outputBuf;
|
||||
if (IS_VAR_DATA_TYPE(inputType)) {
|
||||
input = pInput[0].columnData->pData + pInput[0].columnData->varmeta.offset[0];
|
||||
} else {
|
||||
input = pInput[0].columnData->pData;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
||||
if (colDataIsNull_s(pInput[0].columnData, i)) {
|
||||
colDataAppendNULL(pOutput->columnData, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
switch(outputType) {
|
||||
case TSDB_DATA_TYPE_BIGINT: {
|
||||
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy(output, varDataVal(input), varDataLen(input));
|
||||
*(int64_t *)output = strtoll(output, NULL, 10);
|
||||
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1);
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||
if (len < 0) {
|
||||
taosMemoryFree(newBuf);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
newBuf[len] = 0;
|
||||
*(int64_t *)output = strtoll(newBuf, NULL, 10);
|
||||
taosMemoryFree(newBuf);
|
||||
} else {
|
||||
GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||
memcpy(output, varDataVal(input), varDataLen(input));
|
||||
*(uint64_t *)output = strtoull(output, NULL, 10);
|
||||
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
char *newBuf = taosMemoryCalloc(1, outputLen * TSDB_NCHAR_SIZE + 1);
|
||||
int32_t len = taosUcs4ToMbs((TdUcs4 *)varDataVal(input), varDataLen(input), newBuf);
|
||||
if (len < 0) {
|
||||
taosMemoryFree(newBuf);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
newBuf[len] = 0;
|
||||
*(uint64_t *)output = strtoull(newBuf, NULL, 10);
|
||||
taosMemoryFree(newBuf);
|
||||
} else {
|
||||
GET_TYPED_DATA(*(uint64_t *)output, uint64_t, inputType, input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_TIMESTAMP: {
|
||||
if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
//not support
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
GET_TYPED_DATA(*(int64_t *)output, int64_t, inputType, input);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_BINARY: {
|
||||
if (inputType == TSDB_DATA_TYPE_BOOL) {
|
||||
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), *(int8_t *)input ? "true" : "false");
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||
int32_t len = sprintf(varDataVal(output), "%.*s", (int32_t)(outputLen - VARSTR_HEADER_SIZE), varDataVal(input));
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_BINARY || inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
//not support
|
||||
return TSDB_CODE_FAILED;
|
||||
} else {
|
||||
char tmp[400] = {0};
|
||||
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
|
||||
int32_t len = (int32_t)strlen(tmp);
|
||||
len = (outputLen - VARSTR_HEADER_SIZE) > len ? len : (outputLen - VARSTR_HEADER_SIZE);
|
||||
memcpy(varDataVal(output), tmp, len);
|
||||
varDataSetLen(output, len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
int32_t outputCharLen = (outputLen - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||
if (inputType == TSDB_DATA_TYPE_BOOL) {
|
||||
char tmp[8] = {0};
|
||||
int32_t len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" );
|
||||
bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||
int32_t len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen;
|
||||
bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t len = MIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE);
|
||||
memcpy(output, input, len);
|
||||
varDataSetLen(output, len - VARSTR_HEADER_SIZE);
|
||||
} else {
|
||||
char tmp[400] = {0};
|
||||
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
|
||||
int32_t len = (int32_t)strlen(tmp);
|
||||
len = outputCharLen > len ? len : outputCharLen;
|
||||
bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
varDataSetLen(output, len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
}
|
||||
|
||||
colDataAppend(pOutput->columnData, i, output, false);
|
||||
if (IS_VAR_DATA_TYPE(inputType)) {
|
||||
input += varDataTLen(input);
|
||||
} else {
|
||||
input += tDataTypes[inputType].bytes;
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(outputType)) {
|
||||
output += varDataTLen(output);
|
||||
} else {
|
||||
output += tDataTypes[outputType].bytes;
|
||||
}
|
||||
}
|
||||
|
||||
pOutput->numOfRows = pInput->numOfRows;
|
||||
taosMemoryFree(outputBuf);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
return doScalarFunctionUnique(pInput, inputNum, pOutput, atan);
|
||||
|
|
|
@ -177,9 +177,24 @@ static FORCE_INLINE void varToBool(char *buf, SScalarParam* pOut, int32_t rowInd
|
|||
colDataAppendInt8(pOut->columnData, rowIndex, (int8_t*) &v);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void varToNchar(char* buf, SScalarParam* pOut, int32_t rowIndex) {
|
||||
int32_t len = 0;
|
||||
int32_t inputLen = varDataLen(buf);
|
||||
|
||||
char* t = taosMemoryCalloc(1,(inputLen + 1) * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE);
|
||||
/*int32_t resLen = */taosMbsToUcs4(varDataVal(buf), inputLen, (TdUcs4*) varDataVal(t), pOut->columnData->info.bytes, &len);
|
||||
varDataSetLen(t, len);
|
||||
|
||||
colDataAppend(pOut->columnData, rowIndex, t, false);
|
||||
taosMemoryFree(t);
|
||||
}
|
||||
|
||||
//TODO opt performance, tmp is not needed.
|
||||
int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, int32_t inType, int32_t outType) {
|
||||
int32_t bufSize = pIn->columnData->info.bytes;
|
||||
char *tmp = taosMemoryMalloc(bufSize);
|
||||
char *tmp = taosMemoryMalloc(bufSize + VARSTR_HEADER_SIZE);
|
||||
|
||||
bool vton = false;
|
||||
|
||||
_bufConverteFunc func = NULL;
|
||||
if (TSDB_DATA_TYPE_BOOL == outType) {
|
||||
|
@ -190,6 +205,9 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
|
|||
func = varToUnsigned;
|
||||
} else if (IS_FLOAT_TYPE(outType)) {
|
||||
func = varToFloat;
|
||||
} else if (outType == TSDB_DATA_TYPE_NCHAR) {
|
||||
func = varToNchar;
|
||||
vton = true;
|
||||
} else {
|
||||
sclError("invalid convert outType:%d", outType);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
|
@ -197,20 +215,23 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
|
|||
|
||||
pOut->numOfRows = pIn->numOfRows;
|
||||
for (int32_t i = 0; i < pIn->numOfRows; ++i) {
|
||||
if (colDataIsNull(pIn->columnData, pIn->numOfRows, i, NULL)) {
|
||||
if (colDataIsNull_s(pIn->columnData, i)) {
|
||||
colDataAppendNULL(pOut->columnData, i);
|
||||
continue;
|
||||
}
|
||||
|
||||
char* data = colDataGetData(pIn->columnData, i);
|
||||
if (TSDB_DATA_TYPE_BINARY == inType) {
|
||||
if (vton) {
|
||||
memcpy(tmp, data, varDataTLen(data));
|
||||
} else {
|
||||
if (TSDB_DATA_TYPE_VARCHAR == inType) {
|
||||
memcpy(tmp, varDataVal(data), varDataLen(data));
|
||||
tmp[varDataLen(data)] = 0;
|
||||
} else {
|
||||
ASSERT (varDataLen(data) <= bufSize);
|
||||
ASSERT(varDataLen(data) <= bufSize);
|
||||
|
||||
int len = taosUcs4ToMbs((TdUcs4*)varDataVal(data), varDataLen(data), tmp);
|
||||
if (len < 0){
|
||||
int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(data), varDataLen(data), tmp);
|
||||
if (len < 0) {
|
||||
sclError("castConvert taosUcs4ToMbs error 1");
|
||||
taosMemoryFreeClear(tmp);
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
|
@ -218,6 +239,7 @@ int32_t vectorConvertFromVarData(const SScalarParam* pIn, SScalarParam* pOut, in
|
|||
|
||||
tmp[len] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
(*func)(tmp, pOut, i);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ SRaftStore *raftStoreOpen(const char *path) {
|
|||
static int32_t raftStoreInit(SRaftStore *pRaftStore) {
|
||||
assert(pRaftStore != NULL);
|
||||
|
||||
pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||
pRaftStore->pFile = taosOpenFile(pRaftStore->path, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
assert(pRaftStore->pFile != NULL);
|
||||
|
||||
pRaftStore->currentTerm = 0;
|
||||
|
|
|
@ -37,7 +37,7 @@ extern "C" {
|
|||
/* file */
|
||||
typedef TdFilePtr tdb_fd_t;
|
||||
|
||||
#define TDB_O_CREAT TD_FILE_CTEATE
|
||||
#define TDB_O_CREAT TD_FILE_CREATE
|
||||
#define TDB_O_WRITE TD_FILE_WRITE
|
||||
#define TDB_O_READ TD_FILE_READ
|
||||
#define TDB_O_TRUNC TD_FILE_TRUNC
|
||||
|
|
|
@ -231,7 +231,7 @@ TEST_F(TfsTest, 04_File) {
|
|||
EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0);
|
||||
|
||||
// FILE *fp = fopen(f1.aname, "w");
|
||||
TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
ASSERT_NE(pFile, nullptr);
|
||||
taosWriteFile(pFile, "12345678", 5);
|
||||
taosCloseFile(&pFile);
|
||||
|
@ -640,7 +640,7 @@ TEST_F(TfsTest, 05_MultiDisk) {
|
|||
EXPECT_EQ(tfsMkdir(pTfs, "t3"), 0);
|
||||
|
||||
// FILE *fp = fopen(f1.aname, "w");
|
||||
TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(f1.aname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
ASSERT_NE(pFile, nullptr);
|
||||
taosWriteFile(pFile, "12345678", 5);
|
||||
taosCloseFile(&pFile);
|
||||
|
|
|
@ -164,8 +164,8 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32
|
|||
wb[1] = uv_buf_init((char*)pCont, contLen);
|
||||
|
||||
connect->data = wb;
|
||||
uv_tcp_connect(connect, &socket_tcp, (const struct sockaddr*)&dest, clientConnCb);
|
||||
terrno = 0;
|
||||
uv_tcp_connect(connect, &socket_tcp, (const struct sockaddr*)&dest, clientConnCb);
|
||||
uv_run(loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(loop);
|
||||
taosMemoryFree(connect);
|
||||
|
|
|
@ -129,6 +129,12 @@ static void transDestroyConnCtx(STransConnCtx* ctx);
|
|||
static SCliThrdObj* createThrdObj();
|
||||
static void destroyThrdObj(SCliThrdObj* pThrd);
|
||||
|
||||
// snprintf may cause performance problem
|
||||
#define CONN_CONSTRUCT_HASH_KEY(key, ip, port) \
|
||||
do { \
|
||||
snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \
|
||||
} while (0)
|
||||
|
||||
#define CONN_HOST_THREAD_INDEX(conn) (conn ? ((SCliConn*)conn)->hThrdIdx : -1)
|
||||
#define CONN_PERSIST_TIME(para) (para * 1000 * 10)
|
||||
#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL)
|
||||
|
@ -206,8 +212,10 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define CONN_NO_PERSIST_BY_APP(conn) (((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
#define CONN_RELEASE_BY_SERVER(conn) (((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
#define CONN_NO_PERSIST_BY_APP(conn) \
|
||||
(((conn)->status == ConnNormal || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
#define CONN_RELEASE_BY_SERVER(conn) \
|
||||
(((conn)->status == ConnRelease || (conn)->status == ConnInPool) && T_REF_VAL_GET(conn) == 1)
|
||||
|
||||
#define REQUEST_NO_RESP(msg) ((msg)->noResp == 1)
|
||||
#define REQUEST_PERSIS_HANDLE(msg) ((msg)->persistHandle == 1)
|
||||
|
@ -282,8 +290,9 @@ void cliHandleResp(SCliConn* conn) {
|
|||
tDebug("%s cli conn %p ref by app", CONN_GET_INST_LABEL(conn), conn);
|
||||
}
|
||||
|
||||
tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn, TMSG_INFO(pHead->msgType),
|
||||
taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port), taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen);
|
||||
tDebug("%s cli conn %p %s received from %s:%d, local info: %s:%d, msg size: %d", pTransInst->label, conn,
|
||||
TMSG_INFO(pHead->msgType), taosInetNtoa(conn->addr.sin_addr), ntohs(conn->addr.sin_port),
|
||||
taosInetNtoa(conn->locaddr.sin_addr), ntohs(conn->locaddr.sin_port), transMsg.contLen);
|
||||
|
||||
conn->secured = pHead->secured;
|
||||
|
||||
|
@ -349,10 +358,12 @@ void cliHandleExcept(SCliConn* pConn) {
|
|||
|
||||
if (pMsg == NULL && !CONN_NO_PERSIST_BY_APP(pConn)) {
|
||||
transMsg.ahandle = transCtxDumpVal(&pConn->ctx, transMsg.msgType);
|
||||
tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle, TMSG_INFO(transMsg.msgType));
|
||||
tDebug("%s cli conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle,
|
||||
TMSG_INFO(transMsg.msgType));
|
||||
if (transMsg.ahandle == NULL) {
|
||||
transMsg.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType));
|
||||
tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn, transMsg.ahandle);
|
||||
tDebug("%s cli conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn,
|
||||
transMsg.ahandle);
|
||||
}
|
||||
} else {
|
||||
transMsg.ahandle = pCtx ? pCtx->ahandle : NULL;
|
||||
|
@ -423,8 +434,7 @@ void* destroyConnPool(void* pool) {
|
|||
|
||||
static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) {
|
||||
char key[128] = {0};
|
||||
tstrncpy(key, ip, strlen(ip));
|
||||
tstrncpy(key + strlen(key), (char*)(&port), sizeof(port));
|
||||
CONN_CONSTRUCT_HASH_KEY(key, ip, port);
|
||||
|
||||
SHashObj* pPool = pool;
|
||||
SConnList* plist = taosHashGet(pPool, key, strlen(key));
|
||||
|
@ -456,8 +466,7 @@ static void addConnToPool(void* pool, SCliConn* conn) {
|
|||
conn->status = ConnInPool;
|
||||
|
||||
char key[128] = {0};
|
||||
tstrncpy(key, conn->ip, strlen(conn->ip));
|
||||
tstrncpy(key + strlen(key), (char*)(&conn->port), sizeof(conn->port));
|
||||
CONN_CONSTRUCT_HASH_KEY(key, conn->ip, conn->port);
|
||||
tTrace("cli conn %p added to conn pool, read buf cap: %d", conn, conn->readBuf.cap);
|
||||
|
||||
SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key));
|
||||
|
@ -626,8 +635,9 @@ void cliSend(SCliConn* pConn) {
|
|||
pHead->release = REQUEST_RELEASE_HANDLE(pCliMsg) ? 1 : 0;
|
||||
|
||||
uv_buf_t wb = uv_buf_init((char*)pHead, msgLen);
|
||||
tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pHead->msgType),
|
||||
taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port), taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port));
|
||||
tDebug("%s cli conn %p %s is send to %s:%d, local info %s:%d", CONN_GET_INST_LABEL(pConn), pConn,
|
||||
TMSG_INFO(pHead->msgType), taosInetNtoa(pConn->addr.sin_addr), ntohs(pConn->addr.sin_port),
|
||||
taosInetNtoa(pConn->locaddr.sin_addr), ntohs(pConn->locaddr.sin_port));
|
||||
|
||||
if (pHead->persist == 1) {
|
||||
CONN_SET_PERSIST_BY_APP(pConn);
|
||||
|
|
|
@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
|
|||
tInfo("RPC server is running, ctrl-c to exit");
|
||||
|
||||
if (commit) {
|
||||
pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||
pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno));
|
||||
}
|
||||
qhandle = taosOpenQueue();
|
||||
|
|
|
@ -177,7 +177,7 @@ int main(int argc, char *argv[]) {
|
|||
tInfo("RPC server is running, ctrl-c to exit");
|
||||
|
||||
if (commit) {
|
||||
pDataFile = taosOpenFile(dataName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pDataFile = taosOpenFile(dataName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno));
|
||||
}
|
||||
qhandle = taosOpenQueue();
|
||||
|
|
|
@ -360,7 +360,7 @@ int walSaveMeta(SWal* pWal) {
|
|||
int metaVer = walFindCurMetaVer(pWal);
|
||||
char fnameStr[WAL_FILE_LEN];
|
||||
walBuildMetaName(pWal, metaVer + 1, fnameStr);
|
||||
TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||
TdFilePtr pMataFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
if (pMataFile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -56,13 +56,13 @@ int walSetWrite(SWal* pWal) {
|
|||
|
||||
char fnameStr[WAL_FILE_LEN];
|
||||
walBuildIdxName(pWal, fileFirstVer, fnameStr);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pIdxTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pLogTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
@ -102,14 +102,14 @@ int walChangeWrite(SWal* pWal, int64_t ver) {
|
|||
|
||||
int64_t fileFirstVer = pFileInfo->firstVer;
|
||||
walBuildIdxName(pWal, fileFirstVer, fnameStr);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pIdxTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
pWal->pWriteIdxTFile = NULL;
|
||||
return -1;
|
||||
}
|
||||
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pLogTFile == NULL) {
|
||||
taosCloseFile(&pIdxTFile);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
|
|
|
@ -216,13 +216,13 @@ int walRoll(SWal *pWal) {
|
|||
int64_t newFileFirstVersion = pWal->vers.lastVer + 1;
|
||||
char fnameStr[WAL_FILE_LEN];
|
||||
walBuildIdxName(pWal, newFileFirstVersion, fnameStr);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pIdxTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
}
|
||||
walBuildLogName(pWal, newFileFirstVersion, fnameStr);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
if (pLogTFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
return -1;
|
||||
|
|
|
@ -129,7 +129,7 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
|||
if (pFileFrom == NULL) goto _err;
|
||||
|
||||
// fidto = open(to, O_WRONLY | O_CREAT | O_EXCL, 0755);
|
||||
TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_EXCL);
|
||||
TdFilePtr pFileTo = taosOpenFile(to, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_EXCL);
|
||||
if (pFileTo == NULL) goto _err;
|
||||
|
||||
while (true) {
|
||||
|
@ -246,7 +246,7 @@ TdFilePtr taosOpenFile(const char *path, int32_t tdFileOptions) {
|
|||
}
|
||||
} else {
|
||||
int access = O_BINARY;
|
||||
access |= (tdFileOptions & TD_FILE_CTEATE) ? O_CREAT : 0;
|
||||
access |= (tdFileOptions & TD_FILE_CREATE) ? O_CREAT : 0;
|
||||
if ((tdFileOptions & TD_FILE_WRITE) && (tdFileOptions & TD_FILE_READ)) {
|
||||
access |= O_RDWR;
|
||||
} else if (tdFileOptions & TD_FILE_WRITE) {
|
||||
|
|
|
@ -24,7 +24,7 @@ int32_t taosNewProc(char **args) {
|
|||
if (pid == 0) {
|
||||
args[0] = tsProcPath;
|
||||
// close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
// close(STDOUT_FILENO);
|
||||
// close(STDERR_FILENO);
|
||||
return execvp(tsProcPath, args);
|
||||
} else {
|
||||
|
|
|
@ -369,53 +369,33 @@ int32_t taosGetCpuCores(float *numOfCores) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int32_t taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
|
||||
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
|
||||
void taosGetCpuUsage(double *cpu_system, double *cpu_engine) {
|
||||
static int64_t lastSysUsed = 0;
|
||||
static int64_t lastSysTotal = 0;
|
||||
static int64_t lastProcTotal = 0;
|
||||
static int64_t curSysUsed = 0;
|
||||
static int64_t curSysTotal = 0;
|
||||
static int64_t curProcTotal = 0;
|
||||
|
||||
*cpu_system = 0;
|
||||
*cpu_engine = 0;
|
||||
return 0;
|
||||
#elif defined(_TD_DARWIN_64)
|
||||
*cpu_system = 0;
|
||||
*cpu_engine = 0;
|
||||
return 0;
|
||||
#else
|
||||
static uint64_t lastSysUsed = 0;
|
||||
static uint64_t lastSysTotal = 0;
|
||||
static uint64_t lastProcTotal = 0;
|
||||
|
||||
SysCpuInfo sysCpu;
|
||||
ProcCpuInfo procCpu;
|
||||
if (taosGetSysCpuInfo(&sysCpu) != 0) {
|
||||
return -1;
|
||||
}
|
||||
if (taosGetProcCpuInfo(&procCpu) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t curSysUsed = sysCpu.user + sysCpu.nice + sysCpu.system;
|
||||
uint64_t curSysTotal = curSysUsed + sysCpu.idle;
|
||||
uint64_t curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime;
|
||||
|
||||
if (lastSysUsed == 0 || lastSysTotal == 0 || lastProcTotal == 0) {
|
||||
lastSysUsed = curSysUsed > 1 ? curSysUsed : 1;
|
||||
lastSysTotal = curSysTotal > 1 ? curSysTotal : 1;
|
||||
lastProcTotal = curProcTotal > 1 ? curProcTotal : 1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (curSysTotal == lastSysTotal) {
|
||||
return -1;
|
||||
}
|
||||
SysCpuInfo sysCpu = {0};
|
||||
ProcCpuInfo procCpu = {0};
|
||||
if (taosGetSysCpuInfo(&sysCpu) == 0 && taosGetProcCpuInfo(&procCpu) == 0) {
|
||||
curSysUsed = sysCpu.user + sysCpu.nice + sysCpu.system;
|
||||
curSysTotal = curSysUsed + sysCpu.idle;
|
||||
curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime;
|
||||
|
||||
if (curSysTotal > lastSysTotal && curSysUsed >= lastSysUsed && curProcTotal >= lastProcTotal) {
|
||||
*cpu_engine = (curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100;
|
||||
*cpu_system = (curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100;
|
||||
}
|
||||
|
||||
lastSysUsed = curSysUsed;
|
||||
lastSysTotal = curSysTotal;
|
||||
lastProcTotal = curProcTotal;
|
||||
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int32_t taosGetTotalMemory(int64_t *totalKB) {
|
||||
|
@ -618,7 +598,6 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
|
|||
static int64_t last_wchars = 0;
|
||||
static int64_t last_read_bytes = 0;
|
||||
static int64_t last_write_bytes = 0;
|
||||
|
||||
static int64_t cur_rchars = 0;
|
||||
static int64_t cur_wchars = 0;
|
||||
static int64_t cur_read_bytes = 0;
|
||||
|
@ -632,6 +611,11 @@ void taosGetProcIODelta(int64_t *rchars, int64_t *wchars, int64_t *read_bytes, i
|
|||
last_wchars = cur_wchars;
|
||||
last_read_bytes = cur_read_bytes;
|
||||
last_write_bytes = cur_write_bytes;
|
||||
} else {
|
||||
*rchars = 0;
|
||||
*wchars = 0;
|
||||
*read_bytes = 0;
|
||||
*write_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -693,7 +677,6 @@ int32_t taosGetCardInfo(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
||||
static int64_t last_receive_bytes = 0;
|
||||
static int64_t last_transmit_bytes = 0;
|
||||
|
||||
static int64_t cur_receive_bytes = 0;
|
||||
static int64_t cur_transmit_bytes = 0;
|
||||
if (taosGetCardInfo(&cur_receive_bytes, &cur_transmit_bytes) == 0) {
|
||||
|
@ -701,6 +684,9 @@ void taosGetCardInfoDelta(int64_t *receive_bytes, int64_t *transmit_bytes) {
|
|||
*transmit_bytes = cur_transmit_bytes - last_transmit_bytes;
|
||||
last_receive_bytes = cur_receive_bytes;
|
||||
last_transmit_bytes = cur_transmit_bytes;
|
||||
} else {
|
||||
*receive_bytes = 0;
|
||||
*transmit_bytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -199,7 +199,7 @@ static void *taosThreadToOpenNewFile(void *param) {
|
|||
|
||||
taosUmaskFile(0);
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
tsLogObj.openInProgress = 0;
|
||||
tsLogObj.lines = tsLogObj.maxLines - 1000;
|
||||
|
@ -348,7 +348,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
|
|||
taosThreadMutexInit(&tsLogObj.logMutex, NULL);
|
||||
|
||||
taosUmaskFile(0);
|
||||
tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CTEATE | TD_FILE_WRITE);
|
||||
tsLogObj.logHandle->pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||
|
||||
if (tsLogObj.logHandle->pFile == NULL) {
|
||||
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
|
||||
|
@ -699,7 +699,7 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
|
|||
goto cmp_end;
|
||||
}
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CTEATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
TdFilePtr pFile = taosOpenFile(destFileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||
if (pFile == NULL) {
|
||||
ret = -2;
|
||||
goto cmp_end;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue