Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0a9eb233
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看板
提交
0a9eb233
编写于
12月 13, 2021
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-11819 mock catalog function for parser ut
上级
29aabe5d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
163 addition
and
105 deletion
+163
-105
include/libs/parser/parser.h
include/libs/parser/parser.h
+1
-1
source/libs/parser/inc/dataBlockMgt.h
source/libs/parser/inc/dataBlockMgt.h
+1
-15
source/libs/parser/src/dataBlockMgt.c
source/libs/parser/src/dataBlockMgt.c
+7
-20
source/libs/parser/src/insertParser.c
source/libs/parser/src/insertParser.c
+7
-13
source/libs/parser/test/insertTest.cpp
source/libs/parser/test/insertTest.cpp
+34
-18
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+23
-22
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+87
-14
source/libs/parser/test/mockCatalogService.h
source/libs/parser/test/mockCatalogService.h
+3
-2
未找到文件。
include/libs/parser/parser.h
浏览文件 @
0a9eb233
...
...
@@ -162,7 +162,7 @@ typedef struct SVgDataBlocks {
int64_t
vgId
;
// virtual group id
int32_t
numOfTables
;
// number of tables in current submit block
uint32_t
size
;
char
*
pData
;
char
*
pData
;
// SMsgDesc + SSubmitMsg + SSubmitBlk + ...
}
SVgDataBlocks
;
typedef
struct
SInsertStmtInfo
{
...
...
source/libs/parser/inc/dataBlockMgt.h
浏览文件 @
0a9eb233
...
...
@@ -75,16 +75,7 @@ typedef struct {
SMemRowInfo
*
rowInfo
;
}
SMemRowBuilder
;
typedef
struct
SParamInfo
{
int32_t
idx
;
uint8_t
type
;
uint8_t
timePrec
;
int16_t
bytes
;
uint32_t
offset
;
}
SParamInfo
;
typedef
struct
STableDataBlocks
{
SName
tableName
;
int8_t
tsSource
;
// where does the UNIX timestamp come from, server or client
bool
ordered
;
// if current rows are ordered or not
int64_t
vgId
;
// virtual group id
...
...
@@ -100,11 +91,6 @@ typedef struct STableDataBlocks {
STagData
tagData
;
SParsedDataColInfo
boundColumnInfo
;
// for parameter ('?') binding
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
SMemRowBuilder
rowBuilder
;
}
STableDataBlocks
;
...
...
@@ -187,7 +173,7 @@ void destroyBoundColumnInfo(SParsedDataColInfo* pColList);
int32_t
initMemRowBuilder
(
SMemRowBuilder
*
pBuilder
,
uint32_t
nRows
,
uint32_t
nCols
,
uint32_t
nBoundCols
,
int32_t
allNullLen
);
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
SName
*
name
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
);
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
);
int32_t
mergeTableDataBlocks
(
SHashObj
*
pHashObj
,
int8_t
schemaAttached
,
uint8_t
payloadType
,
bool
freeBlockMap
);
#endif // TDENGINE_DATABLOCKMGT_H
source/libs/parser/src/dataBlockMgt.c
浏览文件 @
0a9eb233
...
...
@@ -108,7 +108,7 @@ void destroyBoundColumnInfo(SParsedDataColInfo* pColList) {
tfree
(
pColList
->
colIdxInfo
);
}
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
SName
*
name
,
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
calloc
(
1
,
sizeof
(
STableDataBlocks
));
if
(
dataBuf
==
NULL
)
{
...
...
@@ -145,7 +145,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
dataBuf
->
tsSource
=
-
1
;
dataBuf
->
vgId
=
dataBuf
->
pTableMeta
->
vgId
;
tNameAssign
(
&
dataBuf
->
tableName
,
name
);
//
tNameAssign(&dataBuf->tableName, name);
assert
(
defaultSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
...
...
@@ -154,8 +154,7 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
}
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
SName
*
name
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
)
{
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
)
{
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
...
...
@@ -163,7 +162,7 @@ int32_t getDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, int3
}
if
(
*
dataBlocks
==
NULL
)
{
int32_t
ret
=
createDataBlock
((
size_t
)
size
,
rowSize
,
startOffset
,
name
,
pTableMeta
,
dataBlocks
);
int32_t
ret
=
createDataBlock
((
size_t
)
size
,
rowSize
,
startOffset
,
pTableMeta
,
dataBlocks
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
ret
;
}
...
...
@@ -253,23 +252,13 @@ static FORCE_INLINE void convertSMemRow(SMemRow dest, SMemRow src, STableDataBlo
}
}
void
destroyDataBlock
(
STableDataBlocks
*
pDataBlock
,
bool
removeMeta
)
{
void
destroyDataBlock
(
STableDataBlocks
*
pDataBlock
)
{
if
(
pDataBlock
==
NULL
)
{
return
;
}
tfree
(
pDataBlock
->
pData
);
if
(
removeMeta
)
{
char
name
[
TSDB_TABLE_FNAME_LEN
]
=
{
0
};
tNameExtractFullName
(
&
pDataBlock
->
tableName
,
name
);
// taosHashRemove(tscTableMetaMap, name, strnlen(name, TSDB_TABLE_FNAME_LEN));
}
if
(
!
pDataBlock
->
cloned
)
{
tfree
(
pDataBlock
->
params
);
// free the refcount for metermeta
if
(
pDataBlock
->
pTableMeta
!=
NULL
)
{
tfree
(
pDataBlock
->
pTableMeta
);
...
...
@@ -277,7 +266,6 @@ void destroyDataBlock(STableDataBlocks* pDataBlock, bool removeMeta) {
destroyBoundColumnInfo
(
&
pDataBlock
->
boundColumnInfo
);
}
tfree
(
pDataBlock
);
}
...
...
@@ -289,7 +277,7 @@ void* destroyBlockArrayList(SArray* pDataBlockList) {
size_t
size
=
taosArrayGetSize
(
pDataBlockList
);
for
(
int32_t
i
=
0
;
i
<
size
;
i
++
)
{
void
*
d
=
taosArrayGetP
(
pDataBlockList
,
i
);
destroyDataBlock
(
d
,
false
);
destroyDataBlock
(
d
);
}
taosArrayDestroy
(
pDataBlockList
);
...
...
@@ -505,7 +493,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t
if
(
pBlocks
->
numOfRows
>
0
)
{
STableDataBlocks
*
dataBuf
=
NULL
;
int32_t
ret
=
getDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
INSERT_HEAD_SIZE
,
0
,
&
pOneTableBlock
->
tableName
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
);
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosHashCleanup
(
pVnodeDataBlockHashList
);
destroyBlockArrayList
(
pVnodeDataBlockList
);
...
...
@@ -580,7 +568,6 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, int8_t schemaAttached, uint8_t
extractTableNameList
(
pHashObj
,
freeBlockMap
);
// free the table data blocks;
// pInsertParam->pDataBlocks = pVnodeDataBlockList;
taosHashCleanup
(
pVnodeDataBlockHashList
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
...
...
source/libs/parser/src/insertParser.c
浏览文件 @
0a9eb233
...
...
@@ -167,11 +167,12 @@ static int32_t skipInsertInto(SInsertParseContext* pCxt) {
static
int32_t
buildTableName
(
SInsertParseContext
*
pCxt
,
SToken
*
pStname
,
SArray
*
tableNameList
)
{
if
(
parserValidateIdToken
(
pStname
)
!=
TSDB_CODE_SUCCESS
)
{
return
build
InvalidOperationMsg
(
&
pCxt
->
msg
,
"invalid table name"
);
return
build
SyntaxErrMsg
(
&
pCxt
->
msg
,
"invalid table name"
,
pStname
->
z
);
}
SName
name
=
{
0
};
strndequote
(
name
.
tname
,
pStname
->
z
,
pStname
->
n
);
strcpy
(
name
.
dbname
,
pCxt
->
pComCxt
->
pDbname
);
strncpy
(
name
.
tname
,
pStname
->
z
,
pStname
->
n
);
taosArrayPush
(
tableNameList
,
&
name
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -686,7 +687,6 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks,
// 1. set the parsed value from sql string
for
(
int
i
=
0
;
i
<
spd
->
numOfBound
;
++
i
)
{
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
// todo bind param
SSchema
*
pSchema
=
&
schema
[
spd
->
boundedColumns
[
i
]];
param
.
schema
=
pSchema
;
param
.
compareStat
=
pBuilder
->
compareStat
;
...
...
@@ -770,14 +770,6 @@ static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* da
int32_t
numOfRows
=
0
;
CHECK_CODE
(
parseValues
(
pCxt
,
dataBuf
,
maxNumOfRows
,
&
numOfRows
));
for
(
uint32_t
i
=
0
;
i
<
dataBuf
->
numOfParams
;
++
i
)
{
SParamInfo
*
param
=
dataBuf
->
params
+
i
;
if
(
param
->
idx
==
-
1
)
{
// param->idx = pInsertParam->numOfParams++;
param
->
offset
-=
sizeof
(
SSubmitBlk
);
}
}
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)(
dataBuf
->
pData
);
if
(
TSDB_CODE_SUCCESS
!=
setBlockInfo
(
pBlocks
,
dataBuf
->
pTableMeta
,
numOfRows
))
{
return
buildInvalidOperationMsg
(
&
pCxt
->
msg
,
"too many rows in sql, total number of rows should be less than 32767"
);
...
...
@@ -815,12 +807,12 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
CHECK_CODE
(
parseUsingClause
(
pCxt
,
&
tbnameToken
));
NEXT_TOKEN
(
pCxt
->
pSql
,
sToken
);
}
else
{
CHECK_CODE
(
getTableMeta
(
pCxt
,
&
s
Token
));
CHECK_CODE
(
getTableMeta
(
pCxt
,
&
tbname
Token
));
}
STableDataBlocks
*
dataBuf
=
NULL
;
CHECK_CODE
(
getDataBlockFromList
(
pCxt
->
pTableBlockHashObj
,
pCxt
->
pTableMeta
->
uid
,
TSDB_DEFAULT_PAYLOAD_SIZE
,
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
NULL
/* tbname */
,
pCxt
->
pTableMeta
,
&
dataBuf
,
NULL
));
sizeof
(
SSubmitBlk
),
getTableInfo
(
pCxt
->
pTableMeta
).
rowSize
,
pCxt
->
pTableMeta
,
&
dataBuf
,
NULL
));
if
(
TK_LP
==
sToken
.
type
)
{
// pSql -> field1_name, ...)
...
...
@@ -831,6 +823,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
if
(
TK_VALUES
==
sToken
.
type
)
{
// pSql -> (field1_value, ...) [(field1_value2, ...) ...]
CHECK_CODE
(
parseValuesClause
(
pCxt
,
dataBuf
));
pCxt
->
pOutput
->
insertType
=
TSDB_QUERY_TYPE_INSERT
;
continue
;
}
...
...
@@ -842,6 +835,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
return
buildSyntaxErrMsg
(
&
pCxt
->
msg
,
"file path is required following keyword FILE"
,
sToken
.
z
);
}
// todo
pCxt
->
pOutput
->
insertType
=
TSDB_QUERY_TYPE_FILE_INSERT
;
continue
;
}
...
...
source/libs/parser/test/insertTest.cpp
浏览文件 @
0a9eb233
...
...
@@ -36,51 +36,67 @@ namespace {
// [...];
class
InsertTest
:
public
Test
{
protected:
void
setDatabase
(
const
string
&
db
)
{
db_
=
db
;
}
void
bind
(
const
char
*
sql
)
{
reset
();
cxt
.
pSql
=
sql
;
cxt
.
sqlLen
=
strlen
(
sql
);
cxt_
.
sqlLen
=
strlen
(
sql
);
strcpy
(
sqlBuf_
,
sql
);
sqlBuf_
[
cxt_
.
sqlLen
]
=
'\0'
;
cxt_
.
pSql
=
sqlBuf_
;
cxt_
.
pDbname
=
db_
.
c_str
();
}
int32_t
run
()
{
code
=
parseInsertSql
(
&
cxt
,
&
res
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
cout
<<
"code:"
<<
toString
(
code
)
<<
", msg:"
<<
errMagBuf
<<
endl
;
code
_
=
parseInsertSql
(
&
cxt_
,
&
res_
);
if
(
code
_
!=
TSDB_CODE_SUCCESS
)
{
cout
<<
"code:"
<<
toString
(
code
_
)
<<
", msg:"
<<
errMagBuf_
<<
endl
;
}
return
code
;
return
code
_
;
}
SInsertStmtInfo
*
reslut
()
{
return
res
;
return
res
_
;
}
private:
static
const
int
max_err_len
=
1024
;
static
const
int
max_sql_len
=
1024
*
1024
;
void
reset
()
{
memset
(
&
cxt
,
0
,
sizeof
(
cxt
));
memset
(
errMagBuf
,
0
,
max_err_len
);
cxt
.
pMsg
=
errMagBuf
;
cxt
.
msgLen
=
max_err_len
;
code
=
TSDB_CODE_SUCCESS
;
res
=
nullptr
;
memset
(
&
cxt
_
,
0
,
sizeof
(
cxt_
));
memset
(
errMagBuf
_
,
0
,
max_err_len
);
cxt
_
.
pMsg
=
errMagBuf_
;
cxt
_
.
msgLen
=
max_err_len
;
code
_
=
TSDB_CODE_SUCCESS
;
res
_
=
nullptr
;
}
char
errMagBuf
[
max_err_len
];
SParseContext
cxt
;
int32_t
code
;
SInsertStmtInfo
*
res
;
string
db_
;
char
errMagBuf_
[
max_err_len
];
char
sqlBuf_
[
max_sql_len
];
SParseContext
cxt_
;
int32_t
code_
;
SInsertStmtInfo
*
res_
;
};
// INSERT INTO tb_name VALUES (field1_value, ...)
TEST_F
(
InsertTest
,
simpleTest
)
{
bind
(
"insert into .. values (...)"
);
setDatabase
(
"test"
);
bind
(
"insert into t1 values (now, 1,
\"
wxy
\"
)"
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
SInsertStmtInfo
*
res
=
reslut
();
// todo check
ASSERT_EQ
(
res
->
insertType
,
TSDB_QUERY_TYPE_INSERT
);
// ASSERT_EQ(taosArrayGetSize(res->pDataBlocks), 1);
}
TEST_F
(
InsertTest
,
toleranceTest
)
{
setDatabase
(
"test"
);
bind
(
"insert into"
);
ASSERT_NE
(
run
(),
TSDB_CODE_SUCCESS
);
bind
(
"insert into t"
);
...
...
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
0a9eb233
...
...
@@ -17,29 +17,30 @@
#include <iostream>
namespace
{
void
generateTestT1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
3
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
setVgid
(
1
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
).
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
10
);
builder
.
done
();
}
void
generateTestST1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
2
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addTag
(
"tag1"
,
TSDB_DATA_TYPE_INT
).
addTag
(
"tag2"
,
TSDB_DATA_TYPE_BINARY
,
10
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
).
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
10
);
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
}
}
void
generateMetaData
(
MockCatalogService
*
mcs
)
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
MockCatalogService
::
numOfDataTypes
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
setVgid
(
1
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
);
for
(
int32_t
i
=
0
;
i
<
MockCatalogService
::
numOfDataTypes
;
++
i
)
{
if
(
TSDB_DATA_TYPE_NULL
==
tDataTypes
[
i
].
type
)
{
continue
;
}
builder
=
builder
.
addColumn
(
"c"
+
std
::
to_string
(
i
+
1
),
tDataTypes
[
i
].
type
);
}
builder
.
done
();
}
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
MockCatalogService
::
numOfDataTypes
,
2
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
setVgid
(
2
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
);
for
(
int32_t
i
=
0
;
i
<
MockCatalogService
::
numOfDataTypes
;
++
i
)
{
if
(
TSDB_DATA_TYPE_NULL
==
tDataTypes
[
i
].
type
)
{
continue
;
}
builder
=
builder
.
addColumn
(
"c"
+
std
::
to_string
(
i
+
1
),
tDataTypes
[
i
].
type
);
}
builder
.
done
();
}
generateTestT1
(
mcs
);
generateTestST1
(
mcs
);
mcs
->
showTables
();
}
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
0a9eb233
...
...
@@ -19,6 +19,7 @@
#include <iostream>
#include <map>
#include "tname.h"
#include "ttypes.h"
std
::
unique_ptr
<
MockCatalogService
>
mockCatalogService
;
...
...
@@ -82,12 +83,26 @@ public:
MockCatalogServiceImpl
()
{
}
struct
SCatalog
*
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
)
{
struct
SCatalog
*
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
)
const
{
return
(
struct
SCatalog
*
)
0x01
;
}
int32_t
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
)
{
return
0
;
int32_t
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
)
const
{
assert
(
nullptr
!=
pMetaReq
&&
1
==
taosArrayGetSize
(
pMetaReq
->
pTableName
));
SName
*
fullName
=
(
SName
*
)
taosArrayGet
(
pMetaReq
->
pTableName
,
0
);
std
::
unique_ptr
<
STableMeta
>
table
;
int32_t
code
=
copyTableMeta
(
fullName
->
dbname
,
fullName
->
tname
,
&
table
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
std
::
unique_ptr
<
SArray
>
tables
((
SArray
*
)
taosArrayInit
(
1
,
sizeof
(
STableMeta
*
)));
if
(
!
tables
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
STableMeta
*
elem
=
table
.
release
();
taosArrayPush
(
tables
.
get
(),
&
elem
);
pMetaData
->
pTableMeta
=
tables
.
release
();
return
TSDB_CODE_SUCCESS
;
}
TableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
...
...
@@ -97,6 +112,15 @@ public:
return
*
(
builder_
.
get
());
}
void
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
)
{
std
::
unique_ptr
<
STableMeta
>
table
;
if
(
TSDB_CODE_SUCCESS
!=
copyTableMeta
(
db
,
stbname
,
&
table
))
{
throw
std
::
runtime_error
(
"copyTableMeta failed"
);
}
meta_
[
db
][
tbname
].
reset
(
table
.
release
());
meta_
[
db
][
tbname
]
->
uid
=
id_
++
;
}
void
showTables
()
const
{
// number of forward fills
#define NOF(n) ((n) / 2)
...
...
@@ -120,20 +144,35 @@ public:
#define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ')
for
(
const
auto
&
db
:
meta_
)
{
std
::
cout
<<
SH
(
"Database"
)
<<
SH
(
"Table"
)
<<
SH
(
"Type"
)
<<
SH
(
"Precision"
)
<<
IH
(
std
::
string
(
"Vgid"
))
<<
std
::
endl
;
std
::
cout
<<
SL
(
4
,
1
)
<<
std
::
endl
;
std
::
cout
<<
"Databse:"
<<
db
.
first
<<
std
::
endl
;
std
::
cout
<<
SH
(
"Table"
)
<<
SH
(
"Type"
)
<<
SH
(
"Precision"
)
<<
IH
(
"Vgid"
)
<<
std
::
endl
;
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
for
(
const
auto
&
table
:
db
.
second
)
{
std
::
cout
<<
SF
(
db
.
first
)
<<
SF
(
table
.
first
)
<<
SF
(
ttToString
(
table
.
second
->
tableType
))
<<
SF
(
pToString
(
table
.
second
->
tableInfo
.
precision
))
<<
IF
(
table
.
second
->
vgId
)
<<
std
::
endl
;
// int16_t numOfFields = table.second->tableInfo.numOfTags + table.second->tableInfo.numOfColumns;
// for (int16_t i = 0; i < numOfFields; ++i) {
// const SSchema* schema = table.second->schema + i;
// std::cout << schema->name << " " << schema->type << " " << schema->bytes << std::endl;
// }
std
::
cout
<<
SF
(
table
.
first
)
<<
SF
(
ttToString
(
table
.
second
->
tableType
))
<<
SF
(
pToString
(
table
.
second
->
tableInfo
.
precision
))
<<
IF
(
table
.
second
->
vgId
)
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
;
}
for
(
const
auto
&
db
:
meta_
)
{
for
(
const
auto
&
table
:
db
.
second
)
{
std
::
cout
<<
"Table:"
<<
table
.
first
<<
std
::
endl
;
std
::
cout
<<
SH
(
"Field"
)
<<
SH
(
"Type"
)
<<
SH
(
"DataType"
)
<<
IH
(
"Bytes"
)
<<
std
::
endl
;
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
int16_t
numOfTags
=
table
.
second
->
tableInfo
.
numOfTags
;
int16_t
numOfFields
=
numOfTags
+
table
.
second
->
tableInfo
.
numOfColumns
;
for
(
int16_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
const
SSchema
*
schema
=
table
.
second
->
schema
+
i
;
std
::
cout
<<
SF
(
std
::
string
(
schema
->
name
))
<<
SH
((
i
<
numOfTags
?
std
::
string
(
"tag"
)
:
std
::
string
(
"column"
)))
<<
SH
(
dtToString
(
schema
->
type
))
<<
IF
(
schema
->
bytes
)
<<
std
::
endl
;
}
std
::
cout
<<
std
::
endl
;
}
}
}
private:
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
STableMeta
>
>
TableMetaCache
;
typedef
std
::
map
<
std
::
string
,
TableMetaCache
>
DbMetaCache
;
std
::
string
ttToString
(
int8_t
tableType
)
const
{
switch
(
tableType
)
{
case
TSDB_SUPER_TABLE
:
...
...
@@ -160,9 +199,39 @@ private:
}
}
std
::
string
dtToString
(
int8_t
type
)
const
{
return
tDataTypes
[
type
].
name
;
}
std
::
shared_ptr
<
STableMeta
>
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
{
DbMetaCache
::
const_iterator
it
=
meta_
.
find
(
db
);
if
(
meta_
.
end
()
==
it
)
{
return
std
::
shared_ptr
<
STableMeta
>
();
}
TableMetaCache
::
const_iterator
tit
=
it
->
second
.
find
(
tbname
);
if
(
it
->
second
.
end
()
==
tit
)
{
return
std
::
shared_ptr
<
STableMeta
>
();
}
return
tit
->
second
;
}
int32_t
copyTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
std
::
unique_ptr
<
STableMeta
>*
dst
)
const
{
std
::
shared_ptr
<
STableMeta
>
src
=
getTableMeta
(
db
,
tbname
);
if
(
!
src
)
{
return
TSDB_CODE_TSC_INVALID_TABLE_NAME
;
}
int32_t
len
=
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
(
src
->
tableInfo
.
numOfTags
+
src
->
tableInfo
.
numOfColumns
);
dst
->
reset
((
STableMeta
*
)
std
::
calloc
(
1
,
len
));
if
(
!
dst
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
memcpy
(
dst
->
get
(),
src
.
get
(),
len
);
return
TSDB_CODE_SUCCESS
;
}
uint64_t
id_
;
std
::
unique_ptr
<
TableBuilder
>
builder_
;
std
::
map
<
std
::
string
,
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
STableMeta
>
>
>
meta_
;
DbMetaCache
meta_
;
};
MockCatalogService
::
MockCatalogService
()
:
impl_
(
new
MockCatalogServiceImpl
())
{
...
...
@@ -171,11 +240,11 @@ MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {
MockCatalogService
::~
MockCatalogService
()
{
}
struct
SCatalog
*
MockCatalogService
::
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
)
{
struct
SCatalog
*
MockCatalogService
::
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
)
const
{
return
impl_
->
getCatalogHandle
(
pMgmtEps
);
}
int32_t
MockCatalogService
::
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
)
{
int32_t
MockCatalogService
::
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
)
const
{
return
impl_
->
catalogGetMetaData
(
pCatalog
,
pMetaReq
,
pMetaData
);
}
...
...
@@ -183,6 +252,10 @@ ITableBuilder& MockCatalogService::createTableBuilder(const std::string& db, con
return
impl_
->
createTableBuilder
(
db
,
tbname
,
tableType
,
numOfColumns
,
numOfTags
);
}
void
MockCatalogService
::
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
)
{
impl_
->
createSubTable
(
db
,
stbname
,
tbname
,
vgid
);
}
void
MockCatalogService
::
showTables
()
const
{
impl_
->
showTables
();
}
\ No newline at end of file
source/libs/parser/test/mockCatalogService.h
浏览文件 @
0a9eb233
...
...
@@ -49,9 +49,10 @@ public:
MockCatalogService
();
~
MockCatalogService
();
struct
SCatalog
*
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
);
int32_t
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
);
struct
SCatalog
*
getCatalogHandle
(
const
SEpSet
*
pMgmtEps
)
const
;
int32_t
catalogGetMetaData
(
struct
SCatalog
*
pCatalog
,
const
SMetaReq
*
pMetaReq
,
SMetaData
*
pMetaData
)
const
;
ITableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
=
0
);
void
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
);
void
showTables
()
const
;
private:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录