Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
469cd23f
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看板
提交
469cd23f
编写于
4月 02, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
integrate constant calculate
上级
ba5503da
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
234 addition
and
110 deletion
+234
-110
include/libs/nodes/nodes.h
include/libs/nodes/nodes.h
+8
-8
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-1
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+1
-24
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+6
-0
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+24
-24
source/libs/nodes/test/nodesTest.cpp
source/libs/nodes/test/nodesTest.cpp
+1
-1
source/libs/parser/CMakeLists.txt
source/libs/parser/CMakeLists.txt
+1
-1
source/libs/parser/inc/parInt.h
source/libs/parser/inc/parInt.h
+3
-2
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+18
-18
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+1
-1
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+128
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+16
-15
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+5
-2
source/libs/parser/test/parserAstTest.cpp
source/libs/parser/test/parserAstTest.cpp
+2
-2
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+2
-2
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+3
-3
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+7
-0
source/libs/scalar/src/filter.c
source/libs/scalar/src/filter.c
+4
-4
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+2
-2
未找到文件。
include/libs/nodes/nodes.h
浏览文件 @
469cd23f
...
@@ -213,16 +213,16 @@ typedef enum EDealRes {
...
@@ -213,16 +213,16 @@ typedef enum EDealRes {
}
EDealRes
;
}
EDealRes
;
typedef
EDealRes
(
*
FNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeWalker
)(
SNode
*
pNode
,
void
*
pContext
);
void
nodesWalk
Node
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
Expr
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
List
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
Exprs
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
Node
PostOrder
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
Expr
PostOrder
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
List
PostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalk
Exprs
PostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeRewriter
)(
SNode
**
pNode
,
void
*
pContext
);
typedef
EDealRes
(
*
FNodeRewriter
)(
SNode
**
pNode
,
void
*
pContext
);
void
nodesRewrite
Node
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
Expr
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
List
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
Exprs
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
Node
PostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
Expr
PostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
List
PostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
void
nodesRewrite
Exprs
PostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
);
bool
nodesEqualNode
(
const
SNodeptr
a
,
const
SNodeptr
b
);
bool
nodesEqualNode
(
const
SNodeptr
a
,
const
SNodeptr
b
);
...
...
include/libs/nodes/querynodes.h
浏览文件 @
469cd23f
...
@@ -79,6 +79,7 @@ typedef struct SValueNode {
...
@@ -79,6 +79,7 @@ typedef struct SValueNode {
char
*
literal
;
char
*
literal
;
bool
isDuration
;
bool
isDuration
;
bool
translate
;
bool
translate
;
bool
genByCalc
;
union
{
union
{
bool
b
;
bool
b
;
int64_t
i
;
int64_t
i
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
469cd23f
...
@@ -5801,7 +5801,7 @@ void getDBNameFromCondition(SNode* pCondition, char* dbName) {
...
@@ -5801,7 +5801,7 @@ void getDBNameFromCondition(SNode* pCondition, char* dbName) {
return
;
return
;
}
}
nodesWalk
Node
(
pCondition
,
getDBNameFromConditionWalker
,
dbName
);
nodesWalk
Expr
(
pCondition
,
getDBNameFromConditionWalker
,
dbName
);
}
}
static
SSDataBlock
*
doSysTableScan
(
SOperatorInfo
*
pOperator
,
bool
*
newgroup
)
{
static
SSDataBlock
*
doSysTableScan
(
SOperatorInfo
*
pOperator
,
bool
*
newgroup
)
{
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
469cd23f
...
@@ -113,36 +113,13 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
...
@@ -113,36 +113,13 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
}
}
static
SNode
*
valueNodeCopy
(
const
SValueNode
*
pSrc
,
SValueNode
*
pDst
)
{
static
SNode
*
valueNodeCopy
(
const
SValueNode
*
pSrc
,
SValueNode
*
pDst
)
{
COPY_ALL_SCALAR_FIELDS
;
exprNodeCopy
((
const
SExprNode
*
)
pSrc
,
(
SExprNode
*
)
pDst
);
exprNodeCopy
((
const
SExprNode
*
)
pSrc
,
(
SExprNode
*
)
pDst
);
COPY_CHAR_POINT_FIELD
(
literal
);
COPY_CHAR_POINT_FIELD
(
literal
);
COPY_SCALAR_FIELD
(
isDuration
);
COPY_SCALAR_FIELD
(
translate
);
if
(
!
pSrc
->
translate
)
{
if
(
!
pSrc
->
translate
)
{
return
(
SNode
*
)
pDst
;
return
(
SNode
*
)
pDst
;
}
}
switch
(
pSrc
->
node
.
resType
.
type
)
{
switch
(
pSrc
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_NULL
:
break
;
case
TSDB_DATA_TYPE_BOOL
:
COPY_SCALAR_FIELD
(
datum
.
b
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
COPY_SCALAR_FIELD
(
datum
.
i
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
COPY_SCALAR_FIELD
(
datum
.
u
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
COPY_SCALAR_FIELD
(
datum
.
d
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
case
TSDB_DATA_TYPE_VARBINARY
:
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
469cd23f
...
@@ -1544,6 +1544,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
...
@@ -1544,6 +1544,9 @@ static int32_t valueNodeToJson(const void* pObj, SJson* pJson) {
int32_t
code
=
exprNodeToJson
(
pObj
,
pJson
);
int32_t
code
=
exprNodeToJson
(
pObj
,
pJson
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddBoolToObject
(
pJson
,
jkValueTranslate
,
pNode
->
genByCalc
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
!
pNode
->
genByCalc
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkValueLiteral
,
pNode
->
literal
);
code
=
tjsonAddStringToObject
(
pJson
,
jkValueLiteral
,
pNode
->
literal
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
@@ -1614,6 +1617,9 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
...
@@ -1614,6 +1617,9 @@ static int32_t jsonToValueNode(const SJson* pJson, void* pObj) {
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
int32_t
code
=
jsonToExprNode
(
pJson
,
pObj
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetBoolValue
(
pJson
,
jkValueDuration
,
&
pNode
->
genByCalc
);
}
if
(
TSDB_CODE_SUCCESS
==
code
&&
!
pNode
->
genByCalc
)
{
code
=
tjsonDupStringValue
(
pJson
,
jkValueLiteral
,
&
pNode
->
literal
);
code
=
tjsonDupStringValue
(
pJson
,
jkValueLiteral
,
&
pNode
->
literal
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
469cd23f
...
@@ -138,19 +138,19 @@ static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FNodeWalke
...
@@ -138,19 +138,19 @@ static EDealRes walkList(SNodeList* pNodeList, ETraversalOrder order, FNodeWalke
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
void
nodesWalk
Node
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalk
Expr
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkNode
(
pNode
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
(
void
)
walkNode
(
pNode
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
}
}
void
nodesWalk
List
(
SNodeList
*
pNodeList
,
FNodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalk
Exprs
(
SNodeList
*
pNodeList
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkList
(
pNodeList
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
(
void
)
walkList
(
pNodeList
,
TRAVERSAL_PREORDER
,
walker
,
pContext
);
}
}
void
nodesWalk
Node
PostOrder
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalk
Expr
PostOrder
(
SNodeptr
pNode
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkNode
(
pNode
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
(
void
)
walkNode
(
pNode
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
}
}
void
nodesWalk
List
PostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
)
{
void
nodesWalk
Exprs
PostOrder
(
SNodeList
*
pList
,
FNodeWalker
walker
,
void
*
pContext
)
{
(
void
)
walkList
(
pList
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
(
void
)
walkList
(
pList
,
TRAVERSAL_POSTORDER
,
walker
,
pContext
);
}
}
...
@@ -267,19 +267,19 @@ static EDealRes rewriteList(SNodeList* pNodeList, ETraversalOrder order, FNodeRe
...
@@ -267,19 +267,19 @@ static EDealRes rewriteList(SNodeList* pNodeList, ETraversalOrder order, FNodeRe
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
void
nodesRewrite
Node
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
void
nodesRewrite
Expr
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
}
}
void
nodesRewrite
List
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
void
nodesRewrite
Exprs
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteList
(
pList
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
(
void
)
rewriteList
(
pList
,
TRAVERSAL_PREORDER
,
rewriter
,
pContext
);
}
}
void
nodesRewrite
Node
PostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
void
nodesRewrite
Expr
PostOrder
(
SNode
**
pNode
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
(
void
)
rewriteNode
(
pNode
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
}
}
void
nodesRewrite
List
PostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
void
nodesRewrite
Exprs
PostOrder
(
SNodeList
*
pList
,
FNodeRewriter
rewriter
,
void
*
pContext
)
{
(
void
)
rewriteList
(
pList
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
(
void
)
rewriteList
(
pList
,
TRAVERSAL_POSTORDER
,
rewriter
,
pContext
);
}
}
...
@@ -290,20 +290,20 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
...
@@ -290,20 +290,20 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
switch
(
clause
)
{
switch
(
clause
)
{
case
SQL_CLAUSE_FROM
:
case
SQL_CLAUSE_FROM
:
nodesWalk
Node
(
pSelect
->
pFromTable
,
walker
,
pContext
);
nodesWalk
Expr
(
pSelect
->
pFromTable
,
walker
,
pContext
);
nodesWalk
Node
(
pSelect
->
pWhere
,
walker
,
pContext
);
nodesWalk
Expr
(
pSelect
->
pWhere
,
walker
,
pContext
);
case
SQL_CLAUSE_WHERE
:
case
SQL_CLAUSE_WHERE
:
nodesWalk
List
(
pSelect
->
pPartitionByList
,
walker
,
pContext
);
nodesWalk
Exprs
(
pSelect
->
pPartitionByList
,
walker
,
pContext
);
case
SQL_CLAUSE_PARTITION_BY
:
case
SQL_CLAUSE_PARTITION_BY
:
nodesWalk
Node
(
pSelect
->
pWindow
,
walker
,
pContext
);
nodesWalk
Expr
(
pSelect
->
pWindow
,
walker
,
pContext
);
case
SQL_CLAUSE_WINDOW
:
case
SQL_CLAUSE_WINDOW
:
nodesWalk
List
(
pSelect
->
pGroupByList
,
walker
,
pContext
);
nodesWalk
Exprs
(
pSelect
->
pGroupByList
,
walker
,
pContext
);
case
SQL_CLAUSE_GROUP_BY
:
case
SQL_CLAUSE_GROUP_BY
:
nodesWalk
Node
(
pSelect
->
pHaving
,
walker
,
pContext
);
nodesWalk
Expr
(
pSelect
->
pHaving
,
walker
,
pContext
);
case
SQL_CLAUSE_HAVING
:
case
SQL_CLAUSE_HAVING
:
nodesWalk
List
(
pSelect
->
pOrderByList
,
walker
,
pContext
);
nodesWalk
Exprs
(
pSelect
->
pOrderByList
,
walker
,
pContext
);
case
SQL_CLAUSE_ORDER_BY
:
case
SQL_CLAUSE_ORDER_BY
:
nodesWalk
List
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
nodesWalk
Exprs
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
case
SQL_CLAUSE_SELECT
:
case
SQL_CLAUSE_SELECT
:
default:
default:
break
;
break
;
...
@@ -319,20 +319,20 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
...
@@ -319,20 +319,20 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
switch
(
clause
)
{
switch
(
clause
)
{
case
SQL_CLAUSE_FROM
:
case
SQL_CLAUSE_FROM
:
nodesRewrite
Node
(
&
(
pSelect
->
pFromTable
),
rewriter
,
pContext
);
nodesRewrite
Expr
(
&
(
pSelect
->
pFromTable
),
rewriter
,
pContext
);
nodesRewrite
Node
(
&
(
pSelect
->
pWhere
),
rewriter
,
pContext
);
nodesRewrite
Expr
(
&
(
pSelect
->
pWhere
),
rewriter
,
pContext
);
case
SQL_CLAUSE_WHERE
:
case
SQL_CLAUSE_WHERE
:
nodesRewrite
List
(
pSelect
->
pPartitionByList
,
rewriter
,
pContext
);
nodesRewrite
Exprs
(
pSelect
->
pPartitionByList
,
rewriter
,
pContext
);
case
SQL_CLAUSE_PARTITION_BY
:
case
SQL_CLAUSE_PARTITION_BY
:
nodesRewrite
Node
(
&
(
pSelect
->
pWindow
),
rewriter
,
pContext
);
nodesRewrite
Expr
(
&
(
pSelect
->
pWindow
),
rewriter
,
pContext
);
case
SQL_CLAUSE_WINDOW
:
case
SQL_CLAUSE_WINDOW
:
nodesRewrite
List
(
pSelect
->
pGroupByList
,
rewriter
,
pContext
);
nodesRewrite
Exprs
(
pSelect
->
pGroupByList
,
rewriter
,
pContext
);
case
SQL_CLAUSE_GROUP_BY
:
case
SQL_CLAUSE_GROUP_BY
:
nodesRewrite
Node
(
&
(
pSelect
->
pHaving
),
rewriter
,
pContext
);
nodesRewrite
Expr
(
&
(
pSelect
->
pHaving
),
rewriter
,
pContext
);
case
SQL_CLAUSE_HAVING
:
case
SQL_CLAUSE_HAVING
:
nodesRewrite
List
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
nodesRewrite
Exprs
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
case
SQL_CLAUSE_SELECT
:
case
SQL_CLAUSE_SELECT
:
nodesRewrite
List
(
pSelect
->
pOrderByList
,
rewriter
,
pContext
);
nodesRewrite
Exprs
(
pSelect
->
pOrderByList
,
rewriter
,
pContext
);
default:
default:
break
;
break
;
}
}
...
...
source/libs/nodes/test/nodesTest.cpp
浏览文件 @
469cd23f
...
@@ -49,7 +49,7 @@ TEST(NodesTest, traverseTest) {
...
@@ -49,7 +49,7 @@ TEST(NodesTest, traverseTest) {
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
EDealRes
res
=
DEAL_RES_CONTINUE
;
nodesRewrite
Node
PostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
nodesRewrite
Expr
PostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
...
...
source/libs/parser/CMakeLists.txt
浏览文件 @
469cd23f
...
@@ -8,7 +8,7 @@ target_include_directories(
...
@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries
(
target_link_libraries
(
parser
parser
PRIVATE os util nodes catalog function transport qcom
PRIVATE os util nodes catalog function
scalar
transport qcom
)
)
if
(
${
BUILD_TEST
}
)
if
(
${
BUILD_TEST
}
)
...
...
source/libs/parser/inc/parInt.h
浏览文件 @
469cd23f
...
@@ -23,9 +23,10 @@ extern "C" {
...
@@ -23,9 +23,10 @@ extern "C" {
#include "parser.h"
#include "parser.h"
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
doP
arse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
int32_t
p
arse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
int32_t
doT
ranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
int32_t
t
ranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
int32_t
extractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
);
int32_t
extractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
);
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
469cd23f
...
@@ -243,27 +243,27 @@ static SDatabaseOptions* setDbRetentions(SAstCreateContext* pCxt, SDatabaseOptio
...
@@ -243,27 +243,27 @@ static SDatabaseOptions* setDbRetentions(SAstCreateContext* pCxt, SDatabaseOptio
return
pOptions
;
return
pOptions
;
}
}
char
val
[
20
]
=
{
0
};
if
(
pVal
->
n
>
2
)
{
int32_t
len
=
trimString
(
pVal
->
z
,
pVal
->
n
,
val
,
sizeof
(
val
));
char
*
pStart
=
pVal
->
z
+
1
;
char
*
pStart
=
val
;
char
*
pEnd
=
pVal
->
z
+
pVal
->
n
-
1
;
char
*
pEnd
=
val
+
len
;
int32_t
sepOrder
=
1
;
int32_t
sepOrder
=
1
;
while
(
1
)
{
while
(
1
)
{
char
*
pPos
=
strchr
(
pStart
,
(
0
==
(
sepOrder
++
)
%
2
)
?
','
:
':'
);
char
*
pPos
=
strchr
(
pStart
,
(
0
==
sepOrder
%
2
)
?
','
:
':'
);
SToken
t
=
{
.
type
=
TK_NK_VARIABLE
,
.
z
=
pStart
,
.
n
=
(
NULL
==
pPos
?
pEnd
-
pStart
:
pPos
-
pStart
)};
SToken
t
=
{
.
type
=
TK_NK_VARIABLE
,
.
z
=
pStart
,
.
n
=
(
NULL
==
pPos
?
pEnd
-
pStart
:
pPos
-
pStart
)};
if
(
TSDB_CODE_SUCCESS
!=
nodesListStrictAppend
(
pOptions
->
pRetentions
,
createDurationValueNode
(
pCxt
,
&
t
)))
{
if
(
TSDB_CODE_SUCCESS
!=
nodesListStrictAppend
(
pOptions
->
pRetentions
,
createDurationValueNode
(
pCxt
,
&
t
)))
{
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"Out of memory"
);
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"Out of memory"
);
return
pOptions
;
return
pOptions
;
}
}
if
(
NULL
==
pPos
)
{
if
(
NULL
==
pPos
)
{
break
;
break
;
}
pStart
=
pPos
+
1
;
}
}
pStart
=
pPos
+
1
;
}
}
if
(
LIST_LENGTH
(
pOptions
->
pRetentions
)
%
2
!=
0
)
{
if
(
LIST_LENGTH
(
pOptions
->
pRetentions
)
<
2
||
LIST_LENGTH
(
pOptions
->
pRetentions
)
%
2
!=
0
)
{
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid db option retentions: %s"
,
val
);
snprintf
(
pCxt
->
pQueryCxt
->
pMsg
,
pCxt
->
pQueryCxt
->
msgLen
,
"invalid db option retentions: %s"
,
pVal
->
z
);
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
}
}
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
469cd23f
...
@@ -26,7 +26,7 @@ extern void Parse(void*, int, SToken, void*);
...
@@ -26,7 +26,7 @@ extern void Parse(void*, int, SToken, void*);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
int32_t
doP
arse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
int32_t
p
arse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
SAstCreateContext
cxt
;
SAstCreateContext
cxt
;
initAstCreateContext
(
pParseCxt
,
&
cxt
);
initAstCreateContext
(
pParseCxt
,
&
cxt
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
...
...
source/libs/parser/src/parCalcConst.c
0 → 100644
浏览文件 @
469cd23f
/*
* 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 "parInt.h"
#include "scalar.h"
typedef
struct
SCalcConstContext
{
int32_t
code
;
}
SCalcConstContext
;
static
int32_t
calcConstQuery
(
SNode
*
pStmt
);
static
EDealRes
doCalcConst
(
SNode
**
pNode
,
SCalcConstContext
*
pCxt
)
{
SNode
*
pNew
=
NULL
;
pCxt
->
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
code
)
{
return
DEAL_RES_ERROR
;
}
((
SValueNode
*
)
pNew
)
->
genByCalc
=
true
;
((
SValueNode
*
)
pNew
)
->
translate
=
true
;
*
pNode
=
pNew
;
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
calcConstOperator
(
SOperatorNode
**
pNode
,
void
*
pContext
)
{
SOperatorNode
*
pOp
=
*
pNode
;
if
(
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pLeft
)
&&
(
NULL
==
pOp
->
pRight
||
QUERY_NODE_VALUE
==
nodeType
(
pOp
->
pRight
)))
{
return
doCalcConst
((
SNode
**
)
pNode
,
(
SCalcConstContext
*
)
pContext
);
}
return
DEAL_RES_CONTINUE
;
}
static
EDealRes
calcConstFunction
(
SFunctionNode
**
pNode
,
void
*
pContext
)
{
SFunctionNode
*
pFunc
=
*
pNode
;
SNode
*
pParam
=
NULL
;
FOREACH
(
pParam
,
pFunc
->
pParameterList
)
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParam
))
{
return
DEAL_RES_CONTINUE
;
}
}
return
doCalcConst
((
SNode
**
)
pNode
,
(
SCalcConstContext
*
)
pContext
);
}
static
EDealRes
calcConstLogicCond
(
SLogicConditionNode
**
pNode
,
void
*
pContext
)
{
SLogicConditionNode
*
pCond
=
*
pNode
;
SNode
*
pParam
=
NULL
;
FOREACH
(
pParam
,
pCond
->
pParameterList
)
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pParam
))
{
return
DEAL_RES_CONTINUE
;
}
}
return
doCalcConst
((
SNode
**
)
pNode
,
(
SCalcConstContext
*
)
pContext
);
}
static
EDealRes
calcConstSubquery
(
STempTableNode
**
pNode
,
void
*
pContext
)
{
SCalcConstContext
*
pCxt
=
pContext
;
pCxt
->
code
=
calcConstQuery
((
*
pNode
)
->
pSubquery
);
return
(
TSDB_CODE_SUCCESS
==
pCxt
->
code
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
);
}
static
EDealRes
calcConst
(
SNode
**
pNode
,
void
*
pContext
)
{
switch
(
nodeType
(
*
pNode
))
{
case
QUERY_NODE_OPERATOR
:
return
calcConstOperator
((
SOperatorNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_FUNCTION
:
return
calcConstFunction
((
SFunctionNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_LOGIC_CONDITION
:
return
calcConstLogicCond
((
SLogicConditionNode
**
)
pNode
,
pContext
);
case
QUERY_NODE_TEMP_TABLE
:
return
calcConstSubquery
((
STempTableNode
**
)
pNode
,
pContext
);
default:
break
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
calcConstSelect
(
SSelectStmt
*
pSelect
)
{
SCalcConstContext
cxt
=
{
.
code
=
TSDB_CODE_SUCCESS
};
nodesRewriteExprsPostOrder
(
pSelect
->
pProjectionList
,
calcConst
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pFromTable
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pWhere
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pPartitionByList
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pWindow
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pGroupByList
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprPostOrder
(
&
pSelect
->
pHaving
,
calcConst
,
&
cxt
);
}
if
(
TSDB_CODE_SUCCESS
==
cxt
.
code
)
{
nodesRewriteExprsPostOrder
(
pSelect
->
pOrderByList
,
calcConst
,
&
cxt
);
}
return
cxt
.
code
;
}
static
int32_t
calcConstQuery
(
SNode
*
pStmt
)
{
switch
(
nodeType
(
pStmt
))
{
case
QUERY_NODE_SELECT_STMT
:
return
calcConstSelect
((
SSelectStmt
*
)
pStmt
);
default:
break
;
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
return
calcConstQuery
(
pQuery
->
pRoot
);
}
source/libs/parser/src/parTranslater.c
浏览文件 @
469cd23f
...
@@ -50,14 +50,12 @@ static bool beforeHaving(ESqlClause clause) {
...
@@ -50,14 +50,12 @@ static bool beforeHaving(ESqlClause clause) {
return
clause
<
SQL_CLAUSE_HAVING
;
return
clause
<
SQL_CLAUSE_HAVING
;
}
}
static
EDealRes
generateDealNodeErrMsg
(
STranslateContext
*
pCxt
,
int32_t
errCode
,
...)
{
#define generateDealNodeErrMsg(pCxt, code, ...) \
va_list
vArgList
;
({ \
va_start
(
vArgList
,
errCode
);
generateSyntaxErrMsg(&pCxt->msgBuf, code, ##__VA_ARGS__); \
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
errCode
,
vArgList
);
pCxt->errCode = code; \
va_end
(
vArgList
);
DEAL_RES_ERROR; \
pCxt
->
errCode
=
errCode
;
})
return
DEAL_RES_ERROR
;
}
static
int32_t
addNamespace
(
STranslateContext
*
pCxt
,
void
*
pTable
)
{
static
int32_t
addNamespace
(
STranslateContext
*
pCxt
,
void
*
pTable
)
{
size_t
currTotalLevel
=
taosArrayGetSize
(
pCxt
->
pNsLevel
);
size_t
currTotalLevel
=
taosArrayGetSize
(
pCxt
->
pNsLevel
);
...
@@ -440,6 +438,9 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
...
@@ -440,6 +438,9 @@ static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
static
EDealRes
translateOperator
(
STranslateContext
*
pCxt
,
SOperatorNode
*
pOp
)
{
static
EDealRes
translateOperator
(
STranslateContext
*
pCxt
,
SOperatorNode
*
pOp
)
{
if
(
nodesIsUnaryOp
(
pOp
))
{
if
(
nodesIsUnaryOp
(
pOp
))
{
if
(
OP_TYPE_MINUS
==
pOp
->
opType
&&
!
IS_NUMERIC_TYPE
(((
SExprNode
*
)(
pOp
->
pLeft
))
->
resType
.
type
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_WRONG_VALUE_TYPE
,
((
SExprNode
*
)(
pOp
->
pLeft
))
->
aliasName
);
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
SDataType
ldt
=
((
SExprNode
*
)(
pOp
->
pLeft
))
->
resType
;
SDataType
ldt
=
((
SExprNode
*
)(
pOp
->
pLeft
))
->
resType
;
...
@@ -510,12 +511,12 @@ static EDealRes doTranslateExpr(SNode* pNode, void* pContext) {
...
@@ -510,12 +511,12 @@ static EDealRes doTranslateExpr(SNode* pNode, void* pContext) {
}
}
static
int32_t
translateExpr
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
static
int32_t
translateExpr
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
nodesWalk
Node
PostOrder
(
pNode
,
doTranslateExpr
,
pCxt
);
nodesWalk
Expr
PostOrder
(
pNode
,
doTranslateExpr
,
pCxt
);
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
static
int32_t
translateExprList
(
STranslateContext
*
pCxt
,
SNodeList
*
pList
)
{
static
int32_t
translateExprList
(
STranslateContext
*
pCxt
,
SNodeList
*
pList
)
{
nodesWalk
List
PostOrder
(
pList
,
doTranslateExpr
,
pCxt
);
nodesWalk
Exprs
PostOrder
(
pList
,
doTranslateExpr
,
pCxt
);
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
...
@@ -570,7 +571,7 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
...
@@ -570,7 +571,7 @@ static EDealRes doCheckExprForGroupBy(SNode* pNode, void* pContext) {
}
}
static
int32_t
checkExprForGroupBy
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
static
int32_t
checkExprForGroupBy
(
STranslateContext
*
pCxt
,
SNode
*
pNode
)
{
nodesWalk
Node
(
pNode
,
doCheckExprForGroupBy
,
pCxt
);
nodesWalk
Expr
(
pNode
,
doCheckExprForGroupBy
,
pCxt
);
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
...
@@ -578,7 +579,7 @@ static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SNodeList* pList
...
@@ -578,7 +579,7 @@ static int32_t checkExprListForGroupBy(STranslateContext* pCxt, SNodeList* pList
if
(
NULL
==
getGroupByList
(
pCxt
))
{
if
(
NULL
==
getGroupByList
(
pCxt
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
nodesWalk
List
(
pList
,
doCheckExprForGroupBy
,
pCxt
);
nodesWalk
Exprs
(
pList
,
doCheckExprForGroupBy
,
pCxt
);
return
pCxt
->
errCode
;
return
pCxt
->
errCode
;
}
}
...
@@ -605,9 +606,9 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
...
@@ -605,9 +606,9 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
CheckAggColCoexistCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
existAggFunc
=
false
,
.
existCol
=
false
};
CheckAggColCoexistCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
existAggFunc
=
false
,
.
existCol
=
false
};
nodesWalk
List
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
nodesWalk
Exprs
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
if
(
!
pSelect
->
isDistinct
)
{
if
(
!
pSelect
->
isDistinct
)
{
nodesWalk
List
(
pSelect
->
pOrderByList
,
doCheckAggColCoexist
,
&
cxt
);
nodesWalk
Exprs
(
pSelect
->
pOrderByList
,
doCheckAggColCoexist
,
&
cxt
);
}
}
if
(
cxt
.
existAggFunc
&&
cxt
.
existCol
)
{
if
(
cxt
.
existAggFunc
&&
cxt
.
existCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
...
@@ -2633,7 +2634,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
...
@@ -2633,7 +2634,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
doT
ranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
int32_t
t
ranslate
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
STranslateContext
cxt
=
{
STranslateContext
cxt
=
{
.
pParseCxt
=
pParseCxt
,
.
pParseCxt
=
pParseCxt
,
.
errCode
=
TSDB_CODE_SUCCESS
,
.
errCode
=
TSDB_CODE_SUCCESS
,
...
...
source/libs/parser/src/parser.c
浏览文件 @
469cd23f
...
@@ -30,9 +30,12 @@ static bool isInsertSql(const char* pStr, size_t length) {
...
@@ -30,9 +30,12 @@ static bool isInsertSql(const char* pStr, size_t length) {
}
}
static
int32_t
parseSqlIntoAst
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
)
{
static
int32_t
parseSqlIntoAst
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
)
{
int32_t
code
=
doP
arse
(
pCxt
,
pQuery
);
int32_t
code
=
p
arse
(
pCxt
,
pQuery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
doTranslate
(
pCxt
,
*
pQuery
);
code
=
translate
(
pCxt
,
*
pQuery
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calculateConstant
(
pCxt
,
*
pQuery
);
}
}
return
code
;
return
code
;
}
}
...
...
source/libs/parser/test/parserAstTest.cpp
浏览文件 @
469cd23f
...
@@ -54,7 +54,7 @@ private:
...
@@ -54,7 +54,7 @@ private:
static
const
int
max_err_len
=
1024
;
static
const
int
max_err_len
=
1024
;
bool
runImpl
(
int32_t
parseCode
,
int32_t
translateCode
)
{
bool
runImpl
(
int32_t
parseCode
,
int32_t
translateCode
)
{
int32_t
code
=
doP
arse
(
&
cxt_
,
&
query_
);
int32_t
code
=
p
arse
(
&
cxt_
,
&
query_
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
parseErrStr_
=
string
(
"code:"
)
+
tstrerror
(
code
)
+
string
(
", msg:"
)
+
errMagBuf_
;
parseErrStr_
=
string
(
"code:"
)
+
tstrerror
(
code
)
+
string
(
", msg:"
)
+
errMagBuf_
;
return
(
terrno
==
parseCode
);
return
(
terrno
==
parseCode
);
...
@@ -63,7 +63,7 @@ private:
...
@@ -63,7 +63,7 @@ private:
return
false
;
return
false
;
}
}
parsedAstStr_
=
toString
(
query_
->
pRoot
);
parsedAstStr_
=
toString
(
query_
->
pRoot
);
code
=
doT
ranslate
(
&
cxt_
,
query_
);
code
=
t
ranslate
(
&
cxt_
,
query_
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
translateErrStr_
=
string
(
"code:"
)
+
tstrerror
(
code
)
+
string
(
", msg:"
)
+
errMagBuf_
;
translateErrStr_
=
string
(
"code:"
)
+
tstrerror
(
code
)
+
string
(
", msg:"
)
+
errMagBuf_
;
return
(
terrno
==
translateCode
);
return
(
terrno
==
translateCode
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
469cd23f
...
@@ -83,7 +83,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
...
@@ -83,7 +83,7 @@ static EDealRes doNameExpr(SNode* pNode, void* pContext) {
}
}
static
int32_t
rewriteExpr
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
static
int32_t
rewriteExpr
(
SNodeList
*
pExprs
,
SSelectStmt
*
pSelect
,
ESqlClause
clause
)
{
nodesWalk
List
(
pExprs
,
doNameExpr
,
NULL
);
nodesWalk
Exprs
(
pExprs
,
doNameExpr
,
NULL
);
SRewriteExprCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
SRewriteExprCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pExprs
=
pExprs
};
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
nodesRewriteSelectStmt
(
pSelect
,
clause
,
doRewriteExpr
,
&
cxt
);
return
cxt
.
errCode
;
return
cxt
.
errCode
;
...
@@ -384,7 +384,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx
...
@@ -384,7 +384,7 @@ static int32_t createColumnByRewriteExps(SLogicPlanContext* pCxt, SNodeList* pEx
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
nodesWalk
List
(
pExprs
,
doCreateColumn
,
&
cxt
);
nodesWalk
Exprs
(
pExprs
,
doCreateColumn
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
nodesDestroyList
(
cxt
.
pList
);
nodesDestroyList
(
cxt
.
pList
);
return
cxt
.
errCode
;
return
cxt
.
errCode
;
...
...
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
469cd23f
...
@@ -264,7 +264,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
...
@@ -264,7 +264,7 @@ static int32_t setNodeSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
.
pLeftHash
=
taosArrayGetP
(
pCxt
->
pLocationHelper
,
leftDataBlockId
),
.
pLeftHash
=
taosArrayGetP
(
pCxt
->
pLocationHelper
,
leftDataBlockId
),
.
pRightHash
=
(
rightDataBlockId
<
0
?
NULL
:
taosArrayGetP
(
pCxt
->
pLocationHelper
,
rightDataBlockId
))
.
pRightHash
=
(
rightDataBlockId
<
0
?
NULL
:
taosArrayGetP
(
pCxt
->
pLocationHelper
,
rightDataBlockId
))
};
};
nodesWalk
Node
(
pRes
,
doSetSlotId
,
&
cxt
);
nodesWalk
Expr
(
pRes
,
doSetSlotId
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
nodesDestroyNode
(
pRes
);
nodesDestroyNode
(
pRes
);
return
cxt
.
errCode
;
return
cxt
.
errCode
;
...
@@ -285,7 +285,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
...
@@ -285,7 +285,7 @@ static int32_t setListSlotId(SPhysiPlanContext* pCxt, int16_t leftDataBlockId, i
.
pLeftHash
=
taosArrayGetP
(
pCxt
->
pLocationHelper
,
leftDataBlockId
),
.
pLeftHash
=
taosArrayGetP
(
pCxt
->
pLocationHelper
,
leftDataBlockId
),
.
pRightHash
=
(
rightDataBlockId
<
0
?
NULL
:
taosArrayGetP
(
pCxt
->
pLocationHelper
,
rightDataBlockId
))
.
pRightHash
=
(
rightDataBlockId
<
0
?
NULL
:
taosArrayGetP
(
pCxt
->
pLocationHelper
,
rightDataBlockId
))
};
};
nodesWalk
List
(
pRes
,
doSetSlotId
,
&
cxt
);
nodesWalk
Exprs
(
pRes
,
doSetSlotId
,
&
cxt
);
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
if
(
TSDB_CODE_SUCCESS
!=
cxt
.
errCode
)
{
nodesDestroyList
(
pRes
);
nodesDestroyList
(
pRes
);
return
cxt
.
errCode
;
return
cxt
.
errCode
;
...
@@ -606,7 +606,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
...
@@ -606,7 +606,7 @@ static int32_t rewritePrecalcExprs(SPhysiPlanContext* pCxt, SNodeList* pList, SN
}
}
}
}
SRewritePrecalcExprsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pPrecalcExprs
=
*
pPrecalcExprs
};
SRewritePrecalcExprsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pPrecalcExprs
=
*
pPrecalcExprs
};
nodesRewrite
List
(
*
pRewrittenList
,
doRewritePrecalcExprs
,
&
cxt
);
nodesRewrite
Exprs
(
*
pRewrittenList
,
doRewritePrecalcExprs
,
&
cxt
);
if
(
0
==
LIST_LENGTH
(
cxt
.
pPrecalcExprs
))
{
if
(
0
==
LIST_LENGTH
(
cxt
.
pPrecalcExprs
))
{
nodesDestroyList
(
cxt
.
pPrecalcExprs
);
nodesDestroyList
(
cxt
.
pPrecalcExprs
);
*
pPrecalcExprs
=
NULL
;
*
pPrecalcExprs
=
NULL
;
...
...
source/libs/planner/test/plannerTest.cpp
浏览文件 @
469cd23f
...
@@ -157,6 +157,13 @@ TEST_F(PlannerTest, simple) {
...
@@ -157,6 +157,13 @@ TEST_F(PlannerTest, simple) {
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
TEST_F
(
PlannerTest
,
selectConstant
)
{
setDatabase
(
"root"
,
"test"
);
bind
(
"SELECT 2-1 FROM t1"
);
ASSERT_TRUE
(
run
());
}
TEST_F
(
PlannerTest
,
stSimple
)
{
TEST_F
(
PlannerTest
,
stSimple
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
...
...
source/libs/scalar/src/filter.c
浏览文件 @
469cd23f
...
@@ -1297,7 +1297,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
...
@@ -1297,7 +1297,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
resGroup
=
taosArrayInit
(
4
,
sizeof
(
SFilterGroup
));
resGroup
=
taosArrayInit
(
4
,
sizeof
(
SFilterGroup
));
SFltBuildGroupCtx
tctx
=
{.
info
=
ctx
->
info
,
.
group
=
newGroup
};
SFltBuildGroupCtx
tctx
=
{.
info
=
ctx
->
info
,
.
group
=
newGroup
};
nodesWalk
Node
(
cell
->
pNode
,
fltTreeToGroup
,
(
void
*
)
&
tctx
);
nodesWalk
Expr
(
cell
->
pNode
,
fltTreeToGroup
,
(
void
*
)
&
tctx
);
FLT_ERR_JRET
(
tctx
.
code
);
FLT_ERR_JRET
(
tctx
.
code
);
FLT_ERR_JRET
(
filterDetachCnfGroups
(
resGroup
,
preGroup
,
newGroup
));
FLT_ERR_JRET
(
filterDetachCnfGroups
(
resGroup
,
preGroup
,
newGroup
));
...
@@ -1322,7 +1322,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
...
@@ -1322,7 +1322,7 @@ EDealRes fltTreeToGroup(SNode* pNode, void* pContext) {
if
(
LOGIC_COND_TYPE_OR
==
node
->
condType
)
{
if
(
LOGIC_COND_TYPE_OR
==
node
->
condType
)
{
SListCell
*
cell
=
node
->
pParameterList
->
pHead
;
SListCell
*
cell
=
node
->
pParameterList
->
pHead
;
for
(
int32_t
i
=
0
;
i
<
node
->
pParameterList
->
length
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
node
->
pParameterList
->
length
;
++
i
)
{
nodesWalk
Node
(
cell
->
pNode
,
fltTreeToGroup
,
(
void
*
)
pContext
);
nodesWalk
Expr
(
cell
->
pNode
,
fltTreeToGroup
,
(
void
*
)
pContext
);
FLT_ERR_JRET
(
ctx
->
code
);
FLT_ERR_JRET
(
ctx
->
code
);
cell
=
cell
->
pNext
;
cell
=
cell
->
pNext
;
...
@@ -3190,7 +3190,7 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) {
...
@@ -3190,7 +3190,7 @@ int32_t fltInitFromNode(SNode* tree, SFilterInfo *info, uint32_t options) {
filterInitUnitsFields
(
info
);
filterInitUnitsFields
(
info
);
SFltBuildGroupCtx
tctx
=
{.
info
=
info
,
.
group
=
group
};
SFltBuildGroupCtx
tctx
=
{.
info
=
info
,
.
group
=
group
};
nodesWalk
Node
(
tree
,
fltTreeToGroup
,
(
void
*
)
&
tctx
);
nodesWalk
Expr
(
tree
,
fltTreeToGroup
,
(
void
*
)
&
tctx
);
FLT_ERR_JRET
(
tctx
.
code
);
FLT_ERR_JRET
(
tctx
.
code
);
filterConvertGroupFromArray
(
info
,
group
);
filterConvertGroupFromArray
(
info
,
group
);
...
@@ -3566,7 +3566,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
...
@@ -3566,7 +3566,7 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
}
}
int32_t
fltReviseNodes
(
SFilterInfo
*
pInfo
,
SNode
**
pNode
,
SFltTreeStat
*
pStat
)
{
int32_t
fltReviseNodes
(
SFilterInfo
*
pInfo
,
SNode
**
pNode
,
SFltTreeStat
*
pStat
)
{
nodesRewrite
Node
PostOrder
(
pNode
,
fltReviseRewriter
,
(
void
*
)
pStat
);
nodesRewrite
Expr
PostOrder
(
pNode
,
fltReviseRewriter
,
(
void
*
)
pStat
);
FLT_RET
(
pStat
->
code
);
FLT_RET
(
pStat
->
code
);
}
}
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
469cd23f
...
@@ -673,7 +673,7 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
...
@@ -673,7 +673,7 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
nodesRewrite
Node
PostOrder
(
&
pNode
,
sclConstantsRewriter
,
(
void
*
)
&
ctx
);
nodesRewrite
Expr
PostOrder
(
&
pNode
,
sclConstantsRewriter
,
(
void
*
)
&
ctx
);
SCL_ERR_JRET
(
ctx
.
code
);
SCL_ERR_JRET
(
ctx
.
code
);
*
pRes
=
pNode
;
*
pRes
=
pNode
;
...
@@ -696,7 +696,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
...
@@ -696,7 +696,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
}
nodesWalk
Node
PostOrder
(
pNode
,
sclCalcWalker
,
(
void
*
)
&
ctx
);
nodesWalk
Expr
PostOrder
(
pNode
,
sclCalcWalker
,
(
void
*
)
&
ctx
);
SCL_ERR_JRET
(
ctx
.
code
);
SCL_ERR_JRET
(
ctx
.
code
);
if
(
pDst
)
{
if
(
pDst
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录