Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cae0a9e7
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cae0a9e7
编写于
8月 17, 2021
作者:
Y
yihaoDeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-4335]<feature> support group by multi column
上级
cb9cd75f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
30 deletion
+33
-30
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+5
-2
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+28
-28
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
cae0a9e7
...
@@ -3555,7 +3555,7 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3555,7 +3555,7 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
const
char
*
msg4
=
"join query does not support group by"
;
const
char
*
msg4
=
"join query does not support group by"
;
const
char
*
msg5
=
"not allowed column type for group by"
;
const
char
*
msg5
=
"not allowed column type for group by"
;
const
char
*
msg6
=
"tags not allowed for table query"
;
const
char
*
msg6
=
"tags not allowed for table query"
;
//const char* msg7 = "not support group by expression
";
const
char
*
msg7
=
"not support group by primary key
"
;
//const char* msg8 = "normal column can only locate at the end of group by clause";
//const char* msg8 = "normal column can only locate at the end of group by clause";
// todo : handle two tables situation
// todo : handle two tables situation
...
@@ -3638,9 +3638,12 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3638,9 +3638,12 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
tscColumnListInsert
(
pTableMetaInfo
->
tagColList
,
index
.
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
tscColumnListInsert
(
pTableMetaInfo
->
tagColList
,
index
.
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
}
else
{
}
else
{
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
// check if the column type is valid, here only support the bool/tinyint/smallint/bigint group by
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_
TIMESTAMP
||
pSchema
->
type
==
TSDB_DATA_TYPE_
FLOAT
||
pSchema
->
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_FLOAT
||
pSchema
->
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
}
if
(
index
.
columnIndex
==
PRIMARYKEY_TIMESTAMP_COL_INDEX
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
tscColumnListInsert
(
pQueryInfo
->
colList
,
index
.
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
tscColumnListInsert
(
pQueryInfo
->
colList
,
index
.
columnIndex
,
pTableMeta
->
id
.
uid
,
pSchema
);
...
...
src/query/src/qExecutor.c
浏览文件 @
cae0a9e7
...
@@ -52,7 +52,6 @@
...
@@ -52,7 +52,6 @@
(_dst).ekey = (_src).ekey;\
(_dst).ekey = (_src).ekey;\
} while (0)
} while (0)
#define GROUPBY_MULTI_COLUMN_DELIM "-"
enum
{
enum
{
TS_JOIN_TS_EQUAL
=
0
,
TS_JOIN_TS_EQUAL
=
0
,
...
@@ -1675,17 +1674,18 @@ static bool initGroupbyInfo(const SSDataBlock *pSDataBlock, const SGroupbyExpr *
...
@@ -1675,17 +1674,18 @@ static bool initGroupbyInfo(const SSDataBlock *pSDataBlock, const SGroupbyExpr *
}
}
}
}
}
}
pInfo
->
totalBytes
+=
(
int32_t
)
strlen
(
GROUPBY_MULTI_COLUMN
_DELIM
)
*
pGroupbyExpr
->
numOfGroupCols
;
pInfo
->
totalBytes
+=
(
int32_t
)
strlen
(
MULTI_KEY
_DELIM
)
*
pGroupbyExpr
->
numOfGroupCols
;
return
true
;
return
true
;
}
}
static
void
buildGroupbyKeyBuf
(
const
SSDataBlock
*
pSDataBlock
,
SGroupbyOperatorInfo
*
pInfo
,
int32_t
rowId
,
char
**
buf
,
bool
*
isNullKey
)
{
static
void
buildGroupbyKeyBuf
(
const
SSDataBlock
*
pSDataBlock
,
SGroupbyOperatorInfo
*
pInfo
,
int32_t
rowId
,
char
**
buf
)
{
char
*
p
=
calloc
(
1
,
pInfo
->
totalBytes
);
char
*
p
=
calloc
(
1
,
pInfo
->
totalBytes
);
if
(
p
==
NULL
)
{
*
buf
=
NULL
;
return
;
}
if
(
p
==
NULL
)
{
*
buf
=
NULL
;
return
;
}
*
buf
=
p
;
*
buf
=
p
;
*
isNullKey
=
true
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
...
@@ -1703,24 +1703,27 @@ static void buildGroupbyKeyBuf(const SSDataBlock *pSDataBlock, SGroupbyOperatorI
...
@@ -1703,24 +1703,27 @@ static void buildGroupbyKeyBuf(const SSDataBlock *pSDataBlock, SGroupbyOperatorI
memcpy
(
p
,
val
,
pDataInfo
->
bytes
);
memcpy
(
p
,
val
,
pDataInfo
->
bytes
);
p
+=
pDataInfo
->
bytes
;
p
+=
pDataInfo
->
bytes
;
}
}
memcpy
(
p
,
GROUPBY_MULTI_COLUMN_DELIM
,
strlen
(
GROUPBY_MULTI_COLUMN_DELIM
));
p
+=
strlen
(
GROUPBY_MULTI_COLUMN_DELIM
);
memcpy
(
p
,
MULTI_KEY_DELIM
,
strlen
(
MULTI_KEY_DELIM
)
);
*
isNullKey
=
false
;
p
+=
strlen
(
MULTI_KEY_DELIM
);
}
}
}
}
static
bool
isGroupbyKeyEqual
(
void
*
a
,
void
*
b
,
void
*
ext
)
{
static
bool
isGroupbyKeyEqual
(
void
*
a
,
void
*
b
,
void
*
ext
)
{
SGroupbyOperatorInfo
*
pInfo
=
(
SGroupbyOperatorInfo
*
)
ext
;
SGroupbyOperatorInfo
*
pInfo
=
(
SGroupbyOperatorInfo
*
)
ext
;
if
(
memcmp
(
a
,
b
,
pInfo
->
totalBytes
)
==
0
)
{
return
true
;
}
int32_t
offset
=
0
;
int32_t
offset
=
0
;
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
taosArrayGetSize
(
pInfo
->
pGroupbyDataInfo
);
i
++
)
{
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
SGroupbyDataInfo
*
pDataInfo
=
taosArrayGet
(
pInfo
->
pGroupbyDataInfo
,
i
);
char
*
k1
=
(
char
*
)
a
+
offset
;
char
*
k1
=
(
char
*
)
a
+
offset
;
char
*
k2
=
(
char
*
)
b
+
offset
;
char
*
k2
=
(
char
*
)
b
+
offset
;
if
(
getComparFunc
(
pDataInfo
->
type
,
0
)(
k1
,
k2
)
!=
0
)
{
if
(
getComparFunc
(
pDataInfo
->
type
,
0
)(
k1
,
k2
)
!=
0
)
{
return
false
;
return
false
;
}
}
offset
+=
pDataInfo
->
bytes
;
offset
+=
pDataInfo
->
bytes
;
offset
+=
(
int32_t
)
strlen
(
GROUPBY_MULTI_COLUMN
_DELIM
);
offset
+=
(
int32_t
)
strlen
(
MULTI_KEY
_DELIM
);
}
}
return
true
;
return
true
;
}
}
...
@@ -1747,11 +1750,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
...
@@ -1747,11 +1750,9 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
char
*
key
=
NULL
;
char
*
key
=
NULL
;
int16_t
num
=
0
;
int16_t
num
=
0
;
int32_t
type
=
0
;
int32_t
type
=
0
;
bool
isNullKey
=
false
;
for
(
int32_t
j
=
0
;
j
<
pSDataBlock
->
info
.
rows
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
pSDataBlock
->
info
.
rows
;
++
j
)
{
buildGroupbyKeyBuf
(
pSDataBlock
,
pInfo
,
j
,
&
key
,
&
isNullKey
);
buildGroupbyKeyBuf
(
pSDataBlock
,
pInfo
,
j
,
&
key
);
if
(
isNullKey
)
{
continue
;}
if
(
!
key
)
{
continue
;}
if
(
key
==
NULL
)
{
/* handle malloc failure*/
}
if
(
pInfo
->
prevData
==
NULL
)
{
if
(
pInfo
->
prevData
==
NULL
)
{
// first row of
// first row of
pInfo
->
prevData
=
key
;
pInfo
->
prevData
=
key
;
...
@@ -1781,20 +1782,19 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
...
@@ -1781,20 +1782,19 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SGroupbyOperatorInfo *pIn
}
}
if
(
num
>
0
)
{
if
(
num
>
0
)
{
buildGroupbyKeyBuf
(
pSDataBlock
,
pInfo
,
pSDataBlock
->
info
.
rows
-
num
,
&
key
,
&
isNullKey
);
buildGroupbyKeyBuf
(
pSDataBlock
,
pInfo
,
pSDataBlock
->
info
.
rows
-
num
,
&
key
);
tfree
(
pInfo
->
prevData
);
if
(
key
)
{
pInfo
->
prevData
=
key
;
tfree
(
pInfo
->
prevData
);
pInfo
->
prevData
=
key
;
if
(
pQueryAttr
->
stableQuery
&&
pQueryAttr
->
stabledev
&&
(
pRuntimeEnv
->
prevResult
!=
NULL
))
{
if
(
pQueryAttr
->
stableQuery
&&
pQueryAttr
->
stabledev
&&
(
pRuntimeEnv
->
prevResult
!=
NULL
))
{
setParamForStableStddevByColData
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
pOperator
->
numOfOutput
,
pOperator
->
pExpr
,
pInfo
);
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
);
int32_t
ret
=
setGroupResultOutputBuf
(
pRuntimeEnv
,
&
(
pInfo
->
binfo
),
pOperator
->
numOfOutput
,
pInfo
->
prevData
,
type
,
pInfo
->
totalBytes
,
item
->
groupIndex
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
// null data, too many state code
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
longjmp
(
pRuntimeEnv
->
env
,
TSDB_CODE_QRY_APP_ERROR
);
}
doApplyFunctions
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
&
w
,
pSDataBlock
->
info
.
rows
-
num
,
num
,
tsList
,
pSDataBlock
->
info
.
rows
,
pOperator
->
numOfOutput
);
}
}
doApplyFunctions
(
pRuntimeEnv
,
pInfo
->
binfo
.
pCtx
,
&
w
,
pSDataBlock
->
info
.
rows
-
num
,
num
,
tsList
,
pSDataBlock
->
info
.
rows
,
pOperator
->
numOfOutput
);
}
}
tfree
(
pInfo
->
prevData
);
tfree
(
pInfo
->
prevData
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录