Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6567cff9
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看板
提交
6567cff9
编写于
11月 24, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix group by json tag format [change json type with qid return logic]
上级
8f0788e9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
72 addition
and
19 deletion
+72
-19
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+1
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+37
-15
src/client/src/tscServer.c
src/client/src/tscServer.c
+1
-1
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+14
-0
src/client/tests/CMakeLists.txt
src/client/tests/CMakeLists.txt
+1
-1
src/client/tests/jsonTagTest.cpp
src/client/tests/jsonTagTest.cpp
+16
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+1
-1
tests/pytest/stable/json_tag.py
tests/pytest/stable/json_tag.py
+1
-1
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
6567cff9
...
...
@@ -396,6 +396,7 @@ void getJsonTagValueAll(void* data, void* dst, int16_t bytes);
int8_t
jsonType2DbType
(
double
data
,
int
jsonType
);
void
*
getJsonTagValue
(
STable
*
pTable
,
char
*
key
,
int32_t
keyLen
,
int16_t
*
colId
);
void
getJsonKey
(
SStrToken
*
t0
);
char
*
cloneCurrentDBName
(
SSqlObj
*
pSql
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
6567cff9
...
...
@@ -1910,14 +1910,26 @@ static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumn
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
pIndex
->
columnIndex
);
if
(
pItem
->
aliasName
){
tstrncpy
(
pExpr
->
base
.
aliasName
,
pItem
->
aliasName
,
sizeof
(
pExpr
->
base
.
aliasName
));
}
else
{
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
pItem
->
pNode
->
tokenId
==
TK_ARROW
)
{
tstrncpy
(
pExpr
->
base
.
aliasName
,
pItem
->
pNode
->
exprToken
.
z
,
(
pItem
->
pNode
->
exprToken
.
n
+
1
)
<
sizeof
(
pExpr
->
base
.
aliasName
)
?
(
pItem
->
pNode
->
exprToken
.
n
+
1
)
:
sizeof
(
pExpr
->
base
.
aliasName
));
}
else
{
char
oriAliasName
[
TSDB_COL_NAME_LEN
+
TSDB_TABLE_NAME_LEN
+
TSDB_MAX_JSON_KEY_LEN
+
4
+
1
]
=
{
0
};
void
*
oriAliasNamePtr
=
&
oriAliasName
;
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
pItem
->
pNode
->
tokenId
==
TK_ARROW
)
{
char
keyMd5
[
TSDB_MAX_JSON_KEY_MD5_LEN
+
1
]
=
{
0
};
if
(
pItem
->
aliasName
){
jsonKeyMd5
(
pItem
->
aliasName
,
strlen
(
pItem
->
aliasName
),
keyMd5
);
*
(
char
**
)
oriAliasNamePtr
=
pItem
->
aliasName
;
}
else
{
jsonKeyMd5
(
pItem
->
pNode
->
exprToken
.
z
,
pItem
->
pNode
->
exprToken
.
n
,
keyMd5
);
tstrncpy
(
*
(
char
**
)
oriAliasNamePtr
,
pItem
->
pNode
->
exprToken
.
z
,
pItem
->
pNode
->
exprToken
.
n
+
1
<
sizeof
(
oriAliasName
)
?
pItem
->
pNode
->
exprToken
.
n
+
1
:
sizeof
(
oriAliasName
));
}
tstrncpy
(
pExpr
->
base
.
aliasName
,
keyMd5
,
sizeof
(
pExpr
->
base
.
aliasName
));
}
else
{
if
(
pItem
->
aliasName
){
tstrncpy
(
pExpr
->
base
.
aliasName
,
pItem
->
aliasName
,
sizeof
(
pExpr
->
base
.
aliasName
));
*
(
char
**
)
oriAliasNamePtr
=
pItem
->
aliasName
;
}
else
{
tstrncpy
(
pExpr
->
base
.
aliasName
,
pSchema
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
*
(
char
**
)
oriAliasNamePtr
=
pSchema
->
name
;
}
}
...
...
@@ -1930,7 +1942,7 @@ static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumn
ids
.
num
=
0
;
}
insertResultField
(
pQueryInfo
,
startPos
,
&
ids
,
pExpr
->
base
.
resBytes
,
(
int8_t
)
pExpr
->
base
.
resType
,
pExpr
->
base
.
aliasName
,
pExpr
);
insertResultField
(
pQueryInfo
,
startPos
,
&
ids
,
pExpr
->
base
.
resBytes
,
(
int8_t
)
pExpr
->
base
.
resType
,
*
(
char
**
)
oriAliasNamePtr
,
pExpr
);
}
static
void
addPrimaryTsColIntoResult
(
SQueryInfo
*
pQueryInfo
,
SSqlCmd
*
pCmd
)
{
...
...
@@ -2183,6 +2195,11 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
TAOS_FIELD
f
=
tscCreateField
(
type
,
fieldName
,
bytes
);
SInternalField
*
pInfo
=
tscFieldInfoInsert
(
&
pQueryInfo
->
fieldsInfo
,
outputIndex
,
&
f
);
if
(
type
==
TSDB_DATA_TYPE_JSON
){
char
keyMd5
[
TSDB_MAX_JSON_KEY_MD5_LEN
+
1
]
=
{
0
};
jsonKeyMd5
(
fieldName
,
strlen
(
fieldName
),
keyMd5
);
strncpy
(
pInfo
->
fieldJson
.
name
,
keyMd5
,
sizeof
(
pInfo
->
fieldJson
.
name
));
}
pInfo
->
pExpr
=
pSqlExpr
;
return
TSDB_CODE_SUCCESS
;
...
...
@@ -3822,7 +3839,8 @@ int32_t validateGroupbyNode(SQueryInfo* pQueryInfo, SArray* pList, SSqlCmd* pCmd
SColIndex
colIndex
=
{
.
colIndex
=
relIndex
,
.
flag
=
TSDB_COL_TAG
,
.
colId
=
pSchema
->
colId
,
};
if
(
pItem
->
isJsonExp
)
{
tstrncpy
(
colIndex
.
name
,
pItem
->
jsonExp
->
pRight
->
value
.
pz
,
tListLen
(
colIndex
.
name
));
tstrncpy
(
colIndex
.
name
,
pItem
->
jsonExp
->
exprToken
.
z
,
pItem
->
jsonExp
->
exprToken
.
n
+
1
>
tListLen
(
colIndex
.
name
)
?
tListLen
(
colIndex
.
name
)
:
pItem
->
jsonExp
->
exprToken
.
n
+
1
);
}
else
{
tstrncpy
(
colIndex
.
name
,
pSchema
->
name
,
tListLen
(
colIndex
.
name
));
}
...
...
@@ -7281,7 +7299,7 @@ static bool tagColumnInGroupby(SGroupbyExpr* pGroupbyExpr, int16_t columnId, int
for
(
int32_t
j
=
0
;
j
<
pGroupbyExpr
->
numOfGroupCols
;
++
j
)
{
SColIndex
*
pColIndex
=
taosArrayGet
(
pGroupbyExpr
->
columnInfo
,
j
);
if
(
type
==
TSDB_DATA_TYPE_JSON
){
if
(
type
==
TSDB_DATA_TYPE_JSON
&&
name
!=
NULL
){
if
(
columnId
==
pColIndex
->
colId
&&
strncmp
(
pColIndex
->
name
,
name
,
tListLen
(
pColIndex
->
name
))
==
0
&&
TSDB_COL_IS_TAG
(
pColIndex
->
flag
))
{
return
true
;
}
...
...
@@ -7502,20 +7520,24 @@ static int32_t doAddGroupbyColumnsOnDemand(SSqlCmd* pCmd, SQueryInfo* pQueryInfo
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
){
tVariantCreateFromBinary
(
&
(
pExpr
->
base
.
param
[
pExpr
->
base
.
numOfParams
]),
pColIndex
->
name
,
strlen
(
pColIndex
->
name
),
TSDB_DATA_TYPE_BINARY
);
SStrToken
t0
=
{.
z
=
pColIndex
->
name
};
getJsonKey
(
&
t0
);
tVariantCreateFromBinary
(
&
(
pExpr
->
base
.
param
[
pExpr
->
base
.
numOfParams
]),
t0
.
z
,
t0
.
n
,
TSDB_DATA_TYPE_BINARY
);
pExpr
->
base
.
numOfParams
++
;
}
char
keyMd5
[
TSDB_MAX_JSON_KEY_MD5_LEN
+
1
]
=
{
0
};
jsonKeyMd5
(
pColIndex
->
name
,
strlen
(
pColIndex
->
name
),
keyMd5
);
memset
(
pExpr
->
base
.
aliasName
,
0
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
aliasName
,
pColIndex
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
token
,
pColIndex
->
name
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
aliasName
,
keyMd5
,
sizeof
(
pExpr
->
base
.
aliasName
));
tstrncpy
(
pExpr
->
base
.
token
,
keyMd5
,
sizeof
(
pExpr
->
base
.
token
));
pExpr
->
base
.
colInfo
.
flag
=
TSDB_COL_TAG
;
// NOTE: tag column does not add to source column list
SColumnList
ids
=
createColumnList
(
1
,
0
,
pColIndex
->
colIndex
);
insertResultField
(
pQueryInfo
,
pos
,
&
ids
,
s
->
bytes
,
(
int8_t
)
s
->
type
,
s
->
name
,
pExpr
);
insertResultField
(
pQueryInfo
,
pos
,
&
ids
,
s
->
bytes
,
(
int8_t
)
s
->
type
,
pColIndex
->
name
,
pExpr
);
}
else
{
// if this query is "group by" normal column, time window query is not allowed
if
(
isTimeWindowQuery
(
pQueryInfo
))
{
...
...
src/client/src/tscServer.c
浏览文件 @
6567cff9
...
...
@@ -2657,7 +2657,7 @@ static void updateFieldForJson(SSqlObj *pSql, SQueryTableRsp *pQueryAttr){
if
(
pField
->
field
.
type
==
TSDB_DATA_TYPE_JSON
)
{
pField
->
fieldJson
.
type
=
TSDB_DATA_TYPE_JSON
;
for
(
int
k
=
0
;
k
<
pQueryAttr
->
tJsonSchLen
;
++
k
)
{
if
(
strncmp
(
pField
->
field
.
name
,
pQueryAttr
->
tagJsonSchema
[
k
].
name
,
TSDB_MAX_JSON_KEY_LEN
)
==
0
)
{
if
(
strncmp
(
pField
->
field
Json
.
name
,
pQueryAttr
->
tagJsonSchema
[
k
].
name
,
TSDB_MAX_JSON_KEY_LEN
)
==
0
)
{
pField
->
fieldJson
.
type
=
pQueryAttr
->
tagJsonSchema
[
k
].
type
;
pField
->
fieldJson
.
bytes
=
TYPE_BYTES
[
pField
->
field
.
type
];
tscDebug
(
"0x%"
PRIx64
" change json type %s:%s to %d"
,
pSql
->
self
,
pField
->
field
.
name
,
pQueryAttr
->
tagJsonSchema
[
k
].
name
,
...
...
src/client/src/tscUtil.c
浏览文件 @
6567cff9
...
...
@@ -5681,3 +5681,17 @@ void* getJsonTagValue(STable* pTable, char* key, int32_t keyLen, int16_t* retCol
}
return
NULL
;
}
void
getJsonKey
(
SStrToken
*
t0
){
while
(
true
){
t0
->
n
=
tGetToken
(
t0
->
z
,
&
t0
->
type
);
if
(
t0
->
type
==
TK_STRING
){
t0
->
z
++
;
t0
->
n
-=
2
;
break
;
}
else
if
(
t0
->
type
==
TK_ILLEGAL
){
assert
(
0
);
}
t0
->
z
+=
t0
->
n
;
}
}
src/client/tests/CMakeLists.txt
浏览文件 @
6567cff9
...
...
@@ -16,6 +16,6 @@ IF (HEADER_GTEST_INCLUDE_DIR AND (LIB_GTEST_STATIC_DIR OR LIB_GTEST_SHARED_DIR))
AUX_SOURCE_DIRECTORY
(
${
CMAKE_CURRENT_SOURCE_DIR
}
SOURCE_LIST
)
ADD_EXECUTABLE
(
cliTest
${
SOURCE_LIST
}
)
ADD_EXECUTABLE
(
cliTest
${
SOURCE_LIST
}
jsonTagTest.cpp
)
TARGET_LINK_LIBRARIES
(
cliTest taos cJson tutil common gtest pthread
)
ENDIF
()
src/client/tests/jsonTagTest.cpp
0 → 100644
浏览文件 @
6567cff9
//
// Created by mingming wanng on 2021/11/24.
//
#include <gtest/gtest.h>
#include <inttypes.h>
#include "tscUtil.h"
/* test set config function */
TEST
(
testCase
,
json_test1
)
{
SStrToken
t0
=
{.
z
=
"jtag->'location'"
};
getJsonKey
(
&
t0
);
ASSERT_EQ
(
t0
.
n
,
8
);
t0
.
z
[
8
]
=
0
;
ASSERT_STREQ
(
t0
.
z
,
"location"
);
}
\ No newline at end of file
src/inc/taosmsg.h
浏览文件 @
6567cff9
...
...
@@ -405,7 +405,7 @@ typedef struct SColIndex {
int16_t
colId
;
// column id
int16_t
colIndex
;
// column index in colList if it is a normal column or index in tagColList if a tag
uint16_t
flag
;
// denote if it is a tag or a normal column
char
name
[
TSDB_COL_NAME_LEN
+
TSDB_TABLE_NAME_LEN
+
1
];
char
name
[
TSDB_COL_NAME_LEN
+
TSDB_TABLE_NAME_LEN
+
TSDB_MAX_JSON_KEY_LEN
+
4
+
1
];
}
SColIndex
;
typedef
struct
SColumnFilterInfo
{
...
...
tests/pytest/stable/json_tag.py
浏览文件 @
6567cff9
...
...
@@ -194,7 +194,7 @@ class TDTestCase:
tdSql
.
checkData
(
0
,
0
,
"{
\"
k1
\"
:
\"\"
,
\"
k2
\"
:true,
\"
k3
\"
:false,
\"
k4
\"
:55}"
)
tdSql
.
query
(
"select jtag->'k2' from db_json_tag_test.jsons1_10"
)
tdSql
.
checkData
(
0
,
0
,
"true"
)
tdSql
.
checkData
(
0
,
0
,
True
)
tdSql
.
query
(
"select jtag from db_json_tag_test.jsons1 where jtag->'k1'=''"
)
tdSql
.
checkRows
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录