add quick cmd
This commit is contained in:
parent
f876bfd6c9
commit
eddc7918d3
|
@ -216,9 +216,9 @@ typedef struct SDataBlockInfo {
|
|||
} SDataBlockInfo;
|
||||
|
||||
typedef struct SSDataBlock {
|
||||
SColumnDataAgg* pBlockAgg;
|
||||
SArray* pDataBlock; // SArray<SColumnInfoData>
|
||||
SDataBlockInfo info;
|
||||
SColumnDataAgg* pBlockAgg;
|
||||
SArray* pDataBlock; // SArray<SColumnInfoData>
|
||||
SDataBlockInfo info;
|
||||
} SSDataBlock;
|
||||
|
||||
typedef struct SVarColAttr {
|
||||
|
@ -299,6 +299,26 @@ typedef struct STableBlockDistInfo {
|
|||
int32_t tSerializeBlockDistInfo(void* buf, int32_t bufLen, const STableBlockDistInfo* pInfo);
|
||||
int32_t tDeserializeBlockDistInfo(void* buf, int32_t bufLen, STableBlockDistInfo* pInfo);
|
||||
|
||||
typedef struct SDBBlockUsageInfo {
|
||||
uint32_t rowSize;
|
||||
uint16_t numOfFiles;
|
||||
uint32_t numOfTables;
|
||||
uint32_t numOfBlocks;
|
||||
uint64_t totalSize;
|
||||
uint64_t totalRows;
|
||||
int32_t maxRows;
|
||||
int32_t minRows;
|
||||
int32_t defMinRows;
|
||||
int32_t defMaxRows;
|
||||
int32_t firstSeekTimeUs;
|
||||
uint32_t numOfInmemRows;
|
||||
uint32_t numOfSttRows;
|
||||
uint32_t numOfVgroups;
|
||||
} SDBBlockUsageInfo;
|
||||
|
||||
int32_t tSerializeBlockDbUsage(void* buf, int32_t bufLen, const SDBBlockUsageInfo* pInfo);
|
||||
int32_t tDeserializeBlockDbUsage(void* buf, int32_t bufLen, SDBBlockUsageInfo* pInfo);
|
||||
|
||||
enum {
|
||||
FUNC_PARAM_TYPE_VALUE = 0x1,
|
||||
FUNC_PARAM_TYPE_COLUMN = 0x2,
|
||||
|
@ -391,9 +411,9 @@ typedef struct STUidTagInfo {
|
|||
int32_t taosGenCrashJsonMsg(int signum, char** pMsg, int64_t clusterId, int64_t startTime);
|
||||
int32_t dumpConfToDataBlock(SSDataBlock* pBlock, int32_t startCol);
|
||||
|
||||
#define TSMA_RES_STB_POSTFIX "_tsma_res_stb_"
|
||||
#define MD5_OUTPUT_LEN 32
|
||||
#define TSMA_RES_STB_EXTRA_COLUMN_NUM 4 // 3 columns: _wstart, _wend, _wduration, 1 tag: tbname
|
||||
#define TSMA_RES_STB_POSTFIX "_tsma_res_stb_"
|
||||
#define MD5_OUTPUT_LEN 32
|
||||
#define TSMA_RES_STB_EXTRA_COLUMN_NUM 4 // 3 columns: _wstart, _wend, _wduration, 1 tag: tbname
|
||||
|
||||
static inline bool isTsmaResSTb(const char* stbName) {
|
||||
const char* pos = strstr(stbName, TSMA_RES_STB_POSTFIX);
|
||||
|
|
|
@ -218,6 +218,9 @@ typedef enum EFunctionType {
|
|||
FUNCTION_TYPE_CONTAINS,
|
||||
FUNCTION_TYPE_CONTAINS_PROPERLY,
|
||||
|
||||
FUNCTION_TYPE_DB_USAGE = 4300,
|
||||
FUNCTION_TYPE_DB_USAGE_INFO,
|
||||
|
||||
// user defined funcion
|
||||
FUNCTION_TYPE_UDF = 10000
|
||||
} EFunctionType;
|
||||
|
@ -289,11 +292,13 @@ bool fmIsPrimaryKeyFunc(int32_t funcId);
|
|||
bool fmIsProcessByRowFunc(int32_t funcId);
|
||||
bool fmisSelectGroupConstValueFunc(int32_t funcId);
|
||||
bool fmIsElapsedFunc(int32_t funcId);
|
||||
bool fmIsDBUsageFunc(int32_t funcId);
|
||||
|
||||
void getLastCacheDataType(SDataType* pType, int32_t pkBytes);
|
||||
void getLastCacheDataType(SDataType* pType, int32_t pkBytes);
|
||||
int32_t createFunction(const char* pName, SNodeList* pParameterList, SFunctionNode** pFunc);
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc, SFunctionNode** pMergeFunc);
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc,
|
||||
SFunctionNode** pMergeFunc);
|
||||
|
||||
typedef enum EFuncDataRequired {
|
||||
FUNC_DATA_REQUIRED_DATA_LOAD = 1,
|
||||
|
@ -316,7 +321,7 @@ int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
|
|||
bool fmIsInvertible(int32_t funcId);
|
||||
#endif
|
||||
|
||||
char* fmGetFuncName(int32_t funcId);
|
||||
char* fmGetFuncName(int32_t funcId);
|
||||
|
||||
bool fmIsTSMASupportedFunc(func_id_t funcId);
|
||||
int32_t fmCreateStateFuncs(SNodeList* pFuncs);
|
||||
|
|
|
@ -339,7 +339,7 @@ typedef struct SShowStmt {
|
|||
SNode* pTbName; // SValueNode
|
||||
EOperatorType tableCondType;
|
||||
EShowKind showKind; // show databases: user/system, show tables: normal/child, others NULL
|
||||
bool withFull; // for show users full;
|
||||
bool withFull; // for show users full;
|
||||
} SShowStmt;
|
||||
|
||||
typedef struct SShowCreateDatabaseStmt {
|
||||
|
@ -375,6 +375,11 @@ typedef struct SShowTableDistributedStmt {
|
|||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
} SShowTableDistributedStmt;
|
||||
|
||||
typedef struct SShowDBUsageStmt {
|
||||
ENodeType type;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SShowDBUsageStmt;
|
||||
|
||||
typedef struct SShowDnodeVariablesStmt {
|
||||
ENodeType type;
|
||||
SNode* pDnodeId;
|
||||
|
@ -649,7 +654,7 @@ typedef struct SCreateTSMAStmt {
|
|||
bool ignoreExists;
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name
|
||||
char tableName[TSDB_TABLE_NAME_LEN]; // base tb name or base tsma name
|
||||
char originalTbName[TSDB_TABLE_NAME_LEN];
|
||||
STSMAOptions* pOptions;
|
||||
SNode* pPrevQuery;
|
||||
|
@ -658,10 +663,10 @@ typedef struct SCreateTSMAStmt {
|
|||
} SCreateTSMAStmt;
|
||||
|
||||
typedef struct SDropTSMAStmt {
|
||||
ENodeType type;
|
||||
bool ignoreNotExists;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
ENodeType type;
|
||||
bool ignoreNotExists;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tsmaName[TSDB_TABLE_NAME_LEN];
|
||||
} SDropTSMAStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -77,7 +77,8 @@ typedef enum EScanType {
|
|||
SCAN_TYPE_TABLE_MERGE,
|
||||
SCAN_TYPE_BLOCK_INFO,
|
||||
SCAN_TYPE_LAST_ROW,
|
||||
SCAN_TYPE_TABLE_COUNT
|
||||
SCAN_TYPE_TABLE_COUNT,
|
||||
SCAN_TYPE_DB_DISK_USAGE,
|
||||
} EScanType;
|
||||
|
||||
typedef struct SScanLogicNode {
|
||||
|
@ -121,12 +122,12 @@ typedef struct SScanLogicNode {
|
|||
bool sortPrimaryKey;
|
||||
bool igLastNull;
|
||||
bool groupOrderScan;
|
||||
bool onlyMetaCtbIdx; // for tag scan with no tbname
|
||||
bool filesetDelimited; // returned blocks delimited by fileset
|
||||
bool isCountByTag; // true if selectstmt hasCountFunc & part by tag/tbname
|
||||
SArray* pFuncTypes; // for last, last_row
|
||||
bool paraTablesSort; // for table merge scan
|
||||
bool smallDataTsSort; // disable row id sort for table merge scan
|
||||
bool onlyMetaCtbIdx; // for tag scan with no tbname
|
||||
bool filesetDelimited; // returned blocks delimited by fileset
|
||||
bool isCountByTag; // true if selectstmt hasCountFunc & part by tag/tbname
|
||||
SArray* pFuncTypes; // for last, last_row
|
||||
bool paraTablesSort; // for table merge scan
|
||||
bool smallDataTsSort; // disable row id sort for table merge scan
|
||||
bool needSplit;
|
||||
} SScanLogicNode;
|
||||
|
||||
|
@ -143,7 +144,7 @@ typedef struct SJoinLogicNode {
|
|||
SNode* pColOnCond;
|
||||
SNode* pTagEqCond;
|
||||
SNode* pTagOnCond;
|
||||
SNode* pFullOnCond; // except prim eq cond
|
||||
SNode* pFullOnCond; // except prim eq cond
|
||||
SNodeList* pLeftEqNodes;
|
||||
SNodeList* pRightEqNodes;
|
||||
bool allEqTags;
|
||||
|
@ -156,10 +157,10 @@ typedef struct SJoinLogicNode {
|
|||
bool batchScanHint;
|
||||
|
||||
// FOR HASH JOIN
|
||||
int32_t timeRangeTarget; //table onCond filter
|
||||
STimeWindow timeRange; //table onCond filter
|
||||
SNode* pLeftOnCond; //table onCond filter
|
||||
SNode* pRightOnCond; //table onCond filter
|
||||
int32_t timeRangeTarget; // table onCond filter
|
||||
STimeWindow timeRange; // table onCond filter
|
||||
SNode* pLeftOnCond; // table onCond filter
|
||||
SNode* pRightOnCond; // table onCond filter
|
||||
} SJoinLogicNode;
|
||||
|
||||
typedef struct SAggLogicNode {
|
||||
|
@ -174,7 +175,7 @@ typedef struct SAggLogicNode {
|
|||
bool isGroupTb;
|
||||
bool isPartTb; // true if partition keys has tbname
|
||||
bool hasGroup;
|
||||
SNodeList *pTsmaSubplans;
|
||||
SNodeList* pTsmaSubplans;
|
||||
} SAggLogicNode;
|
||||
|
||||
typedef struct SProjectLogicNode {
|
||||
|
@ -210,19 +211,19 @@ typedef struct SForecastFuncLogicNode {
|
|||
} SForecastFuncLogicNode;
|
||||
|
||||
typedef struct SGroupCacheLogicNode {
|
||||
SLogicNode node;
|
||||
bool grpColsMayBeNull;
|
||||
bool grpByUid;
|
||||
bool globalGrp;
|
||||
bool batchFetch;
|
||||
SNodeList* pGroupCols;
|
||||
SLogicNode node;
|
||||
bool grpColsMayBeNull;
|
||||
bool grpByUid;
|
||||
bool globalGrp;
|
||||
bool batchFetch;
|
||||
SNodeList* pGroupCols;
|
||||
} SGroupCacheLogicNode;
|
||||
|
||||
typedef struct SDynQueryCtrlStbJoin {
|
||||
bool batchFetch;
|
||||
SNodeList* pVgList;
|
||||
SNodeList* pUidList;
|
||||
bool srcScan[2];
|
||||
bool batchFetch;
|
||||
SNodeList* pVgList;
|
||||
SNodeList* pUidList;
|
||||
bool srcScan[2];
|
||||
} SDynQueryCtrlStbJoin;
|
||||
|
||||
typedef struct SDynQueryCtrlLogicNode {
|
||||
|
@ -342,7 +343,7 @@ typedef struct SSortLogicNode {
|
|||
bool groupSort;
|
||||
bool skipPKSortOpt;
|
||||
bool calcGroupId;
|
||||
bool excludePkCol; // exclude PK ts col when calc group id
|
||||
bool excludePkCol; // exclude PK ts col when calc group id
|
||||
} SSortLogicNode;
|
||||
|
||||
typedef struct SPartitionLogicNode {
|
||||
|
@ -352,8 +353,8 @@ typedef struct SPartitionLogicNode {
|
|||
SNode* pSubtable;
|
||||
SNodeList* pAggFuncs;
|
||||
|
||||
bool needBlockOutputTsOrder; // if true, partition output block will have ts order maintained
|
||||
int32_t pkTsColId;
|
||||
bool needBlockOutputTsOrder; // if true, partition output block will have ts order maintained
|
||||
int32_t pkTsColId;
|
||||
uint64_t pkTsColTbId;
|
||||
} SPartitionLogicNode;
|
||||
|
||||
|
@ -435,7 +436,7 @@ typedef struct SScanPhysiNode {
|
|||
|
||||
typedef struct STagScanPhysiNode {
|
||||
SScanPhysiNode scan;
|
||||
bool onlyMetaCtbIdx; //no tbname, tag index not used.
|
||||
bool onlyMetaCtbIdx; // no tbname, tag index not used.
|
||||
} STagScanPhysiNode;
|
||||
|
||||
typedef SScanPhysiNode SBlockDistScanPhysiNode;
|
||||
|
@ -535,12 +536,12 @@ typedef struct SSortMergeJoinPhysiNode {
|
|||
int32_t rightPrimSlotId;
|
||||
SNodeList* pEqLeft;
|
||||
SNodeList* pEqRight;
|
||||
SNode* pPrimKeyCond; //remove
|
||||
SNode* pColEqCond; //remove
|
||||
SNode* pPrimKeyCond; // remove
|
||||
SNode* pColEqCond; // remove
|
||||
SNode* pColOnCond;
|
||||
SNode* pFullOnCond;
|
||||
SNodeList* pTargets;
|
||||
SQueryStat inputStat[2];
|
||||
SQueryStat inputStat[2];
|
||||
bool seqWinGroup;
|
||||
bool grpJoin;
|
||||
} SSortMergeJoinPhysiNode;
|
||||
|
@ -550,25 +551,25 @@ typedef struct SHashJoinPhysiNode {
|
|||
EJoinType joinType;
|
||||
EJoinSubType subType;
|
||||
SNode* pWindowOffset;
|
||||
SNode* pJLimit;
|
||||
SNode* pJLimit;
|
||||
SNodeList* pOnLeft;
|
||||
SNodeList* pOnRight;
|
||||
SNode* leftPrimExpr;
|
||||
SNode* rightPrimExpr;
|
||||
int32_t leftPrimSlotId;
|
||||
int32_t rightPrimSlotId;
|
||||
int32_t timeRangeTarget; //table onCond filter
|
||||
STimeWindow timeRange; //table onCond filter
|
||||
SNode* pLeftOnCond; //table onCond filter
|
||||
SNode* pRightOnCond; //table onCond filter
|
||||
SNode* pFullOnCond; //preFilter
|
||||
int32_t timeRangeTarget; // table onCond filter
|
||||
STimeWindow timeRange; // table onCond filter
|
||||
SNode* pLeftOnCond; // table onCond filter
|
||||
SNode* pRightOnCond; // table onCond filter
|
||||
SNode* pFullOnCond; // preFilter
|
||||
SNodeList* pTargets;
|
||||
SQueryStat inputStat[2];
|
||||
|
||||
// only in planner internal
|
||||
SNode* pPrimKeyCond;
|
||||
SNode* pColEqCond;
|
||||
SNode* pTagEqCond;
|
||||
SNode* pPrimKeyCond;
|
||||
SNode* pColEqCond;
|
||||
SNode* pTagEqCond;
|
||||
} SHashJoinPhysiNode;
|
||||
|
||||
typedef struct SGroupCachePhysiNode {
|
||||
|
@ -581,10 +582,10 @@ typedef struct SGroupCachePhysiNode {
|
|||
} SGroupCachePhysiNode;
|
||||
|
||||
typedef struct SStbJoinDynCtrlBasic {
|
||||
bool batchFetch;
|
||||
int32_t vgSlot[2];
|
||||
int32_t uidSlot[2];
|
||||
bool srcScan[2];
|
||||
bool batchFetch;
|
||||
int32_t vgSlot[2];
|
||||
int32_t uidSlot[2];
|
||||
bool srcScan[2];
|
||||
} SStbJoinDynCtrlBasic;
|
||||
|
||||
typedef struct SDynQueryCtrlPhysiNode {
|
||||
|
@ -678,7 +679,7 @@ typedef struct SFillPhysiNode {
|
|||
SNode* pWStartTs; // SColumnNode
|
||||
SNode* pValues; // SNodeListNode
|
||||
STimeWindow timeRange;
|
||||
SNodeList* pFillNullExprs;
|
||||
SNodeList* pFillNullExprs;
|
||||
} SFillPhysiNode;
|
||||
|
||||
typedef SFillPhysiNode SStreamFillPhysiNode;
|
||||
|
@ -788,9 +789,9 @@ typedef struct SDataDeleterNode {
|
|||
char tableFName[TSDB_TABLE_NAME_LEN];
|
||||
char tsColName[TSDB_COL_NAME_LEN];
|
||||
STimeWindow deleteTimeRange;
|
||||
SNode* pAffectedRows; // usless
|
||||
SNode* pStartTs; // usless
|
||||
SNode* pEndTs; // usless
|
||||
SNode* pAffectedRows; // usless
|
||||
SNode* pStartTs; // usless
|
||||
SNode* pEndTs; // usless
|
||||
} SDataDeleterNode;
|
||||
|
||||
typedef struct SSubplan {
|
||||
|
|
|
@ -26,9 +26,9 @@ extern "C" {
|
|||
|
||||
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems);
|
||||
|
||||
int32_t saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
int32_t updateTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
int32_t loadTupleData(SqlFunctionCtx* pCtx, const STuplePos* pPos, char** value);
|
||||
int32_t saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
int32_t updateTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
int32_t loadTupleData(SqlFunctionCtx* pCtx, const STuplePos* pPos, char** value);
|
||||
|
||||
int32_t functionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t functionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
@ -40,7 +40,7 @@ bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEn
|
|||
int32_t countFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
#ifdef BUILD_NO_CALL
|
||||
int32_t countInvertFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t countInvertFunction(SqlFunctionCtx* pCtx);
|
||||
#endif
|
||||
|
||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
|
@ -48,10 +48,10 @@ bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv)
|
|||
int32_t sumFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
#ifdef BUILD_NO_CALL
|
||||
int32_t sumInvertFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t sumInvertFunction(SqlFunctionCtx* pCtx);
|
||||
#endif
|
||||
|
||||
int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||
int32_t sumCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||
|
||||
int32_t minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
@ -97,7 +97,7 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
|||
int32_t leastSQRCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
||||
|
||||
bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t percentileFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
void percentileFunctionCleanupExt(SqlFunctionCtx* pCtx);
|
||||
|
@ -206,7 +206,7 @@ int32_t mavgFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo
|
|||
int32_t mavgFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
bool getSampleFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t sampleFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t sampleFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t sampleFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
|
@ -225,7 +225,7 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
|||
void modeFunctionCleanupExt(SqlFunctionCtx* pCtx);
|
||||
|
||||
bool getTwaFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t twaFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t twaFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
|
@ -242,6 +242,10 @@ int32_t groupKeyCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
|
|||
int32_t groupConstValueFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t groupConstValueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
int32_t blockDBUsageSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t blockDBUsageFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t blockDBUsageFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -196,7 +196,7 @@ static int32_t addTimezoneParam(SNodeList* pList) {
|
|||
int32_t len = (int32_t)strlen(buf);
|
||||
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal);
|
||||
if (pVal == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
@ -228,7 +228,7 @@ static int32_t addTimezoneParam(SNodeList* pList) {
|
|||
|
||||
static int32_t addUint8Param(SNodeList** pList, uint8_t param) {
|
||||
SValueNode* pVal = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_VALUE, (SNode**)&pVal);
|
||||
if (pVal == NULL) {
|
||||
return code;
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ static int32_t addUint8Param(SNodeList** pList, uint8_t param) {
|
|||
}
|
||||
|
||||
static int32_t addPseudoParam(SNodeList** pList) {
|
||||
SNode *pseudoNode = NULL;
|
||||
SNode* pseudoNode = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_LEFT_VALUE, &pseudoNode);
|
||||
if (pseudoNode == NULL) {
|
||||
return code;
|
||||
|
@ -689,19 +689,17 @@ static int32_t validateHistogramBinDesc(char* binDescStr, int8_t binType, char*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t checkRangeValue(SNode *pNode, SParamRange range, bool *isMatch) {
|
||||
static int32_t checkRangeValue(SNode* pNode, SParamRange range, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (pNode->type == QUERY_NODE_VALUE) {
|
||||
SValueNode* pVal = (SValueNode*)pNode;
|
||||
if (IS_INTEGER_TYPE(getSDataTypeFromNode(pNode)->type)) {
|
||||
if (pVal->datum.i < range.iMinVal ||
|
||||
pVal->datum.i > range.iMaxVal) {
|
||||
if (pVal->datum.i < range.iMinVal || pVal->datum.i > range.iMaxVal) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_RANGE;
|
||||
*isMatch = false;
|
||||
}
|
||||
} else {
|
||||
if ((int64_t)pVal->datum.d < range.iMinVal ||
|
||||
(int64_t)pVal->datum.d > range.iMaxVal) {
|
||||
if ((int64_t)pVal->datum.d < range.iMinVal || (int64_t)pVal->datum.d > range.iMaxVal) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_RANGE;
|
||||
*isMatch = false;
|
||||
}
|
||||
|
@ -712,11 +710,10 @@ static int32_t checkRangeValue(SNode *pNode, SParamRange range, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkFixedValue(SNode *pNode, const SParamInfo *paramPattern, int32_t paramIdx, bool *isMatch) {
|
||||
static int32_t checkFixedValue(SNode* pNode, const SParamInfo* paramPattern, int32_t paramIdx, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
bool checkStr = paramSupportVarBinary(paramPattern->validDataType) ||
|
||||
paramSupportVarchar(paramPattern->validDataType) ||
|
||||
paramSupportNchar(paramPattern->validDataType);
|
||||
paramSupportVarchar(paramPattern->validDataType) || paramSupportNchar(paramPattern->validDataType);
|
||||
if (pNode->type == QUERY_NODE_VALUE) {
|
||||
SValueNode* pVal = (SValueNode*)pNode;
|
||||
if (!checkStr) {
|
||||
|
@ -748,7 +745,7 @@ static int32_t checkFixedValue(SNode *pNode, const SParamInfo *paramPattern, int
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkPrimTS(SNode *pNode, bool *isMatch) {
|
||||
static int32_t checkPrimTS(SNode* pNode, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (nodeType(pNode) != QUERY_NODE_COLUMN || !IS_TIMESTAMP_TYPE(getSDataTypeFromNode(pNode)->type) ||
|
||||
!((SColumnNode*)pNode)->isPrimTs) {
|
||||
|
@ -758,7 +755,7 @@ static int32_t checkPrimTS(SNode *pNode, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkPrimaryKey(SNode *pNode, bool *isMatch) {
|
||||
static int32_t checkPrimaryKey(SNode* pNode, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (nodeType(pNode) != QUERY_NODE_COLUMN || !IS_INTEGER_TYPE(getSDataTypeFromNode(pNode)->type) ||
|
||||
!((SColumnNode*)pNode)->isPk) {
|
||||
|
@ -768,7 +765,7 @@ static int32_t checkPrimaryKey(SNode *pNode, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkHasColumn(SNode *pNode, bool *isMatch) {
|
||||
static int32_t checkHasColumn(SNode* pNode, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (!nodesExprHasColumn(pNode)) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_HAS_COL;
|
||||
|
@ -777,7 +774,7 @@ static int32_t checkHasColumn(SNode *pNode, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkValueNodeNotNull(SNode *pNode, bool *isMatch) {
|
||||
static int32_t checkValueNodeNotNull(SNode* pNode, bool* isMatch) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
if (IS_NULL_TYPE(getSDataTypeFromNode(pNode)->type) && QUERY_NODE_VALUE == nodeType(pNode)) {
|
||||
code = TSDB_CODE_FUNC_FUNTION_PARA_TYPE;
|
||||
|
@ -786,7 +783,7 @@ static int32_t checkValueNodeNotNull(SNode *pNode, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t checkTimeUnit(SNode *pNode, int32_t precision, bool *isMatch) {
|
||||
static int32_t checkTimeUnit(SNode* pNode, int32_t precision, bool* isMatch) {
|
||||
if (nodeType(pNode) != QUERY_NODE_VALUE || !IS_INTEGER_TYPE(getSDataTypeFromNode(pNode)->type)) {
|
||||
*isMatch = false;
|
||||
return TSDB_CODE_FUNC_FUNTION_PARA_TYPE;
|
||||
|
@ -804,15 +801,15 @@ static int32_t checkTimeUnit(SNode *pNode, int32_t precision, bool *isMatch) {
|
|||
return code;
|
||||
}
|
||||
static int32_t validateParam(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNodeList* paramList = pFunc->pParameterList;
|
||||
char errMsg[128] = {0};
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNodeList* paramList = pFunc->pParameterList;
|
||||
char errMsg[128] = {0};
|
||||
|
||||
// no need to check
|
||||
if (funcMgtBuiltins[pFunc->funcId].parameters.paramInfoPattern == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
// check param num
|
||||
if ((funcMgtBuiltins[pFunc->funcId].parameters.maxParamNum != -1 &&
|
||||
LIST_LENGTH(paramList) > funcMgtBuiltins[pFunc->funcId].parameters.maxParamNum) ||
|
||||
|
@ -827,7 +824,8 @@ static int32_t validateParam(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
const SParamInfo* paramPattern = funcMgtBuiltins[pFunc->funcId].parameters.inputParaInfo[i];
|
||||
|
||||
while (1) {
|
||||
for (int8_t j = paramPattern[paramIdx].startParam; j <= (paramPattern[paramIdx].endParam == -1 ? INT8_MAX : paramPattern[paramIdx].endParam); j++) {
|
||||
for (int8_t j = paramPattern[paramIdx].startParam;
|
||||
j <= (paramPattern[paramIdx].endParam == -1 ? INT8_MAX : paramPattern[paramIdx].endParam); j++) {
|
||||
if (j > LIST_LENGTH(paramList)) {
|
||||
code = TSDB_CODE_SUCCESS;
|
||||
isMatch = true;
|
||||
|
@ -911,8 +909,8 @@ static int32_t validateParam(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_RANGE, "Invalid parameter range : %s",
|
||||
pFunc->functionName);
|
||||
case TSDB_CODE_FUNC_FUNTION_PARA_PRIMTS:
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_PRIMTS, "Parameter should be primary timestamp : %s",
|
||||
pFunc->functionName);
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_PRIMTS,
|
||||
"Parameter should be primary timestamp : %s", pFunc->functionName);
|
||||
case TSDB_CODE_FUNC_FUNTION_PARA_PK:
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_PARA_PK, "Parameter should be primary key : %s",
|
||||
pFunc->functionName);
|
||||
|
@ -924,7 +922,7 @@ static int32_t validateParam(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
pFunc->functionName);
|
||||
case TSDB_CODE_FUNC_TIME_UNIT_TOO_SMALL:
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_TIME_UNIT_TOO_SMALL, "Time unit is too small : %s",
|
||||
pFunc->functionName);
|
||||
pFunc->functionName);
|
||||
case TSDB_CODE_FUNC_FUNCTION_HISTO_TYPE:
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNCTION_HISTO_TYPE, "Invalid histogram bin type : %s",
|
||||
pFunc->functionName);
|
||||
|
@ -952,8 +950,8 @@ static int32_t translateMinMax(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
|
||||
SDataType* dataType = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0));
|
||||
uint8_t paraType = IS_NULL_TYPE(dataType->type) ? TSDB_DATA_TYPE_BIGINT : dataType->type;
|
||||
int32_t bytes = IS_STR_DATA_TYPE(paraType) ? dataType->bytes : tDataTypes[paraType].bytes;
|
||||
uint8_t paraType = IS_NULL_TYPE(dataType->type) ? TSDB_DATA_TYPE_BIGINT : dataType->type;
|
||||
int32_t bytes = IS_STR_DATA_TYPE(paraType) ? dataType->bytes : tDataTypes[paraType].bytes;
|
||||
pFunc->node.resType = (SDataType){.bytes = bytes, .type = paraType};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -965,7 +963,6 @@ static int32_t translateOutDouble(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t translateTrimStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isLtrim) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
|
||||
|
@ -1020,7 +1017,8 @@ static int32_t translateSum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
|
||||
static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// pseudo column do not need to check parameters
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT,
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes,
|
||||
.type = TSDB_DATA_TYPE_BIGINT,
|
||||
.precision = pFunc->node.resType.precision};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1050,8 +1048,7 @@ static int32_t translateRand(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes, .type = TSDB_DATA_TYPE_DOUBLE};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1065,9 +1062,9 @@ static int32_t translateOutFirstIn(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// pseudo column do not need to check parameters
|
||||
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes, .type = TSDB_DATA_TYPE_TIMESTAMP,
|
||||
.precision = pFunc->node.resType.precision};
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes,
|
||||
.type = TSDB_DATA_TYPE_TIMESTAMP,
|
||||
.precision = pFunc->node.resType.precision};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1097,7 +1094,6 @@ static int32_t translateVgIdColumn(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t reserveFirstMergeParam(SNodeList* pRawParameters, SNode* pPartialRes, SNodeList** pParameters) {
|
||||
int32_t code = nodesListMakeAppend(pParameters, pPartialRes);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -1126,13 +1122,9 @@ int32_t apercentileCreateMergeParam(SNodeList* pRawParameters, SNode* pPartialRe
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateElapsedPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return 0;
|
||||
}
|
||||
static int32_t translateElapsedPartial(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return 0; }
|
||||
|
||||
static int32_t translateElapsedMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return 0;
|
||||
}
|
||||
static int32_t translateElapsedMerge(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { return 0; }
|
||||
|
||||
static int32_t translateCsum(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
|
@ -1160,8 +1152,8 @@ static int32_t translateSampleTail(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
uint8_t colType = pSDataType->type;
|
||||
|
||||
// set result type
|
||||
pFunc->node.resType = (SDataType){.bytes = IS_STR_DATA_TYPE(colType) ? pSDataType->bytes : tDataTypes[colType].bytes,
|
||||
.type = colType};
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = IS_STR_DATA_TYPE(colType) ? pSDataType->bytes : tDataTypes[colType].bytes, .type = colType};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1260,7 +1252,7 @@ static EFuncReturnRows diffEstReturnRows(SFunctionNode* pFunc) {
|
|||
return FUNC_RETURN_ROWS_N_MINUS_1;
|
||||
}
|
||||
return 1 < ((SValueNode*)nodesListGetNode(pFunc->pParameterList, 1))->datum.i ? FUNC_RETURN_ROWS_INDEFINITE
|
||||
: FUNC_RETURN_ROWS_N_MINUS_1;
|
||||
: FUNC_RETURN_ROWS_N_MINUS_1;
|
||||
}
|
||||
|
||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum,
|
||||
|
@ -1327,14 +1319,14 @@ static int32_t translateChar(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
|
||||
static int32_t translateAscii(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_UTINYINT].bytes, .type = TSDB_DATA_TYPE_UTINYINT};
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_UTINYINT].bytes, .type = TSDB_DATA_TYPE_UTINYINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateTrim(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
|
||||
|
||||
uint8_t para0Type = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0))->type;
|
||||
int32_t resLen = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0))->bytes;
|
||||
uint8_t type = para0Type;
|
||||
|
@ -1401,7 +1393,7 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
// The number of parameters has been limited by the syntax definition
|
||||
|
||||
SExprNode* pPara0 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
uint8_t para0Type = pPara0->resType.type;
|
||||
uint8_t para0Type = pPara0->resType.type;
|
||||
if (TSDB_DATA_TYPE_VARBINARY == para0Type) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
@ -1418,7 +1410,7 @@ static int32_t translateCast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
if (TSDB_DATA_TYPE_NCHAR == para2Type) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"CAST function converted length should be in range (0, %d] NCHARS",
|
||||
(TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE)/TSDB_NCHAR_SIZE);
|
||||
(TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE);
|
||||
} else {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
"CAST function converted length should be in range (0, %d] bytes",
|
||||
|
@ -1522,8 +1514,7 @@ static int32_t translateAddPrecOutBigint(SFunctionNode* pFunc, char* pErrBuf, in
|
|||
return code;
|
||||
}
|
||||
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1535,7 +1526,8 @@ static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
|
||||
static int32_t translateOutGeom(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_GEOMETRY].bytes, .type = TSDB_DATA_TYPE_GEOMETRY};
|
||||
pFunc->node.resType =
|
||||
(SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_GEOMETRY].bytes, .type = TSDB_DATA_TYPE_GEOMETRY};
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1573,6 +1565,10 @@ static bool getBlockDistFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv
|
|||
pEnv->calcMemSize = sizeof(STableBlockDistInfo);
|
||||
return true;
|
||||
}
|
||||
static bool getBlockDBUsageFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SDBBlockUsageInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t translateGroupKey(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
|
@ -1582,7 +1578,6 @@ static int32_t translateGroupKey(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t translateServerStatusFunc(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_INT].bytes, .type = TSDB_DATA_TYPE_INT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1665,12 +1660,17 @@ static int32_t translateOutVarchar(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
case FUNCTION_TYPE_FIRST_STATE:
|
||||
case FUNCTION_TYPE_LAST_STATE:
|
||||
bytes = getFirstLastInfoSize(getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0))->bytes,
|
||||
(pFunc->hasPk) ? pFunc->pkBytes : 0) + VARSTR_HEADER_SIZE;
|
||||
(pFunc->hasPk) ? pFunc->pkBytes : 0) +
|
||||
VARSTR_HEADER_SIZE;
|
||||
break;
|
||||
case FUNCTION_TYPE_FIRST_STATE_MERGE:
|
||||
case FUNCTION_TYPE_LAST_STATE_MERGE:
|
||||
bytes = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0))->bytes;
|
||||
break;
|
||||
case FUNCTION_TYPE_DB_USAGE:
|
||||
case FUNCTION_TYPE_DB_USAGE_INFO:
|
||||
bytes = 128;
|
||||
break;
|
||||
default:
|
||||
bytes = 0;
|
||||
break;
|
||||
|
@ -1682,8 +1682,8 @@ static int32_t translateOutVarchar(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
static int32_t translateHistogramImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
FUNC_ERR_RET(validateParam(pFunc, pErrBuf, len));
|
||||
int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList);
|
||||
int8_t binType;
|
||||
char* binDesc;
|
||||
int8_t binType;
|
||||
char* binDesc;
|
||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||
SValueNode* pValue = (SValueNode*)nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (i == 1) {
|
||||
|
@ -5587,6 +5587,30 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_db_usage",
|
||||
.type = FUNCTION_TYPE_DB_USAGE,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_FORBID_STREAM_FUNC,
|
||||
.parameters = {.minParamNum = 0,
|
||||
.maxParamNum = 0,
|
||||
.paramInfoPattern = 0,
|
||||
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_VARCHAR_TYPE}},
|
||||
.translateFunc = translateOutVarchar,
|
||||
.getEnvFunc = getBlockDBUsageFuncEnv,
|
||||
.initFunc = blockDBUsageSetup,
|
||||
.processFunc = blockDBUsageFunction,
|
||||
.finalizeFunc = blockDBUsageFinalize
|
||||
},
|
||||
{
|
||||
.name = "_db_usage_info",
|
||||
.type = FUNCTION_TYPE_DB_USAGE_INFO,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_SCAN_PC_FUNC,
|
||||
.parameters = {.minParamNum = 0,
|
||||
.maxParamNum = 0,
|
||||
.paramInfoPattern = 0,
|
||||
.outputParaInfo = {.validDataType = FUNC_PARAM_SUPPORT_VARCHAR_TYPE}},
|
||||
.translateFunc = translateOutVarchar,
|
||||
},
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
|
|
|
@ -28,12 +28,8 @@
|
|||
#include "thistogram.h"
|
||||
#include "tpercentile.h"
|
||||
|
||||
bool ignoreNegative(int8_t ignoreOption){
|
||||
return (ignoreOption & 0x1) == 0x1;
|
||||
}
|
||||
bool ignoreNull(int8_t ignoreOption){
|
||||
return (ignoreOption & 0x2) == 0x2;
|
||||
}
|
||||
bool ignoreNegative(int8_t ignoreOption) { return (ignoreOption & 0x1) == 0x1; }
|
||||
bool ignoreNull(int8_t ignoreOption) { return (ignoreOption & 0x2) == 0x2; }
|
||||
|
||||
typedef enum {
|
||||
APERCT_ALGO_UNKNOWN = 0,
|
||||
|
@ -215,7 +211,7 @@ void funcInputUpdate(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow, bool *res) {
|
||||
int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow, bool* res) {
|
||||
if (pIter->finalRow) {
|
||||
if (pIter->hasPrev) {
|
||||
pRow->ts = pIter->prevBlockTsEnd;
|
||||
|
@ -223,7 +219,7 @@ int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow,
|
|||
pRow->pData = pIter->pPrevData;
|
||||
pRow->block = pIter->pPrevRowBlock;
|
||||
pRow->rowIndex = 0;
|
||||
|
||||
|
||||
pIter->hasPrev = false;
|
||||
*res = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -312,7 +308,8 @@ int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow,
|
|||
qError("out of memory when function get input row.");
|
||||
return terrno;
|
||||
}
|
||||
(void)memcpy(pIter->pPrevData, colDataGetData(pIter->pDataCol, pIter->inputEndIndex), pIter->pDataCol->info.bytes);
|
||||
(void)memcpy(pIter->pPrevData, colDataGetData(pIter->pDataCol, pIter->inputEndIndex),
|
||||
pIter->pDataCol->info.bytes);
|
||||
pIter->pPrevPk = taosMemoryMalloc(pIter->pPkCol->info.bytes);
|
||||
if (NULL == pIter->pPrevPk) {
|
||||
qError("out of memory when function get input row.");
|
||||
|
@ -341,12 +338,12 @@ static void setInputRowInfo(SFuncInputRow* pRow, SFuncInputRowIter* pIter, int32
|
|||
pRow->ts = pIter->tsList[rowIndex];
|
||||
pRow->isDataNull = colDataIsNull_f(pIter->pDataCol->nullbitmap, rowIndex);
|
||||
pRow->pData = colDataGetData(pIter->pDataCol, rowIndex);
|
||||
pRow->pPk = setPk? colDataGetData(pIter->pPkCol, rowIndex):NULL;
|
||||
pRow->pPk = setPk ? colDataGetData(pIter->pPkCol, rowIndex) : NULL;
|
||||
pRow->block = pIter->pSrcBlock;
|
||||
pRow->rowIndex = rowIndex;
|
||||
}
|
||||
|
||||
bool funcInputGetNextRowAscPk(SFuncInputRowIter *pIter, SFuncInputRow* pRow) {
|
||||
bool funcInputGetNextRowAscPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow) {
|
||||
if (pIter->hasPrev) {
|
||||
if (pIter->prevBlockTsEnd == pIter->tsList[pIter->inputEndIndex]) {
|
||||
pIter->hasPrev = true;
|
||||
|
@ -363,7 +360,7 @@ bool funcInputGetNextRowAscPk(SFuncInputRowIter *pIter, SFuncInputRow* pRow) {
|
|||
return true;
|
||||
}
|
||||
} else {
|
||||
if (pIter->rowIndex <= pIter->inputEndIndex) {
|
||||
if (pIter->rowIndex <= pIter->inputEndIndex) {
|
||||
setInputRowInfo(pRow, pIter, pIter->rowIndex, true);
|
||||
|
||||
TSKEY tsEnd = pIter->tsList[pIter->inputEndIndex];
|
||||
|
@ -382,17 +379,17 @@ bool funcInputGetNextRowAscPk(SFuncInputRowIter *pIter, SFuncInputRow* pRow) {
|
|||
}
|
||||
}
|
||||
|
||||
bool funcInputGetNextRowNoPk(SFuncInputRowIter *pIter, SFuncInputRow* pRow) {
|
||||
bool funcInputGetNextRowNoPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow) {
|
||||
if (pIter->rowIndex <= pIter->inputEndIndex) {
|
||||
setInputRowInfo(pRow, pIter, pIter->rowIndex, false);
|
||||
++pIter->rowIndex;
|
||||
return true;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t funcInputGetNextRow(SqlFunctionCtx* pCtx, SFuncInputRow* pRow, bool *res) {
|
||||
int32_t funcInputGetNextRow(SqlFunctionCtx* pCtx, SFuncInputRow* pRow, bool* res) {
|
||||
SFuncInputRowIter* pIter = &pCtx->rowIter;
|
||||
if (pCtx->hasPrimaryKey) {
|
||||
if (pCtx->order == TSDB_ORDER_ASC) {
|
||||
|
@ -448,7 +445,8 @@ int32_t appendSelectivityCols(SqlFunctionCtx* pCtx, SSDataBlock* pSrcBlock, int3
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool funcInputGetNextRowIndex(SInputColumnInfoData* pInput, int32_t from, bool firstOccur, int32_t* pRowIndex, int32_t* nextFrom);
|
||||
bool funcInputGetNextRowIndex(SInputColumnInfoData* pInput, int32_t from, bool firstOccur, int32_t* pRowIndex,
|
||||
int32_t* nextFrom);
|
||||
|
||||
static bool firstLastTransferInfoImpl(SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst);
|
||||
|
||||
|
@ -505,7 +503,7 @@ int32_t functionFinalizeWithResultBuf(SqlFunctionCtx* pCtx, SSDataBlock* pBlock,
|
|||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
|
||||
|
||||
char* in = finalResult;
|
||||
char* in = finalResult;
|
||||
int32_t code = colDataSetVal(pCol, pBlock->info.rows, in, pResInfo->isNullRes);
|
||||
|
||||
return code;
|
||||
|
@ -534,7 +532,7 @@ static int64_t getNumOfElems(SqlFunctionCtx* pCtx) {
|
|||
*/
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
if(1 == pInput->numOfRows && pInput->blankFill) {
|
||||
if (1 == pInput->numOfRows && pInput->blankFill) {
|
||||
return 0;
|
||||
}
|
||||
if (pInput->colDataSMAIsSet && pInput->totalRows == pInput->numOfRows) {
|
||||
|
@ -918,8 +916,8 @@ int32_t setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STu
|
|||
|
||||
if ((pCtx->saveHandle.pBuf != NULL && pTuplePos->pageId != -1) ||
|
||||
(pCtx->saveHandle.pState && pTuplePos->streamTupleKey.ts > 0)) {
|
||||
int32_t numOfCols = pCtx->subsidiaries.num;
|
||||
char* p = NULL;
|
||||
int32_t numOfCols = pCtx->subsidiaries.num;
|
||||
char* p = NULL;
|
||||
int32_t code = loadTupleData(pCtx, pTuplePos, &p);
|
||||
if (p == NULL || TSDB_CODE_SUCCESS != code) {
|
||||
qError("Load tuple data failed since %s, groupId:%" PRIu64 ", ts:%" PRId64, terrstr(),
|
||||
|
@ -1004,7 +1002,7 @@ int32_t appendSelectivityValue(SqlFunctionCtx* pCtx, int32_t rowIndex, int32_t p
|
|||
|
||||
void replaceTupleData(STuplePos* pDestPos, STuplePos* pSourcePos) { *pDestPos = *pSourcePos; }
|
||||
|
||||
#define COMPARE_MINMAX_DATA(type) (( (*(type*)&pDBuf->v) < (*(type*)&pSBuf->v) ) ^ isMinFunc)
|
||||
#define COMPARE_MINMAX_DATA(type) (((*(type*)&pDBuf->v) < (*(type*)&pSBuf->v)) ^ isMinFunc)
|
||||
int32_t minMaxCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx, int32_t isMinFunc) {
|
||||
SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx);
|
||||
SMinmaxResInfo* pDBuf = GET_ROWCELL_INTERBUF(pDResInfo);
|
||||
|
@ -1318,8 +1316,8 @@ int32_t stdFunctionMerge(SqlFunctionCtx* pCtx) {
|
|||
|
||||
for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) {
|
||||
if (colDataIsNull_s(pCol, i)) continue;
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SStdRes* pInputInfo = (SStdRes*)varDataVal(data);
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SStdRes* pInputInfo = (SStdRes*)varDataVal(data);
|
||||
stdTransferInfo(pInputInfo, pInfo);
|
||||
}
|
||||
|
||||
|
@ -1805,7 +1803,8 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) {
|
|||
pResInfo->complete = true;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup, &pInfo->pMemBucket);
|
||||
code = tMemBucketCreate(pCol->info.bytes, type, pInfo->minval, pInfo->maxval, pCtx->hasWindowOrGroup,
|
||||
&pInfo->pMemBucket);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -1893,8 +1892,9 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
tMemBucket** pMemBucket = &ppInfo->pMemBucket;
|
||||
if ((*pMemBucket) != NULL && (*pMemBucket)->total > 0) { // check for null
|
||||
if (pCtx->numOfParams > 2) {
|
||||
char buf[3200] = {0};
|
||||
// max length of double num is 317, e.g. use %.6lf to print -1.0e+308, consider the comma and bracket, 3200 is enough.
|
||||
char buf[3200] = {0};
|
||||
// max length of double num is 317, e.g. use %.6lf to print -1.0e+308, consider the comma and bracket, 3200 is
|
||||
// enough.
|
||||
size_t len = 1;
|
||||
|
||||
varDataVal(buf)[0] = '[';
|
||||
|
@ -2139,7 +2139,7 @@ static int32_t apercentileTransferInfo(SAPercentileInfo* pInput, SAPercentileInf
|
|||
pHisto->numOfEntries, pInput->pHisto);
|
||||
|
||||
SHistogramInfo* pRes = NULL;
|
||||
int32_t code = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN, &pRes);
|
||||
int32_t code = tHistogramMerge(pHisto, pInput->pHisto, MAX_HISTOGRAM_BIN, &pRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
tHistogramDestroy(&pRes);
|
||||
return code;
|
||||
|
@ -2169,13 +2169,13 @@ int32_t apercentileFunctionMerge(SqlFunctionCtx* pCtx) {
|
|||
|
||||
qDebug("%s total %" PRId64 " rows will merge, %p", __FUNCTION__, pInput->numOfRows, pInfo->pHisto);
|
||||
|
||||
bool hasRes = false;
|
||||
bool hasRes = false;
|
||||
int32_t start = pInput->startRowIndex;
|
||||
for (int32_t i = start; i < start + pInput->numOfRows; ++i) {
|
||||
char* data = colDataGetData(pCol, i);
|
||||
|
||||
SAPercentileInfo* pInputInfo = (SAPercentileInfo*)varDataVal(data);
|
||||
int32_t code = apercentileTransferInfo(pInputInfo, pInfo, &hasRes);
|
||||
int32_t code = apercentileTransferInfo(pInputInfo, pInfo, &hasRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2299,7 +2299,7 @@ static int32_t comparePkDataWithSValue(int8_t pkType, char* pkData, SValue* pVal
|
|||
default:
|
||||
break;
|
||||
}
|
||||
char* blockData = (IS_NUMERIC_TYPE(pkType)) ? (char*) numVal : (char*)pVal->pData;
|
||||
char* blockData = (IS_NUMERIC_TYPE(pkType)) ? (char*)numVal : (char*)pVal->pData;
|
||||
__compar_fn_t fn = getKeyComparFunc(pkType, order);
|
||||
return fn(pkData, blockData);
|
||||
}
|
||||
|
@ -2318,7 +2318,7 @@ EFuncDataRequired firstDynDataReq(void* pRes, SDataBlockInfo* pBlockInfo) {
|
|||
pResult->pkData = pResult->buf + pResult->bytes;
|
||||
} else {
|
||||
pResult->pkData = NULL;
|
||||
}
|
||||
}
|
||||
if (pResult->ts < pBlockInfo->window.skey) {
|
||||
return FUNC_DATA_REQUIRED_NOT_LOAD;
|
||||
} else if (pResult->ts == pBlockInfo->window.skey) {
|
||||
|
@ -2363,12 +2363,12 @@ EFuncDataRequired lastDynDataReq(void* pRes, SDataBlockInfo* pBlockInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO modify it to include primary key bytes
|
||||
// TODO modify it to include primary key bytes
|
||||
int32_t getFirstLastInfoSize(int32_t resBytes, int32_t pkBytes) { return sizeof(SFirstLastRes) + resBytes + pkBytes; }
|
||||
|
||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
//TODO: change SFunctionNode to add pk info
|
||||
// TODO: change SFunctionNode to add pk info
|
||||
int32_t pkBytes = (pFunc->hasPk) ? pFunc->pkBytes : 0;
|
||||
pEnv->calcMemSize = getFirstLastInfoSize(pNode->node.resType.bytes, pkBytes);
|
||||
return true;
|
||||
|
@ -2402,7 +2402,7 @@ int32_t firstLastFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResIn
|
|||
return TSDB_CODE_FUNC_SETUP_ERROR;
|
||||
}
|
||||
|
||||
SFirstLastRes * pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
|
||||
pRes->nullTupleSaved = false;
|
||||
|
@ -2444,7 +2444,8 @@ static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowI
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t doSaveCurrentVal(SqlFunctionCtx* pCtx, int32_t rowIndex, int64_t currentTs, char* pkData, int32_t type, char* pData) {
|
||||
static int32_t doSaveCurrentVal(SqlFunctionCtx* pCtx, int32_t rowIndex, int64_t currentTs, char* pkData, int32_t type,
|
||||
char* pData) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SFirstLastRes* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
|
@ -2490,7 +2491,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
pInfo->pkType = -1;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
if (pCtx->hasPrimaryKey) {
|
||||
pInfo->pkType = pkCol->info.type;
|
||||
pInfo->pkBytes = pkCol->info.bytes;
|
||||
|
@ -2569,7 +2570,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
#else
|
||||
int64_t* pts = (int64_t*)pInput->pPTS->pData;
|
||||
|
||||
int from = -1;
|
||||
int from = -1;
|
||||
int32_t i = -1;
|
||||
while (funcInputGetNextRowIndex(pInput, from, true, &i, &from)) {
|
||||
if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
|
||||
|
@ -2583,8 +2584,8 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
|||
pkData = colDataGetData(pkCol, i);
|
||||
}
|
||||
TSKEY cts = pts[i];
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts > cts ||
|
||||
(pInfo->ts == cts && pkCompareFn && pkCompareFn(pkData, pInfo->pkData) < 0)) {
|
||||
if (pResInfo->numOfRes == 0 || pInfo->ts > cts ||
|
||||
(pInfo->ts == cts && pkCompareFn && pkCompareFn(pkData, pInfo->pkData) < 0)) {
|
||||
int32_t code = doSaveCurrentVal(pCtx, i, cts, pkData, pInputCol->info.type, data);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -2625,7 +2626,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
pInfo->pkType = -1;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
if (pCtx->hasPrimaryKey) {
|
||||
pInfo->pkType = pkCol->info.type;
|
||||
pInfo->pkBytes = pkCol->info.bytes;
|
||||
|
@ -2703,7 +2704,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
#else
|
||||
|
||||
// todo refactor
|
||||
// todo refactor
|
||||
if (!pInputCol->hasNull && !pCtx->hasPrimaryKey) {
|
||||
numOfElems = 1;
|
||||
|
||||
|
@ -2750,7 +2751,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
int from = -1;
|
||||
int from = -1;
|
||||
int32_t i = -1;
|
||||
while (funcInputGetNextRowIndex(pInput, from, false, &i, &from)) {
|
||||
if (colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) {
|
||||
|
@ -2976,8 +2977,7 @@ int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
|||
static int32_t doSaveLastrow(SqlFunctionCtx* pCtx, char* pData, int32_t rowIndex, int64_t cts, SFirstLastRes* pInfo) {
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
|
||||
if (colDataIsNull_s(pInputCol, rowIndex)) {
|
||||
pInfo->isNull = true;
|
||||
|
@ -3028,7 +3028,7 @@ int32_t lastRowFunction(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
pInfo->pkType = -1;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
if (pCtx->hasPrimaryKey) {
|
||||
pInfo->pkType = pkCol->info.type;
|
||||
pInfo->pkBytes = pkCol->info.bytes;
|
||||
|
@ -3069,8 +3069,8 @@ int32_t lastRowFunction(SqlFunctionCtx* pCtx) {
|
|||
#else
|
||||
|
||||
int64_t* pts = (int64_t*)pInput->pPTS->pData;
|
||||
int from = -1;
|
||||
int32_t i = -1;
|
||||
int from = -1;
|
||||
int32_t i = -1;
|
||||
while (funcInputGetNextRowIndex(pInput, from, false, &i, &from)) {
|
||||
bool isNull = colDataIsNull(pInputCol, pInput->numOfRows, i, NULL);
|
||||
char* data = isNull ? NULL : colDataGetData(pInputCol, i);
|
||||
|
@ -3188,7 +3188,7 @@ static bool diffIsNegtive(SDiffInfo* pDiffInfo, int32_t type, const char* pv) {
|
|||
int64_t v = *(int16_t*)pv;
|
||||
return v < pDiffInfo->prev.i64;
|
||||
}
|
||||
case TSDB_DATA_TYPE_UBIGINT:{
|
||||
case TSDB_DATA_TYPE_UBIGINT: {
|
||||
uint64_t v = *(uint64_t*)pv;
|
||||
return v < (uint64_t)pDiffInfo->prev.i64;
|
||||
}
|
||||
|
@ -3214,7 +3214,7 @@ static bool diffIsNegtive(SDiffInfo* pDiffInfo, int32_t type, const char* pv) {
|
|||
|
||||
static void tryToSetInt64(SDiffInfo* pDiffInfo, int32_t type, SColumnInfoData* pOutput, int64_t v, int32_t pos) {
|
||||
bool isNegative = v < pDiffInfo->prev.i64;
|
||||
if(type == TSDB_DATA_TYPE_UBIGINT){
|
||||
if (type == TSDB_DATA_TYPE_UBIGINT) {
|
||||
isNegative = (uint64_t)v < (uint64_t)pDiffInfo->prev.i64;
|
||||
}
|
||||
int64_t delta = v - pDiffInfo->prev.i64;
|
||||
|
@ -3270,7 +3270,7 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
|
|||
tryToSetInt64(pDiffInfo, type, pOutput, v, pos);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_USMALLINT:{
|
||||
case TSDB_DATA_TYPE_USMALLINT: {
|
||||
int64_t v = *(uint16_t*)pv;
|
||||
tryToSetInt64(pDiffInfo, type, pOutput, v, pos);
|
||||
break;
|
||||
|
@ -3304,9 +3304,10 @@ static int32_t doHandleDiff(SDiffInfo* pDiffInfo, int32_t type, const char* pv,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
//TODO: the primary key compare can be skipped for ordered pk if knonwn before
|
||||
//TODO: for desc ordered, pk shall select the smallest one for one ts. if across block boundaries.
|
||||
bool funcInputGetNextRowIndex(SInputColumnInfoData* pInput, int32_t from, bool firstOccur, int32_t* pRowIndex, int32_t* nextFrom) {
|
||||
// TODO: the primary key compare can be skipped for ordered pk if knonwn before
|
||||
// TODO: for desc ordered, pk shall select the smallest one for one ts. if across block boundaries.
|
||||
bool funcInputGetNextRowIndex(SInputColumnInfoData* pInput, int32_t from, bool firstOccur, int32_t* pRowIndex,
|
||||
int32_t* nextFrom) {
|
||||
if (pInput->pPrimaryKey == NULL) {
|
||||
if (from == -1) {
|
||||
from = pInput->startRowIndex;
|
||||
|
@ -3322,16 +3323,16 @@ bool funcInputGetNextRowIndex(SInputColumnInfoData* pInput, int32_t from, bool f
|
|||
} else if (from >= pInput->numOfRows + pInput->startRowIndex) {
|
||||
return false;
|
||||
}
|
||||
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
||||
TSKEY* tsList = (int64_t*)pInput->pPTS->pData;
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
int8_t pkType = pkCol->info.type;
|
||||
int32_t order = (firstOccur) ? TSDB_ORDER_ASC: TSDB_ORDER_DESC;
|
||||
__compar_fn_t compareFunc = getKeyComparFunc(pkType, order);
|
||||
int32_t select = from;
|
||||
char* val = colDataGetData(pkCol, select);
|
||||
while (from < pInput->numOfRows + pInput->startRowIndex - 1 && tsList[from + 1] == tsList[from]) {
|
||||
int8_t pkType = pkCol->info.type;
|
||||
int32_t order = (firstOccur) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC;
|
||||
__compar_fn_t compareFunc = getKeyComparFunc(pkType, order);
|
||||
int32_t select = from;
|
||||
char* val = colDataGetData(pkCol, select);
|
||||
while (from < pInput->numOfRows + pInput->startRowIndex - 1 && tsList[from + 1] == tsList[from]) {
|
||||
char* val1 = colDataGetData(pkCol, from + 1);
|
||||
if (compareFunc(val1, val) < 0) {
|
||||
if (compareFunc(val1, val) < 0) {
|
||||
select = from + 1;
|
||||
val = val1;
|
||||
}
|
||||
|
@ -3348,13 +3349,13 @@ bool getForecastConfEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv)
|
|||
return true;
|
||||
}
|
||||
|
||||
int32_t diffResultIsNull(SqlFunctionCtx* pCtx, SFuncInputRow* pRow){
|
||||
int32_t diffResultIsNull(SqlFunctionCtx* pCtx, SFuncInputRow* pRow) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SDiffInfo* pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
if (pRow->isDataNull || !pDiffInfo->hasPrev ) {
|
||||
if (pRow->isDataNull || !pDiffInfo->hasPrev) {
|
||||
return true;
|
||||
} else if (ignoreNegative(pDiffInfo->ignoreOption)){
|
||||
} else if (ignoreNegative(pDiffInfo->ignoreOption)) {
|
||||
return diffIsNegtive(pDiffInfo, pCtx->input.pData[0]->info.type, pRow->pData);
|
||||
}
|
||||
return false;
|
||||
|
@ -3378,7 +3379,7 @@ int32_t trySetPreVal(SqlFunctionCtx* pCtx, SFuncInputRow* pRow) {
|
|||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
int8_t inputType = pInputCol->info.type;
|
||||
|
||||
char* pv = pRow->pData;
|
||||
char* pv = pRow->pData;
|
||||
return doSetPrevVal(pDiffInfo, inputType, pv, pRow->ts);
|
||||
}
|
||||
|
||||
|
@ -3425,19 +3426,17 @@ int32_t setDoDiffResult(SqlFunctionCtx* pCtx, SFuncInputRow* pRow, int32_t pos)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t diffFunction(SqlFunctionCtx* pCtx) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t diffFunction(SqlFunctionCtx* pCtx) { return TSDB_CODE_SUCCESS; }
|
||||
|
||||
int32_t diffFunctionByRow(SArray* pCtxArray) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int diffColNum = pCtxArray->size;
|
||||
if(diffColNum == 0) {
|
||||
int diffColNum = pCtxArray->size;
|
||||
if (diffColNum == 0) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t numOfElems = 0;
|
||||
|
||||
SArray* pRows = taosArrayInit_s(sizeof(SFuncInputRow), diffColNum);
|
||||
SArray* pRows = taosArrayInit_s(sizeof(SFuncInputRow), diffColNum);
|
||||
if (NULL == pRows) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -3458,7 +3457,7 @@ int32_t diffFunctionByRow(SArray* pCtxArray) {
|
|||
}
|
||||
|
||||
SqlFunctionCtx* pCtx0 = *(SqlFunctionCtx**)taosArrayGet(pCtxArray, 0);
|
||||
SFuncInputRow* pRow0 = (SFuncInputRow*)taosArrayGet(pRows, 0);
|
||||
SFuncInputRow* pRow0 = (SFuncInputRow*)taosArrayGet(pRows, 0);
|
||||
if (NULL == pCtx0 || NULL == pRow0) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
|
@ -3476,7 +3475,7 @@ int32_t diffFunctionByRow(SArray* pCtxArray) {
|
|||
bool hasNotNullValue = !diffResultIsNull(pCtx0, pRow0);
|
||||
for (int i = 1; i < diffColNum; ++i) {
|
||||
SqlFunctionCtx* pCtx = *(SqlFunctionCtx**)taosArrayGet(pCtxArray, i);
|
||||
SFuncInputRow* pRow = (SFuncInputRow*)taosArrayGet(pRows, i);
|
||||
SFuncInputRow* pRow = (SFuncInputRow*)taosArrayGet(pRows, i);
|
||||
if (NULL == pCtx || NULL == pRow) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
|
@ -3504,7 +3503,7 @@ int32_t diffFunctionByRow(SArray* pCtxArray) {
|
|||
code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
if ((keepNull || hasNotNullValue) && !isFirstRow(pCtx, pRow)){
|
||||
if ((keepNull || hasNotNullValue) && !isFirstRow(pCtx, pRow)) {
|
||||
code = setDoDiffResult(pCtx, pRow, pos);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
|
@ -3514,14 +3513,14 @@ int32_t diffFunctionByRow(SArray* pCtxArray) {
|
|||
code = trySetPreVal(pCtx, pRow);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (newRow) ++numOfElems;
|
||||
}
|
||||
|
||||
for (int i = 0; i < diffColNum; ++i) {
|
||||
SqlFunctionCtx* pCtx = *(SqlFunctionCtx**)taosArrayGet(pCtxArray, i);
|
||||
SqlFunctionCtx* pCtx = *(SqlFunctionCtx**)taosArrayGet(pCtxArray, i);
|
||||
if (NULL == pCtx) {
|
||||
code = terrno;
|
||||
goto _exit;
|
||||
|
@ -3738,7 +3737,7 @@ int32_t doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSD
|
|||
qDebug("page_copyTuple pageId:%d, offset:%d", pItem->tuplePos.pageId, pItem->tuplePos.offset);
|
||||
#endif
|
||||
code = taosheapadjust((void*)pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void*)&type,
|
||||
topBotResComparFn, NULL, !isTopQuery);
|
||||
topBotResComparFn, NULL, !isTopQuery);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3755,7 +3754,7 @@ int32_t doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSD
|
|||
* +------------------------------------+--------------+--------------+
|
||||
*/
|
||||
int32_t serializeTupleData(const SSDataBlock* pSrcBlock, int32_t rowIndex, SSubsidiaryResInfo* pSubsidiaryies,
|
||||
char* buf, char** res) {
|
||||
char* buf, char** res) {
|
||||
char* nullList = buf;
|
||||
char* pStart = (char*)(nullList + sizeof(bool) * pSubsidiaryies->num);
|
||||
|
||||
|
@ -3829,7 +3828,7 @@ static int32_t doSaveTupleData(SSerializeDataHandle* pHandle, const void* pBuf,
|
|||
pPage->num += length;
|
||||
setBufPageDirty(pPage, true);
|
||||
releaseBufPage(pHandle->pBuf, pPage);
|
||||
} else { // other tuple save policy
|
||||
} else { // other tuple save policy
|
||||
if (pStore->streamStateFuncPut(pHandle->pState, key, pBuf, length) >= 0) {
|
||||
p.streamTupleKey = *key;
|
||||
}
|
||||
|
@ -3866,7 +3865,8 @@ int32_t saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock*
|
|||
return doSaveTupleData(&pCtx->saveHandle, buf, pCtx->subsidiaries.rowLen, &key, pPos, pCtx->pStore);
|
||||
}
|
||||
|
||||
static int32_t doUpdateTupleData(SSerializeDataHandle* pHandle, const void* pBuf, size_t length, STuplePos* pPos, SFunctionStateStore* pStore) {
|
||||
static int32_t doUpdateTupleData(SSerializeDataHandle* pHandle, const void* pBuf, size_t length, STuplePos* pPos,
|
||||
SFunctionStateStore* pStore) {
|
||||
if (pHandle->pBuf != NULL) {
|
||||
SFilePage* pPage = getBufPage(pHandle->pBuf, pPos->pageId);
|
||||
if (pPage == NULL) {
|
||||
|
@ -3899,7 +3899,8 @@ int32_t updateTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBloc
|
|||
return doUpdateTupleData(&pCtx->saveHandle, buf, pCtx->subsidiaries.rowLen, pPos, pCtx->pStore);
|
||||
}
|
||||
|
||||
static int32_t doLoadTupleData(SSerializeDataHandle* pHandle, const STuplePos* pPos, SFunctionStateStore* pStore, char** value) {
|
||||
static int32_t doLoadTupleData(SSerializeDataHandle* pHandle, const STuplePos* pPos, SFunctionStateStore* pStore,
|
||||
char** value) {
|
||||
if (pHandle->pBuf != NULL) {
|
||||
SFilePage* pPage = getBufPage(pHandle->pBuf, pPos->pageId);
|
||||
if (pPage == NULL) {
|
||||
|
@ -3912,7 +3913,7 @@ static int32_t doLoadTupleData(SSerializeDataHandle* pHandle, const STuplePos* p
|
|||
} else {
|
||||
*value = NULL;
|
||||
int32_t vLen;
|
||||
int32_t code = pStore->streamStateFuncGet(pHandle->pState, &pPos->streamTupleKey, (void **)(value), &vLen);
|
||||
int32_t code = pStore->streamStateFuncGet(pHandle->pState, &pPos->streamTupleKey, (void**)(value), &vLen);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3979,11 +3980,11 @@ int32_t addResult(SqlFunctionCtx* pCtx, STopBotResItem* pSourceItem, int16_t typ
|
|||
pItem->tuplePos.pageId = -1;
|
||||
replaceTupleData(&pItem->tuplePos, &pSourceItem->tuplePos);
|
||||
pEntryInfo->numOfRes++;
|
||||
code = taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type,
|
||||
code = taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type,
|
||||
topBotResComparFn, !isTopQuery);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
} else { // replace the minimum value in the result
|
||||
if ((isTopQuery && ((IS_SIGNED_NUMERIC_TYPE(type) && pSourceItem->v.i > pItems[0].v.i) ||
|
||||
(IS_UNSIGNED_NUMERIC_TYPE(type) && pSourceItem->v.u > pItems[0].v.u) ||
|
||||
|
@ -4159,7 +4160,7 @@ int32_t spreadFunctionMerge(SqlFunctionCtx* pCtx) {
|
|||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
for (int32_t i = start; i < start + pInput->numOfRows; ++i) {
|
||||
if(colDataIsNull_s(pCol, i)) continue;
|
||||
if (colDataIsNull_s(pCol, i)) continue;
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SSpreadInfo* pInputInfo = (SSpreadInfo*)varDataVal(data);
|
||||
if (pInputInfo->hasResult) {
|
||||
|
@ -4609,7 +4610,7 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
pInfo->totalCount = 0;
|
||||
pInfo->normalized = 0;
|
||||
|
||||
char* binTypeStr = taosStrndup(varDataVal(pCtx->param[1].param.pz), varDataLen(pCtx->param[1].param.pz));
|
||||
char* binTypeStr = taosStrndup(varDataVal(pCtx->param[1].param.pz), varDataLen(pCtx->param[1].param.pz));
|
||||
if (binTypeStr == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -4619,7 +4620,7 @@ int32_t histogramFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResul
|
|||
if (binType == UNKNOWN_BIN) {
|
||||
return TSDB_CODE_FUNC_FUNTION_PARA_VALUE;
|
||||
}
|
||||
char* binDesc = taosStrndup(varDataVal(pCtx->param[2].param.pz), varDataLen(pCtx->param[2].param.pz));
|
||||
char* binDesc = taosStrndup(varDataVal(pCtx->param[2].param.pz), varDataLen(pCtx->param[2].param.pz));
|
||||
if (binDesc == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -4740,11 +4741,13 @@ int32_t histogramFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
int32_t len;
|
||||
char buf[512] = {0};
|
||||
if (!pInfo->normalized) {
|
||||
len = tsnprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}",
|
||||
pInfo->bins[i].lower, pInfo->bins[i].upper, pInfo->bins[i].count);
|
||||
len = tsnprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE,
|
||||
"{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%" PRId64 "}", pInfo->bins[i].lower,
|
||||
pInfo->bins[i].upper, pInfo->bins[i].count);
|
||||
} else {
|
||||
len = tsnprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE, "{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", pInfo->bins[i].lower,
|
||||
pInfo->bins[i].upper, pInfo->bins[i].percentage);
|
||||
len = tsnprintf(varDataVal(buf), sizeof(buf) - VARSTR_HEADER_SIZE,
|
||||
"{\"lower_bin\":%g, \"upper_bin\":%g, \"count\":%lf}", pInfo->bins[i].lower, pInfo->bins[i].upper,
|
||||
pInfo->bins[i].percentage);
|
||||
}
|
||||
varDataSetLen(buf, len);
|
||||
code = colDataSetVal(pCol, currentRow, buf, false);
|
||||
|
@ -5854,7 +5857,7 @@ int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void modeFunctionCleanup(SModeInfo * pInfo) {
|
||||
static void modeFunctionCleanup(SModeInfo* pInfo) {
|
||||
taosHashCleanup(pInfo->pHash);
|
||||
pInfo->pHash = NULL;
|
||||
taosMemoryFreeClear(pInfo->buf);
|
||||
|
@ -5867,7 +5870,7 @@ void modeFunctionCleanupExt(SqlFunctionCtx* pCtx) {
|
|||
modeFunctionCleanup(GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)));
|
||||
}
|
||||
|
||||
static int32_t saveModeTupleData(SqlFunctionCtx* pCtx, char* data, SModeInfo *pInfo, STuplePos* pPos) {
|
||||
static int32_t saveModeTupleData(SqlFunctionCtx* pCtx, char* data, SModeInfo* pInfo, STuplePos* pPos) {
|
||||
if (IS_VAR_DATA_TYPE(pInfo->colType)) {
|
||||
(void)memcpy(pInfo->buf, data, varDataTLen(data));
|
||||
} else {
|
||||
|
@ -5881,10 +5884,10 @@ static int32_t doModeAdd(SModeInfo* pInfo, int32_t rowIndex, SqlFunctionCtx* pCt
|
|||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
int32_t hashKeyBytes = IS_STR_DATA_TYPE(pInfo->colType) ? varDataTLen(data) : pInfo->colBytes;
|
||||
|
||||
SModeItem* pHashItem = (SModeItem *)taosHashGet(pInfo->pHash, data, hashKeyBytes);
|
||||
SModeItem* pHashItem = (SModeItem*)taosHashGet(pInfo->pHash, data, hashKeyBytes);
|
||||
if (pHashItem == NULL) {
|
||||
int32_t size = sizeof(SModeItem);
|
||||
SModeItem item = {0};
|
||||
int32_t size = sizeof(SModeItem);
|
||||
SModeItem item = {0};
|
||||
|
||||
item.count += 1;
|
||||
code = saveModeTupleData(pCtx, data, pInfo, &item.dataPos);
|
||||
|
@ -5968,11 +5971,11 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
STuplePos resDataPos, resTuplePos;
|
||||
int32_t maxCount = 0;
|
||||
int32_t maxCount = 0;
|
||||
|
||||
void *pIter = taosHashIterate(pInfo->pHash, NULL);
|
||||
void* pIter = taosHashIterate(pInfo->pHash, NULL);
|
||||
while (pIter != NULL) {
|
||||
SModeItem *pItem = (SModeItem *)pIter;
|
||||
SModeItem* pItem = (SModeItem*)pIter;
|
||||
if (pItem->count >= maxCount) {
|
||||
maxCount = pItem->count;
|
||||
resDataPos = pItem->dataPos;
|
||||
|
@ -5996,7 +5999,7 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
code = colDataSetVal(pCol, currentRow, pData, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
modeFunctionCleanup(pInfo);
|
||||
return code;
|
||||
return code;
|
||||
}
|
||||
code = setSelectivityValue(pCtx, pBlock, &resTuplePos, currentRow);
|
||||
} else {
|
||||
|
@ -6372,8 +6375,8 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
int32_t len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Total_Blocks=[%d] Total_Size=[%.2f KiB] Average_size=[%.2f KiB] Compression_Ratio=[%.2f %c]",
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, averageSize / 1024.0, compRatio, '%');
|
||||
"Total_Blocks=[%d] Total_Size=[%.2f KiB] Average_size=[%.2f KiB] Compression_Ratio=[%.2f %c]",
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, averageSize / 1024.0, compRatio, '%');
|
||||
|
||||
varDataSetLen(st, len);
|
||||
int32_t code = colDataSetVal(pColInfo, row++, st, false);
|
||||
|
@ -6386,23 +6389,26 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
avgRows = pData->totalRows / pData->numOfBlocks;
|
||||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Block_Rows=[%" PRId64 "] MinRows=[%d] MaxRows=[%d] AvgRows=[%" PRId64 "]",
|
||||
pData->totalRows, pData->minRows, pData->maxRows, avgRows);
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Block_Rows=[%" PRId64 "] MinRows=[%d] MaxRows=[%d] AvgRows=[%" PRId64 "]", pData->totalRows,
|
||||
pData->minRows, pData->maxRows, avgRows);
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Inmem_Rows=[%d] Stt_Rows=[%d] ", pData->numOfInmemRows, pData->numOfSttRows);
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Inmem_Rows=[%d] Stt_Rows=[%d] ",
|
||||
pData->numOfInmemRows, pData->numOfSttRows);
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "Total_Tables=[%d] Total_Filesets=[%d] Total_Vgroups=[%d]", pData->numOfTables,
|
||||
pData->numOfFiles, pData->numOfVgroups);
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Total_Tables=[%d] Total_Filesets=[%d] Total_Vgroups=[%d]", pData->numOfTables, pData->numOfFiles,
|
||||
pData->numOfVgroups);
|
||||
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
|
@ -6411,7 +6417,7 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"--------------------------------------------------------------------------------");
|
||||
"--------------------------------------------------------------------------------");
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -6434,10 +6440,11 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
double factor = pData->numOfBlocks / 80.0;
|
||||
|
||||
int32_t numOfBuckets = sizeof(pData->blockRowsHisto) / sizeof(pData->blockRowsHisto[0]);
|
||||
int32_t bucketRange = ceil(((double) (pData->defMaxRows - pData->defMinRows)) / numOfBuckets);
|
||||
int32_t bucketRange = ceil(((double)(pData->defMaxRows - pData->defMinRows)) / numOfBuckets);
|
||||
|
||||
for (int32_t i = 0; i < tListLen(pData->blockRowsHisto); ++i) {
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "%04d |", pData->defMinRows + bucketRange * (i + 1));
|
||||
len =
|
||||
tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE, "%04d |", pData->defMinRows + bucketRange * (i + 1));
|
||||
|
||||
int32_t num = 0;
|
||||
if (pData->blockRowsHisto[i] > 0) {
|
||||
|
@ -6451,7 +6458,8 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
if (pData->blockRowsHisto[i] > 0) {
|
||||
double v = pData->blockRowsHisto[i] * 100.0 / pData->numOfBlocks;
|
||||
len += tsnprintf(varDataVal(st) + len, sizeof(st) - VARSTR_HEADER_SIZE - len, " %d (%.2f%c)", pData->blockRowsHisto[i], v, '%');
|
||||
len += tsnprintf(varDataVal(st) + len, sizeof(st) - VARSTR_HEADER_SIZE - len, " %d (%.2f%c)",
|
||||
pData->blockRowsHisto[i], v, '%');
|
||||
}
|
||||
|
||||
varDataSetLen(st, len);
|
||||
|
@ -6463,6 +6471,168 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t blockDBUsageSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (pResultInfo->initialized) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != functionSetup(pCtx, pResultInfo)) {
|
||||
return TSDB_CODE_FUNC_SETUP_ERROR;
|
||||
}
|
||||
|
||||
SDBBlockUsageInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
pInfo->minRows = INT32_MAX;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t blockDBUsageFunction(SqlFunctionCtx* pCtx) {
|
||||
const int32_t BLOCK_DISK_USAGE_RESULT_ROWS = 2;
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pInputCol = pInput->pData[0];
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SDBBlockUsageInfo* pDistInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
SDBBlockUsageInfo p1 = {0};
|
||||
if (tDeserializeBlockDbUsage(varDataVal(pInputCol->pData), varDataLen(pInputCol->pData), &p1) < 0) {
|
||||
qError("failed to deserialize block dist info");
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
pDistInfo->numOfBlocks += p1.numOfBlocks;
|
||||
pDistInfo->numOfTables += p1.numOfTables;
|
||||
pDistInfo->numOfInmemRows += p1.numOfInmemRows;
|
||||
pDistInfo->numOfSttRows += p1.numOfSttRows;
|
||||
pDistInfo->totalSize += p1.totalSize;
|
||||
pDistInfo->totalRows += p1.totalRows;
|
||||
pDistInfo->numOfFiles += p1.numOfFiles;
|
||||
|
||||
pDistInfo->defMinRows = p1.defMinRows;
|
||||
pDistInfo->defMaxRows = p1.defMaxRows;
|
||||
pDistInfo->rowSize = p1.rowSize;
|
||||
|
||||
if (pDistInfo->minRows > p1.minRows) {
|
||||
pDistInfo->minRows = p1.minRows;
|
||||
}
|
||||
if (pDistInfo->maxRows < p1.maxRows) {
|
||||
pDistInfo->maxRows = p1.maxRows;
|
||||
}
|
||||
pDistInfo->numOfVgroups += (p1.numOfTables != 0 ? 1 : 0);
|
||||
|
||||
pResInfo->numOfRes = BLOCK_DISK_USAGE_RESULT_ROWS; // default output rows
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tSerializeBlockDbUsage(void* buf, int32_t bufLen, const SDBBlockUsageInfo* pInfo) {
|
||||
SEncoder encoder = {0};
|
||||
int32_t code = 0;
|
||||
int32_t lino;
|
||||
int32_t tlen;
|
||||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
TAOS_CHECK_EXIT(tStartEncode(&encoder));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->rowSize));
|
||||
|
||||
TAOS_CHECK_EXIT(tEncodeU16(&encoder, pInfo->numOfFiles));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfBlocks));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfTables));
|
||||
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalSize));
|
||||
TAOS_CHECK_EXIT(tEncodeU64(&encoder, pInfo->totalRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->maxRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->minRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMaxRows));
|
||||
TAOS_CHECK_EXIT(tEncodeI32(&encoder, pInfo->defMinRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfInmemRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfSttRows));
|
||||
TAOS_CHECK_EXIT(tEncodeU32(&encoder, pInfo->numOfVgroups));
|
||||
|
||||
tEndEncode(&encoder);
|
||||
|
||||
_exit:
|
||||
if (code) {
|
||||
tlen = code;
|
||||
} else {
|
||||
tlen = encoder.pos;
|
||||
}
|
||||
tEncoderClear(&encoder);
|
||||
return tlen;
|
||||
}
|
||||
int32_t tDeserializeBlockDbUsage(void* buf, int32_t bufLen, SDBBlockUsageInfo* pInfo) {
|
||||
SDecoder decoder = {0};
|
||||
int32_t code = 0;
|
||||
int32_t lino;
|
||||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
TAOS_CHECK_EXIT(tStartDecode(&decoder));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->rowSize));
|
||||
|
||||
TAOS_CHECK_EXIT(tDecodeU16(&decoder, &pInfo->numOfFiles));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfBlocks));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfTables));
|
||||
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalSize));
|
||||
TAOS_CHECK_EXIT(tDecodeU64(&decoder, &pInfo->totalRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->maxRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->minRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMaxRows));
|
||||
TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pInfo->defMinRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfInmemRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfSttRows));
|
||||
TAOS_CHECK_EXIT(tDecodeU32(&decoder, &pInfo->numOfVgroups));
|
||||
|
||||
_exit:
|
||||
tDecoderClear(&decoder);
|
||||
return code;
|
||||
}
|
||||
int32_t blockDBUsageFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
SDBBlockUsageInfo* pData = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||
if (NULL == pColInfo) {
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
if (pData->totalRows == 0) {
|
||||
pData->minRows = 0;
|
||||
}
|
||||
|
||||
int32_t row = 0;
|
||||
char st[256] = {0};
|
||||
double averageSize = 0;
|
||||
if (pData->numOfBlocks != 0) {
|
||||
averageSize = ((double)pData->totalSize) / pData->numOfBlocks;
|
||||
}
|
||||
uint64_t totalRawSize = pData->totalRows * pData->rowSize;
|
||||
double compRatio = 0;
|
||||
if (totalRawSize != 0) {
|
||||
compRatio = pData->totalSize * 100 / (double)totalRawSize;
|
||||
}
|
||||
|
||||
int32_t len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Total_Blocks=[%d] Total_Size=[%.2f KiB] Average_size=[%.2f KiB] Compression_Ratio=[%.2f %c]",
|
||||
pData->numOfBlocks, pData->totalSize / 1024.0, averageSize / 1024.0, compRatio, '%');
|
||||
|
||||
varDataSetLen(st, len);
|
||||
int32_t code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
int64_t avgRows = 0;
|
||||
if (pData->numOfBlocks > 0) {
|
||||
avgRows = pData->totalRows / pData->numOfBlocks;
|
||||
}
|
||||
|
||||
len = tsnprintf(varDataVal(st), sizeof(st) - VARSTR_HEADER_SIZE,
|
||||
"Block_Rows=[%" PRId64 "] MinRows=[%d] MaxRows=[%d] AvgRows=[%" PRId64 "]", pData->totalRows,
|
||||
pData->minRows, pData->maxRows, avgRows);
|
||||
varDataSetLen(st, len);
|
||||
code = colDataSetVal(pColInfo, row++, st, false);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
bool getDerivativeFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SDerivInfo);
|
||||
|
@ -6503,7 +6673,7 @@ int32_t derivativeFunction(SqlFunctionCtx* pCtx) {
|
|||
double v = 0;
|
||||
if (pCtx->order == TSDB_ORDER_ASC) {
|
||||
SFuncInputRow row = {0};
|
||||
bool result = false;
|
||||
bool result = false;
|
||||
while (1) {
|
||||
code = funcInputGetNextRow(pCtx, &row, &result);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -6678,7 +6848,7 @@ static void initializeRateInfo(SqlFunctionCtx* pCtx, SRateInfo* pRateInfo, bool
|
|||
} else {
|
||||
pRateInfo->firstPk = NULL;
|
||||
pRateInfo->lastPk = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int32_t irateFunction(SqlFunctionCtx* pCtx) {
|
||||
|
@ -6692,14 +6862,14 @@ int32_t irateFunction(SqlFunctionCtx* pCtx) {
|
|||
SColumnInfoData* pOutput = (SColumnInfoData*)pCtx->pOutput;
|
||||
|
||||
funcInputUpdate(pCtx);
|
||||
|
||||
|
||||
initializeRateInfo(pCtx, pRateInfo, false);
|
||||
|
||||
int32_t numOfElems = 0;
|
||||
int32_t type = pInputCol->info.type;
|
||||
int32_t numOfElems = 0;
|
||||
int32_t type = pInputCol->info.type;
|
||||
SFuncInputRow row = {0};
|
||||
bool result = false;
|
||||
while (1) {
|
||||
while (1) {
|
||||
code = funcInputGetNextRow(pCtx, &row, &result);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
|
@ -6728,19 +6898,18 @@ int32_t irateFunction(SqlFunctionCtx* pCtx) {
|
|||
doSaveRateInfo(pRateInfo, false, row.ts, row.pPk, v);
|
||||
continue;
|
||||
} else if (row.ts == pRateInfo->lastKey) {
|
||||
return TSDB_CODE_FUNC_DUP_TIMESTAMP;
|
||||
return TSDB_CODE_FUNC_DUP_TIMESTAMP;
|
||||
}
|
||||
|
||||
|
||||
if ((INT64_MIN == pRateInfo->firstKey) || row.ts > pRateInfo->firstKey) {
|
||||
doSaveRateInfo(pRateInfo, true, row.ts, row.pPk, v);
|
||||
doSaveRateInfo(pRateInfo, true, row.ts, row.pPk, v);
|
||||
} else if (row.ts == pRateInfo->firstKey) {
|
||||
return TSDB_CODE_FUNC_DUP_TIMESTAMP;
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
|
||||
|
||||
SET_VAL(pResInfo, numOfElems, 1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -6792,8 +6961,9 @@ static void irateCopyInfo(SRateInfo* pInput, SRateInfo* pOutput) {
|
|||
}
|
||||
|
||||
static int32_t irateTransferInfo(SRateInfo* pInput, SRateInfo* pOutput) {
|
||||
if ((pInput->firstKey != INT64_MIN && (pInput->firstKey == pOutput->firstKey || pInput->firstKey == pOutput->lastKey)) ||
|
||||
(pInput->lastKey != INT64_MIN && (pInput->lastKey == pOutput->firstKey || pInput->lastKey == pOutput->lastKey))) {
|
||||
if ((pInput->firstKey != INT64_MIN &&
|
||||
(pInput->firstKey == pOutput->firstKey || pInput->firstKey == pOutput->lastKey)) ||
|
||||
(pInput->lastKey != INT64_MIN && (pInput->lastKey == pOutput->firstKey || pInput->lastKey == pOutput->lastKey))) {
|
||||
return TSDB_CODE_FUNC_DUP_TIMESTAMP;
|
||||
}
|
||||
|
||||
|
@ -6827,8 +6997,8 @@ int32_t irateFunctionMerge(SqlFunctionCtx* pCtx) {
|
|||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
for (int32_t i = start; i < start + pInput->numOfRows; ++i) {
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SRateInfo* pInputInfo = (SRateInfo*)varDataVal(data);
|
||||
char* data = colDataGetData(pCol, i);
|
||||
SRateInfo* pInputInfo = (SRateInfo*)varDataVal(data);
|
||||
initializeRateInfo(pCtx, pInfo, true);
|
||||
if (pInputInfo->hasResult) {
|
||||
int32_t code = irateTransferInfo(pInputInfo, pInfo);
|
||||
|
@ -6860,8 +7030,8 @@ int32_t iratePartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
if (NULL == pCol) {
|
||||
taosMemoryFree(res);
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
taosMemoryFree(res);
|
||||
return TSDB_CODE_OUT_OF_RANGE;
|
||||
}
|
||||
|
||||
int32_t code = colDataSetVal(pCol, pBlock->info.rows, res, false);
|
||||
|
@ -6882,7 +7052,7 @@ int32_t irateFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
|
||||
SRateInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
double result = doCalcRate(pInfo, (double)TSDB_TICK_PER_SECOND(pCtx->param[1].param.i));
|
||||
int32_t code = colDataSetVal(pCol, pBlock->info.rows, (const char*)&result, pResInfo->isNullRes);
|
||||
int32_t code = colDataSetVal(pCol, pBlock->info.rows, (const char*)&result, pResInfo->isNullRes);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -6922,9 +7092,7 @@ _group_value_over:
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
|
||||
return groupConstValueFunction(pCtx);
|
||||
}
|
||||
int32_t groupKeyFunction(SqlFunctionCtx* pCtx) { return groupConstValueFunction(pCtx); }
|
||||
|
||||
int32_t groupConstValueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
|
@ -6953,9 +7121,7 @@ int32_t groupConstValueFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock){
|
||||
return groupConstValueFinalize(pCtx, pBlock);
|
||||
}
|
||||
int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { return groupConstValueFinalize(pCtx, pBlock); }
|
||||
|
||||
int32_t groupKeyCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
||||
SResultRowEntryInfo* pDResInfo = GET_RES_INFO(pDestCtx);
|
||||
|
@ -6977,7 +7143,8 @@ int32_t groupKeyCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
|
|||
|
||||
if (IS_VAR_DATA_TYPE(pSourceCtx->resDataInfo.type)) {
|
||||
(void)memcpy(pDBuf->data, pSBuf->data,
|
||||
(pSourceCtx->resDataInfo.type == TSDB_DATA_TYPE_JSON) ? getJsonValueLen(pSBuf->data) : varDataTLen(pSBuf->data));
|
||||
(pSourceCtx->resDataInfo.type == TSDB_DATA_TYPE_JSON) ? getJsonValueLen(pSBuf->data)
|
||||
: varDataTLen(pSBuf->data));
|
||||
} else {
|
||||
(void)memcpy(pDBuf->data, pSBuf->data, pSourceCtx->resDataInfo.bytes);
|
||||
}
|
||||
|
@ -7004,7 +7171,7 @@ int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx) {
|
|||
|
||||
SColumnInfoData* pkCol = pInput->pPrimaryKey;
|
||||
pInfo->pkType = -1;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
__compar_fn_t pkCompareFn = NULL;
|
||||
if (pCtx->hasPrimaryKey) {
|
||||
pInfo->pkType = pkCol->info.type;
|
||||
pInfo->pkBytes = pkCol->info.bytes;
|
||||
|
|
|
@ -122,7 +122,8 @@ EFuncDataRequired fmFuncDynDataRequired(int32_t funcId, void* pRes, SDataBlockIn
|
|||
|
||||
const char* name = funcMgtBuiltins[funcId].name;
|
||||
if ((strcmp(name, "_group_key") == 0) || (strcmp(name, "_select_value") == 0)) {
|
||||
return FUNC_DATA_REQUIRED_NOT_LOAD;;
|
||||
return FUNC_DATA_REQUIRED_NOT_LOAD;
|
||||
;
|
||||
}
|
||||
|
||||
if (funcMgtBuiltins[funcId].dynDataRequiredFunc == NULL) {
|
||||
|
@ -188,7 +189,6 @@ bool fmIsWindowClauseFunc(int32_t funcId) { return fmIsAggFunc(funcId) || fmIsWi
|
|||
|
||||
bool fmIsIndefiniteRowsFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_INDEFINITE_ROWS_FUNC); }
|
||||
|
||||
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_SPECIAL_DATA_REQUIRED);
|
||||
}
|
||||
|
@ -299,6 +299,13 @@ bool fmIsBlockDistFunc(int32_t funcId) {
|
|||
return FUNCTION_TYPE_BLOCK_DIST == funcMgtBuiltins[funcId].type;
|
||||
}
|
||||
|
||||
bool fmIsDBUsageFunc(int32_t funcId) {
|
||||
if (funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return false;
|
||||
}
|
||||
return FUNCTION_TYPE_DB_USAGE == funcMgtBuiltins[funcId].type;
|
||||
}
|
||||
|
||||
bool fmIsProcessByRowFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PROCESS_BY_ROW); }
|
||||
|
||||
bool fmIsIgnoreNullFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_IGNORE_NULL_FUNC); }
|
||||
|
@ -377,15 +384,11 @@ bool fmIsConstantResFunc(SFunctionNode* pFunc) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool fmIsSkipScanCheckFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_SKIP_SCAN_CHECK_FUNC);
|
||||
}
|
||||
bool fmIsSkipScanCheckFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_SKIP_SCAN_CHECK_FUNC); }
|
||||
|
||||
bool fmIsPrimaryKeyFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_PRIMARY_KEY_FUNC);
|
||||
}
|
||||
bool fmIsPrimaryKeyFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_PRIMARY_KEY_FUNC); }
|
||||
void getLastCacheDataType(SDataType* pType, int32_t pkBytes) {
|
||||
//TODO: do it later.
|
||||
// TODO: do it later.
|
||||
pType->bytes = getFirstLastInfoSize(pType->bytes, pkBytes) + VARSTR_HEADER_SIZE;
|
||||
pType->type = TSDB_DATA_TYPE_BINARY;
|
||||
}
|
||||
|
@ -434,11 +437,11 @@ bool fmIsDistExecFunc(int32_t funcId) {
|
|||
|
||||
static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNode** pPartialFunc) {
|
||||
SNodeList* pParameterList = NULL;
|
||||
int32_t code = nodesCloneList(pSrcFunc->pParameterList, &pParameterList);
|
||||
int32_t code = nodesCloneList(pSrcFunc->pParameterList, &pParameterList);
|
||||
if (NULL == pParameterList) {
|
||||
return code;
|
||||
}
|
||||
code = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pPartialFunc, pParameterList,pPartialFunc );
|
||||
code = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pPartialFunc, pParameterList, pPartialFunc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(pParameterList);
|
||||
return code;
|
||||
|
@ -446,7 +449,7 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod
|
|||
(*pPartialFunc)->hasOriginalFunc = true;
|
||||
(*pPartialFunc)->originalFuncId = pSrcFunc->hasOriginalFunc ? pSrcFunc->originalFuncId : pSrcFunc->funcId;
|
||||
char name[TSDB_FUNC_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_POINTER_PRINT_BYTES + 1] = {0};
|
||||
|
||||
|
||||
int32_t len = tsnprintf(name, sizeof(name), "%s.%p", (*pPartialFunc)->functionName, pSrcFunc);
|
||||
if (taosHashBinary(name, len) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
|
@ -459,7 +462,7 @@ static int32_t createPartialFunction(const SFunctionNode* pSrcFunc, SFunctionNod
|
|||
|
||||
static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||
SNodeList** pParameterList) {
|
||||
SNode *pRes = NULL;
|
||||
SNode* pRes = NULL;
|
||||
int32_t code = createColumnByFunc(pPartialFunc, (SColumnNode**)&pRes);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
|
@ -472,15 +475,15 @@ static int32_t createMergeFuncPara(const SFunctionNode* pSrcFunc, const SFunctio
|
|||
}
|
||||
|
||||
static int32_t createMidFunction(const SFunctionNode* pSrcFunc, const SFunctionNode* pPartialFunc,
|
||||
SFunctionNode** pMidFunc) {
|
||||
SFunctionNode** pMidFunc) {
|
||||
SNodeList* pParameterList = NULL;
|
||||
SFunctionNode* pFunc = NULL;
|
||||
|
||||
int32_t code = createMergeFuncPara(pSrcFunc, pPartialFunc, &pParameterList);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc != NULL){
|
||||
if (funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc != NULL) {
|
||||
code = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMiddleFunc, pParameterList, &pFunc);
|
||||
}else{
|
||||
} else {
|
||||
code = createFunction(funcMgtBuiltins[pSrcFunc->funcId].pMergeFunc, pParameterList, &pFunc);
|
||||
}
|
||||
}
|
||||
|
@ -527,7 +530,8 @@ static int32_t createMergeFunction(const SFunctionNode* pSrcFunc, const SFunctio
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc, SFunctionNode** pMergeFunc) {
|
||||
int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc, SFunctionNode** pMidFunc,
|
||||
SFunctionNode** pMergeFunc) {
|
||||
if (!fmIsDistExecFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -553,7 +557,7 @@ char* fmGetFuncName(int32_t funcId) {
|
|||
if (fmIsUserDefinedFunc(funcId) || funcId < 0 || funcId >= funcMgtBuiltinsNum) {
|
||||
return taosStrdup("invalid function");
|
||||
}
|
||||
return taosStrdup(funcMgtBuiltins[funcId].name);
|
||||
return taosStrdup(funcMgtBuiltins[funcId].name);
|
||||
}
|
||||
|
||||
/// @param [out] pStateFunc, not changed if error occured or no need to create state func
|
||||
|
@ -561,7 +565,7 @@ char* fmGetFuncName(int32_t funcId) {
|
|||
static int32_t fmCreateStateFunc(const SFunctionNode* pFunc, SFunctionNode** pStateFunc) {
|
||||
if (funcMgtBuiltins[pFunc->funcId].pStateFunc) {
|
||||
SNodeList* pParams = NULL;
|
||||
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
||||
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
||||
if (!pParams) return code;
|
||||
code = createFunction(funcMgtBuiltins[pFunc->funcId].pStateFunc, pParams, pStateFunc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -608,7 +612,7 @@ int32_t fmCreateStateFuncs(SNodeList* pFuncs) {
|
|||
static int32_t fmCreateStateMergeFunc(SFunctionNode* pFunc, SFunctionNode** pStateMergeFunc) {
|
||||
if (funcMgtBuiltins[pFunc->funcId].pMergeFunc) {
|
||||
SNodeList* pParams = NULL;
|
||||
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
||||
int32_t code = nodesCloneList(pFunc->pParameterList, &pParams);
|
||||
if (!pParams) return code;
|
||||
code = createFunction(funcMgtBuiltins[pFunc->funcId].pMergeFunc, pParams, pStateMergeFunc);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
|
@ -676,6 +680,4 @@ bool fmIsMyStateFunc(int32_t funcId, int32_t stateFuncId) {
|
|||
return strcmp(pStateFunc->name, pStateMergeFunc->pMergeFunc) == 0;
|
||||
}
|
||||
|
||||
bool fmIsCountLikeFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_COUNT_LIKE_FUNC);
|
||||
}
|
||||
bool fmIsCountLikeFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_COUNT_LIKE_FUNC); }
|
||||
|
|
|
@ -2785,6 +2785,26 @@ static int32_t translateBlockDistFunc(STranslateContext* pCtx, SFunctionNode* pF
|
|||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t translateDBUsageFunc(STranslateContext* pCtx, SFunctionNode* pFunc) {
|
||||
if (!fmIsDBUsageFunc(pFunc->funcId)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (!isSelectStmt(pCtx->pCurrStmt)) {
|
||||
return generateSyntaxErrMsgExt(&pCtx->msgBuf, TSDB_CODE_PAR_ONLY_SUPPORT_SINGLE_TABLE,
|
||||
"%s is only supported in single table query", pFunc->functionName);
|
||||
}
|
||||
SSelectStmt* pSelect = (SSelectStmt*)pCtx->pCurrStmt;
|
||||
SNode* pTable = pSelect->pFromTable;
|
||||
// if (NULL != pTable && (QUERY_NODE_REAL_TABLE != nodeType(pTable) ||
|
||||
// (TSDB_SUPER_TABLE != ((SRealTableNode*)pTable)->pMeta->tableType &&
|
||||
// TSDB_CHILD_TABLE != ((SRealTableNode*)pTable)->pMeta->tableType &&
|
||||
// TSDB_NORMAL_TABLE != ((SRealTableNode*)pTable)->pMeta->tableType))) {
|
||||
// return generateSyntaxErrMsgExt(&pCtx->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||
// "%s is only supported on super table, child table or normal table",
|
||||
// pFunc->functionName);
|
||||
// }
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isStarParam(SNode* pNode) { return nodesIsStar(pNode) || nodesIsTableStar(pNode); }
|
||||
|
||||
|
@ -3139,6 +3159,10 @@ static int32_t translateNormalFunction(STranslateContext* pCxt, SNode** ppNode)
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateBlockDistFunc(pCxt, pFunc);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = translateDBUsageFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
setFuncClassification(pCxt, pFunc);
|
||||
}
|
||||
|
@ -13156,6 +13180,12 @@ static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt)
|
|||
static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) {
|
||||
return createSimpleSelectStmtFromCols(pStmt->dbName, pStmt->tableName, 0, NULL, pOutput);
|
||||
}
|
||||
static int32_t createSelectStmtForShowDBUsage(SShowStmt* pStmt, SSelectStmt** pOutput) {
|
||||
int32_t type = nodeType(pStmt);
|
||||
const SSysTableShowAdapter* pShow = &sysTableShowAdapter[type - SYSTABLE_SHOW_TYPE_OFFSET];
|
||||
return createSimpleSelectStmtFromCols(pShow->pDbName, pShow->pTableName, pShow->numOfShowCols, pShow->pShowCols,
|
||||
pOutput);
|
||||
}
|
||||
|
||||
static int32_t createOperatorNode(EOperatorType opType, const char* pColName, const SNode* pRight, SNode** pOp) {
|
||||
if (NULL == pRight) {
|
||||
|
@ -13687,6 +13717,50 @@ static int32_t rewriteShowTableDist(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createDBUsageFunc(SFunctionNode** ppNode) {
|
||||
SFunctionNode* pFunc = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_FUNCTION, (SNode**)&pFunc);
|
||||
if (NULL == pFunc) {
|
||||
return code;
|
||||
}
|
||||
|
||||
strcpy(pFunc->functionName, "_db_usage");
|
||||
strcpy(pFunc->node.aliasName, "_db_usage");
|
||||
SFunctionNode* pFuncNew = NULL;
|
||||
code = createBlockDistInfoFunc(&pFuncNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListMakeStrictAppend(&pFunc->pParameterList, (SNode*)pFuncNew);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode((SNode*)pFunc);
|
||||
return code;
|
||||
}
|
||||
*ppNode = pFunc;
|
||||
return code;
|
||||
}
|
||||
static int32_t rewriteShowDBUsage(STranslateContext* pCtx, SQuery* pQuery) {
|
||||
SSelectStmt* pStmt = NULL;
|
||||
int32_t code = createSelectStmtForShowDBUsage((SShowStmt*)pQuery->pRoot, &pStmt);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
NODES_DESTORY_LIST(pStmt->pProjectionList);
|
||||
SFunctionNode* pFuncNew = NULL;
|
||||
code = createDBUsageFunc(&pFuncNew);
|
||||
if (TSDB_CODE_SUCCESS == code) code = nodesListMakeStrictAppend(&pStmt->pProjectionList, (SNode*)pFuncNew);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createShowCondition((SShowStmt*)pQuery->pRoot, pStmt);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pCtx->showRewrite = true;
|
||||
pQuery->showRewrite = true;
|
||||
nodesDestroyNode(pQuery->pRoot);
|
||||
pQuery->pRoot = (SNode*)pStmt;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
typedef struct SVgroupCreateTableBatch {
|
||||
SVCreateTbBatchReq req;
|
||||
SVgroupInfo info;
|
||||
|
@ -16061,9 +16135,11 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_SHOW_ARBGROUPS_STMT:
|
||||
case QUERY_NODE_SHOW_ENCRYPTIONS_STMT:
|
||||
case QUERY_NODE_SHOW_TSMAS_STMT:
|
||||
case QUERY_NODE_SHOW_USAGE_STMT:
|
||||
code = rewriteShow(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_USAGE_STMT:
|
||||
code = rewriteShowDBUsage(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_SHOW_TAGS_STMT:
|
||||
code = rewriteShowTags(pCxt, pQuery);
|
||||
break;
|
||||
|
|
|
@ -30,8 +30,7 @@ typedef struct SSlotIndex {
|
|||
SArray* pSlotIdsInfo; // duplicate name slot
|
||||
} SSlotIndex;
|
||||
|
||||
|
||||
static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int32_t *pLen, uint16_t extraBufLen) {
|
||||
static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int32_t* pLen, uint16_t extraBufLen) {
|
||||
int32_t code = 0;
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
|
@ -125,11 +124,10 @@ static int32_t getSlotKey(SNode* pNode, const char* pStmtName, char** ppKey, int
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const char* pName, const SNode* pNode, int16_t slotId,
|
||||
bool output, bool reserve) {
|
||||
SSlotDescNode* pSlot = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_SLOT_DESC, (SNode**)&pSlot);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_SLOT_DESC, (SNode**)&pSlot);
|
||||
if (NULL == pSlot) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
|
@ -144,7 +142,7 @@ static SNode* createSlotDesc(SPhysiPlanContext* pCxt, const char* pName, const S
|
|||
|
||||
static int32_t createTarget(SNode* pNode, int16_t dataBlockId, int16_t slotId, SNode** pOutput) {
|
||||
STargetNode* pTarget = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_TARGET, (SNode**)&pTarget);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_TARGET, (SNode**)&pTarget);
|
||||
if (NULL == pTarget) {
|
||||
return code;
|
||||
}
|
||||
|
@ -178,7 +176,8 @@ static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char
|
|||
return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex));
|
||||
}
|
||||
|
||||
static int32_t putSlotToHash(const char* pName, int32_t len, int16_t dataBlockId, int16_t slotId, SNode* pNode, SHashObj* pHash) {
|
||||
static int32_t putSlotToHash(const char* pName, int32_t len, int16_t dataBlockId, int16_t slotId, SNode* pNode,
|
||||
SHashObj* pHash) {
|
||||
return putSlotToHashImpl(dataBlockId, slotId, pName, len, pHash);
|
||||
}
|
||||
|
||||
|
@ -220,7 +219,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD
|
|||
int16_t slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
char* name = NULL;
|
||||
char* name = NULL;
|
||||
int32_t len = 0;
|
||||
code = getSlotKey(pNode, NULL, &name, &len, 16);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -247,7 +246,7 @@ static int32_t buildDataBlockSlots(SPhysiPlanContext* pCxt, SNodeList* pList, SD
|
|||
|
||||
static int32_t createDataBlockDesc(SPhysiPlanContext* pCxt, SNodeList* pList, SDataBlockDescNode** pDataBlockDesc) {
|
||||
SDataBlockDescNode* pDesc = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC, (SNode**)&pDesc);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_DATABLOCK_DESC, (SNode**)&pDesc);
|
||||
if (NULL == pDesc) {
|
||||
return code;
|
||||
}
|
||||
|
@ -292,15 +291,15 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList,
|
|||
int16_t nextSlotId = LIST_LENGTH(pDataBlockDesc->pSlots), slotId = 0;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pList) {
|
||||
SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode;
|
||||
char *name = NULL;
|
||||
int32_t len = 0;
|
||||
SNode* pExpr = QUERY_NODE_ORDER_BY_EXPR == nodeType(pNode) ? ((SOrderByExprNode*)pNode)->pExpr : pNode;
|
||||
char* name = NULL;
|
||||
int32_t len = 0;
|
||||
code = getSlotKey(pExpr, pStmtName, &name, &len, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SSlotIndex* pIndex = taosHashGet(pHash, name, len);
|
||||
if (NULL == pIndex) {
|
||||
code =
|
||||
nodesListStrictAppend(pDataBlockDesc->pSlots, createSlotDesc(pCxt, name, pExpr, nextSlotId, output, reserve));
|
||||
code = nodesListStrictAppend(pDataBlockDesc->pSlots,
|
||||
createSlotDesc(pCxt, name, pExpr, nextSlotId, output, reserve));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = putSlotToHashImpl(pDataBlockDesc->dataBlockId, nextSlotId, name, len, pHash);
|
||||
}
|
||||
|
@ -315,7 +314,7 @@ static int32_t addDataBlockSlotsImpl(SPhysiPlanContext* pCxt, SNodeList* pList,
|
|||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(name);
|
||||
taosMemoryFree(name);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode* pTarget = NULL;
|
||||
code = createTarget(pNode, pDataBlockDesc->dataBlockId, slotId, &pTarget);
|
||||
|
@ -388,13 +387,13 @@ static void dumpSlots(const char* pName, SHashObj* pHash) {
|
|||
static EDealRes doSetSlotId(SNode* pNode, void* pContext) {
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode) && 0 != strcmp(((SColumnNode*)pNode)->colName, "*")) {
|
||||
SSetSlotIdCxt* pCxt = (SSetSlotIdCxt*)pContext;
|
||||
char *name = NULL;
|
||||
char* name = NULL;
|
||||
int32_t len = 0;
|
||||
pCxt->errCode = getSlotKey(pNode, NULL, &name, &len, 16);
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
SSlotIndex *pIndex = NULL;
|
||||
SSlotIndex* pIndex = NULL;
|
||||
if (((SColumnNode*)pNode)->projRefIdx > 0) {
|
||||
sprintf(name + strlen(name), "_%d", ((SColumnNode*)pNode)->projRefIdx);
|
||||
pIndex = taosHashGet(pCxt->pLeftProjIdxHash, name, strlen(name));
|
||||
|
@ -430,7 +429,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pRes = NULL;
|
||||
SNode* pRes = NULL;
|
||||
int32_t code = nodesCloneNode(pNode, &pRes);
|
||||
if (NULL == pRes) {
|
||||
return code;
|
||||
|
@ -459,7 +458,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
}
|
||||
|
||||
SNodeList* pRes = NULL;
|
||||
int32_t code = nodesCloneList(pList, &pRes);
|
||||
int32_t code = nodesCloneList(pList, &pRes);
|
||||
if (NULL == pRes) {
|
||||
return code;
|
||||
}
|
||||
|
@ -481,7 +480,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
|
|||
|
||||
static SPhysiNode* makePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, ENodeType type) {
|
||||
SPhysiNode* pPhysiNode = NULL;
|
||||
int32_t code = nodesMakeNode(type, (SNode**)&pPhysiNode);
|
||||
int32_t code = nodesMakeNode(type, (SNode**)&pPhysiNode);
|
||||
if (NULL == pPhysiNode) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
|
@ -524,7 +523,7 @@ static int32_t sortScanCols(SNodeList* pScanCols) {
|
|||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SNode* pCol = NULL;
|
||||
SNode* pCol = NULL;
|
||||
FOREACH(pCol, pScanCols) {
|
||||
if (NULL == taosArrayPush(pArray, &pCol)) {
|
||||
code = terrno;
|
||||
|
@ -633,6 +632,7 @@ static ENodeType getScanOperatorType(EScanType scanType) {
|
|||
return QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN;
|
||||
case SCAN_TYPE_TABLE_COUNT:
|
||||
return QUERY_NODE_PHYSICAL_PLAN_TABLE_COUNT_SCAN;
|
||||
case SCAN_TYPE_DB_DISK_USAGE:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -654,7 +654,7 @@ static int32_t createSimpleScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSub
|
|||
}
|
||||
|
||||
static int32_t createTagScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan, SScanLogicNode* pScanLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SPhysiNode** pPhyNode) {
|
||||
STagScanPhysiNode* pScan =
|
||||
(STagScanPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pScanLogicNode, QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN);
|
||||
if (NULL == pScan) {
|
||||
|
@ -677,7 +677,7 @@ static int32_t createLastRowScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSu
|
|||
}
|
||||
pScan->pTargets = NULL;
|
||||
int32_t code = nodesCloneList(pScanLogicNode->node.pTargets, &pScan->pTargets);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode((SNode*)pScan);
|
||||
return code;
|
||||
}
|
||||
|
@ -703,7 +703,7 @@ static int32_t createLastRowScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSu
|
|||
}
|
||||
|
||||
SNode* pTargetNode = NULL;
|
||||
int funcTypeIndex = 0;
|
||||
int funcTypeIndex = 0;
|
||||
FOREACH(pTargetNode, ((SScanPhysiNode*)pScan)->pScanCols) {
|
||||
if (((STargetNode*)pTargetNode)->pExpr->type != QUERY_NODE_COLUMN) {
|
||||
continue;
|
||||
|
@ -713,7 +713,7 @@ static int32_t createLastRowScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSu
|
|||
for (int i = 0; i < TARRAY_SIZE(pScanLogicNode->pFuncTypes); ++i) {
|
||||
SFunctParam* pFunctParam = taosArrayGet(pScanLogicNode->pFuncTypes, i);
|
||||
if (pColNode->colId == pFunctParam->pCol->colId &&
|
||||
0 == strncmp(pColNode->colName, pFunctParam->pCol->name, strlen(pColNode->colName))) {
|
||||
0 == strncmp(pColNode->colName, pFunctParam->pCol->name, strlen(pColNode->colName))) {
|
||||
if (NULL == taosArrayInsert(pScan->pFuncTypes, funcTypeIndex, &pFunctParam->type)) {
|
||||
code = terrno;
|
||||
}
|
||||
|
@ -767,13 +767,13 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
pTableScan->dataRequired = pScanLogicNode->dataRequired;
|
||||
pTableScan->pDynamicScanFuncs = NULL;
|
||||
int32_t code = nodesCloneList(pScanLogicNode->pDynamicScanFuncs, &pTableScan->pDynamicScanFuncs);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode((SNode*)pTableScan);
|
||||
return code;
|
||||
}
|
||||
pTableScan->pGroupTags = NULL;
|
||||
code = nodesCloneList(pScanLogicNode->pGroupTags, &pTableScan->pGroupTags);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode((SNode*)pTableScan);
|
||||
return code;
|
||||
}
|
||||
|
@ -878,22 +878,25 @@ static int32_t createScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubplan,
|
|||
static int32_t getJoinDataBlockDescNode(SNodeList* pChildren, int32_t idx, SDataBlockDescNode** ppDesc) {
|
||||
if (2 == pChildren->length) {
|
||||
*ppDesc = ((SPhysiNode*)nodesListGetNode(pChildren, idx))->pOutputDataBlockDesc;
|
||||
} else if (1 == pChildren->length && nodeType(nodesListGetNode(pChildren, 0)) == QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE) {
|
||||
} else if (1 == pChildren->length &&
|
||||
nodeType(nodesListGetNode(pChildren, 0)) == QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE) {
|
||||
SGroupCachePhysiNode* pGrpCache = (SGroupCachePhysiNode*)nodesListGetNode(pChildren, 0);
|
||||
*ppDesc = ((SPhysiNode*)nodesListGetNode(pGrpCache->node.pChildren, idx))->pOutputDataBlockDesc;
|
||||
} else {
|
||||
planError("Invalid join children num:%d or child type:%d", pChildren->length, nodeType(nodesListGetNode(pChildren, 0)));
|
||||
planError("Invalid join children num:%d or child type:%d", pChildren->length,
|
||||
nodeType(nodesListGetNode(pChildren, 0)));
|
||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t setColEqList(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkId, SNodeList** ppLeft, SNodeList** ppRight) {
|
||||
static int32_t setColEqList(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkId, SNodeList** ppLeft,
|
||||
SNodeList** ppRight) {
|
||||
int32_t code = 0;
|
||||
if (QUERY_NODE_OPERATOR == nodeType(pEqCond) && ((SOperatorNode*)pEqCond)->opType == OP_TYPE_EQUAL) {
|
||||
SOperatorNode* pOp = (SOperatorNode*)pEqCond;
|
||||
SNode* pNew = NULL;
|
||||
SNode* pNew = NULL;
|
||||
if (leftBlkId == ((SColumnNode*)pOp->pLeft)->dataBlockId) {
|
||||
code = nodesCloneNode(pOp->pLeft, &pNew);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -908,7 +911,7 @@ static int32_t setColEqList(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkI
|
|||
planError("invalid col equal list, leftBlockId:%d", ((SColumnNode*)pOp->pLeft)->dataBlockId);
|
||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pNew = NULL;
|
||||
if (leftBlkId == ((SColumnNode*)pOp->pRight)->dataBlockId) {
|
||||
code = nodesCloneNode(pOp->pRight, &pNew);
|
||||
|
@ -925,9 +928,10 @@ static int32_t setColEqList(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkI
|
|||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
} else if (QUERY_NODE_LOGIC_CONDITION == nodeType(pEqCond) && ((SLogicConditionNode*)pEqCond)->condType == LOGIC_COND_TYPE_AND) {
|
||||
} else if (QUERY_NODE_LOGIC_CONDITION == nodeType(pEqCond) &&
|
||||
((SLogicConditionNode*)pEqCond)->condType == LOGIC_COND_TYPE_AND) {
|
||||
SLogicConditionNode* pLogic = (SLogicConditionNode*)pEqCond;
|
||||
SNode* pNode = NULL;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pLogic->pParameterList) {
|
||||
int32_t code = setColEqList(pNode, leftBlkId, rightBlkId, ppLeft, ppRight);
|
||||
if (code) {
|
||||
|
@ -942,7 +946,8 @@ static int32_t setColEqList(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkI
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_t leftBlkId, int16_t rightBlkId, SSortMergeJoinPhysiNode* pJoin) {
|
||||
static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_t leftBlkId, int16_t rightBlkId,
|
||||
SSortMergeJoinPhysiNode* pJoin) {
|
||||
int32_t code = 0;
|
||||
if (QUERY_NODE_OPERATOR == nodeType(pEqCond)) {
|
||||
SOperatorNode* pOp = (SOperatorNode*)pEqCond;
|
||||
|
@ -996,7 +1001,7 @@ static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_
|
|||
planError("invalid primary cond left node type, leftNodeType:%d", nodeType(pOp->pLeft));
|
||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
switch (nodeType(pOp->pRight)) {
|
||||
|
@ -1053,7 +1058,7 @@ static int32_t setMergeJoinPrimColEqCond(SNode* pEqCond, int32_t subType, int16_
|
|||
}
|
||||
|
||||
static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SPhysiNode** pPhyNode) {
|
||||
SSortMergeJoinPhysiNode* pJoin =
|
||||
(SSortMergeJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
|
@ -1066,7 +1071,7 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
|||
pJoin->subType = pJoinLogicNode->subType;
|
||||
pJoin->pWindowOffset = NULL;
|
||||
int32_t code = nodesCloneNode(pJoinLogicNode->pWindowOffset, &pJoin->pWindowOffset);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pJoin->pJLimit = NULL;
|
||||
code = nodesCloneNode(pJoinLogicNode->pJLimit, (SNode**)&pJoin->pJLimit);
|
||||
}
|
||||
|
@ -1083,9 +1088,10 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
|||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pPrimKeyEqCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pPrimKeyEqCond,
|
||||
&pJoin->pPrimKeyCond);
|
||||
&pJoin->pPrimKeyCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setMergeJoinPrimColEqCond(pJoin->pPrimKeyCond, pJoin->subType, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin);
|
||||
code = setMergeJoinPrimColEqCond(pJoin->pPrimKeyCond, pJoin->subType, pLeftDesc->dataBlockId,
|
||||
pRightDesc->dataBlockId, pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->leftPrimExpr) {
|
||||
code = addDataBlockSlot(pCxt, &pJoin->leftPrimExpr, pLeftDesc);
|
||||
|
@ -1098,9 +1104,10 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
|||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->addPrimEqCond) {
|
||||
SNode* pPrimKeyCond = NULL;
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->addPrimEqCond,
|
||||
&pPrimKeyCond);
|
||||
&pPrimKeyCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setMergeJoinPrimColEqCond(pPrimKeyCond, pJoin->subType, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin);
|
||||
code = setMergeJoinPrimColEqCond(pPrimKeyCond, pJoin->subType, pLeftDesc->dataBlockId, pRightDesc->dataBlockId,
|
||||
pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->leftPrimExpr) {
|
||||
code = addDataBlockSlot(pCxt, &pJoin->leftPrimExpr, pLeftDesc);
|
||||
|
@ -1117,42 +1124,44 @@ static int32_t createMergeJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pFullOnCond) {
|
||||
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1,
|
||||
pJoinLogicNode->pFullOnCond, &pJoin->pFullOnCond);
|
||||
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pJoinLogicNode->pFullOnCond,
|
||||
&pJoin->pFullOnCond);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && ((NULL != pJoinLogicNode->pColEqCond) || (NULL != pJoinLogicNode->pTagEqCond))) {
|
||||
code = mergeJoinConds(&pJoinLogicNode->pColEqCond, &pJoinLogicNode->pTagEqCond);
|
||||
}
|
||||
//TODO set from input blocks for group algo
|
||||
/*
|
||||
// TODO set from input blocks for group algo
|
||||
/*
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pColEqCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColEqCond,
|
||||
&pJoin->pColEqCond);
|
||||
}
|
||||
*/
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pColEqCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColEqCond, &pJoin->pColEqCond);
|
||||
}
|
||||
*/
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pColEqCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId,
|
||||
pJoinLogicNode->pColEqCond, &pJoin->pColEqCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setColEqList(pJoin->pColEqCond, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, &pJoin->pEqLeft, &pJoin->pEqRight);
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColEqCond,
|
||||
&pJoin->pColEqCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setColEqList(pJoin->pColEqCond, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, &pJoin->pEqLeft,
|
||||
&pJoin->pEqRight);
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && ((NULL != pJoinLogicNode->pColOnCond) || (NULL != pJoinLogicNode->pTagOnCond))) {
|
||||
code = mergeJoinConds(&pJoinLogicNode->pColOnCond, &pJoinLogicNode->pTagOnCond);
|
||||
}
|
||||
//TODO set from input blocks for group algo
|
||||
/*
|
||||
// TODO set from input blocks for group algo
|
||||
/*
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pColOnCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColOnCond, &pJoin->pColOnCond);
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColOnCond,
|
||||
&pJoin->pColOnCond);
|
||||
}
|
||||
*/
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoinLogicNode->pColOnCond) {
|
||||
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1,
|
||||
pJoinLogicNode->pColOnCond, &pJoin->pColOnCond);
|
||||
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pJoinLogicNode->pColOnCond,
|
||||
&pJoin->pColOnCond);
|
||||
}
|
||||
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
||||
}
|
||||
|
@ -1174,34 +1183,35 @@ static int32_t extractHashJoinOpCols(int16_t lBlkId, int16_t rBlkId, SNode* pEq,
|
|||
int32_t code = 0;
|
||||
if (QUERY_NODE_OPERATOR == nodeType(pEq)) {
|
||||
SOperatorNode* pOp = (SOperatorNode*)pEq;
|
||||
SColumnNode* pLeft = (SColumnNode*)pOp->pLeft;
|
||||
SColumnNode* pRight = (SColumnNode*)pOp->pRight;
|
||||
SColumnNode* pLeft = (SColumnNode*)pOp->pLeft;
|
||||
SColumnNode* pRight = (SColumnNode*)pOp->pRight;
|
||||
if (lBlkId == pLeft->dataBlockId && rBlkId == pRight->dataBlockId) {
|
||||
SNode* pL = NULL, *pR = NULL;
|
||||
SNode *pL = NULL, *pR = NULL;
|
||||
code = nodesCloneNode(pOp->pLeft, &pL);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->pOnLeft, pL);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesCloneNode(pOp->pRight, &pR);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->pOnRight, pR);
|
||||
}
|
||||
} else if (rBlkId == pLeft->dataBlockId && lBlkId == pRight->dataBlockId) {
|
||||
SNode* pL = NULL, *pR = NULL;
|
||||
SNode *pL = NULL, *pR = NULL;
|
||||
code = nodesCloneNode(pOp->pRight, &pR);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->pOnLeft, pR);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesCloneNode(pOp->pLeft, &pL);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesListStrictAppend(pJoin->pOnRight, pL);
|
||||
}
|
||||
} else {
|
||||
planError("Invalid join equal cond, lbid:%d, rbid:%d, oplid:%d, oprid:%d", lBlkId, rBlkId, pLeft->dataBlockId, pRight->dataBlockId);
|
||||
planError("Invalid join equal cond, lbid:%d, rbid:%d, oplid:%d, oprid:%d", lBlkId, rBlkId, pLeft->dataBlockId,
|
||||
pRight->dataBlockId);
|
||||
return TSDB_CODE_PLAN_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
|
@ -1222,7 +1232,7 @@ static int32_t extractHashJoinOnCols(int16_t lBlkId, int16_t rBlkId, SNode* pEq,
|
|||
code = extractHashJoinOpCols(lBlkId, rBlkId, pEq, pJoin);
|
||||
} else if (QUERY_NODE_LOGIC_CONDITION == nodeType(pEq)) {
|
||||
SLogicConditionNode* pLogic = (SLogicConditionNode*)pEq;
|
||||
SNode* pNode = NULL;
|
||||
SNode* pNode = NULL;
|
||||
FOREACH(pNode, pLogic->pParameterList) {
|
||||
code = extractHashJoinOpCols(lBlkId, rBlkId, pNode, pJoin);
|
||||
if (code) {
|
||||
|
@ -1237,16 +1247,17 @@ static int32_t extractHashJoinOnCols(int16_t lBlkId, int16_t rBlkId, SNode* pEq,
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createHashJoinColList(int16_t lBlkId, int16_t rBlkId, SNode* pEq1, SNode* pEq2, SNode* pEq3, SHashJoinPhysiNode* pJoin) {
|
||||
static int32_t createHashJoinColList(int16_t lBlkId, int16_t rBlkId, SNode* pEq1, SNode* pEq2, SNode* pEq3,
|
||||
SHashJoinPhysiNode* pJoin) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
pJoin->pOnLeft = NULL;
|
||||
code = nodesMakeList(&pJoin->pOnLeft);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
pJoin->pOnRight = NULL;
|
||||
code = nodesMakeList(&pJoin->pOnRight);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1266,25 +1277,25 @@ static int32_t createHashJoinColList(int16_t lBlkId, int16_t rBlkId, SNode* pEq1
|
|||
}
|
||||
|
||||
static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhysiNode* pJoin) {
|
||||
SNode* pNode = NULL;
|
||||
SNode* pNode = NULL;
|
||||
SSHashObj* pHash = tSimpleHashInit(pJoin->pTargets->length, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY));
|
||||
if (NULL == pHash) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SNodeList* pNew = NULL;
|
||||
int32_t code = nodesMakeList(&pNew);
|
||||
int32_t code = nodesMakeList(&pNew);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
FOREACH(pNode, pJoin->pTargets) {
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
char *pName = NULL;
|
||||
int32_t len = 0;
|
||||
char* pName = NULL;
|
||||
int32_t len = 0;
|
||||
code = getSlotKey(pNode, NULL, &pName, &len, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tSimpleHashPut(pHash, pName, len, &pCol, POINTER_BYTES);
|
||||
}
|
||||
taosMemoryFree(pName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1294,9 +1305,9 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys
|
|||
pJoin->pTargets = pNew;
|
||||
|
||||
FOREACH(pNode, pJoin->pOnLeft) {
|
||||
char* pName = NULL;
|
||||
char* pName = NULL;
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
int32_t len = 0;
|
||||
int32_t len = 0;
|
||||
code = getSlotKey(pNode, NULL, &pName, &len, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode** p = tSimpleHashGet(pHash, pName, len);
|
||||
|
@ -1315,9 +1326,9 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
FOREACH(pNode, pJoin->pOnRight) {
|
||||
char* pName = NULL;
|
||||
char* pName = NULL;
|
||||
SColumnNode* pCol = (SColumnNode*)pNode;
|
||||
int32_t len = 0;
|
||||
int32_t len = 0;
|
||||
code = getSlotKey(pNode, NULL, &pName, &len, 0);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
SNode** p = tSimpleHashGet(pHash, pName, len);
|
||||
|
@ -1357,8 +1368,8 @@ static int32_t sortHashJoinTargets(int16_t lBlkId, int16_t rBlkId, SHashJoinPhys
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t setHashJoinPrimColEqCond(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkId, SHashJoinPhysiNode* pJoin) {
|
||||
static int32_t setHashJoinPrimColEqCond(SNode* pEqCond, int16_t leftBlkId, int16_t rightBlkId,
|
||||
SHashJoinPhysiNode* pJoin) {
|
||||
int32_t code = 0;
|
||||
if (QUERY_NODE_OPERATOR == nodeType(pEqCond)) {
|
||||
SOperatorNode* pOp = (SOperatorNode*)pEqCond;
|
||||
|
@ -1464,11 +1475,10 @@ static int32_t setHashJoinPrimColEqCond(SNode* pEqCond, int16_t leftBlkId, int16
|
|||
return code;
|
||||
}
|
||||
|
||||
|
||||
static int32_t createHashJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SJoinLogicNode* pJoinLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SPhysiNode** pPhyNode) {
|
||||
SHashJoinPhysiNode* pJoin =
|
||||
(SHashJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN);
|
||||
(SHashJoinPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pJoinLogicNode, QUERY_NODE_PHYSICAL_PLAN_HASH_JOIN);
|
||||
if (NULL == pJoin) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1498,22 +1508,24 @@ static int32_t createHashJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
|
||||
if (NULL != pJoinLogicNode->pPrimKeyEqCond) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pPrimKeyEqCond,
|
||||
&pJoin->pPrimKeyCond);
|
||||
&pJoin->pPrimKeyCond);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setHashJoinPrimColEqCond(pJoin->pPrimKeyCond, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin);
|
||||
code = setHashJoinPrimColEqCond(pJoin->pPrimKeyCond, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->leftPrimExpr) {
|
||||
code = addDataBlockSlot(pCxt, &pJoin->leftPrimExpr, pLeftDesc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pJoin->rightPrimExpr) {
|
||||
code = addDataBlockSlot(pCxt, &pJoin->rightPrimExpr, pRightDesc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColEqCond, &pJoin->pColEqCond);
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pColEqCond,
|
||||
&pJoin->pColEqCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pTagEqCond, &pJoin->pTagEqCond);
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->pTagEqCond,
|
||||
&pJoin->pTagEqCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNodeSlotId(pCxt, pLeftDesc->dataBlockId, -1, pJoinLogicNode->pLeftOnCond, &pJoin->pLeftOnCond);
|
||||
|
@ -1523,19 +1535,22 @@ static int32_t createHashJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == code && ((NULL != pJoinLogicNode->pColOnCond) || (NULL != pJoinLogicNode->pTagOnCond))) {
|
||||
code = mergeJoinConds(&pJoinLogicNode->pColOnCond, &pJoinLogicNode->pTagOnCond);
|
||||
}
|
||||
}
|
||||
SNode* pOnCond = (NULL != pJoinLogicNode->pColOnCond) ? pJoinLogicNode->pColOnCond : pJoinLogicNode->pTagOnCond;
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pOnCond) {
|
||||
code = setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pOnCond, &pJoin->pFullOnCond);
|
||||
code =
|
||||
setNodeSlotId(pCxt, ((SPhysiNode*)pJoin)->pOutputDataBlockDesc->dataBlockId, -1, pOnCond, &pJoin->pFullOnCond);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets, &pJoin->pTargets);
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoinLogicNode->node.pTargets,
|
||||
&pJoin->pTargets);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setConditionsSlotId(pCxt, (const SLogicNode*)pJoinLogicNode, (SPhysiNode*)pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createHashJoinColList(pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin->pPrimKeyCond, pJoin->pColEqCond, pJoin->pTagEqCond, pJoin);
|
||||
code = createHashJoinColList(pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin->pPrimKeyCond,
|
||||
pJoin->pColEqCond, pJoin->pTagEqCond, pJoin);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = sortHashJoinTargets(pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pJoin);
|
||||
|
@ -1568,10 +1583,10 @@ static int32_t createJoinPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
static int32_t createGroupCachePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SGroupCacheLogicNode* pLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
static int32_t createGroupCachePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SGroupCacheLogicNode* pLogicNode, SPhysiNode** pPhyNode) {
|
||||
SGroupCachePhysiNode* pGrpCache =
|
||||
(SGroupCachePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pLogicNode, QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE);
|
||||
(SGroupCachePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pLogicNode, QUERY_NODE_PHYSICAL_PLAN_GROUP_CACHE);
|
||||
if (NULL == pGrpCache) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1582,30 +1597,30 @@ static int32_t createGroupCachePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pCh
|
|||
pGrpCache->batchFetch = pLogicNode->batchFetch;
|
||||
SDataBlockDescNode* pChildDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
/*
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pChildDesc->dataBlockId, -1, pLogicNode->pGroupCols, &pGrpCache->pGroupCols);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pChildDesc->dataBlockId, -1, pLogicNode->pGroupCols, &pGrpCache->pGroupCols);
|
||||
}
|
||||
*/
|
||||
|
||||
*pPhyNode = (SPhysiNode*)pGrpCache;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t updateDynQueryCtrlStbJoinInfo(SPhysiPlanContext* pCxt, SNodeList* pChildren, SDynQueryCtrlLogicNode* pLogicNode,
|
||||
SDynQueryCtrlPhysiNode* pDynCtrl) {
|
||||
static int32_t updateDynQueryCtrlStbJoinInfo(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SDynQueryCtrlLogicNode* pLogicNode, SDynQueryCtrlPhysiNode* pDynCtrl) {
|
||||
SDataBlockDescNode* pPrevDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc;
|
||||
SNodeList* pVgList = NULL;
|
||||
SNodeList* pUidList = NULL;
|
||||
int32_t code = setListSlotId(pCxt, pPrevDesc->dataBlockId, -1, pLogicNode->stbJoin.pVgList, &pVgList);
|
||||
SNodeList* pVgList = NULL;
|
||||
SNodeList* pUidList = NULL;
|
||||
int32_t code = setListSlotId(pCxt, pPrevDesc->dataBlockId, -1, pLogicNode->stbJoin.pVgList, &pVgList);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setListSlotId(pCxt, pPrevDesc->dataBlockId, -1, pLogicNode->stbJoin.pUidList, &pUidList);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
memcpy(pDynCtrl->stbJoin.srcScan, pLogicNode->stbJoin.srcScan, sizeof(pDynCtrl->stbJoin.srcScan));
|
||||
|
||||
SNode* pNode = NULL;
|
||||
SNode* pNode = NULL;
|
||||
int32_t i = 0;
|
||||
FOREACH(pNode, pVgList) {
|
||||
pDynCtrl->stbJoin.vgSlot[i] = ((SColumnNode*)pNode)->slotId;
|
||||
|
@ -1624,11 +1639,11 @@ static int32_t updateDynQueryCtrlStbJoinInfo(SPhysiPlanContext* pCxt, SNodeList*
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t createDynQueryCtrlPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SDynQueryCtrlLogicNode* pLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
static int32_t createDynQueryCtrlPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SDynQueryCtrlLogicNode* pLogicNode, SPhysiNode** pPhyNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SDynQueryCtrlPhysiNode* pDynCtrl =
|
||||
(SDynQueryCtrlPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pLogicNode, QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL);
|
||||
(SDynQueryCtrlPhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pLogicNode, QUERY_NODE_PHYSICAL_PLAN_DYN_QUERY_CTRL);
|
||||
if (NULL == pDynCtrl) {
|
||||
return terrno;
|
||||
}
|
||||
|
@ -1689,7 +1704,7 @@ static EDealRes collectAndRewrite(SRewritePrecalcExprsCxt* pCxt, SNode** pNode)
|
|||
|
||||
static int32_t rewriteValueToOperator(SRewritePrecalcExprsCxt* pCxt, SNode** pNode) {
|
||||
SOperatorNode* pOper = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&pOper);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_OPERATOR, (SNode**)&pOper);
|
||||
if (NULL == pOper) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2351,7 +2366,7 @@ static int32_t createCountWindowPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pC
|
|||
pCount->windowCount = pWindowLogicNode->windowCount;
|
||||
pCount->windowSliding = pWindowLogicNode->windowSliding;
|
||||
|
||||
int32_t code = createWindowPhysiNodeFinalize(pCxt, pChildren, &pCount->window, pWindowLogicNode);
|
||||
int32_t code = createWindowPhysiNodeFinalize(pCxt, pChildren, &pCount->window, pWindowLogicNode);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pCount;
|
||||
} else {
|
||||
|
@ -2515,7 +2530,7 @@ static int32_t createPartitionPhysiNodeImpl(SPhysiPlanContext* pCxt, SNodeList*
|
|||
|
||||
if (pPart->needBlockOutputTsOrder) {
|
||||
SNode* node;
|
||||
bool found = false;
|
||||
bool found = false;
|
||||
FOREACH(node, pPartLogicNode->node.pTargets) {
|
||||
if (nodeType(node) == QUERY_NODE_COLUMN) {
|
||||
SColumnNode* pCol = (SColumnNode*)node;
|
||||
|
@ -2599,7 +2614,7 @@ static int32_t createFillPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == code && LIST_LENGTH(pFillNode->pFillNullExprs) > 0) {
|
||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pFillNode->pFillNullExprs, &pFill->pFillNullExprs);
|
||||
if (TSDB_CODE_SUCCESS == code ) {
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pFill->pFillNullExprs, pFill->node.pOutputDataBlockDesc);
|
||||
}
|
||||
}
|
||||
|
@ -2630,7 +2645,7 @@ static int32_t createFillPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
|||
|
||||
static int32_t createExchangePhysiNodeByMerge(SMergePhysiNode* pMerge, int32_t idx) {
|
||||
SExchangePhysiNode* pExchange = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, (SNode**)&pExchange);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, (SNode**)&pExchange);
|
||||
if (NULL == pExchange) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2649,8 +2664,9 @@ static int32_t createExchangePhysiNodeByMerge(SMergePhysiNode* pMerge, int32_t i
|
|||
return nodesListMakeStrictAppend(&pMerge->node.pChildren, (SNode*)pExchange);
|
||||
}
|
||||
|
||||
static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SMergeLogicNode* pMergeLogicNode, SPhysiNode** pPhyNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren, SMergeLogicNode* pMergeLogicNode,
|
||||
SPhysiNode** pPhyNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SMergePhysiNode* pMerge =
|
||||
(SMergePhysiNode*)makePhysiNode(pCxt, (SLogicNode*)pMergeLogicNode, QUERY_NODE_PHYSICAL_PLAN_MERGE);
|
||||
if (NULL == pMerge) {
|
||||
|
@ -2664,7 +2680,7 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildre
|
|||
} else {
|
||||
pMerge->type = MERGE_TYPE_NON_SORT;
|
||||
}
|
||||
|
||||
|
||||
pMerge->numOfChannels = pMergeLogicNode->numOfChannels;
|
||||
pMerge->srcGroupId = pMergeLogicNode->srcGroupId;
|
||||
pMerge->srcEndGroupId = pMergeLogicNode->srcEndGroupId;
|
||||
|
@ -2703,7 +2719,8 @@ static int32_t createMergePhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildre
|
|||
SDataBlockDescNode* pLeftDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 0))->pOutputDataBlockDesc;
|
||||
SDataBlockDescNode* pRightDesc = ((SPhysiNode*)nodesListGetNode(pChildren, 1))->pOutputDataBlockDesc;
|
||||
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pMergeLogicNode->node.pTargets, &pMerge->pTargets);
|
||||
code = setListSlotId(pCxt, pLeftDesc->dataBlockId, pRightDesc->dataBlockId, pMergeLogicNode->node.pTargets,
|
||||
&pMerge->pTargets);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addDataBlockSlots(pCxt, pMerge->pTargets, pMerge->node.pOutputDataBlockDesc);
|
||||
}
|
||||
|
@ -2761,7 +2778,7 @@ static int32_t doCreatePhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode
|
|||
static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubplan* pSubplan,
|
||||
SPhysiNode** pPhyNode) {
|
||||
SNodeList* pChildren = NULL;
|
||||
int32_t code = nodesMakeList(&pChildren);
|
||||
int32_t code = nodesMakeList(&pChildren);
|
||||
if (NULL == pChildren) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2799,7 +2816,7 @@ static int32_t createPhysiNode(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode,
|
|||
|
||||
static int32_t createDataInserter(SPhysiPlanContext* pCxt, SVgDataBlocks* pBlocks, SDataSinkNode** pSink) {
|
||||
SDataInserterNode* pInserter = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT, (SNode**)&pInserter);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_INSERT, (SNode**)&pInserter);
|
||||
if (NULL == pInserter) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2814,7 +2831,7 @@ static int32_t createDataInserter(SPhysiPlanContext* pCxt, SVgDataBlocks* pBlock
|
|||
|
||||
static int32_t createDataDispatcher(SPhysiPlanContext* pCxt, const SPhysiNode* pRoot, SDataSinkNode** pSink) {
|
||||
SDataDispatcherNode* pDispatcher = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&pDispatcher);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DISPATCH, (SNode**)&pDispatcher);
|
||||
if (NULL == pDispatcher) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2832,7 +2849,7 @@ static int32_t createDataDispatcher(SPhysiPlanContext* pCxt, const SPhysiNode* p
|
|||
|
||||
static int32_t makeSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan** ppSubplan) {
|
||||
SSubplan* pSubplan = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&pSubplan);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_SUBPLAN, (SNode**)&pSubplan);
|
||||
if (NULL == pSubplan) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2860,7 +2877,7 @@ static int32_t buildInsertValuesSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLog
|
|||
static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, SSubplan* pSubplan,
|
||||
SDataSinkNode** pSink) {
|
||||
SQueryInserterNode* pInserter = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT, (SNode**)&pInserter);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_QUERY_INSERT, (SNode**)&pInserter);
|
||||
if (NULL == pInserter) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2876,7 +2893,7 @@ static int32_t createQueryInserter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNod
|
|||
vgroupInfoToNodeAddr(pModify->pVgroupList->vgroups, &pSubplan->execNode);
|
||||
}
|
||||
code = setListSlotId(pCxt, pSubplan->pNode->pOutputDataBlockDesc->dataBlockId, -1, pModify->pInsertCols,
|
||||
&pInserter->pCols);
|
||||
&pInserter->pCols);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pInserter->sink.pInputDataBlockDesc = NULL;
|
||||
code = nodesCloneNode((SNode*)pSubplan->pNode->pOutputDataBlockDesc, (SNode**)&pInserter->sink.pInputDataBlockDesc);
|
||||
|
@ -2914,7 +2931,7 @@ static int32_t buildInsertSubplan(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode
|
|||
static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode* pModify, const SPhysiNode* pRoot,
|
||||
SDataSinkNode** pSink) {
|
||||
SDataDeleterNode* pDeleter = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DELETE, (SNode**)&pDeleter);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_DELETE, (SNode**)&pDeleter);
|
||||
if (NULL == pDeleter) {
|
||||
return code;
|
||||
}
|
||||
|
@ -2926,7 +2943,7 @@ static int32_t createDataDeleter(SPhysiPlanContext* pCxt, SVnodeModifyLogicNode*
|
|||
pDeleter->deleteTimeRange = pModify->deleteTimeRange;
|
||||
|
||||
code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pAffectedRows,
|
||||
&pDeleter->pAffectedRows);
|
||||
&pDeleter->pAffectedRows);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = setNodeSlotId(pCxt, pRoot->pOutputDataBlockDesc->dataBlockId, -1, pModify->pStartTs, &pDeleter->pStartTs);
|
||||
}
|
||||
|
@ -2979,7 +2996,7 @@ static int32_t buildVnodeModifySubplan(SPhysiPlanContext* pCxt, SLogicSubplan* p
|
|||
|
||||
static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SSubplan** pPhysiSubplan) {
|
||||
SSubplan* pSubplan = NULL;
|
||||
int32_t code = makeSubplan(pCxt, pLogicSubplan, &pSubplan);
|
||||
int32_t code = makeSubplan(pCxt, pLogicSubplan, &pSubplan);
|
||||
if (NULL == pSubplan) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3009,7 +3026,7 @@ static int32_t createPhysiSubplan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogic
|
|||
|
||||
static int32_t makeQueryPhysiPlan(SPhysiPlanContext* pCxt, SQueryPlan** ppQueryPlan) {
|
||||
SQueryPlan* pPlan = NULL;
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&pPlan);
|
||||
int32_t code = nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN, (SNode**)&pPlan);
|
||||
if (NULL == pPlan) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3084,7 +3101,7 @@ static int32_t buildPhysiPlan(SPhysiPlanContext* pCxt, SLogicSubplan* pLogicSubp
|
|||
|
||||
static int32_t doCreatePhysiPlan(SPhysiPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryPlan** pPhysiPlan) {
|
||||
SQueryPlan* pPlan = NULL;
|
||||
int32_t code = makeQueryPhysiPlan(pCxt, &pPlan);
|
||||
int32_t code = makeQueryPhysiPlan(pCxt, &pPlan);
|
||||
if (NULL == pPlan) {
|
||||
return code;
|
||||
}
|
||||
|
@ -3139,8 +3156,7 @@ static int32_t setExecNodeList(SPhysiPlanContext* pCxt, SArray* pExecNodeList) {
|
|||
}
|
||||
if (pCxt->hasSysScan || !pCxt->hasScan) {
|
||||
SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0};
|
||||
if (NULL == taosArrayPush(pExecNodeList, &node))
|
||||
code = terrno;
|
||||
if (NULL == taosArrayPush(pExecNodeList, &node)) code = terrno;
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue