Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1a1f8ee5
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
1a1f8ee5
编写于
9月 13, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-6129<feature> add json tag
上级
b8693f13
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
114 addition
and
5 deletion
+114
-5
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+66
-0
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+35
-0
src/common/src/ttypes.c
src/common/src/ttypes.c
+5
-3
src/inc/taos.h
src/inc/taos.h
+1
-0
src/inc/taosdef.h
src/inc/taosdef.h
+1
-1
src/inc/ttype.h
src/inc/ttype.h
+1
-1
src/util/src/tutil.c
src/util/src/tutil.c
+5
-0
未找到文件。
src/client/src/tscParseInsert.c
浏览文件 @
1a1f8ee5
...
...
@@ -32,6 +32,7 @@
#include "ttoken.h"
#include "tdataformat.h"
#include "cJSON.h"
enum
{
TSDB_USE_SERVER_TS
=
0
,
...
...
@@ -387,6 +388,10 @@ int32_t tsParseOneColumn(SSchema *pSchema, SStrToken *pToken, char *payload, cha
}
break
;
case
TSDB_DATA_TYPE_JSON
:
*
((
int8_t
*
)
payload
)
=
-
1
;
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
pToken
->
type
==
TK_NULL
)
{
if
(
primaryKey
)
{
...
...
@@ -1067,6 +1072,67 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC
tdAddColToKVRow
(
&
kvRowBuilder
,
pSchema
->
colId
,
pSchema
->
type
,
tagVal
);
}
// encode json tag string
if
(
spd
.
numOfBound
==
1
&&
pTagSchema
[
spd
.
boundedColumns
[
0
]].
type
==
TSDB_DATA_TYPE_JSON
){
const
char
*
msg1
=
"json parse error"
;
char
tmp
=
sToken
.
z
[
sToken
.
n
];
sToken
.
z
[
sToken
.
n
]
=
0
;
cJSON
*
root
=
cJSON_Parse
(
sToken
.
z
);
if
(
root
==
NULL
){
tscError
(
"json parse error"
);
return
false
;
}
int
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
)
||
size
==
0
){
tscError
(
"json error invalide value"
);
}
int
jsonIndex
=
0
;
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
tscError
(
"json inner error:%d"
,
i
);
continue
;
}
char
tagVal
[
TSDB_MAX_TAGS_LEN
];
int32_t
output
=
0
;
if
(
!
taosMbsToUcs4
(
item
->
string
,
strlen
(
item
->
string
),
varDataVal
(
tagVal
),
pSchema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
tscError
(
"json string error:%s|%s"
,
strerror
(
errno
),
item
->
string
);
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
tscDestroyBoundColumnInfo
(
&
spd
);
return
tscSQLSyntaxErrMsg
(
pInsertParam
->
msg
,
"serizelize json error"
,
NULL
);
}
varDataSetLen
(
tagVal
,
output
);
tdAddColToKVRow
(
&
kvRowBuilder
,
jsonIndex
++
,
TSDB_DATA_TYPE_NCHAR
,
tagVal
);
if
(
item
->
type
==
cJSON_String
){
output
=
0
;
if
(
!
taosMbsToUcs4
(
item
->
valuestring
,
strlen
(
item
->
valuestring
),
varDataVal
(
tagVal
),
pSchema
->
bytes
-
VARSTR_HEADER_SIZE
,
&
output
))
{
tscError
(
"json string error:%s|%s"
,
strerror
(
errno
),
item
->
string
);
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
tscDestroyBoundColumnInfo
(
&
spd
);
return
tscSQLSyntaxErrMsg
(
pInsertParam
->
msg
,
"serizelize json error"
,
NULL
);
}
varDataSetLen
(
tagVal
,
output
);
tdAddColToKVRow
(
&
kvRowBuilder
,
jsonIndex
++
,
TSDB_DATA_TYPE_NCHAR
,
tagVal
);
}
else
if
(
item
->
type
==
cJSON_Number
){
*
((
double
*
)
tagVal
)
=
item
->
valuedouble
;
tdAddColToKVRow
(
&
kvRowBuilder
,
jsonIndex
++
,
TSDB_DATA_TYPE_BIGINT
,
tagVal
);
}
else
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
tscDestroyBoundColumnInfo
(
&
spd
);
return
tscSQLSyntaxErrMsg
(
pInsertParam
->
msg
,
"invalidate json value"
,
NULL
);
}
}
cJSON_Delete
(
root
);
sToken
.
z
[
sToken
.
n
]
=
tmp
;
}
tscDestroyBoundColumnInfo
(
&
spd
);
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
1a1f8ee5
...
...
@@ -41,6 +41,7 @@
#include "qScript.h"
#include "ttype.h"
#include "qFilter.h"
#include "cJSON.h"
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
...
...
@@ -1476,6 +1477,34 @@ static bool validateTableColumnInfo(SArray* pFieldList, SSqlCmd* pCmd) {
return
true
;
}
static
bool
validataTagJson
(
char
*
json
){
const
char
*
msg1
=
"json parse error"
;
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
tscError
(
"json parse error : %s"
,
json
);
return
false
;
}
int
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
)
||
size
==
0
)
}
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
item
->
string
,
}
}
cJSON_Delete
(
root
);
}
if
(
numOfTags
==
1
)
{
TAOS_FIELD
*
p
=
taosArrayGet
(
pTagsList
,
0
);
if
(
p
->
type
==
TSDB_DATA_TYPE_JSON
&&
validataTagJson
(
p
->
))
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
return
false
;
}
}
static
bool
validateTagParams
(
SArray
*
pTagsList
,
SArray
*
pFieldList
,
SSqlCmd
*
pCmd
)
{
assert
(
pTagsList
!=
NULL
);
...
...
@@ -1487,6 +1516,7 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
const
char
*
msg5
=
"invalid data type in tags"
;
const
char
*
msg6
=
"invalid tag name"
;
const
char
*
msg7
=
"invalid binary/nchar tag length"
;
const
char
*
msg8
=
"only support one tag if include json type"
;
// number of fields at least 1
size_t
numOfTags
=
taosArrayGetSize
(
pTagsList
);
...
...
@@ -1502,6 +1532,11 @@ static bool validateTagParams(SArray* pTagsList, SArray* pFieldList, SSqlCmd* pC
return
false
;
}
if
(
p
->
type
==
TSDB_DATA_TYPE_JSON
&&
numOfTags
!=
1
)
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg8
);
return
false
;
}
if
((
p
->
type
==
TSDB_DATA_TYPE_BINARY
&&
p
->
bytes
<=
0
)
||
(
p
->
type
==
TSDB_DATA_TYPE_NCHAR
&&
p
->
bytes
<=
0
))
{
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
...
...
src/common/src/ttypes.c
浏览文件 @
1a1f8ee5
...
...
@@ -18,7 +18,7 @@
#include "ttokendef.h"
#include "tscompression.h"
const
int32_t
TYPE_BYTES
[
1
5
]
=
{
const
int32_t
TYPE_BYTES
[
1
6
]
=
{
-
1
,
// TSDB_DATA_TYPE_NULL
sizeof
(
int8_t
),
// TSDB_DATA_TYPE_BOOL
sizeof
(
int8_t
),
// TSDB_DATA_TYPE_TINYINT
...
...
@@ -34,6 +34,7 @@ const int32_t TYPE_BYTES[15] = {
sizeof
(
uint16_t
),
// TSDB_DATA_TYPE_USMALLINT
sizeof
(
uint32_t
),
// TSDB_DATA_TYPE_UINT
sizeof
(
uint64_t
),
// TSDB_DATA_TYPE_UBIGINT
sizeof
(
VarDataOffsetT
),
// TSDB_DATA_TYPE_JSON
};
#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \
...
...
@@ -367,7 +368,7 @@ static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, i
*
maxIndex
=
0
;
}
tDataTypeDescriptor
tDataTypes
[
1
5
]
=
{
tDataTypeDescriptor
tDataTypes
[
1
6
]
=
{
{
TSDB_DATA_TYPE_NULL
,
6
,
1
,
"NOTYPE"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
TSDB_DATA_TYPE_BOOL
,
4
,
CHAR_BYTES
,
"BOOL"
,
false
,
true
,
tsCompressBool
,
tsDecompressBool
,
getStatics_bool
},
{
TSDB_DATA_TYPE_TINYINT
,
7
,
CHAR_BYTES
,
"TINYINT"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_i8
},
...
...
@@ -383,6 +384,7 @@ tDataTypeDescriptor tDataTypes[15] = {
{
TSDB_DATA_TYPE_USMALLINT
,
17
,
SHORT_BYTES
,
"SMALLINT UNSIGNED"
,
0
,
UINT16_MAX
,
tsCompressSmallint
,
tsDecompressSmallint
,
getStatics_u16
},
{
TSDB_DATA_TYPE_UINT
,
12
,
INT_BYTES
,
"INT UNSIGNED"
,
0
,
UINT32_MAX
,
tsCompressInt
,
tsDecompressInt
,
getStatics_u32
},
{
TSDB_DATA_TYPE_UBIGINT
,
15
,
LONG_BYTES
,
"BIGINT UNSIGNED"
,
0
,
UINT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
,
getStatics_u64
},
{
TSDB_DATA_TYPE_JSON
,
4
,
CHAR_BYTES
,
"JSON"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_i8
},
};
char
tTokenTypeSwitcher
[
13
]
=
{
...
...
@@ -428,7 +430,7 @@ FORCE_INLINE void* getDataMax(int32_t type) {
bool
isValidDataType
(
int32_t
type
)
{
return
type
>=
TSDB_DATA_TYPE_NULL
&&
type
<=
TSDB_DATA_TYPE_
UBIGINT
;
return
type
>=
TSDB_DATA_TYPE_NULL
&&
type
<=
TSDB_DATA_TYPE_
JSON
;
}
void
setVardataNull
(
void
*
val
,
int32_t
type
)
{
...
...
src/inc/taos.h
浏览文件 @
1a1f8ee5
...
...
@@ -46,6 +46,7 @@ typedef void **TAOS_ROW;
#define TSDB_DATA_TYPE_USMALLINT 12 // 2 bytes
#define TSDB_DATA_TYPE_UINT 13 // 4 bytes
#define TSDB_DATA_TYPE_UBIGINT 14 // 8 bytes
#define TSDB_DATA_TYPE_JSON 15
typedef
enum
{
TSDB_OPTION_LOCALE
,
...
...
src/inc/taosdef.h
浏览文件 @
1a1f8ee5
...
...
@@ -39,7 +39,7 @@ extern "C" {
#define TSKEY_INITIAL_VAL INT64_MIN
// Bytes for each type.
extern
const
int32_t
TYPE_BYTES
[
1
5
];
extern
const
int32_t
TYPE_BYTES
[
1
6
];
// TODO: replace and remove code below
#define CHAR_BYTES sizeof(char)
...
...
src/inc/ttype.h
浏览文件 @
1a1f8ee5
...
...
@@ -192,7 +192,7 @@ typedef struct tDataTypeDescriptor {
int16_t
*
minindex
,
int16_t
*
maxindex
,
int16_t
*
numofnull
);
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypes
[
1
5
];
extern
tDataTypeDescriptor
tDataTypes
[
1
6
];
bool
isValidDataType
(
int32_t
type
);
...
...
src/util/src/tutil.c
浏览文件 @
1a1f8ee5
...
...
@@ -21,6 +21,11 @@
#include "tulog.h"
#include "taoserror.h"
bool
isInteger
(
double
x
){
int
truncated
=
(
int
)
x
;
return
(
x
==
truncated
);
}
int32_t
strdequote
(
char
*
z
)
{
if
(
z
==
NULL
)
{
return
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录