Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
3d7051b9
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
提交
3d7051b9
编写于
7月 02, 2022
作者:
羽飞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
select is done
上级
263a6e3e
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
296 addition
and
11 deletion
+296
-11
src/observer/sql/executor/delete_operator.h
src/observer/sql/executor/delete_operator.h
+9
-0
src/observer/sql/executor/execute_stage.cpp
src/observer/sql/executor/execute_stage.cpp
+33
-5
src/observer/sql/executor/operator.h
src/observer/sql/executor/operator.h
+4
-0
src/observer/sql/executor/predicate_operator.cpp
src/observer/sql/executor/predicate_operator.cpp
+10
-1
src/observer/sql/executor/predicate_operator.h
src/observer/sql/executor/predicate_operator.h
+2
-0
src/observer/sql/executor/project_operator.cpp
src/observer/sql/executor/project_operator.cpp
+62
-0
src/observer/sql/executor/project_operator.h
src/observer/sql/executor/project_operator.h
+44
-0
src/observer/sql/executor/table_scan_operator.cpp
src/observer/sql/executor/table_scan_operator.cpp
+4
-0
src/observer/sql/executor/table_scan_operator.h
src/observer/sql/executor/table_scan_operator.h
+7
-0
src/observer/sql/executor/tuple.h
src/observer/sql/executor/tuple.h
+119
-4
src/observer/sql/stmt/select_stmt.h
src/observer/sql/stmt/select_stmt.h
+2
-1
未找到文件。
src/observer/sql/executor/delete_operator.h
浏览文件 @
3d7051b9
...
...
@@ -35,6 +35,15 @@ public:
Tuple
*
current_tuple
()
override
{
return
nullptr
;
}
int
tuple_cell_num
()
const
override
{
return
0
;
}
RC
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
{
return
RC
::
NOTFOUND
;
}
private:
DeleteStmt
*
delete_stmt_
=
nullptr
;
};
src/observer/sql/executor/execute_stage.cpp
浏览文件 @
3d7051b9
...
...
@@ -29,6 +29,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/executor/table_scan_operator.h"
#include "sql/executor/predicate_operator.h"
#include "sql/executor/delete_operator.h"
#include "sql/executor/project_operator.h"
#include "sql/stmt/stmt.h"
#include "sql/stmt/select_stmt.h"
#include "sql/stmt/update_stmt.h"
...
...
@@ -216,6 +217,25 @@ void end_trx_if_need(Session *session, Trx *trx, bool all_right)
}
}
void
print_tuple_header
(
std
::
ostream
&
os
,
const
Operator
&
oper
)
{
const
int
cell_num
=
oper
.
tuple_cell_num
();
TupleCellSpec
cell_spec
;
for
(
int
i
=
0
;
i
<
cell_num
;
i
++
)
{
oper
.
tuple_cell_spec_at
(
i
,
cell_spec
);
if
(
i
!=
0
)
{
os
<<
" | "
;
}
if
(
cell_spec
.
alias
())
{
os
<<
cell_spec
.
alias
();
}
}
if
(
cell_num
>
0
)
{
os
<<
'\n'
;
}
}
void
tuple_to_string
(
std
::
ostream
&
os
,
const
Tuple
&
tuple
)
{
TupleCell
cell
;
...
...
@@ -249,17 +269,25 @@ RC ExecuteStage::do_select(SQLStageEvent *sql_event)
Table
*
table
=
select_stmt
->
tables
().
front
();
TableScanOperator
table_scan_operator
(
table
);
rc
=
table_scan_operator
.
open
();
PredicateOperator
pred_oper
(
select_stmt
->
filter_stmt
());
pred_oper
.
add_child
(
&
table_scan_operator
);
ProjectOperator
project_oper
;
project_oper
.
add_child
(
&
pred_oper
);
for
(
const
FieldDesc
&
field
:
select_stmt
->
query_fields
())
{
project_oper
.
add_projection
(
field
.
table_
,
field
.
field_meta_
);
}
rc
=
project_oper
.
open
();
if
(
rc
!=
RC
::
SUCCESS
)
{
LOG_WARN
(
"failed to open operator"
);
return
rc
;
}
std
::
stringstream
ss
;
while
((
rc
=
table_scan_operator
.
next
())
==
RC
::
SUCCESS
)
{
print_tuple_header
(
ss
,
project_oper
);
while
((
rc
=
project_oper
.
next
())
==
RC
::
SUCCESS
)
{
// get current record
// write to response
Tuple
*
tuple
=
table_scan_operato
r
.
current_tuple
();
Tuple
*
tuple
=
project_ope
r
.
current_tuple
();
if
(
nullptr
==
tuple
)
{
rc
=
RC
::
INTERNAL
;
LOG_WARN
(
"failed to get current record. rc=%s"
,
strrc
(
rc
));
...
...
@@ -272,9 +300,9 @@ RC ExecuteStage::do_select(SQLStageEvent *sql_event)
if
(
rc
!=
RC
::
RECORD_EOF
)
{
LOG_WARN
(
"something wrong while iterate operator. rc=%s"
,
strrc
(
rc
));
table_scan_operato
r
.
close
();
project_ope
r
.
close
();
}
else
{
rc
=
table_scan_operato
r
.
close
();
rc
=
project_ope
r
.
close
();
}
session_event
->
set_response
(
ss
.
str
());
return
rc
;
...
...
src/observer/sql/executor/operator.h
浏览文件 @
3d7051b9
...
...
@@ -19,6 +19,7 @@ See the Mulan PSL v2 for more details. */
#include "sql/executor/tuple.h"
class
Record
;
class
TupleCellSpec
;
class
Operator
{
...
...
@@ -33,11 +34,14 @@ public:
virtual
RC
close
()
=
0
;
virtual
Tuple
*
current_tuple
()
=
0
;
virtual
int
tuple_cell_num
()
const
=
0
;
virtual
RC
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
=
0
;
void
add_child
(
Operator
*
oper
)
{
children_
.
push_back
(
oper
);
}
protected:
std
::
vector
<
Operator
*>
children_
;
};
src/observer/sql/executor/predicate_operator.cpp
浏览文件 @
3d7051b9
...
...
@@ -74,7 +74,7 @@ void get_cell(const RowTuple &tuple, const FilterItem &filter_item, TupleCell &c
bool
PredicateOperator
::
do_predicate
(
RowTuple
&
tuple
)
{
if
(
filter_stmt_
==
nullptr
)
{
if
(
filter_stmt_
==
nullptr
||
filter_stmt_
->
filter_units
().
empty
()
)
{
return
true
;
}
...
...
@@ -102,3 +102,12 @@ bool PredicateOperator::do_predicate(RowTuple &tuple)
}
return
false
;
}
int
PredicateOperator
::
tuple_cell_num
()
const
{
return
children_
[
0
]
->
tuple_cell_num
();
}
RC
PredicateOperator
::
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
{
return
children_
[
0
]
->
tuple_cell_spec_at
(
index
,
spec
);
}
src/observer/sql/executor/predicate_operator.h
浏览文件 @
3d7051b9
...
...
@@ -31,6 +31,8 @@ public:
RC
close
()
override
;
Tuple
*
current_tuple
()
override
;
int
tuple_cell_num
()
const
override
;
RC
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
;
private:
bool
do_predicate
(
RowTuple
&
tuple
);
private:
...
...
src/observer/sql/executor/project_operator.cpp
0 → 100644
浏览文件 @
3d7051b9
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */
//
// Created by WangYunlai on 2022/07/01.
//
#include "common/log/log.h"
#include "sql/executor/project_operator.h"
#include "storage/common/record.h"
#include "storage/common/table.h"
RC
ProjectOperator
::
open
()
{
if
(
children_
.
size
()
!=
1
)
{
LOG_WARN
(
"project operator must has 1 child"
);
return
RC
::
INTERNAL
;
}
Operator
*
child
=
children_
[
0
];
RC
rc
=
child
->
open
();
if
(
rc
!=
RC
::
SUCCESS
)
{
LOG_WARN
(
"failed to open child operator: %s"
,
strrc
(
rc
));
return
rc
;
}
return
RC
::
SUCCESS
;
}
RC
ProjectOperator
::
next
()
{
return
children_
[
0
]
->
next
();
}
RC
ProjectOperator
::
close
()
{
children_
[
0
]
->
close
();
return
RC
::
SUCCESS
;
}
Tuple
*
ProjectOperator
::
current_tuple
()
{
tuple_
.
set_tuple
(
children_
[
0
]
->
current_tuple
());
return
&
tuple_
;
}
void
ProjectOperator
::
add_projection
(
const
Table
*
table
,
const
FieldMeta
*
field_meta
)
{
TupleCellSpec
spec
(
table
->
name
(),
field_meta
->
name
(),
field_meta
->
name
());
tuple_
.
add_cell_spec
(
spec
);
}
RC
ProjectOperator
::
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
{
return
tuple_
.
cell_spec_at
(
index
,
spec
);
}
src/observer/sql/executor/project_operator.h
0 → 100644
浏览文件 @
3d7051b9
/* Copyright (c) 2021 Xie Meiyi(xiemeiyi@hust.edu.cn) and OceanBase and/or its affiliates. All rights reserved.
miniob is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details. */
//
// Created by WangYunlai on 2022/07/01.
//
#pragma once
#include "sql/executor/operator.h"
#include "rc.h"
class
ProjectOperator
:
public
Operator
{
public:
ProjectOperator
()
{}
virtual
~
ProjectOperator
()
=
default
;
void
add_projection
(
const
Table
*
table
,
const
FieldMeta
*
field
);
// TODO how to handle the memory in tupleCellSpec?
RC
open
()
override
;
RC
next
()
override
;
RC
close
()
override
;
int
tuple_cell_num
()
const
override
{
return
tuple_
.
cell_num
();
}
RC
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
;
Tuple
*
current_tuple
()
override
;
private:
ProjectTuple
tuple_
;
};
src/observer/sql/executor/table_scan_operator.cpp
浏览文件 @
3d7051b9
...
...
@@ -47,3 +47,7 @@ Tuple * TableScanOperator::current_tuple()
tuple_
.
set_record
(
&
current_record_
);
return
&
tuple_
;
}
RC
TableScanOperator
::
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
{
return
tuple_
.
cell_spec_at
(
index
,
spec
);
}
src/observer/sql/executor/table_scan_operator.h
浏览文件 @
3d7051b9
...
...
@@ -36,6 +36,13 @@ public:
RC
close
()
override
;
Tuple
*
current_tuple
()
override
;
int
tuple_cell_num
()
const
override
{
return
tuple_
.
cell_num
();
}
RC
tuple_cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
;
private:
Table
*
table_
=
nullptr
;
RecordFileScanner
record_scanner_
;
...
...
src/observer/sql/executor/tuple.h
浏览文件 @
3d7051b9
...
...
@@ -27,7 +27,50 @@ class Table;
class
TupleCellSpec
{
public:
TupleCellSpec
()
=
default
;
TupleCellSpec
(
const
char
*
table_name
,
const
char
*
field_name
,
const
char
*
alias
)
:
table_name_
(
table_name
),
field_name_
(
field_name
),
alias_
(
alias
)
{}
void
set_table_name
(
const
char
*
table_name
)
{
this
->
table_name_
=
table_name
;
}
void
set_field_name
(
const
char
*
field_name
)
{
this
->
field_name_
=
field_name
;
}
void
set_alias
(
const
char
*
alias
)
{
this
->
alias_
=
alias
;
}
const
char
*
table_name
()
const
{
return
table_name_
;
}
const
char
*
field_name
()
const
{
return
field_name_
;
}
const
char
*
alias
()
const
{
return
alias_
;
}
bool
is_same_cell
(
const
TupleCellSpec
&
other
)
const
{
return
0
==
strcmp
(
this
->
table_name_
,
other
.
table_name_
)
&&
0
==
strcmp
(
this
->
field_name_
,
other
.
field_name_
);
}
private:
// TODO table and field cannot describe all scenerio, should be expression
const
char
*
table_name_
=
nullptr
;
const
char
*
field_name_
=
nullptr
;
const
char
*
alias_
=
nullptr
;
};
class
Tuple
...
...
@@ -38,8 +81,9 @@ public:
virtual
int
cell_num
()
const
=
0
;
virtual
RC
cell_at
(
int
index
,
TupleCell
&
cell
)
const
=
0
;
virtual
RC
find_cell
(
const
TupleCellSpec
&
spec
,
TupleCell
&
cell
)
const
=
0
;
//virtual RC cell_spec_at(int index, TupleCellSpec &spec) const
;
virtual
RC
cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
=
0
;
};
class
RowTuple
:
public
Tuple
...
...
@@ -82,14 +126,33 @@ public:
return
RC
::
SUCCESS
;
}
RC
cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
RC
find_cell
(
const
TupleCellSpec
&
spec
,
TupleCell
&
cell
)
const
override
{
const
char
*
table_name
=
spec
.
table_name
();
if
(
0
!=
strcmp
(
table_name
,
table_
->
name
()))
{
return
RC
::
NOTFOUND
;
}
const
char
*
field_name
=
spec
.
field_name
();
for
(
int
i
=
0
;
i
<
fields_
->
size
();
++
i
)
{
const
FieldMeta
&
field_meta
=
(
*
fields_
)[
i
];
if
(
0
==
strcmp
(
field_name
,
field_meta
.
name
()))
{
return
cell_at
(
i
,
cell
);
}
}
return
RC
::
NOTFOUND
;
}
RC
cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
{
if
(
index
<
0
||
index
>=
fields_
->
size
())
{
LOG_WARN
(
"invalid argument. index=%d"
,
index
);
return
RC
::
INVALID_ARGUMENT
;
}
const
FieldMeta
&
field_meta
=
(
*
fields_
)[
index
];
// TODO
spec
.
set_table_name
(
table_
->
name
());
spec
.
set_field_name
(
field_meta
.
name
());
spec
.
set_alias
(
field_meta
.
name
());
return
RC
::
SUCCESS
;
}
...
...
@@ -112,7 +175,59 @@ private:
class CompositeTuple : public Tuple
{
public:
int cell_num() const override;
RC cell_at(int index, TupleCell &cell) const = 0;
private:
int cell_num_ = 0;
std::vector<Tuple *> tuples_;
};
*/
class
ProjectTuple
:
public
Tuple
{
public:
ProjectTuple
()
=
default
;
void
set_tuple
(
Tuple
*
tuple
)
{
this
->
tuple_
=
tuple
;
}
void
add_cell_spec
(
const
TupleCellSpec
&
spec
)
{
speces_
.
push_back
(
spec
);
}
int
cell_num
()
const
override
{
return
speces_
.
size
();
}
RC
cell_at
(
int
index
,
TupleCell
&
cell
)
const
override
{
if
(
index
<
0
||
index
>=
speces_
.
size
())
{
return
RC
::
GENERIC_ERROR
;
}
if
(
tuple_
==
nullptr
)
{
return
RC
::
GENERIC_ERROR
;
}
const
TupleCellSpec
&
spec
=
speces_
[
index
];
// TODO better: add mapping between projection and raw tuple
return
tuple_
->
find_cell
(
spec
,
cell
);
}
RC
find_cell
(
const
TupleCellSpec
&
spec
,
TupleCell
&
cell
)
const
override
{
return
tuple_
->
find_cell
(
spec
,
cell
);
}
RC
cell_spec_at
(
int
index
,
TupleCellSpec
&
spec
)
const
override
{
if
(
index
<
0
||
index
>=
speces_
.
size
())
{
return
RC
::
NOTFOUND
;
}
spec
=
speces_
[
index
];
return
RC
::
SUCCESS
;
}
private:
std
::
vector
<
TupleCellSpec
>
speces_
;
Tuple
*
tuple_
=
nullptr
;
};
src/observer/sql/stmt/select_stmt.h
浏览文件 @
3d7051b9
...
...
@@ -24,7 +24,7 @@ class FilterStmt;
class
Db
;
class
Table
;
// better to create a field class
//
TODO
better to create a field class
struct
FieldDesc
{
Table
*
table_
=
nullptr
;
...
...
@@ -47,6 +47,7 @@ public:
public:
const
std
::
vector
<
Table
*>
&
tables
()
const
{
return
tables_
;
}
const
std
::
vector
<
FieldDesc
>
&
query_fields
()
const
{
return
query_fields_
;
}
FilterStmt
*
filter_stmt
()
const
{
return
filter_stmt_
;
}
private:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录