Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Rattenking
TDengine
提交
a3e77f23
T
TDengine
项目概览
Rattenking
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a3e77f23
编写于
8月 25, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-1213]
上级
dac0a985
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
10 addition
and
26 deletion
+10
-26
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+10
-26
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
a3e77f23
...
...
@@ -1111,42 +1111,31 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
}
int32_t
tableIndex
=
columnList
.
ids
[
0
].
tableIndex
;
// todo potential data overflow
char
*
arithmeticExprStr
=
malloc
(
1024
*
1024
);
char
*
p
=
arithmeticExprStr
;
if
(
arithmeticType
==
NORMAL_ARITHMETIC
)
{
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
// all columns in arithmetic expression must belong to the same table
for
(
int32_t
f
=
1
;
f
<
columnList
.
num
;
++
f
)
{
if
(
columnList
.
ids
[
f
].
tableIndex
!=
tableIndex
)
{
taosTFree
(
arithmeticExprStr
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
}
if
(
arithmeticExprToString
(
pItem
->
pNode
,
&
p
)
!=
TSDB_CODE_SUCCESS
)
{
taosTFree
(
arithmeticExprStr
);
return
TSDB_CODE_TSC_INVALID_SQL
;
}
// expr string is set as the parameter of function
SColumnIndex
index
=
{.
tableIndex
=
tableIndex
};
SSqlExpr
*
pExpr
=
tscSqlExprAppend
(
pQueryInfo
,
TSDB_FUNC_ARITHM
,
&
index
,
TSDB_DATA_TYPE_DOUBLE
,
sizeof
(
double
),
sizeof
(
double
),
false
);
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
arithmeticExprStr
;
tstrncpy
(
pExpr
->
aliasName
,
name
,
sizeof
(
pExpr
->
aliasName
));
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
pItem
->
pNode
->
token
.
z
;
size_t
len
=
MIN
(
sizeof
(
pExpr
->
aliasName
),
pItem
->
pNode
->
token
.
n
+
1
);
tstrncpy
(
pExpr
->
aliasName
,
name
,
len
);
tExprNode
*
pNode
=
NULL
;
SArray
*
colList
=
taosArrayInit
(
10
,
sizeof
(
SColIndex
));
int32_t
ret
=
exprTreeFromSqlExpr
(
pCmd
,
&
pNode
,
pItem
->
pNode
,
pQueryInfo
->
exprList
,
pQueryInfo
,
colList
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosTFree
(
arithmeticExprStr
);
taosArrayDestroy
(
colList
);
tExprTreeDestroy
(
&
pNode
,
NULL
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
...
...
@@ -1157,7 +1146,6 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
SColIndex
*
pIndex
=
taosArrayGet
(
colList
,
k
);
if
(
TSDB_COL_IS_TAG
(
pIndex
->
flag
))
{
tExprTreeDestroy
(
&
pNode
,
NULL
);
taosTFree
(
arithmeticExprStr
);
taosArrayDestroy
(
colList
);
tExprTreeDestroy
(
&
pNode
,
NULL
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
...
...
@@ -1174,7 +1162,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
// TODO: other error handling
}
END_TRY
size_t
len
=
tbufTell
(
&
bw
);
len
=
tbufTell
(
&
bw
);
char
*
c
=
tbufGetData
(
&
bw
,
true
);
// set the serialized binary string as the parameter of arithmetic expression
...
...
@@ -1185,16 +1173,14 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
taosArrayDestroy
(
colList
);
tExprTreeDestroy
(
&
pNode
,
NULL
);
}
else
{
if
(
arithmeticExprToString
(
pItem
->
pNode
,
&
p
)
!=
TSDB_CODE_SUCCESS
)
{
taosTFree
(
arithmeticExprStr
);
return
TSDB_CODE_TSC_INVALID_SQL
;
}
columnList
.
num
=
0
;
columnList
.
ids
[
0
]
=
(
SColumnIndex
)
{
0
,
0
};
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
arithmeticExprStr
;
insertResultField
(
pQueryInfo
,
exprIndex
,
&
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
name
,
NULL
);
char
*
name
=
(
pItem
->
aliasName
!=
NULL
)
?
pItem
->
aliasName
:
pItem
->
pNode
->
token
.
z
;
size_t
len
=
MIN
(
sizeof
(
pItem
->
aliasName
),
pItem
->
pNode
->
token
.
n
+
1
);
tstrncpy
(
pItem
->
aliasName
,
name
,
len
);
insertResultField
(
pQueryInfo
,
exprIndex
,
&
columnList
,
sizeof
(
double
),
TSDB_DATA_TYPE_DOUBLE
,
pItem
->
aliasName
,
NULL
);
int32_t
slot
=
tscNumOfFields
(
pQueryInfo
)
-
1
;
SFieldSupInfo
*
pInfo
=
tscFieldInfoGetSupp
(
&
pQueryInfo
->
fieldsInfo
,
slot
);
...
...
@@ -1210,7 +1196,6 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
int32_t
ret
=
exprTreeFromSqlExpr
(
pCmd
,
&
pArithExprInfo
->
pExpr
,
pItem
->
pNode
,
pQueryInfo
->
exprList
,
pQueryInfo
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
tExprTreeDestroy
(
&
pArithExprInfo
->
pExpr
,
NULL
);
taosTFree
(
arithmeticExprStr
);
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
"invalid expression in select clause"
);
}
...
...
@@ -1218,7 +1203,6 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, int32_t clauseIndex, int32_t
}
}
taosTFree
(
arithmeticExprStr
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -3170,7 +3154,7 @@ int32_t doArithmeticExprToString(tSQLExpr* pExpr, char** exprString) {
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
arithmeticExprToString
(
tSQLExpr
*
pExpr
,
char
**
str
)
{
static
UNUSED_FUNC
int32_t
arithmeticExprToString
(
tSQLExpr
*
pExpr
,
char
**
str
)
{
char
*
start
=
*
str
;
int32_t
code
=
doArithmeticExprToString
(
pExpr
,
str
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录