TD-13120 SELECT statement data structure definition
This commit is contained in:
parent
61fd05654a
commit
a0a61fa91d
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_FUNCTION_MGT_H_
|
||||
#define _TD_FUNCTION_MGT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
struct SQLFunctionCtx;
|
||||
struct SResultRowEntryInfo;
|
||||
struct STimeWindow;
|
||||
|
||||
typedef struct SFuncExecEnv {
|
||||
int32_t calcMemSize;
|
||||
} SFuncExecEnv;
|
||||
|
||||
typedef void* FuncMgtHandle;
|
||||
typedef bool (*FExecGetEnv)(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
typedef bool (*FExecInit)(struct SQLFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||
typedef void (*FExecProcess)(struct SQLFunctionCtx *pCtx);
|
||||
typedef void (*FExecFinalize)(struct SQLFunctionCtx *pCtx);
|
||||
|
||||
typedef struct SFuncExecFuncs {
|
||||
FExecGetEnv getEnv;
|
||||
FExecInit init;
|
||||
FExecProcess process;
|
||||
FExecFinalize finalize;
|
||||
} SFuncExecFuncs;
|
||||
|
||||
int32_t fmFuncMgtInit();
|
||||
|
||||
int32_t fmGetHandle(FuncMgtHandle* pHandle);
|
||||
|
||||
int32_t fmGetFuncId(FuncMgtHandle handle, const char* name);
|
||||
int32_t fmGetFuncResultType(FuncMgtHandle handle, SFunctionNode* pFunc);
|
||||
bool fmIsAggFunc(int32_t funcId);
|
||||
bool fmIsStringFunc(int32_t funcId);
|
||||
bool fmIsTimestampFunc(int32_t funcId);
|
||||
bool fmIsTimelineFunc(int32_t funcId);
|
||||
bool fmIsTimeorderFunc(int32_t funcId);
|
||||
bool fmIsNonstandardSQLFunc(int32_t funcId);
|
||||
int32_t fmFuncScanType(int32_t funcId);
|
||||
|
||||
int32_t fmGetFuncExecFuncs(FuncMgtHandle handle, int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TD_FUNCTION_MGT_H_
|
|
@ -0,0 +1,271 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_NODES_H_
|
||||
#define _TD_NODES_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "tarray.h"
|
||||
#include "tdef.h"
|
||||
|
||||
typedef enum ENodeType {
|
||||
QUERY_NODE_COLUMN = 1,
|
||||
QUERY_NODE_VALUE,
|
||||
QUERY_NODE_OPERATOR,
|
||||
QUERY_NODE_LOGIC_CONDITION,
|
||||
QUERY_NODE_IS_NULL_CONDITION,
|
||||
QUERY_NODE_FUNCTION,
|
||||
QUERY_NODE_REAL_TABLE,
|
||||
QUERY_NODE_TEMP_TABLE,
|
||||
QUERY_NODE_JOIN_TABLE,
|
||||
QUERY_NODE_GROUPING_SET,
|
||||
QUERY_NODE_ORDER_BY_EXPR,
|
||||
QUERY_NODE_STATE_WINDOW,
|
||||
QUERY_NODE_SESSION_WINDOW,
|
||||
QUERY_NODE_INTERVAL_WINDOW,
|
||||
|
||||
QUERY_NODE_SET_OPERATOR,
|
||||
QUERY_NODE_SELECT_STMT
|
||||
} ENodeType;
|
||||
|
||||
/**
|
||||
* The first field of a node of any type is guaranteed to be the ENodeType.
|
||||
* Hence the type of any node can be gotten by casting it to SNode.
|
||||
*/
|
||||
typedef struct SNode {
|
||||
ENodeType type;
|
||||
} SNode;
|
||||
|
||||
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
|
||||
|
||||
typedef struct SDataType {
|
||||
uint8_t type;
|
||||
uint8_t precision;
|
||||
uint8_t scale;
|
||||
int32_t bytes;
|
||||
} SDataType;
|
||||
|
||||
typedef struct SExprNode {
|
||||
ENodeType nodeType;
|
||||
SDataType resType;
|
||||
char aliasName[TSDB_COL_NAME_LEN];
|
||||
} SExprNode;
|
||||
|
||||
typedef enum EColumnType {
|
||||
COLUMN_TYPE_COLUMN = 1,
|
||||
COLUMN_TYPE_TAG
|
||||
} EColumnType;
|
||||
|
||||
typedef struct SColumnNode {
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
int16_t colId;
|
||||
EColumnType colType; // column or tag
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char colName[TSDB_COL_NAME_LEN];
|
||||
} SColumnNode;
|
||||
|
||||
typedef struct SValueNode {
|
||||
SExprNode type; // QUERY_NODE_VALUE
|
||||
char* literal;
|
||||
} SValueNode;
|
||||
|
||||
typedef enum EOperatorType {
|
||||
// arithmetic operator
|
||||
OP_TYPE_ADD = 1,
|
||||
OP_TYPE_SUB,
|
||||
OP_TYPE_MULTI,
|
||||
OP_TYPE_DIV,
|
||||
OP_TYPE_MOD,
|
||||
|
||||
// comparison operator
|
||||
OP_TYPE_GREATER_THAN,
|
||||
OP_TYPE_GREATER_EQUAL,
|
||||
OP_TYPE_LOWER_THAN,
|
||||
OP_TYPE_LOWER_EQUAL,
|
||||
OP_TYPE_EQUAL,
|
||||
OP_TYPE_NOT_EQUAL,
|
||||
OP_TYPE_IN,
|
||||
OP_TYPE_NOT_IN,
|
||||
OP_TYPE_LIKE,
|
||||
OP_TYPE_NOT_LIKE,
|
||||
OP_TYPE_MATCH,
|
||||
OP_TYPE_NMATCH,
|
||||
|
||||
// json operator
|
||||
OP_TYPE_JSON_GET_VALUE,
|
||||
OP_TYPE_JSON_CONTAINS
|
||||
} EOperatorType;
|
||||
|
||||
typedef struct SOperatorNode {
|
||||
SExprNode type; // QUERY_NODE_OPERATOR
|
||||
EOperatorType opType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
} SOperatorNode;
|
||||
|
||||
typedef enum ELogicConditionType {
|
||||
LOGIC_COND_TYPE_AND,
|
||||
LOGIC_COND_TYPE_OR,
|
||||
LOGIC_COND_TYPE_NOT,
|
||||
} ELogicConditionType;
|
||||
|
||||
typedef struct SLogicConditionNode {
|
||||
ENodeType type; // QUERY_NODE_LOGIC_CONDITION
|
||||
ELogicConditionType condType;
|
||||
SArray* pParameterList;
|
||||
} SLogicConditionNode;
|
||||
|
||||
typedef struct SIsNullCondNode {
|
||||
ENodeType type; // QUERY_NODE_IS_NULL_CONDITION
|
||||
SNode* pExpr;
|
||||
bool isNot;
|
||||
} SIsNullCondNode;
|
||||
|
||||
typedef struct SFunctionNode {
|
||||
SExprNode type; // QUERY_NODE_FUNCTION
|
||||
char functionName[TSDB_FUNC_NAME_LEN];
|
||||
int32_t funcId;
|
||||
SArray* pParameterList; // SNode
|
||||
} SFunctionNode;
|
||||
|
||||
typedef struct STableNode {
|
||||
ENodeType type;
|
||||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAliasName[TSDB_COL_NAME_LEN];
|
||||
} STableNode;
|
||||
|
||||
typedef struct SRealTableNode {
|
||||
STableNode type; // QUERY_NODE_REAL_TABLE
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SRealTableNode;
|
||||
|
||||
typedef struct STempTableNode {
|
||||
STableNode type; // QUERY_NODE_TEMP_TABLE
|
||||
SNode* pSubquery;
|
||||
} STempTableNode;
|
||||
|
||||
typedef enum EJoinType {
|
||||
JOIN_TYPE_INNER = 1
|
||||
} EJoinType;
|
||||
|
||||
typedef struct SJoinTableNode {
|
||||
STableNode type; // QUERY_NODE_JOIN_TABLE
|
||||
EJoinType joinType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
SNode* pOnCond;
|
||||
} SJoinTableNode;
|
||||
|
||||
typedef enum EGroupingSetType {
|
||||
GP_TYPE_NORMAL = 1
|
||||
} EGroupingSetType;
|
||||
|
||||
typedef struct SGroupingSetNode {
|
||||
ENodeType type; // QUERY_NODE_GROUPING_SET
|
||||
EGroupingSetType groupingSetType;
|
||||
SArray* pParameterList;
|
||||
} SGroupingSetNode;
|
||||
|
||||
typedef enum EOrder {
|
||||
ORDER_ASC = 1,
|
||||
ORDER_DESC
|
||||
} EOrder;
|
||||
|
||||
typedef enum ENullOrder {
|
||||
NULL_ORDER_FIRST = 1,
|
||||
NULL_ORDER_LAST
|
||||
} ENullOrder;
|
||||
|
||||
typedef struct SOrderByExprNode {
|
||||
ENodeType type; // QUERY_NODE_ORDER_BY_EXPR
|
||||
SNode* pExpr;
|
||||
EOrder order;
|
||||
ENullOrder nullOrder;
|
||||
} SOrderByExprNode;
|
||||
|
||||
typedef struct SLimitInfo {
|
||||
uint64_t limit;
|
||||
uint64_t offset;
|
||||
} SLimitInfo;
|
||||
|
||||
typedef struct SStateWindowNode {
|
||||
ENodeType type; // QUERY_NODE_STATE_WINDOW
|
||||
SNode* pCol;
|
||||
} SStateWindowNode;
|
||||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
int64_t gap; // gap between two session window(in microseconds)
|
||||
SNode* pCol;
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
ENodeType type; // QUERY_NODE_INTERVAL_WINDOW
|
||||
int64_t interval;
|
||||
int64_t sliding;
|
||||
int64_t offset;
|
||||
} SIntervalWindowNode;
|
||||
|
||||
typedef struct SSelectStmt {
|
||||
ENodeType type; // QUERY_NODE_SELECT_STMT
|
||||
bool isDistinct;
|
||||
SArray* pProjectionList; // SNode
|
||||
SNode* pFromTable;
|
||||
SNode* pWhereCond;
|
||||
SArray* pPartitionByList; // SNode
|
||||
SNode* pWindowClause;
|
||||
SArray* pGroupByList; // SGroupingSetNode
|
||||
SArray* pOrderByList; // SOrderByExprNode
|
||||
SLimitInfo limit;
|
||||
SLimitInfo slimit;
|
||||
} SSelectStmt;
|
||||
|
||||
typedef enum ESetOperatorType {
|
||||
SET_OP_TYPE_UNION_ALL = 1
|
||||
} ESetOperatorType;
|
||||
|
||||
typedef struct SSetOperator {
|
||||
ENodeType type; // QUERY_NODE_SET_OPERATOR
|
||||
ESetOperatorType opType;
|
||||
SNode* pLeft;
|
||||
SNode* pRight;
|
||||
} SSetOperator;
|
||||
|
||||
typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext);
|
||||
|
||||
bool nodeArrayWalker(SArray* pArray, FQueryNodeWalker walker, void* pContext);
|
||||
bool nodeTreeWalker(SNode* pNode, FQueryNodeWalker walker, void* pContext);
|
||||
|
||||
bool stmtWalker(SNode* pNode, FQueryNodeWalker walker, void* pContext);
|
||||
|
||||
bool nodeEqual(const SNode* a, const SNode* b);
|
||||
|
||||
void cloneNode(const SNode* pNode);
|
||||
|
||||
int32_t nodeToString(const SNode* pNode, char** pStr, int32_t* pLen);
|
||||
int32_t stringToNode(const char* pStr, SNode** pNode);
|
||||
|
||||
bool isTimeorderQuery(const SNode* pQuery);
|
||||
bool isTimelineQuery(const SNode* pQuery);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_NODES_H_*/
|
|
@ -3,4 +3,5 @@ add_subdirectory(util)
|
|||
add_subdirectory(common)
|
||||
add_subdirectory(libs)
|
||||
add_subdirectory(client)
|
||||
add_subdirectory(dnode)
|
||||
add_subdirectory(dnode)
|
||||
add_subdirectory(nodes)
|
|
@ -8,5 +8,5 @@ target_include_directories(
|
|||
|
||||
target_link_libraries(
|
||||
function
|
||||
PRIVATE os util common
|
||||
PRIVATE os util common nodes
|
||||
)
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_FUNCTION_MGT_INT_H_
|
||||
#define _TD_FUNCTION_MGT_INT_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "functionMgt.h"
|
||||
|
||||
#define FUNC_MGT_DATA_TYPE_MASK(n) (1 << n)
|
||||
|
||||
#define FUNC_MGT_DATA_TYPE_NULL 0
|
||||
#define FUNC_MGT_DATA_TYPE_BOOL FUNC_MGT_DATA_TYPE_MASK(0)
|
||||
#define FUNC_MGT_DATA_TYPE_TINYINT FUNC_MGT_DATA_TYPE_MASK(1)
|
||||
#define FUNC_MGT_DATA_TYPE_SMALLINT FUNC_MGT_DATA_TYPE_MASK(2)
|
||||
#define FUNC_MGT_DATA_TYPE_INT FUNC_MGT_DATA_TYPE_MASK(3)
|
||||
#define FUNC_MGT_DATA_TYPE_BIGINT FUNC_MGT_DATA_TYPE_MASK(4)
|
||||
#define FUNC_MGT_DATA_TYPE_FLOAT FUNC_MGT_DATA_TYPE_MASK(5)
|
||||
#define FUNC_MGT_DATA_TYPE_DOUBLE FUNC_MGT_DATA_TYPE_MASK(6)
|
||||
#define FUNC_MGT_DATA_TYPE_BINARY FUNC_MGT_DATA_TYPE_MASK(7)
|
||||
#define FUNC_MGT_DATA_TYPE_TIMESTAMP FUNC_MGT_DATA_TYPE_MASK(8)
|
||||
#define FUNC_MGT_DATA_TYPE_NCHAR FUNC_MGT_DATA_TYPE_MASK(9)
|
||||
#define FUNC_MGT_DATA_TYPE_UTINYINT FUNC_MGT_DATA_TYPE_MASK(10)
|
||||
#define FUNC_MGT_DATA_TYPE_USMALLINT FUNC_MGT_DATA_TYPE_MASK(11)
|
||||
#define FUNC_MGT_DATA_TYPE_UINT FUNC_MGT_DATA_TYPE_MASK(12)
|
||||
#define FUNC_MGT_DATA_TYPE_UBIGINT FUNC_MGT_DATA_TYPE_MASK(13)
|
||||
#define FUNC_MGT_DATA_TYPE_VARCHAR FUNC_MGT_DATA_TYPE_MASK(14)
|
||||
#define FUNC_MGT_DATA_TYPE_VARBINARY FUNC_MGT_DATA_TYPE_MASK(15)
|
||||
#define FUNC_MGT_DATA_TYPE_JSON FUNC_MGT_DATA_TYPE_MASK(16)
|
||||
#define FUNC_MGT_DATA_TYPE_DECIMAL FUNC_MGT_DATA_TYPE_MASK(17)
|
||||
#define FUNC_MGT_DATA_TYPE_BLOB FUNC_MGT_DATA_TYPE_MASK(18)
|
||||
|
||||
#define FUNC_MGT_EXACT_NUMERIC_DATA_TYPE \
|
||||
(FUNC_MGT_DATA_TYPE_TINYINT | FUNC_MGT_DATA_TYPE_SMALLINT | FUNC_MGT_DATA_TYPE_INT | FUNC_MGT_DATA_TYPE_BIGINT \
|
||||
| FUNC_MGT_DATA_TYPE_UTINYINT | FUNC_MGT_DATA_TYPE_USMALLINT | FUNC_MGT_DATA_TYPE_UINT | FUNC_MGT_DATA_TYPE_UBIGINT)
|
||||
|
||||
#define FUNC_MGT_APPRO_NUMERIC_DATA_TYPE (FUNC_MGT_DATA_TYPE_FLOAT | FUNC_MGT_DATA_TYPE_DOUBLE)
|
||||
|
||||
#define FUNC_MGT_NUMERIC_DATA_TYPE (FUNC_MGT_EXACT_NUMERIC_DATA_TYPE | FUNC_MGT_APPRO_NUMERIC_DATA_TYPE)
|
||||
|
||||
typedef void* FuncDef;
|
||||
|
||||
typedef struct SFuncElement {
|
||||
FuncDef (*defineFunc)();
|
||||
} SFuncElement;
|
||||
|
||||
extern const SFuncElement gBuiltinFuncs[];
|
||||
|
||||
FuncDef createFuncDef(const char* name, int32_t maxNumOfParams);
|
||||
FuncDef setOneParamSignature(FuncDef def, int64_t resDataType, int64_t paramDataType);
|
||||
FuncDef setTwoParamsSignature(FuncDef def, int64_t resDataType, int64_t p1DataType, int64_t p2DataType);
|
||||
FuncDef setFollowParamSignature(FuncDef def, int64_t paramDataType);
|
||||
FuncDef setFollowParamsSignature(FuncDef def, int64_t p1DataType, int64_t p2DataType, int32_t followNo);
|
||||
|
||||
FuncDef setExecFuncs(FuncDef def, FExecGetEnv getEnv, FExecInit init, FExecProcess process, FExecFinalize finalize);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _TD_FUNCTION_MGT_INT_H_
|
|
@ -95,6 +95,10 @@ static FORCE_INLINE void initResultRowEntry(SResultRowEntryInfo *pResInfo, int32
|
|||
memset(GET_ROWCELL_INTERBUF(pResInfo), 0, bufLen);
|
||||
}
|
||||
|
||||
#include "functionMgtInt.h"
|
||||
|
||||
FuncDef defineCount();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "functionMgtInt.h"
|
||||
#include "taggfunction.h"
|
||||
|
||||
const SFuncElement gBuiltinFuncs[] = {
|
||||
{.defineFunc = defineCount}
|
||||
};
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "functionMgt.h"
|
||||
|
||||
#include "functionMgtInt.h"
|
||||
#include "taos.h"
|
||||
#include "taoserror.h"
|
||||
#include "thash.h"
|
||||
|
||||
typedef struct SFuncMgtService {
|
||||
SHashObj* pFuncNameHashTable;
|
||||
} SFuncMgtService;
|
||||
|
||||
static SFuncMgtService gFunMgtService;
|
||||
|
||||
int32_t fmFuncMgtInit() {
|
||||
gFunMgtService.pFuncNameHashTable = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||
if (NULL == gFunMgtService.pFuncNameHashTable) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
typedef struct SFuncDef {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
int32_t maxNumOfParams;
|
||||
SFuncExecFuncs execFuncs;
|
||||
} SFuncDef ;
|
||||
|
||||
FuncDef createFuncDef(const char* name, int32_t maxNumOfParams) {
|
||||
SFuncDef* pDef = calloc(1, sizeof(SFuncDef));
|
||||
if (NULL == pDef) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(pDef->name, name);
|
||||
pDef->maxNumOfParams = maxNumOfParams;
|
||||
return pDef;
|
||||
}
|
||||
|
||||
FuncDef setOneParamSignature(FuncDef def, int64_t resDataType, int64_t paramDataType) {
|
||||
// todo
|
||||
}
|
||||
|
||||
FuncDef setTwoParamsSignature(FuncDef def, int64_t resDataType, int64_t p1DataType, int64_t p2DataType) {
|
||||
// todo
|
||||
}
|
||||
|
||||
FuncDef setFollowParamSignature(FuncDef def, int64_t paramDataType) {
|
||||
// todo
|
||||
}
|
||||
|
||||
FuncDef setFollowParamsSignature(FuncDef def, int64_t p1DataType, int64_t p2DataType, int32_t followNo) {
|
||||
// todo
|
||||
}
|
||||
|
||||
FuncDef setExecFuncs(FuncDef def, FExecGetEnv getEnv, FExecInit init, FExecProcess process, FExecFinalize finalize) {
|
||||
SFuncDef* pDef = (SFuncDef*)def;
|
||||
pDef->execFuncs.getEnv = getEnv;
|
||||
pDef->execFuncs.init = init;
|
||||
pDef->execFuncs.process = process;
|
||||
pDef->execFuncs.finalize = finalize;
|
||||
return def;
|
||||
}
|
||||
|
||||
int32_t registerFunc(FuncDef func) {
|
||||
|
||||
}
|
|
@ -4835,3 +4835,9 @@ SAggFunctionInfo aggFunc[35] = {{
|
|||
statisRequired,
|
||||
}
|
||||
};
|
||||
|
||||
FuncDef defineCount() {
|
||||
FuncDef def = createFuncDef("count", 1);
|
||||
// todo define signature
|
||||
return setExecFuncs(def, NULL, function_setup, count_function, doFinalizer);
|
||||
}
|
||||
|
|
|
@ -212,7 +212,7 @@ static SQueryPlanNode* doAddTableColumnNode(const SQueryStmtInfo* pQueryInfo, SQ
|
|||
pExpr[i] = p;
|
||||
}
|
||||
|
||||
pNode = createQueryNode(QNODE_PROJECT, "Projection", &pNode, 1, pExpr, numOfCols, NULL);
|
||||
// pNode = createQueryNode(QNODE_PROJECT, "Projection", &pNode, 1, pExpr, numOfCols, NULL);
|
||||
tfree(pExpr);
|
||||
}
|
||||
|
||||
|
|
|
@ -109,6 +109,26 @@ static bool fromPnode(const cJSON* json, const char* name, FFromJson func, void*
|
|||
return func(jObj, *obj);
|
||||
}
|
||||
|
||||
static bool fromPnodeArray(const cJSON* json, const char* name, FFromJson func, SArray** array) {
|
||||
const cJSON* jArray = cJSON_GetObjectItem(json, name);
|
||||
int32_t size = (NULL == jArray ? 0 : cJSON_GetArraySize(jArray));
|
||||
if (size > 0) {
|
||||
*array = taosArrayInit(size, POINTER_BYTES);
|
||||
if (NULL == *array) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
cJSON* jItem = cJSON_GetArrayItem(jArray, i);
|
||||
void* item = calloc(1, getPnodeTypeSize(jItem));
|
||||
if (NULL == item || !func(jItem, item)) {
|
||||
return false;
|
||||
}
|
||||
taosArrayPush(*array, &item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool addTarray(cJSON* json, const char* name, FToJson func, const SArray* array, bool isPoint) {
|
||||
size_t size = (NULL == array) ? 0 : taosArrayGetSize(array);
|
||||
if (size > 0) {
|
||||
|
@ -379,8 +399,8 @@ static const char* jkFunctionChild = "Child";
|
|||
static bool functionToJson(const void* obj, cJSON* jFunc) {
|
||||
const tExprNode* exprInfo = (const tExprNode*)obj;
|
||||
bool res = cJSON_AddStringToObject(jFunc, jkFunctionName, exprInfo->_function.functionName);
|
||||
if (res) {
|
||||
res = addRawArray(jFunc, jkFunctionChild, exprNodeToJson, exprInfo->_function.pChild, sizeof(tExprNode*), exprInfo->_function.num);
|
||||
if (res && NULL != exprInfo->_function.pChild) {
|
||||
res = addRawArray(jFunc, jkFunctionChild, exprNodeToJson, *(exprInfo->_function.pChild), sizeof(tExprNode*), exprInfo->_function.num);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -388,6 +408,10 @@ static bool functionToJson(const void* obj, cJSON* jFunc) {
|
|||
static bool functionFromJson(const cJSON* json, void* obj) {
|
||||
tExprNode* exprInfo = (tExprNode*)obj;
|
||||
copyString(json, jkFunctionName, exprInfo->_function.functionName);
|
||||
exprInfo->_function.pChild = calloc(1, sizeof(tExprNode*));
|
||||
if (NULL == exprInfo->_function.pChild) {
|
||||
return false;
|
||||
}
|
||||
return fromRawArrayWithAlloc(json, jkFunctionChild, exprNodeFromJson, (void**)exprInfo->_function.pChild, sizeof(tExprNode*), &exprInfo->_function.num);
|
||||
}
|
||||
|
||||
|
@ -808,7 +832,7 @@ static bool specificPhyNodeFromJson(const cJSON* json, void* obj) {
|
|||
case OP_SystemTableScan:
|
||||
return scanNodeFromJson(json, obj);
|
||||
case OP_Aggregate:
|
||||
break; // todo
|
||||
return aggNodeFromJson(json, obj);
|
||||
case OP_Project:
|
||||
return true;
|
||||
// case OP_Groupby:
|
||||
|
@ -879,7 +903,7 @@ static bool phyNodeFromJson(const cJSON* json, void* obj) {
|
|||
res = fromObject(json, jkPnodeSchema, dataBlockSchemaFromJson, &node->targetSchema, true);
|
||||
}
|
||||
if (res) {
|
||||
res = fromArray(json, jkPnodeChildren, phyNodeFromJson, &node->pChildren, sizeof(SSlotSchema));
|
||||
res = fromPnodeArray(json, jkPnodeChildren, phyNodeFromJson, &node->pChildren);
|
||||
}
|
||||
if (res) {
|
||||
res = fromObject(json, node->info.name, specificPhyNodeFromJson, node, true);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
aux_source_directory(src NODES_SRC)
|
||||
add_library(nodes STATIC ${NODES_SRC})
|
||||
target_include_directories(
|
||||
nodes
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/nodes"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
nodes
|
||||
PRIVATE os util
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
void cloneNode(const SNode* pNode) {
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
int32_t nodeToString(const SNode* pNode, char** pStr, int32_t* pLen) {
|
||||
|
||||
}
|
||||
|
||||
int32_t stringToNode(const char* pStr, SNode** pNode) {
|
||||
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
#define COMPARE_SCALAR_FIELD(fldname) \
|
||||
do { \
|
||||
if (a->fldname != b->fldname) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_STRING(a, b) \
|
||||
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
|
||||
|
||||
#define COMPARE_STRING_FIELD(fldname) \
|
||||
do { \
|
||||
if (!COMPARE_STRING(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_NODE_FIELD(fldname) \
|
||||
do { \
|
||||
if (!nodeEqual(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
#define COMPARE_ARRAY_FIELD(fldname) \
|
||||
do { \
|
||||
if (!nodeArrayEqual(a->fldname, b->fldname)) \
|
||||
return false; \
|
||||
} while (0)
|
||||
|
||||
static bool nodeArrayEqual(const SArray* a, const SArray* b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NULL == a || NULL == b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(a) != taosArrayGetSize(b)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = taosArrayGetSize(a);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (!nodeEqual((SNode*)taosArrayGetP(a, i), (SNode*)taosArrayGetP(b, i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool columnNodeEqual(const SColumnNode* a, const SColumnNode* b) {
|
||||
COMPARE_STRING_FIELD(dbName);
|
||||
COMPARE_STRING_FIELD(tableName);
|
||||
COMPARE_STRING_FIELD(colName);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool valueNodeEqual(const SValueNode* a, const SValueNode* b) {
|
||||
COMPARE_STRING_FIELD(literal);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool operatorNodeEqual(const SOperatorNode* a, const SOperatorNode* b) {
|
||||
COMPARE_SCALAR_FIELD(opType);
|
||||
COMPARE_NODE_FIELD(pLeft);
|
||||
COMPARE_NODE_FIELD(pRight);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool logicConditionNodeEqual(const SLogicConditionNode* a, const SLogicConditionNode* b) {
|
||||
COMPARE_SCALAR_FIELD(condType);
|
||||
COMPARE_ARRAY_FIELD(pParameterList);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool isNullConditionNodeEqual(const SIsNullCondNode* a, const SIsNullCondNode* b) {
|
||||
COMPARE_NODE_FIELD(pExpr);
|
||||
COMPARE_SCALAR_FIELD(isNot);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool functionNodeEqual(const SFunctionNode* a, const SFunctionNode* b) {
|
||||
COMPARE_SCALAR_FIELD(funcId);
|
||||
COMPARE_ARRAY_FIELD(pParameterList);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nodeEqual(const SNode* a, const SNode* b) {
|
||||
if (a == b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (NULL == a || NULL == b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (nodeType(a) != nodeType(b)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (nodeType(a)) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
return columnNodeEqual((const SColumnNode*)a, (const SColumnNode*)b);
|
||||
case QUERY_NODE_VALUE:
|
||||
return valueNodeEqual((const SValueNode*)a, (const SValueNode*)b);
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return operatorNodeEqual((const SOperatorNode*)a, (const SOperatorNode*)b);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return logicConditionNodeEqual((const SLogicConditionNode*)a, (const SLogicConditionNode*)b);
|
||||
case QUERY_NODE_IS_NULL_CONDITION:
|
||||
return isNullConditionNodeEqual((const SIsNullCondNode*)a, (const SIsNullCondNode*)b);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return functionNodeEqual((const SFunctionNode*)a, (const SFunctionNode*)b);
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
case QUERY_NODE_JOIN_TABLE:
|
||||
case QUERY_NODE_GROUPING_SET:
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return false; // todo
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext);
|
||||
|
||||
bool nodeArrayWalker(SArray* pArray, FQueryNodeWalker walker, void* pContext) {
|
||||
size_t size = taosArrayGetSize(pArray);
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
if (!nodeTreeWalker((SNode*)taosArrayGetP(pArray, i), walker, pContext)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nodeTreeWalker(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
|
||||
if (NULL == pNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!walker(pNode, pContext)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (nodeType(pNode)) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
case QUERY_NODE_VALUE:
|
||||
// these node types with no subnodes
|
||||
return true;
|
||||
case QUERY_NODE_OPERATOR: {
|
||||
SOperatorNode* pOpNode = (SOperatorNode*)pNode;
|
||||
if (!nodeTreeWalker(pOpNode->pLeft, walker, pContext)) {
|
||||
return false;
|
||||
}
|
||||
return nodeTreeWalker(pOpNode->pRight, walker, pContext);
|
||||
}
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return nodeArrayWalker(((SLogicConditionNode*)pNode)->pParameterList, walker, pContext);
|
||||
case QUERY_NODE_IS_NULL_CONDITION:
|
||||
return nodeTreeWalker(((SIsNullCondNode*)pNode)->pExpr, walker, pContext);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return nodeArrayWalker(((SFunctionNode*)pNode)->pParameterList, walker, pContext);
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return true; // todo
|
||||
case QUERY_NODE_JOIN_TABLE: {
|
||||
SJoinTableNode* pJoinTableNode = (SJoinTableNode*)pNode;
|
||||
if (!nodeTreeWalker(pJoinTableNode->pLeft, walker, pContext)) {
|
||||
return false;
|
||||
}
|
||||
if (!nodeTreeWalker(pJoinTableNode->pRight, walker, pContext)) {
|
||||
return false;
|
||||
}
|
||||
return nodeTreeWalker(pJoinTableNode->pOnCond, walker, pContext);
|
||||
}
|
||||
case QUERY_NODE_GROUPING_SET:
|
||||
return nodeArrayWalker(((SGroupingSetNode*)pNode)->pParameterList, walker, pContext);
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return nodeTreeWalker(((SOrderByExprNode*)pNode)->pExpr, walker, pContext);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool stmtWalker(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "nodes.h"
|
||||
|
||||
bool isTimeorderQuery(const SNode* pQuery) {
|
||||
|
||||
}
|
||||
|
||||
bool isTimelineQuery(const SNode* pQuery) {
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
MESSAGE(STATUS "build nodes unit test")
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
ADD_EXECUTABLE(nodesTest ${SOURCE_LIST})
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
nodesTest
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include/nodes/"
|
||||
PRIVATE "${CMAKE_SOURCE_DIR}/source/nodes/inc"
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES(
|
||||
nodesTest
|
||||
PUBLIC os util common nodes gtest
|
||||
)
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(NodesTest, traverseTest) {
|
||||
// todo
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue