Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b084be71
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看板
提交
b084be71
编写于
6月 21, 2022
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: show create table
上级
be2935cb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
126 addition
and
84 deletion
+126
-84
include/libs/qcom/query.h
include/libs/qcom/query.h
+1
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+0
-74
source/common/src/tmsg.c
source/common/src/tmsg.c
+1
-1
source/libs/command/src/command.c
source/libs/command/src/command.c
+49
-9
source/libs/qcom/src/queryUtil.c
source/libs/qcom/src/queryUtil.c
+75
-0
未找到文件。
include/libs/qcom/query.h
浏览文件 @
b084be71
...
...
@@ -208,6 +208,7 @@ char* jobTaskStatusStr(int32_t status);
SSchema
createSchema
(
int8_t
type
,
int32_t
bytes
,
col_id_t
colId
,
const
char
*
name
);
void
destroyQueryExecRes
(
SQueryExecRes
*
pRes
);
int32_t
dataConverToStr
(
char
*
str
,
int
type
,
void
*
buf
,
int32_t
bufSize
,
int32_t
*
len
);
char
*
parseTagDatatoJson
(
void
*
p
);
extern
int32_t
(
*
queryBuildMsg
[
TDMT_MAX
])(
void
*
input
,
char
**
msg
,
int32_t
msgSize
,
int32_t
*
msgLen
,
void
*
(
*
mallocFp
)(
int32_t
));
extern
int32_t
(
*
queryProcessMsgRsp
[
TDMT_MAX
])(
void
*
output
,
char
*
msg
,
int32_t
msgSize
);
...
...
source/client/src/clientImpl.c
浏览文件 @
b084be71
...
...
@@ -1444,80 +1444,6 @@ static int32_t doPrepareResPtr(SReqResultInfo* pResInfo) {
return
TSDB_CODE_SUCCESS
;
}
static
char
*
parseTagDatatoJson
(
void
*
p
)
{
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
SArray
*
pTagVals
=
NULL
;
if
(
tTagToValArray
((
const
STag
*
)
p
,
&
pTagVals
)
!=
0
)
{
goto
end
;
}
int16_t
nCols
=
taosArrayGetSize
(
pTagVals
);
char
tagJsonKey
[
256
]
=
{
0
};
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
// json key encode by binary
memset
(
tagJsonKey
,
0
,
sizeof
(
tagJsonKey
));
memcpy
(
tagJsonKey
,
pTagVal
->
pKey
,
strlen
(
pTagVal
->
pKey
));
// json value
char
type
=
pTagVal
->
type
;
if
(
type
==
TSDB_DATA_TYPE_NULL
)
{
cJSON
*
value
=
cJSON_CreateNull
();
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
cJSON
*
value
=
NULL
;
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
,
pTagVal
->
pData
);
taosMemoryFree
(
tagJsonValue
);
goto
end
;
}
value
=
cJSON_CreateString
(
tagJsonValue
);
taosMemoryFree
(
tagJsonValue
);
if
(
value
==
NULL
)
{
goto
end
;
}
}
else
if
(
pTagVal
->
nData
==
0
)
{
value
=
cJSON_CreateString
(
""
);
}
else
{
ASSERT
(
0
);
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
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_BOOL
)
{
char
jsonVd
=
*
(
char
*
)(
&
pTagVal
->
i64
);
cJSON
*
value
=
cJSON_CreateBool
(
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
{
ASSERT
(
0
);
}
}
string
=
cJSON_PrintUnformatted
(
json
);
end:
cJSON_Delete
(
json
);
return
string
;
}
static
int32_t
doConvertUCS4
(
SReqResultInfo
*
pResultInfo
,
int32_t
numOfRows
,
int32_t
numOfCols
,
int32_t
*
colLength
)
{
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
int32_t
type
=
pResultInfo
->
fields
[
i
].
type
;
...
...
source/common/src/tmsg.c
浏览文件 @
b084be71
...
...
@@ -1918,7 +1918,7 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp)
}
if
(
tDecodeI32
(
&
decoder
,
&
pRsp
->
tagsLen
)
<
0
)
return
-
1
;
if
(
tDecodeBinaryAlloc
(
&
decoder
,
&
pRsp
->
pTags
,
NULL
)
<
0
)
return
-
1
;
if
(
tDecodeBinaryAlloc
(
&
decoder
,
(
void
**
)
&
pRsp
->
pTags
,
NULL
)
<
0
)
return
-
1
;
tEndDecode
(
&
decoder
);
...
...
source/libs/command/src/command.c
浏览文件 @
b084be71
...
...
@@ -332,6 +332,15 @@ void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
}
}
void
appendTagNameFields
(
char
*
buf
,
int32_t
*
len
,
STableCfg
*
pCfg
)
{
for
(
int32_t
i
=
0
;
i
<
pCfg
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
pCfg
->
pSchemas
+
pCfg
->
numOfColumns
+
i
;
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"%s`%s`"
,
((
i
>
0
)
?
", "
:
""
),
pSchema
->
name
);
}
}
int32_t
appendTagValues
(
char
*
buf
,
int32_t
*
len
,
STableCfg
*
pCfg
)
{
SArray
*
pTagVals
=
NULL
;
STag
*
pTag
=
(
STag
*
)
pCfg
->
pTags
;
...
...
@@ -340,6 +349,7 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
char
*
pJson
=
parseTagDatatoJson
(
pTag
);
if
(
pJson
)
{
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"%s"
,
pJson
);
taosMemoryFree
(
pJson
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -350,15 +360,40 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
return
code
;
}
int16_t
nCols
=
taosArrayGetSize
(
pTagVals
);
int16_t
valueNum
=
taosArrayGetSize
(
pTagVals
);
int32_t
num
=
0
;
for
(
int
i
=
0
;
i
<
nCols
;
i
++
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
i
);
char
type
=
pTagVal
->
type
;
int32_t
tlen
=
0
;
dataConverToStr
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
type
,
pTagVal
->
pData
,
pTagVal
->
nData
,
&
tlen
);
*
len
+=
tlen
;
int32_t
j
=
0
;
for
(
int32_t
i
=
0
;
i
<
pCfg
->
numOfTags
;
++
i
)
{
SSchema
*
pSchema
=
pCfg
->
pSchemas
+
pCfg
->
numOfColumns
+
i
;
if
(
i
>
0
)
{
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
", "
);
}
if
(
j
>=
valueNum
)
{
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"NULL"
);
continue
;
}
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
if
(
pSchema
->
colId
>
pTagVal
->
cid
)
{
qError
(
"tag value and column mismatch, schemaId:%d, valId:%d"
,
pSchema
->
colId
,
pTagVal
->
cid
);
taosArrayDestroy
(
pTagVals
);
return
TSDB_CODE_APP_ERROR
;
}
else
if
(
pSchema
->
colId
==
pTagVal
->
cid
)
{
char
type
=
pTagVal
->
type
;
int32_t
tlen
=
0
;
if
(
IS_VAR_DATA_TYPE
(
type
))
{
dataConverToStr
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
type
,
pTagVal
->
pData
,
pTagVal
->
nData
,
&
tlen
);
}
else
{
dataConverToStr
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
type
,
&
pTagVal
->
i64
,
tDataTypes
[
type
].
bytes
,
&
tlen
);
}
*
len
+=
tlen
;
j
++
;
}
else
{
*
len
+=
sprintf
(
buf
+
VARSTR_HEADER_SIZE
+
*
len
,
"NULL"
);
}
/*
if (type == TSDB_DATA_TYPE_BINARY) {
...
...
@@ -389,6 +424,9 @@ int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg) {
*/
}
taosArrayDestroy
(
pTagVals
);
return
TSDB_CODE_SUCCESS
;
}
void
appendTableOptions
(
char
*
buf
,
int32_t
*
len
,
STableCfg
*
pCfg
)
{
...
...
@@ -444,7 +482,9 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, char *tbName,
appendTagFields
(
buf2
,
&
len
,
pCfg
);
len
+=
sprintf
(
buf2
+
VARSTR_HEADER_SIZE
+
len
,
")"
);
}
else
if
(
TSDB_CHILD_TABLE
==
pCfg
->
tableType
)
{
len
+=
sprintf
(
buf2
+
VARSTR_HEADER_SIZE
,
"CREATE TABLE `%s` USING `%s` TAGS ("
,
tbName
,
pCfg
->
stbName
);
len
+=
sprintf
(
buf2
+
VARSTR_HEADER_SIZE
,
"CREATE TABLE `%s` USING `%s` ("
,
tbName
,
pCfg
->
stbName
);
appendTagNameFields
(
buf2
,
&
len
,
pCfg
);
len
+=
sprintf
(
buf2
+
VARSTR_HEADER_SIZE
+
len
,
") TAGS ("
);
code
=
appendTagValues
(
buf2
,
&
len
,
pCfg
);
if
(
code
)
{
return
code
;
...
...
source/libs/qcom/src/queryUtil.c
浏览文件 @
b084be71
...
...
@@ -19,6 +19,7 @@
#include "tmsg.h"
#include "trpc.h"
#include "tsched.h"
#include "cJSON.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
...
...
@@ -297,4 +298,78 @@ int32_t dataConverToStr(char *str, int type, void *buf, int32_t bufSize, int32_t
return
TSDB_CODE_SUCCESS
;
}
char
*
parseTagDatatoJson
(
void
*
p
)
{
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
if
(
json
==
NULL
)
{
goto
end
;
}
SArray
*
pTagVals
=
NULL
;
if
(
tTagToValArray
((
const
STag
*
)
p
,
&
pTagVals
)
!=
0
)
{
goto
end
;
}
int16_t
nCols
=
taosArrayGetSize
(
pTagVals
);
char
tagJsonKey
[
256
]
=
{
0
};
for
(
int
j
=
0
;
j
<
nCols
;
++
j
)
{
STagVal
*
pTagVal
=
(
STagVal
*
)
taosArrayGet
(
pTagVals
,
j
);
// json key encode by binary
memset
(
tagJsonKey
,
0
,
sizeof
(
tagJsonKey
));
memcpy
(
tagJsonKey
,
pTagVal
->
pKey
,
strlen
(
pTagVal
->
pKey
));
// json value
char
type
=
pTagVal
->
type
;
if
(
type
==
TSDB_DATA_TYPE_NULL
)
{
cJSON
*
value
=
cJSON_CreateNull
();
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_NCHAR
)
{
cJSON
*
value
=
NULL
;
if
(
pTagVal
->
nData
>
0
)
{
char
*
tagJsonValue
=
taosMemoryCalloc
(
pTagVal
->
nData
,
1
);
int32_t
length
=
taosUcs4ToMbs
((
TdUcs4
*
)
pTagVal
->
pData
,
pTagVal
->
nData
,
tagJsonValue
);
if
(
length
<
0
)
{
qError
(
"charset:%s to %s. val:%s convert json value failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
pTagVal
->
pData
);
taosMemoryFree
(
tagJsonValue
);
goto
end
;
}
value
=
cJSON_CreateString
(
tagJsonValue
);
taosMemoryFree
(
tagJsonValue
);
if
(
value
==
NULL
)
{
goto
end
;
}
}
else
if
(
pTagVal
->
nData
==
0
)
{
value
=
cJSON_CreateString
(
""
);
}
else
{
ASSERT
(
0
);
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
if
(
type
==
TSDB_DATA_TYPE_DOUBLE
)
{
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_BOOL
)
{
char
jsonVd
=
*
(
char
*
)(
&
pTagVal
->
i64
);
cJSON
*
value
=
cJSON_CreateBool
(
jsonVd
);
if
(
value
==
NULL
)
{
goto
end
;
}
cJSON_AddItemToObject
(
json
,
tagJsonKey
,
value
);
}
else
{
ASSERT
(
0
);
}
}
string
=
cJSON_PrintUnformatted
(
json
);
end:
cJSON_Delete
(
json
);
return
string
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录