Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
45c4099e
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45c4099e
编写于
1月 27, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-13197 SELECT statement syntax definition
上级
09071e70
变更
11
展开全部
隐藏空白更改
内联
并排
Showing
11 changed file
with
1355 addition
and
712 deletion
+1355
-712
include/common/ttokendef.h
include/common/ttokendef.h
+46
-30
include/nodes/nodes.h
include/nodes/nodes.h
+28
-23
source/libs/parser/inc/astCreateContext.h
source/libs/parser/inc/astCreateContext.h
+8
-2
source/libs/parser/inc/astCreateFuncs.h
source/libs/parser/inc/astCreateFuncs.h
+23
-8
source/libs/parser/inc/new_sql.y
source/libs/parser/inc/new_sql.y
+216
-119
source/libs/parser/src/astCreateContext.c
source/libs/parser/src/astCreateContext.c
+38
-10
source/libs/parser/src/astCreateFuncs.c
source/libs/parser/src/astCreateFuncs.c
+167
-27
source/libs/parser/src/new_sql.c
source/libs/parser/src/new_sql.c
+767
-477
source/libs/parser/src/parserImpl.c
source/libs/parser/src/parserImpl.c
+5
-2
source/libs/parser/test/newParserTest.cpp
source/libs/parser/test/newParserTest.cpp
+21
-5
source/nodes/src/nodesUtilFuncs.c
source/nodes/src/nodesUtilFuncs.c
+36
-9
未找到文件。
include/common/ttokendef.h
浏览文件 @
45c4099e
...
...
@@ -207,36 +207,50 @@
#define TK_INTO 189
#define TK_VALUES 190
#define NEW_TK_UNION 1
#define NEW_TK_ALL 2
#define NEW_TK_MINUS 3
#define NEW_TK_EXCEPT 4
#define NEW_TK_INTERSECT 5
#define NEW_TK_NK_PLUS 6
#define NEW_TK_NK_MINUS 7
#define NEW_TK_NK_STAR 8
#define NEW_TK_NK_SLASH 9
#define NEW_TK_SHOW 10
#define NEW_TK_DATABASES 11
#define NEW_TK_NK_ID 12
#define NEW_TK_NK_LP 13
#define NEW_TK_NK_RP 14
#define NEW_TK_NK_COMMA 15
#define NEW_TK_NK_LITERAL 16
#define NEW_TK_NK_DOT 17
#define NEW_TK_SELECT 18
#define NEW_TK_DISTINCT 19
#define NEW_TK_AS 20
#define NEW_TK_FROM 21
#define NEW_TK_WITH 22
#define NEW_TK_RECURSIVE 23
#define NEW_TK_ORDER 24
#define NEW_TK_BY 25
#define NEW_TK_ASC 26
#define NEW_TK_DESC 27
#define NEW_TK_NULLS 28
#define NEW_TK_FIRST 29
#define NEW_TK_LAST 30
#define NEW_TK_OR 1
#define NEW_TK_AND 2
#define NEW_TK_NOT 3
#define NEW_TK_UNION 4
#define NEW_TK_ALL 5
#define NEW_TK_MINUS 6
#define NEW_TK_EXCEPT 7
#define NEW_TK_INTERSECT 8
#define NEW_TK_NK_PLUS 9
#define NEW_TK_NK_MINUS 10
#define NEW_TK_NK_STAR 11
#define NEW_TK_NK_SLASH 12
#define NEW_TK_SHOW 13
#define NEW_TK_DATABASES 14
#define NEW_TK_NK_INTEGER 15
#define NEW_TK_NK_FLOAT 16
#define NEW_TK_NK_STRING 17
#define NEW_TK_NK_BOOL 18
#define NEW_TK_NK_NOW 19
#define NEW_TK_NK_ID 20
#define NEW_TK_NK_QUESTION 21
#define NEW_TK_NK_LP 22
#define NEW_TK_NK_RP 23
#define NEW_TK_NK_DOT 24
#define NEW_TK_FROM 25
#define NEW_TK_NK_COMMA 26
#define NEW_TK_AS 27
#define NEW_TK_JOIN 28
#define NEW_TK_ON 29
#define NEW_TK_INNER 30
#define NEW_TK_SELECT 31
#define NEW_TK_DISTINCT 32
#define NEW_TK_ORDER 33
#define NEW_TK_BY 34
#define NEW_TK_SLIMIT 35
#define NEW_TK_SOFFSET 36
#define NEW_TK_LIMIT 37
#define NEW_TK_OFFSET 38
#define NEW_TK_NK_LR 39
#define NEW_TK_ASC 40
#define NEW_TK_DESC 41
#define NEW_TK_NULLS 42
#define NEW_TK_FIRST 43
#define NEW_TK_LAST 44
#define TK_SPACE 300
#define TK_COMMENT 301
...
...
@@ -247,6 +261,8 @@
#define TK_FILE 306
#define TK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
#define TK_NIL 65535
#endif
include/nodes/nodes.h
浏览文件 @
45c4099e
...
...
@@ -22,6 +22,19 @@ extern "C" {
#include "tdef.h"
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
#define FOREACH(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHead : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
#define FORBOTH(node1, list1, node2, list2) \
for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHead : NULL), *cell2 = (NULL != (list2) ? (list2)->pHead : NULL); \
(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)
typedef
enum
ENodeType
{
QUERY_NODE_COLUMN
=
1
,
QUERY_NODE_VALUE
,
...
...
@@ -52,9 +65,6 @@ typedef struct SNode {
ENodeType
type
;
}
SNode
;
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
typedef
struct
SListCell
{
SNode
*
pNode
;
struct
SListCell
*
pNext
;
...
...
@@ -62,19 +72,10 @@ typedef struct SListCell {
typedef
struct
SNodeList
{
int16_t
length
;
SListCell
*
pHeader
;
SListCell
*
pHead
;
SListCell
*
pTail
;
}
SNodeList
;
#define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
#define FOREACH(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHeader : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
#define FORBOTH(node1, list1, node2, list2) \
for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHeader : NULL), *cell2 = (NULL != (list2) ? (list2)->pHeader : NULL); \
(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)
typedef
struct
SDataType
{
uint8_t
type
;
uint8_t
precision
;
...
...
@@ -252,13 +253,14 @@ typedef struct SSelectStmt {
bool
isStar
;
SNodeList
*
pProjectionList
;
// SNode
SNode
*
pFromTable
;
SNode
*
pWhere
Cond
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
// SNode
SNode
*
pWindow
Clause
;
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SLimitNode
l
imit
;
SLimitNode
s
limit
;
SLimitNode
*
pL
imit
;
SLimitNode
*
pS
limit
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
...
...
@@ -272,10 +274,17 @@ typedef struct SSetOperator {
SNode
*
pRight
;
}
SSetOperator
;
SNode
*
nodesMakeNode
(
ENodeType
type
);
void
nodesDestroyNode
(
SNode
*
pNode
);
SNodeList
*
nodesMakeList
();
SNodeList
*
nodesListAppend
(
SNodeList
*
pList
,
SNode
*
pNode
);
void
nodesDestroyList
(
SNodeList
*
pList
);
typedef
bool
(
*
FQueryNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
bool
nodesWalkNode
(
SNode
*
pNode
,
FQueryNodeWalker
walker
,
void
*
pContext
);
bool
nodesWalk
NodeList
(
SNodeList
*
pNode
List
,
FQueryNodeWalker
walker
,
void
*
pContext
);
bool
nodesWalk
List
(
SNodeList
*
p
List
,
FQueryNodeWalker
walker
,
void
*
pContext
);
bool
nodesWalkStmt
(
SNode
*
pNode
,
FQueryNodeWalker
walker
,
void
*
pContext
);
...
...
@@ -289,10 +298,6 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
SNode
*
nodesMakeNode
(
ENodeType
type
);
void
nodesDestroyNode
(
SNode
*
pNode
);
void
nodesDestroyNodeList
(
SNodeList
*
pList
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/parser/inc/astCreateContext.h
浏览文件 @
45c4099e
...
...
@@ -23,17 +23,23 @@ extern "C" {
#include "nodes.h"
#include "parser.h"
typedef
enum
EResourceType
{
AST_CXT_RESOURCE_NODE
=
1
,
AST_CXT_RESOURCE_NODE_LIST
}
EResourceType
;
typedef
struct
SAstCreateContext
{
SParseContext
*
pQueryCxt
;
bool
notSupport
;
bool
valid
;
SNode
*
pRootNode
;
SHashObj
*
pResourceHash
;
}
SAstCreateContext
;
int32_t
createAstCreateContext
(
const
SParseContext
*
pQueryCxt
,
SAstCreateContext
*
pCxt
);
int32_t
createAstCreateContext
(
SParseContext
*
pQueryCxt
,
SAstCreateContext
*
pCxt
);
int32_t
destroyAstCreateContext
(
SAstCreateContext
*
pCxt
);
void
*
acquireRaii
(
SAstCreateContext
*
pCxt
,
void
*
p
);
void
*
acquireRaii
(
SAstCreateContext
*
pCxt
,
EResourceType
type
,
void
*
p
);
void
*
releaseRaii
(
SAstCreateContext
*
pCxt
,
void
*
p
);
#ifdef __cplusplus
...
...
source/libs/parser/inc/astCreateFuncs.h
浏览文件 @
45c4099e
...
...
@@ -25,20 +25,35 @@
extern
"C"
{
#endif
bool
checkTableName
(
const
SToken
*
pTableName
);
extern
SToken
nil_token
;
SNodeList
*
createNodeList
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
SNodeList
*
addNodeToList
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pList
,
SNode
*
pNode
);
SNode
*
addOrderByList
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pOrderByList
);
SNode
*
addSlimit
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pSlimit
);
SNode
*
addLimit
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pLimit
);
SNode
*
createColumnNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pTableName
,
const
SToken
*
pColumnName
);
SNode
*
createLimitNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLimit
,
const
SToken
*
pOffset
);
SNodeList
*
createNodeList
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
);
SNode
*
addMinusSign
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
const
SToken
*
pAlias
);
SNode
*
createLogicConditionNode
(
SAstCreateContext
*
pCxt
,
ELogicConditionType
type
,
SNode
*
pParam1
,
SNode
*
pParam2
);
SNode
*
createRealTableNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
const
SToken
*
pTableName
,
const
SToken
*
pTableAlias
);
SNode
*
createTempTableNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pSubquery
,
const
SToken
*
pTableAlias
);
SNode
*
createJoinTableNode
(
SAstCreateContext
*
pCxt
,
EJoinType
type
,
SNode
*
pLeft
,
SNode
*
pRight
,
SNode
*
pJoinCond
);
SNode
*
createLimitNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pLimit
,
SNode
*
pOffset
);
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
);
SNode
*
createRealTableNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
const
SToken
*
pTableName
);
SNode
*
addWhereClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pWhere
);
SNode
*
addPartitionByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pPartitionByList
);
SNode
*
addWindowClauseClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pWindow
);
SNode
*
addGroupByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pGroupByList
);
SNode
*
addHavingClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pHaving
);
SNode
*
addOrderByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pOrderByList
);
SNode
*
addSlimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pSlimit
);
SNode
*
addLimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pLimit
);
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
EShowStmtType
type
);
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
const
SToken
*
pAlias
);
#ifdef __cplusplus
}
...
...
source/libs/parser/inc/new_sql.y
浏览文件 @
45c4099e
此差异已折叠。
点击以展开。
source/libs/parser/src/astCreateContext.c
浏览文件 @
45c4099e
...
...
@@ -16,10 +16,46 @@
#include "ttoken.h"
#include "astCreateContext.h"
void
*
acquireRaii
(
SAstCreateContext
*
pCxt
,
void
*
p
)
{
typedef
struct
SResourceEntry
{
EResourceType
type
;
void
*
res
;
}
SResourceEntry
;
int32_t
createAstCreateContext
(
SParseContext
*
pQueryCxt
,
SAstCreateContext
*
pCxt
)
{
pCxt
->
pQueryCxt
=
pQueryCxt
;
pCxt
->
notSupport
=
false
;
pCxt
->
valid
=
true
;
pCxt
->
pRootNode
=
NULL
;
pCxt
->
pResourceHash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
if
(
NULL
==
pCxt
->
pResourceHash
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
destroyAstCreateContext
(
SAstCreateContext
*
pCxt
)
{
SResourceEntry
*
item
=
taosHashIterate
(
pCxt
->
pResourceHash
,
NULL
);
while
(
item
)
{
switch
(
item
->
type
)
{
case
AST_CXT_RESOURCE_NODE
:
nodesDestroyNode
(
item
->
res
);
break
;
case
AST_CXT_RESOURCE_NODE_LIST
:
nodesDestroyList
(
item
->
res
);
break
;
default:
tfree
(
item
->
res
);
}
item
=
taosHashIterate
(
pCxt
->
pResourceHash
,
item
);
}
}
void
*
acquireRaii
(
SAstCreateContext
*
pCxt
,
EResourceType
type
,
void
*
p
)
{
if
(
NULL
==
p
)
{
return
NULL
;
}
SResourceEntry
entry
=
{
.
type
=
type
,
.
res
=
p
};
taosHashPut
(
pCxt
->
pResourceHash
,
&
p
,
POINTER_BYTES
,
&
entry
,
sizeof
(
SResourceEntry
));
return
p
;
}
...
...
@@ -27,14 +63,6 @@ void* releaseRaii(SAstCreateContext* pCxt, void* p) {
if
(
NULL
==
p
)
{
return
NULL
;
}
taosHashRemove
(
pCxt
->
pResourceHash
,
&
p
,
POINTER_BYTES
);
return
p
;
}
int32_t
createAstCreater
(
const
SParseContext
*
pQueryCxt
,
SAstCreateContext
*
pCxt
)
{
}
int32_t
destroyAstCreater
(
SAstCreateContext
*
pCxt
)
{
}
source/libs/parser/src/astCreateFuncs.c
浏览文件 @
45c4099e
...
...
@@ -16,76 +16,216 @@
#include "astCreateFuncs.h"
#include "astCreateContext.h"
#define CHECK_OUT_OF_MEM(p) \
do { \
if (NULL == (p)) { \
pCxt->valid = false; \
return NULL; \
} \
} while (0)
SToken
nil_token
=
{
.
type
=
TK_NIL
,
.
n
=
0
,
.
z
=
NULL
};
static
bool
checkDbName
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
)
{
if
(
NULL
==
pDbName
)
{
return
true
;
}
pCxt
->
valid
=
pDbName
->
n
<
TSDB_DB_NAME_LEN
?
true
:
false
;
return
pCxt
->
valid
;
}
bool
checkTableName
(
const
SToken
*
pTableName
)
{
printf
(
"%p : %d, %d, %s
\n
"
,
pTableName
,
pTableName
->
type
,
pTableName
->
n
,
pTableName
->
z
);
return
pTableName
->
n
<
TSDB_TABLE_NAME_LEN
?
true
:
false
;
static
bool
checkTableName
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pTableName
)
{
if
(
NULL
==
pTableName
)
{
return
true
;
}
pCxt
->
valid
=
pTableName
->
n
<
TSDB_TABLE_NAME_LEN
?
true
:
false
;
return
pCxt
->
valid
;
}
static
bool
checkColumnName
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pColumnName
)
{
if
(
NULL
==
pColumnName
)
{
return
true
;
}
pCxt
->
valid
=
pColumnName
->
n
<
TSDB_COL_NAME_LEN
?
true
:
false
;
return
pCxt
->
valid
;
}
SNodeList
*
createNodeList
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
SNodeList
*
list
=
nodesMakeList
();
CHECK_OUT_OF_MEM
(
list
);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE_LIST
,
nodesListAppend
(
list
,
releaseRaii
(
pCxt
,
pNode
)));
}
SNodeList
*
addNodeToList
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pList
,
SNode
*
pNode
)
{
return
nodesListAppend
(
pList
,
releaseRaii
(
pCxt
,
pNode
));
}
SNode
*
createColumnNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pTableName
,
const
SToken
*
pColumnName
)
{
if
(
!
checkTableName
(
pCxt
,
pTableName
)
||
!
checkColumnName
(
pCxt
,
pColumnName
))
{
return
NULL
;
}
SColumnNode
*
col
=
(
SColumnNode
*
)
nodesMakeNode
(
QUERY_NODE_COLUMN
);
CHECK_OUT_OF_MEM
(
col
);
if
(
NULL
!=
pTableName
)
{
strncpy
(
col
->
tableName
,
pTableName
->
z
,
pTableName
->
n
);
}
strncpy
(
col
->
colName
,
pColumnName
->
z
,
pColumnName
->
n
);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
col
);
}
SNode
*
createValueNode
(
SAstCreateContext
*
pCxt
,
int32_t
dataType
,
const
SToken
*
pLiteral
)
{
SValueNode
*
val
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
CHECK_OUT_OF_MEM
(
val
);
// strncpy(col->colName, pColumnName->z, pColumnName->n);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
val
);
}
SNode
*
addOrderByList
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pOrderByList
)
{
SNode
*
addMinusSign
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
// todo
}
SNode
*
createLogicConditionNode
(
SAstCreateContext
*
pCxt
,
ELogicConditionType
type
,
SNode
*
pParam1
,
SNode
*
pParam2
)
{
SLogicConditionNode
*
cond
=
(
SLogicConditionNode
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_CONDITION
);
CHECK_OUT_OF_MEM
(
cond
);
cond
->
condType
=
type
;
cond
->
pParameterList
=
nodesMakeList
();
nodesListAppend
(
cond
->
pParameterList
,
releaseRaii
(
pCxt
,
pParam1
));
nodesListAppend
(
cond
->
pParameterList
,
releaseRaii
(
pCxt
,
pParam2
));
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
cond
);
}
SNode
*
addSlimit
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pSlimit
)
{
SNode
*
createRealTableNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
const
SToken
*
pTableName
,
const
SToken
*
pTableAlias
)
{
if
(
!
checkDbName
(
pCxt
,
pDbName
)
||
!
checkTableName
(
pCxt
,
pTableName
))
{
return
NULL
;
}
SRealTableNode
*
realTable
=
(
SRealTableNode
*
)
nodesMakeNode
(
QUERY_NODE_REAL_TABLE
);
CHECK_OUT_OF_MEM
(
realTable
);
if
(
NULL
!=
pDbName
)
{
strncpy
(
realTable
->
dbName
,
pDbName
->
z
,
pDbName
->
n
);
}
strncpy
(
realTable
->
table
.
tableName
,
pTableName
->
z
,
pTableName
->
n
);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
realTable
);
}
SNode
*
createTempTableNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pSubquery
,
const
SToken
*
pTableAlias
)
{
STempTableNode
*
tempTable
=
(
STempTableNode
*
)
nodesMakeNode
(
QUERY_NODE_TEMP_TABLE
);
CHECK_OUT_OF_MEM
(
tempTable
);
tempTable
->
pSubquery
=
pSubquery
;
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
tempTable
);
}
SNode
*
addLimit
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pLimit
)
{
SNode
*
createJoinTableNode
(
SAstCreateContext
*
pCxt
,
EJoinType
type
,
SNode
*
pLeft
,
SNode
*
pRight
,
SNode
*
pJoinCond
)
{
SJoinTableNode
*
joinTable
=
(
SJoinTableNode
*
)
nodesMakeNode
(
QUERY_NODE_JOIN_TABLE
);
CHECK_OUT_OF_MEM
(
joinTable
);
joinTable
->
joinType
=
type
;
joinTable
->
pLeft
=
releaseRaii
(
pCxt
,
pLeft
);
joinTable
->
pRight
=
releaseRaii
(
pCxt
,
pRight
);
joinTable
->
pOnCond
=
pJoinCond
;
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
joinTable
);
}
SNode
*
createLimitNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pLimit
,
SNode
*
pOffset
)
{
SLimitNode
*
limitNode
=
(
SLimitNode
*
)
nodesMakeNode
(
QUERY_NODE_LIMIT
);
CHECK_OUT_OF_MEM
(
limitNode
);
// limitNode->limit = limit;
// limitNode->offset = offset;
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
limitNode
);
}
SNode
*
createColumnNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pTableName
,
const
SToken
*
pColumnName
)
{
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
)
{
SOrderByExprNode
*
orderByExpr
=
(
SOrderByExprNode
*
)
nodesMakeNode
(
QUERY_NODE_ORDER_BY_EXPR
);
CHECK_OUT_OF_MEM
(
orderByExpr
);
orderByExpr
->
pExpr
=
releaseRaii
(
pCxt
,
pExpr
);
orderByExpr
->
order
=
order
;
orderByExpr
->
nullOrder
=
nullOrder
;
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
orderByExpr
);
}
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
const
SToken
*
pAlias
)
{
strncpy
(((
SExprNode
*
)
pNode
)
->
aliasName
,
pAlias
->
z
,
pAlias
->
n
);
return
pNode
;
}
SNode
*
createLimitNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pLimit
,
const
SToken
*
pOffset
)
{
SNode
*
addWhereClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pWhere
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pWhere
=
releaseRaii
(
pCxt
,
pWhere
);
}
return
pStmt
;
}
SNode
*
addPartitionByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pPartitionByList
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pPartitionByList
=
releaseRaii
(
pCxt
,
pPartitionByList
);
}
return
pStmt
;
}
SNodeList
*
createNodeList
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
SNode
*
addWindowClauseClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pWindow
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pWindow
=
releaseRaii
(
pCxt
,
pWindow
);
}
return
pStmt
;
}
SNode
*
addGroupByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pGroupByList
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pGroupByList
=
releaseRaii
(
pCxt
,
pGroupByList
);
}
return
pStmt
;
}
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
)
{
SNode
*
addHavingClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pHaving
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pHaving
=
releaseRaii
(
pCxt
,
pHaving
);
}
return
pStmt
;
}
SNode
*
addOrderByClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNodeList
*
pOrderByList
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pOrderByList
=
releaseRaii
(
pCxt
,
pOrderByList
);
}
return
pStmt
;
}
SNode
*
addSlimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pSlimit
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pSlimit
=
releaseRaii
(
pCxt
,
pSlimit
);
}
return
pStmt
;
}
SNode
*
createRealTableNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDbName
,
const
SToken
*
pTableName
)
{
SRealTableNode
*
realTable
=
(
SRealTableNode
*
)
nodesMakeNode
(
QUERY_NODE_REAL_TABLE
);
if
(
NULL
!=
pDbName
)
{
printf
(
"DbName %p : %d, %d, %s
\n
"
,
pDbName
,
pDbName
->
type
,
pDbName
->
n
,
pDbName
->
z
);
strncpy
(
realTable
->
dbName
,
pDbName
->
z
,
pDbName
->
n
);
SNode
*
addLimitClause
(
SAstCreateContext
*
pCxt
,
SNode
*
pStmt
,
SNode
*
pLimit
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
((
SSelectStmt
*
)
pStmt
)
->
pLimit
=
releaseRaii
(
pCxt
,
pLimit
);
}
printf
(
"TableName %p : %d, %d, %s
\n
"
,
pTableName
,
pTableName
->
type
,
pTableName
->
n
,
pTableName
->
z
);
strncpy
(
realTable
->
table
.
tableName
,
pTableName
->
z
,
pTableName
->
n
);
return
acquireRaii
(
pCxt
,
realTable
);
return
pStmt
;
}
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
)
{
SSelectStmt
*
select
=
(
SSelectStmt
*
)
nodesMakeNode
(
QUERY_NODE_SELECT_STMT
);
CHECK_OUT_OF_MEM
(
select
);
select
->
isDistinct
=
isDistinct
;
if
(
NULL
==
pProjectionList
)
{
select
->
isStar
=
true
;
}
select
->
pProjectionList
=
releaseRaii
(
pCxt
,
pProjectionList
);
printf
(
"pTable = %p, name = %s
\n
"
,
pTable
,
((
SRealTableNode
*
)
pTable
)
->
table
.
tableName
);
select
->
pFromTable
=
releaseRaii
(
pCxt
,
pTable
);
return
acquireRaii
(
pCxt
,
select
);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
select
);
}
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
SSetOperator
*
setOp
=
(
SSetOperator
*
)
nodesMakeNode
(
QUERY_NODE_SET_OPERATOR
);
CHECK_OUT_OF_MEM
(
setOp
);
setOp
->
opType
=
type
;
setOp
->
pLeft
=
releaseRaii
(
pCxt
,
pLeft
);
setOp
->
pRight
=
releaseRaii
(
pCxt
,
pRight
);
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
setOp
);
}
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
EShowStmtType
type
)
{
}
SNode
*
setProjectionAlias
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
,
const
SToken
*
pAlias
)
{
SShowStmt
*
show
=
(
SShowStmt
*
)
nodesMakeNode
(
QUERY_NODE_SHOW_STMT
);
CHECK_OUT_OF_MEM
(
show
);
show
->
showType
=
type
;
return
acquireRaii
(
pCxt
,
AST_CXT_RESOURCE_NODE
,
show
);
}
source/libs/parser/src/new_sql.c
浏览文件 @
45c4099e
此差异已折叠。
点击以展开。
source/libs/parser/src/parserImpl.c
浏览文件 @
45c4099e
...
...
@@ -80,7 +80,8 @@ uint32_t getToken(const char* z, uint32_t* tokenId) {
}
int32_t
doParse
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
SAstCreateContext
cxt
=
{
.
pQueryCxt
=
pParseCxt
,
.
valid
=
true
,
.
pRootNode
=
NULL
};
SAstCreateContext
cxt
;
createAstCreateContext
(
pParseCxt
,
&
cxt
);
void
*
pParser
=
NewParseAlloc
(
malloc
);
int32_t
i
=
0
;
while
(
1
)
{
...
...
@@ -93,7 +94,7 @@ int32_t doParse(SParseContext* pParseCxt, SQuery* pQuery) {
printf
(
"input: [%s]
\n
"
,
cxt
.
pQueryCxt
->
pSql
+
i
);
t0
.
n
=
getToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
z
=
(
char
*
)(
cxt
.
pQueryCxt
->
pSql
+
i
);
printf
(
"token
%p : %d %d [%s]
\n
"
,
&
t0
,
t0
.
type
,
t0
.
n
,
t0
.
z
);
printf
(
"token
: %d %d [%s]
\n
"
,
t0
.
type
,
t0
.
n
,
t0
.
z
);
i
+=
t0
.
n
;
switch
(
t0
.
type
)
{
...
...
@@ -130,7 +131,9 @@ int32_t doParse(SParseContext* pParseCxt, SQuery* pQuery) {
}
abort_parse:
printf
(
"doParse completed.
\n
"
);
NewParseFree
(
pParser
,
free
);
destroyAstCreateContext
(
&
cxt
);
pQuery
->
pRoot
=
cxt
.
pRootNode
;
return
cxt
.
valid
?
TSDB_CODE_SUCCESS
:
TSDB_CODE_FAILED
;
}
source/libs/parser/test/newParserTest.cpp
浏览文件 @
45c4099e
...
...
@@ -38,11 +38,11 @@ protected:
}
int32_t
run
(
)
{
bool
run
(
int32_t
expectCode
=
TSDB_CODE_SUCCESS
)
{
int32_t
code
=
doParse
(
&
cxt_
,
&
query_
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
cout
<<
"code:"
<<
tstrerror
(
code
)
<<
", msg:"
<<
errMagBuf_
<<
endl
;
return
code
;
return
(
code
==
expectCode
)
;
}
cout
<<
nodeType
(
query_
.
pRoot
)
<<
endl
;
if
(
NULL
!=
query_
.
pRoot
&&
QUERY_NODE_SELECT_STMT
==
nodeType
(
query_
.
pRoot
))
{
...
...
@@ -76,7 +76,7 @@ protected:
// return code;
// }
// cout << "node tree:\n" << pStr << endl;
return
TSDB_CODE_SUCCESS
;
return
(
code
==
expectCode
)
;
}
private:
...
...
@@ -136,8 +136,24 @@ TEST_F(NewParserTest, selectStar) {
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT * FROM t1"
);
ASSERT_
EQ
(
run
(),
TSDB_CODE_SUCCESS
);
ASSERT_
TRUE
(
run
()
);
bind
(
"SELECT * FROM test.t1"
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
NewParserTest
,
syntaxError
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECTT * FROM t1"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_FAILED
));
bind
(
"SELECT *"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_FAILED
));
bind
(
"SELECT *, * FROM test.t1"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_FAILED
));
bind
(
"SELECT * FROM test.t1 t WHER"
);
ASSERT_TRUE
(
run
(
TSDB_CODE_FAILED
));
}
source/nodes/src/nodesUtilFuncs.c
浏览文件 @
45c4099e
...
...
@@ -15,17 +15,13 @@
#include "nodes.h"
#include "nodesShowStmts.h"
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
}
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
}
#include "taoserror.h"
static
SNode
*
makeNode
(
ENodeType
type
,
size_t
size
)
{
SNode
*
p
=
calloc
(
1
,
size
);
if
(
NULL
==
p
)
{
return
NULL
;
}
setNodeType
(
p
,
type
);
return
p
;
}
...
...
@@ -78,6 +74,37 @@ void nodesDestroyNode(SNode* pNode) {
}
void
nodesDestroyNodeList
(
SNodeList
*
pList
)
{
SNodeList
*
nodesMakeList
()
{
SNodeList
*
p
=
calloc
(
1
,
sizeof
(
SNodeList
));
if
(
NULL
==
p
)
{
return
NULL
;
}
return
p
;
}
SNodeList
*
nodesListAppend
(
SNodeList
*
pList
,
SNode
*
pNode
)
{
if
(
NULL
==
pList
||
NULL
==
pNode
)
{
return
NULL
;
}
SListCell
*
p
=
calloc
(
1
,
sizeof
(
SListCell
));
if
(
NULL
==
p
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
pList
;
}
p
->
pNode
=
pNode
;
pList
->
pTail
->
pNext
=
p
;
pList
->
pTail
=
p
;
return
pList
;
}
void
nodesDestroyList
(
SNodeList
*
pList
)
{
}
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
}
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录