Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
860bf88f
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
提交
860bf88f
编写于
6月 30, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add last_row function without cache
TD-16927
上级
45e9b239
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
116 addition
and
25 deletion
+116
-25
include/libs/function/functionMgt.h
include/libs/function/functionMgt.h
+1
-0
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+3
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+4
-7
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+108
-18
未找到文件。
include/libs/function/functionMgt.h
浏览文件 @
860bf88f
...
@@ -34,6 +34,7 @@ typedef enum EFunctionType {
...
@@ -34,6 +34,7 @@ typedef enum EFunctionType {
FUNCTION_TYPE_ELAPSED
,
FUNCTION_TYPE_ELAPSED
,
FUNCTION_TYPE_IRATE
,
FUNCTION_TYPE_IRATE
,
FUNCTION_TYPE_LAST_ROW
,
FUNCTION_TYPE_LAST_ROW
,
FUNCTION_TYPE_LAST_ROWT
,
FUNCTION_TYPE_MAX
,
FUNCTION_TYPE_MAX
,
FUNCTION_TYPE_MIN
,
FUNCTION_TYPE_MIN
,
FUNCTION_TYPE_MODE
,
FUNCTION_TYPE_MODE
,
...
...
source/libs/function/inc/builtinsimpl.h
浏览文件 @
860bf88f
...
@@ -117,6 +117,9 @@ int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
...
@@ -117,6 +117,9 @@ int32_t firstCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx);
int32_t
lastCombine
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
);
int32_t
lastCombine
(
SqlFunctionCtx
*
pDestCtx
,
SqlFunctionCtx
*
pSourceCtx
);
int32_t
getFirstLastInfoSize
(
int32_t
resBytes
);
int32_t
getFirstLastInfoSize
(
int32_t
resBytes
);
int32_t
lastRowFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
lastRowFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getTopBotFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
bool
getTopBotFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
bool
getTopBotMergeFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
bool
getTopBotMergeFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
);
bool
topBotFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
bool
topBotFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
860bf88f
...
@@ -1947,17 +1947,14 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
...
@@ -1947,17 +1947,14 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
finalizeFunc
=
irateFinalize
.
finalizeFunc
=
irateFinalize
},
},
{
{
.
name
=
"last_row"
,
.
name
=
"last_row
t
"
,
.
type
=
FUNCTION_TYPE_LAST_ROW
,
.
type
=
FUNCTION_TYPE_LAST_ROW
T
,
.
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
,
.
translateFunc
=
translateFirstLast
,
.
translateFunc
=
translateFirstLast
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
.
initFunc
=
functionSetup
,
.
processFunc
=
lastFunction
,
.
processFunc
=
lastRowFunction
,
.
finalizeFunc
=
firstLastFinalize
,
.
finalizeFunc
=
lastRowFinalize
,
.
pPartialFunc
=
"_last_partial"
,
.
pMergeFunc
=
"_last_merge"
,
.
combineFunc
=
lastCombine
,
},
},
{
{
.
name
=
"_cache_last_row"
,
.
name
=
"_cache_last_row"
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
860bf88f
...
@@ -80,6 +80,7 @@ typedef struct STopBotRes {
...
@@ -80,6 +80,7 @@ typedef struct STopBotRes {
typedef
struct
SFirstLastRes
{
typedef
struct
SFirstLastRes
{
bool
hasResult
;
bool
hasResult
;
bool
isNull
;
//used for last_row function only
int32_t
bytes
;
int32_t
bytes
;
char
buf
[];
char
buf
[];
}
SFirstLastRes
;
}
SFirstLastRes
;
...
@@ -2597,15 +2598,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
...
@@ -2597,15 +2598,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
else
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
}
pInfo
->
hasResult
=
true
;
pInfo
->
hasResult
=
true
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
pResInfo
->
numOfRes
=
1
;
...
@@ -2629,15 +2621,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
...
@@ -2629,15 +2621,6 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
//handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
else
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
}
pInfo
->
hasResult
=
true
;
pInfo
->
hasResult
=
true
;
pResInfo
->
numOfRes
=
1
;
pResInfo
->
numOfRes
=
1
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
...
@@ -2763,6 +2746,113 @@ int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
...
@@ -2763,6 +2746,113 @@ int32_t lastCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
lastRowFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SFirstLastRes
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
int32_t
type
=
pInputCol
->
info
.
type
;
int32_t
bytes
=
pInputCol
->
info
.
bytes
;
pInfo
->
bytes
=
bytes
;
SColumnDataAgg
*
pColAgg
=
(
pInput
->
colDataAggIsSet
)
?
pInput
->
pColumnDataAgg
[
0
]
:
NULL
;
TSKEY
startKey
=
getRowPTs
(
pInput
->
pPTS
,
0
);
TSKEY
endKey
=
getRowPTs
(
pInput
->
pPTS
,
pInput
->
totalRows
-
1
);
int32_t
blockDataOrder
=
(
startKey
<=
endKey
)
?
TSDB_ORDER_ASC
:
TSDB_ORDER_DESC
;
if
(
blockDataOrder
==
TSDB_ORDER_ASC
)
{
for
(
int32_t
i
=
pInput
->
numOfRows
+
pInput
->
startRowIndex
-
1
;
i
>=
pInput
->
startRowIndex
;
--
i
)
{
char
*
data
=
colDataGetData
(
pInputCol
,
i
);
TSKEY
cts
=
getRowPTs
(
pInput
->
pPTS
,
i
);
if
(
pResInfo
->
numOfRes
==
0
||
*
(
TSKEY
*
)(
pInfo
->
buf
)
<
cts
)
{
if
(
pInputCol
->
hasNull
&&
colDataIsNull
(
pInputCol
,
pInput
->
totalRows
,
i
,
pColAgg
))
{
pInfo
->
isNull
=
true
;
}
else
{
pInfo
->
isNull
=
false
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
bytes
=
varDataTLen
(
data
);
pInfo
->
bytes
=
bytes
;
}
memcpy
(
pInfo
->
buf
+
sizeof
(
TSKEY
),
data
,
bytes
);
}
*
(
TSKEY
*
)(
pInfo
->
buf
)
=
cts
;
numOfElems
++
;
//handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
else
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
}
pInfo
->
hasResult
=
true
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
}
break
;
}
}
else
{
// descending order
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
++
i
)
{
char
*
data
=
colDataGetData
(
pInputCol
,
i
);
TSKEY
cts
=
getRowPTs
(
pInput
->
pPTS
,
i
);
if
(
pResInfo
->
numOfRes
==
0
||
*
(
TSKEY
*
)(
pInfo
->
buf
)
<
cts
)
{
if
(
pInputCol
->
hasNull
&&
colDataIsNull
(
pInputCol
,
pInput
->
totalRows
,
i
,
pColAgg
))
{
pInfo
->
isNull
=
true
;
}
else
{
pInfo
->
isNull
=
false
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
bytes
=
varDataTLen
(
data
);
pInfo
->
bytes
=
bytes
;
}
memcpy
(
pInfo
->
buf
+
sizeof
(
TSKEY
),
data
,
bytes
);
}
*
(
TSKEY
*
)(
pInfo
->
buf
)
=
cts
;
numOfElems
++
;
//handle selectivity
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pInfo
->
buf
+
bytes
+
sizeof
(
TSKEY
));
if
(
!
pInfo
->
hasResult
)
{
saveTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
else
{
copyTupleData
(
pCtx
,
i
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
}
pInfo
->
hasResult
=
true
;
pResInfo
->
numOfRes
=
1
;
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
}
break
;
}
}
SET_VAL
(
pResInfo
,
numOfElems
,
1
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
lastRowFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
SResultRowEntryInfo
*
pResInfo
=
GET_RES_INFO
(
pCtx
);
SFirstLastRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
pRes
->
buf
+
sizeof
(
TSKEY
),
pRes
->
isNull
);
//handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pRes
->
buf
+
pRes
->
bytes
+
sizeof
(
TSKEY
));
setSelectivityValue
(
pCtx
,
pBlock
,
pTuplePos
,
pBlock
->
info
.
rows
);
return
pResInfo
->
numOfRes
;
}
bool
getDiffFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
bool
getDiffFuncEnv
(
SFunctionNode
*
UNUSED_PARAM
(
pFunc
),
SFuncExecEnv
*
pEnv
)
{
pEnv
->
calcMemSize
=
sizeof
(
SDiffInfo
);
pEnv
->
calcMemSize
=
sizeof
(
SDiffInfo
);
return
true
;
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录