Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
235fbfae
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看板
提交
235fbfae
编写于
11月 03, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
json tag support for group by logic
上级
196f1ee1
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
57 addition
and
4 deletion
+57
-4
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+40
-3
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+1
-1
src/util/inc/tutil.h
src/util/inc/tutil.h
+1
-0
src/util/src/tutil.c
src/util/src/tutil.c
+15
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
235fbfae
...
@@ -3711,6 +3711,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3711,6 +3711,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
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 expression"
;
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"
;
const
char
*
msg9
=
"json tag format error, like json->'key'"
;
const
char
*
msg10
=
"-> operation only apply for json tag"
;
// todo : handle two tables situation
// todo : handle two tables situation
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
STableMetaInfo
*
pTableMetaInfo
=
NULL
;
...
@@ -3750,15 +3752,29 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3750,15 +3752,29 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
tVariant
*
pVar
=
&
pItem
->
pVar
;
tVariant
*
pVar
=
&
pItem
->
pVar
;
SStrToken
token
=
{
pVar
->
nLen
,
pVar
->
nType
,
pVar
->
pz
};
SStrToken
token
=
{
pVar
->
nLen
,
pVar
->
nType
,
pVar
->
pz
};
char
*
jsonName
=
NULL
;
char
*
jsonKey
=
NULL
;
int
ret
=
getArrowKV
(
pVar
->
pz
,
pVar
->
nLen
,
&
jsonName
,
&
jsonKey
);
if
(
jsonName
&&
jsonKey
)
tscDebug
(
"group by json k:%s, v:%s"
,
jsonName
,
jsonKey
);
if
(
ret
==
2
){
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg9
);
}
if
(
ret
==
0
){
token
.
z
=
jsonName
;
token
.
n
=
strlen
(
jsonName
);
}
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
token
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
if
(
getColumnIndexByName
(
&
token
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
tfree
(
jsonName
);
tfree
(
jsonKey
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
}
if
(
tableIndex
==
COLUMN_INDEX_INITIAL_VAL
)
{
if
(
tableIndex
==
COLUMN_INDEX_INITIAL_VAL
)
{
tableIndex
=
index
.
tableIndex
;
tableIndex
=
index
.
tableIndex
;
}
else
if
(
tableIndex
!=
index
.
tableIndex
)
{
}
else
if
(
tableIndex
!=
index
.
tableIndex
)
{
tfree
(
jsonName
);
tfree
(
jsonKey
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg3
);
}
}
...
@@ -3770,12 +3786,18 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3770,12 +3786,18 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
}
else
{
}
else
{
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
}
}
if
(
ret
==
0
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_JSON
){
tfree
(
jsonName
);
tfree
(
jsonKey
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg10
);
}
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
int32_t
numOfCols
=
tscGetNumOfColumns
(
pTableMeta
);
bool
groupTag
=
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
||
index
.
columnIndex
>=
numOfCols
);
bool
groupTag
=
(
index
.
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
||
index
.
columnIndex
>=
numOfCols
);
if
(
groupTag
)
{
if
(
groupTag
)
{
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
if
(
!
UTIL_TABLE_IS_SUPER_TABLE
(
pTableMetaInfo
))
{
tfree
(
jsonName
);
tfree
(
jsonKey
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
}
...
@@ -3785,7 +3807,11 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3785,7 +3807,11 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
}
}
SColIndex
colIndex
=
{
.
colIndex
=
relIndex
,
.
flag
=
TSDB_COL_TAG
,
.
colId
=
pSchema
->
colId
,
};
SColIndex
colIndex
=
{
.
colIndex
=
relIndex
,
.
flag
=
TSDB_COL_TAG
,
.
colId
=
pSchema
->
colId
,
};
strncpy
(
colIndex
.
name
,
pSchema
->
name
,
tListLen
(
colIndex
.
name
));
if
(
ret
==
0
){
tstrncpy
(
colIndex
.
name
,
jsonKey
,
tListLen
(
colIndex
.
name
));
}
else
{
tstrncpy
(
colIndex
.
name
,
pSchema
->
name
,
tListLen
(
colIndex
.
name
));
}
taosArrayPush
(
pGroupExpr
->
columnInfo
,
&
colIndex
);
taosArrayPush
(
pGroupExpr
->
columnInfo
,
&
colIndex
);
index
.
columnIndex
=
relIndex
;
index
.
columnIndex
=
relIndex
;
...
@@ -3793,6 +3819,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3793,6 +3819,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
}
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_FLOAT
||
pSchema
->
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_FLOAT
||
pSchema
->
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
tfree
(
jsonName
);
tfree
(
jsonKey
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
}
...
@@ -3805,6 +3833,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
...
@@ -3805,6 +3833,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
pQueryInfo
->
groupbyExpr
.
orderType
=
TSDB_ORDER_ASC
;
pQueryInfo
->
groupbyExpr
.
orderType
=
TSDB_ORDER_ASC
;
numOfGroupCols
++
;
numOfGroupCols
++
;
}
}
tfree
(
jsonName
);
tfree
(
jsonKey
);
}
}
// 1. only one normal column allowed in the group by clause
// 1. only one normal column allowed in the group by clause
...
@@ -7414,6 +7444,13 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
...
@@ -7414,6 +7444,13 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
SColumnIndex
index
=
{.
tableIndex
=
pQueryInfo
->
groupbyExpr
.
tableIndex
,
.
columnIndex
=
colIndex
};
SColumnIndex
index
=
{.
tableIndex
=
pQueryInfo
->
groupbyExpr
.
tableIndex
,
.
columnIndex
=
colIndex
};
SExprInfo
*
pExpr
=
tscExprInsert
(
pQueryInfo
,
pos
,
f
,
&
index
,
s
->
type
,
s
->
bytes
,
getNewResColId
(
pCmd
),
s
->
bytes
,
true
);
SExprInfo
*
pExpr
=
tscExprInsert
(
pQueryInfo
,
pos
,
f
,
&
index
,
s
->
type
,
s
->
bytes
,
getNewResColId
(
pCmd
),
s
->
bytes
,
true
);
// if json->key is more than TSDB_COL_NAME_LEN + TSDB_DB_NAME_LEN, truncature it, maybe case error, can encode name by md5.
if
(
s
->
type
==
TSDB_DATA_TYPE_JSON
){
tstrncpy
(
s
->
name
,
pColIndex
->
name
,
TSDB_COL_NAME_LEN
);
tVariantCreateFromBinary
(
&
(
pExpr
->
base
.
param
[
pExpr
->
base
.
numOfParams
]),
pColIndex
->
name
,
strlen
(
pColIndex
->
name
),
TSDB_DATA_TYPE_BINARY
);
pExpr
->
base
.
numOfParams
++
;
}
memset
(
pExpr
->
base
.
aliasName
,
0
,
sizeof
(
pExpr
->
base
.
aliasName
));
memset
(
pExpr
->
base
.
aliasName
,
0
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
aliasName
,
s
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
aliasName
,
s
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
...
...
src/query/src/qExecutor.c
浏览文件 @
235fbfae
...
@@ -3449,7 +3449,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
...
@@ -3449,7 +3449,7 @@ void setTagValue(SOperatorInfo* pOperatorInfo, void *pTable, SQLFunctionCtx* pCt
// todo use tag column index to optimize performance
// todo use tag column index to optimize performance
GET_JSON_KEY
(
pLocalExprInfo
)
GET_JSON_KEY
(
pLocalExprInfo
)
doSetTagValueInParam
(
pTable
,
param
,
paramLen
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
base
.
resType
,
doSetTagValueInParam
(
pTable
,
param
,
paramLen
,
pLocalExprInfo
->
base
.
colInfo
.
colId
,
&
pCtx
[
idx
].
tag
,
pLocalExprInfo
->
base
.
resType
,
pLocalExprInfo
->
base
.
resBytes
);
pLocalExprInfo
->
base
.
resBytes
);
if
(
IS_NUMERIC_TYPE
(
pLocalExprInfo
->
base
.
resType
)
if
(
IS_NUMERIC_TYPE
(
pLocalExprInfo
->
base
.
resType
)
...
...
src/util/inc/tutil.h
浏览文件 @
235fbfae
...
@@ -38,6 +38,7 @@ char * strntolower_s(char *dst, const char *src, int32_t n);
...
@@ -38,6 +38,7 @@ char * strntolower_s(char *dst, const char *src, int32_t n);
int64_t
strnatoi
(
char
*
num
,
int32_t
len
);
int64_t
strnatoi
(
char
*
num
,
int32_t
len
);
char
*
strbetween
(
char
*
string
,
char
*
begin
,
char
*
end
);
char
*
strbetween
(
char
*
string
,
char
*
begin
,
char
*
end
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
char
*
paGetToken
(
char
*
src
,
char
**
token
,
int32_t
*
tokenLen
);
int
getArrowKV
(
char
*
src
,
int32_t
len
,
char
**
name
,
char
**
key
);
int32_t
taosByteArrayToHexStr
(
char
bytes
[],
int32_t
len
,
char
hexstr
[]);
int32_t
taosByteArrayToHexStr
(
char
bytes
[],
int32_t
len
,
char
hexstr
[]);
int32_t
taosHexStrToByteArray
(
char
hexstr
[],
char
bytes
[]);
int32_t
taosHexStrToByteArray
(
char
hexstr
[],
char
bytes
[]);
...
...
src/util/src/tutil.c
浏览文件 @
235fbfae
...
@@ -185,6 +185,21 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
...
@@ -185,6 +185,21 @@ char *strnchr(char *haystack, char needle, int32_t len, bool skipquote) {
return
NULL
;
return
NULL
;
}
}
// src = json->'id' => name=json key=id
int
getArrowKV
(
char
*
src
,
int32_t
len
,
char
**
name
,
char
**
key
){
char
*
loc
=
strstr
(
src
,
"->"
);
if
(
loc
==
NULL
){
return
1
;}
if
(
loc
-
src
+
4
>=
len
)
{
return
2
;}
if
(
*
(
loc
+
2
)
!=
*
(
src
+
len
-
1
))
{
return
2
;}
if
(
*
(
loc
+
2
)
!=
'\''
&&
*
(
loc
+
2
)
!=
'"'
)
{
return
2
;}
*
name
=
calloc
(
1
,
loc
-
src
+
1
);
*
key
=
calloc
(
1
,
len
-
(
loc
-
src
+
4
)
+
1
);
tstrncpy
(
*
name
,
src
,
loc
-
src
+
1
);
tstrncpy
(
*
key
,
loc
+
2
,
len
-
(
loc
-
src
+
4
)
+
1
);
return
0
;
}
char
*
tstrstr
(
char
*
src
,
char
*
dst
,
bool
ignoreInEsc
)
{
char
*
tstrstr
(
char
*
src
,
char
*
dst
,
bool
ignoreInEsc
)
{
if
(
!
ignoreInEsc
)
{
if
(
!
ignoreInEsc
)
{
return
strstr
(
src
,
dst
);
return
strstr
(
src
,
dst
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录