Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e9c8813e
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看板
未验证
提交
e9c8813e
编写于
6月 09, 2021
作者:
H
haojun Liao
提交者:
GitHub
6月 09, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6407 from taosdata/feature/query
Feature/query
上级
db251e8e
a40c9272
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
1160 addition
and
1343 deletion
+1160
-1343
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+46
-29
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+6
-4
src/query/inc/sql.y
src/query/inc/sql.y
+2
-4
src/query/src/qAggMain.c
src/query/src/qAggMain.c
+9
-12
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+11
-8
src/query/src/queryMain.c
src/query/src/queryMain.c
+2
-2
src/query/src/sql.c
src/query/src/sql.c
+948
-1280
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+13
-3
tests/script/general/parser/function.sim
tests/script/general/parser/function.sim
+122
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
e9c8813e
...
...
@@ -122,7 +122,7 @@ static int32_t getColumnIndexByName(SSqlCmd* pCmd, const SStrToken* pToken, SQue
static
int32_t
getTableIndexByName
(
SStrToken
*
pToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
getTableIndexImpl
(
SStrToken
*
pTableToken
,
SQueryInfo
*
pQueryInfo
,
SColumnIndex
*
pIndex
);
static
int32_t
doFunctionsCompatibleCheck
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
);
static
int32_t
doFunctionsCompatibleCheck
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
char
*
msg
);
static
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
);
static
int32_t
tscCheckCreateDbParams
(
SSqlCmd
*
pCmd
,
SCreateDbMsg
*
pCreate
);
...
...
@@ -2157,7 +2157,9 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
const
char
*
msg6
=
"function applied to tags not allowed"
;
const
char
*
msg7
=
"normal table can not apply this function"
;
const
char
*
msg8
=
"multi-columns selection does not support alias column name"
;
const
char
*
msg9
=
"diff can no be applied to unsigned numeric type"
;
const
char
*
msg9
=
"diff/derivative can no be applied to unsigned numeric type"
;
const
char
*
msg10
=
"derivative duration should be greater than 1 Second"
;
const
char
*
msg11
=
"third parameter in derivative should be 0 or 1"
;
switch
(
functionId
)
{
case
TSDB_FUNC_COUNT
:
{
...
...
@@ -2309,7 +2311,7 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
result
Size
,
false
);
SExprInfo
*
pExpr
=
tscExprAppend
(
pQueryInfo
,
functionId
,
&
index
,
resultType
,
resultSize
,
getNewResColId
(
pCmd
),
intermediateRes
Size
,
false
);
if
(
functionId
==
TSDB_FUNC_LEASTSQR
)
{
// set the leastsquares parameters
char
val
[
8
]
=
{
0
};
...
...
@@ -2340,12 +2342,22 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
tickPerSec
/=
1000
;
}
if
(
tickPerSec
<=
0
||
tickPerSec
<
TSDB_TICK_PER_SECOND
(
info
.
precision
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg10
);
}
tscExprAddParams
(
&
pExpr
->
base
,
(
char
*
)
&
tickPerSec
,
TSDB_DATA_TYPE_BIGINT
,
LONG_BYTES
);
memset
(
val
,
0
,
tListLen
(
val
));
if
(
tVariantDump
(
&
pParamElem
[
2
].
pNode
->
value
,
val
,
TSDB_DATA_TYPE_BIGINT
,
true
)
<
0
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
int64_t
v
=
*
(
int64_t
*
)
val
;
if
(
v
!=
0
&&
v
!=
1
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg11
);
}
tscExprAddParams
(
&
pExpr
->
base
,
val
,
TSDB_DATA_TYPE_BIGINT
,
LONG_BYTES
);
}
...
...
@@ -5645,7 +5657,7 @@ int32_t validateSqlFunctionInStreamSql(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
int32_t
validateFunctionsInIntervalOrGroupbyQuery
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
)
{
bool
isProjectionFunction
=
false
;
const
char
*
msg1
=
"
column projection i
s not compatible with interval"
;
const
char
*
msg1
=
"
function
s not compatible with interval"
;
// multi-output set/ todo refactor
size_t
size
=
taosArrayGetSize
(
pQueryInfo
->
exprList
);
...
...
@@ -5669,8 +5681,8 @@ int32_t validateFunctionsInIntervalOrGroupbyQuery(SSqlCmd* pCmd, SQueryInfo* pQu
}
}
i
f
((
pExpr
->
base
.
functionId
==
TSDB_FUNC_PRJ
&&
pExpr
->
base
.
numOfParams
==
0
)
||
pExpr
->
base
.
functionId
==
TSDB_FUNC_DIFF
||
pExpr
->
base
.
functionId
==
TSDB_FUNC_ARITHM
)
{
i
nt32_t
f
=
pExpr
->
base
.
functionId
;
if
((
f
==
TSDB_FUNC_PRJ
&&
pExpr
->
base
.
numOfParams
==
0
)
||
f
==
TSDB_FUNC_DIFF
||
f
==
TSDB_FUNC_ARITHM
||
f
==
TSDB_FUNC_DERIVATIVE
)
{
isProjectionFunction
=
true
;
}
}
...
...
@@ -6266,7 +6278,7 @@ static void updateTagPrjFunction(SQueryInfo* pQueryInfo) {
* 2. if selectivity function and tagprj function both exist, there should be only
* one selectivity function exists.
*/
static
int32_t
checkUpdateTagPrjFunctions
(
SQueryInfo
*
pQueryInfo
,
SSqlCmd
*
pCmd
)
{
static
int32_t
checkUpdateTagPrjFunctions
(
SQueryInfo
*
pQueryInfo
,
char
*
msg
)
{
const
char
*
msg1
=
"only one selectivity function allowed in presence of tags function"
;
const
char
*
msg3
=
"aggregation function should not be mixed up with projection"
;
...
...
@@ -6293,6 +6305,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
continue
;
}
if
((
aAggs
[
functionId
].
status
&
TSDB_FUNCSTATE_SELECTIVITY
)
!=
0
)
{
numOfSelectivity
++
;
}
else
{
...
...
@@ -6304,7 +6317,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
// When the tag projection function on tag column that is not in the group by clause, aggregation function and
// selectivity function exist in select clause is not allowed.
if
(
numOfAggregation
>
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
msg
,
msg1
);
}
/*
...
...
@@ -6333,7 +6346,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
(
functionId
==
TSDB_FUNC_LAST_DST
&&
(
pExpr
->
base
.
colInfo
.
flag
&
TSDB_COL_NULL
)
!=
0
))
{
// do nothing
}
else
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
msg
,
msg1
);
}
}
...
...
@@ -6346,7 +6359,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
}
else
{
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_PROJECTION_QUERY
)
!=
0
)
{
if
(
numOfAggregation
>
0
&&
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
==
0
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg3
);
return
invalidOperationMsg
(
msg
,
msg3
);
}
if
(
numOfAggregation
>
0
||
numOfSelectivity
>
0
)
{
...
...
@@ -6456,7 +6469,7 @@ static int32_t doTagFunctionCheck(SQueryInfo* pQueryInfo) {
return
(
tableCounting
&&
tagProjection
)
?
-
1
:
0
;
}
int32_t
doFunctionsCompatibleCheck
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
)
{
int32_t
doFunctionsCompatibleCheck
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
char
*
msg
)
{
const
char
*
msg1
=
"functions/columns not allowed in group by query"
;
const
char
*
msg2
=
"projection query on columns not allowed"
;
const
char
*
msg3
=
"group by/session/state_window not allowed on projection query"
;
...
...
@@ -6466,17 +6479,17 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
// only retrieve tags, group by is not supportted
if
(
tscQueryTags
(
pQueryInfo
))
{
if
(
doTagFunctionCheck
(
pQueryInfo
)
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg5
);
return
invalidOperationMsg
(
msg
,
msg5
);
}
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
||
isTimeWindowQuery
(
pQueryInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg4
);
return
invalidOperationMsg
(
msg
,
msg4
);
}
else
{
return
TSDB_CODE_SUCCESS
;
}
}
if
(
tscIsProjectionQuery
(
pQueryInfo
)
&&
tscIsSessionWindowQuery
(
pQueryInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg3
);
return
invalidOperationMsg
(
msg
,
msg3
);
}
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
)
{
...
...
@@ -6484,6 +6497,7 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
if
(
onlyTagPrjFunction
(
pQueryInfo
)
&&
allTagPrjInGroupby
(
pQueryInfo
))
{
// It is a groupby aggregate query, the tag project function is not suitable for this case.
updateTagPrjFunction
(
pQueryInfo
);
return
doAddGroupbyColumnsOnDemand
(
pCmd
,
pQueryInfo
);
}
...
...
@@ -6508,21 +6522,21 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
}
if
(
!
qualified
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg2
);
return
invalidOperationMsg
(
msg
,
msg2
);
}
}
if
(
IS_MULTIOUTPUT
(
aAggs
[
functId
].
status
)
&&
functId
!=
TSDB_FUNC_TOP
&&
functId
!=
TSDB_FUNC_BOTTOM
&&
functId
!=
TSDB_FUNC_DIFF
&&
functId
!=
TSDB_FUNC_TAGPRJ
&&
functId
!=
TSDB_FUNC_PRJ
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
msg
,
msg1
);
}
if
(
functId
==
TSDB_FUNC_COUNT
&&
pExpr
->
base
.
colInfo
.
colIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg1
);
return
invalidOperationMsg
(
msg
,
msg1
);
}
}
if
(
checkUpdateTagPrjFunctions
(
pQueryInfo
,
pCmd
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
checkUpdateTagPrjFunctions
(
pQueryInfo
,
msg
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
@@ -6532,12 +6546,12 @@ int32_t doFunctionsCompatibleCheck(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
// projection query on super table does not compatible with "group by" syntax
if
(
tscIsProjectionQuery
(
pQueryInfo
))
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
)
,
msg3
);
return
invalidOperationMsg
(
msg
,
msg3
);
}
return
TSDB_CODE_SUCCESS
;
}
else
{
return
checkUpdateTagPrjFunctions
(
pQueryInfo
,
pCmd
);
return
checkUpdateTagPrjFunctions
(
pQueryInfo
,
msg
);
}
}
int32_t
doLocalQueryProcess
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SSqlNode
*
pSqlNode
)
{
...
...
@@ -7796,7 +7810,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
if
(
validateIntervalNode
(
pSql
,
pQueryInfo
,
pSqlNode
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
if
(
isTimeWindowQuery
(
pQueryInfo
))
{
if
(
isTimeWindowQuery
(
pQueryInfo
)
||
pQueryInfo
->
sessionWindow
.
gap
>
0
)
{
// check if the first column of the nest query result is timestamp column
SColumn
*
pCol
=
taosArrayGetP
(
pQueryInfo
->
colList
,
0
);
if
(
pCol
->
info
.
type
!=
TSDB_DATA_TYPE_TIMESTAMP
)
{
...
...
@@ -7811,10 +7825,13 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
// set order by info
STableMeta
*
pTableMeta
=
tscGetMetaInfo
(
pQueryInfo
,
0
)
->
pTableMeta
;
if
(
validateOrderbyNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
tscGetTableSchema
(
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
validateOrderbyNode
(
pCmd
,
pQueryInfo
,
pSqlNode
,
tscGetTableSchema
(
pTableMeta
))
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
((
code
=
doFunctionsCompatibleCheck
(
pCmd
,
pQueryInfo
,
tscGetErrorMsgPayload
(
pCmd
)))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
}
else
{
pQueryInfo
->
command
=
TSDB_SQL_SELECT
;
...
...
@@ -7879,11 +7896,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
// set interval value
if
(
validateIntervalNode
(
pSql
,
pQueryInfo
,
pSqlNode
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
else
{
if
(
isTimeWindowQuery
(
pQueryInfo
)
&&
(
validateFunctionsInIntervalOrGroupbyQuery
(
pCmd
,
pQueryInfo
)
!=
TSDB_CODE_SUCCESS
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
}
if
(
tscQueryTags
(
pQueryInfo
))
{
...
...
@@ -7914,6 +7926,11 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
((
isTimeWindowQuery
(
pQueryInfo
)
||
pQueryInfo
->
sessionWindow
.
gap
>
0
)
&&
(
validateFunctionsInIntervalOrGroupbyQuery
(
pCmd
,
pQueryInfo
)
!=
TSDB_CODE_SUCCESS
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
isSTable
)
{
tscTansformFuncForSTableQuery
(
pQueryInfo
);
if
(
hasUnsupportFunctionsForSTableQuery
(
pCmd
,
pQueryInfo
))
{
...
...
@@ -7943,7 +7960,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
return
code
;
}
if
((
code
=
doFunctionsCompatibleCheck
(
pCmd
,
pQueryInfo
))
!=
TSDB_CODE_SUCCESS
)
{
if
((
code
=
doFunctionsCompatibleCheck
(
pCmd
,
pQueryInfo
,
tscGetErrorMsgPayload
(
pCmd
)
))
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
e9c8813e
...
...
@@ -912,7 +912,7 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
SGroupbyExpr
*
pGroupbyExpr
=
query
.
pGroupbyExpr
;
if
(
pGroupbyExpr
->
numOfGroupCols
>
0
)
{
if
(
pGroupbyExpr
!=
NULL
&&
pGroupbyExpr
->
numOfGroupCols
>
0
)
{
pQueryMsg
->
orderByIdx
=
htons
(
pGroupbyExpr
->
orderIndex
);
pQueryMsg
->
orderType
=
htons
(
pGroupbyExpr
->
orderType
);
...
...
src/client/src/tscUtil.c
浏览文件 @
e9c8813e
...
...
@@ -962,6 +962,9 @@ static void destroyDummyInputOperator(void* param, int32_t numOfOutput) {
pInfo
->
block
=
destroyOutputBuf
(
pInfo
->
block
);
pInfo
->
pSql
=
NULL
;
cleanupResultRowInfo
(
&
pInfo
->
pTableQueryInfo
->
resInfo
);
tfree
(
pInfo
->
pTableQueryInfo
);
}
// todo this operator servers as the adapter for Operator tree and SqlRes result, remove it later
...
...
@@ -4263,10 +4266,9 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
STableMetaInfo
*
pTableMetaInfo
=
pQueryInfo
->
pTableMetaInfo
[
0
];
pQueryAttr
->
pGroupbyExpr
=
calloc
(
1
,
sizeof
(
SGroupbyExpr
));
*
(
pQueryAttr
->
pGroupbyExpr
)
=
pQueryInfo
->
groupbyExpr
;
if
(
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
>
0
)
{
pQueryAttr
->
pGroupbyExpr
=
calloc
(
1
,
sizeof
(
SGroupbyExpr
));
*
(
pQueryAttr
->
pGroupbyExpr
)
=
pQueryInfo
->
groupbyExpr
;
pQueryAttr
->
pGroupbyExpr
->
columnInfo
=
taosArrayDup
(
pQueryInfo
->
groupbyExpr
.
columnInfo
);
}
else
{
assert
(
pQueryInfo
->
groupbyExpr
.
columnInfo
==
NULL
);
...
...
@@ -4345,7 +4347,7 @@ int32_t tscCreateQueryFromQueryInfo(SQueryInfo* pQueryInfo, SQueryAttr* pQueryAt
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
if
(
pQueryAttr
->
pGroupbyExpr
->
numOfGroupCols
<
0
)
{
if
(
pQueryAttr
->
pGroupbyExpr
!=
NULL
&&
pQueryAttr
->
pGroupbyExpr
->
numOfGroupCols
<
0
)
{
tscError
(
"%p illegal value of numOfGroupCols in query msg: %d"
,
addr
,
pQueryInfo
->
groupbyExpr
.
numOfGroupCols
);
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
...
...
src/query/inc/sql.y
浏览文件 @
e9c8813e
...
...
@@ -559,10 +559,8 @@ session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP. {
X.gap = Y;
}
%type windowstate_option {SWindowStateVal}
windowstate_option(X) ::= . {X.col.n = 0;}
windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. {
X.col = V;
}
windowstate_option(X) ::= . { X.col.n = 0; X.col.z = NULL;}
windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP. { X.col = V; }
%type fill_opt {SArray*}
%destructor fill_opt {taosArrayDestroy($$);}
...
...
src/query/src/qAggMain.c
浏览文件 @
e9c8813e
...
...
@@ -3428,7 +3428,7 @@ static bool deriv_function_setup(SQLFunctionCtx *pCtx) {
SResultRowCellInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SDerivInfo
*
pDerivInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
pDerivInfo
->
ignoreNegative
=
pCtx
->
param
[
2
].
i64
;
pDerivInfo
->
ignoreNegative
=
pCtx
->
param
[
1
].
i64
;
pDerivInfo
->
prevTs
=
-
1
;
pDerivInfo
->
tsWindow
=
pCtx
->
param
[
0
].
i64
;
pDerivInfo
->
valueSet
=
false
;
...
...
@@ -3440,10 +3440,8 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
SDerivInfo
*
pDerivInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
void
*
data
=
GET_INPUT_DATA_LIST
(
pCtx
);
bool
isFirstBlock
=
(
pDerivInfo
->
valueSet
==
false
);
int32_t
notNullElems
=
0
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pCtx
->
order
);
int32_t
i
=
(
pCtx
->
order
==
TSDB_ORDER_ASC
)
?
0
:
pCtx
->
size
-
1
;
...
...
@@ -3469,12 +3467,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*
pTimestamp
=
tsList
[
i
];
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
...
...
@@ -3496,12 +3494,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*
pTimestamp
=
tsList
[
i
];
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
(
double
)
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
}
...
...
@@ -3522,12 +3520,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*
pTimestamp
=
tsList
[
i
];
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
}
...
...
@@ -3549,12 +3547,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*
pTimestamp
=
tsList
[
i
];
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
}
...
...
@@ -3575,12 +3573,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*
pTimestamp
=
tsList
[
i
];
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
}
...
...
@@ -3602,12 +3600,12 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
pOutput
+=
1
;
pTimestamp
+=
1
;
notNullElems
++
;
}
}
pDerivInfo
->
prevValue
=
pData
[
i
];
pDerivInfo
->
prevTs
=
tsList
[
i
];
notNullElems
++
;
}
break
;
}
...
...
@@ -3623,8 +3621,7 @@ static void deriv_function(SQLFunctionCtx *pCtx) {
*/
assert
(
pCtx
->
hasNull
);
}
else
{
int32_t
forwardStep
=
(
isFirstBlock
)
?
notNullElems
-
1
:
notNullElems
;
GET_RES_INFO
(
pCtx
)
->
numOfRes
+=
forwardStep
;
GET_RES_INFO
(
pCtx
)
->
numOfRes
+=
notNullElems
;
}
}
...
...
@@ -5303,7 +5300,7 @@ SAggFunctionInfo aAggs[] = {{
},
{
// 17
"ts
_dummy
"
,
"ts"
,
TSDB_FUNC_TS_DUMMY
,
TSDB_FUNC_TS_DUMMY
,
TSDB_BASE_FUNC_SO
|
TSDB_FUNCSTATE_NEED_TS
,
...
...
src/query/src/qExecutor.c
浏览文件 @
e9c8813e
...
...
@@ -735,6 +735,7 @@ static void doApplyFunctions(SQueryRuntimeEnv* pRuntimeEnv, SQLFunctionCtx* pCtx
if
(
pCtx
[
k
].
preAggVals
.
isSet
&&
forwardStep
<
numOfTotal
)
{
pCtx
[
k
].
preAggVals
.
isSet
=
false
;
}
if
(
functionNeedToExecute
(
pRuntimeEnv
,
&
pCtx
[
k
],
functionId
))
{
aAggs
[
functionId
].
xFunction
(
&
pCtx
[
k
]);
}
...
...
@@ -918,7 +919,7 @@ void setInputDataBlock(SOperatorInfo* pOperator, SQLFunctionCtx* pCtx, SSDataBlo
doSetInputDataBlockInfo
(
pOperator
,
pCtx
,
pBlock
,
order
);
}
}
else
{
if
(
pCtx
[
0
].
pInput
==
NULL
&&
pBlock
->
pDataBlock
!=
NULL
)
{
if
(
/*pCtx[0].pInput == NULL && */
pBlock
->
pDataBlock
!=
NULL
)
{
doSetInputDataBlock
(
pOperator
,
pCtx
,
pBlock
,
order
);
}
else
{
doSetInputDataBlockInfo
(
pOperator
,
pCtx
,
pBlock
,
order
);
...
...
@@ -1169,7 +1170,7 @@ static void hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul
SQueryRuntimeEnv
*
pRuntimeEnv
=
pOperatorInfo
->
pRuntimeEnv
;
int32_t
numOfOutput
=
pOperatorInfo
->
numOfOutput
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
SQueryAttr
*
pQueryAttr
=
pRuntimeEnv
->
pQueryAttr
;
int32_t
step
=
GET_FORWARD_DIRECTION_FACTOR
(
pQueryAttr
->
order
.
order
);
bool
ascQuery
=
QUERY_IS_ASC_QUERY
(
pQueryAttr
);
...
...
@@ -3094,7 +3095,7 @@ int32_t initResultRow(SResultRow *pResultRow) {
* +------------+-----------------result column 1-----------+-----------------result column 2-----------+
* + SResultRow | SResultRowCellInfo | intermediate buffer1 | SResultRowCellInfo | intermediate buffer 2|
* +------------+-------------------------------------------+-------------------------------------------+
* offset[0] offset[1]
* offset[0] offset[1]
offset[2]
*/
void
setDefaultOutputBuf
(
SQueryRuntimeEnv
*
pRuntimeEnv
,
SOptrBasicInfo
*
pInfo
,
int64_t
uid
,
int32_t
stage
)
{
SQLFunctionCtx
*
pCtx
=
pInfo
->
pCtx
;
...
...
@@ -3323,7 +3324,7 @@ void setResultRowOutputBufInitCtx(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pRe
offset
+=
pCtx
[
i
].
outputBytes
;
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
)
{
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
}
...
...
@@ -3381,7 +3382,7 @@ void setResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, SResultRow *pResult, SQLF
offset
+=
pCtx
[
i
].
outputBytes
;
int32_t
functionId
=
pCtx
[
i
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
)
{
if
(
functionId
==
TSDB_FUNC_TOP
||
functionId
==
TSDB_FUNC_BOTTOM
||
functionId
==
TSDB_FUNC_DIFF
||
functionId
==
TSDB_FUNC_DERIVATIVE
)
{
pCtx
[
i
].
ptsOutputBuf
=
pCtx
[
0
].
pOutput
;
}
...
...
@@ -3589,6 +3590,8 @@ static int32_t doCopyToSDataBlock(SQueryRuntimeEnv* pRuntimeEnv, SGroupResInfo*
int32_t
step
=
-
1
;
qDebug
(
"QInfo:0x%"
PRIx64
" start to copy data from windowResInfo to output buf"
,
GET_QID
(
pRuntimeEnv
));
assert
(
orderType
==
TSDB_ORDER_ASC
||
orderType
==
TSDB_ORDER_DESC
);
if
(
orderType
==
TSDB_ORDER_ASC
)
{
start
=
pGroupResInfo
->
index
;
step
=
1
;
...
...
@@ -4570,7 +4573,7 @@ SOperatorInfo* createDataBlocksOptScanInfo(void* pTsdbQueryHandle, SQueryRuntime
}
SArray
*
getOrderCheckColumns
(
SQueryAttr
*
pQuery
)
{
int32_t
numOfCols
=
pQuery
->
pGroupbyExpr
->
numOfGroupCols
;
int32_t
numOfCols
=
pQuery
->
pGroupbyExpr
==
NULL
?
0
:
pQuery
->
pGroupbyExpr
->
numOfGroupCols
;
SArray
*
pOrderColumns
=
NULL
;
if
(
numOfCols
>
0
)
{
...
...
@@ -4609,7 +4612,7 @@ SArray* getOrderCheckColumns(SQueryAttr* pQuery) {
}
SArray
*
getResultGroupCheckColumns
(
SQueryAttr
*
pQuery
)
{
int32_t
numOfCols
=
pQuery
->
pGroupbyExpr
->
numOfGroupCols
;
int32_t
numOfCols
=
pQuery
->
pGroupbyExpr
==
NULL
?
0
:
pQuery
->
pGroupbyExpr
->
numOfGroupCols
;
SArray
*
pOrderColumns
=
NULL
;
if
(
numOfCols
>
0
)
{
...
...
@@ -7213,7 +7216,7 @@ SQInfo* createQInfoImpl(SQueryTableMsg* pQueryMsg, SGroupbyExpr* pGroupbyExpr, S
// todo refactor
pQInfo
->
query
.
queryBlockDist
=
(
numOfOutput
==
1
&&
pExprs
[
0
].
base
.
functionId
==
TSDB_FUNC_BLKINFO
);
qDebug
(
"qmsg:%p
QInfo:0x%"
PRIx64
"-%p created"
,
pQueryMsg
,
pQInfo
->
qId
,
pQInfo
);
qDebug
(
"qmsg:%p
vgId:%d, QInfo:0x%"
PRIx64
"-%p created"
,
pQueryMsg
,
pQInfo
->
query
.
vgId
,
pQInfo
->
qId
,
pQInfo
);
return
pQInfo
;
_cleanup_qinfo:
...
...
src/query/src/queryMain.c
浏览文件 @
e9c8813e
...
...
@@ -132,7 +132,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
numOfGroupByCols
=
0
;
}
qDebug
(
"qmsg:%p query stable, uid:%"
PRI
d
64
", tid:%d"
,
pQueryMsg
,
id
->
uid
,
id
->
tid
);
qDebug
(
"qmsg:%p query stable, uid:%"
PRI
u
64
", tid:%d"
,
pQueryMsg
,
id
->
uid
,
id
->
tid
);
code
=
tsdbQuerySTableByTagCond
(
tsdb
,
id
->
uid
,
pQueryMsg
->
window
.
skey
,
param
.
tagCond
,
pQueryMsg
->
tagCondLen
,
pQueryMsg
->
tagNameRelType
,
param
.
tbnameCond
,
&
tableGroupInfo
,
param
.
pGroupColIndex
,
numOfGroupByCols
);
...
...
@@ -162,7 +162,7 @@ int32_t qCreateQueryInfo(void* tsdb, int32_t vgId, SQueryTableMsg* pQueryMsg, qi
assert
(
pQueryMsg
->
stableQuery
==
isSTableQuery
);
(
*
pQInfo
)
=
createQInfoImpl
(
pQueryMsg
,
param
.
pGroupbyExpr
,
param
.
pExprs
,
param
.
pSecExprs
,
&
tableGroupInfo
,
param
.
pTagColumnInfo
,
vgId
,
param
.
sql
,
qId
);
param
.
pTagColumnInfo
,
vgId
,
param
.
sql
,
qId
);
param
.
sql
=
NULL
;
param
.
pExprs
=
NULL
;
...
...
src/query/src/sql.c
浏览文件 @
e9c8813e
此差异已折叠。
点击以展开。
src/tsdb/src/tsdbRead.c
浏览文件 @
e9c8813e
...
...
@@ -1087,7 +1087,11 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p
assert
(
cur
->
pos
>=
0
&&
cur
->
pos
<=
binfo
.
rows
);
TSKEY
key
=
(
row
!=
NULL
)
?
dataRowKey
(
row
)
:
TSKEY_INITIAL_VAL
;
tsdbDebug
(
"%p key in mem:%"
PRId64
", 0x%"
PRIx64
,
pQueryHandle
,
key
,
pQueryHandle
->
qId
);
if
(
key
!=
TSKEY_INITIAL_VAL
)
{
tsdbDebug
(
"%p key in mem:%"
PRId64
", 0x%"
PRIx64
,
pQueryHandle
,
key
,
pQueryHandle
->
qId
);
}
else
{
tsdbDebug
(
"%p no data in mem, 0x%"
PRIx64
,
pQueryHandle
,
pQueryHandle
->
qId
);
}
if
((
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
<=
binfo
.
window
.
ekey
))
||
(
!
ASCENDING_TRAVERSE
(
pQueryHandle
->
order
)
&&
(
key
!=
TSKEY_INITIAL_VAL
&&
key
>=
binfo
.
window
.
skey
)))
{
...
...
@@ -1151,8 +1155,14 @@ static int32_t handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SBlock* p
}
assert
(
cur
->
blockCompleted
);
tsdbDebug
(
"create data block from remain file block, brange:%"
PRId64
"-%"
PRId64
", rows:%d, lastKey:%"
PRId64
", %p"
,
cur
->
win
.
skey
,
cur
->
win
.
ekey
,
cur
->
rows
,
cur
->
lastKey
,
pQueryHandle
);
if
(
cur
->
rows
==
binfo
.
rows
)
{
tsdbDebug
(
"%p whole file block qualified, brange:%"
PRId64
"-%"
PRId64
", rows:%d, lastKey:%"
PRId64
", %"
PRIx64
,
pQueryHandle
,
cur
->
win
.
skey
,
cur
->
win
.
ekey
,
cur
->
rows
,
cur
->
lastKey
,
pQueryHandle
->
qId
);
}
else
{
tsdbDebug
(
"%p create data block from remain file block, brange:%"
PRId64
"-%"
PRId64
", rows:%d, total:%d, lastKey:%"
PRId64
", %"
PRIx64
,
pQueryHandle
,
cur
->
win
.
skey
,
cur
->
win
.
ekey
,
cur
->
rows
,
binfo
.
rows
,
cur
->
lastKey
,
pQueryHandle
->
qId
);
}
}
return
code
;
...
...
tests/script/general/parser/function.sim
浏览文件 @
e9c8813e
...
...
@@ -932,3 +932,125 @@ if $data32 != 0.000144445 then
return -1
endi
print ===========================> derivative
sql drop table t1
sql drop table tx;
sql drop table m1;
sql drop table if exists tm0;
sql drop table if exists tm1;
sql create table tm0(ts timestamp, k double)
sql insert into tm0 values('2015-08-18T00:00:00Z', 2.064) ('2015-08-18T00:06:00Z', 2.116) ('2015-08-18T00:12:00Z', 2.028)
sql insert into tm0 values('2015-08-18T00:18:00Z', 2.126) ('2015-08-18T00:24:00Z', 2.041) ('2015-08-18T00:30:00Z', 2.051)
sql_error select derivative(ts) from tm0;
sql_error select derivative(k) from tm0;
sql_error select derivative(k, 0, 0) from tm0;
sql_error select derivative(k, 1, 911) from tm0;
sql_error select derivative(kx, 1s, 1) from tm0;
sql_error select derivative(k, -20s, 1) from tm0;
sql_error select derivative(k, 20a, 0) from tm0;
sql_error select derivative(k, 200a, 0) from tm0;
sql_error select derivative(k, 999a, 0) from tm0;
sql_error select derivative(k, 20s, -12) from tm0;
sql select derivative(k, 1s, 0) from tm0
if $rows != 5 then
return -1
endi
if $data00 != @15-08-18 08:06:00.000@ then
return -1
endi
if $data01 != 0.000144444 then
print expect 0.000144444, actual: $data01
return -1
endi
if $data10 != @15-08-18 08:12:00.000@ then
return -1
endi
if $data11 != -0.000244444 then
return -1
endi
if $data20 != @15-08-18 08:18:00.000@ then
return -1
endi
if $data21 != 0.000272222 then
print expect 0.000272222, actual: $data21
return -1
endi
if $data30 != @15-08-18 08:24:00.000@ then
return -1
endi
if $data31 != -0.000236111 then
print expect 0.000236111, actual: $data31
return -1
endi
sql select derivative(k, 6m, 0) from tm0;
if $rows != 5 then
return -1
endi
if $data00 != @15-08-18 08:06:00.000@ then
return -1
endi
if $data01 != 0.052000000 then
print expect 0.052000000, actual: $data01
return -1
endi
if $data10 != @15-08-18 08:12:00.000@ then
return -1
endi
if $data11 != -0.088000000 then
return -1
endi
if $data20 != @15-08-18 08:18:00.000@ then
return -1
endi
if $data21 != 0.098000000 then
return -1
endi
if $data30 != @15-08-18 08:24:00.000@ then
return -1
endi
if $data31 != -0.085000000 then
return -1
endi
sql select derivative(k, 12m, 0) from tm0;
if $rows != 5 then
return -1
endi
if $data00 != @15-08-18 08:06:00.000@ then
return -1
endi
if $data01 != 0.104000000 then
print expect 0.104000000, actual: $data01
return -1
endi
sql select derivative(k, 6m, 1) from tm0;
if $rows != 3 then
return -1
endi
sql_error select derivative(k, 6m, 1) from tm0 interval(1s);
sql_error select derivative(k, 6m, 1) from tm0 session(ts, 1s);
sql_error select derivative(k, 6m, 1) from tm0 group by k;
sql_error select derivative(k, 6m, 1) from
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录