Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
716dd2c5
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看板
提交
716dd2c5
编写于
6月 08, 2022
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: do some internal refactor, add the column info in STableRetrieveRsp.
上级
9bee5e2c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
114 addition
and
111 deletion
+114
-111
include/util/tdef.h
include/util/tdef.h
+2
-2
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+18
-21
source/common/src/tdatablock.c
source/common/src/tdatablock.c
+1
-1
source/libs/command/src/command.c
source/libs/command/src/command.c
+61
-58
source/libs/command/src/explain.c
source/libs/command/src/explain.c
+32
-29
未找到文件。
include/util/tdef.h
浏览文件 @
716dd2c5
...
...
@@ -356,8 +356,8 @@ typedef enum ELogicConditionType {
#define TSDB_DEFAULT_EXPLAIN_VERBOSE false
#define TSDB_EXPLAIN_RESULT_ROW_SIZE
1024
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY
PLAN"
#define TSDB_EXPLAIN_RESULT_ROW_SIZE
512
#define TSDB_EXPLAIN_RESULT_COLUMN_NAME "QUERY
_
PLAN"
#define TSDB_MAX_FIELD_LEN 16384
#define TSDB_MAX_BINARY_LEN (TSDB_MAX_FIELD_LEN - TSDB_KEYSIZE) // keep 16384
...
...
source/client/test/clientTests.cpp
浏览文件 @
716dd2c5
...
...
@@ -780,31 +780,28 @@ TEST(testCase, async_api_test) {
taos_query
(
pConn
,
"use test"
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"select * from t1"
);
taos_query
(
pConn
,
"alter table t1 add column b int"
);
pRes
=
taos_query
(
pConn
,
"insert into t1 values(now, 1, 2)"
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"desc abc1.tu"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
//
int32_t n = 0;
//
TAOS_ROW pRow = NULL;
//
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
//
int32_t numOfFields = taos_num_fields(pRes);
//
//
char str[512] = {0};
//
while ((pRow = taos_fetch_row(pRes)) != NULL) {
//
int32_t* length = taos_fetch_lengths(pRes);
//
for(int32_t i = 0; i < numOfFields; ++i) {
//
printf("(%d):%d " , i, length[i]);
//
}
//
printf("\n");
//
//
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
//
printf("%s\n", str);
//
memset(str, 0, sizeof(str));
//
}
int32_t
n
=
0
;
TAOS_ROW
pRow
=
NULL
;
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
char
str
[
512
]
=
{
0
};
while
((
pRow
=
taos_fetch_row
(
pRes
))
!=
NULL
)
{
int32_t
*
length
=
taos_fetch_lengths
(
pRes
);
for
(
int32_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
printf
(
"(%d):%d "
,
i
,
length
[
i
]);
}
printf
(
"
\n
"
);
int32_t
code
=
taos_print_row
(
str
,
pRow
,
pFields
,
numOfFields
);
printf
(
"%s
\n
"
,
str
);
memset
(
str
,
0
,
sizeof
(
str
));
}
taos_query_a
(
pConn
,
"alter table test.m1 comment 'abcde' "
,
queryCallback
,
pConn
);
getchar
();
...
...
source/common/src/tdatablock.c
浏览文件 @
716dd2c5
...
...
@@ -1902,7 +1902,7 @@ void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen
int32_t
*
colSizes
=
(
int32_t
*
)
data
;
data
+=
numOfCols
*
sizeof
(
int32_t
);
*
dataLen
=
blockDataGetSerialMetaSize
(
numOfCols
);
;
*
dataLen
=
blockDataGetSerialMetaSize
(
numOfCols
);
int32_t
numOfRows
=
pBlock
->
info
.
rows
;
for
(
int32_t
col
=
0
;
col
<
numOfCols
;
++
col
)
{
...
...
source/libs/command/src/command.c
浏览文件 @
716dd2c5
...
...
@@ -28,91 +28,94 @@ static int32_t getSchemaBytes(const SSchema* pSchema) {
}
}
// todo : to convert data according to SSDatablock
static
void
buildRspData
(
const
STableMeta
*
pMeta
,
char
*
pData
)
{
int32_t
*
payloadLen
=
(
int32_t
*
)
pData
;
uint64_t
*
groupId
=
(
uint64_t
*
)(
pData
+
sizeof
(
int32_t
))
;
static
SSDataBlock
*
buildDescResultDataBlock
()
{
SSDataBlock
*
pBlock
=
taosMemoryCalloc
(
1
,
sizeof
(
SSDataBlock
));
pBlock
->
info
.
numOfCols
=
DESCRIBE_RESULT_COLS
;
pBlock
->
info
.
hasVarCol
=
true
;
int32_t
*
pColSizes
=
(
int32_t
*
)(
pData
+
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
));
pData
=
(
char
*
)
pColSizes
+
DESCRIBE_RESULT_COLS
*
sizeof
(
int32_t
);
pBlock
->
pDataBlock
=
taosArrayInit
(
4
,
sizeof
(
SColumnInfoData
));
int32_t
numOfRows
=
TABLE_TOTAL_COL_NUM
(
pMeta
);
SColumnInfoData
infoData
=
{
0
};
infoData
.
info
.
type
=
TSDB_DATA_TYPE_VARCHAR
;
infoData
.
info
.
bytes
=
DESCRIBE_RESULT_FIELD_LEN
;
// Field
int32_t
*
pOffset
=
(
int32_t
*
)
pData
;
pData
+=
numOfRows
*
sizeof
(
int32_t
);
taosArrayPush
(
pBlock
->
pDataBlock
,
&
infoData
);
infoData
.
info
.
type
=
TSDB_DATA_TYPE_VARCHAR
;
infoData
.
info
.
bytes
=
DESCRIBE_RESULT_TYPE_LEN
;
taosArrayPush
(
pBlock
->
pDataBlock
,
&
infoData
);
infoData
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
infoData
.
info
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_INT
].
bytes
;;
taosArrayPush
(
pBlock
->
pDataBlock
,
&
infoData
);
infoData
.
info
.
type
=
TSDB_DATA_TYPE_VARCHAR
;
infoData
.
info
.
bytes
=
DESCRIBE_RESULT_NOTE_LEN
;
taosArrayPush
(
pBlock
->
pDataBlock
,
&
infoData
);
return
pBlock
;
}
static
void
setDescResultIntoDataBlock
(
SSDataBlock
*
pBlock
,
int32_t
numOfRows
,
STableMeta
*
pMeta
)
{
blockDataEnsureCapacity
(
pBlock
,
numOfRows
);
pBlock
->
info
.
rows
=
numOfRows
;
// field
SColumnInfoData
*
pCol1
=
taosArrayGet
(
pBlock
->
pDataBlock
,
0
);
char
buf
[
DESCRIBE_RESULT_FIELD_LEN
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
STR_TO_VARSTR
(
pData
,
pMeta
->
schema
[
i
].
name
);
int16_t
len
=
varDataTLen
(
pData
);
pData
+=
len
;
*
pOffset
=
pColSizes
[
0
];
pOffset
+=
1
;
pColSizes
[
0
]
+=
len
;
STR_TO_VARSTR
(
buf
,
pMeta
->
schema
[
i
].
name
);
colDataAppend
(
pCol1
,
i
,
buf
,
false
);
}
// Type
pOffset
=
(
int32_t
*
)
pData
;
pData
+=
numOfRows
*
sizeof
(
int32_t
);
SColumnInfoData
*
pCol2
=
taosArrayGet
(
pBlock
->
pDataBlock
,
1
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
STR_TO_VARSTR
(
pData
,
tDataTypes
[
pMeta
->
schema
[
i
].
type
].
name
);
int16_t
len
=
varDataTLen
(
pData
);
pData
+=
len
;
*
pOffset
=
pColSizes
[
1
];
pOffset
+=
1
;
pColSizes
[
1
]
+=
len
;
STR_TO_VARSTR
(
buf
,
tDataTypes
[
pMeta
->
schema
[
i
].
type
].
name
);
colDataAppend
(
pCol2
,
i
,
buf
,
false
);
}
// Length
pData
+=
BitmapLen
(
numOfRows
);
SColumnInfoData
*
pCol3
=
taosArrayGet
(
pBlock
->
pDataBlock
,
2
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
*
(
int32_t
*
)
pData
=
getSchemaBytes
(
pMeta
->
schema
+
i
);
pData
+=
sizeof
(
int32_t
);
int32_t
bytes
=
getSchemaBytes
(
pMeta
->
schema
+
i
);
colDataAppend
(
pCol3
,
i
,
(
const
char
*
)
&
bytes
,
false
);
}
pColSizes
[
2
]
=
sizeof
(
int32_t
)
*
numOfRows
;
// Note
pOffset
=
(
int32_t
*
)
pData
;
pData
+=
numOfRows
*
sizeof
(
int32_t
);
SColumnInfoData
*
pCol4
=
taosArrayGet
(
pBlock
->
pDataBlock
,
3
);
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
STR_TO_VARSTR
(
pData
,
i
>=
pMeta
->
tableInfo
.
numOfColumns
?
"TAG"
:
""
);
int16_t
len
=
varDataTLen
(
pData
);
pData
+=
len
;
*
pOffset
=
pColSizes
[
3
];
pOffset
+=
1
;
pColSizes
[
3
]
+=
len
;
}
for
(
int32_t
i
=
0
;
i
<
DESCRIBE_RESULT_COLS
;
++
i
)
{
pColSizes
[
i
]
=
htonl
(
pColSizes
[
i
]);
STR_TO_VARSTR
(
buf
,
i
>=
pMeta
->
tableInfo
.
numOfColumns
?
"TAG"
:
""
);
colDataAppend
(
pCol4
,
i
,
buf
,
false
);
}
*
payloadLen
=
(
int32_t
)(
pData
-
(
char
*
)
payloadLen
);
}
static
int32_t
calcRspSize
(
const
STableMeta
*
pMeta
)
{
int32_t
numOfRows
=
TABLE_TOTAL_COL_NUM
(
pMeta
);
return
sizeof
(
SRetrieveTableRsp
)
+
(
numOfRows
*
sizeof
(
int32_t
)
+
numOfRows
*
DESCRIBE_RESULT_FIELD_LEN
)
+
(
numOfRows
*
sizeof
(
int32_t
)
+
numOfRows
*
DESCRIBE_RESULT_TYPE_LEN
)
+
(
BitmapLen
(
numOfRows
)
+
numOfRows
*
sizeof
(
int32_t
))
+
(
numOfRows
*
sizeof
(
int32_t
)
+
numOfRows
*
DESCRIBE_RESULT_NOTE_LEN
)
+
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
);
}
static
int32_t
execDescribe
(
SNode
*
pStmt
,
SRetrieveTableRsp
**
pRsp
)
{
SDescribeStmt
*
pDesc
=
(
SDescribeStmt
*
)
pStmt
;
*
pRsp
=
taosMemoryCalloc
(
1
,
calcRspSize
(
pDesc
->
pMeta
));
SDescribeStmt
*
pDesc
=
(
SDescribeStmt
*
)
pStmt
;
int32_t
numOfRows
=
TABLE_TOTAL_COL_NUM
(
pDesc
->
pMeta
);
SSDataBlock
*
pBlock
=
buildDescResultDataBlock
();
setDescResultIntoDataBlock
(
pBlock
,
numOfRows
,
pDesc
->
pMeta
);
size_t
rspSize
=
sizeof
(
SRetrieveTableRsp
)
+
blockGetEncodeSize
(
pBlock
);
*
pRsp
=
taosMemoryCalloc
(
1
,
rspSize
);
if
(
NULL
==
*
pRsp
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
(
*
pRsp
)
->
useconds
=
0
;
(
*
pRsp
)
->
completed
=
1
;
(
*
pRsp
)
->
precision
=
0
;
(
*
pRsp
)
->
compressed
=
0
;
(
*
pRsp
)
->
compLen
=
0
;
(
*
pRsp
)
->
numOfRows
=
htonl
(
TABLE_TOTAL_COL_NUM
(
pDesc
->
pMeta
));
buildRspData
(
pDesc
->
pMeta
,
(
*
pRsp
)
->
data
);
(
*
pRsp
)
->
numOfRows
=
htonl
(
numOfRows
);
(
*
pRsp
)
->
numOfCols
=
htonl
(
DESCRIBE_RESULT_COLS
);
int32_t
len
=
0
;
blockCompressEncode
(
pBlock
,
(
*
pRsp
)
->
data
,
&
len
,
DESCRIBE_RESULT_COLS
,
false
);
ASSERT
(
len
==
rspSize
-
sizeof
(
SRetrieveTableRsp
));
blockDataDestroy
(
pBlock
);
return
TSDB_CODE_SUCCESS
;
}
...
...
source/libs/command/src/explain.c
浏览文件 @
716dd2c5
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "tdatablock.h"
#include "commandInt.h"
#include "plannodes.h"
#include "query.h"
...
...
@@ -916,9 +917,32 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
QRY_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
int32_t
colNum
=
1
;
int32_t
rspSize
=
sizeof
(
SRetrieveTableRsp
)
+
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
)
+
sizeof
(
int32_t
)
*
colNum
+
sizeof
(
int32_t
)
*
rowNum
+
pCtx
->
dataSize
;
SSDataBlock
*
pBlock
=
taosMemoryCalloc
(
1
,
sizeof
(
SSDataBlock
));
SColumnInfoData
infoData
=
{
0
};
infoData
.
info
.
type
=
TSDB_DATA_TYPE_VARCHAR
;
infoData
.
info
.
bytes
=
TSDB_EXPLAIN_RESULT_ROW_SIZE
;
pBlock
->
pDataBlock
=
taosArrayInit
(
1
,
sizeof
(
SColumnInfoData
));
taosArrayPush
(
pBlock
->
pDataBlock
,
&
infoData
);
SColumnInfoData
*
pInfoData
=
taosArrayGet
(
pBlock
->
pDataBlock
,
0
);
pInfoData
->
hasNull
=
false
;
colInfoDataEnsureCapacity
(
pInfoData
,
0
,
rowNum
);
char
buf
[
1024
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
SQueryExplainRowInfo
*
row
=
taosArrayGet
(
pCtx
->
rows
,
i
);
varDataCopy
(
buf
,
row
->
buf
);
ASSERT
(
varDataTLen
(
row
->
buf
)
==
row
->
len
);
colDataAppend
(
pInfoData
,
i
,
buf
,
false
);
}
pBlock
->
info
.
numOfCols
=
1
;
pBlock
->
info
.
rows
=
rowNum
;
pBlock
->
info
.
hasVarCol
=
true
;
int32_t
rspSize
=
sizeof
(
SRetrieveTableRsp
)
+
blockGetEncodeSize
(
pBlock
);
SRetrieveTableRsp
*
rsp
=
(
SRetrieveTableRsp
*
)
taosMemoryCalloc
(
1
,
rspSize
);
if
(
NULL
==
rsp
)
{
qError
(
"malloc SRetrieveTableRsp failed, size:%d"
,
rspSize
);
...
...
@@ -928,34 +952,13 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) {
rsp
->
completed
=
1
;
rsp
->
numOfRows
=
htonl
(
rowNum
);
// payload length
*
(
int32_t
*
)
rsp
->
data
=
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
)
+
sizeof
(
int32_t
)
*
colNum
+
sizeof
(
int32_t
)
*
rowNum
+
pCtx
->
dataSize
;
int32_t
len
=
0
;
blockCompressEncode
(
pBlock
,
rsp
->
data
,
&
len
,
pBlock
->
info
.
numOfCols
,
0
);
ASSERT
(
len
==
rspSize
-
sizeof
(
SRetrieveTableRsp
))
;
// group id
*
(
uint64_t
*
)(
rsp
->
data
+
sizeof
(
int32_t
))
=
0
;
// column length
int32_t
*
colLength
=
(
int32_t
*
)(
rsp
->
data
+
sizeof
(
int32_t
)
+
sizeof
(
uint64_t
));
// varchar column offset segment
int32_t
*
offset
=
(
int32_t
*
)((
char
*
)
colLength
+
sizeof
(
int32_t
));
// varchar data real payload
char
*
data
=
(
char
*
)(
offset
+
rowNum
);
char
*
start
=
data
;
for
(
int32_t
i
=
0
;
i
<
rowNum
;
++
i
)
{
SQueryExplainRowInfo
*
row
=
taosArrayGet
(
pCtx
->
rows
,
i
);
offset
[
i
]
=
data
-
start
;
varDataCopy
(
data
,
row
->
buf
);
ASSERT
(
varDataTLen
(
row
->
buf
)
==
row
->
len
);
data
+=
row
->
len
;
}
rsp
->
compLen
=
htonl
(
len
);
*
colLength
=
htonl
(
data
-
start
);
rsp
->
compLen
=
htonl
(
rspSize
);
blockDataDestroy
(
pBlock
);
*
pRsp
=
rsp
;
return
TSDB_CODE_SUCCESS
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录