Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f350ade4
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f350ade4
编写于
6月 16, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: the unique function and tail function are rewritten as the corresponding clauses
上级
e224d404
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
59 addition
and
26 deletion
+59
-26
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+3
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+6
-1
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+20
-0
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+3
-0
tests/system-test/2-query/tail.py
tests/system-test/2-query/tail.py
+12
-11
tests/system-test/2-query/unique.py
tests/system-test/2-query/unique.py
+15
-14
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
f350ade4
...
...
@@ -376,6 +376,9 @@ bool nodesIsComparisonOp(const SOperatorNode* pOp);
bool
nodesIsJsonOp
(
const
SOperatorNode
*
pOp
);
bool
nodesIsRegularOp
(
const
SOperatorNode
*
pOp
);
bool
nodesExprHasColumn
(
SNode
*
pNode
);
bool
nodesExprsHasColumn
(
SNodeList
*
pList
);
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
);
int32_t
nodesSetValueNodeValue
(
SValueNode
*
pNode
,
void
*
value
);
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
f350ade4
...
...
@@ -1085,7 +1085,12 @@ static int32_t translateUnique(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
invaildFuncParaNumErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
pFunc
->
node
.
resType
=
((
SExprNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
))
->
resType
;
SNode
*
pPara
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
if
(
!
nodesExprHasColumn
(
pPara
))
{
return
buildFuncErrMsg
(
pErrBuf
,
len
,
TSDB_CODE_FUNC_FUNTION_ERROR
,
"The parameters of UNIQUE must contain columns"
);
}
pFunc
->
node
.
resType
=
((
SExprNode
*
)
pPara
)
->
resType
;
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
f350ade4
...
...
@@ -1463,6 +1463,26 @@ int32_t nodesCollectSpecialNodes(SSelectStmt* pSelect, ESqlClause clause, ENodeT
return
TSDB_CODE_SUCCESS
;
}
static
EDealRes
hasColumn
(
SNode
*
pNode
,
void
*
pContext
)
{
if
(
QUERY_NODE_COLUMN
==
nodeType
(
pNode
))
{
*
(
bool
*
)
pContext
=
true
;
return
DEAL_RES_END
;
}
return
DEAL_RES_CONTINUE
;
}
bool
nodesExprHasColumn
(
SNode
*
pNode
)
{
bool
hasCol
=
false
;
nodesWalkExprPostOrder
(
pNode
,
hasColumn
,
&
hasCol
);
return
hasCol
;
}
bool
nodesExprsHasColumn
(
SNodeList
*
pList
)
{
bool
hasCol
=
false
;
nodesWalkExprsPostOrder
(
pList
,
hasColumn
,
&
hasCol
);
return
hasCol
;
}
char
*
nodesGetFillModeString
(
EFillMode
mode
)
{
switch
(
mode
)
{
case
FILL_MODE_NONE
:
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
f350ade4
...
...
@@ -2170,6 +2170,7 @@ static EDealRes rewriteSeletcValueFunc(STranslateContext* pCxt, SNode** pNode) {
}
strcpy
(
pFirst
->
functionName
,
"first"
);
TSWAP
(
pFirst
->
pParameterList
,
((
SFunctionNode
*
)
*
pNode
)
->
pParameterList
);
strcpy
(
pFirst
->
node
.
aliasName
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pFirst
;
pCxt
->
errCode
=
fmGetFuncInfo
(
pFirst
,
pCxt
->
msgBuf
.
buf
,
pCxt
->
msgBuf
.
len
);
...
...
@@ -2184,6 +2185,7 @@ static EDealRes rewriteUniqueFunc(SNode** pNode, void* pContext) {
if
(
FUNCTION_TYPE_UNIQUE
==
pFunc
->
funcType
)
{
SNode
*
pExpr
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
NODES_CLEAR_LIST
(
pFunc
->
pParameterList
);
strcpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
pExpr
;
pCxt
->
pExpr
=
pExpr
;
...
...
@@ -2238,6 +2240,7 @@ static EDealRes rewriteTailFunc(SNode** pNode, void* pContext) {
pCxt
->
offset
=
((
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
2
))
->
datum
.
i
;
}
SNode
*
pExpr
=
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
strcpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
((
SExprNode
*
)
*
pNode
)
->
aliasName
);
NODES_CLEAR_LIST
(
pFunc
->
pParameterList
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
pExpr
;
...
...
tests/system-test/2-query/tail.py
浏览文件 @
f350ade4
...
...
@@ -188,7 +188,8 @@ class TDTestCase:
def
check_tail_table
(
self
,
tbname
,
col_name
,
tail_rows
,
offset
):
tail_sql
=
f
"select tail(
{
col_name
}
,
{
tail_rows
}
,
{
offset
}
) from
{
tbname
}
"
equal_sql
=
f
"select
{
col_name
}
from (select ts ,
{
col_name
}
from
{
tbname
}
order by ts desc limit
{
tail_rows
}
offset
{
offset
}
) order by ts"
#equal_sql = f"select {col_name} from (select ts , {col_name} from {tbname} order by ts desc limit {tail_rows} offset {offset}) order by ts"
equal_sql
=
f
"select
{
col_name
}
from
{
tbname
}
order by ts desc limit
{
tail_rows
}
offset
{
offset
}
"
tdSql
.
query
(
tail_sql
)
tail_result
=
tdSql
.
queryResult
...
...
@@ -294,21 +295,21 @@ class TDTestCase:
tdSql
.
checkData
(
1
,
0
,
None
)
tdSql
.
query
(
"select tail(c1,3,2) from ct4 where c1 >2 "
)
tdSql
.
checkData
(
0
,
0
,
7
)
tdSql
.
checkData
(
0
,
0
,
5
)
tdSql
.
checkData
(
1
,
0
,
6
)
tdSql
.
checkData
(
2
,
0
,
5
)
tdSql
.
checkData
(
2
,
0
,
7
)
tdSql
.
query
(
"select tail(c1,2,1) from ct4 where c2 between 0 and 99999"
)
tdSql
.
checkData
(
0
,
0
,
2
)
tdSql
.
checkData
(
1
,
0
,
1
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
checkData
(
1
,
0
,
2
)
# tail with union all
tdSql
.
query
(
"select tail(c1,2,1) from ct4 union all select c1 from ct1"
)
tdSql
.
checkRows
(
15
)
tdSql
.
query
(
"select tail(c1,2,1) from ct4 union all select c1 from ct2"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
1
)
tdSql
.
checkData
(
1
,
0
,
0
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
checkData
(
1
,
0
,
1
)
tdSql
.
query
(
"select tail(c2,2,1) from ct4 union all select abs(c2)/2 from ct4"
)
tdSql
.
checkRows
(
14
)
...
...
@@ -336,16 +337,16 @@ class TDTestCase:
tdSql
.
query
(
"select tail(tb2.num,3,2) from tb1, tb2 where tb1.ts=tb2.ts "
)
tdSql
.
checkRows
(
3
)
tdSql
.
checkData
(
0
,
0
,
5
)
tdSql
.
checkData
(
0
,
0
,
7
)
tdSql
.
checkData
(
1
,
0
,
6
)
tdSql
.
checkData
(
2
,
0
,
7
)
tdSql
.
checkData
(
2
,
0
,
5
)
# nest query
# tdSql.query("select tail(c1,2) from (select c1 from ct1)")
tdSql
.
query
(
"select c1 from (select tail(c1,2) c1 from ct4)"
)
tdSql
.
checkRows
(
2
)
tdSql
.
checkData
(
0
,
0
,
0
)
tdSql
.
checkData
(
1
,
0
,
None
)
tdSql
.
checkData
(
0
,
0
,
None
)
tdSql
.
checkData
(
1
,
0
,
0
)
tdSql
.
query
(
"select sum(c1) from (select tail(c1,2) c1 from ct1)"
)
tdSql
.
checkRows
(
1
)
...
...
tests/system-test/2-query/unique.py
浏览文件 @
f350ade4
...
...
@@ -93,8 +93,8 @@ class TDTestCase:
"select unique(c1) , min(c1) from t1"
,
"select unique(c1) , spread(c1) from t1"
,
"select unique(c1) , diff(c1) from t1"
,
"select unique(c1) , abs(c1) from t1"
,
"select unique(c1) , c1 from t1"
,
#"select unique(c1) , abs(c1) from t1", # support
#
"select unique(c1) , c1 from t1",
"select unique from stb1 partition by tbname"
,
"select unique(123--123)==1 from stb1 partition by tbname"
,
"select unique(123) from stb1 partition by tbname"
,
...
...
@@ -104,21 +104,21 @@ class TDTestCase:
"select unique(c1 ,c2 ) from stb1 partition by tbname"
,
"select unique(c1 ,NULL) from stb1 partition by tbname"
,
"select unique(,) from stb1 partition by tbname;"
,
"select unique(floor(c1) ab from stb1 partition by tbname)"
,
"select unique(c1) as int from stb1 partition by tbname"
,
#"select unique(floor(c1) ab from stb1 partition by tbname)", # support
#
"select unique(c1) as int from stb1 partition by tbname",
"select unique('c1') from stb1 partition by tbname"
,
"select unique(NULL) from stb1 partition by tbname"
,
"select unique('') from stb1 partition by tbname"
,
"select unique(c%) from stb1 partition by tbname"
,
#"select unique(t1) from stb1 partition by tbname",
#"select unique(t1) from stb1 partition by tbname",
# support
"select unique(True) from stb1 partition by tbname"
,
"select unique(c1) , count(c1) from stb1 partition by tbname"
,
"select unique(c1) , avg(c1) from stb1 partition by tbname"
,
"select unique(c1) , min(c1) from stb1 partition by tbname"
,
"select unique(c1) , spread(c1) from stb1 partition by tbname"
,
"select unique(c1) , diff(c1) from stb1 partition by tbname"
,
"select unique(c1) , abs(c1) from stb1 partition by tbname"
,
"select unique(c1) , c1 from stb1 partition by tbname"
#"select unique(c1) , abs(c1) from stb1 partition by tbname", # support
#"select unique(c1) , c1 from stb1 partition by tbname" # support
]
for
error_sql
in
error_sql_lists
:
...
...
@@ -198,7 +198,7 @@ class TDTestCase:
unique_datas
=
[]
for
elem
in
unique_result
:
unique_datas
.
append
(
elem
[
0
])
unique_datas
.
sort
(
key
=
lambda
x
:
(
x
is
None
,
x
))
tdSql
.
query
(
origin_sql
)
origin_result
=
tdSql
.
queryResult
...
...
@@ -212,6 +212,7 @@ class TDTestCase:
continue
else
:
pre_unique
.
append
(
elem
)
pre_unique
.
sort
(
key
=
lambda
x
:
(
x
is
None
,
x
))
if
pre_unique
==
unique_datas
:
tdLog
.
info
(
" unique query check pass , unique sql is: %s"
%
unique_sql
)
...
...
@@ -266,16 +267,16 @@ class TDTestCase:
tdSql
.
checkRows
(
10
)
tdSql
.
error
(
"select unique(c1),tbname from ct1"
)
tdSql
.
error
(
"select unique(c1),t1 from ct1"
)
#tdSql.error("select unique(c1),t1 from ct1") #support
# unique with common col
tdSql
.
error
(
"select unique(c1) ,ts from ct1"
)
tdSql
.
error
(
"select unique(c1) ,c1 from ct1"
)
#
tdSql.error("select unique(c1) ,ts from ct1")
#
tdSql.error("select unique(c1) ,c1 from ct1")
# unique with scalar function
tdSql
.
error
(
"select unique(c1) ,abs(c1) from ct1"
)
#
tdSql.error("select unique(c1) ,abs(c1) from ct1")
tdSql
.
error
(
"select unique(c1) , unique(c2) from ct1"
)
tdSql
.
error
(
"select unique(c1) , abs(c2)+2 from ct1"
)
#
tdSql.error("select unique(c1) , abs(c2)+2 from ct1")
# unique with aggregate function
...
...
@@ -288,7 +289,7 @@ class TDTestCase:
tdSql
.
query
(
"select unique(c1) from ct4 where c1 is null"
)
tdSql
.
checkData
(
0
,
0
,
None
)
tdSql
.
query
(
"select unique(c1) from ct4 where c1 >2
"
)
tdSql
.
query
(
"select unique(c1) from ct4 where c1 >2"
)
tdSql
.
checkData
(
0
,
0
,
8
)
tdSql
.
checkData
(
1
,
0
,
7
)
tdSql
.
checkData
(
2
,
0
,
6
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录