Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d97f1cc3
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看板
提交
d97f1cc3
编写于
5月 01, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: sql commadn 'select max(c1), c2 from t'
上级
d6cf6883
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
44 deletion
+60
-44
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+49
-35
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+9
-7
tests/system-test/2-query/distinct.py
tests/system-test/2-query/distinct.py
+2
-2
未找到文件。
source/libs/parser/src/parTranslater.c
浏览文件 @
d97f1cc3
...
@@ -268,6 +268,10 @@ static bool isSelectFunc(const SNode* pNode) {
...
@@ -268,6 +268,10 @@ static bool isSelectFunc(const SNode* pNode) {
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsSelectFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsSelectFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
}
}
static
bool
isTimelineFunc
(
const
SNode
*
pNode
)
{
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsTimelineFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
}
static
bool
isDistinctOrderBy
(
STranslateContext
*
pCxt
)
{
static
bool
isDistinctOrderBy
(
STranslateContext
*
pCxt
)
{
return
(
SQL_CLAUSE_ORDER_BY
==
pCxt
->
currClause
&&
pCxt
->
pCurrStmt
->
isDistinct
);
return
(
SQL_CLAUSE_ORDER_BY
==
pCxt
->
currClause
&&
pCxt
->
pCurrStmt
->
isDistinct
);
}
}
...
@@ -672,38 +676,6 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
...
@@ -672,38 +676,6 @@ static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount)
return
code
;
return
code
;
}
}
static
int32_t
createPrimaryKeyColByTable
(
STranslateContext
*
pCxt
,
STableNode
*
pTable
,
SNode
**
pPrimaryKey
)
{
SColumnNode
*
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
setColumnInfoBySchema
((
SRealTableNode
*
)
pTable
,
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
schema
,
false
,
pCol
);
}
else
{
// todo
}
*
pPrimaryKey
=
(
SNode
*
)
pCol
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
createPrimaryKeyCol
(
STranslateContext
*
pCxt
,
SNode
**
pPrimaryKey
)
{
STableNode
*
pTable
=
NULL
;
int32_t
code
=
findTable
(
pCxt
,
NULL
,
&
pTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createPrimaryKeyColByTable
(
pCxt
,
pTable
,
pPrimaryKey
);
}
return
code
;
}
static
int32_t
rewriteTimelineFunc
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
SNode
*
pPrimaryKey
=
NULL
;
int32_t
code
=
createPrimaryKeyCol
(
pCxt
,
&
pPrimaryKey
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
nodesListMakeStrictAppend
(
&
pFunc
->
pParameterList
,
pPrimaryKey
);
}
return
code
;
}
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
SFmGetFuncInfoParam
param
=
{.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
SFmGetFuncInfoParam
param
=
{.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
...
@@ -727,9 +699,6 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
...
@@ -727,9 +699,6 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
pCxt
->
errCode
=
rewriteCountStar
(
pCxt
,
pFunc
);
pCxt
->
errCode
=
rewriteCountStar
(
pCxt
,
pFunc
);
}
}
}
}
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
&&
fmIsTimelineFunc
(
pFunc
->
funcId
))
{
pCxt
->
errCode
=
rewriteTimelineFunc
(
pCxt
,
pFunc
);
}
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
;
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_CONTINUE
:
DEAL_RES_ERROR
;
}
}
...
@@ -1641,6 +1610,48 @@ static int32_t checkLimit(STranslateContext* pCxt, SSelectStmt* pSelect) {
...
@@ -1641,6 +1610,48 @@ static int32_t checkLimit(STranslateContext* pCxt, SSelectStmt* pSelect) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
static
int32_t
createPrimaryKeyColByTable
(
STranslateContext
*
pCxt
,
STableNode
*
pTable
,
SNode
**
pPrimaryKey
)
{
SColumnNode
*
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
if
(
NULL
==
pCol
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
QUERY_NODE_REAL_TABLE
==
nodeType
(
pTable
))
{
setColumnInfoBySchema
((
SRealTableNode
*
)
pTable
,
((
SRealTableNode
*
)
pTable
)
->
pMeta
->
schema
,
false
,
pCol
);
}
else
{
// todo
}
*
pPrimaryKey
=
(
SNode
*
)
pCol
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
createPrimaryKeyCol
(
STranslateContext
*
pCxt
,
SNode
**
pPrimaryKey
)
{
STableNode
*
pTable
=
NULL
;
int32_t
code
=
findTable
(
pCxt
,
NULL
,
&
pTable
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
createPrimaryKeyColByTable
(
pCxt
,
pTable
,
pPrimaryKey
);
}
return
code
;
}
static
EDealRes
rewriteTimelineFuncImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
STranslateContext
*
pCxt
=
pContext
;
if
(
isTimelineFunc
(
pNode
))
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
pNode
;
SNode
*
pPrimaryKey
=
NULL
;
pCxt
->
errCode
=
createPrimaryKeyCol
(
pCxt
,
&
pPrimaryKey
);
if
(
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
)
{
pCxt
->
errCode
=
nodesListMakeStrictAppend
(
&
pFunc
->
pParameterList
,
pPrimaryKey
);
}
return
TSDB_CODE_SUCCESS
==
pCxt
->
errCode
?
DEAL_RES_IGNORE_CHILD
:
DEAL_RES_ERROR
;
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteTimelineFunc
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
nodesWalkSelectStmt
(
pSelect
,
SQL_CLAUSE_FROM
,
rewriteTimelineFuncImpl
,
pCxt
);
return
pCxt
->
errCode
;
}
static
int32_t
translateSelect
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
static
int32_t
translateSelect
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
pCxt
->
pCurrStmt
=
pSelect
;
pCxt
->
pCurrStmt
=
pSelect
;
int32_t
code
=
translateFrom
(
pCxt
,
pSelect
);
int32_t
code
=
translateFrom
(
pCxt
,
pSelect
);
...
@@ -1671,6 +1682,9 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
...
@@ -1671,6 +1682,9 @@ static int32_t translateSelect(STranslateContext* pCxt, SSelectStmt* pSelect) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkLimit
(
pCxt
,
pSelect
);
code
=
checkLimit
(
pCxt
,
pSelect
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteTimelineFunc
(
pCxt
,
pSelect
);
}
return
code
;
return
code
;
}
}
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
d97f1cc3
...
@@ -67,27 +67,29 @@ TEST_F(ParserSelectTest, condition) {
...
@@ -67,27 +67,29 @@ TEST_F(ParserSelectTest, condition) {
TEST_F
(
ParserSelectTest
,
pseudoColumn
)
{
TEST_F
(
ParserSelectTest
,
pseudoColumn
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"SELECT _
wstartts, _wendts
, COUNT(*) FROM t1 INTERVAL(10s)"
);
run
(
"SELECT _
WSTARTTS, _WENDTS
, COUNT(*) FROM t1 INTERVAL(10s)"
);
}
}
TEST_F
(
ParserSelectTest
,
multiResFunc
)
{
TEST_F
(
ParserSelectTest
,
multiResFunc
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"SELECT
last(*), first(*), last_row
(*) FROM t1"
);
run
(
"SELECT
LAST(*), FIRST(*), LAST_ROW
(*) FROM t1"
);
run
(
"SELECT
last(c1, c2), first(t1.*), last_row
(c3) FROM t1"
);
run
(
"SELECT
LAST(c1, c2), FIRST(t1.*), LAST_ROW
(c3) FROM t1"
);
run
(
"SELECT
last(t2.*), first(t1.c1, t2.*), last_row
(t1.*, t2.*) FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts"
);
run
(
"SELECT
LAST(t2.*), FIRST(t1.c1, t2.*), LAST_ROW
(t1.*, t2.*) FROM st1s1 t1, st1s2 t2 WHERE t1.ts = t2.ts"
);
}
}
TEST_F
(
ParserSelectTest
,
timelineFunc
)
{
TEST_F
(
ParserSelectTest
,
timelineFunc
)
{
useDb
(
"root"
,
"test"
);
useDb
(
"root"
,
"test"
);
run
(
"SELECT
last(*), first
(*) FROM t1"
);
run
(
"SELECT
LAST(*), FIRST
(*) FROM t1"
);
run
(
"SELECT
last(*), first(*) FROM t1 GROUP BY c
1"
);
run
(
"SELECT
FIRST(ts), FIRST(c1), FIRST(c2), FIRST(c3) FROM t
1"
);
run
(
"SELECT last(*), first(*) FROM t1 INTERVAL(10s)"
);
run
(
"SELECT LAST(*), FIRST(*) FROM t1 GROUP BY c1"
);
run
(
"SELECT LAST(*), FIRST(*) FROM t1 INTERVAL(10s)"
);
run
(
"SELECT diff(c1) FROM t1"
);
run
(
"SELECT diff(c1) FROM t1"
);
}
}
...
...
tests/system-test/2-query/distinct.py
浏览文件 @
d97f1cc3
...
@@ -109,9 +109,9 @@ class TDTestCase:
...
@@ -109,9 +109,9 @@ class TDTestCase:
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) ")
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) ")
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) "
)
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)")
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 interval(1d) fill(next)")
tdSql
.
error
(
"select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)"
)
#
tdSql.error("select distinct c1, c2 from t1 where c1 > 3 interval(1d) fill(next)")
# tdSql.error("select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)")
# tdSql.error("select distinct c1, c2 from stb1 where ts > now-10d and ts < now interval(1d) fill(next)")
tdSql
.
error
(
"select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)"
)
#
tdSql.error("select distinct c1, c2 from t1 where ts > now-10d and ts < now interval(1d) fill(next)")
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 slimit 1")
# tdSql.error("select distinct c1, c2 from stb1 where c1 > 3 slimit 1")
# tdSql.error("select distinct c1, c2 from t1 where c1 > 3 slimit 1")
# tdSql.error("select distinct c1, c2 from t1 where c1 > 3 slimit 1")
# tdSql.query(f"select distinct c1, c2 from stb1 where c1 between {tbnum-2} and {tbnum} ")
# tdSql.query(f"select distinct c1, c2 from stb1 where c1 between {tbnum-2} and {tbnum} ")
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录