Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
3fc7fa3b
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看板
提交
3fc7fa3b
编写于
6月 21, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add sample function work with selectivity
上级
55a79f25
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
20 deletion
+21
-20
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+21
-20
未找到文件。
source/libs/function/src/builtinsimpl.c
浏览文件 @
3fc7fa3b
...
...
@@ -195,13 +195,13 @@ typedef struct SMavgInfo {
}
SMavgInfo
;
typedef
struct
SSampleInfo
{
int32_t
samples
;
int32_t
totalPoints
;
int32_t
numSampled
;
uint8_t
colType
;
int16_t
colBytes
;
char
*
data
;
int64_t
*
timestamp
;
int32_t
samples
;
int32_t
totalPoints
;
int32_t
numSampled
;
uint8_t
colType
;
int16_t
colBytes
;
char
*
data
;
STuplePos
*
tuplePos
;
}
SSampleInfo
;
typedef
struct
STailItem
{
...
...
@@ -4350,7 +4350,7 @@ bool getSampleFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
int32_t
numOfSamples
=
pVal
->
datum
.
i
;
pEnv
->
calcMemSize
=
sizeof
(
SSampleInfo
)
+
numOfSamples
*
(
pCol
->
node
.
resType
.
bytes
+
sizeof
(
int64_t
));
pEnv
->
calcMemSize
=
sizeof
(
SSampleInfo
)
+
numOfSamples
*
(
pCol
->
node
.
resType
.
bytes
+
sizeof
(
STuplePos
));
return
true
;
}
...
...
@@ -4371,25 +4371,30 @@ bool sampleFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo)
return
false
;
}
pInfo
->
data
=
(
char
*
)
pInfo
+
sizeof
(
SSampleInfo
);
pInfo
->
t
imestamp
=
(
int64_t
*
)((
char
*
)
pInfo
+
sizeof
(
SSampleInfo
)
+
pInfo
->
samples
*
pInfo
->
colBytes
);
pInfo
->
t
uplePos
=
(
STuplePos
*
)((
char
*
)
pInfo
+
sizeof
(
SSampleInfo
)
+
pInfo
->
samples
*
pInfo
->
colBytes
);
return
true
;
}
static
void
sampleAssignResult
(
SSampleInfo
*
pInfo
,
char
*
data
,
TSKEY
ts
,
int32_t
index
)
{
static
void
sampleAssignResult
(
SSampleInfo
*
pInfo
,
char
*
data
,
int32_t
index
)
{
assignVal
(
pInfo
->
data
+
index
*
pInfo
->
colBytes
,
data
,
pInfo
->
colBytes
,
pInfo
->
colType
);
*
(
pInfo
->
timestamp
+
index
)
=
ts
;
}
static
void
doReservoirSample
(
S
SampleInfo
*
pInfo
,
char
*
data
,
TSKEY
ts
,
int32_t
index
)
{
static
void
doReservoirSample
(
S
qlFunctionCtx
*
pCtx
,
SSampleInfo
*
pInfo
,
char
*
data
,
int32_t
index
)
{
pInfo
->
totalPoints
++
;
if
(
pInfo
->
numSampled
<
pInfo
->
samples
)
{
sampleAssignResult
(
pInfo
,
data
,
ts
,
pInfo
->
numSampled
);
sampleAssignResult
(
pInfo
,
data
,
pInfo
->
numSampled
);
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
index
,
pCtx
->
pSrcBlock
,
pInfo
->
tuplePos
+
pInfo
->
numSampled
*
sizeof
(
STuplePos
));
}
pInfo
->
numSampled
++
;
}
else
{
int32_t
j
=
taosRand
()
%
(
pInfo
->
totalPoints
);
if
(
j
<
pInfo
->
samples
)
{
sampleAssignResult
(
pInfo
,
data
,
ts
,
j
);
sampleAssignResult
(
pInfo
,
data
,
j
);
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
index
,
pCtx
->
pSrcBlock
,
pInfo
->
tuplePos
+
j
*
sizeof
(
STuplePos
));
}
}
}
}
...
...
@@ -4400,11 +4405,6 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx) {
SInputColumnInfoData
*
pInput
=
&
pCtx
->
input
;
TSKEY
*
tsList
=
NULL
;
if
(
pInput
->
pPTS
!=
NULL
)
{
tsList
=
(
int64_t
*
)
pInput
->
pPTS
->
pData
;
}
SColumnInfoData
*
pInputCol
=
pInput
->
pData
[
0
];
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
i
+=
1
)
{
if
(
colDataIsNull_s
(
pInputCol
,
i
))
{
...
...
@@ -4412,7 +4412,7 @@ int32_t sampleFunction(SqlFunctionCtx* pCtx) {
}
char
*
data
=
colDataGetData
(
pInputCol
,
i
);
doReservoirSample
(
p
Info
,
data
,
/*tsList[i]*/
0
,
i
);
doReservoirSample
(
p
Ctx
,
pInfo
,
data
,
i
);
}
SET_VAL
(
pResInfo
,
pInfo
->
numSampled
,
pInfo
->
numSampled
);
...
...
@@ -4431,6 +4431,7 @@ int32_t sampleFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
int32_t
currentRow
=
pBlock
->
info
.
rows
;
for
(
int32_t
i
=
0
;
i
<
pInfo
->
numSampled
;
++
i
)
{
colDataAppend
(
pCol
,
currentRow
+
i
,
pInfo
->
data
+
i
*
pInfo
->
colBytes
,
false
);
setSelectivityValue
(
pCtx
,
pBlock
,
pInfo
->
tuplePos
+
i
*
sizeof
(
STuplePos
),
currentRow
+
i
);
}
return
pInfo
->
numSampled
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录