Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a7058d81
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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,发现更多精彩内容 >>
提交
a7058d81
编写于
11月 09, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-10564] Fix bug in parse sql.
上级
bdcaeff1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
57 addition
and
7 deletion
+57
-7
source/libs/parser/inc/sql.y
source/libs/parser/inc/sql.y
+0
-3
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+8
-2
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+4
-2
source/libs/parser/test/plannerTest.cpp
source/libs/parser/test/plannerTest.cpp
+45
-0
未找到文件。
source/libs/parser/inc/sql.y
浏览文件 @
a7058d81
...
...
@@ -30,7 +30,6 @@
#include "tmsgtype.h"
#include "ttoken.h"
#include "ttokendef.h"
//#include "tutil.h"
#include "tvariant.h"
}
...
...
@@ -784,10 +783,8 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A). {
cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
toTSDBType(A.type);
SArray* K = tListItemAppendToken(NULL, &A, -1);
SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
...
...
source/libs/parser/src/astValidate.c
浏览文件 @
a7058d81
...
...
@@ -2017,12 +2017,18 @@ int32_t extractFunctionParameterInfo(SQueryStmtInfo* pQueryInfo, int32_t tokenId
static
int32_t
checkForkParam
(
tSqlExpr
*
pSqlExpr
,
size_t
k
,
SMsgBuf
*
pMsgBuf
)
{
const
char
*
msg1
=
"invalid parameters"
;
SArray
*
pParamList
=
pSqlExpr
->
Expr
.
paramList
;
if
(
k
==
0
)
{
if
(
p
SqlExpr
->
Expr
.
paramList
!=
NULL
&&
taosArrayGetSize
(
pSqlExpr
->
Expr
.
p
aramList
)
!=
0
)
{
if
(
p
ParamList
!=
NULL
&&
taosArrayGetSize
(
pP
aramList
)
!=
0
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
}
else
if
(
k
==
1
)
{
if
(
!
(
pParamList
==
NULL
||
taosArrayGetSize
(
pParamList
)
==
k
))
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);;
}
}
else
{
if
(
p
SqlExpr
->
Expr
.
paramList
==
NULL
||
taosArrayGetSize
(
pSqlExpr
->
Expr
.
p
aramList
)
!=
k
)
{
if
(
p
ParamList
!=
NULL
&&
taosArrayGetSize
(
pP
aramList
)
!=
k
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
}
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
a7058d81
...
...
@@ -406,8 +406,10 @@ TEST(testCase, function_Test10) {
sqlCheck
(
"select cov(a, b) from `t.1abc`"
,
true
);
sqlCheck
(
"select sum(length(a) + count(b)) from `t.1abc`"
,
false
);
sqlCheck
(
"select concat(concat(a,b), concat(a,b)) from `t.1abc`"
,
true
);
sqlCheck
(
"select length(length(length(a))) from `t.1abc`"
,
true
);
sqlCheck
(
"select concat(concat(a,b), concat(a,b)) from `t.1abc`"
,
true
);
sqlCheck
(
"select length(length(length(a))) from `t.1abc`"
,
true
);
sqlCheck
(
"select count() from `t.1abc`"
,
false
);
sqlCheck
(
"select block_dist() from `t.1abc`"
,
true
);
}
TEST
(
testCase
,
function_Test6
)
{
...
...
source/libs/parser/test/plannerTest.cpp
浏览文件 @
a7058d81
...
...
@@ -64,6 +64,44 @@ void setTableMetaInfo(SQueryStmtInfo* pQueryInfo, SMetaReq *req) {
setSchema
(
&
pSchema
[
2
],
TSDB_DATA_TYPE_DOUBLE
,
8
,
"b"
,
2
);
setSchema
(
&
pSchema
[
3
],
TSDB_DATA_TYPE_DOUBLE
,
8
,
"col"
,
3
);
}
void
generateLogicplan
(
const
char
*
sql
)
{
SSqlInfo
info1
=
doGenerateAST
(
sql
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
createQueryInfo
();
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
ASSERT_EQ
(
ret
,
0
);
struct
SQueryPlanNode
*
n
=
nullptr
;
code
=
qCreateQueryPlan
(
pQueryInfo
,
&
n
);
char
*
str
=
NULL
;
qQueryPlanToString
(
n
,
&
str
);
printf
(
"%s
\n
"
,
str
);
destroyQueryInfo
(
pQueryInfo
);
qParserClearupMetaRequestInfo
(
&
req
);
destroySqlInfo
(
&
info1
);
}
}
...
...
@@ -123,4 +161,11 @@ TEST(testCase, planner_test) {
destroyQueryInfo
(
pQueryInfo
);
qParserClearupMetaRequestInfo
(
&
req
);
destroySqlInfo
(
&
info1
);
}
TEST
(
testCase
,
displayPlan
)
{
generateLogicplan
(
"select count(*) from `t.1abc`"
);
generateLogicplan
(
"select count(*) from `t.1abc` group by a"
);
generateLogicplan
(
"select count(*) from `t.1abc` interval(10s, 5s) sliding(7s)"
);
generateLogicplan
(
"select count(*),sum(a),avg(b),min(a+b) from `t.1abc`"
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录