Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4be158b3
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
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看板
提交
4be158b3
编写于
5月 16, 2022
作者:
G
Ganlin Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(query): add tail function
上级
3ef067ff
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
48 addition
and
18 deletion
+48
-18
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+1
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+47
-17
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
4be158b3
...
...
@@ -884,7 +884,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
.
getEnvFunc
=
getTailFuncEnv
,
.
initFunc
=
tailFunctionSetup
,
.
processFunc
=
tailFunction
,
.
finalizeFunc
=
NULL
.
finalizeFunc
=
tailFinalize
},
{
.
name
=
"abs"
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
4be158b3
...
...
@@ -164,10 +164,10 @@ typedef struct SSampleInfo {
int64_t
*
timestamp
;
}
SSampleInfo
;
typedef
struct
STail
Unit
{
typedef
struct
STail
Item
{
int64_t
timestamp
;
char
data
[];
}
STail
Unit
;
}
STail
Item
;
typedef
struct
STailInfo
{
int32_t
numOfPoints
;
...
...
@@ -175,7 +175,7 @@ typedef struct STailInfo {
int32_t
offset
;
uint8_t
colType
;
int16_t
colBytes
;
STail
Unit
**
pRe
s
;
STail
Item
**
pItem
s
;
}
STailInfo
;
#define SET_VAL(_info, numOfElem, res) \
...
...
@@ -3164,7 +3164,7 @@ bool getTailFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
SColumnNode
*
pCol
=
(
SColumnNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
0
);
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesListGetNode
(
pFunc
->
pParameterList
,
1
);
int32_t
numOfPoints
=
pVal
->
datum
.
i
;
pEnv
->
calcMemSize
=
sizeof
(
STailInfo
)
+
numOfPoints
*
(
POINTER_BYTES
+
sizeof
(
STail
Unit
)
+
pCol
->
node
.
resType
.
bytes
);
pEnv
->
calcMemSize
=
sizeof
(
STailInfo
)
+
numOfPoints
*
(
POINTER_BYTES
+
sizeof
(
STail
Item
)
+
pCol
->
node
.
resType
.
bytes
);
return
true
;
}
...
...
@@ -3184,36 +3184,37 @@ bool tailFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo *pResultInfo) {
return
false
;
}
pInfo
->
p
Res
=
(
STailUnit
**
)((
char
*
)
pInfo
+
sizeof
(
STailInfo
));
char
*
p
Unit
=
(
char
*
)
pInfo
->
pRe
s
+
pInfo
->
numOfPoints
*
POINTER_BYTES
;
pInfo
->
p
Items
=
(
STailItem
**
)((
char
*
)
pInfo
+
sizeof
(
STailInfo
));
char
*
p
Item
=
(
char
*
)
pInfo
->
pItem
s
+
pInfo
->
numOfPoints
*
POINTER_BYTES
;
size_t
unitSize
=
sizeof
(
STail
Unit
)
+
pInfo
->
colBytes
;
size_t
unitSize
=
sizeof
(
STail
Item
)
+
pInfo
->
colBytes
;
for
(
int32_t
i
=
0
;
i
<
pInfo
->
numOfPoints
;
++
i
)
{
pInfo
->
p
Res
[
i
]
=
(
STailUnit
*
)(
pUnit
+
i
*
unitSize
);
pInfo
->
p
Items
[
i
]
=
(
STailItem
*
)(
pItem
+
i
*
unitSize
);
}
return
true
;
}
static
void
tailAssignResult
(
STail
Unit
*
pUnit
,
char
*
data
,
int32_t
colBytes
,
TSKEY
ts
)
{
p
Unit
->
timestamp
=
ts
;
memcpy
(
p
Unit
->
data
,
data
,
colBytes
);
static
void
tailAssignResult
(
STail
Item
*
pItem
,
char
*
data
,
int32_t
colBytes
,
TSKEY
ts
)
{
p
Item
->
timestamp
=
ts
;
memcpy
(
p
Item
->
data
,
data
,
colBytes
);
}
static
int32_t
tailCompFn
(
const
void
*
p1
,
const
void
*
p2
,
const
void
*
param
)
{
STail
Unit
*
d1
=
*
(
STailUnit
**
)
p1
;
STail
Unit
*
d2
=
*
(
STailUnit
**
)
p2
;
STail
Item
*
d1
=
*
(
STailItem
**
)
p1
;
STail
Item
*
d2
=
*
(
STailItem
**
)
p2
;
return
compareInt64Val
(
&
d1
->
timestamp
,
&
d2
->
timestamp
);
}
static
void
doTailAdd
(
STailInfo
*
pInfo
,
char
*
data
,
TSKEY
ts
)
{
STail
Unit
**
pList
=
pInfo
->
pRe
s
;
STail
Item
**
pList
=
pInfo
->
pItem
s
;
if
(
pInfo
->
numAdded
<
pInfo
->
numOfPoints
)
{
tailAssignResult
(
pList
[
pInfo
->
numAdded
],
data
,
pInfo
->
colBytes
,
ts
);
taosheapsort
((
void
*
)
pList
,
sizeof
(
STailUnit
**
),
pInfo
->
numAdded
+
1
,
NULL
,
tailCompFn
,
0
);
taosheapsort
((
void
*
)
pList
,
sizeof
(
STailItem
**
),
pInfo
->
numAdded
+
1
,
NULL
,
tailCompFn
,
0
);
pInfo
->
numAdded
++
;
}
else
if
(
pList
[
0
]
->
timestamp
<
ts
)
{
tailAssignResult
(
pList
[
0
],
data
,
pInfo
->
colBytes
,
ts
);
taosheapadjust
((
void
*
)
pList
,
sizeof
(
STail
Unit
**
),
0
,
pInfo
->
numOfPoints
-
1
,
NULL
,
tailCompFn
,
NULL
,
0
);
taosheapadjust
((
void
*
)
pList
,
sizeof
(
STail
Item
**
),
0
,
pInfo
->
numOfPoints
-
1
,
NULL
,
tailCompFn
,
NULL
,
0
);
}
}
...
...
@@ -3231,7 +3232,7 @@ int32_t tailFunction(SqlFunctionCtx* pCtx) {
int32_t
startOffset
=
pCtx
->
offset
;
for
(
int32_t
i
=
pInput
->
startRowIndex
;
i
<
pInput
->
numOfRows
+
pInput
->
startRowIndex
;
i
+=
1
)
{
if
(
colDataIsNull_f
(
pInputCol
->
nullbitmap
,
i
))
{
//
colDataAppendNULL(pOutput, i);
colDataAppendNULL
(
pOutput
,
i
);
continue
;
}
...
...
@@ -3239,5 +3240,34 @@ int32_t tailFunction(SqlFunctionCtx* pCtx) {
doTailAdd
(
pInfo
,
data
,
tsList
[
i
]);
}
for
(
int32_t
i
=
0
;
i
<
pInfo
->
numOfPoints
;
++
i
)
{
int32_t
pos
=
startOffset
+
i
;
STailItem
*
pItem
=
pInfo
->
pItems
[
i
];
colDataAppend
(
pOutput
,
pos
,
pItem
->
data
,
false
);
}
return
pInfo
->
numOfPoints
;
}
int32_t
tailFinalize
(
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SResultRowEntryInfo
*
pEntryInfo
=
GET_RES_INFO
(
pCtx
);
STailInfo
*
pInfo
=
GET_ROWCELL_INTERBUF
(
pEntryInfo
);
pEntryInfo
->
complete
=
true
;
int32_t
type
=
pCtx
->
input
.
pData
[
0
]
->
info
.
type
;
int32_t
slotId
=
pCtx
->
pExpr
->
base
.
resSchema
.
slotId
;
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
// todo assign the tag value and the corresponding row data
int32_t
currentRow
=
pBlock
->
info
.
rows
;
for
(
int32_t
i
=
0
;
i
<
pEntryInfo
->
numOfRes
;
++
i
)
{
STailItem
*
pItem
=
pInfo
->
pItems
[
i
];
colDataAppend
(
pCol
,
currentRow
,
pItem
->
data
,
false
);
//setSelectivityValue(pCtx, pBlock, &pInfo->pItems[i].tuplePos, currentRow);
currentRow
+=
1
;
}
return
pEntryInfo
->
numOfRes
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录