Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d0dd4514
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看板
提交
d0dd4514
编写于
6月 12, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor of sample function.
上级
c2e8aa96
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
14 deletion
+25
-14
source/libs/function/inc/builtinsimpl.h
source/libs/function/inc/builtinsimpl.h
+1
-0
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+2
-2
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+22
-12
未找到文件。
source/libs/function/inc/builtinsimpl.h
浏览文件 @
d0dd4514
...
...
@@ -155,6 +155,7 @@ int32_t mavgFunction(SqlFunctionCtx* pCtx);
bool
getSampleFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
sampleFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
int32_t
sampleFunction
(
SqlFunctionCtx
*
pCtx
);
int32_t
sampleFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
);
bool
getTailFuncEnv
(
struct
SFunctionNode
*
pFunc
,
SFuncExecEnv
*
pEnv
);
bool
tailFunctionSetup
(
SqlFunctionCtx
*
pCtx
,
SResultRowEntryInfo
*
pResultInfo
);
...
...
source/libs/function/src/builtins.c
浏览文件 @
d0dd4514
...
...
@@ -1751,12 +1751,12 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"sample"
,
.
type
=
FUNCTION_TYPE_SAMPLE
,
.
classification
=
FUNC_MGT_
INDEFINITE_ROWS_FUNC
|
FUNC_MGT_TIMELINE
_FUNC
,
.
classification
=
FUNC_MGT_
AGG_FUNC
|
FUNC_MGT_SELECT_FUNC
|
FUNC_MGT_INDEFINITE_ROWS
_FUNC
,
.
translateFunc
=
translateSample
,
.
getEnvFunc
=
getSampleFuncEnv
,
.
initFunc
=
sampleFunctionSetup
,
.
processFunc
=
sampleFunction
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
sampleFinalize
},
{
.
name
=
"tail"
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
d0dd4514
...
...
@@ -198,7 +198,7 @@ typedef struct SSampleInfo {
int32_t
numSampled
;
uint8_t
colType
;
int16_t
colBytes
;
char
*
data
;
char
*
data
;
int64_t
*
timestamp
;
}
SSampleInfo
;
...
...
@@ -4183,28 +4183,38 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx) {
SSampleInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
TSKEY
*
tsList
=
(
int64_t
*
)
pInput
->
pPTS
->
pData
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
SColumnInfoData
*
pOutput
=
(
SColumnInfoData
*
)
pCtx
->
pOutput
;
int32_t
alreadySampled
=
pInfo
->
numSampled
;
TSKEY
*
tsList
=
NULL
;
if
(
pInput
->
pPTS
!=
NULL
)
{
tsList
=
(
int64_t
*
)
pInput
->
pPTS
->
pData
;
}
int32_t
startOffset
=
pCtx
->
offset
;
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
]
;
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
i
+=
1
)
{
if
(
colDataIsNull_s
(
pInputCol
,
i
))
{
//colDataAppendNULL(pOutput, i);
continue
;
}
char
*
data
=
colDataGetData
(
pInputCol
,
i
);
doReservoirSample
(
pInfo
,
data
,
tsList
[
i
]
,
i
);
doReservoirSample
(
pInfo
,
data
,
/*tsList[i]*/
0
,
i
);
}
SET_VAL
(
pResInfo
,
pInfo
->
numSampled
,
pInfo
->
numSampled
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
sampleFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
SSampleInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pEntryInfo
);
pEntryInfo
->
complete
=
true
;
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
int32_t
currentRow
=
pBlock
->
info
.
rows
;
for
(
int32_t
i
=
0
;
i
<
pInfo
->
numSampled
;
++
i
)
{
int32_t
pos
=
startOffset
+
i
;
colDataAppend
(
pOutput
,
pos
,
pInfo
->
data
+
i
*
pInfo
->
colBytes
,
false
);
//TODO: handle ts output
colDataAppend
(
pCol
,
currentRow
+
i
,
pInfo
->
data
+
i
*
pInfo
->
colBytes
,
false
);
}
return
pInfo
->
numSampled
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录