Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
oceanbase
miniob
提交
ab89b1d5
M
miniob
项目概览
oceanbase
/
miniob
1 年多 前同步成功
通知
74
Star
1521
Fork
537
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
M
miniob
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
提交
ab89b1d5
编写于
1月 28, 2023
作者:
L
Longda Feng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename parser's result command from Query to Command
上级
3653849b
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
550 addition
and
480 deletion
+550
-480
deps/common/lang/string.cpp
deps/common/lang/string.cpp
+20
-0
deps/common/lang/string.h
deps/common/lang/string.h
+13
-2
src/observer/event/sql_event.h
src/observer/event/sql_event.h
+4
-4
src/observer/sql/executor/execute_stage.cpp
src/observer/sql/executor/execute_stage.cpp
+174
-122
src/observer/sql/parser/parse.cpp
src/observer/sql/parser/parse.cpp
+4
-4
src/observer/sql/parser/parse_defs.h
src/observer/sql/parser/parse_defs.h
+9
-8
src/observer/sql/parser/parse_stage.cpp
src/observer/sql/parser/parse_stage.cpp
+3
-3
src/observer/sql/parser/resolve_stage.cpp
src/observer/sql/parser/resolve_stage.cpp
+2
-2
src/observer/sql/parser/yacc_sql.cpp
src/observer/sql/parser/yacc_sql.cpp
+245
-251
src/observer/sql/parser/yacc_sql.hpp
src/observer/sql/parser/yacc_sql.hpp
+2
-2
src/observer/sql/parser/yacc_sql.y
src/observer/sql/parser/yacc_sql.y
+60
-68
src/observer/sql/stmt/explain_stmt.cpp
src/observer/sql/stmt/explain_stmt.cpp
+1
-1
src/observer/sql/stmt/stmt.cpp
src/observer/sql/stmt/stmt.cpp
+7
-7
src/observer/sql/stmt/stmt.h
src/observer/sql/stmt/stmt.h
+1
-1
src/observer/storage/default/default_storage_stage.cpp
src/observer/storage/default/default_storage_stage.cpp
+5
-5
未找到文件。
deps/common/lang/string.cpp
浏览文件 @
ab89b1d5
...
...
@@ -245,4 +245,24 @@ bool is_blank(const char *s)
return
true
;
}
/**
* 获取子串
* 从s中提取下标为n1~n2的字符组成一个新字符串,然后返回这个新串的首地址
*
* @param s
* @param n1
* @param n2
* @return
*/
char
*
substr
(
const
char
*
s
,
int
n1
,
int
n2
)
{
char
*
sp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
n2
-
n1
+
2
));
int
i
,
j
=
0
;
for
(
i
=
n1
;
i
<=
n2
;
i
++
)
{
sp
[
j
++
]
=
s
[
i
];
}
sp
[
j
]
=
0
;
return
sp
;
}
}
// namespace common
deps/common/lang/string.h
浏览文件 @
ab89b1d5
...
...
@@ -112,6 +112,19 @@ bool str_to_val(const std::string &str, T &val, std::ios_base &(*radix)(std::ios
template
<
class
T
>
void
val_to_str
(
const
T
&
val
,
std
::
string
&
str
,
std
::
ios_base
&
(
*
radix
)(
std
::
ios_base
&
)
=
std
::
dec
);
bool
is_blank
(
const
char
*
s
);
/**
* 获取子串
* 从s中提取下标为n1~n2的字符组成一个新字符串,然后返回这个新串的首地址
*
* @param s
* @param n1
* @param n2
* @return
*/
char
*
substr
(
const
char
*
s
,
int
n1
,
int
n2
);
/**
* get type's name
*/
...
...
@@ -152,7 +165,5 @@ std::string get_type_name(const T &val)
return
sret
;
}
bool
is_blank
(
const
char
*
s
);
}
// namespace common
#endif // __COMMON_LANG_STRING_H__
src/observer/event/sql_event.h
浏览文件 @
ab89b1d5
...
...
@@ -21,7 +21,7 @@ See the Mulan PSL v2 for more details. */
class
SessionEvent
;
class
Stmt
;
class
Query
;
class
Command
;
class
SQLStageEvent
:
public
common
::
StageEvent
{
...
...
@@ -35,20 +35,20 @@ public:
}
const
std
::
string
&
sql
()
const
{
return
sql_
;
}
const
std
::
unique_ptr
<
Query
>
&
query
()
const
{
return
query
_
;
}
const
std
::
unique_ptr
<
Command
>
&
command
()
const
{
return
command
_
;
}
Stmt
*
stmt
()
const
{
return
stmt_
;
}
std
::
unique_ptr
<
PhysicalOperator
>
&
physical_operator
()
{
return
operator_
;
}
const
std
::
unique_ptr
<
PhysicalOperator
>
&
physical_operator
()
const
{
return
operator_
;
}
void
set_sql
(
const
char
*
sql
)
{
sql_
=
sql
;
}
void
set_
query
(
std
::
unique_ptr
<
Query
>
query
)
{
query_
=
std
::
move
(
query
);
}
void
set_
command
(
std
::
unique_ptr
<
Command
>
cmd
)
{
command_
=
std
::
move
(
cmd
);
}
void
set_stmt
(
Stmt
*
stmt
)
{
stmt_
=
stmt
;
}
void
set_operator
(
std
::
unique_ptr
<
PhysicalOperator
>
oper
)
{
operator_
=
std
::
move
(
oper
);
}
private:
SessionEvent
*
session_event_
=
nullptr
;
std
::
string
sql_
;
std
::
unique_ptr
<
Query
>
query
_
;
std
::
unique_ptr
<
Command
>
command
_
;
Stmt
*
stmt_
=
nullptr
;
std
::
unique_ptr
<
PhysicalOperator
>
operator_
;
};
...
...
src/observer/sql/executor/execute_stage.cpp
浏览文件 @
ab89b1d5
...
...
@@ -127,99 +127,109 @@ void ExecuteStage::callback_event(StageEvent *event, CallbackContext *context)
RC
ExecuteStage
::
handle_request
(
common
::
StageEvent
*
event
)
{
SQLStageEvent
*
sql_event
=
static_cast
<
SQLStageEvent
*>
(
event
);
SessionEvent
*
session_event
=
sql_event
->
session_event
();
const
std
::
unique_ptr
<
PhysicalOperator
>
&
physical_operator
=
sql_event
->
physical_operator
();
Stmt
*
stmt
=
sql_event
->
stmt
();
Session
*
session
=
session_event
->
session
();
Query
*
sql
=
sql_event
->
query
().
get
();
const
std
::
unique_ptr
<
PhysicalOperator
>
&
physical_operator
=
sql_event
->
physical_operator
();
if
(
physical_operator
!=
nullptr
)
{
return
handle_request_with_physical_operator
(
sql_event
);
}
SessionEvent
*
session_event
=
sql_event
->
session_event
();
Session
*
session
=
session_event
->
session
();
Command
*
sql
=
sql_event
->
command
().
get
();
Stmt
*
stmt
=
sql_event
->
stmt
();
if
(
stmt
!=
nullptr
)
{
switch
(
stmt
->
type
())
{
case
StmtType
::
INSERT
:
{
do_insert
(
sql_event
);
}
break
;
case
StmtType
::
UPDATE
:
{
//
do_update((UpdateStmt *)stmt, session_event);
}
break
;
case
StmtType
::
DELETE
:
{
do_delete
(
sql_event
);
}
break
;
default:
{
LOG_WARN
(
"should not happen. please implenment"
);
}
break
;
case
StmtType
::
INSERT
:
{
do_insert
(
sql_event
);
}
break
;
case
StmtType
::
UPDATE
:
{
//
do_update((UpdateStmt *)stmt, session_event);
}
break
;
case
StmtType
::
DELETE
:
{
do_delete
(
sql_event
);
}
break
;
default:
{
LOG_WARN
(
"should not happen. please implement this type:%d"
,
stmt
->
type
()
);
}
break
;
}
}
else
{
switch
(
sql
->
flag
)
{
case
SCF_HELP
:
{
do_help
(
sql_event
);
}
break
;
case
SCF_CREATE_TABLE
:
{
do_create_table
(
sql_event
);
}
break
;
case
SCF_CREATE_INDEX
:
{
do_create_index
(
sql_event
);
}
break
;
case
SCF_SHOW_TABLES
:
{
do_show_tables
(
sql_event
);
}
break
;
case
SCF_DESC_TABLE
:
{
do_desc_table
(
sql_event
);
}
break
;
case
SCF_HELP
:
{
do_help
(
sql_event
);
}
break
;
case
SCF_CREATE_TABLE
:
{
do_create_table
(
sql_event
);
}
break
;
case
SCF_CREATE_INDEX
:
{
do_create_index
(
sql_event
);
}
break
;
case
SCF_SHOW_TABLES
:
{
do_show_tables
(
sql_event
);
}
break
;
case
SCF_DESC_TABLE
:
{
do_desc_table
(
sql_event
);
}
break
;
case
SCF_DROP_TABLE
:
case
SCF_DROP_INDEX
:
case
SCF_LOAD_DATA
:
{
default_storage_stage_
->
handle_event
(
event
);
}
break
;
case
SCF_SYNC
:
{
/*
RC rc = DefaultHandler::get_default().sync();
session_event->set_response(strrc(rc));
*/
}
break
;
case
SCF_BEGIN
:
{
do_begin
(
sql_event
);
/*
session_event->set_response("SUCCESS\n");
*/
}
break
;
case
SCF_COMMIT
:
{
do_commit
(
sql_event
);
/*
Trx *trx = session->current_trx();
RC rc = trx->commit();
session->set_trx_multi_operation_mode(false);
session_event->set_response(strrc(rc));
*/
}
break
;
case
SCF_CLOG_SYNC
:
{
do_clog_sync
(
sql_event
);
}
case
SCF_ROLLBACK
:
{
Trx
*
trx
=
session_event
->
session
()
->
current_trx
();
case
SCF_DROP_TABLE
:
case
SCF_DROP_INDEX
:
case
SCF_LOAD_DATA
:
{
default_storage_stage_
->
handle_event
(
event
);
}
break
;
case
SCF_SYNC
:
{
/*
RC rc = DefaultHandler::get_default().sync();
session_event->set_response(strrc(rc));
*/
}
break
;
case
SCF_BEGIN
:
{
do_begin
(
sql_event
);
/*
session_event->set_response("SUCCESS\n");
*/
}
break
;
case
SCF_COMMIT
:
{
do_commit
(
sql_event
);
/*
Trx *trx = session->current_trx();
RC rc = trx->commit();
session->set_trx_multi_operation_mode(false);
session_event->set_response(strrc(rc));
*/
}
break
;
case
SCF_CLOG_SYNC
:
{
do_clog_sync
(
sql_event
);
}
case
SCF_ROLLBACK
:
{
Trx
*
trx
=
session_event
->
session
()
->
current_trx
();
RC
rc
=
trx
->
rollback
();
session
->
set_trx_multi_operation_mode
(
false
);
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
rc
);
session_event
->
set_sql_result
(
sql_result
);
}
break
;
case
SCF_EXIT
:
{
// do nothing
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
RC
::
SUCCESS
);
session_event
->
set_sql_result
(
sql_result
);
}
break
;
default:
{
LOG_ERROR
(
"Unsupported command=%d
\n
"
,
sql
->
flag
);
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
RC
::
UNIMPLENMENT
);
sql_result
->
set_state_string
(
"Unsupported command"
);
session_event
->
set_sql_result
(
sql_result
);
}
RC
rc
=
trx
->
rollback
();
session
->
set_trx_multi_operation_mode
(
false
);
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
rc
);
session_event
->
set_sql_result
(
sql_result
);
}
break
;
case
SCF_EXIT
:
{
// do nothing
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
RC
::
SUCCESS
);
session_event
->
set_sql_result
(
sql_result
);
}
break
;
default:
{
LOG_ERROR
(
"Unsupported command=%d
\n
"
,
sql
->
flag
);
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
RC
::
UNIMPLENMENT
);
sql_result
->
set_state_string
(
"Unsupported command"
);
session_event
->
set_sql_result
(
sql_result
);
}
}
}
return
RC
::
SUCCESS
;
...
...
@@ -228,17 +238,19 @@ RC ExecuteStage::handle_request(common::StageEvent *event)
RC
ExecuteStage
::
handle_request_with_physical_operator
(
SQLStageEvent
*
sql_event
)
{
RC
rc
=
RC
::
SUCCESS
;
Stmt
*
stmt
=
sql_event
->
stmt
();
ASSERT
(
stmt
!=
nullptr
,
"SQL Statement shouldn't be empty!"
);
std
::
unique_ptr
<
PhysicalOperator
>
&
physical_operator
=
sql_event
->
physical_operator
();
ASSERT
(
physical_operator
!=
nullptr
,
"physical operator should not be null"
);
TupleSchema
schema
;
switch
(
stmt
->
type
())
{
case
StmtType
::
SELECT
:
{
SelectStmt
*
select_stmt
=
static_cast
<
SelectStmt
*>
(
stmt
);
bool
with_table_name
=
select_stmt
->
tables
().
size
()
>
1
;
for
(
const
Field
&
field
:
select_stmt
->
query_fields
())
{
if
(
with_table_name
)
{
schema
.
append_cell
(
field
.
table_name
(),
field
.
field_name
());
...
...
@@ -255,9 +267,11 @@ RC ExecuteStage::handle_request_with_physical_operator(SQLStageEvent *sql_event)
// 只有select返回结果
}
break
;
}
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_tuple_schema
(
schema
);
sql_result
->
set_operator
(
std
::
move
(
physical_operator
));
sql_event
->
session_event
()
->
set_sql_result
(
sql_result
);
return
rc
;
}
...
...
@@ -275,9 +289,10 @@ void end_trx_if_need(Session *session, Trx *trx, bool all_right)
void
tuple_to_string
(
std
::
ostream
&
os
,
const
Tuple
&
tuple
)
{
TupleCell
cell
;
RC
rc
=
RC
::
SUCCESS
;
bool
first_field
=
true
;
TupleCell
cell
;
for
(
int
i
=
0
;
i
<
tuple
.
cell_num
();
i
++
)
{
rc
=
tuple
.
cell_at
(
i
,
cell
);
if
(
rc
!=
RC
::
SUCCESS
)
{
...
...
@@ -293,6 +308,7 @@ void tuple_to_string(std::ostream &os, const Tuple &tuple)
cell
.
to_string
(
os
);
}
}
#if 0
IndexScanOperator *try_to_create_index_scan_operator(FilterStmt *filter_stmt)
{
...
...
@@ -319,6 +335,7 @@ IndexScanOperator *try_to_create_index_scan_operator(FilterStmt *filter_stmt)
} else {
continue;
}
FieldExpr &left_field_expr = *(FieldExpr *)left;
const Field &field = left_field_expr.field();
const Table *table = field.table();
...
...
@@ -355,7 +372,6 @@ IndexScanOperator *try_to_create_index_scan_operator(FilterStmt *filter_stmt)
}
}
FieldExpr &left_field_expr = *(FieldExpr *)left;
const Field &field = left_field_expr.field();
const Table *table = field.table();
...
...
@@ -423,10 +439,12 @@ IndexScanOperator *try_to_create_index_scan_operator(FilterStmt *filter_stmt)
RC
ExecuteStage
::
do_select
(
SQLStageEvent
*
sql_event
)
{
#if 0
SelectStmt *select_stmt = (SelectStmt *)(sql_event->stmt());
SessionEvent *session_event = sql_event->session_event();
#if 0
RC rc = RC::SUCCESS;
SessionEvent *session_event = sql_event->session_event();
SelectStmt *select_stmt = (SelectStmt *)(sql_event->stmt());
if (select_stmt->tables().size() != 1) {
LOG_WARN("select more than 1 tables is not supported");
rc = RC::UNIMPLENMENT;
...
...
@@ -438,17 +456,19 @@ RC ExecuteStage::do_select(SQLStageEvent *sql_event)
scan_oper = new TableScanOperator(select_stmt->tables()[0]);
}
SqlResult *sql_result = new SqlResult;
PredicateOperator *pred_oper = new PredicateOperator(select_stmt->filter_stmt());
pred_oper->add_child(scan_oper);
ProjectOperator *project_oper = new ProjectOperator;
project_oper->add_child(pred_oper);
TupleSchema schema;
for (const Field &field : select_stmt->query_fields()) {
project_oper->add_projection(field.table(), field.meta());
schema.append_cell(field.field_name());
}
SqlResult *sql_result = new SqlResult;
sql_result->set_tuple_schema(schema);
sql_result->set_operator(project_oper);
...
...
@@ -484,46 +504,53 @@ RC ExecuteStage::do_select(SQLStageEvent *sql_event)
session_event->set_response(ss.str());
*/
session_event->set_sql_result(sql_result);
#endif
#endif
return
RC
::
SUCCESS
;
}
RC
ExecuteStage
::
do_help
(
SQLStageEvent
*
sql_event
)
{
SessionEvent
*
session_event
=
sql_event
->
session_event
();
const
char
*
strings
[]
=
{
"show tables;"
,
const
char
*
strings
[]
=
{
"show tables;"
,
"desc `table name`;"
,
"create table `table name` (`column name` `column type`, ...);"
,
"create index `index name` on `table` (`column`);"
,
"insert into `table` values(`value1`,`value2`);"
,
"update `table` set column=value [where `column`=`value`];"
,
"delete from `table` [where `column`=`value`];"
,
"select [ * | `columns` ] from `table`;"
};
"select [ * | `columns` ] from `table`;"
};
auto
oper
=
new
StringListPhysicalOperator
();
for
(
size_t
i
=
0
;
i
<
sizeof
(
strings
)
/
sizeof
(
strings
[
0
]);
i
++
)
{
for
(
size_t
i
=
0
;
i
<
sizeof
(
strings
)
/
sizeof
(
strings
[
0
]);
i
++
)
{
oper
->
append
(
strings
[
i
]);
}
SqlResult
*
sql_result
=
new
SqlResult
;
TupleSchema
schema
;
schema
.
append_cell
(
"Commands"
);
sql_result
->
set_tuple_schema
(
schema
);
sql_result
->
set_operator
(
std
::
unique_ptr
<
PhysicalOperator
>
(
oper
));
session_event
->
set_sql_result
(
sql_result
);
return
RC
::
SUCCESS
;
}
RC
ExecuteStage
::
do_create_table
(
SQLStageEvent
*
sql_event
)
{
const
CreateTable
&
create_table
=
sql_event
->
query
()
->
create_table
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
Db
*
db
=
session_event
->
session
()
->
get_current_db
();
const
CreateTable
&
create_table
=
sql_event
->
command
()
->
create_table
;
const
int
attribute_count
=
static_cast
<
int
>
(
create_table
.
attr_infos
.
size
());
RC
rc
=
db
->
create_table
(
create_table
.
relation_name
.
c_str
(),
attribute_count
,
create_table
.
attr_infos
.
data
());
SqlResult
*
sql_result
=
new
SqlResult
;
sql_result
->
set_return_code
(
rc
);
sql_event
->
session_event
()
->
set_sql_result
(
sql_result
);
return
rc
;
}
...
...
@@ -532,8 +559,10 @@ RC ExecuteStage::do_create_index(SQLStageEvent *sql_event)
SqlResult
*
sql_result
=
new
SqlResult
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
session_event
->
set_sql_result
(
sql_result
);
Db
*
db
=
session_event
->
session
()
->
get_current_db
();
const
CreateIndex
&
create_index
=
sql_event
->
query
()
->
create_index
;
const
CreateIndex
&
create_index
=
sql_event
->
command
()
->
create_index
;
Table
*
table
=
db
->
find_table
(
create_index
.
relation_name
.
c_str
());
if
(
nullptr
==
table
)
{
sql_result
->
set_return_code
(
RC
::
SCHEMA_TABLE_NOT_EXIST
);
...
...
@@ -541,6 +570,7 @@ RC ExecuteStage::do_create_index(SQLStageEvent *sql_event)
}
RC
rc
=
table
->
create_index
(
nullptr
,
create_index
.
index_name
.
c_str
(),
create_index
.
attribute_name
.
c_str
());
sql_result
->
set_return_code
(
rc
);
return
rc
;
}
...
...
@@ -550,44 +580,55 @@ RC ExecuteStage::do_show_tables(SQLStageEvent *sql_event)
SqlResult
*
sql_result
=
new
SqlResult
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
session_event
->
set_sql_result
(
sql_result
);
Db
*
db
=
session_event
->
session
()
->
get_current_db
();
std
::
vector
<
std
::
string
>
all_tables
;
db
->
all_tables
(
all_tables
);
TupleSchema
tuple_schema
;
tuple_schema
.
append_cell
(
TupleCellSpec
(
""
,
"Tables_in_SYS"
,
"Tables_in_SYS"
));
sql_result
->
set_tuple_schema
(
tuple_schema
);
auto
oper
=
new
StringListPhysicalOperator
;
for
(
const
std
::
string
&
s
:
all_tables
)
{
oper
->
append
(
s
);
}
sql_result
->
set_operator
(
std
::
unique_ptr
<
PhysicalOperator
>
(
oper
));
return
RC
::
SUCCESS
;
}
RC
ExecuteStage
::
do_desc_table
(
SQLStageEvent
*
sql_event
)
{
Query
*
query
=
sql_event
->
query
().
get
();
Db
*
db
=
sql_event
->
session_event
()
->
session
()
->
get_current_db
();
const
char
*
table_name
=
query
->
desc_table
.
relation_name
.
c_str
();
Table
*
table
=
db
->
find_table
(
table_name
);
SqlResult
*
sql_result
=
new
SqlResult
;
sql_event
->
session_event
()
->
set_sql_result
(
sql_result
);
Command
*
cmd
=
sql_event
->
command
().
get
();
const
char
*
table_name
=
cmd
->
desc_table
.
relation_name
.
c_str
();
Db
*
db
=
sql_event
->
session_event
()
->
session
()
->
get_current_db
();
Table
*
table
=
db
->
find_table
(
table_name
);
if
(
table
!=
nullptr
)
{
TupleSchema
tuple_schema
;
tuple_schema
.
append_cell
(
TupleCellSpec
(
""
,
"Field"
,
"Field"
));
tuple_schema
.
append_cell
(
TupleCellSpec
(
""
,
"Type"
,
"Type"
));
tuple_schema
.
append_cell
(
TupleCellSpec
(
""
,
"Length"
,
"Length"
));
// TODO add Key
sql_result
->
set_tuple_schema
(
tuple_schema
);
auto
oper
=
new
StringListPhysicalOperator
;
const
TableMeta
&
table_meta
=
table
->
table_meta
();
for
(
int
i
=
table_meta
.
sys_field_num
();
i
<
table_meta
.
field_num
();
i
++
)
{
const
FieldMeta
*
field_meta
=
table_meta
.
field
(
i
);
oper
->
append
({
field_meta
->
name
(),
attr_type_to_string
(
field_meta
->
type
()),
std
::
to_string
(
field_meta
->
len
())});
oper
->
append
({
field_meta
->
name
(),
attr_type_to_string
(
field_meta
->
type
()),
std
::
to_string
(
field_meta
->
len
())});
}
sql_result
->
set_operator
(
std
::
unique_ptr
<
PhysicalOperator
>
(
oper
));
}
else
{
sql_result
->
set_return_code
(
RC
::
SCHEMA_TABLE_NOT_EXIST
);
sql_result
->
set_state_string
(
"Table not exists"
);
}
...
...
@@ -596,15 +637,17 @@ RC ExecuteStage::do_desc_table(SQLStageEvent *sql_event)
RC
ExecuteStage
::
do_insert
(
SQLStageEvent
*
sql_event
)
{
Stmt
*
stmt
=
sql_event
->
stmt
();
SessionEvent
*
session_event
=
sql_event
->
session_event
();
SqlResult
*
sql_result
=
new
SqlResult
;
session_event
->
set_sql_result
(
sql_result
);
Session
*
session
=
session_event
->
session
();
Db
*
db
=
session
->
get_current_db
();
Trx
*
trx
=
session
->
current_trx
();
CLogManager
*
clog_manager
=
db
->
get_clog_manager
();
Stmt
*
stmt
=
sql_event
->
stmt
();
if
(
stmt
==
nullptr
)
{
LOG_WARN
(
"cannot find statement"
);
return
RC
::
GENERIC_ERROR
;
...
...
@@ -616,6 +659,7 @@ RC ExecuteStage::do_insert(SQLStageEvent *sql_event)
RC
rc
=
table
->
insert_record
(
trx
,
insert_stmt
->
value_amount
(),
insert_stmt
->
values
());
if
(
rc
==
RC
::
SUCCESS
)
{
if
(
!
session
->
is_trx_multi_operation_mode
())
{
CLogRecord
*
clog_record
=
nullptr
;
rc
=
clog_manager
->
clog_gen_record
(
CLogType
::
REDO_MTR_COMMIT
,
trx
->
get_current_id
(),
clog_record
);
if
(
rc
!=
RC
::
SUCCESS
||
clog_record
==
nullptr
)
{
...
...
@@ -630,7 +674,7 @@ RC ExecuteStage::do_insert(SQLStageEvent *sql_event)
if
(
rc
!=
RC
::
SUCCESS
)
{
sql_result
->
set_return_code
(
rc
);
return
rc
;
}
}
trx
->
next_current_id
();
sql_result
->
set_return_code
(
RC
::
SUCCESS
);
...
...
@@ -645,23 +689,26 @@ RC ExecuteStage::do_insert(SQLStageEvent *sql_event)
RC
ExecuteStage
::
do_delete
(
SQLStageEvent
*
sql_event
)
{
#if 0
Stmt *stmt = sql_event->stmt();
#if 0
SessionEvent *session_event = sql_event->session_event();
Session *session = session_event->session();
Db *db = session->get_current_db();
Trx *trx = session->current_trx();
CLogManager *clog_manager = db->get_clog_manager();
Stmt *stmt = sql_event->stmt();
if (stmt == nullptr) {
LOG_WARN("cannot find statement");
return RC::GENERIC_ERROR;
}
DeleteStmt *delete_stmt = (DeleteStmt *)stmt;
TableScanOperator scan_oper(delete_stmt->table());
PredicateOperator pred_oper(delete_stmt->filter_stmt());
pred_oper.add_child(&scan_oper);
DeleteOperator delete_oper(delete_stmt, trx);
delete_oper.add_child(&pred_oper);
...
...
@@ -669,8 +716,10 @@ RC ExecuteStage::do_delete(SQLStageEvent *sql_event)
if (rc != RC::SUCCESS) {
session_event->set_response("FAILURE\n");
} else {
session_event->set_response("SUCCESS\n");
if (!session->is_trx_multi_operation_mode()) {
CLogRecord *clog_record = nullptr;
rc = clog_manager->clog_gen_record(CLogType::REDO_MTR_COMMIT, trx->get_current_id(), clog_record);
if (rc != RC::SUCCESS || clog_record == nullptr) {
...
...
@@ -689,16 +738,16 @@ RC ExecuteStage::do_delete(SQLStageEvent *sql_event)
}
}
return rc;
#endif
#endif
return
RC
::
SUCCESS
;
}
RC
ExecuteStage
::
do_begin
(
SQLStageEvent
*
sql_event
)
{
RC
rc
=
RC
::
SUCCESS
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
SqlResult
*
sql_result
=
new
SqlResult
;
session_event
->
set_sql_result
(
sql_result
);
Session
*
session
=
session_event
->
session
();
Db
*
db
=
session
->
get_current_db
();
Trx
*
trx
=
session
->
current_trx
();
...
...
@@ -707,7 +756,7 @@ RC ExecuteStage::do_begin(SQLStageEvent *sql_event)
session
->
set_trx_multi_operation_mode
(
true
);
CLogRecord
*
clog_record
=
nullptr
;
rc
=
clog_manager
->
clog_gen_record
(
CLogType
::
REDO_MTR_BEGIN
,
trx
->
get_current_id
(),
clog_record
);
RC
rc
=
clog_manager
->
clog_gen_record
(
CLogType
::
REDO_MTR_BEGIN
,
trx
->
get_current_id
(),
clog_record
);
if
(
rc
!=
RC
::
SUCCESS
||
clog_record
==
nullptr
)
{
sql_result
->
set_return_code
(
rc
);
return
rc
;
...
...
@@ -721,19 +770,20 @@ RC ExecuteStage::do_begin(SQLStageEvent *sql_event)
RC
ExecuteStage
::
do_commit
(
SQLStageEvent
*
sql_event
)
{
RC
rc
=
RC
::
SUCCESS
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
SqlResult
*
sql_result
=
new
SqlResult
;
session_event
->
set_sql_result
(
sql_result
);
Session
*
session
=
session_event
->
session
();
Db
*
db
=
session
->
get_current_db
();
Trx
*
trx
=
session
->
current_trx
();
CLogManager
*
clog_manager
=
db
->
get_clog_manager
();
Session
*
session
=
session_event
->
session
();
session
->
set_trx_multi_operation_mode
(
false
);
Trx
*
trx
=
session
->
current_trx
();
CLogRecord
*
clog_record
=
nullptr
;
rc
=
clog_manager
->
clog_gen_record
(
CLogType
::
REDO_MTR_COMMIT
,
trx
->
get_current_id
(),
clog_record
);
Db
*
db
=
session
->
get_current_db
();
CLogManager
*
clog_manager
=
db
->
get_clog_manager
();
RC
rc
=
clog_manager
->
clog_gen_record
(
CLogType
::
REDO_MTR_COMMIT
,
trx
->
get_current_id
(),
clog_record
);
if
(
rc
!=
RC
::
SUCCESS
||
clog_record
==
nullptr
)
{
sql_result
->
set_return_code
(
rc
);
return
rc
;
...
...
@@ -749,14 +799,16 @@ RC ExecuteStage::do_commit(SQLStageEvent *sql_event)
RC
ExecuteStage
::
do_clog_sync
(
SQLStageEvent
*
sql_event
)
{
RC
rc
=
RC
::
SUCCESS
;
SqlResult
*
sql_result
=
new
SqlResult
;
SessionEvent
*
session_event
=
sql_event
->
session_event
();
session_event
->
set_sql_result
(
sql_result
);
Db
*
db
=
session_event
->
session
()
->
get_current_db
();
CLogManager
*
clog_manager
=
db
->
get_clog_manager
();
rc
=
clog_manager
->
clog_sync
();
RC
rc
=
clog_manager
->
clog_sync
();
sql_result
->
set_return_code
(
rc
);
return
rc
;
...
...
src/observer/sql/parser/parse.cpp
浏览文件 @
ab89b1d5
...
...
@@ -17,7 +17,7 @@ See the Mulan PSL v2 for more details. */
#include "rc.h"
#include "common/log/log.h"
RC
parse
(
char
*
st
,
Query
*
sqln
);
RC
parse
(
char
*
st
,
Command
*
sqln
);
const
char
*
ATTR_TYPE_NAME
[]
=
{
"undefined"
,
"chars"
,
"ints"
,
"floats"
,
"booleans"
};
...
...
@@ -62,16 +62,16 @@ int Value::length()
return
0
;
}
Query
::
Query
()
Command
::
Command
()
:
flag
(
SCF_ERROR
)
{
}
Query
::
Query
(
enum
SqlCommandFlag
_flag
)
Command
::
Command
(
enum
SqlCommandFlag
_flag
)
:
flag
(
_flag
)
{}
void
ParsedSqlResult
::
add_command
(
std
::
unique_ptr
<
Query
>
command
)
void
ParsedSqlResult
::
add_command
(
std
::
unique_ptr
<
Command
>
command
)
{
sql_commands_
.
emplace_back
(
std
::
move
(
command
));
}
...
...
src/observer/sql/parser/parse_defs.h
浏览文件 @
ab89b1d5
...
...
@@ -130,6 +130,7 @@ struct CreateIndex {
// struct of drop_index
struct
DropIndex
{
std
::
string
index_name
;
// Index name
std
::
string
relation_name
;
//Relation name
};
struct
DescTable
{
...
...
@@ -141,9 +142,9 @@ struct LoadData {
std
::
string
file_name
;
};
class
Query
;
class
Command
;
struct
Explain
{
std
::
unique_ptr
<
Query
>
query
;
std
::
unique_ptr
<
Command
>
cmd
;
};
struct
Error
...
...
@@ -177,7 +178,7 @@ enum SqlCommandFlag {
SCF_EXPLAIN
,
};
// struct of flag and sql_struct
class
Query
{
class
Command
{
public:
enum
SqlCommandFlag
flag
;
Error
error
;
...
...
@@ -194,8 +195,8 @@ public:
Explain
explain
;
public:
Query
();
Query
(
enum
SqlCommandFlag
flag
);
Command
();
Command
(
enum
SqlCommandFlag
flag
);
};
/**
...
...
@@ -205,11 +206,11 @@ public:
class
ParsedSqlResult
{
public:
void
add_command
(
std
::
unique_ptr
<
Query
>
command
);
std
::
vector
<
std
::
unique_ptr
<
Query
>>
&
commands
()
{
return
sql_commands_
;
}
void
add_command
(
std
::
unique_ptr
<
Command
>
command
);
std
::
vector
<
std
::
unique_ptr
<
Command
>>
&
commands
()
{
return
sql_commands_
;
}
private:
std
::
vector
<
std
::
unique_ptr
<
Query
>>
sql_commands_
;
std
::
vector
<
std
::
unique_ptr
<
Command
>>
sql_commands_
;
};
const
char
*
attr_type_to_string
(
AttrType
type
);
...
...
src/observer/sql/parser/parse_stage.cpp
浏览文件 @
ab89b1d5
...
...
@@ -138,8 +138,8 @@ RC ParseStage::handle_request(StageEvent *event)
LOG_WARN
(
"got multi sql commands but only 1 will be handled"
);
}
std
::
unique_ptr
<
Query
>
query_result
=
std
::
move
(
parsed_sql_result
.
commands
().
front
());
if
(
query_result
->
flag
==
SCF_ERROR
)
{
std
::
unique_ptr
<
Command
>
cmd
=
std
::
move
(
parsed_sql_result
.
commands
().
front
());
if
(
cmd
->
flag
==
SCF_ERROR
)
{
// set error information to event
sql_result
->
set_return_code
(
RC
::
SQL_SYNTAX
);
sql_result
->
set_state_string
(
"Failed to parse sql"
);
...
...
@@ -148,6 +148,6 @@ RC ParseStage::handle_request(StageEvent *event)
}
delete
sql_result
;
sql_event
->
set_
query
(
std
::
move
(
query_result
));
sql_event
->
set_
command
(
std
::
move
(
cmd
));
return
RC
::
SUCCESS
;
}
src/observer/sql/parser/resolve_stage.cpp
浏览文件 @
ab89b1d5
...
...
@@ -101,9 +101,9 @@ void ResolveStage::handle_event(StageEvent *event)
return
;
}
Query
*
query
=
sql_event
->
query
().
get
();
Command
*
cmd
=
sql_event
->
command
().
get
();
Stmt
*
stmt
=
nullptr
;
RC
rc
=
Stmt
::
create_stmt
(
db
,
*
query
,
stmt
);
RC
rc
=
Stmt
::
create_stmt
(
db
,
*
cmd
,
stmt
);
if
(
rc
!=
RC
::
SUCCESS
&&
rc
!=
RC
::
UNIMPLENMENT
)
{
LOG_WARN
(
"failed to create stmt. rc=%d:%s"
,
rc
,
strrc
(
rc
));
SqlResult
*
sql_result
=
new
SqlResult
;
...
...
src/observer/sql/parser/yacc_sql.cpp
浏览文件 @
ab89b1d5
...
...
@@ -70,40 +70,30 @@
#line 2 "yacc_sql.y"
#include "sql/parser/parse_defs.h"
#include "sql/parser/yacc_sql.hpp"
#include "sql/parser/lex_sql.h"
#include "common/log/log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
//获取子串
char
*
substr
(
const
char
*
s
,
int
n1
,
int
n2
)
/*从s中提取下标为n1~n2的字符组成一个新字符串,然后返回这个新串的首地址*/
{
char
*
sp
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
(
n2
-
n1
+
2
));
int
i
,
j
=
0
;
for
(
i
=
n1
;
i
<=
n2
;
i
++
)
{
sp
[
j
++
]
=
s
[
i
];
}
sp
[
j
]
=
0
;
return
sp
;
}
#include "common/log/log.h"
#include "common/lang/string.h"
#include "sql/parser/parse_defs.h"
#include "sql/parser/yacc_sql.hpp"
#include "sql/parser/lex_sql.h"
int
yyerror
(
YYLTYPE
*
llocp
,
ParsedSqlResult
*
sql_result
,
yyscan_t
scanner
,
const
char
*
msg
)
{
std
::
unique_ptr
<
Query
>
error_query
=
std
::
make_unique
<
Query
>
(
SCF_ERROR
);
error_
query
->
error
.
error_msg
=
msg
;
error_
query
->
error
.
line
=
llocp
->
first_line
;
error_
query
->
error
.
column
=
llocp
->
first_column
;
sql_result
->
add_command
(
std
::
move
(
error_
query
));
std
::
unique_ptr
<
Command
>
error_cmd
=
std
::
make_unique
<
Command
>
(
SCF_ERROR
);
error_
cmd
->
error
.
error_msg
=
msg
;
error_
cmd
->
error
.
line
=
llocp
->
first_line
;
error_
cmd
->
error
.
column
=
llocp
->
first_column
;
sql_result
->
add_command
(
std
::
move
(
error_
cmd
));
return
0
;
}
#line
10
7 "yacc_sql.cpp"
#line
9
7 "yacc_sql.cpp"
# ifndef YY_CAST
# ifdef __cplusplus
...
...
@@ -185,7 +175,7 @@ enum yysymbol_kind_t
YYSYMBOL_STRING_V
=
51
,
/* STRING_V */
YYSYMBOL_YYACCEPT
=
52
,
/* $accept */
YYSYMBOL_commands
=
53
,
/* commands */
YYSYMBOL_command
=
54
,
/* command
*/
YYSYMBOL_command
_wrapper
=
54
,
/* command_wrapper
*/
YYSYMBOL_exit
=
55
,
/* exit */
YYSYMBOL_help
=
56
,
/* help */
YYSYMBOL_sync
=
57
,
/* sync */
...
...
@@ -531,7 +521,7 @@ union yyalloc
/* YYFINAL -- State number of the termination state. */
#define YYFINAL 52
/* YYLAST -- Last index in YYTABLE. */
#define YYLAST 1
09
#define YYLAST 1
12
/* YYNTOKENS -- Number of terminals. */
#define YYNTOKENS 52
...
...
@@ -540,7 +530,7 @@ union yyalloc
/* YYNRULES -- Number of rules. */
#define YYNRULES 76
/* YYNSTATES -- Number of states. */
#define YYNSTATES 13
6
#define YYNSTATES 13
8
/* YYMAXUTOK -- Last valid token kind. */
#define YYMAXUTOK 306
...
...
@@ -594,14 +584,14 @@ static const yytype_int8 yytranslate[] =
/* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
static
const
yytype_int16
yyrline
[]
=
{
0
,
1
52
,
152
,
160
,
161
,
162
,
163
,
164
,
165
,
16
6
,
1
67
,
168
,
169
,
170
,
171
,
172
,
173
,
174
,
175
,
17
6
,
1
77
,
181
,
186
,
191
,
197
,
203
,
209
,
215
,
222
,
22
8
,
2
36
,
250
,
258
,
277
,
280
,
293
,
301
,
311
,
314
,
315
,
3
16
,
319
,
335
,
338
,
349
,
354
,
359
,
369
,
381
,
396
,
41
9
,
426
,
438
,
443
,
454
,
457
,
471
,
474
,
487
,
490
,
4
96
,
499
,
504
,
511
,
523
,
535
,
547
,
562
,
563
,
564
,
5
65
,
566
,
567
,
571
,
581
,
588
,
589
0
,
1
42
,
142
,
150
,
151
,
152
,
153
,
154
,
155
,
15
6
,
1
57
,
158
,
159
,
160
,
161
,
162
,
163
,
164
,
165
,
16
6
,
1
67
,
171
,
176
,
181
,
187
,
193
,
199
,
205
,
212
,
21
8
,
2
26
,
240
,
250
,
269
,
272
,
285
,
293
,
303
,
306
,
307
,
3
08
,
311
,
327
,
330
,
341
,
346
,
351
,
361
,
373
,
388
,
41
1
,
418
,
430
,
435
,
446
,
449
,
463
,
466
,
479
,
482
,
4
88
,
491
,
496
,
503
,
515
,
527
,
539
,
554
,
555
,
556
,
5
57
,
558
,
559
,
563
,
573
,
580
,
581
};
#endif
...
...
@@ -624,7 +614,7 @@ static const char *const yytname[] =
"EXIT"
,
"DOT"
,
"INTO"
,
"VALUES"
,
"FROM"
,
"WHERE"
,
"AND"
,
"SET"
,
"ON"
,
"LOAD"
,
"DATA"
,
"INFILE"
,
"EXPLAIN"
,
"EQ"
,
"LT"
,
"GT"
,
"LE"
,
"GE"
,
"NE"
,
"NUMBER"
,
"FLOAT"
,
"ID"
,
"PATH"
,
"SSS"
,
"STAR"
,
"STRING_V"
,
"$accept"
,
"commands"
,
"command"
,
"exit"
,
"help"
,
"sync"
,
"begin"
,
"commit"
,
"commands"
,
"command
_wrapper
"
,
"exit"
,
"help"
,
"sync"
,
"begin"
,
"commit"
,
"rollback"
,
"drop_table"
,
"show_tables"
,
"desc_table"
,
"create_index"
,
"drop_index"
,
"create_table"
,
"attr_def_list"
,
"attr_def"
,
"number"
,
"type"
,
"insert"
,
"value_list"
,
"value"
,
"delete"
,
"update"
,
"select"
,
...
...
@@ -654,7 +644,7 @@ static const yytype_int16 yytoknum[] =
};
#endif
#define YYPACT_NINF (-8
3
)
#define YYPACT_NINF (-8
5
)
#define yypact_value_is_default(Yyn) \
((Yyn) == YYPACT_NINF)
...
...
@@ -668,20 +658,20 @@ static const yytype_int16 yytoknum[] =
STATE-NUM. */
static
const
yytype_int8
yypact
[]
=
{
10
,
26
,
46
,
-
6
,
-
37
,
4
,
-
8
3
,
-
11
,
-
12
,
-
21
,
-
8
3
,
-
83
,
-
83
,
-
83
,
-
83
,
7
,
10
,
47
,
43
,
-
83
,
-
8
3
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
8
3
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
6
,
8
,
9
,
12
,
30
,
-
8
3
,
31
,
42
,
-
83
,
-
83
,
15
,
16
,
32
,
29
,
-
8
3
,
-
83
,
-
83
,
-
83
,
48
,
33
,
-
83
,
-
83
,
21
,
2
2
,
23
,
-
83
,
44
,
40
,
25
,
28
,
34
,
35
,
-
83
,
56
,
42
,
59
,
-
7
,
-
83
,
37
,
50
,
27
,
61
,
64
,
36
,
40
,
-
83
,
-
33
,
-
83
,
-
83
,
-
83
,
-
36
,
-
36
,
-
83
,
52
,
-
33
,
79
,
-
83
,
-
83
,
-
83
,
70
,
34
,
71
,
4
5
,
56
,
-
83
,
69
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
7
,
-
7
,
-
7
,
40
,
49
,
53
,
61
,
-
83
,
72
,
-
83
,
-
33
,
73
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
74
,
-
8
3
,
-
83
,
69
,
-
83
,
-
83
,
-
83
10
,
26
,
46
,
-
6
,
-
37
,
4
,
-
8
5
,
-
11
,
-
12
,
-
21
,
-
8
5
,
-
85
,
-
85
,
-
85
,
-
85
,
7
,
10
,
47
,
43
,
-
85
,
-
8
5
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
8
5
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
6
,
8
,
9
,
12
,
30
,
-
8
5
,
31
,
42
,
-
85
,
-
85
,
15
,
16
,
32
,
29
,
-
8
5
,
-
85
,
-
85
,
-
85
,
48
,
33
,
-
85
,
34
,
22
,
2
3
,
24
,
-
85
,
44
,
41
,
28
,
25
,
35
,
36
,
37
,
-
85
,
58
,
42
,
61
,
-
7
,
-
85
,
39
,
51
,
27
,
62
,
65
,
-
85
,
38
,
41
,
-
85
,
-
33
,
-
85
,
-
85
,
-
85
,
-
36
,
-
36
,
-
85
,
54
,
-
33
,
81
,
-
85
,
-
85
,
-
85
,
72
,
3
5
,
73
,
45
,
58
,
-
85
,
71
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
7
,
-
7
,
-
7
,
41
,
49
,
50
,
62
,
-
85
,
74
,
-
85
,
-
33
,
76
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
8
5
,
77
,
-
85
,
-
85
,
71
,
-
85
,
-
85
,
-
85
};
/* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
...
...
@@ -694,33 +684,33 @@ static const yytype_int8 yydefact[] =
19
,
13
,
14
,
15
,
16
,
8
,
9
,
10
,
11
,
12
,
7
,
4
,
6
,
5
,
3
,
17
,
18
,
0
,
0
,
0
,
0
,
52
,
50
,
0
,
54
,
29
,
28
,
0
,
0
,
0
,
0
,
74
,
1
,
76
,
2
,
0
,
0
,
27
,
31
,
0
,
0
,
0
,
51
,
0
,
58
,
0
,
0
,
0
,
0
,
53
,
5
6
,
54
,
0
,
60
,
47
,
0
,
0
,
0
,
33
,
0
,
0
,
58
,
55
,
0
,
44
,
45
,
46
,
0
,
0
,
59
,
61
,
0
,
0
,
38
,
39
,
40
,
36
,
0
,
0
,
0
,
56
,
49
,
42
,
67
,
68
,
69
,
70
,
71
,
72
,
0
,
0
,
60
,
58
,
0
,
0
,
33
,
32
,
0
,
57
,
0
,
0
,
64
,
66
,
63
,
65
,
62
,
48
,
73
,
37
,
0
,
34
,
30
,
42
,
41
,
35
,
43
0
,
74
,
1
,
76
,
2
,
0
,
0
,
27
,
0
,
0
,
0
,
0
,
51
,
0
,
58
,
0
,
0
,
0
,
0
,
0
,
5
3
,
56
,
54
,
0
,
60
,
47
,
0
,
0
,
0
,
33
,
0
,
31
,
0
,
58
,
55
,
0
,
44
,
45
,
46
,
0
,
0
,
59
,
61
,
0
,
0
,
38
,
39
,
40
,
36
,
0
,
0
,
0
,
56
,
49
,
42
,
67
,
68
,
69
,
70
,
71
,
72
,
0
,
0
,
60
,
58
,
0
,
0
,
33
,
32
,
0
,
57
,
0
,
0
,
64
,
66
,
63
,
65
,
62
,
48
,
73
,
3
7
,
0
,
3
4
,
30
,
42
,
41
,
35
,
43
};
/* YYPGOTO[NTERM-NUM]. */
static
const
yytype_int8
yypgoto
[]
=
{
-
8
3
,
-
83
,
77
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
83
,
-
8
3
,
-
83
,
-
83
,
-
83
,
-
83
,
-
20
,
0
,
-
83
,
-
83
,
-
83
,
-
3
8
,
-
82
,
-
83
,
-
83
,
-
83
,
-
83
,
-
3
,
38
,
-
1
,
-
79
,
-
10
,
-
8
3
,
14
,
-
83
,
-
83
,
-
83
-
8
5
,
-
85
,
82
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
85
,
-
8
5
,
-
85
,
-
85
,
-
85
,
-
85
,
-
20
,
0
,
-
85
,
-
85
,
-
85
,
-
3
4
,
-
84
,
-
85
,
-
85
,
-
85
,
-
85
,
-
3
,
40
,
-
1
,
-
81
,
-
10
,
-
8
5
,
14
,
-
85
,
-
85
,
-
85
};
/* YYDEFGOTO[NTERM-NUM]. */
static
const
yytype_int16
yydefgoto
[]
=
{
-
1
,
17
,
18
,
19
,
20
,
21
,
22
,
23
,
24
,
25
,
26
,
27
,
28
,
29
,
30
,
98
,
78
,
129
,
96
,
31
,
12
0
,
87
,
32
,
33
,
34
,
43
,
88
,
62
,
81
,
74
,
89
,
90
,
109
,
35
,
36
,
54
26
,
27
,
28
,
29
,
30
,
100
,
79
,
131
,
98
,
31
,
12
2
,
89
,
32
,
33
,
34
,
43
,
90
,
62
,
83
,
75
,
91
,
92
,
111
,
35
,
36
,
54
};
/* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
...
...
@@ -728,32 +718,34 @@ static const yytype_int16 yydefgoto[] =
number is the opposite. If YYTABLE_NINF, syntax error. */
static
const
yytype_uint8
yytable
[]
=
{
44
,
10
2
,
101
,
103
,
104
,
105
,
106
,
107
,
108
,
112
,
45
,
46
,
8
4
,
85
,
1
,
2
,
86
,
47
,
48
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
49
,
12
1
,
123
,
10
,
11
,
12
,
37
,
12
6
,
38
,
13
,
14
,
132
,
84
,
85
,
41
,
41
,
8
6
,
50
,
42
,
15
,
53
,
52
,
16
,
93
,
9
4
,
95
,
39
,
55
,
40
,
56
,
57
,
59
,
71
,
58
,
44
,
10
4
,
103
,
105
,
106
,
107
,
108
,
109
,
110
,
114
,
45
,
46
,
8
6
,
87
,
1
,
2
,
88
,
47
,
48
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
49
,
12
3
,
125
,
10
,
11
,
12
,
37
,
12
8
,
38
,
13
,
14
,
134
,
86
,
87
,
41
,
41
,
8
8
,
50
,
42
,
15
,
53
,
52
,
16
,
95
,
9
6
,
97
,
39
,
55
,
40
,
56
,
57
,
59
,
72
,
58
,
61
,
60
,
63
,
64
,
67
,
65
,
66
,
68
,
69
,
70
,
41
,
73
,
75
,
72
,
80
,
83
,
91
,
76
,
92
,
97
,
99
,
77
,
79
,
100
,
111
,
113
,
114
,
119
,
116
,
131
,
133
,
134
,
117
,
51
,
135
,
130
,
127
,
115
,
128
,
118
,
0
,
125
,
110
,
0
,
0
,
0
,
122
,
124
,
0
,
82
71
,
41
,
74
,
73
,
77
,
76
,
82
,
85
,
93
,
94
,
99
,
101
,
78
,
80
,
81
,
102
,
113
,
115
,
116
,
121
,
118
,
133
,
119
,
135
,
136
,
130
,
129
,
132
,
51
,
117
,
137
,
120
,
0
,
127
,
112
,
0
,
0
,
0
,
124
,
126
,
0
,
0
,
84
};
static
const
yytype_int16
yycheck
[]
=
{
3
,
8
3
,
81
,
39
,
40
,
41
,
42
,
43
,
44
,
91
,
3
,
8
5
,
83
,
39
,
40
,
41
,
42
,
43
,
44
,
93
,
47
,
7
,
45
,
46
,
4
,
5
,
49
,
28
,
30
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
47
,
1
09
,
110
,
19
,
20
,
21
,
6
,
11
2
,
8
,
25
,
26
,
119
,
45
,
46
,
10
,
11
,
12
,
13
,
14
,
15
,
47
,
1
11
,
112
,
19
,
20
,
21
,
6
,
11
4
,
8
,
25
,
26
,
121
,
45
,
46
,
47
,
47
,
49
,
36
,
50
,
35
,
3
,
0
,
38
,
22
,
23
,
24
,
6
,
47
,
8
,
47
,
47
,
27
,
61
,
47
,
18
,
30
,
47
,
47
,
16
,
33
,
37
,
34
,
47
,
47
,
47
,
31
,
47
,
29
,
18
,
16
,
39
,
49
,
28
,
18
,
16
,
47
,
47
,
47
,
32
,
6
,
16
,
18
,
17
,
17
,
17
,
17
,
47
,
16
,
132
,
115
,
47
,
97
,
45
,
100
,
-
1
,
111
,
88
,
-
1
,
-
1
,
-
1
,
109
,
110
,
-
1
,
71
18
,
30
,
47
,
47
,
16
,
33
,
37
,
34
,
34
,
47
,
47
,
47
,
31
,
29
,
49
,
47
,
18
,
16
,
39
,
28
,
18
,
16
,
47
,
47
,
47
,
47
,
32
,
6
,
16
,
18
,
17
,
17
,
47
,
17
,
17
,
45
,
47
,
117
,
16
,
99
,
134
,
102
,
-
1
,
113
,
90
,
-
1
,
-
1
,
-
1
,
111
,
112
,
-
1
,
-
1
,
72
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
...
...
@@ -766,14 +758,14 @@ static const yytype_int8 yystos[] =
66
,
71
,
74
,
75
,
76
,
85
,
86
,
6
,
8
,
6
,
8
,
47
,
50
,
77
,
78
,
47
,
7
,
28
,
30
,
47
,
36
,
54
,
0
,
3
,
87
,
47
,
47
,
47
,
47
,
27
,
30
,
18
,
79
,
47
,
47
,
33
,
37
,
16
,
34
,
47
,
47
,
78
,
29
,
31
,
81
,
47
,
49
,
47
,
68
,
47
,
18
,
80
,
79
,
16
,
45
,
46
,
49
,
73
,
78
,
82
,
83
,
39
,
28
,
22
,
23
,
24
,
70
,
18
,
67
,
16
,
47
,
81
,
73
,
39
,
40
,
41
,
42
,
43
,
44
,
84
,
84
,
32
,
73
,
6
,
16
,
68
,
17
,
47
,
80
,
18
,
72
,
73
,
78
,
73
,
78
,
82
,
81
,
47
,
45
,
69
,
67
,
17
,
73
,
17
,
17
,
72
30
,
18
,
79
,
47
,
47
,
33
,
37
,
16
,
34
,
34
,
47
,
47
,
78
,
29
,
31
,
81
,
47
,
49
,
47
,
68
,
47
,
47
,
18
,
80
,
79
,
16
,
45
,
46
,
49
,
73
,
78
,
82
,
83
,
39
,
28
,
22
,
23
,
24
,
70
,
18
,
67
,
16
,
47
,
81
,
73
,
39
,
40
,
41
,
42
,
43
,
44
,
84
,
84
,
32
,
73
,
6
,
16
,
68
,
17
,
47
,
80
,
18
,
72
,
73
,
78
,
73
,
78
,
82
,
81
,
47
,
45
,
69
,
67
,
17
,
73
,
17
,
17
,
72
};
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
...
...
@@ -795,7 +787,7 @@ static const yytype_int8 yyr2[] =
0
,
2
,
2
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
1
,
3
,
2
,
2
,
8
,
3
,
7
,
0
,
3
,
5
,
2
,
1
,
1
,
1
,
8
,
5
,
7
,
0
,
3
,
5
,
2
,
1
,
1
,
1
,
1
,
8
,
0
,
3
,
1
,
1
,
1
,
4
,
7
,
6
,
1
,
2
,
1
,
3
,
0
,
3
,
0
,
3
,
0
,
2
,
0
,
1
,
3
,
3
,
3
,
3
,
3
,
1
,
1
,
1
,
...
...
@@ -1644,96 +1636,96 @@ yyreduce:
YY_REDUCE_PRINT
(
yyn
);
switch
(
yyn
)
{
case
2
:
/* commands: command opt_semicolon */
#line 1
5
3 "yacc_sql.y"
case
2
:
/* commands: command
_wrapper
opt_semicolon */
#line 1
4
3 "yacc_sql.y"
{
std
::
unique_ptr
<
Query
>
query_command
=
std
::
unique_ptr
<
Query
>
((
yyvsp
[
-
1
].
query
));
sql_result
->
add_command
(
std
::
move
(
query
_command
));
std
::
unique_ptr
<
Command
>
sql_command
=
std
::
unique_ptr
<
Command
>
((
yyvsp
[
-
1
].
command
));
sql_result
->
add_command
(
std
::
move
(
sql
_command
));
}
#line 16
54
"yacc_sql.cpp"
#line 16
46
"yacc_sql.cpp"
break
;
case
21
:
/* exit: EXIT */
#line 1
8
1 "yacc_sql.y"
#line 1
7
1 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_EXIT
);
(
yyval
.
command
)
=
new
Command
(
SCF_EXIT
);
}
#line 16
62
"yacc_sql.cpp"
#line 16
54
"yacc_sql.cpp"
break
;
case
22
:
/* help: HELP */
#line 1
8
6 "yacc_sql.y"
#line 1
7
6 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_HELP
);
(
yyval
.
command
)
=
new
Command
(
SCF_HELP
);
}
#line 16
70
"yacc_sql.cpp"
#line 16
62
"yacc_sql.cpp"
break
;
case
23
:
/* sync: SYNC */
#line 1
9
1 "yacc_sql.y"
#line 1
8
1 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_SYNC
);
(
yyval
.
command
)
=
new
Command
(
SCF_SYNC
);
}
#line 167
8
"yacc_sql.cpp"
#line 167
0
"yacc_sql.cpp"
break
;
case
24
:
/* begin: TRX_BEGIN */
#line 1
9
7 "yacc_sql.y"
#line 1
8
7 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_BEGIN
);
(
yyval
.
command
)
=
new
Command
(
SCF_BEGIN
);
}
#line 16
86
"yacc_sql.cpp"
#line 16
78
"yacc_sql.cpp"
break
;
case
25
:
/* commit: TRX_COMMIT */
#line
20
3 "yacc_sql.y"
#line
19
3 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_COMMIT
);
(
yyval
.
command
)
=
new
Command
(
SCF_COMMIT
);
}
#line 16
94
"yacc_sql.cpp"
#line 16
86
"yacc_sql.cpp"
break
;
case
26
:
/* rollback: TRX_ROLLBACK */
#line
20
9 "yacc_sql.y"
#line
19
9 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_ROLLBACK
);
(
yyval
.
command
)
=
new
Command
(
SCF_ROLLBACK
);
}
#line 1
702
"yacc_sql.cpp"
#line 1
694
"yacc_sql.cpp"
break
;
case
27
:
/* drop_table: DROP TABLE ID */
#line 2
1
5 "yacc_sql.y"
#line 2
0
5 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_DROP_TABLE
);
(
yyval
.
query
)
->
drop_table
.
relation_name
=
(
yyvsp
[
0
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_DROP_TABLE
);
(
yyval
.
command
)
->
drop_table
.
relation_name
=
(
yyvsp
[
0
].
string
);
free
((
yyvsp
[
0
].
string
));
}
#line 17
12
"yacc_sql.cpp"
#line 17
04
"yacc_sql.cpp"
break
;
case
28
:
/* show_tables: SHOW TABLES */
#line 2
2
2 "yacc_sql.y"
#line 2
1
2 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_SHOW_TABLES
);
(
yyval
.
command
)
=
new
Command
(
SCF_SHOW_TABLES
);
}
#line 17
20
"yacc_sql.cpp"
#line 17
12
"yacc_sql.cpp"
break
;
case
29
:
/* desc_table: DESC ID */
#line 2
2
8 "yacc_sql.y"
#line 2
1
8 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_DESC_TABLE
);
(
yyval
.
query
)
->
desc_table
.
relation_name
=
(
yyvsp
[
0
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_DESC_TABLE
);
(
yyval
.
command
)
->
desc_table
.
relation_name
=
(
yyvsp
[
0
].
string
);
free
((
yyvsp
[
0
].
string
));
}
#line 17
30
"yacc_sql.cpp"
#line 17
22
"yacc_sql.cpp"
break
;
case
30
:
/* create_index: CREATE INDEX ID ON ID LBRACE ID RBRACE */
#line 2
3
7 "yacc_sql.y"
#line 2
2
7 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_CREATE_INDEX
);
CreateIndex
&
create_index
=
(
yyval
.
query
)
->
create_index
;
(
yyval
.
command
)
=
new
Command
(
SCF_CREATE_INDEX
);
CreateIndex
&
create_index
=
(
yyval
.
command
)
->
create_index
;
create_index
.
index_name
=
(
yyvsp
[
-
5
].
string
);
create_index
.
relation_name
=
(
yyvsp
[
-
3
].
string
);
create_index
.
attribute_name
=
(
yyvsp
[
-
1
].
string
);
...
...
@@ -1741,24 +1733,26 @@ yyreduce:
free
((
yyvsp
[
-
3
].
string
));
free
((
yyvsp
[
-
1
].
string
));
}
#line 17
45
"yacc_sql.cpp"
#line 17
37
"yacc_sql.cpp"
break
;
case
31
:
/* drop_index: DROP INDEX ID */
#line 2
5
1 "yacc_sql.y"
case
31
:
/* drop_index: DROP INDEX ID
ON ID
*/
#line 2
4
1 "yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_DROP_INDEX
);
(
yyval
.
query
)
->
drop_index
.
index_name
=
(
yyvsp
[
0
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_DROP_INDEX
);
(
yyval
.
command
)
->
drop_index
.
index_name
=
(
yyvsp
[
-
2
].
string
);
(
yyval
.
command
)
->
drop_index
.
relation_name
=
(
yyvsp
[
0
].
string
);
free
((
yyvsp
[
-
2
].
string
));
free
((
yyvsp
[
0
].
string
));
}
#line 17
55
"yacc_sql.cpp"
#line 17
49
"yacc_sql.cpp"
break
;
case
32
:
/* create_table: CREATE TABLE ID LBRACE attr_def attr_def_list RBRACE */
#line 25
9
"yacc_sql.y"
#line 25
1
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_CREATE_TABLE
);
CreateTable
&
create_table
=
(
yyval
.
query
)
->
create_table
;
(
yyval
.
command
)
=
new
Command
(
SCF_CREATE_TABLE
);
CreateTable
&
create_table
=
(
yyval
.
command
)
->
create_table
;
create_table
.
relation_name
=
(
yyvsp
[
-
4
].
string
);
free
((
yyvsp
[
-
4
].
string
));
...
...
@@ -1771,19 +1765,19 @@ yyreduce:
std
::
reverse
(
create_table
.
attr_infos
.
begin
(),
create_table
.
attr_infos
.
end
());
delete
(
yyvsp
[
-
2
].
attr_info
);
}
#line 17
75
"yacc_sql.cpp"
#line 17
69
"yacc_sql.cpp"
break
;
case
33
:
/* attr_def_list: %empty */
#line 2
77
"yacc_sql.y"
#line 2
69
"yacc_sql.y"
{
(
yyval
.
attr_infos
)
=
nullptr
;
}
#line 17
83
"yacc_sql.cpp"
#line 17
77
"yacc_sql.cpp"
break
;
case
34
:
/* attr_def_list: COMMA attr_def attr_def_list */
#line 2
81
"yacc_sql.y"
#line 2
73
"yacc_sql.y"
{
if
((
yyvsp
[
0
].
attr_infos
)
!=
nullptr
)
{
(
yyval
.
attr_infos
)
=
(
yyvsp
[
0
].
attr_infos
);
...
...
@@ -1793,11 +1787,11 @@ yyreduce:
(
yyval
.
attr_infos
)
->
emplace_back
(
*
(
yyvsp
[
-
1
].
attr_info
));
delete
(
yyvsp
[
-
1
].
attr_info
);
}
#line 179
7
"yacc_sql.cpp"
#line 179
1
"yacc_sql.cpp"
break
;
case
35
:
/* attr_def: ID type LBRACE number RBRACE */
#line 2
94
"yacc_sql.y"
#line 2
86
"yacc_sql.y"
{
(
yyval
.
attr_info
)
=
new
AttrInfo
;
(
yyval
.
attr_info
)
->
type
=
(
AttrType
)(
yyvsp
[
-
3
].
number
);
...
...
@@ -1805,11 +1799,11 @@ yyreduce:
(
yyval
.
attr_info
)
->
length
=
(
yyvsp
[
-
1
].
number
);
free
((
yyvsp
[
-
4
].
string
));
}
#line 180
9
"yacc_sql.cpp"
#line 180
3
"yacc_sql.cpp"
break
;
case
36
:
/* attr_def: ID type */
#line
302
"yacc_sql.y"
#line
294
"yacc_sql.y"
{
(
yyval
.
attr_info
)
=
new
AttrInfo
;
(
yyval
.
attr_info
)
->
type
=
(
AttrType
)(
yyvsp
[
0
].
number
);
...
...
@@ -1817,59 +1811,59 @@ yyreduce:
(
yyval
.
attr_info
)
->
length
=
4
;
free
((
yyvsp
[
-
1
].
string
));
}
#line 18
21
"yacc_sql.cpp"
#line 18
15
"yacc_sql.cpp"
break
;
case
37
:
/* number: NUMBER */
#line 3
11
"yacc_sql.y"
#line 3
03
"yacc_sql.y"
{(
yyval
.
number
)
=
(
yyvsp
[
0
].
number
);}
#line 182
7
"yacc_sql.cpp"
#line 182
1
"yacc_sql.cpp"
break
;
case
38
:
/* type: INT_T */
#line 3
14
"yacc_sql.y"
#line 3
06
"yacc_sql.y"
{
(
yyval
.
number
)
=
INTS
;
}
#line 18
33
"yacc_sql.cpp"
#line 18
27
"yacc_sql.cpp"
break
;
case
39
:
/* type: STRING_T */
#line 3
15
"yacc_sql.y"
#line 3
07
"yacc_sql.y"
{
(
yyval
.
number
)
=
CHARS
;
}
#line 183
9
"yacc_sql.cpp"
#line 183
3
"yacc_sql.cpp"
break
;
case
40
:
/* type: FLOAT_T */
#line 3
16
"yacc_sql.y"
#line 3
08
"yacc_sql.y"
{
(
yyval
.
number
)
=
FLOATS
;
}
#line 18
45
"yacc_sql.cpp"
#line 18
39
"yacc_sql.cpp"
break
;
case
41
:
/* insert: INSERT INTO ID VALUES LBRACE value value_list RBRACE */
#line 3
20
"yacc_sql.y"
#line 3
12
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_INSERT
);
(
yyval
.
query
)
->
insertion
.
relation_name
=
(
yyvsp
[
-
5
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_INSERT
);
(
yyval
.
command
)
->
insertion
.
relation_name
=
(
yyvsp
[
-
5
].
string
);
if
((
yyvsp
[
-
1
].
value_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
insertion
.
values
.
swap
(
*
(
yyvsp
[
-
1
].
value_list
));
(
yyval
.
command
)
->
insertion
.
values
.
swap
(
*
(
yyvsp
[
-
1
].
value_list
));
}
(
yyval
.
query
)
->
insertion
.
values
.
emplace_back
(
*
(
yyvsp
[
-
2
].
value
));
std
::
reverse
((
yyval
.
query
)
->
insertion
.
values
.
begin
(),
(
yyval
.
query
)
->
insertion
.
values
.
end
());
(
yyval
.
command
)
->
insertion
.
values
.
emplace_back
(
*
(
yyvsp
[
-
2
].
value
));
std
::
reverse
((
yyval
.
command
)
->
insertion
.
values
.
begin
(),
(
yyval
.
command
)
->
insertion
.
values
.
end
());
delete
(
yyvsp
[
-
2
].
value
);
free
((
yyvsp
[
-
5
].
string
));
}
#line 18
61
"yacc_sql.cpp"
#line 18
55
"yacc_sql.cpp"
break
;
case
42
:
/* value_list: %empty */
#line 3
35
"yacc_sql.y"
#line 3
27
"yacc_sql.y"
{
(
yyval
.
value_list
)
=
nullptr
;
}
#line 186
9
"yacc_sql.cpp"
#line 186
3
"yacc_sql.cpp"
break
;
case
43
:
/* value_list: COMMA value value_list */
#line 33
8
"yacc_sql.y"
#line 33
0
"yacc_sql.y"
{
if
((
yyvsp
[
0
].
value_list
)
!=
nullptr
)
{
(
yyval
.
value_list
)
=
(
yyvsp
[
0
].
value_list
);
...
...
@@ -1879,98 +1873,98 @@ yyreduce:
(
yyval
.
value_list
)
->
emplace_back
(
*
(
yyvsp
[
-
1
].
value
));
delete
(
yyvsp
[
-
1
].
value
);
}
#line 18
83
"yacc_sql.cpp"
#line 18
77
"yacc_sql.cpp"
break
;
case
44
:
/* value: NUMBER */
#line 34
9
"yacc_sql.y"
#line 34
1
"yacc_sql.y"
{
(
yyval
.
value
)
=
new
Value
;
(
yyval
.
value
)
->
type
=
INTS
;
(
yyval
.
value
)
->
int_value
=
(
yyvsp
[
0
].
number
);
}
#line 18
93
"yacc_sql.cpp"
#line 18
87
"yacc_sql.cpp"
break
;
case
45
:
/* value: FLOAT */
#line 3
54
"yacc_sql.y"
#line 3
46
"yacc_sql.y"
{
(
yyval
.
value
)
=
new
Value
;
(
yyval
.
value
)
->
type
=
FLOATS
;
(
yyval
.
value
)
->
float_value
=
(
yyvsp
[
0
].
floats
);
}
#line 1
903
"yacc_sql.cpp"
#line 1
897
"yacc_sql.cpp"
break
;
case
46
:
/* value: SSS */
#line 35
9
"yacc_sql.y"
#line 35
1
"yacc_sql.y"
{
char
*
tmp
=
substr
((
yyvsp
[
0
].
string
),
1
,
strlen
((
yyvsp
[
0
].
string
))
-
2
);
char
*
tmp
=
common
::
substr
((
yyvsp
[
0
].
string
),
1
,
strlen
((
yyvsp
[
0
].
string
))
-
2
);
(
yyval
.
value
)
=
new
Value
;
(
yyval
.
value
)
->
type
=
CHARS
;
(
yyval
.
value
)
->
string_value
=
tmp
;
free
(
tmp
);
}
#line 19
15
"yacc_sql.cpp"
#line 19
09
"yacc_sql.cpp"
break
;
case
47
:
/* delete: DELETE FROM ID where */
#line 3
70
"yacc_sql.y"
#line 3
62
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_DELETE
);
(
yyval
.
query
)
->
deletion
.
relation_name
=
(
yyvsp
[
-
1
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_DELETE
);
(
yyval
.
command
)
->
deletion
.
relation_name
=
(
yyvsp
[
-
1
].
string
);
if
((
yyvsp
[
0
].
condition_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
deletion
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
(
yyval
.
command
)
->
deletion
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
delete
(
yyvsp
[
0
].
condition_list
);
}
free
((
yyvsp
[
-
1
].
string
));
}
#line 192
9
"yacc_sql.cpp"
#line 192
3
"yacc_sql.cpp"
break
;
case
48
:
/* update: UPDATE ID SET ID EQ value where */
#line 3
82
"yacc_sql.y"
#line 3
74
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_UPDATE
);
(
yyval
.
query
)
->
update
.
relation_name
=
(
yyvsp
[
-
5
].
string
);
(
yyval
.
query
)
->
update
.
attribute_name
=
(
yyvsp
[
-
3
].
string
);
(
yyval
.
query
)
->
update
.
value
=
*
(
yyvsp
[
-
1
].
value
);
(
yyval
.
command
)
=
new
Command
(
SCF_UPDATE
);
(
yyval
.
command
)
->
update
.
relation_name
=
(
yyvsp
[
-
5
].
string
);
(
yyval
.
command
)
->
update
.
attribute_name
=
(
yyvsp
[
-
3
].
string
);
(
yyval
.
command
)
->
update
.
value
=
*
(
yyvsp
[
-
1
].
value
);
if
((
yyvsp
[
0
].
condition_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
update
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
(
yyval
.
command
)
->
update
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
delete
(
yyvsp
[
0
].
condition_list
);
}
free
((
yyvsp
[
-
5
].
string
));
free
((
yyvsp
[
-
3
].
string
));
}
#line 194
6
"yacc_sql.cpp"
#line 194
0
"yacc_sql.cpp"
break
;
case
49
:
/* select: SELECT select_attr FROM ID rel_list where */
#line 3
97
"yacc_sql.y"
#line 3
89
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_SELECT
);
(
yyval
.
command
)
=
new
Command
(
SCF_SELECT
);
if
((
yyvsp
[
-
4
].
rel_attr_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
selection
.
attributes
.
swap
(
*
(
yyvsp
[
-
4
].
rel_attr_list
));
(
yyval
.
command
)
->
selection
.
attributes
.
swap
(
*
(
yyvsp
[
-
4
].
rel_attr_list
));
delete
(
yyvsp
[
-
4
].
rel_attr_list
);
}
if
((
yyvsp
[
-
1
].
relation_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
selection
.
relations
.
swap
(
*
(
yyvsp
[
-
1
].
relation_list
));
(
yyval
.
command
)
->
selection
.
relations
.
swap
(
*
(
yyvsp
[
-
1
].
relation_list
));
delete
(
yyvsp
[
-
1
].
relation_list
);
}
(
yyval
.
query
)
->
selection
.
relations
.
push_back
((
yyvsp
[
-
2
].
string
));
std
::
reverse
((
yyval
.
query
)
->
selection
.
relations
.
begin
(),
(
yyval
.
query
)
->
selection
.
relations
.
end
());
(
yyval
.
command
)
->
selection
.
relations
.
push_back
((
yyvsp
[
-
2
].
string
));
std
::
reverse
((
yyval
.
command
)
->
selection
.
relations
.
begin
(),
(
yyval
.
command
)
->
selection
.
relations
.
end
());
if
((
yyvsp
[
0
].
condition_list
)
!=
nullptr
)
{
(
yyval
.
query
)
->
selection
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
(
yyval
.
command
)
->
selection
.
conditions
.
swap
(
*
(
yyvsp
[
0
].
condition_list
));
delete
(
yyvsp
[
0
].
condition_list
);
}
free
((
yyvsp
[
-
2
].
string
));
}
#line 19
70
"yacc_sql.cpp"
#line 19
64
"yacc_sql.cpp"
break
;
case
50
:
/* select_attr: STAR */
#line 41
9
"yacc_sql.y"
#line 41
1
"yacc_sql.y"
{
(
yyval
.
rel_attr_list
)
=
new
std
::
vector
<
RelAttr
>
;
RelAttr
attr
;
...
...
@@ -1978,11 +1972,11 @@ yyreduce:
attr
.
attribute_name
=
"*"
;
(
yyval
.
rel_attr_list
)
->
emplace_back
(
attr
);
}
#line 19
82
"yacc_sql.cpp"
#line 19
76
"yacc_sql.cpp"
break
;
case
51
:
/* select_attr: rel_attr attr_list */
#line 4
26
"yacc_sql.y"
#line 4
18
"yacc_sql.y"
{
if
((
yyvsp
[
0
].
rel_attr_list
)
!=
nullptr
)
{
(
yyval
.
rel_attr_list
)
=
(
yyvsp
[
0
].
rel_attr_list
);
...
...
@@ -1992,21 +1986,21 @@ yyreduce:
(
yyval
.
rel_attr_list
)
->
emplace_back
(
*
(
yyvsp
[
-
1
].
rel_attr
));
delete
(
yyvsp
[
-
1
].
rel_attr
);
}
#line 199
6
"yacc_sql.cpp"
#line 199
0
"yacc_sql.cpp"
break
;
case
52
:
/* rel_attr: ID */
#line 43
8
"yacc_sql.y"
#line 43
0
"yacc_sql.y"
{
(
yyval
.
rel_attr
)
=
new
RelAttr
;
(
yyval
.
rel_attr
)
->
attribute_name
=
(
yyvsp
[
0
].
string
);
free
((
yyvsp
[
0
].
string
));
}
#line 200
6
"yacc_sql.cpp"
#line 200
0
"yacc_sql.cpp"
break
;
case
53
:
/* rel_attr: ID DOT ID */
#line 4
43
"yacc_sql.y"
#line 4
35
"yacc_sql.y"
{
(
yyval
.
rel_attr
)
=
new
RelAttr
;
(
yyval
.
rel_attr
)
->
relation_name
=
(
yyvsp
[
-
2
].
string
);
...
...
@@ -2014,19 +2008,19 @@ yyreduce:
free
((
yyvsp
[
-
2
].
string
));
free
((
yyvsp
[
0
].
string
));
}
#line 201
8
"yacc_sql.cpp"
#line 201
2
"yacc_sql.cpp"
break
;
case
54
:
/* attr_list: %empty */
#line 4
54
"yacc_sql.y"
#line 4
46
"yacc_sql.y"
{
(
yyval
.
rel_attr_list
)
=
nullptr
;
}
#line 202
6
"yacc_sql.cpp"
#line 202
0
"yacc_sql.cpp"
break
;
case
55
:
/* attr_list: COMMA rel_attr attr_list */
#line 4
57
"yacc_sql.y"
#line 4
49
"yacc_sql.y"
{
if
((
yyvsp
[
0
].
rel_attr_list
)
!=
nullptr
)
{
(
yyval
.
rel_attr_list
)
=
(
yyvsp
[
0
].
rel_attr_list
);
...
...
@@ -2037,19 +2031,19 @@ yyreduce:
(
yyval
.
rel_attr_list
)
->
emplace_back
(
*
(
yyvsp
[
-
1
].
rel_attr
));
delete
(
yyvsp
[
-
1
].
rel_attr
);
}
#line 20
41
"yacc_sql.cpp"
#line 20
35
"yacc_sql.cpp"
break
;
case
56
:
/* rel_list: %empty */
#line 4
71
"yacc_sql.y"
#line 4
63
"yacc_sql.y"
{
(
yyval
.
relation_list
)
=
nullptr
;
}
#line 204
9
"yacc_sql.cpp"
#line 204
3
"yacc_sql.cpp"
break
;
case
57
:
/* rel_list: COMMA ID rel_list */
#line 4
74
"yacc_sql.y"
#line 4
66
"yacc_sql.y"
{
if
((
yyvsp
[
0
].
relation_list
)
!=
nullptr
)
{
(
yyval
.
relation_list
)
=
(
yyvsp
[
0
].
relation_list
);
...
...
@@ -2060,55 +2054,55 @@ yyreduce:
(
yyval
.
relation_list
)
->
push_back
((
yyvsp
[
-
1
].
string
));
free
((
yyvsp
[
-
1
].
string
));
}
#line 20
64
"yacc_sql.cpp"
#line 20
58
"yacc_sql.cpp"
break
;
case
58
:
/* where: %empty */
#line 4
87
"yacc_sql.y"
#line 4
79
"yacc_sql.y"
{
(
yyval
.
condition_list
)
=
nullptr
;
}
#line 20
72
"yacc_sql.cpp"
#line 20
66
"yacc_sql.cpp"
break
;
case
59
:
/* where: WHERE condition_list */
#line 4
90
"yacc_sql.y"
#line 4
82
"yacc_sql.y"
{
(
yyval
.
condition_list
)
=
(
yyvsp
[
0
].
condition_list
);
}
#line 20
80
"yacc_sql.cpp"
#line 20
74
"yacc_sql.cpp"
break
;
case
60
:
/* condition_list: %empty */
#line 4
96
"yacc_sql.y"
#line 4
88
"yacc_sql.y"
{
(
yyval
.
condition_list
)
=
nullptr
;
}
#line 208
8
"yacc_sql.cpp"
#line 208
2
"yacc_sql.cpp"
break
;
case
61
:
/* condition_list: condition */
#line 49
9
"yacc_sql.y"
#line 49
1
"yacc_sql.y"
{
(
yyval
.
condition_list
)
=
new
std
::
vector
<
Condition
>
;
(
yyval
.
condition_list
)
->
emplace_back
(
*
(
yyvsp
[
0
].
condition
));
delete
(
yyvsp
[
0
].
condition
);
}
#line 209
8
"yacc_sql.cpp"
#line 209
2
"yacc_sql.cpp"
break
;
case
62
:
/* condition_list: condition AND condition_list */
#line
504
"yacc_sql.y"
#line
496
"yacc_sql.y"
{
(
yyval
.
condition_list
)
=
(
yyvsp
[
0
].
condition_list
);
(
yyval
.
condition_list
)
->
emplace_back
(
*
(
yyvsp
[
-
2
].
condition
));
delete
(
yyvsp
[
-
2
].
condition
);
}
#line 210
8
"yacc_sql.cpp"
#line 210
2
"yacc_sql.cpp"
break
;
case
63
:
/* condition: rel_attr comp_op value */
#line 5
12
"yacc_sql.y"
#line 5
04
"yacc_sql.y"
{
(
yyval
.
condition
)
=
new
Condition
;
(
yyval
.
condition
)
->
left_is_attr
=
1
;
...
...
@@ -2120,11 +2114,11 @@ yyreduce:
delete
(
yyvsp
[
-
2
].
rel_attr
);
delete
(
yyvsp
[
0
].
value
);
}
#line 21
24
"yacc_sql.cpp"
#line 21
18
"yacc_sql.cpp"
break
;
case
64
:
/* condition: value comp_op value */
#line 5
24
"yacc_sql.y"
#line 5
16
"yacc_sql.y"
{
(
yyval
.
condition
)
=
new
Condition
;
(
yyval
.
condition
)
->
left_is_attr
=
0
;
...
...
@@ -2136,11 +2130,11 @@ yyreduce:
delete
(
yyvsp
[
-
2
].
value
);
delete
(
yyvsp
[
0
].
value
);
}
#line 21
40
"yacc_sql.cpp"
#line 21
34
"yacc_sql.cpp"
break
;
case
65
:
/* condition: rel_attr comp_op rel_attr */
#line 5
36
"yacc_sql.y"
#line 5
28
"yacc_sql.y"
{
(
yyval
.
condition
)
=
new
Condition
;
(
yyval
.
condition
)
->
left_is_attr
=
1
;
...
...
@@ -2152,11 +2146,11 @@ yyreduce:
delete
(
yyvsp
[
-
2
].
rel_attr
);
delete
(
yyvsp
[
0
].
rel_attr
);
}
#line 215
6
"yacc_sql.cpp"
#line 215
0
"yacc_sql.cpp"
break
;
case
66
:
/* condition: value comp_op rel_attr */
#line 54
8
"yacc_sql.y"
#line 54
0
"yacc_sql.y"
{
(
yyval
.
condition
)
=
new
Condition
;
(
yyval
.
condition
)
->
left_is_attr
=
0
;
...
...
@@ -2168,67 +2162,67 @@ yyreduce:
delete
(
yyvsp
[
-
2
].
value
);
delete
(
yyvsp
[
0
].
rel_attr
);
}
#line 21
72
"yacc_sql.cpp"
#line 21
66
"yacc_sql.cpp"
break
;
case
67
:
/* comp_op: EQ */
#line 5
62
"yacc_sql.y"
#line 5
54
"yacc_sql.y"
{
(
yyval
.
comp
)
=
EQUAL_TO
;
}
#line 217
8
"yacc_sql.cpp"
#line 217
2
"yacc_sql.cpp"
break
;
case
68
:
/* comp_op: LT */
#line 5
63
"yacc_sql.y"
#line 5
55
"yacc_sql.y"
{
(
yyval
.
comp
)
=
LESS_THAN
;
}
#line 21
84
"yacc_sql.cpp"
#line 21
78
"yacc_sql.cpp"
break
;
case
69
:
/* comp_op: GT */
#line 5
64
"yacc_sql.y"
#line 5
56
"yacc_sql.y"
{
(
yyval
.
comp
)
=
GREAT_THAN
;
}
#line 21
90
"yacc_sql.cpp"
#line 21
84
"yacc_sql.cpp"
break
;
case
70
:
/* comp_op: LE */
#line 5
65
"yacc_sql.y"
#line 5
57
"yacc_sql.y"
{
(
yyval
.
comp
)
=
LESS_EQUAL
;
}
#line 219
6
"yacc_sql.cpp"
#line 219
0
"yacc_sql.cpp"
break
;
case
71
:
/* comp_op: GE */
#line 5
66
"yacc_sql.y"
#line 5
58
"yacc_sql.y"
{
(
yyval
.
comp
)
=
GREAT_EQUAL
;
}
#line 2
202
"yacc_sql.cpp"
#line 2
196
"yacc_sql.cpp"
break
;
case
72
:
/* comp_op: NE */
#line 5
67
"yacc_sql.y"
#line 5
59
"yacc_sql.y"
{
(
yyval
.
comp
)
=
NOT_EQUAL
;
}
#line 220
8
"yacc_sql.cpp"
#line 220
2
"yacc_sql.cpp"
break
;
case
73
:
/* load_data: LOAD DATA INFILE SSS INTO TABLE ID */
#line 5
72
"yacc_sql.y"
#line 5
64
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_LOAD_DATA
);
(
yyval
.
query
)
->
load_data
.
relation_name
=
(
yyvsp
[
0
].
string
);
(
yyval
.
query
)
->
load_data
.
file_name
=
(
yyvsp
[
-
3
].
string
);
(
yyval
.
command
)
=
new
Command
(
SCF_LOAD_DATA
);
(
yyval
.
command
)
->
load_data
.
relation_name
=
(
yyvsp
[
0
].
string
);
(
yyval
.
command
)
->
load_data
.
file_name
=
(
yyvsp
[
-
3
].
string
);
free
((
yyvsp
[
0
].
string
));
}
#line 221
9
"yacc_sql.cpp"
#line 221
3
"yacc_sql.cpp"
break
;
case
74
:
/* explain: EXPLAIN command */
#line 5
82
"yacc_sql.y"
case
74
:
/* explain: EXPLAIN command
_wrapper
*/
#line 5
74
"yacc_sql.y"
{
(
yyval
.
query
)
=
new
Query
(
SCF_EXPLAIN
);
(
yyval
.
query
)
->
explain
.
query
=
std
::
unique_ptr
<
Query
>
((
yyvsp
[
0
].
query
));
(
yyval
.
command
)
=
new
Command
(
SCF_EXPLAIN
);
(
yyval
.
command
)
->
explain
.
cmd
=
std
::
unique_ptr
<
Command
>
((
yyvsp
[
0
].
command
));
}
#line 222
8
"yacc_sql.cpp"
#line 222
2
"yacc_sql.cpp"
break
;
#line 22
32
"yacc_sql.cpp"
#line 22
26
"yacc_sql.cpp"
default:
break
;
}
...
...
@@ -2458,7 +2452,7 @@ yyreturn:
return
yyresult
;
}
#line 5
91
"yacc_sql.y"
#line 5
83
"yacc_sql.y"
//_____________________________________________________________________
extern
void
scan_string
(
const
char
*
str
,
yyscan_t
scanner
);
...
...
src/observer/sql/parser/yacc_sql.hpp
浏览文件 @
ab89b1d5
...
...
@@ -111,9 +111,9 @@ extern int yydebug;
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union
YYSTYPE
{
#line
8
9 "yacc_sql.y"
#line
7
9 "yacc_sql.y"
Query
*
query
;
Command
*
command
;
Condition
*
condition
;
Value
*
value
;
enum
CompOp
comp
;
...
...
src/observer/sql/parser/yacc_sql.y
浏览文件 @
ab89b1d5
%{
#include "sql/parser/parse_defs.h"
#include "sql/parser/yacc_sql.hpp"
#include "sql/parser/lex_sql.h"
#include "common/log/log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
//获取子串
char *substr(const char *s,int n1,int n2)/*从s中提取下标为n1~n2的字符组成一个新字符串,然后返回这个新串的首地址*/
{
char *sp = (char *)malloc(sizeof(char) * (n2 - n1 + 2));
int i, j = 0;
for (i = n1; i <= n2; i++) {
sp[j++] = s[i];
}
sp[j] = 0;
return sp;
}
#include "common/log/log.h"
#include "common/lang/string.h"
#include "sql/parser/parse_defs.h"
#include "sql/parser/yacc_sql.hpp"
#include "sql/parser/lex_sql.h"
int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const char *msg)
{
std::unique_ptr<
Query> error_query = std::make_unique<Query
>(SCF_ERROR);
error_
query
->error.error_msg = msg;
error_
query
->error.line = llocp->first_line;
error_
query
->error.column = llocp->first_column;
sql_result->add_command(std::move(error_
query
));
std::unique_ptr<
Command> error_cmd = std::make_unique<Command
>(SCF_ERROR);
error_
cmd
->error.error_msg = msg;
error_
cmd
->error.line = llocp->first_line;
error_
cmd
->error.column = llocp->first_column;
sql_result->add_command(std::move(error_
cmd
));
return 0;
}
...
...
@@ -87,7 +77,7 @@ int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const
NE
%union {
Query *query
;
Command *command
;
Condition *condition;
Value *value;
enum CompOp comp;
...
...
@@ -126,37 +116,37 @@ int yyerror(YYLTYPE *llocp, ParsedSqlResult *sql_result, yyscan_t scanner, const
%type <rel_attr_list> select_attr
%type <relation_list> rel_list
%type <rel_attr_list> attr_list
%type <
query
> select
%type <
query
> insert
%type <
query
> update
%type <
query
> delete
%type <
query
> create_table
%type <
query
> drop_table
%type <
query
> show_tables
%type <
query
> desc_table
%type <
query
> create_index
%type <
query
> drop_index
%type <
query
> sync
%type <
query
> begin
%type <
query
> commit
%type <
query
> rollback
%type <
query
> load_data
%type <
query
> explain
%type <
query
> help
%type <
query
> exit
%type <
query> command
%type <
command
> select
%type <
command
> insert
%type <
command
> update
%type <
command
> delete
%type <
command
> create_table
%type <
command
> drop_table
%type <
command
> show_tables
%type <
command
> desc_table
%type <
command
> create_index
%type <
command
> drop_index
%type <
command
> sync
%type <
command
> begin
%type <
command
> commit
%type <
command
> rollback
%type <
command
> load_data
%type <
command
> explain
%type <
command
> help
%type <
command
> exit
%type <
command> command_wrapper
// commands should be a list but I use a single command instead
%type <
query
> commands
%type <
command
> commands
%%
commands: command opt_semicolon //commands or sqls. parser starts here.
commands: command
_wrapper
opt_semicolon //commands or sqls. parser starts here.
{
std::unique_ptr<
Query> query_command = std::unique_ptr<Query
>($1);
sql_result->add_command(std::move(
query
_command));
std::unique_ptr<
Command> sql_command = std::unique_ptr<Command
>($1);
sql_result->add_command(std::move(
sql
_command));
}
;
command:
command
_wrapper
:
select
| insert
| update
...
...
@@ -179,54 +169,54 @@ command:
exit:
EXIT {
$$ = new
Query
(SCF_EXIT);
$$ = new
Command
(SCF_EXIT);
};
help:
HELP {
$$ = new
Query
(SCF_HELP);
$$ = new
Command
(SCF_HELP);
};
sync:
SYNC {
$$ = new
Query
(SCF_SYNC);
$$ = new
Command
(SCF_SYNC);
}
;
begin:
TRX_BEGIN {
$$ = new
Query
(SCF_BEGIN);
$$ = new
Command
(SCF_BEGIN);
}
;
commit:
TRX_COMMIT {
$$ = new
Query
(SCF_COMMIT);
$$ = new
Command
(SCF_COMMIT);
}
;
rollback:
TRX_ROLLBACK {
$$ = new
Query
(SCF_ROLLBACK);
$$ = new
Command
(SCF_ROLLBACK);
}
;
drop_table: /*drop table 语句的语法解析树*/
DROP TABLE ID {
$$ = new
Query
(SCF_DROP_TABLE);
$$ = new
Command
(SCF_DROP_TABLE);
$$->drop_table.relation_name = $3;
free($3);
};
show_tables:
SHOW TABLES {
$$ = new
Query
(SCF_SHOW_TABLES);
$$ = new
Command
(SCF_SHOW_TABLES);
}
;
desc_table:
DESC ID {
$$ = new
Query
(SCF_DESC_TABLE);
$$ = new
Command
(SCF_DESC_TABLE);
$$->desc_table.relation_name = $2;
free($2);
}
...
...
@@ -235,7 +225,7 @@ desc_table:
create_index: /*create index 语句的语法解析树*/
CREATE INDEX ID ON ID LBRACE ID RBRACE
{
$$ = new
Query
(SCF_CREATE_INDEX);
$$ = new
Command
(SCF_CREATE_INDEX);
CreateIndex &create_index = $$->create_index;
create_index.index_name = $3;
create_index.relation_name = $5;
...
...
@@ -247,17 +237,19 @@ create_index: /*create index 语句的语法解析树*/
;
drop_index: /*drop index 语句的语法解析树*/
DROP INDEX ID
DROP INDEX ID
ON ID
{
$$ = new
Query
(SCF_DROP_INDEX);
$$ = new
Command
(SCF_DROP_INDEX);
$$->drop_index.index_name = $3;
$$->drop_index.relation_name = $5;
free($3);
free($5);
}
;
create_table: /*create table 语句的语法解析树*/
CREATE TABLE ID LBRACE attr_def attr_def_list RBRACE
{
$$ = new
Query
(SCF_CREATE_TABLE);
$$ = new
Command
(SCF_CREATE_TABLE);
CreateTable &create_table = $$->create_table;
create_table.relation_name = $3;
free($3);
...
...
@@ -318,7 +310,7 @@ type:
insert: /*insert 语句的语法解析树*/
INSERT INTO ID VALUES LBRACE value value_list RBRACE
{
$$ = new
Query
(SCF_INSERT);
$$ = new
Command
(SCF_INSERT);
$$->insertion.relation_name = $3;
if ($7 != nullptr) {
$$->insertion.values.swap(*$7);
...
...
@@ -357,7 +349,7 @@ value:
$$->float_value = $1;
}
|SSS {
char *tmp = substr($1,1,strlen($1)-2);
char *tmp =
common::
substr($1,1,strlen($1)-2);
$$ = new Value;
$$->type = CHARS;
$$->string_value = tmp;
...
...
@@ -368,7 +360,7 @@ value:
delete: /* delete 语句的语法解析树*/
DELETE FROM ID where
{
$$ = new
Query
(SCF_DELETE);
$$ = new
Command
(SCF_DELETE);
$$->deletion.relation_name = $3;
if ($4 != nullptr) {
$$->deletion.conditions.swap(*$4);
...
...
@@ -380,7 +372,7 @@ delete: /* delete 语句的语法解析树*/
update: /* update 语句的语法解析树*/
UPDATE ID SET ID EQ value where
{
$$ = new
Query
(SCF_UPDATE);
$$ = new
Command
(SCF_UPDATE);
$$->update.relation_name = $2;
$$->update.attribute_name = $4;
$$->update.value = *$6;
...
...
@@ -395,7 +387,7 @@ update: /* update 语句的语法解析树*/
select: /* select 语句的语法解析树*/
SELECT select_attr FROM ID rel_list where
{
$$ = new
Query
(SCF_SELECT);
$$ = new
Command
(SCF_SELECT);
if ($2 != nullptr) {
$$->selection.attributes.swap(*$2);
delete $2;
...
...
@@ -570,7 +562,7 @@ comp_op:
load_data:
LOAD DATA INFILE SSS INTO TABLE ID
{
$$ = new
Query
(SCF_LOAD_DATA);
$$ = new
Command
(SCF_LOAD_DATA);
$$->load_data.relation_name = $7;
$$->load_data.file_name = $4;
free($7);
...
...
@@ -578,10 +570,10 @@ load_data:
;
explain:
EXPLAIN command
EXPLAIN command
_wrapper
{
$$ = new
Query
(SCF_EXPLAIN);
$$->explain.
query = std::unique_ptr<Query
>($2);
$$ = new
Command
(SCF_EXPLAIN);
$$->explain.
cmd = std::unique_ptr<Command
>($2);
}
;
...
...
src/observer/sql/stmt/explain_stmt.cpp
浏览文件 @
ab89b1d5
...
...
@@ -23,7 +23,7 @@ ExplainStmt::ExplainStmt(std::unique_ptr<Stmt> child_stmt)
RC
ExplainStmt
::
create
(
Db
*
db
,
const
Explain
&
explain
,
Stmt
*&
stmt
)
{
Stmt
*
child_stmt
=
nullptr
;
RC
rc
=
Stmt
::
create_stmt
(
db
,
*
explain
.
query
,
child_stmt
);
RC
rc
=
Stmt
::
create_stmt
(
db
,
*
explain
.
cmd
,
child_stmt
);
if
(
rc
!=
RC
::
SUCCESS
)
{
LOG_WARN
(
"failed to create explain's child stmt. rc=%s"
,
strrc
(
rc
));
return
rc
;
...
...
src/observer/sql/stmt/stmt.cpp
浏览文件 @
ab89b1d5
...
...
@@ -19,26 +19,26 @@ See the Mulan PSL v2 for more details. */
#include "sql/stmt/select_stmt.h"
#include "sql/stmt/explain_stmt.h"
RC
Stmt
::
create_stmt
(
Db
*
db
,
const
Query
&
query
,
Stmt
*&
stmt
)
RC
Stmt
::
create_stmt
(
Db
*
db
,
const
Command
&
cmd
,
Stmt
*&
stmt
)
{
stmt
=
nullptr
;
switch
(
query
.
flag
)
{
switch
(
cmd
.
flag
)
{
case
SCF_INSERT
:
{
return
InsertStmt
::
create
(
db
,
query
.
insertion
,
stmt
);
return
InsertStmt
::
create
(
db
,
cmd
.
insertion
,
stmt
);
}
case
SCF_DELETE
:
{
return
DeleteStmt
::
create
(
db
,
query
.
deletion
,
stmt
);
return
DeleteStmt
::
create
(
db
,
cmd
.
deletion
,
stmt
);
}
case
SCF_SELECT
:
{
return
SelectStmt
::
create
(
db
,
query
.
selection
,
stmt
);
return
SelectStmt
::
create
(
db
,
cmd
.
selection
,
stmt
);
}
case
SCF_EXPLAIN
:
{
return
ExplainStmt
::
create
(
db
,
query
.
explain
,
stmt
);
return
ExplainStmt
::
create
(
db
,
cmd
.
explain
,
stmt
);
}
default:
{
LOG_
WARN
(
"unknown query command"
);
LOG_
INFO
(
"Command::type %d doesn't need to create statement."
,
cmd
.
flag
);
}
break
;
}
...
...
src/observer/sql/stmt/stmt.h
浏览文件 @
ab89b1d5
...
...
@@ -53,7 +53,7 @@ public:
virtual
StmtType
type
()
const
=
0
;
public:
static
RC
create_stmt
(
Db
*
db
,
const
Query
&
query
,
Stmt
*&
stmt
);
static
RC
create_stmt
(
Db
*
db
,
const
Command
&
cmd
,
Stmt
*&
stmt
);
private:
};
...
...
src/observer/storage/default/default_storage_stage.cpp
浏览文件 @
ab89b1d5
...
...
@@ -144,7 +144,7 @@ void DefaultStorageStage::handle_event(StageEvent *event)
SQLStageEvent
*
sql_event
=
static_cast
<
SQLStageEvent
*>
(
event
);
Query
*
sql
=
sql_event
->
query
().
get
();
Command
*
cmd
=
sql_event
->
command
().
get
();
SessionEvent
*
session_event
=
sql_event
->
session_event
();
...
...
@@ -157,19 +157,19 @@ void DefaultStorageStage::handle_event(StageEvent *event)
RC
rc
=
RC
::
SUCCESS
;
char
response
[
256
];
switch
(
sql
->
flag
)
{
switch
(
cmd
->
flag
)
{
case
SCF_LOAD_DATA
:
{
/*
从文件导入数据,如果做性能测试,需要保持这些代码可以正常工作
load data infile `your/file/path` into table `table-name`;
*/
const
char
*
table_name
=
sql
->
load_data
.
relation_name
.
c_str
();
const
char
*
file_name
=
sql
->
load_data
.
file_name
.
c_str
();
const
char
*
table_name
=
cmd
->
load_data
.
relation_name
.
c_str
();
const
char
*
file_name
=
cmd
->
load_data
.
file_name
.
c_str
();
std
::
string
result
=
load_data
(
dbname
,
table_name
,
file_name
);
snprintf
(
response
,
sizeof
(
response
),
"%s"
,
result
.
c_str
());
}
break
;
default:
snprintf
(
response
,
sizeof
(
response
),
"Unsupported sql: %d
\n
"
,
sql
->
flag
);
snprintf
(
response
,
sizeof
(
response
),
"Unsupported sql: %d
\n
"
,
cmd
->
flag
);
break
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录