Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
4524b826
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,发现更多精彩内容 >>
未验证
提交
4524b826
编写于
6月 29, 2022
作者:
G
Ganlin Zhao
提交者:
GitHub
6月 29, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14323 from taosdata/enh/first_last_select
enh(query): first/last function support selectivity
上级
5c8d734c
e9fba684
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
78 addition
and
19 deletion
+78
-19
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+4
-4
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+70
-11
tests/system-test/2-query/json_tag.py
tests/system-test/2-query/json_tag.py
+4
-4
未找到文件。
source/libs/function/src/builtins.c
浏览文件 @
4524b826
...
...
@@ -1904,7 +1904,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_first_partial"
,
.
type
=
FUNCTION_TYPE_FIRST_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_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
,
.
translateFunc
=
translateFirstLastPartial
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1915,7 +1915,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_first_merge"
,
.
type
=
FUNCTION_TYPE_FIRST_MERGE
,
.
classification
=
FUNC_MGT_AGG_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
,
.
translateFunc
=
translateFirstLastMerge
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1939,7 +1939,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_last_partial"
,
.
type
=
FUNCTION_TYPE_LAST_PARTIAL
,
.
classification
=
FUNC_MGT_AGG_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
,
.
translateFunc
=
translateFirstLastPartial
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
@@ -1950,7 +1950,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
{
.
name
=
"_last_merge"
,
.
type
=
FUNCTION_TYPE_LAST_MERGE
,
.
classification
=
FUNC_MGT_AGG_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
,
.
translateFunc
=
translateFirstLastMerge
,
.
getEnvFunc
=
getFirstLastFuncEnv
,
.
initFunc
=
functionSetup
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
4524b826
...
...
@@ -2409,11 +2409,11 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
return
TSDB_CODE_SUCCESS
;
}
int32_t
getFirstLastInfoSize
(
int32_t
resBytes
)
{
return
sizeof
(
SFirstLastRes
)
+
resBytes
+
sizeof
(
int64_t
);
}
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
);
pEnv
->
calcMemSize
=
sizeof
(
SFirstLastRes
)
+
pNode
->
node
.
resType
.
bytes
+
sizeof
(
int64_t
);
pEnv
->
calcMemSize
=
getFirstLastInfoSize
(
pNode
->
node
.
resType
.
bytes
);
return
true
;
}
...
...
@@ -2491,9 +2491,17 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
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
;
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
break
;
}
...
...
@@ -2525,8 +2533,17 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
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
;
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
pResInfo
->
numOfRes
=
1
;
break
;
}
...
...
@@ -2580,8 +2597,17 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
TSKEY
*
)(
pInfo
->
buf
+
bytes
)
=
cts
;
// DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//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
;
...
...
@@ -2603,9 +2629,18 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
}
memcpy
(
pInfo
->
buf
,
data
,
bytes
);
*
(
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
;
pResInfo
->
numOfRes
=
1
;
//
DO_UPDATE_TAG_COLUMNS(pCtx, ts);
//DO_UPDATE_TAG_COLUMNS(pCtx, ts);
}
break
;
}
...
...
@@ -2615,7 +2650,10 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
return
TSDB_CODE_SUCCESS
;
}
static
void
firstLastTransferInfo
(
SFirstLastRes
*
pInput
,
SFirstLastRes
*
pOutput
,
bool
isFirst
)
{
static
void
firstLastTransferInfo
(
SqlFunctionCtx
*
pCtx
,
SFirstLastRes
*
pInput
,
SFirstLastRes
*
pOutput
,
bool
isFirst
)
{
SInputColumnInfoData
*
pColInfo
=
&
pCtx
->
input
;
int32_t
start
=
pColInfo
->
startRowIndex
;
pOutput
->
bytes
=
pInput
->
bytes
;
TSKEY
*
tsIn
=
(
TSKEY
*
)(
pInput
->
buf
+
pInput
->
bytes
);
TSKEY
*
tsOut
=
(
TSKEY
*
)(
pOutput
->
buf
+
pInput
->
bytes
);
...
...
@@ -2632,7 +2670,17 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput,
}
*
tsOut
=
*
tsIn
;
memcpy
(
pOutput
->
buf
,
pInput
->
buf
,
pOutput
->
bytes
);
//handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pOutput
->
buf
+
pOutput
->
bytes
+
sizeof
(
TSKEY
));
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
if
(
!
pOutput
->
hasResult
)
{
saveTupleData
(
pCtx
,
start
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
else
{
copyTupleData
(
pCtx
,
start
,
pCtx
->
pSrcBlock
,
pTuplePos
);
}
}
pOutput
->
hasResult
=
true
;
return
;
}
...
...
@@ -2647,7 +2695,7 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer
char
*
data
=
colDataGetData
(
pCol
,
start
);
SFirstLastRes
*
pInputInfo
=
(
SFirstLastRes
*
)
varDataVal
(
data
);
firstLastTransferInfo
(
pInputInfo
,
pInfo
,
isFirstQuery
);
firstLastTransferInfo
(
p
Ctx
,
p
InputInfo
,
pInfo
,
isFirstQuery
);
int32_t
numOfElems
=
pInputInfo
->
hasResult
?
1
:
0
;
...
...
@@ -2669,6 +2717,9 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SFirstLastRes
*
pRes
=
GET_ROWCELL_INTERBUF
(
pResInfo
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
pRes
->
buf
,
pResInfo
->
isNullRes
);
//handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pRes
->
buf
+
pRes
->
bytes
+
sizeof
(
TSKEY
));
setSelectivityValue
(
pCtx
,
pBlock
,
pTuplePos
,
pBlock
->
info
.
rows
);
return
pResInfo
->
numOfRes
;
}
...
...
@@ -2687,6 +2738,9 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
SColumnInfoData
*
pCol
=
taosArrayGet
(
pBlock
->
pDataBlock
,
slotId
);
colDataAppend
(
pCol
,
pBlock
->
info
.
rows
,
res
,
false
);
//handle selectivity
STuplePos
*
pTuplePos
=
(
STuplePos
*
)(
pRes
->
buf
+
pRes
->
bytes
+
sizeof
(
TSKEY
));
setSelectivityValue
(
pCtx
,
pBlock
,
pTuplePos
,
pBlock
->
info
.
rows
);
taosMemoryFree
(
res
);
return
1
;
...
...
@@ -3043,7 +3097,9 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
pItem
->
uid
=
uid
;
// save the data of this tuple
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
saveTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
}
// allocate the buffer and keep the data of this row into the new allocated buffer
pEntryInfo
->
numOfRes
++
;
...
...
@@ -3062,7 +3118,10 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
pItem
->
uid
=
uid
;
// save the data of this tuple by over writing the old data
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
if
(
pCtx
->
subsidiaries
.
num
>
0
)
{
copyTupleData
(
pCtx
,
rowIndex
,
pSrcBlock
,
&
pItem
->
tuplePos
);
}
taosheapadjust
((
void
*
)
pItems
,
sizeof
(
STopBotResItem
),
0
,
pEntryInfo
->
numOfRes
-
1
,
(
const
void
*
)
&
type
,
topBotResComparFn
,
NULL
,
!
isTopQuery
);
}
...
...
tests/system-test/2-query/json_tag.py
浏览文件 @
4524b826
...
...
@@ -562,7 +562,7 @@ class TDTestCase:
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select round(dataint) from jsons1 where jtag->'tag1'>1"
)
tdSql
.
checkRows
(
3
)
#math function
tdSql
.
query
(
"select sin(dataint) from jsons1 where jtag->'tag1'>1;"
)
tdSql
.
checkRows
(
3
)
...
...
@@ -606,7 +606,7 @@ class TDTestCase:
tdSql
.
checkRows
(
1
)
tdSql
.
query
(
"select twa(dataint) from jsons1 where jtag->'tag1'>1;"
)
tdSql
.
checkRows
(
1
)
# function not ready
# tdSql.query("select tail(dataint,1) from jsons1 where jtag->'tag1'>1;")
# tdSql.checkRows(3)
...
...
@@ -616,7 +616,7 @@ class TDTestCase:
# tdSql.checkRows(3)
# tdSql.query("select irate(dataint) from jsons1 where jtag->'tag1'>1;")
# tdSql.checkRows(1)
#str function
tdSql
.
query
(
"select upper(dataStr) from jsons1 where jtag->'tag1'>1;"
)
tdSql
.
checkRows
(
3
)
...
...
@@ -658,7 +658,7 @@ class TDTestCase:
tdSql
.
checkRows
(
3
)
tdSql
.
query
(
"select ELAPSED(ts,1h) from jsons1 where jtag->'tag1'>1;"
)
tdSql
.
checkRows
(
1
)
#
# #test TD-12077
tdSql
.
execute
(
"insert into jsons1_16 using jsons1 tags('{
\"
tag1
\"
:
\"
收到货
\"
,
\"
tag2
\"
:
\"\"
,
\"
tag3
\"
:-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录