Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
816cea07
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
816cea07
编写于
5月 31, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat:add new logic for new tag format
上级
5b6f9bdb
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
568 addition
and
523 deletion
+568
-523
include/common/tdataformat.h
include/common/tdataformat.h
+3
-41
include/common/tmsg.h
include/common/tmsg.h
+1
-1
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+10
-41
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+9
-8
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+34
-81
source/dnode/vnode/inc/vnode.h
source/dnode/vnode/inc/vnode.h
+1
-1
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+12
-4
source/dnode/vnode/src/meta/metaTable.c
source/dnode/vnode/src/meta/metaTable.c
+13
-8
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+24
-33
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+1
-3
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+323
-87
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+106
-133
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+20
-54
source/libs/scalar/src/sclvector.c
source/libs/scalar/src/sclvector.c
+11
-28
未找到文件。
include/common/tdataformat.h
浏览文件 @
816cea07
...
...
@@ -59,14 +59,11 @@ void tTSRowBuilderReset(STSRowBuilder *pBuilder);
int32_t
tTSRowBuilderPut
(
STSRowBuilder
*
pBuilder
,
int32_t
cid
,
uint8_t
*
pData
,
uint32_t
nData
);
int32_t
tTSRowBuilderGetRow
(
STSRowBuilder
*
pBuilder
,
const
STSRow2
**
ppRow
);
// STagVal
static
FORCE_INLINE
void
tTagValPush
(
SArray
*
pTagArray
,
void
*
key
,
int8_t
type
,
uint8_t
*
pData
,
uint32_t
nData
,
bool
isJson
);
// STag
int32_t
tTagNew
(
SArray
*
pArray
,
int32_t
version
,
int8_t
isJson
,
STag
**
ppTag
);
void
tTagFree
(
STag
*
pTag
);
bool
tTagGet
(
const
STag
*
pTag
,
STagVal
*
pTagVal
);
char
*
tTagValToData
(
const
STagVal
*
pTagVal
,
bool
isJson
);
int32_t
tEncodeTag
(
SEncoder
*
pEncoder
,
const
STag
*
pTag
);
int32_t
tDecodeTag
(
SDecoder
*
pDecoder
,
STag
**
ppTag
);
int32_t
tTagToValArray
(
const
STag
*
pTag
,
SArray
**
ppArray
);
...
...
@@ -130,16 +127,7 @@ struct STagVal {
};
int8_t
type
;
union
{
int8_t
i8
;
uint8_t
u8
;
int16_t
i16
;
uint16_t
u16
;
int32_t
i32
;
uint32_t
u32
;
int64_t
i64
;
uint64_t
u64
;
float
f
;
double
d
;
struct
{
uint32_t
nData
;
uint8_t
*
pData
;
...
...
@@ -147,24 +135,9 @@ struct STagVal {
};
};
static
FORCE_INLINE
void
tTagValPush
(
SArray
*
pTagArray
,
void
*
key
,
int8_t
type
,
uint8_t
*
pData
,
uint32_t
nData
,
bool
isJson
)
{
STagVal
tagVal
=
{
0
};
if
(
isJson
)
{
tagVal
.
pKey
=
(
char
*
)
key
;
}
else
{
tagVal
.
cid
=
*
(
int16_t
*
)
key
;
}
tagVal
.
type
=
type
;
tagVal
.
pData
=
pData
;
tagVal
.
nData
=
nData
;
taosArrayPush
(
pTagArray
,
&
tagVal
);
}
#pragma pack(push, 1)
#define TD_TAG_JSON ((int8_t)0x
1)
#define TD_TAG_LARGE ((int8_t)0x
2
)
#define TD_TAG_JSON ((int8_t)0x
80) // distinguish JSON string and JSON value with the highest bit
#define TD_TAG_LARGE ((int8_t)0x
40
)
struct
STag
{
int8_t
flags
;
int16_t
len
;
...
...
@@ -424,14 +397,3 @@ int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToM
#endif
/*_TD_COMMON_DATA_FORMAT_H_*/
// SKVRowBuilder;
// int32_t tdInitKVRowBuilder(SKVRowBuilder *pBuilder);
// void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder);
// void tdResetKVRowBuilder(SKVRowBuilder *pBuilder);
// SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder);
// static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t colId, const void *value, int32_t tlen)
// #ifdef JSON_TAG_REFACTOR
// TODO: JSON_TAG_TODO
include/common/tmsg.h
浏览文件 @
816cea07
...
...
@@ -287,7 +287,7 @@ typedef struct SSchema {
char
name
[
TSDB_COL_NAME_LEN
];
}
SSchema
;
#define COL_IS_SET(FLG) ((
FLG) & (COL_SET_VAL | COL_SET_NULL
) != 0)
#define COL_IS_SET(FLG) ((
(FLG) & (COL_SET_VAL | COL_SET_NULL)
) != 0)
#define COL_CLR_SET(FLG) ((FLG) &= (~(COL_SET_VAL | COL_SET_NULL)))
#define IS_BSMA_ON(s) (((s)->flags & 0x01) == COL_SMA_ON)
...
...
source/client/src/clientImpl.c
浏览文件 @
816cea07
...
...
@@ -958,30 +958,11 @@ static char* parseTagDatatoJson(void* p) {
char
tagJsonKey
[
256
]
=
{
0
};
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
// JSON_TAG_REFACTOR
pTagVal
->
nData
;
pTagVal
->
pData
;
// for varChar, len not included
// TODO: adapt below code;
char
*
val
=
(
char
*
)
pTagVal
->
pData
;
// TODO: adapt below code;
if
(
j
==
0
)
{
if
(
*
val
==
TSDB_DATA_TYPE_NULL
)
{
string
=
taosMemoryCalloc
(
1
,
8
);
sprintf
(
string
,
"%s"
,
TSDB_DATA_NULL_STR_L
);
goto
end
;
}
continue
;
}
// json key encode by binary
memset
(
tagJsonKey
,
0
,
sizeof
(
tagJsonKey
));
memcpy
(
tagJsonKey
,
varDataVal
(
val
),
varDataLen
(
val
));
memcpy
(
tagJsonKey
,
pTagVal
->
pKey
,
strlen
(
pTagVal
->
pKey
));
// json value
val
+=
varDataTLen
(
val
);
char
*
realData
=
POINTER_SHIFT
(
val
,
CHAR_BYTES
);
char
type
=
*
val
;
char
type
=
pTagVal
->
type
;
if
(
type
==
TSDB_DATA_TYPE_NULL
)
{
cJSON
*
value
=
cJSON_CreateNull
();
if
(
value
==
NULL
)
{
...
...
@@ -990,11 +971,11 @@ static char* parseTagDatatoJson(void* p) {
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
cJSON
*
value
=
NULL
;
if
(
varDataLen
(
realData
)
>
0
)
{
char
*
tagJsonValue
=
taosMemoryCalloc
(
varDataLen
(
realData
)
,
1
);
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
varDataVal
(
realData
),
varDataLen
(
realData
)
,
tagJsonValue
);
if
(
pTagVal
->
nData
>
0
)
{
char
*
tagJsonValue
=
taosMemoryCalloc
(
pTagVal
->
nData
,
1
);
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
pTagVal
->
pData
,
pTagVal
->
nData
,
tagJsonValue
);
if
(
length
<
0
)
{
tscError
(
"charset:%s to %s. val:%s convert json value failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
val
);
tscError
(
"charset:%s to %s. val:%s convert json value failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
pTagVal
->
pData
);
taosMemoryFree
(
tagJsonValue
);
goto
end
;
}
...
...
@@ -1003,7 +984,7 @@ static char* parseTagDatatoJson(void* p) {
if
(
value
==
NULL
)
{
goto
end
;
}
}
else
if
(
varDataLen
(
realData
)
==
0
)
{
}
else
if
(
pTagVal
->
nData
==
0
)
{
value
=
cJSON_CreateString
(
""
);
}
else
{
ASSERT
(
0
);
...
...
@@ -1011,22 +992,14 @@ static char* parseTagDatatoJson(void* p) {
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
double
jsonVd
=
*
(
double
*
)(
realData
);
double
jsonVd
=
*
(
double
*
)(
&
pTagVal
->
i64
);
cJSON
*
value
=
cJSON_CreateNumber
(
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
// }else if(type == TSDB_DATA_TYPE_BIGINT){
// int64_t jsonVd = *(int64_t*)(realData);
// cJSON* value = cJSON_CreateNumber((double)jsonVd);
// if (value == NULL)
// {
// goto end;
// }
// cJSON_AddItemToObject(json, tagJsonKey, value);
}
else
if
(
type
==
TSDB_DATA_TYPE_BOOL
)
{
char
jsonVd
=
*
(
char
*
)(
realData
);
char
jsonVd
=
*
(
char
*
)(
&
pTagVal
->
i64
);
cJSON
*
value
=
cJSON_CreateBool
(
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
...
...
@@ -1091,7 +1064,7 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
if
(
jsonInnerType
==
TSDB_DATA_TYPE_NULL
)
{
sprintf
(
varDataVal
(
dst
),
"%s"
,
TSDB_DATA_NULL_STR_L
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
T
SDB_DATA_TYPE
_JSON
)
{
}
else
if
(
jsonInnerType
==
T
D_TAG
_JSON
)
{
char
*
jsonString
=
parseTagDatatoJson
(
jsonInnerData
);
STR_TO_VARSTR
(
dst
,
jsonString
);
taosMemoryFree
(
jsonString
);
...
...
@@ -1110,10 +1083,6 @@ static int32_t doConvertUCS4(SReqResultInfo* pResultInfo, int32_t numOfRows, int
double
jsonVd
=
*
(
double
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%.9lf"
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BIGINT
)
{
int64_t
jsonVd
=
*
(
int64_t
*
)(
jsonInnerData
);
sprintf
(
varDataVal
(
dst
),
"%"
PRId64
,
jsonVd
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
}
else
if
(
jsonInnerType
==
TSDB_DATA_TYPE_BOOL
)
{
sprintf
(
varDataVal
(
dst
),
"%s"
,
(
*
((
char
*
)
jsonInnerData
)
==
1
)
?
"true"
:
"false"
);
varDataSetLen
(
dst
,
strlen
(
varDataVal
(
dst
)));
...
...
source/common/src/tdatablock.c
浏览文件 @
816cea07
...
...
@@ -116,22 +116,23 @@ int32_t colDataAppend(SColumnInfoData* pColumnInfoData, uint32_t currentRow, con
int32_t
type
=
pColumnInfoData
->
info
.
type
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
int32_t
dataLen
=
varDataTLen
(
pData
)
;
int32_t
dataLen
=
0
;
if
(
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
*
pData
==
TSDB_DATA_TYPE_NULL
)
{
dataLen
=
0
;
dataLen
=
CHAR_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_NCHAR
)
{
dataLen
=
varDataTLen
(
pData
+
CHAR_BYTES
);
dataLen
=
varDataTLen
(
pData
+
CHAR_BYTES
)
+
CHAR_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_DOUBLE
)
{
dataLen
=
DOUBLE_BYTES
;
dataLen
=
DOUBLE_BYTES
+
CHAR_BYTES
;
}
else
if
(
*
pData
==
TSDB_DATA_TYPE_BOOL
)
{
dataLen
=
CHAR_BYTES
;
}
else
if
(
*
pData
==
T
SDB_DATA_TYPE_JSON
)
{
dataLen
=
((
STag
*
)(
pData
+
CHAR_BYTES
))
->
len
;
dataLen
=
CHAR_BYTES
+
CHAR_BYTES
;
}
else
if
(
*
pData
==
T
D_TAG_JSON
)
{
// json string
dataLen
=
((
STag
*
)(
pData
))
->
len
;
}
else
{
ASSERT
(
0
);
}
dataLen
+=
CHAR_BYTES
;
}
else
{
dataLen
=
varDataTLen
(
pData
);
}
SVarColAttr
*
pAttr
=
&
pColumnInfoData
->
varmeta
;
...
...
source/common/src/tdataformat.c
浏览文件 @
816cea07
...
...
@@ -123,7 +123,7 @@ int32_t tTSRowGet(const STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal
ASSERT
(
iCol
!=
0
);
ASSERT
(
pTColumn
->
colId
!=
0
);
ASSERT
(
pRow
->
flags
&
0xf
!=
0
);
ASSERT
(
(
pRow
->
flags
&
0xf
)
!=
0
);
switch
(
pRow
->
flags
&
0xf
)
{
case
TSROW_HAS_NONE
:
*
pColVal
=
ColValNONE
;
...
...
@@ -432,7 +432,6 @@ static void setBitMap(uint8_t *p, STSchema *pTSchema, uint8_t flags) {
}
int32_t
tTSRowBuilderGetRow
(
STSRowBuilder
*
pBuilder
,
const
STSRow2
**
ppRow
)
{
int32_t
nDataTP
,
nDataKV
;
uint32_t
flags
;
STSKVRow
*
pTSKVRow
=
(
STSKVRow
*
)
pBuilder
->
pKVBuf
;
int32_t
nCols
=
pBuilder
->
pTSchema
->
numOfCols
;
...
...
@@ -446,7 +445,7 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) {
pBuilder
->
row
.
flags
|=
TSROW_HAS_NONE
;
}
ASSERT
(
pBuilder
->
row
.
flags
&
0xf
!=
0
);
ASSERT
(
(
pBuilder
->
row
.
flags
&
0xf
)
!=
0
);
*
(
ppRow
)
=
&
pBuilder
->
row
;
switch
(
pBuilder
->
row
.
flags
&
0xf
)
{
case
TSROW_HAS_NONE
:
...
...
@@ -476,7 +475,7 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) {
if
(
nDataKV
<
nDataTP
)
{
// generate KV row
ASSERT
(
pBuilder
->
row
.
flags
&
0xf
!=
TSROW_HAS_VAL
);
ASSERT
(
(
pBuilder
->
row
.
flags
&
0xf
)
!=
TSROW_HAS_VAL
);
pBuilder
->
row
.
flags
|=
TSROW_KV_ROW
;
pBuilder
->
row
.
nData
=
nDataKV
;
...
...
@@ -492,12 +491,12 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow) {
pBuilder
->
row
.
nData
=
nDataTP
;
uint8_t
*
p
;
uint8_t
flags
=
pBuilder
->
row
.
flags
&
0xf
;
uint8_t
flags
=
(
pBuilder
->
row
.
flags
&
0xf
)
;
if
(
flags
==
TSROW_HAS_VAL
)
{
pBuilder
->
row
.
pData
=
pBuilder
->
pTPBuf
+
pBuilder
->
szBitMap2
;
}
else
{
if
(
flags
==
TSROW_HAS_VAL
|
TSROW_HAS_NULL
|
TSROW_HAS_NONE
)
{
if
(
flags
==
(
TSROW_HAS_VAL
|
TSROW_HAS_NULL
|
TSROW_HAS_NONE
)
)
{
pBuilder
->
row
.
pData
=
pBuilder
->
pTPBuf
;
}
else
{
pBuilder
->
row
.
pData
=
pBuilder
->
pTPBuf
+
pBuilder
->
szBitMap2
-
pBuilder
->
szBitMap1
;
...
...
@@ -620,7 +619,11 @@ void debugPrintSTag(STag *pTag, const char *tag, int32_t ln) {
}
printf
(
"%s:%d loop[%d-%d] offset=%d
\n
"
,
__func__
,
__LINE__
,
(
int32_t
)
pTag
->
nTag
,
(
int32_t
)
n
,
(
int32_t
)
offset
);
tGetTagVal
(
p
+
offset
,
&
tagVal
,
isJson
);
debugPrintTagVal
(
tagVal
.
type
,
tagVal
.
pData
,
tagVal
.
nData
,
__func__
,
__LINE__
);
if
(
IS_VAR_DATA_TYPE
(
tagVal
.
type
)){
debugPrintTagVal
(
tagVal
.
type
,
tagVal
.
pData
,
tagVal
.
nData
,
__func__
,
__LINE__
);
}
else
{
debugPrintTagVal
(
tagVal
.
type
,
&
tagVal
.
i64
,
tDataTypes
[
tagVal
.
type
].
bytes
,
__func__
,
__LINE__
);
}
}
printf
(
"
\n
"
);
}
...
...
@@ -643,44 +646,8 @@ static int32_t tPutTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) {
n
+=
tPutBinary
(
p
?
p
+
n
:
p
,
pTagVal
->
pData
,
pTagVal
->
nData
);
}
else
{
p
=
p
?
p
+
n
:
p
;
switch
(
pTagVal
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
n
+=
tPutI8
(
p
,
pTagVal
->
i8
?
1
:
0
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
n
+=
tPutI8
(
p
,
pTagVal
->
i8
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
n
+=
tPutI16
(
p
,
pTagVal
->
i16
);
break
;
case
TSDB_DATA_TYPE_INT
:
n
+=
tPutI32
(
p
,
pTagVal
->
i32
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
n
+=
tPutI64
(
p
,
pTagVal
->
i64
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
n
+=
tPutFloat
(
p
,
pTagVal
->
f
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
n
+=
tPutDouble
(
p
,
pTagVal
->
d
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
n
+=
tPutU8
(
p
,
pTagVal
->
u8
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
n
+=
tPutU16
(
p
,
pTagVal
->
u16
);
break
;
case
TSDB_DATA_TYPE_UINT
:
n
+=
tPutU32
(
p
,
pTagVal
->
u32
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
n
+=
tPutU64
(
p
,
pTagVal
->
u64
);
break
;
default:
ASSERT
(
0
);
}
n
+=
tDataTypes
[
pTagVal
->
type
].
bytes
;
if
(
p
)
memcpy
(
p
,
&
(
pTagVal
->
i64
),
tDataTypes
[
pTagVal
->
type
].
bytes
);
}
return
n
;
...
...
@@ -702,42 +669,8 @@ static int32_t tGetTagVal(uint8_t *p, STagVal *pTagVal, int8_t isJson) {
if
(
IS_VAR_DATA_TYPE
(
pTagVal
->
type
))
{
n
+=
tGetBinary
(
p
+
n
,
&
pTagVal
->
pData
,
&
pTagVal
->
nData
);
}
else
{
switch
(
pTagVal
->
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
n
+=
tGetI8
(
p
+
n
,
&
pTagVal
->
i8
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
n
+=
tGetI16
(
p
,
&
pTagVal
->
i16
);
break
;
case
TSDB_DATA_TYPE_INT
:
n
+=
tGetI32
(
p
,
&
pTagVal
->
i32
);
break
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
case
TSDB_DATA_TYPE_BIGINT
:
n
+=
tGetI64
(
p
,
&
pTagVal
->
i64
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
n
+=
tGetFloat
(
p
,
&
pTagVal
->
f
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
n
+=
tGetDouble
(
p
,
&
pTagVal
->
d
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
n
+=
tGetU8
(
p
,
&
pTagVal
->
u8
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
n
+=
tGetU16
(
p
,
&
pTagVal
->
u16
);
break
;
case
TSDB_DATA_TYPE_UINT
:
n
+=
tGetU32
(
p
,
&
pTagVal
->
u32
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
n
+=
tGetU64
(
p
,
&
pTagVal
->
u64
);
break
;
default:
ASSERT
(
0
);
}
n
+=
tDataTypes
[
pTagVal
->
type
].
bytes
;
memcpy
(
&
(
pTagVal
->
i64
),
p
+
n
,
tDataTypes
[
pTagVal
->
type
].
bytes
);
}
return
n
;
...
...
@@ -814,6 +747,26 @@ void tTagFree(STag *pTag) {
if
(
pTag
)
taosMemoryFree
(
pTag
);
}
char
*
tTagValToData
(
const
STagVal
*
value
,
bool
isJson
){
if
(
!
value
)
return
NULL
;
char
*
data
=
NULL
;
int8_t
typeBytes
=
0
;
if
(
isJson
)
{
typeBytes
=
CHAR_BYTES
;
}
if
(
IS_VAR_DATA_TYPE
(
value
->
type
)){
data
=
taosMemoryCalloc
(
1
,
typeBytes
+
VARSTR_HEADER_SIZE
+
value
->
nData
);
if
(
data
==
NULL
)
return
NULL
;
if
(
isJson
)
*
data
=
value
->
type
;
varDataLen
(
data
+
typeBytes
)
=
value
->
nData
;
memcpy
(
varDataVal
(
data
+
typeBytes
),
value
->
pData
,
value
->
nData
);
}
else
{
data
=
((
char
*
)
&
(
value
->
i64
))
-
typeBytes
;
// json with type
}
return
data
;
}
bool
tTagGet
(
const
STag
*
pTag
,
STagVal
*
pTagVal
)
{
int16_t
lidx
=
0
;
int16_t
ridx
=
pTag
->
nTag
-
1
;
...
...
source/dnode/vnode/inc/vnode.h
浏览文件 @
816cea07
...
...
@@ -78,7 +78,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags);
void
metaReaderClear
(
SMetaReader
*
pReader
);
int32_t
metaGetTableEntryByUid
(
SMetaReader
*
pReader
,
tb_uid_t
uid
);
int32_t
metaReadNext
(
SMetaReader
*
pReader
);
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
cid
);
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
type
,
STagVal
*
tagVal
);
#if 1 // refact APIs below (TODO)
typedef
SVCreateTbReq
STbCfg
;
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
816cea07
...
...
@@ -564,9 +564,17 @@ SArray *metaGetSmaTbUids(SMeta *pMeta) {
#endif
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
cid
)
{
const
void
*
metaGetTableTagVal
(
SMetaEntry
*
pEntry
,
int16_t
type
,
STagVal
*
val
)
{
ASSERT
(
pEntry
->
type
==
TSDB_CHILD_TABLE
);
STagVal
tagVal
=
{.
cid
=
cid
};
tTagGet
((
const
STag
*
)
pEntry
->
ctbEntry
.
pTags
,
&
tagVal
);
return
tagVal
.
pData
;
STag
*
tag
=
(
STag
*
)
pEntry
->
ctbEntry
.
pTags
;
tTagGet
(
tag
,
val
);
if
(
val
->
type
==
TSDB_DATA_TYPE_NULL
){
return
NULL
;
}
if
(
type
==
TSDB_DATA_TYPE_JSON
){
return
tag
;
}
else
{
return
val
;
}
}
\ No newline at end of file
source/dnode/vnode/src/meta/metaTable.c
浏览文件 @
816cea07
...
...
@@ -573,15 +573,20 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
for
(
int32_t
i
=
0
;
i
<
pTagSchema
->
nCols
;
i
++
)
{
SSchema
*
pCol
=
&
pTagSchema
->
pSchema
[
i
];
if
(
iCol
==
i
)
{
tTagValPush
(
pTagArray
,
&
pCol
->
colId
,
pCol
->
type
,
pAlterTbReq
->
pTagVal
,
pAlterTbReq
->
nTagVal
,
false
);
STagVal
val
=
{
0
};
val
.
type
=
pCol
->
type
;
val
.
cid
=
pCol
->
colId
;
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
val
.
pData
=
pAlterTbReq
->
pTagVal
;
val
.
nData
=
pAlterTbReq
->
nTagVal
;
}
else
{
memcpy
(
&
val
.
i64
,
pAlterTbReq
->
pTagVal
,
pAlterTbReq
->
nTagVal
);
}
taosArrayPush
(
pTagArray
,
&
val
);
}
else
{
STagVal
tagVal
=
{.
cid
=
pCol
->
colId
};
if
(
tTagGet
(
pOldTag
,
&
tagVal
)
&&
tagVal
.
pData
)
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
tTagValPush
(
pTagArray
,
&
pCol
->
colId
,
pCol
->
type
,
varDataVal
(
tagVal
.
pData
),
varDataLen
(
tagVal
.
pData
),
false
);
}
else
{
tTagValPush
(
pTagArray
,
&
pCol
->
colId
,
pCol
->
type
,
tagVal
.
pData
,
pCol
->
bytes
,
false
);
}
STagVal
val
=
{
0
};
if
(
tTagGet
(
pOldTag
,
&
val
))
{
taosArrayPush
(
pTagArray
,
&
val
);
}
}
}
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
816cea07
...
...
@@ -303,29 +303,22 @@ void addTagPseudoColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock)
if
(
fmIsScanPseudoColumnFunc
(
functionId
))
{
setTbNameColData
(
pTableScanInfo
->
readHandle
.
meta
,
pBlock
,
pColInfoData
,
functionId
);
}
else
{
// these are tags
const
char
*
p
=
NULL
;
if
(
pColInfoData
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
{
const
STag
*
tmp
=
(
const
STag
*
)
mr
.
me
.
ctbEntry
.
pTags
;
char
*
data
=
taosMemoryCalloc
(
tmp
->
len
+
1
,
1
);
if
(
data
==
NULL
)
{
metaReaderClear
(
&
mr
);
qError
(
"doTagScan calloc error:%d"
,
tmp
->
len
+
1
);
return
;
}
*
data
=
TSDB_DATA_TYPE_JSON
;
memcpy
(
data
+
1
,
tmp
,
tmp
->
len
);
p
=
data
;
}
else
{
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pExpr
->
base
.
pParam
[
0
].
pCol
->
colId
);
STagVal
tagVal
=
{
0
};
tagVal
.
cid
=
pExpr
->
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pColInfoData
->
info
.
type
,
&
tagVal
);
char
*
data
=
NULL
;
if
(
pColInfoData
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
p
!=
NULL
){
data
=
tTagValToData
((
const
STagVal
*
)
p
,
false
);
}
else
{
data
=
(
char
*
)
p
;
}
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
rows
;
++
i
)
{
colDataAppend
(
pColInfoData
,
i
,
p
,
(
p
==
NULL
));
colDataAppend
(
pColInfoData
,
i
,
data
,
(
data
==
NULL
));
}
if
(
pColInfoData
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
{
taosMemoryFree
(
(
void
*
)
p
);
if
(
pColInfoData
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
IS_VAR_DATA_TYPE
(((
const
STagVal
*
)
p
)
->
type
)
&&
data
)
{
taosMemoryFree
(
data
);
}
}
}
...
...
@@ -1632,22 +1625,20 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
STR_TO_VARSTR
(
str
,
mr
.
me
.
name
);
colDataAppend
(
pDst
,
count
,
str
,
false
);
}
else
{
// it is a tag value
if
(
pDst
->
info
.
type
==
TSDB_DATA_TYPE_JSON
)
{
const
STag
*
tmp
=
(
const
STag
*
)
mr
.
me
.
ctbEntry
.
pTags
;
// TODO opt perf by realloc memory
char
*
data
=
taosMemoryCalloc
(
tmp
->
len
+
1
,
1
);
if
(
data
==
NULL
)
{
qError
(
"%s failed to malloc memory, size:%d"
,
GET_TASKID
(
pTaskInfo
),
tmp
->
len
+
1
);
longjmp
(
pTaskInfo
->
env
,
TSDB_CODE_OUT_OF_MEMORY
);
}
STagVal
val
=
{
0
};
val
.
cid
=
pExprInfo
[
j
].
base
.
pParam
[
0
].
pCol
->
colId
;
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pDst
->
info
.
type
,
&
val
);
char
*
data
=
NULL
;
if
(
pDst
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
p
!=
NULL
){
data
=
tTagValToData
((
const
STagVal
*
)
p
,
false
);
}
else
{
data
=
(
char
*
)
p
;
}
colDataAppend
(
pDst
,
count
,
data
,
(
data
==
NULL
));
*
data
=
TSDB_DATA_TYPE_JSON
;
memcpy
(
data
+
1
,
tmp
,
tmp
->
len
);
colDataAppend
(
pDst
,
count
,
data
,
false
);
if
(
pDst
->
info
.
type
!=
TSDB_DATA_TYPE_JSON
&&
IS_VAR_DATA_TYPE
(((
const
STagVal
*
)
p
)
->
type
)
&&
data
){
taosMemoryFree
(
data
);
}
else
{
const
char
*
p
=
metaGetTableTagVal
(
&
mr
.
me
,
pExprInfo
[
j
].
base
.
pParam
[
0
].
pCol
->
colId
);
colDataAppend
(
pDst
,
count
,
p
,
(
p
==
NULL
));
}
}
}
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
816cea07
...
...
@@ -55,9 +55,7 @@ int32_t getNumOfColumns(const STableMeta* pTableMeta);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
#ifdef JSON_TAG_REFACTOR
int32_t
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
errMsg
,
int16_t
startColId
);
#endif
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
SMsgBuf
*
errMsg
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
816cea07
此差异已折叠。
点击以展开。
source/libs/parser/src/parTranslater.c
浏览文件 @
816cea07
...
...
@@ -4144,26 +4144,6 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S
}
}
// static int32_t addValToKVRow(STranslateContext* pCxt, SValueNode* pVal, const SSchema* pSchema,
// SKVRowBuilder* pBuilder) {
#ifdef JSON_TAG_REFACTOR
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pVal
->
literal
&&
strlen
(
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pVal
->
literal
);
}
return
parseJsontoTagData
(
pVal
->
literal
,
pBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
}
#endif
// if (pVal->node.resType.type != TSDB_DATA_TYPE_NULL) {
// tdAddColToKVRow(pBuilder, pSchema->colId, nodesGetValueFromNode(pVal),
// IS_VAR_DATA_TYPE(pSchema->type) ? varDataTLen(pVal->datum.p) : TYPE_BYTES[pSchema->type]);
// }
// return TSDB_CODE_SUCCESS;
// }
static
int32_t
createValueFromFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
,
SValueNode
**
pVal
)
{
int32_t
code
=
getFuncInfo
(
pCxt
,
pFunc
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
...
...
@@ -4199,16 +4179,14 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
}
SArray
*
pTagArray
=
taosArrayInit
(
LIST_LENGTH
(
pStmt
->
pValsOfTags
),
sizeof
(
STagVal
));
char
*
pTagBuf
=
taosMemoryCalloc
(
1
,
TSDB_MAX_TAGS_LEN
);
if
(
!
pTagArray
||
!
pTagBuf
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
pTagBuf
);
if
(
!
pTagArray
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_TSC_OUT_OF_MEMORY
);
}
int32_t
code
=
0
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int16_t
nTags
=
0
,
nBufPos
=
0
;
SSchema
*
pTagSchema
=
getTableTagSchema
(
pSuperTableMeta
);
SNode
*
pTag
,
*
pNode
;
SNode
*
pTag
=
NULL
,
*
pNode
=
NULL
;
bool
isJson
=
false
;
FORBOTH
(
pTag
,
pStmt
->
pSpecificTags
,
pNode
,
pStmt
->
pValsOfTags
)
{
SColumnNode
*
pCol
=
(
SColumnNode
*
)
pTag
;
SSchema
*
pSchema
=
NULL
;
...
...
@@ -4219,57 +4197,56 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
}
}
if
(
NULL
==
pSchema
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
pTagBuf
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
code
=
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
goto
end
;
}
SValueNode
*
pVal
=
NULL
;
code
=
translateTagVal
(
pCxt
,
pSuperTableMeta
->
tableInfo
.
precision
,
pSchema
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
}
else
{
REPLACE_LIST2_NODE
(
pVal
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
goto
end
;
}
#ifdef JSON_TAG_REFACTOR
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addValToKVRow
(
pCxt
,
pVal
,
pSchema
,
pBuilder
);
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
}
else
{
REPLACE_LIST2_NODE
(
pVal
);
}
#endif
if
(
pTagSchema
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pVal
->
literal
&&
strlen
(
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
code
=
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pVal
->
literal
);
goto
end
;
}
if
(
pVal
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_NULL
)
{
// TODO: JSON_TAG_TODO: is copy is a must?
isJson
=
true
;
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
&
pCxt
->
msgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
}
}
else
if
(
pVal
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_NULL
)
{
void
*
nodeVal
=
nodesGetValueFromNode
(
pVal
);
if
(
IS_VAR_DATA_TYPE
(
pSchema
->
type
))
{
memcpy
(
pTagBuf
+
nBufPos
,
varDataVal
(
nodeVal
),
varDataLen
(
nodeVal
));
tTagValPush
(
pTagArray
,
&
pSchema
->
colId
,
pSchema
->
type
,
(
uint8_t
*
)
pTagBuf
+
nBufPos
,
varDataLen
(
nodeVal
),
false
);
nBufPos
+=
varDataLen
(
pVal
->
datum
.
p
);
STagVal
val
=
{.
cid
=
pTagSchema
->
colId
,
.
type
=
pTagSchema
->
type
};
if
(
IS_VAR_DATA_TYPE
(
pTagSchema
->
type
))
{
val
.
pData
=
varDataVal
(
nodeVal
);
val
.
nData
=
varDataLen
(
nodeVal
);
}
else
{
memcpy
(
pTagBuf
+
nBufPos
,
varDataVal
(
nodeVal
),
TYPE_BYTES
[
pSchema
->
type
]);
tTagValPush
(
pTagArray
,
&
pSchema
->
colId
,
pSchema
->
type
,
(
uint8_t
*
)
pTagBuf
+
nBufPos
,
TYPE_BYTES
[
pSchema
->
type
],
false
);
nBufPos
+=
TYPE_BYTES
[
pSchema
->
type
];
memcpy
(
&
val
.
i64
,
nodeVal
,
pTagSchema
->
bytes
);
}
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
pTagBuf
);
return
code
;
taosArrayPush
(
pTagArray
,
&
val
);
}
}
// TODO: JSON_TAG_TODO: version
code
=
tTagNew
(
pTagArray
,
1
,
false
,
ppTag
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
pTagBuf
);
return
code
;
}
end:
if
(
isJson
){
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagArray
);
++
i
)
{
STagVal
*
p
=
(
STagVal
*
)
taosArrayGet
(
pTagArray
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
type
)){
taosMemoryFree
(
p
->
pData
);
}
}
}
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
pTagBuf
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -4281,71 +4258,64 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
SSchema
*
pTagSchemas
=
getTableTagSchema
(
pSuperTableMeta
);
SNode
*
pNode
;
int32_t
code
=
0
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
index
=
0
;
SArray
*
pTagArray
=
taosArrayInit
(
LIST_LENGTH
(
pStmt
->
pValsOfTags
),
sizeof
(
STagVal
));
char
*
pTagBuf
=
taosMemoryCalloc
(
1
,
TSDB_MAX_TAGS_LEN
);
const
char
*
qTagBuf
=
pTagBuf
;
if
(
!
pTagArray
||
!
pTagBuf
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
qTagBuf
);
if
(
!
pTagArray
)
{
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_TSC_OUT_OF_MEMORY
);
}
bool
isJson
=
false
;
FOREACH
(
pNode
,
pStmt
->
pValsOfTags
)
{
SValueNode
*
pVal
=
NULL
;
SSchema
*
pTagSchema
=
pTagSchemas
+
index
;
code
=
translateTagVal
(
pCxt
,
pSuperTableMeta
->
tableInfo
.
precision
,
pTagSchema
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
}
else
{
REPLACE_NODE
(
pVal
);
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
goto
end
;
}
#ifdef JSON_TAG_REFACTOR
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
addValToKVRow
(
pCxt
,
pVal
,
pTagSchema
+
index
++
,
pBuilder
);
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
}
else
{
REPLACE_NODE
(
pVal
);
}
#endif
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
pVal
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_NULL
)
{
char
*
tmpVal
=
nodesGetValueFromNode
(
pVal
);
if
(
IS_VAR_DATA_TYPE
(
pTagSchema
->
type
))
{
memcpy
(
pTagBuf
,
varDataVal
(
tmpVal
),
varDataLen
(
tmpVal
));
tTagValPush
(
pTagArray
,
&
pTagSchema
->
colId
,
pTagSchema
->
type
,
(
uint8_t
*
)
pTagBuf
,
varDataLen
(
tmpVal
),
false
);
pTagBuf
+=
varDataLen
(
tmpVal
);
}
else
{
memcpy
(
pTagBuf
,
tmpVal
,
TYPE_BYTES
[
pTagSchema
->
type
]);
tTagValPush
(
pTagArray
,
&
pTagSchema
->
colId
,
pTagSchema
->
type
,
(
uint8_t
*
)
pTagBuf
,
TYPE_BYTES
[
pTagSchema
->
type
],
false
);
pTagBuf
+=
TYPE_BYTES
[
pTagSchema
->
type
];
}
if
(
pTagSchema
->
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
pVal
->
literal
&&
strlen
(
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
code
=
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pVal
->
literal
);
goto
end
;
}
++
index
;
}
// TODO: buf is need to store the tags
// TODO: JSON_TAG_TODO remove below codes if code is 0 all the time.
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
qTagBuf
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
code
);
isJson
=
true
;
code
=
parseJsontoTagData
(
pVal
->
literal
,
pTagArray
,
&
pCxt
->
msgBuf
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
goto
end
;
}
}
else
if
(
pVal
->
node
.
resType
.
type
!=
TSDB_DATA_TYPE_NULL
)
{
char
*
tmpVal
=
nodesGetValueFromNode
(
pVal
);
STagVal
val
=
{.
cid
=
pTagSchema
->
colId
,
.
type
=
pTagSchema
->
type
};
if
(
IS_VAR_DATA_TYPE
(
pTagSchema
->
type
))
{
val
.
pData
=
varDataVal
(
tmpVal
);
val
.
nData
=
varDataLen
(
tmpVal
);
}
else
{
memcpy
(
&
val
.
i64
,
tmpVal
,
pTagSchema
->
bytes
);
}
taosArrayPush
(
pTagArray
,
&
val
);
}
++
index
;
}
// TODO: JSON_TAG_TODO: version?
// TODO: JSON_TAG_REFACTOR: json or not
if
(
0
!=
(
code
=
tTagNew
(
pTagArray
,
1
,
false
,
ppTag
)))
{
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
qTagBuf
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
code
);
code
=
tTagNew
(
pTagArray
,
1
,
false
,
ppTag
);
end:
if
(
isJson
){
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagArray
);
++
i
)
{
STagVal
*
p
=
(
STagVal
*
)
taosArrayGet
(
pTagArray
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
type
)){
taosMemoryFree
(
p
->
pData
);
}
}
}
taosArrayDestroy
(
pTagArray
);
taosMemoryFreeClear
(
qTagBuf
);
return
TSDB_CODE_SUCCESS
;
return
code
;
}
static
int32_t
checkCreateSubTable
(
STranslateContext
*
pCxt
,
SCreateSubTableClause
*
pStmt
)
{
...
...
@@ -4602,39 +4572,42 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
pReq
->
isNull
=
(
TSDB_DATA_TYPE_NULL
==
pStmt
->
pVal
->
node
.
resType
.
type
);
if
(
pStmt
->
pVal
->
node
.
resType
.
type
==
TSDB_DATA_TYPE_JSON
)
{
#ifdef JSON_TAG_REFACTOR
SKVRowBuilder
kvRowBuilder
=
{
0
};
int32_t
code
=
tdInitKVRowBuilder
(
&
kvRowBuilder
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
if
(
pStmt
->
pVal
->
literal
&&
strlen
(
pStmt
->
pVal
->
literal
)
>
(
TSDB_MAX_JSON_TAG_LEN
-
VARSTR_HEADER_SIZE
)
/
TSDB_NCHAR_SIZE
)
{
return
buildSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
"json string too long than 4095"
,
pStmt
->
pVal
->
literal
);
}
code
=
parseJsontoTagData
(
pStmt
->
pVal
->
literal
,
&
kvRowBuilder
,
&
pCxt
->
msgBuf
,
pSchema
->
colId
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
SArray
*
pTagVals
=
taosArrayInit
(
1
,
sizeof
(
STagVal
));
int32_t
code
=
TSDB_CODE_SUCCESS
;
STag
*
pTag
=
NULL
;
do
{
code
=
parseJsontoTagData
(
pStmt
->
pVal
->
literal
,
pTagVals
,
&
pCxt
->
msgBuf
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
break
;
}
code
=
tTagNew
(
pTagVals
,
1
,
false
,
&
pTag
);
}
while
(
0
);
for
(
int
i
=
0
;
i
<
taosArrayGetSize
(
pTagVals
);
++
i
)
{
STagVal
*
p
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
i
);
if
(
IS_VAR_DATA_TYPE
(
p
->
type
)){
taosMemoryFree
(
p
->
pData
);
}
}
SKVRow
row
=
tdGetKVRowFromBuilder
(
&
kvRowBuilder
);
if
(
NULL
==
row
)
{
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
return
TSDB_CODE_OUT_OF_MEMORY
;
taosArrayDestroy
(
pTagVals
);
if
(
code
!=
TSDB_CODE_SUCCESS
){
return
code
;
}
pReq
->
nTagVal
=
kvRowLen
(
row
);
pReq
->
pTagVal
=
row
;
pStmt
->
pVal
->
datum
.
p
=
row
;
// for free
tdDestroyKVRowBuilder
(
&
kvRowBuilder
);
#endif
pReq
->
nTagVal
=
pTag
->
len
;
pReq
->
pTagVal
=
(
uint8_t
*
)
pTag
;
pStmt
->
pVal
->
datum
.
p
=
(
char
*
)
pTag
;
// for free
}
else
{
pReq
->
nTagVal
=
pStmt
->
pVal
->
node
.
resType
.
bytes
;
if
(
TSDB_DATA_TYPE_NCHAR
==
pStmt
->
pVal
->
node
.
resType
.
type
)
{
pReq
->
nTagVal
=
pReq
->
nTagVal
*
TSDB_NCHAR_SIZE
;
}
pReq
->
pTagVal
=
nodesGetValueFromNode
(
pStmt
->
pVal
);
// data and length are seperated for new tag format STagVal
if
(
IS_VAR_DATA_TYPE
(
pStmt
->
pVal
->
node
.
resType
.
type
))
{
pReq
->
nTagVal
=
varDataLen
(
pReq
->
pTagVal
);
pReq
->
pTagVal
=
varDataVal
(
pReq
->
pTagVal
);
}
}
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
816cea07
...
...
@@ -328,13 +328,9 @@ static bool isValidateTag(char* input) {
return
true
;
}
#ifdef JSON_TAG_REFACTOR
int32_t
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
pMsgBuf
,
int16_t
startColId
)
{
int32_t
parseJsontoTagData
(
const
char
*
json
,
SArray
*
pTagVals
,
SMsgBuf
*
pMsgBuf
)
{
// set json NULL data
uint8_t
jsonNULL
=
TSDB_DATA_TYPE_NULL
;
int32_t
jsonIndex
=
startColId
+
1
;
if
(
!
json
||
strtrim
((
char
*
)
json
)
==
0
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
)
{
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -349,13 +345,12 @@ int32_t parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBu
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
}
int32_t
retCode
=
0
;
char
*
tagKV
=
NULL
;
int32_t
retCode
=
TSDB_CODE_SUCCESS
;
SHashObj
*
keyHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
q
Error
(
"json inner error:%d"
,
i
);
u
Error
(
"json inner error:%d"
,
i
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json inner error"
,
json
);
goto
end
;
}
...
...
@@ -367,89 +362,60 @@ int32_t parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBu
}
size_t
keyLen
=
strlen
(
jsonKey
);
if
(
keyLen
>
TSDB_MAX_JSON_KEY_LEN
)
{
q
Error
(
"json key too long error"
);
u
Error
(
"json key too long error"
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key too long, more than 256"
,
jsonKey
);
goto
end
;
}
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
continue
;
}
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: DOUBLE_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
DOUBLE_BYTES
,
1
);
if
(
!
tagKV
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
strncpy
(
varDataVal
(
tagKV
),
jsonKey
,
keyLen
);
varDataSetLen
(
tagKV
,
keyLen
);
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
uint8_t
jsonNotNULL
=
TSDB_DATA_TYPE_JSON
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
&
jsonNotNULL
,
CHAR_BYTES
);
// add json type
}
taosHashPut
(
keyHash
,
jsonKey
,
keyLen
,
&
keyLen
,
CHAR_BYTES
);
// add key to hash to remove dumplicate, value is useless
STagVal
val
=
{
0
};
val
.
pKey
=
jsonKey
;
taosHashPut
(
keyHash
,
jsonKey
,
keyLen
,
&
keyLen
,
CHAR_BYTES
);
// add key to hash to remove dumplicate, value is useless
if
(
item
->
type
==
cJSON_String
)
{
// add json value format: type|data
char
*
jsonValue
=
item
->
valuestring
;
int32_t
valLen
=
(
int32_t
)
strlen
(
jsonValue
);
int32_t
totalLen
=
keyLen
+
VARSTR_HEADER_SIZE
+
valLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
;
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
char
*
tmp
=
taosMemoryCalloc
(
1
,
valLen
*
TSDB_NCHAR_SIZE
);
if
(
!
tmp
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
tagKV
=
tmp
;
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_NCHAR
;
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
varDataVal
(
valueData
),
val
.
type
=
TSDB_DATA_TYPE_NCHAR
;
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
tmp
,
(
int32_t
)(
valLen
*
TSDB_NCHAR_SIZE
),
&
valLen
))
{
q
Error
(
"charset:%s to %s. val:%s, errno:%s, convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
jsonValue
,
u
Error
(
"charset:%s to %s. val:%s, errno:%s, convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
jsonValue
,
strerror
(
errno
));
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"charset convert json error"
,
jsonValue
);
goto
end
;
}
varDataSetLen
(
valueData
,
valLen
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
totalLen
);
val
.
nData
=
valLen
;
val
.
pData
=
tmp
;
}
else
if
(
item
->
type
==
cJSON_Number
)
{
if
(
!
isfinite
(
item
->
valuedouble
))
{
q
Error
(
"json value is invalidate"
);
u
Error
(
"json value is invalidate"
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json value number is illegal"
,
json
);
goto
end
;
}
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_DOUBLE
;
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
DOUBLE_BYTES
);
val
.
type
=
TSDB_DATA_TYPE_DOUBLE
;
*
((
double
*
)
&
(
val
.
i64
))
=
item
->
valuedouble
;
}
else
if
(
item
->
type
==
cJSON_True
||
item
->
type
==
cJSON_False
)
{
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_BOOL
;
*
valueData
=
(
char
)(
item
->
valueint
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
CHAR_BYTES
);
val
.
type
=
TSDB_DATA_TYPE_BOOL
;
*
((
char
*
)
&
(
val
.
i64
))
=
(
char
)(
item
->
valueint
);
}
else
if
(
item
->
type
==
cJSON_NULL
)
{
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
*
valueType
=
TSDB_DATA_TYPE_NULL
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
val
.
type
=
TSDB_DATA_TYPE_NULL
;
}
else
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"invalidate json value"
,
json
);
goto
end
;
}
}
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
// set json NULL true
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
taosArrayPush
(
pTagVals
,
&
val
);
}
end:
taosMemoryFree
(
tagKV
);
taosHashCleanup
(
keyHash
);
cJSON_Delete
(
root
);
return
retCode
;
}
#endif
static
int32_t
buildTableReq
(
SHashObj
*
pTablesHash
,
SArray
**
pTables
)
{
if
(
NULL
!=
pTablesHash
)
{
...
...
source/libs/scalar/src/sclvector.c
浏览文件 @
816cea07
...
...
@@ -922,29 +922,12 @@ static void doReleaseVec(SColumnInfoData* pCol, int32_t type) {
}
}
char
*
getJsonValue
(
char
*
json
,
char
*
key
)
{
// todo
json
++
;
// jump type
STagVal
tagVal
=
{.
pKey
=
key
};
tTagGet
(((
const
STag
*
)
json
),
&
tagVal
);
return
(
char
*
)
tagVal
.
pData
;
#if 0
int16_t cols = kvRowNCols(json);
for (int i = 0; i < cols; ++i) {
SColIdx *pColIdx = kvRowColIdxAt(json, i);
char *data = kvRowColVal(json, pColIdx);
if(i == 0){
if(*data == TSDB_DATA_TYPE_NULL) {
return NULL;
}
continue;
}
if(memcmp(key, data, varDataTLen(data)) == 0){
return data + varDataTLen(data);
}
STagVal
*
getJsonValue
(
char
*
json
,
STagVal
*
tagVal
)
{
bool
find
=
tTagGet
(((
const
STag
*
)
json
),
tagVal
);
// json value is null and not exist is different
if
(
!
find
){
return
NULL
;
}
return NULL;
#endif
return
tagVal
;
}
void
vectorJsonArrow
(
SScalarParam
*
pLeft
,
SScalarParam
*
pRight
,
SScalarParam
*
pOut
,
int32_t
_ord
)
{
...
...
@@ -963,13 +946,13 @@ void vectorJsonArrow(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pO
continue
;
}
char
*
pLeftData
=
colDataGetVarData
(
pLeft
->
columnData
,
i
);
char
*
value
=
getJsonValue
(
pLeftData
,
pRightData
);
if
(
!
value
)
{
colDataSetNull_var
(
pOutputCol
,
i
);
pOutputCol
->
hasNull
=
true
;
continue
;
STagVal
val
=
{.
pKey
=
pRightData
};
STagVal
*
value
=
getJsonValue
(
pLeftData
,
&
val
);
char
*
data
=
tTagValToData
(
value
,
true
);
colDataAppend
(
pOutputCol
,
i
,
data
,
data
==
NULL
);
if
(
value
&&
IS_VAR_DATA_TYPE
(
value
->
type
)
&&
data
){
taosMemoryFree
(
data
)
}
colDataAppend
(
pOutputCol
,
i
,
value
,
false
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录