Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
cdd60902
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cdd60902
编写于
2月 10, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-13338 SELECT statement translate code
上级
ae8e556b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
520 addition
and
271 deletion
+520
-271
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-1
include/nodes/nodes.h
include/nodes/nodes.h
+17
-257
include/nodes/querynodes.h
include/nodes/querynodes.h
+280
-0
source/libs/parser/inc/astCreateFuncs.h
source/libs/parser/inc/astCreateFuncs.h
+1
-1
source/libs/parser/inc/parserImpl.h
source/libs/parser/inc/parserImpl.h
+2
-1
source/libs/planner/inc/plannerImpl.h
source/libs/planner/inc/plannerImpl.h
+27
-0
source/libs/planner/src/plannerImpl.c
source/libs/planner/src/plannerImpl.c
+19
-0
source/nodes/src/nodesEqualFuncs.c
source/nodes/src/nodesEqualFuncs.c
+1
-1
source/nodes/src/nodesTraverseFuncs.c
source/nodes/src/nodesTraverseFuncs.c
+134
-8
source/nodes/src/nodesUtilFuncs.c
source/nodes/src/nodesUtilFuncs.c
+1
-1
source/nodes/test/nodesTest.cpp
source/nodes/test/nodesTest.cpp
+37
-1
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
cdd60902
...
...
@@ -20,7 +20,7 @@
extern
"C"
{
#endif
#include "nodes.h"
#include "
query
nodes.h"
typedef
enum
EFunctionType
{
// aggregate function
...
...
include/nodes/nodes.h
浏览文件 @
cdd60902
...
...
@@ -40,7 +40,11 @@ extern "C" {
(NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \
cell1 = cell1->pNext, cell2 = cell2->pNext)
#define FOREACH_FOR_REWRITE(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = &(cell->pNode), true) : (node = NULL, false)); cell = cell->pNext)
typedef
enum
ENodeType
{
// Syntax nodes are used in parser and planner module, and some are also used in executor module, such as COLUMN, VALUE, OPERATOR, FUNCTION and so on.
QUERY_NODE_COLUMN
=
1
,
QUERY_NODE_VALUE
,
QUERY_NODE_OPERATOR
,
...
...
@@ -59,9 +63,10 @@ typedef enum ENodeType {
QUERY_NODE_NODE_LIST
,
QUERY_NODE_FILL
,
//
only for parser
//
Only be used in parser module.
QUERY_NODE_RAW_EXPR
,
// Statement nodes are used in parser and planner module.
QUERY_NODE_SET_OPERATOR
,
QUERY_NODE_SELECT_STMT
,
QUERY_NODE_SHOW_STMT
...
...
@@ -87,248 +92,6 @@ typedef struct SNodeList {
SListCell
*
pTail
;
}
SNodeList
;
typedef
struct
SRawExprNode
{
ENodeType
nodeType
;
char
*
p
;
uint32_t
n
;
SNode
*
pNode
;
}
SRawExprNode
;
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
];
SNodeList
*
pAssociationList
;
}
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
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SNode
*
pProjectRef
;
}
SColumnNode
;
typedef
struct
SValueNode
{
SExprNode
node
;
// QUERY_NODE_VALUE
char
*
literal
;
bool
isDuration
;
union
{
bool
b
;
int64_t
i
;
uint64_t
u
;
double
d
;
char
*
p
;
}
datum
;
}
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
node
;
// 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
;
SNodeList
*
pParameterList
;
}
SLogicConditionNode
;
typedef
struct
SIsNullCondNode
{
ENodeType
type
;
// QUERY_NODE_IS_NULL_CONDITION
SNode
*
pExpr
;
bool
isNull
;
}
SIsNullCondNode
;
typedef
struct
SNodeListNode
{
ENodeType
type
;
// QUERY_NODE_NODE_LIST
SNodeList
*
pNodeList
;
}
SNodeListNode
;
typedef
struct
SFunctionNode
{
SExprNode
node
;
// QUERY_NODE_FUNCTION
char
functionName
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcId
;
int32_t
funcType
;
SNodeList
*
pParameterList
;
}
SFunctionNode
;
typedef
struct
STableNode
{
ENodeType
type
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
}
STableNode
;
struct
STableMeta
;
typedef
struct
SRealTableNode
{
STableNode
table
;
// QUERY_NODE_REAL_TABLE
struct
STableMeta
*
pMeta
;
}
SRealTableNode
;
typedef
struct
STempTableNode
{
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
SNode
*
pSubquery
;
}
STempTableNode
;
typedef
enum
EJoinType
{
JOIN_TYPE_INNER
=
1
}
EJoinType
;
typedef
struct
SJoinTableNode
{
STableNode
table
;
// 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
;
SNodeList
*
pParameterList
;
}
SGroupingSetNode
;
typedef
enum
EOrder
{
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
typedef
enum
ENullOrder
{
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
typedef
struct
SOrderByExprNode
{
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
SNode
*
pExpr
;
EOrder
order
;
ENullOrder
nullOrder
;
}
SOrderByExprNode
;
typedef
struct
SLimitNode
{
ENodeType
type
;
// QUERY_NODE_LIMIT
uint64_t
limit
;
uint64_t
offset
;
}
SLimitNode
;
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
SNode
*
pInterval
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pFill
;
}
SIntervalWindowNode
;
typedef
enum
EFillMode
{
FILL_MODE_NONE
=
1
,
FILL_MODE_VALUE
,
FILL_MODE_PREV
,
FILL_MODE_NULL
,
FILL_MODE_LINEAR
,
FILL_MODE_NEXT
}
EFillMode
;
typedef
struct
SFillNode
{
ENodeType
type
;
// QUERY_NODE_FILL
EFillMode
mode
;
SNode
*
pValues
;
// SNodeListNode
}
SFillNode
;
typedef
struct
SSelectStmt
{
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
bool
isDistinct
;
SNodeList
*
pProjectionList
;
// SNode
SNode
*
pFromTable
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
// SNode
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
SNode
*
pSlimit
;
}
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
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
}
SSetOperator
;
SNode
*
nodesMakeNode
(
ENodeType
type
);
void
nodesDestroyNode
(
SNode
*
pNode
);
...
...
@@ -343,12 +106,18 @@ typedef enum EDealRes {
DEAL_RES_IGNORE_CHILD
,
DEAL_RES_ERROR
,
}
EDealRes
;
typedef
EDealRes
(
*
FQueryNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
void
nodesWalkNode
(
SNode
*
pNode
,
FQueryNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkList
(
SNodeList
*
pList
,
FQueryNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkNodePostOrder
(
SNode
*
pNode
,
FQueryNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkListPostOrder
(
SNodeList
*
pList
,
FQueryNodeWalker
walker
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
void
nodesWalkNode
(
SNode
*
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkList
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkNodePostOrder
(
SNode
*
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkListPostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeRewriter
)(
SNode
**
pNode
,
void
*
pContext
);
void
nodesRewriteNode
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewriteList
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewriteNodePostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewriteListPostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
bool
nodesEqualNode
(
const
SNode
*
a
,
const
SNode
*
b
);
...
...
@@ -357,15 +126,6 @@ void nodesCloneNode(const SNode* pNode);
int32_t
nodesNodeToString
(
const
SNode
*
pNode
,
char
**
pStr
,
int32_t
*
pLen
);
int32_t
nodesStringToNode
(
const
char
*
pStr
,
SNode
**
pNode
);
bool
nodesIsExprNode
(
const
SNode
*
pNode
);
bool
nodesIsArithmeticOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsComparisonOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsJsonOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
#ifdef __cplusplus
}
#endif
...
...
include/nodes/querynodes.h
0 → 100644
浏览文件 @
cdd60902
/*
* 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_QUERY_NODES_H_
#define _TD_QUERY_NODES_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#include "nodes.h"
typedef
struct
SRawExprNode
{
ENodeType
nodeType
;
char
*
p
;
uint32_t
n
;
SNode
*
pNode
;
}
SRawExprNode
;
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
];
SNodeList
*
pAssociationList
;
}
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
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SNode
*
pProjectRef
;
}
SColumnNode
;
typedef
struct
SValueNode
{
SExprNode
node
;
// QUERY_NODE_VALUE
char
*
literal
;
bool
isDuration
;
union
{
bool
b
;
int64_t
i
;
uint64_t
u
;
double
d
;
char
*
p
;
}
datum
;
}
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
node
;
// 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
;
SNodeList
*
pParameterList
;
}
SLogicConditionNode
;
typedef
struct
SIsNullCondNode
{
ENodeType
type
;
// QUERY_NODE_IS_NULL_CONDITION
SNode
*
pExpr
;
bool
isNull
;
}
SIsNullCondNode
;
typedef
struct
SNodeListNode
{
ENodeType
type
;
// QUERY_NODE_NODE_LIST
SNodeList
*
pNodeList
;
}
SNodeListNode
;
typedef
struct
SFunctionNode
{
SExprNode
node
;
// QUERY_NODE_FUNCTION
char
functionName
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcId
;
int32_t
funcType
;
SNodeList
*
pParameterList
;
}
SFunctionNode
;
typedef
struct
STableNode
{
ENodeType
type
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
}
STableNode
;
struct
STableMeta
;
typedef
struct
SRealTableNode
{
STableNode
table
;
// QUERY_NODE_REAL_TABLE
struct
STableMeta
*
pMeta
;
}
SRealTableNode
;
typedef
struct
STempTableNode
{
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
SNode
*
pSubquery
;
}
STempTableNode
;
typedef
enum
EJoinType
{
JOIN_TYPE_INNER
=
1
}
EJoinType
;
typedef
struct
SJoinTableNode
{
STableNode
table
;
// 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
;
SNodeList
*
pParameterList
;
}
SGroupingSetNode
;
typedef
enum
EOrder
{
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
typedef
enum
ENullOrder
{
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
typedef
struct
SOrderByExprNode
{
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
SNode
*
pExpr
;
EOrder
order
;
ENullOrder
nullOrder
;
}
SOrderByExprNode
;
typedef
struct
SLimitNode
{
ENodeType
type
;
// QUERY_NODE_LIMIT
uint64_t
limit
;
uint64_t
offset
;
}
SLimitNode
;
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
SNode
*
pInterval
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pFill
;
}
SIntervalWindowNode
;
typedef
enum
EFillMode
{
FILL_MODE_NONE
=
1
,
FILL_MODE_VALUE
,
FILL_MODE_PREV
,
FILL_MODE_NULL
,
FILL_MODE_LINEAR
,
FILL_MODE_NEXT
}
EFillMode
;
typedef
struct
SFillNode
{
ENodeType
type
;
// QUERY_NODE_FILL
EFillMode
mode
;
SNode
*
pValues
;
// SNodeListNode
}
SFillNode
;
typedef
struct
SSelectStmt
{
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
bool
isDistinct
;
SNodeList
*
pProjectionList
;
// SNode
SNode
*
pFromTable
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
// SNode
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
SNode
*
pSlimit
;
}
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
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
}
SSetOperator
;
bool
nodesIsExprNode
(
const
SNode
*
pNode
);
bool
nodesIsArithmeticOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsComparisonOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsJsonOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
#ifdef __cplusplus
}
#endif
#endif
/*_TD_QUERY_NODES_H_*/
\ No newline at end of file
source/libs/parser/inc/astCreateFuncs.h
浏览文件 @
cdd60902
...
...
@@ -20,7 +20,7 @@
extern
"C"
{
#endif
#include "nodes.h"
#include "
query
nodes.h"
#include "nodesShowStmts.h"
#include "astCreateContext.h"
#include "ttoken.h"
...
...
source/libs/parser/inc/parserImpl.h
浏览文件 @
cdd60902
...
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nodes.h"
#include "
query
nodes.h"
#include "parser.h"
#ifndef _TD_AST_CREATE_FUNCS_H_
...
...
@@ -25,6 +25,7 @@ extern "C" {
typedef
struct
SQuery
{
SNode
*
pRoot
;
// todo reslut meta
}
SQuery
;
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
...
...
source/libs/planner/inc/plannerImpl.h
0 → 100644
浏览文件 @
cdd60902
/*
* 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_PLANNER_IMPL_H_
#define _TD_PLANNER_IMPL_H_
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef __cplusplus
}
#endif
#endif
/*_TD_PLANNER_IMPL_H_*/
source/libs/planner/src/plannerImpl.c
0 → 100644
浏览文件 @
cdd60902
/*
* 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/>.
*/
int32_t
getPlan
(
SNode
*
pRoot
,
SQueryPlanNode
**
pQueryPlan
)
{
}
\ No newline at end of file
source/nodes/src/nodesEqualFuncs.c
浏览文件 @
cdd60902
...
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nodes.h"
#include "
query
nodes.h"
#define COMPARE_SCALAR_FIELD(fldname) \
do { \
...
...
source/nodes/src/nodesTraverseFuncs.c
浏览文件 @
cdd60902
...
...
@@ -13,16 +13,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nodes.h"
#include "
query
nodes.h"
typedef
enum
ETraversalOrder
{
TRAVERSAL_PREORDER
=
1
,
TRAVERSAL_POSTORDER
}
ETraversalOrder
;
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
F
Query
NodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkNode
(
SNode
*
pNode
,
ETraversalOrder
order
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
static
EDealRes
walkNode
(
SNode
*
pNode
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
if
(
NULL
==
pNode
)
{
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -119,7 +119,7 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FQueryNodeWalker w
return
res
;
}
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
static
EDealRes
walkList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
SNode
*
node
;
FOREACH
(
node
,
pNodeList
)
{
if
(
DEAL_RES_ERROR
==
walkNode
(
node
,
order
,
walker
,
pContext
))
{
...
...
@@ -129,18 +129,144 @@ static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FQueryNode
return
DEAL_RES_CONTINUE
;
}
void
nodesWalkNode
(
SNode
*
pNode
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalkNode
(
SNode
*
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkNode
(
pNode
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
}
void
nodesWalkList
(
SNodeList
*
pNodeList
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalkList
(
SNodeList
*
pNodeList
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkList
(
pNodeList
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
}
void
nodesWalkNodePostOrder
(
SNode
*
pNode
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalkNodePostOrder
(
SNode
*
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkNode
(
pNode
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
}
void
nodesWalkListPostOrder
(
SNodeList
*
pList
,
F
Query
NodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalkListPostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkList
(
pList
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
}
static
EDealRes
rewriteList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeRewriter
rewriter
,
void
*
pContext
);
static
EDealRes
rewriteNode
(
SNode
**
pRawNode
,
ETraversalOrder
order
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
if
(
NULL
==
pRawNode
||
NULL
==
*
pRawNode
)
{
return
DEAL_RES_CONTINUE
;
}
EDealRes
res
=
DEAL_RES_CONTINUE
;
if
(
TRAVERSAL_PREORDER
==
order
)
{
res
=
rewriter
(
pRawNode
,
pContext
);
if
(
DEAL_RES_CONTINUE
!=
res
)
{
return
res
;
}
}
SNode
*
pNode
=
*
pRawNode
;
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_COLUMN
:
case
QUERY_NODE_VALUE
:
case
QUERY_NODE_LIMIT
:
// these node types with no subnodes
break
;
case
QUERY_NODE_OPERATOR
:
{
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pOpNode
->
pLeft
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pOpNode
->
pRight
),
order
,
rewriter
,
pContext
);
}
break
;
}
case
QUERY_NODE_LOGIC_CONDITION
:
res
=
rewriteList
(((
SLogicConditionNode
*
)
pNode
)
->
pParameterList
,
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_IS_NULL_CONDITION
:
res
=
rewriteNode
(
&
(((
SIsNullCondNode
*
)
pNode
)
->
pExpr
),
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_FUNCTION
:
res
=
rewriteList
(((
SFunctionNode
*
)
pNode
)
->
pParameterList
,
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
break
;
// todo
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pRight
),
order
,
rewriter
,
pContext
);
}
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pJoinTableNode
->
pOnCond
),
order
,
rewriter
,
pContext
);
}
break
;
}
case
QUERY_NODE_GROUPING_SET
:
res
=
rewriteList
(((
SGroupingSetNode
*
)
pNode
)
->
pParameterList
,
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_ORDER_BY_EXPR
:
res
=
rewriteNode
(
&
(((
SOrderByExprNode
*
)
pNode
)
->
pExpr
),
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_STATE_WINDOW
:
res
=
rewriteNode
(
&
(((
SStateWindowNode
*
)
pNode
)
->
pCol
),
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_SESSION_WINDOW
:
res
=
rewriteNode
(
&
(((
SSessionWindowNode
*
)
pNode
)
->
pCol
),
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_INTERVAL_WINDOW
:
{
SIntervalWindowNode
*
pInterval
=
(
SIntervalWindowNode
*
)
pNode
;
res
=
rewriteNode
(
&
(
pInterval
->
pInterval
),
order
,
rewriter
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pOffset
),
order
,
rewriter
,
pContext
);
}
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pSliding
),
order
,
rewriter
,
pContext
);
}
if
(
DEAL_RES_ERROR
!=
res
)
{
res
=
rewriteNode
(
&
(
pInterval
->
pFill
),
order
,
rewriter
,
pContext
);
}
break
;
}
case
QUERY_NODE_NODE_LIST
:
res
=
rewriteList
(((
SNodeListNode
*
)
pNode
)
->
pNodeList
,
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_FILL
:
res
=
rewriteNode
(
&
(((
SFillNode
*
)
pNode
)
->
pValues
),
order
,
rewriter
,
pContext
);
break
;
case
QUERY_NODE_RAW_EXPR
:
res
=
rewriteNode
(
&
(((
SRawExprNode
*
)
pNode
)
->
pNode
),
order
,
rewriter
,
pContext
);
break
;
default:
break
;
}
if
(
DEAL_RES_ERROR
!=
res
&&
TRAVERSAL_POSTORDER
==
order
)
{
res
=
rewriter
(
pRawNode
,
pContext
);
}
return
res
;
}
static
EDealRes
rewriteList
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
SNode
**
pNode
;
FOREACH_FOR_REWRITE
(
pNode
,
pNodeList
)
{
if
(
DEAL_RES_ERROR
==
rewriteNode
(
pNode
,
order
,
rewriter
,
pContext
))
{
return
DEAL_RES_ERROR
;
}
}
return
DEAL_RES_CONTINUE
;
}
void
nodesRewriteNode
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
}
void
nodesRewriteList
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteList
(
pList
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
}
void
nodesRewriteNodePostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
}
void
nodesRewriteListPostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteList
(
pList
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
}
source/nodes/src/nodesUtilFuncs.c
浏览文件 @
cdd60902
...
...
@@ -13,7 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "nodes.h"
#include "
query
nodes.h"
#include "nodesShowStmts.h"
#include "taoserror.h"
...
...
source/nodes/test/nodesTest.cpp
浏览文件 @
cdd60902
...
...
@@ -15,8 +15,44 @@
#include <gtest/gtest.h>
#include "querynodes.h"
using
namespace
std
;
static
EDealRes
rewriterTest
(
SNode
**
pNode
,
void
*
pContext
)
{
EDealRes
*
pRes
=
(
EDealRes
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)(
*
pNode
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
))
{
*
pRes
=
DEAL_RES_ERROR
;
}
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
string
tmp
=
to_string
(
stoi
(((
SValueNode
*
)(
pOp
->
pLeft
))
->
literal
)
+
stoi
(((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
));
pVal
->
literal
=
strdup
(
tmp
.
c_str
());
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pVal
;
}
return
DEAL_RES_CONTINUE
;
}
TEST
(
NodesTest
,
traverseTest
)
{
// todo
SNode
*
pRoot
=
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)
pRoot
;
SOperatorNode
*
pLeft
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
pLeft
->
pLeft
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pLeft
))
->
literal
=
strdup
(
"10"
);
pLeft
->
pRight
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pRight
))
->
literal
=
strdup
(
"5"
);
pOp
->
pLeft
=
(
SNode
*
)
pLeft
;
pOp
->
pRight
=
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
=
strdup
(
"3"
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
nodesRewriteNodePostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录