Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a64a0320
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
a64a0320
编写于
7月 10, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some problem of parser and planner
上级
2454298b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
56 addition
and
72 deletion
+56
-72
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+2
-0
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+1
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+43
-63
source/libs/parser/test/parSelectTest.cpp
source/libs/parser/test/parSelectTest.cpp
+3
-3
source/libs/planner/test/planPartByTest.cpp
source/libs/planner/test/planPartByTest.cpp
+2
-0
tests/system-test/1-insert/time_range_wise.py
tests/system-test/1-insert/time_range_wise.py
+5
-5
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
a64a0320
...
...
@@ -250,6 +250,7 @@ typedef struct SSelectStmt {
SLimitNode
*
pSlimit
;
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
int32_t
selectFuncNum
;
bool
isEmptyResult
;
bool
isTimeLineResult
;
bool
hasAggFuncs
;
...
...
@@ -257,6 +258,7 @@ typedef struct SSelectStmt {
bool
hasIndefiniteRowsFunc
;
bool
hasSelectFunc
;
bool
hasSelectValFunc
;
bool
hasOtherVectorFunc
;
bool
hasUniqueFunc
;
bool
hasTailFunc
;
bool
hasInterpFunc
;
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
a64a0320
...
...
@@ -139,7 +139,7 @@ bool fmIsAggFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MG
bool
fmIsScalarFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_SCALAR_FUNC
);
}
bool
fmIsVectorFunc
(
int32_t
funcId
)
{
return
!
fmIsScalarFunc
(
funcId
);
}
bool
fmIsVectorFunc
(
int32_t
funcId
)
{
return
!
fmIsScalarFunc
(
funcId
)
&&
!
fmIsScanPseudoColumnFunc
(
funcId
)
;
}
bool
fmIsSelectFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_SELECT_FUNC
);
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
a64a0320
...
...
@@ -1186,6 +1186,12 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
pSelect
->
hasAggFuncs
=
pSelect
->
hasAggFuncs
?
true
:
fmIsAggFunc
(
pFunc
->
funcId
);
pSelect
->
hasRepeatScanFuncs
=
pSelect
->
hasRepeatScanFuncs
?
true
:
fmIsRepeatScanFunc
(
pFunc
->
funcId
);
pSelect
->
hasIndefiniteRowsFunc
=
pSelect
->
hasIndefiniteRowsFunc
?
true
:
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
);
if
(
fmIsSelectFunc
(
pFunc
->
funcId
))
{
pSelect
->
hasSelectFunc
=
true
;
++
(
pSelect
->
selectFuncNum
);
}
else
if
(
fmIsAggFunc
(
pFunc
->
funcId
)
||
fmIsIndefiniteRowsFunc
(
pFunc
->
funcId
))
{
pSelect
->
hasOtherVectorFunc
=
true
;
}
pSelect
->
hasUniqueFunc
=
pSelect
->
hasUniqueFunc
?
true
:
(
FUNCTION_TYPE_UNIQUE
==
pFunc
->
funcType
);
pSelect
->
hasTailFunc
=
pSelect
->
hasTailFunc
?
true
:
(
FUNCTION_TYPE_TAIL
==
pFunc
->
funcType
);
pSelect
->
hasInterpFunc
=
pSelect
->
hasInterpFunc
?
true
:
(
FUNCTION_TYPE_INTERP
==
pFunc
->
funcType
);
...
...
@@ -1395,16 +1401,12 @@ static int32_t getGroupByErrorCode(STranslateContext* pCxt) {
if
(
isDistinctOrderBy
(
pCxt
))
{
return
TSDB_CODE_PAR_NOT_SELECTED_EXPRESSION
;
}
return
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
;
if
(
isSelectStmt
(
pCxt
->
pCurrStmt
)
&&
NULL
!=
((
SSelectStmt
*
)
pCxt
->
pCurrStmt
)
->
pGroupByList
)
{
return
TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION
;
}
return
TSDB_CODE_PAR_NO_VALID_FUNC_IN_WIN
;
}
typedef
struct
SCheckExprForGroupByCxt
{
STranslateContext
*
pTranslateCxt
;
int32_t
selectFuncNum
;
bool
hasSelectValFunc
;
bool
hasOtherAggFunc
;
}
SCheckExprForGroupByCxt
;
static
EDealRes
rewriteColToSelectValFunc
(
STranslateContext
*
pCxt
,
SNode
**
pNode
)
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
nodesMakeNode
(
QUERY_NODE_FUNCTION
);
if
(
NULL
==
pFunc
)
{
...
...
@@ -1445,67 +1447,49 @@ static EDealRes rewriteExprToGroupKeyFunc(STranslateContext* pCxt, SNode** pNode
}
static
EDealRes
doCheckExprForGroupBy
(
SNode
**
pNode
,
void
*
pContext
)
{
SCheckExprForGroupByCxt
*
pCxt
=
(
SCheckExprForGroupByCxt
*
)
pContext
;
STranslateContext
*
pCxt
=
(
STranslateContext
*
)
pContext
;
SSelectStmt
*
pSelect
=
(
SSelectStmt
*
)
pCxt
->
pCurrStmt
;
if
(
!
nodesIsExprNode
(
*
pNode
)
||
isAliasColumn
(
*
pNode
))
{
return
DEAL_RES_CONTINUE
;
}
if
(
isSelectFunc
(
*
pNode
))
{
++
(
pCxt
->
selectFuncNum
);
}
else
if
(
isAggFunc
(
*
pNode
))
{
pCxt
->
hasOtherAggFunc
=
true
;
}
if
((
pCxt
->
selectFuncNum
>
1
&&
pCxt
->
hasSelectValFunc
)
||
(
pCxt
->
hasOtherAggFunc
&&
pCxt
->
hasSelectValFunc
))
{
return
generateDealNodeErrMsg
(
pCxt
->
pTranslateCxt
,
getGroupByErrorCode
(
pCxt
->
pTranslateCxt
));
}
if
(
isAggFunc
(
*
pNode
)
&&
!
isDistinctOrderBy
(
pCxt
->
pTranslateCxt
))
{
if
(
isVectorFunc
(
*
pNode
)
&&
!
isDistinctOrderBy
(
pCxt
))
{
return
DEAL_RES_IGNORE_CHILD
;
}
SNode
*
pGroupNode
=
NULL
;
FOREACH
(
pGroupNode
,
getGroupByList
(
pCxt
->
pTranslateCxt
))
{
FOREACH
(
pGroupNode
,
getGroupByList
(
pCxt
))
{
if
(
nodesEqualNode
(
getGroupByNode
(
pGroupNode
),
*
pNode
))
{
return
DEAL_RES_IGNORE_CHILD
;
}
}
SNode
*
pPartKey
=
NULL
;
FOREACH
(
pPartKey
,
((
SSelectStmt
*
)
pCxt
->
pTranslateCxt
->
pCurrStmt
)
->
pPartitionByList
)
{
FOREACH
(
pPartKey
,
pSelect
->
pPartitionByList
)
{
if
(
nodesEqualNode
(
pPartKey
,
*
pNode
))
{
return
rewriteExprToGroupKeyFunc
(
pCxt
->
pTranslateCxt
,
pNode
);
return
rewriteExprToGroupKeyFunc
(
pCxt
,
pNode
);
}
}
if
(
isScanPseudoColumnFunc
(
*
pNode
)
||
QUERY_NODE_COLUMN
==
nodeType
(
*
pNode
))
{
if
(
p
Cxt
->
selectFuncNum
>
1
||
pCxt
->
hasOtherAgg
Func
)
{
return
generateDealNodeErrMsg
(
pCxt
->
pTranslateCxt
,
getGroupByErrorCode
(
pCxt
->
pTranslate
Cxt
));
if
(
p
Select
->
selectFuncNum
>
1
||
pSelect
->
hasOtherVectorFunc
||
!
pSelect
->
hasSelect
Func
)
{
return
generateDealNodeErrMsg
(
pCxt
,
getGroupByErrorCode
(
p
Cxt
));
}
else
{
pCxt
->
hasSelectValFunc
=
true
;
return
rewriteColToSelectValFunc
(
pCxt
->
pTranslateCxt
,
pNode
);
return
rewriteColToSelectValFunc
(
pCxt
,
pNode
);
}
}
if
(
is
AggFunc
(
*
pNode
)
&&
isDistinctOrderBy
(
pCxt
->
pTranslate
Cxt
))
{
return
generateDealNodeErrMsg
(
pCxt
->
pTranslateCxt
,
getGroupByErrorCode
(
pCxt
->
pTranslate
Cxt
));
if
(
is
VectorFunc
(
*
pNode
)
&&
isDistinctOrderBy
(
p
Cxt
))
{
return
generateDealNodeErrMsg
(
pCxt
,
getGroupByErrorCode
(
p
Cxt
));
}
return
DEAL_RES_CONTINUE
;
}
static
int32_t
checkExprForGroupBy
(
STranslateContext
*
pCxt
,
SNode
**
pNode
)
{
SCheckExprForGroupByCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
selectFuncNum
=
0
,
.
hasSelectValFunc
=
false
,
.
hasOtherAggFunc
=
false
};
nodesRewriteExpr
(
pNode
,
doCheckExprForGroupBy
,
&
cxt
);
if
(
cxt
.
selectFuncNum
!=
1
&&
cxt
.
hasSelectValFunc
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
getGroupByErrorCode
(
pCxt
));
}
nodesRewriteExpr
(
pNode
,
doCheckExprForGroupBy
,
pCxt
);
return
pCxt
->
errCode
;
}
static
int32_t
checkExprListForGroupBy
(
STranslateContext
*
pCxt
,
SNodeList
*
pList
)
{
if
(
NULL
==
getGroupByList
(
pCxt
))
{
static
int32_t
checkExprListForGroupBy
(
STranslateContext
*
pCxt
,
S
SelectStmt
*
pSelect
,
S
NodeList
*
pList
)
{
if
(
NULL
==
getGroupByList
(
pCxt
)
&&
NULL
==
pSelect
->
pWindow
)
{
return
TSDB_CODE_SUCCESS
;
}
SCheckExprForGroupByCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
selectFuncNum
=
0
,
.
hasSelectValFunc
=
false
,
.
hasOtherAggFunc
=
false
};
nodesRewriteExprs
(
pList
,
doCheckExprForGroupBy
,
&
cxt
);
if
(
cxt
.
selectFuncNum
!=
1
&&
cxt
.
hasSelectValFunc
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
getGroupByErrorCode
(
pCxt
));
}
nodesRewriteExprs
(
pList
,
doCheckExprForGroupBy
,
pCxt
);
return
pCxt
->
errCode
;
}
...
...
@@ -1529,7 +1513,6 @@ static int32_t rewriteColsToSelectValFunc(STranslateContext* pCxt, SSelectStmt*
typedef
struct
CheckAggColCoexistCxt
{
STranslateContext
*
pTranslateCxt
;
bool
existVectorFunc
;
bool
existCol
;
int32_t
selectFuncNum
;
bool
existOtherVectorFunc
;
...
...
@@ -1537,13 +1520,12 @@ typedef struct CheckAggColCoexistCxt {
static
EDealRes
doCheckAggColCoexist
(
SNode
**
pNode
,
void
*
pContext
)
{
CheckAggColCoexistCxt
*
pCxt
=
(
CheckAggColCoexistCxt
*
)
pContext
;
if
(
isSelectFunc
(
*
pNode
))
{
++
(
pCxt
->
selectFuncNum
);
}
else
if
(
isAggFunc
(
*
pNode
))
{
pCxt
->
existOtherVectorFunc
=
true
;
}
if
(
isVectorFunc
(
*
pNode
))
{
pCxt
->
existVectorFunc
=
true
;
if
(
isSelectFunc
(
*
pNode
))
{
++
(
pCxt
->
selectFuncNum
);
}
else
{
pCxt
->
existOtherVectorFunc
=
true
;
}
return
DEAL_RES_IGNORE_CHILD
;
}
SNode
*
pPartKey
=
NULL
;
...
...
@@ -1559,14 +1541,12 @@ static EDealRes doCheckAggColCoexist(SNode** pNode, void* pContext) {
}
static
int32_t
checkAggColCoexist
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
if
(
NULL
!=
pSelect
->
pGroupByList
)
{
if
(
NULL
!=
pSelect
->
pGroupByList
||
NULL
!=
pSelect
->
pWindow
||
(
!
pSelect
->
hasAggFuncs
&&
!
pSelect
->
hasIndefiniteRowsFunc
))
{
return
TSDB_CODE_SUCCESS
;
}
CheckAggColCoexistCxt
cxt
=
{.
pTranslateCxt
=
pCxt
,
.
existVectorFunc
=
false
,
.
existCol
=
false
,
.
selectFuncNum
=
0
,
.
existOtherVectorFunc
=
false
};
CheckAggColCoexistCxt
cxt
=
{
.
pTranslateCxt
=
pCxt
,
.
existCol
=
false
,
.
selectFuncNum
=
0
,
.
existOtherVectorFunc
=
false
};
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
doCheckAggColCoexist
,
&
cxt
);
if
(
!
pSelect
->
isDistinct
)
{
nodesRewriteExprs
(
pSelect
->
pOrderByList
,
doCheckAggColCoexist
,
&
cxt
);
...
...
@@ -1574,7 +1554,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
if
(
1
==
cxt
.
selectFuncNum
&&
!
cxt
.
existOtherVectorFunc
)
{
return
rewriteColsToSelectValFunc
(
pCxt
,
pSelect
);
}
if
(
(
cxt
.
selectFuncNum
>
1
||
cxt
.
existVectorFunc
||
NULL
!=
pSelect
->
pWindow
)
&&
cxt
.
existCol
)
{
if
(
cxt
.
existCol
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NOT_SINGLE_GROUP
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -2056,7 +2036,7 @@ static int32_t translateOrderBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
pCxt
->
currClause
=
SQL_CLAUSE_ORDER_BY
;
code
=
translateExprList
(
pCxt
,
pSelect
->
pOrderByList
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkExprListForGroupBy
(
pCxt
,
pSelect
->
pOrderByList
);
code
=
checkExprListForGroupBy
(
pCxt
,
pSelect
,
pSelect
->
pOrderByList
);
}
}
return
code
;
...
...
@@ -2069,7 +2049,7 @@ static int32_t translateSelectList(STranslateContext* pCxt, SSelectStmt* pSelect
code
=
translateStar
(
pCxt
,
pSelect
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
checkExprListForGroupBy
(
pCxt
,
pSelect
->
pProjectionList
);
code
=
checkExprListForGroupBy
(
pCxt
,
pSelect
,
pSelect
->
pProjectionList
);
}
return
code
;
}
...
...
@@ -5264,8 +5244,8 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch
}
static
void
destroyCreateTbReqBatch
(
void
*
data
)
{
SVgroupCreateTableBatch
*
pTbBatch
=
(
SVgroupCreateTableBatch
*
)
data
;
size_t
size
=
taosArrayGetSize
(
pTbBatch
->
req
.
pArray
);
SVgroupCreateTableBatch
*
pTbBatch
=
(
SVgroupCreateTableBatch
*
)
data
;
size_t
size
=
taosArrayGetSize
(
pTbBatch
->
req
.
pArray
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
SVCreateTbReq
*
pTableReq
=
taosArrayGet
(
pTbBatch
->
req
.
pArray
,
i
);
taosMemoryFreeClear
(
pTableReq
->
name
);
...
...
@@ -5347,10 +5327,10 @@ static int32_t rewriteCreateTable(STranslateContext* pCxt, SQuery* pQuery) {
static
void
addCreateTbReqIntoVgroup
(
int32_t
acctId
,
SHashObj
*
pVgroupHashmap
,
SCreateSubTableClause
*
pStmt
,
const
STag
*
pTag
,
uint64_t
suid
,
SVgroupInfo
*
pVgInfo
)
{
// char dbFName[TSDB_DB_FNAME_LEN] = {0};
// SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
// strcpy(name.dbname, pStmt->dbName);
// tNameGetFullDbName(&name, dbFName);
// char dbFName[TSDB_DB_FNAME_LEN] = {0};
// SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
// strcpy(name.dbname, pStmt->dbName);
// tNameGetFullDbName(&name, dbFName);
struct
SVCreateTbReq
req
=
{
0
};
req
.
type
=
TD_CHILD_TABLE
;
...
...
source/libs/parser/test/parSelectTest.cpp
浏览文件 @
a64a0320
...
...
@@ -144,9 +144,9 @@ TEST_F(ParserSelectTest, IndefiniteRowsFunc) {
TEST_F
(
ParserSelectTest
,
IndefiniteRowsFuncSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT DIFF(c1), c2 FROM t1"
,
TSDB_CODE_PAR_NOT_
ALLOWED_FUNC
);
run
(
"SELECT DIFF(c1), c2 FROM t1"
,
TSDB_CODE_PAR_NOT_
SINGLE_GROUP
);
run
(
"SELECT DIFF(c1), tbname FROM t1"
,
TSDB_CODE_PAR_NOT_
ALLOWED_FUNC
);
run
(
"SELECT DIFF(c1), tbname FROM t1"
,
TSDB_CODE_PAR_NOT_
SINGLE_GROUP
);
run
(
"SELECT DIFF(c1), count(*) FROM t1"
,
TSDB_CODE_PAR_NOT_ALLOWED_FUNC
);
...
...
@@ -273,7 +273,7 @@ TEST_F(ParserSelectTest, interval) {
TEST_F
(
ParserSelectTest
,
intervalSemanticCheck
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT c1 FROM t1 INTERVAL(10s)"
,
TSDB_CODE_PAR_NO
T_SINGLE_GROUP
);
run
(
"SELECT c1 FROM t1 INTERVAL(10s)"
,
TSDB_CODE_PAR_NO
_VALID_FUNC_IN_WIN
);
run
(
"SELECT DISTINCT c1, c2 FROM t1 WHERE c1 > 3 INTERVAL(1d) FILL(NEXT)"
,
TSDB_CODE_PAR_INVALID_FILL_TIME_RANGE
);
run
(
"SELECT HISTOGRAM(c1, 'log_bin', '{
\"
start
\"
: -33,
\"
factor
\"
: 55,
\"
count
\"
: 5,
\"
infinity
\"
: false}', 1) FROM t1 "
"WHERE ts > TIMESTAMP '2022-04-01 00:00:00' and ts < TIMESTAMP '2022-04-30 23:59:59' INTERVAL(10s) FILL(NULL)"
,
...
...
source/libs/planner/test/planPartByTest.cpp
浏览文件 @
a64a0320
...
...
@@ -35,6 +35,8 @@ TEST_F(PlanPartitionByTest, withAggFunc) {
run
(
"select count(*) from t1 partition by c1"
);
run
(
"select count(*) from st1 partition by c1"
);
run
(
"select count(*), c1 from t1 partition by c1"
);
}
...
...
tests/system-test/1-insert/time_range_wise.py
浏览文件 @
a64a0320
...
...
@@ -614,12 +614,12 @@ class TDTestCase:
self
.
__insert_data
()
self
.
all_test
()
tdLog
.
printNoPrefix
(
"==========step2:create table in rollup database"
)
tdSql
.
execute
(
"create database db3 retentions 1s:4m,2s:8m,3s:12m"
)
tdSql
.
execute
(
"use db3"
)
#
tdLog.printNoPrefix("==========step2:create table in rollup database")
#
tdSql.execute("create database db3 retentions 1s:4m,2s:8m,3s:12m")
#
tdSql.execute("use db3")
# self.__create_tb()
tdSql
.
execute
(
f
"create stable stb1 (
{
PRIMARY_COL
}
timestamp,
{
INT_COL
}
int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma(
{
INT_COL
}
) "
)
self
.
all_test
()
#
tdSql.execute(f"create stable stb1 ({PRIMARY_COL} timestamp, {INT_COL} int) tags (tag1 int) rollup(first) watermark 5s max_delay 1m sma({INT_COL}) ")
#
self.all_test()
# self.__insert_data()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录