Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e4cb5c29
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看板
提交
e4cb5c29
编写于
11月 11, 2021
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sqlexpr_type_* introduced for validate sql expr
上级
fc8bb51e
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
94 addition
and
71 deletion
+94
-71
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+90
-68
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+4
-3
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
e4cb5c29
...
@@ -1893,7 +1893,7 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
...
@@ -1893,7 +1893,7 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
const
char
*
msg1
=
"invalid column name, illegal column type, or columns in arithmetic expression from two tables"
;
const
char
*
msg1
=
"invalid column name, illegal column type, or columns in arithmetic expression from two tables"
;
SColumnList
columnList
=
{
0
};
SColumnList
columnList
=
{
0
};
int32_t
arithmeticType
=
NON_ARITHMEIC_EXPR
;
int32_t
arithmeticType
=
SQLEXPR_TYPE_UNASSIGNED
;
uint64_t
uid
;
uint64_t
uid
;
if
(
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateSQLExprItem
(
pCmd
,
pItem
->
pNode
,
pQueryInfo
,
&
columnList
,
&
arithmeticType
,
&
uid
)
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -1901,7 +1901,7 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
...
@@ -1901,7 +1901,7 @@ static int32_t handleSQLExprItem(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t
}
}
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
arithmeticType
==
NORMAL_ARITHMETIC
)
{
if
(
arithmeticType
==
SQLEXPR_TYPE_SCALAR
)
{
code
=
handleScalarExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
code
=
handleScalarExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
}
else
{
}
else
{
code
=
handleAggregateExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
code
=
handleAggregateExpr
(
pCmd
,
pQueryInfo
,
exprIndex
,
pItem
,
&
columnList
,
true
);
...
@@ -4352,53 +4352,60 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
...
@@ -4352,53 +4352,60 @@ static int32_t getJoinCondInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr*
return
checkAndSetJoinCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
);
return
checkAndSetJoinCondInfo
(
pCmd
,
pQueryInfo
,
pExpr
);
}
}
static
int32_t
validateSQLExprSQLFunc
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
static
int32_t
validateSQLExpr
Item
SQLFunc
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
int32_t
functionId
=
isValidFunction
(
pExpr
->
Expr
.
operand
.
z
,
pExpr
->
Expr
.
operand
.
n
);
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
NORMAL_ARITHMETIC
;
}
else
{
*
type
=
AGG_ARIGHTMEIC
;
}
}
else
if
(
*
type
==
NORMAL_ARITHMETIC
)
{
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
*
type
=
AGG_ARIGHTMEIC
;
}
}
pExpr
->
functionId
=
functionId
;
pExpr
->
functionId
=
functionId
;
if
(
pExpr
->
Expr
.
paramList
!=
NULL
)
{
if
(
pExpr
->
Expr
.
paramList
!=
NULL
)
{
size_t
numChildren
=
taosArrayGetSize
(
pExpr
->
Expr
.
paramList
);
size_t
numChildren
=
taosArrayGetSize
(
pExpr
->
Expr
.
paramList
);
int32_t
*
childrenTypes
=
calloc
(
numChildren
,
sizeof
(
int32_t
));
for
(
int32_t
i
=
0
;
i
<
numChildren
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numChildren
;
++
i
)
{
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
)
&&
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
childrenTypes
+
i
,
uid
);
(
pParamElem
->
pNode
->
type
==
SQL_NODE_EXPR
||
pParamElem
->
pNode
->
type
==
SQL_NODE_SQLFUNCTION
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
code
=
validateSQLExprItem
(
pCmd
,
pParamElem
->
pNode
,
pQueryInfo
,
pList
,
type
,
uid
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
free
(
childrenTypes
);
return
code
;
return
code
;
}
}
}
}
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
)
&&
(
pParamElem
->
pNode
->
type
==
SQL_NODE_EXPR
||
pParamElem
->
pNode
->
type
==
SQL_NODE_SQLFUNCTION
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
}
if
(
pExpr
->
Expr
.
paramList
!=
NULL
)
{
{
size_t
numChildren
=
taosArrayGetSize
(
pExpr
->
Expr
.
paramList
);
bool
allChildValue
=
true
;
for
(
int32_t
i
=
0
;
i
<
numChildren
;
++
i
)
{
bool
anyChildScalar
=
false
;
tSqlExprItem
*
pParamElem
=
taosArrayGet
(
pExpr
->
Expr
.
paramList
,
i
);
bool
anyChildAgg
=
false
;
if
(
pParamElem
->
pNode
->
type
==
SQL_NODE_EXPR
||
pParamElem
->
pNode
->
type
==
SQL_NODE_SQLFUNCTION
)
{
for
(
int
i
=
0
;
i
<
numChildren
;
++
i
)
{
assert
(
childrenTypes
[
i
]
!=
SQLEXPR_TYPE_UNASSIGNED
);
allChildValue
=
allChildValue
&&
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_VALUE
);
anyChildScalar
=
anyChildScalar
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_SCALAR
);
anyChildAgg
=
anyChildAgg
||
(
childrenTypes
[
i
]
==
SQLEXPR_TYPE_AGG
);
}
if
(
anyChildAgg
&&
anyChildScalar
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
if
(
anyChildAgg
)
{
*
type
=
SQLEXPR_TYPE_AGG
;
}
else
if
(
allChildValue
)
{
*
type
=
SQLEXPR_TYPE_VALUE
;
}
else
{
*
type
=
SQLEXPR_TYPE_SCALAR
;
}
}
else
{
*
type
=
SQLEXPR_TYPE_AGG
;
}
}
}
}
free
(
childrenTypes
);
}
if
(
!
TSDB_FUNC_IS_SCALAR
(
functionId
))
{
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
int32_t
outputIndex
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
tSqlExprItem
item
=
{.
pNode
=
pExpr
,
.
aliasName
=
NULL
};
...
@@ -4450,52 +4457,61 @@ static int32_t validateSQLExprSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
...
@@ -4450,52 +4457,61 @@ static int32_t validateSQLExprSQLFunc(SSqlCmd* pCmd, tSqlExpr* pExpr,
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
validateSQLExprItem
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
static
int32_t
validateSQLExprItemArithmeticExpr
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
int32_t
*
type
,
uint64_t
*
uid
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
if
(
pExpr
->
type
==
SQL_NODE_EXPR
)
{
if
(
*
type
==
NON_ARITHMEIC_EXPR
)
{
*
type
=
NORMAL_ARITHMETIC
;
}
uint64_t
uidLeft
=
0
;
uint64_t
uidLeft
=
0
;
uint64_t
uidRight
=
0
;
uint64_t
uidRight
=
0
;
int32_t
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
type
,
&
uidLeft
);
int32_t
leftType
=
SQLEXPR_TYPE_UNASSIGNED
;
int32_t
rightType
=
SQLEXPR_TYPE_UNASSIGNED
;
int32_t
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pLeft
,
pQueryInfo
,
pList
,
&
leftType
,
&
uidLeft
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pRight
,
pQueryInfo
,
pList
,
t
ype
,
&
uidRight
);
ret
=
validateSQLExprItem
(
pCmd
,
pExpr
->
pRight
,
pQueryInfo
,
pList
,
&
rightT
ype
,
&
uidRight
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
if
(
uidLeft
!=
uidRight
&&
uidLeft
!=
0
&&
uidRight
!=
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
*
uid
=
uidLeft
;
{
{
tSqlExpr
*
leftChild
=
pExpr
->
pLeft
;
assert
(
leftType
!=
SQLEXPR_TYPE_UNASSIGNED
&&
rightType
!=
SQLEXPR_TYPE_UNASSIGNED
)
;
tSqlExpr
*
rightChild
=
pExpr
->
pRight
;
// return invalid operation when one child aggregate and the other child scalar or column
// return invalid operation when one child aggregate and the other child scalar or column
if
(
leftChild
->
type
==
SQL_NODE_SQLFUNCTION
&&
!
TSDB_FUNC_IS_SCALAR
(
leftChild
->
functionId
))
{
if
(
leftType
==
SQLEXPR_TYPE_AGG
&&
rightType
==
SQLEXPR_TYPE_SCALAR
)
{
if
((
rightChild
->
type
==
SQL_NODE_SQLFUNCTION
&&
TSDB_FUNC_IS_SCALAR
(
rightChild
->
functionId
))
||
rightChild
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
}
if
(
rightType
==
SQLEXPR_TYPE_AGG
&&
leftType
==
SQLEXPR_TYPE_SCALAR
)
{
if
(
rightChild
->
type
==
SQL_NODE_SQLFUNCTION
&&
!
TSDB_FUNC_IS_SCALAR
(
rightChild
->
functionId
))
{
if
((
leftChild
->
type
==
SQL_NODE_SQLFUNCTION
&&
TSDB_FUNC_IS_SCALAR
(
leftChild
->
functionId
))
||
leftChild
->
type
==
SQL_NODE_TABLE_COLUMN
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
leftType
==
SQLEXPR_TYPE_AGG
||
rightType
==
SQLEXPR_TYPE_AGG
)
{
*
type
=
SQLEXPR_TYPE_AGG
;
}
else
if
(
leftType
==
SQLEXPR_TYPE_VALUE
&&
rightType
==
SQLEXPR_TYPE_VALUE
)
{
*
type
=
SQLEXPR_TYPE_VALUE
;
}
else
if
(
leftType
==
SQLEXPR_TYPE_SCALAR
||
rightType
==
SQLEXPR_TYPE_SCALAR
){
*
type
=
SQLEXPR_TYPE_SCALAR
;
}
}
}
}
return
TSDB_CODE_SUCCESS
;
}
if
(
uidLeft
!=
uidRight
&&
uidLeft
!=
0
&&
uidRight
!=
0
)
{
static
int32_t
validateSQLExprItem
(
SSqlCmd
*
pCmd
,
tSqlExpr
*
pExpr
,
return
TSDB_CODE_TSC_INVALID_OPERATION
;
SQueryInfo
*
pQueryInfo
,
SColumnList
*
pList
,
int32_t
*
type
,
uint64_t
*
uid
)
{
if
(
pExpr
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
}
*
uid
=
uidLeft
;
if
(
pExpr
->
type
==
SQL_NODE_EXPR
)
{
int32_t
ret
=
validateSQLExprItemArithmeticExpr
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
}
else
if
(
pExpr
->
type
==
SQL_NODE_SQLFUNCTION
)
{
int32_t
ret
=
validateSQLExprSQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
int32_t
ret
=
validateSQLExpr
Item
SQLFunc
(
pCmd
,
pExpr
,
pQueryInfo
,
pList
,
type
,
uid
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
return
ret
;
}
}
...
@@ -4507,10 +4523,16 @@ static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr,
...
@@ -4507,10 +4523,16 @@ static int32_t validateSQLExprItem(SSqlCmd* pCmd, tSqlExpr* pExpr,
}
}
pList
->
ids
[
pList
->
num
++
]
=
index
;
pList
->
ids
[
pList
->
num
++
]
=
index
;
}
else
if
((
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
||
*
type
=
SQLEXPR_TYPE_SCALAR
;
}
else
{
if
((
pExpr
->
tokenId
==
TK_FLOAT
&&
(
isnan
(
pExpr
->
value
.
dKey
)
||
isinf
(
pExpr
->
value
.
dKey
)))
||
pExpr
->
tokenId
==
TK_NULL
)
{
pExpr
->
tokenId
==
TK_NULL
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
pExpr
->
type
==
SQL_NODE_VALUE
)
{
*
type
=
SQLEXPR_TYPE_VALUE
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
...
src/query/inc/qSqlparser.h
浏览文件 @
e4cb5c29
...
@@ -28,9 +28,10 @@ extern "C" {
...
@@ -28,9 +28,10 @@ extern "C" {
#define ParseTOKENTYPE SStrToken
#define ParseTOKENTYPE SStrToken
#define NON_ARITHMEIC_EXPR 0
#define SQLEXPR_TYPE_UNASSIGNED 0
#define NORMAL_ARITHMETIC 1
#define SQLEXPR_TYPE_SCALAR 1
#define AGG_ARIGHTMEIC 2
#define SQLEXPR_TYPE_AGG 2
#define SQLEXPR_TYPE_VALUE 3
enum
SQL_NODE_TYPE
{
enum
SQL_NODE_TYPE
{
SQL_NODE_TABLE_COLUMN
=
1
,
SQL_NODE_TABLE_COLUMN
=
1
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录