Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
53928fff
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看板
提交
53928fff
编写于
12月 23, 2021
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-12450 ut of combination of insert parser and insert planner
上级
1ce9487f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
68 addition
and
15 deletion
+68
-15
include/libs/parser/parser.h
include/libs/parser/parser.h
+0
-1
source/libs/parser/src/insertParser.c
source/libs/parser/src/insertParser.c
+1
-0
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+4
-4
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+11
-3
source/libs/planner/test/phyPlanTests.cpp
source/libs/planner/test/phyPlanTests.cpp
+52
-7
未找到文件。
include/libs/parser/parser.h
浏览文件 @
53928fff
...
...
@@ -35,7 +35,6 @@ typedef struct SParseContext {
void
*
pRpc
;
struct
SCatalog
*
pCatalog
;
const
SEpSet
*
pEpSet
;
int64_t
id
;
// query id, generated by uuid generator
int8_t
schemaAttached
;
// denote if submit block is built with table schema or not
const
char
*
pSql
;
// sql string
size_t
sqlLen
;
// length of the sql string
...
...
source/libs/parser/src/insertParser.c
浏览文件 @
53928fff
...
...
@@ -909,6 +909,7 @@ int32_t parseInsertSql(SParseContext* pContext, SInsertStmtInfo** pInfo) {
}
*
pInfo
=
context
.
pOutput
;
context
.
pOutput
->
nodeType
=
TSDB_SQL_INSERT
;
context
.
pOutput
->
schemaAttache
=
pContext
->
schemaAttached
;
context
.
pOutput
->
payloadType
=
PAYLOAD_TYPE_KV
;
...
...
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
53928fff
...
...
@@ -23,20 +23,20 @@
namespace
{
void
generateTestT1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"
root.
test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
3
)
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
,
20
);
builder
.
done
();
}
void
generateTestST1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"
root.
test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
2
)
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
,
20
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
).
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
);
builder
.
done
();
mcs
->
createSubTable
(
"
root.
test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"
root.
test"
,
"st1"
,
"st1s2"
,
2
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
}
}
...
...
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
53928fff
...
...
@@ -94,9 +94,9 @@ public:
return
0
;
}
int32_t
catalogGetTableMeta
(
const
char
*
pD
B
Name
,
const
char
*
pTableName
,
STableMeta
**
pTableMeta
)
const
{
int32_t
catalogGetTableMeta
(
const
char
*
pD
bFull
Name
,
const
char
*
pTableName
,
STableMeta
**
pTableMeta
)
const
{
std
::
unique_ptr
<
STableMeta
>
table
;
int32_t
code
=
copyTableSchemaMeta
(
pDBName
,
pTableName
,
&
table
);
int32_t
code
=
copyTableSchemaMeta
(
toDbname
(
pDbFullName
)
,
pTableName
,
&
table
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
...
...
@@ -104,7 +104,7 @@ public:
return
TSDB_CODE_SUCCESS
;
}
int32_t
catalogGetTableHashVgroup
(
const
char
*
pD
B
Name
,
const
char
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
{
int32_t
catalogGetTableHashVgroup
(
const
char
*
pD
bFull
Name
,
const
char
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
{
// todo
return
0
;
}
...
...
@@ -195,6 +195,14 @@ private:
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
MockTableMeta
>>
TableMetaCache
;
typedef
std
::
map
<
std
::
string
,
TableMetaCache
>
DbMetaCache
;
std
::
string
toDbname
(
const
std
::
string
&
dbFullName
)
const
{
std
::
string
::
size_type
n
=
dbFullName
.
find
(
"."
);
if
(
n
==
std
::
string
::
npos
)
{
return
dbFullName
;
}
return
dbFullName
.
substr
(
n
+
1
);
}
std
::
string
ttToString
(
int8_t
tableType
)
const
{
switch
(
tableType
)
{
case
TSDB_SUPER_TABLE
:
...
...
source/libs/planner/test/phyPlanTests.cpp
浏览文件 @
53928fff
...
...
@@ -33,10 +33,6 @@ protected:
void
pushScan
(
const
string
&
db
,
const
string
&
table
,
int32_t
scanOp
)
{
shared_ptr
<
MockTableMeta
>
meta
=
mockCatalogService
->
getTableMeta
(
db
,
table
);
EXPECT_TRUE
(
meta
);
// typedef struct SQueryPlanNode {
// SArray *pExpr; // the query functions or sql aggregations
// int32_t numOfExpr; // number of result columns, which is also the number of pExprs
// } SQueryPlanNode;
unique_ptr
<
SQueryPlanNode
>
scan
((
SQueryPlanNode
*
)
calloc
(
1
,
sizeof
(
SQueryPlanNode
)));
scan
->
info
.
type
=
scanOp
;
scan
->
numOfCols
=
meta
->
schema
->
tableInfo
.
numOfColumns
;
...
...
@@ -54,6 +50,27 @@ protected:
return
code
;
}
int32_t
run
(
const
string
&
db
,
const
string
&
sql
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
SParseContext
cxt
;
buildParseContext
(
db
,
sql
,
&
cxt
);
SQueryNode
*
query
;
if
(
qIsInsertSql
(
cxt
.
pSql
,
cxt
.
sqlLen
))
{
code
=
qParseInsertSql
(
&
cxt
,
(
SInsertStmtInfo
**
)
&
query
);
}
else
{
// todo
code
=
TSDB_CODE_FAILED
;
}
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
cout
<<
"error no:"
<<
code
<<
", msg:"
<<
cxt
.
pMsg
<<
endl
;
return
code
;
}
SQueryDag
*
dag
=
nullptr
;
code
=
qCreateQueryDag
(
query
,
nullptr
,
&
dag
);
dag_
.
reset
(
dag
);
return
code
;
}
void
explain
()
{
size_t
level
=
taosArrayGetSize
(
dag_
->
pSubplans
);
for
(
size_t
i
=
0
;
i
<
level
;
++
i
)
{
...
...
@@ -64,7 +81,8 @@ protected:
std
::
cout
<<
"no "
<<
j
<<
":"
<<
std
::
endl
;
int32_t
len
=
0
;
char
*
str
=
nullptr
;
ASSERT_EQ
(
TSDB_CODE_SUCCESS
,
qSubPlanToString
((
const
SSubplan
*
)
taosArrayGetP
(
subplans
,
j
),
&
str
,
&
len
));
ASSERT_EQ
(
TSDB_CODE_SUCCESS
,
qSubPlanToString
((
const
SSubplan
*
)
taosArrayGetP
(
subplans
,
j
),
&
str
,
&
len
));
std
::
cout
<<
"len:"
<<
len
<<
std
::
endl
;
std
::
cout
<<
str
<<
std
::
endl
;
free
(
str
);
}
...
...
@@ -108,6 +126,25 @@ private:
return
info
;
}
void
buildParseContext
(
const
string
&
db
,
const
string
&
sql
,
SParseContext
*
pCxt
)
{
static
string
_db
;
static
string
_sql
;
static
const
int32_t
_msgMaxLen
=
4096
;
static
char
_msg
[
_msgMaxLen
];
_db
=
db
;
_sql
=
sql
;
memset
(
_msg
,
0
,
_msgMaxLen
);
pCxt
->
ctx
.
acctId
=
1
;
pCxt
->
ctx
.
db
=
_db
.
c_str
();
pCxt
->
ctx
.
requestId
=
1
;
pCxt
->
pSql
=
_sql
.
c_str
();
pCxt
->
sqlLen
=
_sql
.
length
();
pCxt
->
pMsg
=
_msg
;
pCxt
->
msgLen
=
_msgMaxLen
;
}
shared_ptr
<
MockTableMeta
>
meta_
;
unique_ptr
<
SQueryPlanNode
>
logicPlan_
;
unique_ptr
<
SQueryDag
>
dag_
;
...
...
@@ -115,7 +152,7 @@ private:
// select * from table
TEST_F
(
PhyPlanTest
,
tableScanTest
)
{
pushScan
(
"
root.
test"
,
"t1"
,
QNODE_TABLESCAN
);
pushScan
(
"test"
,
"t1"
,
QNODE_TABLESCAN
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
explain
();
SQueryDag
*
dag
=
reslut
();
...
...
@@ -124,9 +161,17 @@ TEST_F(PhyPlanTest, tableScanTest) {
// select * from supertable
TEST_F
(
PhyPlanTest
,
superTableScanTest
)
{
pushScan
(
"
root.
test"
,
"st1"
,
QNODE_TABLESCAN
);
pushScan
(
"test"
,
"st1"
,
QNODE_TABLESCAN
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
explain
();
SQueryDag
*
dag
=
reslut
();
// todo check
}
// insert into t values(...)
TEST_F
(
PhyPlanTest
,
insertTest
)
{
ASSERT_EQ
(
run
(
"test"
,
"insert into t1 values (now, 1,
\"
beijing
\"
)"
),
TSDB_CODE_SUCCESS
);
explain
();
SQueryDag
*
dag
=
reslut
();
// todo check
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录