Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
20406dd4
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看板
提交
20406dd4
编写于
11月 08, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-10564]Fix bugs in parser.
上级
4eebc5c4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
146 addition
and
151 deletion
+146
-151
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+11
-16
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+135
-135
未找到文件。
source/libs/parser/src/astValidate.c
浏览文件 @
20406dd4
...
...
@@ -2412,7 +2412,7 @@ int32_t addAggExprAndResColumn(SQueryStmtInfo* pQueryInfo, int32_t colIndex, tSq
SSourceParam
param
=
{
0
};
addIntoSourceParam
(
&
param
,
NULL
,
&
c
);
SExprInfo
*
pExpr
=
doAddOneExprInfo
(
pQueryInfo
,
functionId
,
&
param
,
colIndex
,
pTableMetaInfo
,
&
s
,
resInfo
.
intermediateBytes
,
token
,
finalResult
);
SExprInfo
*
pExpr
=
doAddOneExprInfo
(
pQueryInfo
,
"block_dist"
,
&
param
,
colIndex
,
pTableMetaInfo
,
&
s
,
resInfo
.
intermediateBytes
,
token
,
finalResult
);
int64_t
rowSize
=
pTableMetaInfo
->
pTableMeta
->
tableInfo
.
rowSize
;
addExprInfoParam
(
&
pExpr
->
base
,
(
char
*
)
&
rowSize
,
TSDB_DATA_TYPE_BIGINT
,
8
);
...
...
@@ -2724,7 +2724,7 @@ static int32_t handleTbnameProjection(SQueryStmtInfo* pQueryInfo, tSqlExprItem*
const
char
*
msg3
=
"tbname not allowed in outer query"
;
SSchema
colSchema
=
{
0
};
int32_t
functionId
=
0
;
char
*
funcName
=
NULL
;
if
(
outerQuery
)
{
// todo??
STableMetaInfo
*
pTableMetaInfo
=
getMetaInfo
(
pQueryInfo
,
pIndex
->
tableIndex
);
...
...
@@ -2746,10 +2746,10 @@ static int32_t handleTbnameProjection(SQueryStmtInfo* pQueryInfo, tSqlExprItem*
}
colSchema
=
pSchema
[
pIndex
->
columnIndex
];
func
tionId
=
FUNCTION_PRJ
;
func
Name
=
"project_col"
;
}
else
{
colSchema
=
*
getTbnameColumnSchema
();
func
tionId
=
FUNCTION_TAGPRJ
;
func
Name
=
"project_tag"
;
}
SSchema
resultSchema
=
colSchema
;
...
...
@@ -2764,7 +2764,7 @@ static int32_t handleTbnameProjection(SQueryStmtInfo* pQueryInfo, tSqlExprItem*
SSourceParam
param
=
{
0
};
addIntoSourceParam
(
&
param
,
NULL
,
&
c
);
doAddOneExprInfo
(
pQueryInfo
,
functionId
,
&
param
,
startPos
,
pTableMetaInfo
,
&
colSchema
,
0
,
rawName
,
true
);
doAddOneExprInfo
(
pQueryInfo
,
"project_tab"
,
&
param
,
startPos
,
pTableMetaInfo
,
&
colSchema
,
0
,
rawName
,
true
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -2991,7 +2991,6 @@ int32_t sqlExprToExprNode(tExprNode **pExpr, const tSqlExpr* pSqlExpr, SQuerySt
(
*
pExpr
)
->
nodeType
=
TEXPR_FUNCTION_NODE
;
(
*
pExpr
)
->
_function
.
pChild
=
p
;
// (*pExpr)->_function.functionId = functionId;
strncpy
((
*
pExpr
)
->
_function
.
functionName
,
pSqlExpr
->
Expr
.
operand
.
z
,
pSqlExpr
->
Expr
.
operand
.
n
);
return
TSDB_CODE_SUCCESS
;
}
else
{
...
...
@@ -3077,11 +3076,7 @@ int32_t sqlExprToExprNode(tExprNode **pExpr, const tSqlExpr* pSqlExpr, SQuerySt
SSchema
*
pSchema
=
getOneColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
*
(
*
pExpr
)
->
pSchema
=
*
pSchema
;
if
(
pCols
!=
NULL
)
{
// record the involved columns
SColumn
c
=
createColumn
(
pTableMeta
->
uid
,
pTableMetaInfo
->
aliasName
,
TSDB_COL_NORMAL
,
(
*
pExpr
)
->
pSchema
);
taosArrayPush
(
pCols
,
&
c
);
}
columnListInsert
(
pQueryInfo
->
colList
,
pTableMeta
->
uid
,
pSchema
,
TSDB_COL_NORMAL
);
return
TSDB_CODE_SUCCESS
;
}
else
if
(
pSqlExpr
->
tokenId
==
TK_SET
)
{
int32_t
colType
=
-
1
;
...
...
@@ -3188,11 +3183,6 @@ static int32_t addScalarExprAndResColumn(SQueryStmtInfo* pQueryInfo, int32_t exp
for
(
int32_t
i
=
0
;
i
<
num
;
++
i
)
{
SColumn
*
pCol
=
taosArrayGet
(
pColumnList
,
i
);
pExpr
->
base
.
pColumns
[
i
]
=
*
pCol
;
if
(
pCol
->
flag
==
TSDB_COL_NORMAL
)
{
SSchema
sch
=
createSchema
(
pCol
->
info
.
type
,
pCol
->
info
.
bytes
,
pCol
->
info
.
colId
,
pCol
->
name
);
columnListInsert
(
pQueryInfo
->
colList
,
pCol
->
uid
,
&
sch
,
pCol
->
flag
);
}
}
pExpr
->
base
.
numOfCols
=
num
;
...
...
@@ -3214,6 +3204,11 @@ static int32_t addScalarExprAndResColumn(SQueryStmtInfo* pQueryInfo, int32_t exp
tbufCloseWriter
(
&
bw
);
if
(
pQueryInfo
->
exprListLevelIndex
==
0
)
{
int32_t
exists
=
getNumOfFields
(
&
pQueryInfo
->
fieldsInfo
);
addResColumnInfo
(
pQueryInfo
,
exists
,
&
pExpr
->
base
.
resSchema
,
pExpr
);
}
// tbufCloseWriter(&bw); // TODO there is a memory leak
taosArrayDestroy
(
pColumnList
);
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
20406dd4
...
...
@@ -37,7 +37,7 @@ void setSchema(SSchema* p, int32_t type, int32_t bytes, const char* name, int32_
strcpy
(
p
->
name
,
name
);
}
void
setTableMetaInfo
(
SQueryStmtInfo
*
pQueryInfo
,
SMetaReq
*
req
)
{
void
setTableMetaInfo
(
SQueryStmtInfo
*
pQueryInfo
,
SMetaReq
*
req
)
{
pQueryInfo
->
numOfTables
=
1
;
pQueryInfo
->
pTableMetaInfo
=
(
STableMetaInfo
**
)
calloc
(
1
,
POINTER_BYTES
);
...
...
@@ -55,7 +55,7 @@ void setTableMetaInfo(SQueryStmtInfo* pQueryInfo, SMetaReq *req) {
pTableMeta
->
tableInfo
.
rowSize
=
28
;
pTableMeta
->
uid
=
110
;
pTableMetaInfo
->
tagColList
=
(
SArray
*
)
taosArrayInit
(
4
,
POINTER_BYTES
);
pTableMetaInfo
->
tagColList
=
(
SArray
*
)
taosArrayInit
(
4
,
POINTER_BYTES
);
SSchema
*
pSchema
=
pTableMetaInfo
->
pTableMeta
->
schema
;
setSchema
(
&
pSchema
[
0
],
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"ts"
,
0
);
...
...
@@ -75,8 +75,8 @@ void sqlCheck(const char* sql, bool valid) {
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
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
};
...
...
@@ -101,7 +101,7 @@ void sqlCheck(const char* sql, bool valid) {
destroySqlInfo
(
&
info1
);
}
}
}
// namespace
//TEST(testCase, validateAST_test) {
// SSqlInfo info1 = doGenerateAST("select a a1111, a+b + 22, tbname from `t.1abc` where ts<now+2h and `col` < 20 + 99");
...
...
@@ -112,8 +112,8 @@ void sqlCheck(const char* sql, bool valid) {
// buf.len = 128;
// buf.buf = msg;
//
// SSqlNode* pNode = (SSqlNode*)
taosArrayGetP(((SArray*)info1.list), 0);
// int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
// 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};
...
...
@@ -130,27 +130,27 @@ void sqlCheck(const char* sql, bool valid) {
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 3);
//
// SExprInfo* p1 = (SExprInfo*)
taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->
info.colI
d, 110);
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->
ui
d, 110);
// ASSERT_EQ(p1->base.numOfParams, 0);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_INT);
// ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1111");
// ASSERT_STRCASEEQ(p1->base.pColumns->name, "t.1abc.a");
// ASSERT_EQ(p1->base.pColumns->info.colId, 1);
// ASSERT_EQ(p1->base.pColumns->flag, TSDB_COL_NORMAL);
// ASSERT_STRCASEEQ(p1->base.token, "a");
// ASSERT_STRCASEEQ(p1->base.token, "a
1111
");
//
// ASSERT_EQ(taosArrayGetSize(pExprList), 3);
//
// SExprInfo* p2 = (SExprInfo*)
taosArrayGetP(pExprList, 1);
// ASSERT_EQ(p2->base.pColumns->uid, 0);
// SExprInfo* p2 = (SExprInfo*)taosArrayGetP(pExprList, 1);
// ASSERT_EQ(p2->base.pColumns->uid,
11
0);
// ASSERT_EQ(p2->base.numOfParams, 1); // it is the serialized binary string of expression.
// ASSERT_EQ(p2->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
// ASSERT_STRCASEEQ(p2->base.resSchema.name, "a+b + 22");
//
//// ASSERT_STRCASEEQ(p2->base.colInfo.name, "t.1abc.a");
//// ASSERT_EQ(p1->base.colInfo.colId, 1);
//// ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
//
// ASSERT_STRCASEEQ(p2->base.colInfo.name, "t.1abc.a");
//
// ASSERT_EQ(p1->base.colInfo.colId, 1);
//
// ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
// ASSERT_STRCASEEQ(p2->base.token, "a+b + 22");
//
// ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
...
...
@@ -170,8 +170,8 @@ void sqlCheck(const char* sql, bool valid) {
// buf.len = 128;
// buf.buf = msg;
//
// SSqlNode* pNode = (SSqlNode*)
taosArrayGetP(((SArray*)info1.list), 0);
// int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
// 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};
...
...
@@ -188,7 +188,7 @@ void sqlCheck(const char* sql, bool valid) {
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 1);
//
// SExprInfo* p1 = (SExprInfo*)
taosArrayGetP(pExprList, 0);
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
// ASSERT_EQ(p1->base.numOfParams, 0);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT);
...
...
@@ -216,8 +216,8 @@ void sqlCheck(const char* sql, bool valid) {
// buf.len = 128;
// buf.buf = msg;
//
// SSqlNode* pNode = (SSqlNode*)
taosArrayGetP(((SArray*)info1.list), 0);
// int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
// 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};
...
...
@@ -234,7 +234,7 @@ void sqlCheck(const char* sql, bool valid) {
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 1);
//
// SExprInfo* p1 = (SExprInfo*)
taosArrayGetP(pExprList, 0);
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
// ASSERT_EQ(p1->base.numOfParams, 0);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT);
...
...
@@ -262,8 +262,8 @@ void sqlCheck(const char* sql, bool valid) {
// buf.len = 128;
// buf.buf = msg;
//
// SSqlNode* pNode = (SSqlNode*)
taosArrayGetP(((SArray*)info1.list), 0);
// int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
// 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};
...
...
@@ -278,9 +278,9 @@ void sqlCheck(const char* sql, bool valid) {
// ret = validateSqlNode(pSqlNode, pQueryInfo, &buf);
//
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList),
4
);
// ASSERT_EQ(taosArrayGetSize(pExprList),
6
);
//
// SExprInfo* p1 = (SExprInfo*)
taosArrayGetP(pExprList, 0);
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
// ASSERT_EQ(p1->base.numOfParams, 0);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_TIMESTAMP);
...
...
@@ -291,7 +291,7 @@ void sqlCheck(const char* sql, bool valid) {
// ASSERT_STRCASEEQ(p1->base.token, "first(ts)");
// ASSERT_EQ(p1->base.interBytes, 24);
//
// ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput,
4
);
// ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput,
6
);
//
// destroyQueryInfo(pQueryInfo);
// qParserClearupMetaRequestInfo(&req);
...
...
@@ -299,7 +299,7 @@ void sqlCheck(const char* sql, bool valid) {
//}
//
//TEST(testCase, function_Test4) {
// SSqlInfo info1 = doGenerateAST("select
_
block_dist() as a1 from `t.1abc`");
// SSqlInfo info1 = doGenerateAST("select block_dist() as a1 from `t.1abc`");
// ASSERT_EQ(info1.valid, true);
//
// char msg[128] = {0};
...
...
@@ -307,8 +307,8 @@ void sqlCheck(const char* sql, bool valid) {
// buf.len = 128;
// buf.buf = msg;
//
// SSqlNode* pNode = (SSqlNode*)
taosArrayGetP(((SArray*)info1.list), 0);
// int32_t code = evaluateSqlNode(pNode, TSDB_TIME_PRECISION_NANO, &buf);
// 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};
...
...
@@ -325,15 +325,15 @@ void sqlCheck(const char* sql, bool valid) {
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 1);
//
// SExprInfo* p1 = (SExprInfo*)
taosArrayGetP(pExprList, 0);
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
// ASSERT_EQ(p1->base.numOfParams, 1);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BINARY);
// ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
//// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
//// ASSERT_EQ(p1->base.colInfo.colId, 0);
// ASSERT_EQ(p1->base.pColumns->flag, TSDB_COL_
NORMAL
);
// ASSERT_STRCASEEQ(p1->base.token, "
_
block_dist()");
//
// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
//
// ASSERT_EQ(p1->base.colInfo.colId, 0);
// ASSERT_EQ(p1->base.pColumns->flag, TSDB_COL_
UDC
);
// ASSERT_STRCASEEQ(p1->base.token, "block_dist()");
// ASSERT_EQ(p1->base.interBytes, 0);
//
// ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 1);
...
...
@@ -344,71 +344,10 @@ void sqlCheck(const char* sql, bool valid) {
// destroySqlInfo(&info1);
//}
//TEST(testCase, function_Test5) {
// //todo select concat(concat(a, b), concat(b, a)) from `t.1abc`;
//
// SSqlInfo info1 = doGenerateAST("select sum(a) + avg(b) as a1 from `t.1abc`");
// 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);
//
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 3);
//
// SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.numOfCols, 2);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
//
// ASSERT_EQ(p1->base.numOfParams, 1);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
// ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
//
// ASSERT_EQ(p1->base.pColumns->flag, TSDB_COL_NORMAL);
// ASSERT_STRCASEEQ(p1->base.token, "sum(a) + avg(b)");
// ASSERT_EQ(p1->base.interBytes, 0);
//
// ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
// ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 1);
//
// destroyQueryInfo(pQueryInfo);
// qParserClearupMetaRequestInfo(&req);
// destroySqlInfo(&info1);
//}
TEST
(
testCase
,
function_Test5
)
{
// todo select concat(concat(a, b), concat(b, a)) from `t.1abc`;
//TEST(testCase, function_Test10) {
// sqlCheck("select c from `t.1abc`", true);
// sqlCheck("select length(c) from `t.1abc`", true);
// sqlCheck("select sum(length(a+b)) from `t.1abc`", true);
// sqlCheck("select sum(sum(a+b)) from `t.1abc`", false);
// sqlCheck("select sum(length(a) + length(b)) from `t.1abc`", true);
// sqlCheck("select length(sum(a) + sum(b)) + length(sum(a) + sum(b)) from `t.1abc`", true);
// sqlCheck("select sum(length(sum(a))) from `t.1abc`", true);
// sqlCheck("select cov(a, b) 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);
//}
TEST
(
testCase
,
function_Test6
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select sum(a+b) as a1, first(b*a), count(b+b), count(1), count(42.1) from `t.1abc` interval(10s, 1s)"
);
SSqlInfo
info1
=
doGenerateAST
(
"select sum(a) + avg(b) as a1 from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
...
...
@@ -416,8 +355,8 @@ TEST(testCase, function_Test6) {
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
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
};
...
...
@@ -433,53 +372,114 @@ TEST(testCase, function_Test6) {
ASSERT_EQ
(
ret
,
0
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
[
0
];
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
5
);
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
3
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
numOfCols
,
2
);
ASSERT_EQ
(
p1
->
base
.
pColumns
->
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
1
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"a1"
);
ASSERT_EQ
(
p1
->
base
.
pColumns
->
flag
,
TSDB_COL_TMP
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"sum(a+b)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
16
);
ASSERT_EQ
(
p1
->
pExpr
->
nodeType
,
TEXPR_FUNCTION_NODE
);
ASSERT_STRCASEEQ
(
p1
->
pExpr
->
_function
.
functionName
,
"sum"
);
ASSERT_EQ
(
p1
->
pExpr
->
_function
.
num
,
1
);
tExprNode
*
pParam
=
p1
->
pExpr
->
_function
.
pChild
[
0
];
ASSERT_EQ
(
pParam
->
nodeType
,
TEXPR_COL_NODE
);
ASSERT_STREQ
(
pParam
->
pSchema
->
name
,
"t.1abc.a+b"
);
ASSERT_EQ
(
p1
->
base
.
pColumns
->
flag
,
TSDB_COL_TMP
);
ASSERT_STREQ
(
p1
->
base
.
pColumns
->
name
,
"sum(a)"
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"sum(a) + avg(b)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
3
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
5
);
SExprInfo
*
p2
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
1
);
ASSERT_EQ
(
p2
->
base
.
pColumns
->
uid
,
110
);
ASSERT_EQ
(
p2
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p2
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_STRCASEEQ
(
p2
->
base
.
resSchema
.
name
,
"first(b*a)"
);
ASSERT_EQ
(
p2
->
base
.
pColumns
->
flag
,
TSDB_COL_TMP
);
ASSERT_STREQ
(
p2
->
base
.
pColumns
->
name
,
"t.1abc.b*a"
);
ASSERT_STRCASEEQ
(
p2
->
base
.
token
,
"first(b*a)"
);
ASSERT_EQ
(
p2
->
base
.
interBytes
,
24
);
ASSERT_EQ
(
p2
->
pExpr
->
nodeType
,
TEXPR_FUNCTION_NODE
);
ASSERT_STRCASEEQ
(
p2
->
pExpr
->
_function
.
functionName
,
"first"
);
ASSERT_EQ
(
p2
->
pExpr
->
_function
.
num
,
1
);
ASSERT_EQ
(
p2
->
pExpr
->
_function
.
pChild
[
0
]
->
nodeType
,
TEXPR_COL_NODE
);
ASSERT_STREQ
(
p2
->
pExpr
->
_function
.
pChild
[
0
]
->
pSchema
->
name
,
"t.1abc.b*a"
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
destroyQueryInfo
(
pQueryInfo
);
qParserClearupMetaRequestInfo
(
&
req
);
destroySqlInfo
(
&
info1
);
}
//TEST(testCase, function_Test10) {
// sqlCheck("select c from `t.1abc`", true);
// sqlCheck("select length(c) from `t.1abc`", true);
// sqlCheck("select sum(length(a+b)) from `t.1abc`", true);
// sqlCheck("select sum(sum(a+b)) from `t.1abc`", false);
// sqlCheck("select sum(length(a) + length(b)) from `t.1abc`", true);
// sqlCheck("select length(sum(a) + sum(b)) + length(sum(a) + sum(b)) from `t.1abc`", true);
// sqlCheck("select sum(length(sum(a))) from `t.1abc`", true);
// sqlCheck("select cov(a, b) 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);
//}
//
//TEST(testCase, function_Test6) {
// SSqlInfo info1 = doGenerateAST(
// "select sum(a+b) as a1, first(b*a), count(b+b), count(1), count(42.1) from `t.1abc` interval(10s, 1s)");
// 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);
//
// SArray* pExprList = pQueryInfo->exprList[0];
// ASSERT_EQ(taosArrayGetSize(pExprList), 5);
//
// SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0);
// ASSERT_EQ(p1->base.pColumns->uid, 110);
// ASSERT_EQ(p1->base.numOfParams, 0);
// ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
// ASSERT_STRCASEEQ(p1->base.resSchema.name, "a1");
// ASSERT_EQ(p1->base.pColumns->flag, TSDB_COL_TMP);
// ASSERT_STRCASEEQ(p1->base.token, "sum(a+b)");
// ASSERT_EQ(p1->base.interBytes, 16);
// ASSERT_EQ(p1->pExpr->nodeType, TEXPR_FUNCTION_NODE);
// ASSERT_STRCASEEQ(p1->pExpr->_function.functionName, "sum");
// ASSERT_EQ(p1->pExpr->_function.num, 1);
//
// tExprNode* pParam = p1->pExpr->_function.pChild[0];
//
// ASSERT_EQ(pParam->nodeType, TEXPR_COL_NODE);
// ASSERT_STREQ(pParam->pSchema->name, "t.1abc.a+b");
//
// ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
// ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 5);
//
// SExprInfo* p2 = (SExprInfo*)taosArrayGetP(pExprList, 1);
// ASSERT_EQ(p2->base.pColumns->uid, 110);
// ASSERT_EQ(p2->base.numOfParams, 0);
// ASSERT_EQ(p2->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
// ASSERT_STRCASEEQ(p2->base.resSchema.name, "first(b*a)");
//
// ASSERT_EQ(p2->base.pColumns->flag, TSDB_COL_TMP);
// ASSERT_STREQ(p2->base.pColumns->name, "t.1abc.b*a");
//
// ASSERT_STRCASEEQ(p2->base.token, "first(b*a)");
// ASSERT_EQ(p2->base.interBytes, 24);
// ASSERT_EQ(p2->pExpr->nodeType, TEXPR_FUNCTION_NODE);
// ASSERT_STRCASEEQ(p2->pExpr->_function.functionName, "first");
// ASSERT_EQ(p2->pExpr->_function.num, 1);
// ASSERT_EQ(p2->pExpr->_function.pChild[0]->nodeType, TEXPR_COL_NODE);
// ASSERT_STREQ(p2->pExpr->_function.pChild[0]->pSchema->name, "t.1abc.b*a");
//
// destroyQueryInfo(pQueryInfo);
// qParserClearupMetaRequestInfo(&req);
// destroySqlInfo(&info1);
//}
//TEST(testCase, function_Test7) {
//
TEST(testCase, function_Test7) {
// SSqlInfo info1 = doGenerateAST("select count(a+b),count(1) from `t.1abc` interval(10s, 1s)");
// ASSERT_EQ(info1.valid, true);
//
...
...
@@ -534,7 +534,7 @@ TEST(testCase, function_Test6) {
// destroySqlInfo(&info1);
//}
//
//TEST(testCase, function_Test8) {
//
TEST(testCase, function_Test8) {
// SSqlInfo info1 = doGenerateAST("select top(a*b / 99, 20) from `t.1abc` interval(10s, 1s)");
// ASSERT_EQ(info1.valid, true);
//
...
...
@@ -590,7 +590,7 @@ TEST(testCase, function_Test6) {
// destroySqlInfo(&info1);
//}
//
//TEST(testCase, invalid_sql_Test) {
//
TEST(testCase, invalid_sql_Test) {
// char msg[128] = {0};
// SMsgBuf buf;
// buf.len = 128;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录