Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5d5d0a24
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看板
未验证
提交
5d5d0a24
编写于
6月 22, 2022
作者:
M
Minglei Jin
提交者:
GitHub
6月 22, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14052 from taosdata/fix/TS-1619-V26
fix: multi group by compare key same
上级
35a05770
5a53e235
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
41 addition
and
20 deletion
+41
-20
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+24
-20
tests/pytest/query/queryGroupbySort.py
tests/pytest/query/queryGroupbySort.py
+17
-0
未找到文件。
src/query/src/qExecutor.c
浏览文件 @
5d5d0a24
...
...
@@ -1588,6 +1588,8 @@ static bool initGroupbyInfo(const SSDataBlock *pSDataBlock, const SGroupbyExpr *
return
true
;
}
pInfo
->
pGroupbyDataInfo
=
taosArrayInit
(
pGroupbyExpr
->
numOfGroupCols
,
sizeof
(
SGroupbyDataInfo
));
// head put key length (int32_t type)
pInfo
->
totalBytes
=
sizeof
(
int32_t
);
for
(
int32_t
k
=
0
;
k
<
pGroupbyExpr
->
numOfGroupCols
;
++
k
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
k
);
...
...
@@ -1625,6 +1627,7 @@ static void buildGroupbyKeyBuf(const SSDataBlock *pSDataBlock, SGroupbyOperatorI
return
;
}
*
buf
=
p
;
p
+=
sizeof
(
int32_t
);
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
...
...
@@ -1646,26 +1649,22 @@ static void buildGroupbyKeyBuf(const SSDataBlock *pSDataBlock, SGroupbyOperatorI
memcpy
(
p
,
MULTI_KEY_DELIM
,
strlen
(
MULTI_KEY_DELIM
));
p
+=
strlen
(
MULTI_KEY_DELIM
);
}
// calc keyLen and save
int32_t
keyLen
=
(
p
-
*
buf
)
-
sizeof
(
int32_t
);
*
(
int32_t
*
)(
*
buf
)
=
keyLen
;
}
static
bool
isGroupbyKeyEqual
(
void
*
a
,
void
*
b
,
void
*
ext
)
{
SGroupbyOperatorInfo
*
pInfo
=
(
SGroupbyOperatorInfo
*
)
ext
;
if
(
memcmp
(
a
,
b
,
pInfo
->
totalBytes
)
==
0
)
{
return
true
;
}
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
char
*
k1
=
(
char
*
)
a
+
offset
;
char
*
k2
=
(
char
*
)
b
+
offset
;
if
(
getComparFunc
(
pDataInfo
->
type
,
0
)(
k1
,
k2
)
!=
0
)
{
int32_t
len1
=
*
(
int32_t
*
)
a
;
int32_t
len2
=
*
(
int32_t
*
)
b
;
if
(
len1
!=
len2
)
{
return
false
;
}
offset
+=
pDataInfo
->
bytes
;
offset
+=
(
int32_t
)
strlen
(
MULTI_KEY_DELIM
);
}
return
true
;
char
*
a1
=
(
char
*
)
a
+
sizeof
(
int32_t
)
;
char
*
b1
=
(
char
*
)
b
+
sizeof
(
int32_t
);
return
memcmp
(
a1
,
b1
,
len1
)
==
0
;
}
static
void
doHashGroupbyAgg
(
SOperatorInfo
*
pOperator
,
SGroupbyOperatorInfo
*
pInfo
,
SSDataBlock
*
pSDataBlock
)
{
...
...
@@ -1708,7 +1707,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
pInfo
);
}
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
pInfo
->
prevData
,
type
,
pInfo
->
totalBytes
,
item
->
groupIndex
);
char
*
preKey
=
pInfo
->
prevData
+
sizeof
(
int32_t
);
int32_t
keyLen
=
*
(
int32_t
*
)
pInfo
->
prevData
;
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
preKey
,
type
,
keyLen
,
item
->
groupIndex
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
...
...
@@ -1730,7 +1731,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
if
(
pQueryAttr
->
stableQuery
&&
pQueryAttr
->
stabledev
&&
(
pRuntimeEnv
->
prevResult
!=
NULL
))
{
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
pInfo
);
}
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
pInfo
->
prevData
,
type
,
pInfo
->
totalBytes
,
item
->
groupIndex
);
char
*
preKey
=
pInfo
->
prevData
+
sizeof
(
int32_t
);
int32_t
keyLen
=
*
(
int32_t
*
)
pInfo
->
prevData
;
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
preKey
,
type
,
keyLen
,
item
->
groupIndex
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
...
...
@@ -4312,14 +4315,15 @@ void setParamForStableStddevByColData(SQueryRuntimeEnv* pRuntimeEnv, SQLFunction
// find colid in dataBlock
int32_t
bytes
,
offset
=
0
;
char
*
val
=
NULL
;
char
*
prevData
=
pInfo
->
prevData
+
sizeof
(
int32_t
);
// head is key length (int32_t type)
for
(
int32_t
idx
=
0
;
idx
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
idx
++
)
{
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
idx
);
if
(
pDataInfo
->
index
==
pExpr1
->
colInfo
.
colId
)
{
bytes
=
pDataInfo
->
bytes
;
val
=
p
Info
->
p
revData
+
offset
;
val
=
prevData
+
offset
;
break
;
}
offset
+=
pDataInfo
->
bytes
;
offset
+=
pDataInfo
->
bytes
+
strlen
(
MULTI_KEY_DELIM
);
// multi value split by MULTI_KEY_DELIM
}
if
(
val
==
NULL
)
{
continue
;
}
...
...
tests/pytest/query/queryGroupbySort.py
浏览文件 @
5d5d0a24
...
...
@@ -88,6 +88,23 @@ class TDTestCase:
tdSql
.
query
(
"select count(*) from tb group by c1"
)
tdSql
.
checkRows
(
0
)
# TS-1619
tdSql
.
execute
(
"create database test"
)
tdSql
.
execute
(
"use test"
)
tdSql
.
execute
(
"create table stb(ts timestamp, c1 int, c2 nchar(30)) tags(t1 int)"
)
for
i
in
range
(
3
):
tdSql
.
execute
(
"create table t%d using stb tags(%d)"
%
(
i
,
i
))
sql
=
"insert into t%d values "
%
i
for
j
in
range
(
16
):
if
j
%
4
==
0
:
s
=
'00'
else
:
s
=
str
(
j
%
4
*
15
)
sql
+=
"(%d, %d, '2022-06-01 0%d:%s')"
%
(
self
.
ts
+
j
,
i
,
int
(
j
/
4
),
s
)
tdSql
.
execute
(
sql
)
tdSql
.
query
(
"select c2, sum(c1) from stb group by c2"
)
tdSql
.
checkRows
(
16
)
def
stop
(
self
):
tdSql
.
close
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录