Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8a8939f9
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看板
提交
8a8939f9
编写于
7月 01, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: csum/diff/mavg support subquery
上级
8c2e9842
变更
12
显示空白变更内容
内联
并排
Showing
12 changed file
with
118 addition
and
102 deletion
+118
-102
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-0
include/libs/nodes/plannodes.h
include/libs/nodes/plannodes.h
+1
-0
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+2
-1
source/libs/function/inc/functionMgtInt.h
source/libs/function/inc/functionMgtInt.h
+1
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+19
-18
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+67
-71
source/libs/function/src/functionMgt.c
source/libs/function/src/functionMgt.c
+2
-0
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+1
-1
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+1
-1
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+14
-9
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+1
-0
source/libs/planner/test/planBasicTest.cpp
source/libs/planner/test/planBasicTest.cpp
+8
-0
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
8a8939f9
...
...
@@ -195,6 +195,7 @@ bool fmIsIntervalInterpoFunc(int32_t funcId);
bool
fmIsInterpFunc
(
int32_t
funcId
);
bool
fmIsLastRowFunc
(
int32_t
funcId
);
bool
fmIsSystemInfoFunc
(
int32_t
funcId
);
bool
fmIsImplicitTsFunc
(
int32_t
funcId
);
int32_t
fmGetDistMethod
(
const
SFunctionNode
*
pFunc
,
SFunctionNode
**
pPartialFunc
,
SFunctionNode
**
pMergeFunc
);
...
...
include/libs/nodes/plannodes.h
浏览文件 @
8a8939f9
...
...
@@ -104,6 +104,7 @@ typedef struct SIndefRowsFuncLogicNode {
SNodeList
*
pFuncs
;
bool
isTailFunc
;
bool
isUniqueFunc
;
bool
isTimeLineFunc
;
}
SIndefRowsFuncLogicNode
;
typedef
struct
SInterpFuncLogicNode
{
...
...
include/libs/nodes/querynodes.h
浏览文件 @
8a8939f9
...
...
@@ -251,7 +251,7 @@ typedef struct SSelectStmt {
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
bool
isEmptyResult
;
bool
isTime
OrderQuery
;
bool
isTime
LineResult
;
bool
hasAggFuncs
;
bool
hasRepeatScanFuncs
;
bool
hasIndefiniteRowsFunc
;
...
...
@@ -261,6 +261,7 @@ typedef struct SSelectStmt {
bool
hasTailFunc
;
bool
hasInterpFunc
;
bool
hasLastRowFunc
;
bool
hasTimeLineFunc
;
bool
groupSort
;
}
SSelectStmt
;
...
...
source/libs/function/inc/functionMgtInt.h
浏览文件 @
8a8939f9
...
...
@@ -32,7 +32,7 @@ extern "C" {
#define FUNC_MGT_STRING_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(3)
#define FUNC_MGT_DATETIME_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(4)
#define FUNC_MGT_TIMELINE_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(5)
#define FUNC_MGT_
TIMEORDER_FUNC
FUNC_MGT_FUNC_CLASSIFICATION_MASK(6)
#define FUNC_MGT_
IMPLICIT_TS_FUNC
FUNC_MGT_FUNC_CLASSIFICATION_MASK(6)
#define FUNC_MGT_PSEUDO_COLUMN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(7)
#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8)
#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9)
...
...
source/libs/function/src/builtins.c
浏览文件 @
8a8939f9
...
...
@@ -238,7 +238,7 @@ static int32_t translateWduration(SFunctionNode* pFunc, char* pErrBuf, int32_t l
static
int32_t
translateNowToday
(
SFunctionNode
*
pFunc
,
char
*
pErrBuf
,
int32_t
len
)
{
// pseudo column do not need to check parameters
//add database precision as param
//
add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1017,7 +1017,7 @@ static int32_t translateIrate(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
//add database precision as param
//
add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1477,7 +1477,7 @@ static int32_t translateToUnixtimestamp(SFunctionNode* pFunc, char* pErrBuf, int
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
//add database precision as param
//
add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1497,7 +1497,7 @@ static int32_t translateTimeTruncate(SFunctionNode* pFunc, char* pErrBuf, int32_
return
invaildFuncParaTypeErrMsg
(
pErrBuf
,
len
,
pFunc
->
functionName
);
}
//add database precision as param
//
add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1525,7 +1525,7 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
}
}
//add database precision as param
//
add database precision as param
uint8_t
dbPrec
=
pFunc
->
node
.
resType
.
precision
;
addDbPrecisonParam
(
&
pFunc
->
pParameterList
,
dbPrec
);
...
...
@@ -1924,7 +1924,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"interp"
,
.
type
=
FUNCTION_TYPE_INTERP
,
.
classification
=
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_INTERVAL_INTERPO_FUNC
,
.
classification
=
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_INTERVAL_INTERPO_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getSelectivityFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1954,7 +1954,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"last_row"
,
.
type
=
FUNCTION_TYPE_LAST_ROW
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1967,7 +1967,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_cache_last_row"
,
.
type
=
FUNCTION_TYPE_CACHE_LAST_ROW
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateLastRow
,
.
getEnvFunc
=
getMinmaxFuncEnv
,
.
initFunc
=
minmaxFunctionSetup
,
...
...
@@ -1977,7 +1977,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"first"
,
.
type
=
FUNCTION_TYPE_FIRST
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1990,7 +1990,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_first_partial"
,
.
type
=
FUNCTION_TYPE_FIRST_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLastPartial
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2001,7 +2001,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_first_merge"
,
.
type
=
FUNCTION_TYPE_FIRST_MERGE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLastMerge
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2012,7 +2012,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"last"
,
.
type
=
FUNCTION_TYPE_LAST
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2025,7 +2025,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_last_partial"
,
.
type
=
FUNCTION_TYPE_LAST_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLastPartial
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2036,7 +2036,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_last_merge"
,
.
type
=
FUNCTION_TYPE_LAST_MERGE
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_MULTI_RES_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateFirstLastMerge
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2047,7 +2047,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"twa"
,
.
type
=
FUNCTION_TYPE_TWA
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_INTERVAL_INTERPO_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
,
.
classification
=
FUNC_MGT_AGG_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_INTERVAL_INTERPO_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateInNumOutDou
,
.
dataRequiredFunc
=
statisDataRequired
,
.
getEnvFunc
=
getTwaFuncEnv
,
...
...
@@ -2144,7 +2144,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"statecount"
,
.
type
=
FUNCTION_TYPE_STATE_COUNT
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_
TIMELINE_FUNC
|
FUNC_MGT_
FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
,
.
translateFunc
=
translateStateCount
,
.
getEnvFunc
=
getStateFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -2194,7 +2194,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"tail"
,
.
type
=
FUNCTION_TYPE_TAIL
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
|
FUNC_MGT_FORBID_GROUP_BY_FUNC
,
.
classification
=
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
|
FUNC_MGT_FORBID_GROUP_BY_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateTail
,
.
getEnvFunc
=
getTailFuncEnv
,
.
initFunc
=
tailFunctionSetup
,
...
...
@@ -2205,7 +2206,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
name
=
"unique"
,
.
type
=
FUNCTION_TYPE_UNIQUE
,
.
classification
=
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE_FUNC
|
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
|
FUNC_MGT_FORBID_GROUP_BY_FUNC
,
FUNC_MGT_FORBID_STREAM_FUNC
|
FUNC_MGT_FORBID_WINDOW_FUNC
|
FUNC_MGT_FORBID_GROUP_BY_FUNC
|
FUNC_MGT_IMPLICIT_TS_FUNC
,
.
translateFunc
=
translateUnique
,
.
getEnvFunc
=
getUniqueFuncEnv
,
.
initFunc
=
uniqueFunctionSetup
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
8a8939f9
...
...
@@ -276,13 +276,12 @@ typedef struct SRateInfo {
int8_t
hasResult
;
// flag to denote has value
}
SRateInfo
;
typedef
struct
SGroupKeyInfo
{
typedef
struct
SGroupKeyInfo
{
bool
hasResult
;
bool
isNull
;
char
data
[];
}
SGroupKeyInfo
;
#define SET_VAL(_info, numOfElem, res) \
do { \
if ((numOfElem) <= 0) { \
...
...
@@ -2409,7 +2408,9 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
return
TSDB_CODE_SUCCESS
;
}
int32_t
getFirstLastInfoSize
(
int32_t
resBytes
)
{
return
sizeof
(
SFirstLastRes
)
+
resBytes
+
sizeof
(
int64_t
)
+
sizeof
(
STuplePos
);
}
int32_t
getFirstLastInfoSize
(
int32_t
resBytes
)
{
return
sizeof
(
SFirstLastRes
)
+
resBytes
+
sizeof
(
int64_t
)
+
sizeof
(
STuplePos
);
}
bool
getFirstLastFuncEnv
(
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
SColumnNode
*
pNode
=
(
SColumnNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
...
...
@@ -2491,7 +2492,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
//
handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
...
...
@@ -2501,7 +2502,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
}
pInfo
->
hasResult
=
true
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
break
;
}
...
...
@@ -2533,7 +2534,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
//
handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
...
...
@@ -2543,7 +2544,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
}
pInfo
->
hasResult
=
true
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
break
;
}
...
...
@@ -2597,7 +2598,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
//
handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
...
...
@@ -2607,7 +2608,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
}
pInfo
->
hasResult
=
true
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
}
break
;
...
...
@@ -2629,7 +2630,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
//
handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
...
...
@@ -2640,7 +2641,7 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
pInfo
->
hasResult
=
true
;
pResInfo
->
numOfRes
=
1
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
}
break
;
}
...
...
@@ -2670,7 +2671,7 @@ static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, S
}
*
tsOut
=
*
tsIn
;
memcpy
(
pOutput
->
buf
,
pInput
->
buf
,
pOutput
->
bytes
);
//handle selectivity
//
handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pOutput
->
buf
+
pOutput
->
bytes
+
sizeof
(
TSKEY
));
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
if
(
!
pOutput
->
hasResult
)
{
...
...
@@ -2717,7 +2718,7 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SFirstLastRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
pRes
->
buf
,
pResInfo
->
isNullRes
);
//handle selectivity
//
handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pRes
->
buf
+
pRes
->
bytes
+
sizeof
(
TSKEY
));
setSelectivityValue
(
pCtx
,
pBlock
,
pTuplePos
,
pBlock
->
info
.
rows
);
...
...
@@ -2738,7 +2739,7 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
res
,
false
);
//handle selectivity
//
handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pRes
->
buf
+
pRes
->
bytes
+
sizeof
(
TSKEY
));
setSelectivityValue
(
pCtx
,
pBlock
,
pTuplePos
,
pBlock
->
info
.
rows
);
...
...
@@ -3131,7 +3132,7 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
void
saveTupleData
(
SqlFunctionCtx
*
pCtx
,
int32_t
rowIndex
,
const
SSDataBlock
*
pSrcBlock
,
STuplePos
*
pPos
)
{
SFilePage
*
pPage
=
NULL
;
int32_t
completeRowSize
=
pSrcBlock
->
info
.
rowSize
+
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
)
*
sizeof
(
bool
);
int32_t
completeRowSize
=
pSrcBlock
->
info
.
rowSize
+
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
)
*
sizeof
(
bool
);
if
(
pCtx
->
curBufPage
==
-
1
)
{
pPage
=
getNewBufPage
(
pCtx
->
pBuf
,
0
,
&
pCtx
->
curBufPage
);
...
...
@@ -3149,8 +3150,8 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
// keep the current row data, extract method
int32_t
offset
=
0
;
bool
*
nullList
=
(
bool
*
)((
char
*
)
pPage
+
pPage
->
num
);
char
*
pStart
=
(
char
*
)(
nullList
+
sizeof
(
bool
)
*
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
));
for
(
int32_t
i
=
0
;
i
<
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
);
++
i
)
{
char
*
pStart
=
(
char
*
)(
nullList
+
sizeof
(
bool
)
*
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
));
for
(
int32_t
i
=
0
;
i
<
(
int32_t
)
taosArrayGetSize
(
pSrcBlock
->
pDataBlock
);
++
i
)
{
SColumnInfoData
*
pCol
=
taosArrayGet
(
pSrcBlock
->
pDataBlock
,
i
);
bool
isNull
=
colDataIsNull_s
(
pCol
,
rowIndex
);
if
(
isNull
)
{
...
...
@@ -4405,7 +4406,6 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) {
SMavgInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
TSKEY
*
tsList
=
(
int64_t
*
)
pInput
->
pPTS
->
pData
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pTsOutput
=
pCtx
->
pTsOutput
;
...
...
@@ -4445,10 +4445,6 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx) {
colDataAppend
(
pOutput
,
pos
,
(
char
*
)
&
result
,
false
);
}
// TODO: remove this after pTsOutput is handled
if
(
pTsOutput
!=
NULL
)
{
colDataAppendInt64
(
pTsOutput
,
pos
,
&
tsList
[
i
]);
}
numOfElems
++
;
}
...
...
@@ -4860,7 +4856,6 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
pResInfo
->
numOfRes
;
}
bool
getTwaFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
STwaInfo
);
return
true
;
...
...
@@ -5112,7 +5107,7 @@ int32_t twaFinalize(struct SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
functionFinalize
(
pCtx
,
pBlock
);
}
bool
blockDistSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
bool
blockDistSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
)
{
if
(
!
functionSetup
(
pCtx
,
pResultInfo
))
{
return
false
;
}
...
...
@@ -5230,16 +5225,18 @@ int32_t blockDistFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t
row
=
0
;
char
st
[
256
]
=
{
0
};
double
totalRawSize
=
pData
->
totalRows
*
pData
->
rowSize
;
int32_t
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]"
,
int32_t
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Blocks=[%d] Total_Size=[%.2f Kb] Average_size=[%.2f Kb] Compression_Ratio=[%.2f %c]"
,
pData
->
numOfBlocks
,
pData
->
totalSize
/
1024
.
0
,
((
double
)
pData
->
totalSize
)
/
pData
->
numOfBlocks
,
pData
->
totalSize
*
100
/
totalRawSize
,
'%'
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Rows=[%"
PRId64
"] Inmem_Rows=[%d] MinRows=[%d] MaxRows=[%d] Average_Rows=[%"
PRId64
"]"
,
pData
->
totalRows
,
pData
->
numOfInmemRows
,
pData
->
minRows
,
pData
->
maxRows
,
pData
->
totalRows
/
pData
->
numOfBlocks
);
len
=
sprintf
(
st
+
VARSTR_HEADER_SIZE
,
"Total_Rows=[%"
PRId64
"] Inmem_Rows=[%d] MinRows=[%d] MaxRows=[%d] Average_Rows=[%"
PRId64
"]"
,
pData
->
totalRows
,
pData
->
numOfInmemRows
,
pData
->
minRows
,
pData
->
maxRows
,
pData
->
totalRows
/
pData
->
numOfBlocks
);
varDataSetLen
(
st
,
len
);
colDataAppend
(
pColInfo
,
row
++
,
st
,
false
);
...
...
@@ -5471,7 +5468,6 @@ int32_t irateFunction(SqlFunctionCtx* pCtx) {
pRateInfo
->
firstValue
=
v
;
pRateInfo
->
firstKey
=
tsList
[
i
];
}
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
...
...
@@ -5497,7 +5493,7 @@ static double doCalcRate(const SRateInfo* pRateInfo, double tickPerSec) {
return
0
;
}
return
(
duration
>
0
)
?
((
double
)
diff
)
/
(
duration
/
tickPerSec
)
:
0
.
0
;
return
(
duration
>
0
)
?
((
double
)
diff
)
/
(
duration
/
tickPerSec
)
:
0
.
0
;
}
int32_t
irateFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
...
...
@@ -5525,7 +5521,7 @@ int32_t groupKeyFunction(SqlFunctionCtx* pCtx) {
int32_t
startIndex
=
pInput
->
startRowIndex
;
//escape rest of data blocks to avoid first entry to be overwritten.
//
escape rest of data blocks to avoid first entry to be overwritten.
if
(
pInfo
->
hasResult
)
{
goto
_group_key_over
;
}
...
...
source/libs/function/src/functionMgt.c
浏览文件 @
8a8939f9
...
...
@@ -181,6 +181,8 @@ bool fmIsForbidGroupByFunc(int32_t funcId) { return isSpecificClassifyFunc(funcI
bool
fmIsSystemInfoFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_SYSTEM_INFO_FUNC
);
}
bool
fmIsImplicitTsFunc
(
int32_t
funcId
)
{
return
isSpecificClassifyFunc
(
funcId
,
FUNC_MGT_IMPLICIT_TS_FUNC
);
}
bool
fmIsInterpFunc
(
int32_t
funcId
)
{
if
(
funcId
<
0
||
funcId
>=
funcMgtBuiltinsNum
)
{
return
false
;
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
8a8939f9
...
...
@@ -600,7 +600,7 @@ static int32_t selectStmtCopy(const SSelectStmt* pSrc, SSelectStmt* pDst) {
COPY_CHAR_ARRAY_FIELD
(
stmtName
);
COPY_SCALAR_FIELD
(
precision
);
COPY_SCALAR_FIELD
(
isEmptyResult
);
COPY_SCALAR_FIELD
(
isTime
OrderQuery
);
COPY_SCALAR_FIELD
(
isTime
LineResult
);
COPY_SCALAR_FIELD
(
hasAggFuncs
);
COPY_SCALAR_FIELD
(
hasRepeatScanFuncs
);
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
8a8939f9
...
...
@@ -717,7 +717,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
select
->
pProjectionList
=
pProjectionList
;
select
->
pFromTable
=
pTable
;
sprintf
(
select
->
stmtName
,
"%p"
,
select
);
select
->
isTime
OrderQuery
=
true
;
select
->
isTime
LineResult
=
true
;
return
(
SNode
*
)
select
;
}
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
8a8939f9
...
...
@@ -440,6 +440,10 @@ static bool isTimelineFunc(const SNode* pNode) {
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsTimelineFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
}
static
bool
isImplicitTsFunc
(
const
SNode
*
pNode
)
{
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsImplicitTsFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
}
static
bool
isScanPseudoColumnFunc
(
const
SNode
*
pNode
)
{
return
(
QUERY_NODE_FUNCTION
==
nodeType
(
pNode
)
&&
fmIsScanPseudoColumnFunc
(((
SFunctionNode
*
)
pNode
)
->
funcId
));
}
...
...
@@ -557,9 +561,9 @@ static bool isInternalPrimaryKey(const SColumnNode* pCol) {
return
PRIMARYKEY_TIMESTAMP_COL_ID
==
pCol
->
colId
&&
0
==
strcmp
(
pCol
->
colName
,
PK_TS_COL_INTERNAL_NAME
);
}
static
bool
isTime
Order
Query
(
SNode
*
pStmt
)
{
static
bool
isTime
Line
Query
(
SNode
*
pStmt
)
{
if
(
QUERY_NODE_SELECT_STMT
==
nodeType
(
pStmt
))
{
return
((
SSelectStmt
*
)
pStmt
)
->
isTime
OrderQuery
;
return
((
SSelectStmt
*
)
pStmt
)
->
isTime
LineResult
;
}
else
{
return
false
;
}
...
...
@@ -580,7 +584,7 @@ static bool isPrimaryKeyImpl(STempTableNode* pTable, SNode* pExpr) {
}
static
bool
isPrimaryKey
(
STempTableNode
*
pTable
,
SNode
*
pExpr
)
{
if
(
!
isTime
Order
Query
(
pTable
->
pSubquery
))
{
if
(
!
isTime
Line
Query
(
pTable
->
pSubquery
))
{
return
false
;
}
return
isPrimaryKeyImpl
(
pTable
,
pExpr
);
...
...
@@ -1252,6 +1256,7 @@ static void setFuncClassification(SNode* pCurrStmt, SFunctionNode* pFunc) {
pSelect
->
hasTailFunc
=
pSelect
->
hasTailFunc
?
true
:
(
FUNCTION_TYPE_TAIL
==
pFunc
->
funcType
);
pSelect
->
hasInterpFunc
=
pSelect
->
hasInterpFunc
?
true
:
(
FUNCTION_TYPE_INTERP
==
pFunc
->
funcType
);
pSelect
->
hasLastRowFunc
=
pSelect
->
hasLastRowFunc
?
true
:
(
FUNCTION_TYPE_LAST_ROW
==
pFunc
->
funcType
);
pSelect
->
hasTimeLineFunc
=
pSelect
->
hasLastRowFunc
?
true
:
fmIsTimelineFunc
(
pFunc
->
funcId
);
}
}
...
...
@@ -2130,7 +2135,7 @@ static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
}
if
(
NULL
!=
pSelect
->
pGroupByList
)
{
pCxt
->
currClause
=
SQL_CLAUSE_GROUP_BY
;
pSelect
->
isTime
OrderQuery
=
false
;
pSelect
->
isTime
LineResult
=
false
;
return
translateExprList
(
pCxt
,
pSelect
->
pGroupByList
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -2464,9 +2469,9 @@ static int32_t createPrimaryKeyCol(STranslateContext* pCxt, SNode** pPrimaryKey)
return
code
;
}
static
EDealRes
rewriteTimeline
FuncImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
appendTsForImplicitTs
FuncImpl
(
SNode
*
pNode
,
void
*
pContext
)
{
STranslateContext
*
pCxt
=
pContext
;
if
(
is
Timeline
Func
(
pNode
))
{
if
(
is
ImplicitTs
Func
(
pNode
))
{
SFunctionNode
*
pFunc
=
(
SFunctionNode
*
)
pNode
;
SNode
*
pPrimaryKey
=
NULL
;
pCxt
->
errCode
=
createPrimaryKeyCol
(
pCxt
,
&
pPrimaryKey
);
...
...
@@ -2478,8 +2483,8 @@ static EDealRes rewriteTimelineFuncImpl(SNode* pNode, void* pContext) {
return
DEAL_RES_CONTINUE
;
}
static
int32_t
rewriteTimeline
Func
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
nodesWalkSelectStmt
(
pSelect
,
SQL_CLAUSE_FROM
,
rewriteTimeline
FuncImpl
,
pCxt
);
static
int32_t
appendTsForImplicitTs
Func
(
STranslateContext
*
pCxt
,
SSelectStmt
*
pSelect
)
{
nodesWalkSelectStmt
(
pSelect
,
SQL_CLAUSE_FROM
,
appendTsForImplicitTs
FuncImpl
,
pCxt
);
return
pCxt
->
errCode
;
}
...
...
@@ -2579,7 +2584,7 @@ static int32_t translateSelectFrom(STranslateContext* pCxt, SSelectStmt* pSelect
code
=
translateInterp
(
pCxt
,
pSelect
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
rewriteTimeline
Func
(
pCxt
,
pSelect
);
code
=
appendTsForImplicitTs
Func
(
pCxt
,
pSelect
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
replaceOrderByAlias
(
pCxt
,
pSelect
->
pProjectionList
,
pSelect
->
pOrderByList
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
8a8939f9
...
...
@@ -542,6 +542,7 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt
pIdfRowsFunc
->
isTailFunc
=
pSelect
->
hasTailFunc
;
pIdfRowsFunc
->
isUniqueFunc
=
pSelect
->
hasUniqueFunc
;
pIdfRowsFunc
->
isTimeLineFunc
=
pSelect
->
hasTimeLineFunc
;
// indefinite rows functions and _select_values functions
int32_t
code
=
nodesCollectFuncs
(
pSelect
,
SQL_CLAUSE_SELECT
,
fmIsVectorFunc
,
&
pIdfRowsFunc
->
pFuncs
);
...
...
source/libs/planner/test/planBasicTest.cpp
浏览文件 @
8a8939f9
...
...
@@ -103,6 +103,14 @@ TEST_F(PlanBasicTest, lastRowFunc) {
run
(
"SELECT LAST_ROW(c1), SUM(c3) FROM t1"
);
}
TEST_F
(
PlanBasicTest
,
timeLineFunc
)
{
useDb
(
"root"
,
"test"
);
run
(
"SELECT CSUM(c1) FROM t1"
);
run
(
"SELECT CSUM(c1) FROM st1"
);
}
TEST_F
(
PlanBasicTest
,
sampleFunc
)
{
useDb
(
"root"
,
"test"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录