Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(parser): add create log file group sql parser. #205

Merged
merged 4 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 61 additions & 2 deletions pisa-proxy/parser/mysql/src/ast/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use crate::ast::{base::*, FieldType, SelectStmt};
pub enum Create {
CreateDatabase(Box<CreateDatabase>),
CreateViewOrTriggerOrSpOrEvent(Box<ViewOrTriggerOrSpOrEvent>),
CreateLogFileGroup(Box<CreateLogFileGroup>),
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -261,7 +262,7 @@ pub enum SpatialIndexOption {
#[derive(Debug, Clone)]
pub enum CommonIndexOption {
KeyBlockSizeOption(KeyBlockSizeOption),
CommentOption(CommentOption),
CommentOption(IndexCommentOption),
Visibility(Visibility),
AttributeOption(AttributeOption),
}
Expand All @@ -274,7 +275,7 @@ pub struct KeyBlockSizeOption {
}

#[derive(Debug, Clone)]
pub struct CommentOption {
pub struct IndexCommentOption {
pub span: Span,
pub comment: String,
}
Expand Down Expand Up @@ -325,3 +326,61 @@ pub struct KeyPart {
pub length: Option<u32>,
pub direction: Option<String>,
}

#[derive(Debug, Clone)]
pub struct CreateLogFileGroup {
pub span: Span,
pub logfile_group: String,
pub undo_file: UndoFile,
pub opt_logfile_group_options: Option<Vec<LogFileGroupOption>>,
}

#[derive(Debug, Clone)]
pub struct UndoFile {
pub span: Span,
pub file_name: String,
}

#[derive(Debug, Clone)]
pub enum LogFileGroupOption {
SizeOption(SizeOption),
NodeGroupOption(NodeGroupOption),
CommentOption(CommentOption),
EngineOption(EngineOption),
WaitOption(WaitOption),
}

#[derive(Debug, Clone)]
pub struct SizeOption {
pub span: Span,
pub is_equal: bool,
pub size: String,
}

#[derive(Debug, Clone)]
pub struct NodeGroupOption {
pub span: Span,
pub is_equal: bool,
pub nodegroup_id: String,
}

#[derive(Debug, Clone)]
pub struct CommentOption {
pub span: Span,
pub is_equal: bool,
pub comment: String,
}

#[derive(Debug, Clone)]
pub struct EngineOption {
pub span: Span,
pub opt_storage: bool,
pub is_equal: bool,
pub engine_name: String,
}

#[derive(Debug, Clone)]
pub enum WaitOption {
Wait,
NoWait,
}
201 changes: 184 additions & 17 deletions pisa-proxy/parser/mysql/src/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -6376,22 +6376,37 @@ opt_savepoint -> bool:
;

create -> Create:
'CREATE' 'DATABASE' opt_if_not_exists ident opt_create_database_options
{
Create::CreateDatabase(Box::new(
CreateDatabase{
is_not_exists: $3,
database_name: $4.0,
opt_create_database_options: $5,
}
))
}
| 'CREATE' view_or_trigger_or_sp_or_event
{
Create::CreateViewOrTriggerOrSpOrEvent(Box::new($2))
}
/* TODO */
;
'CREATE' 'DATABASE' opt_if_not_exists ident opt_create_database_options
{
Create::CreateDatabase(Box::new(
CreateDatabase{
is_not_exists: $3,
database_name: $4.0,
opt_create_database_options: $5,
}
))
}
| 'CREATE' view_or_trigger_or_sp_or_event
{
Create::CreateViewOrTriggerOrSpOrEvent(Box::new($2))
}

/* TODO create user */

| 'CREATE' 'LOGFILE' 'GROUP' ident 'ADD' lg_undofile opt_logfile_group_options
{
Create::CreateLogFileGroup(Box::new(
CreateLogFileGroup {
span: $span,
logfile_group: $4.0,
undo_file: $6,
opt_logfile_group_options: $7,
}
))
}

/* TODO */
;

opt_if_not_exists -> bool:
/* empty */ { false }
Expand Down Expand Up @@ -6781,6 +6796,158 @@ sp_suid -> SpSuid:
}
;

lg_undofile -> UndoFile:
'UNDOFILE' 'TEXT_STRING'
{
UndoFile {
span: $span,
file_name: String::from($lexer.span_str($2.as_ref().unwrap().span())),
}
}
;

opt_logfile_group_options -> Option<Vec<LogFileGroupOption>>:
/* empty */ { None }
| logfile_group_option_list
{
Some($1)
}
;

logfile_group_option_list -> Vec<LogFileGroupOption>:
logfile_group_option
{
vec![$1]
}
| logfile_group_option_list opt_comma logfile_group_option
{
$1.push($3);
$1
}
;

opt_comma -> bool:
/* empty */ { false }
| ',' { true }
;

logfile_group_option -> LogFileGroupOption:
ts_option_initial_size { $1 }
| ts_option_undo_buffer_size { $1 }
| ts_option_redo_buffer_size { $1 }
| ts_option_nodegroup { $1 }
| ts_option_engine { $1 }
| ts_option_wait { $1 }
| ts_option_comment { $1 }
;

ts_option_initial_size -> LogFileGroupOption:
'INITIAL_SIZE' opt_equal size_number
{
let is_equal = match $2 {
Some(_) => true,
None => false,
};
LogFileGroupOption::SizeOption(SizeOption {
span: $span,
is_equal: is_equal,
size: $3,
})
}
;

ts_option_undo_buffer_size -> LogFileGroupOption:
'UNDO_BUFFER_SIZE' opt_equal size_number
{
let is_equal = match $2 {
Some(_) => true,
None => false,
};
LogFileGroupOption::SizeOption(SizeOption {
span: $span,
is_equal: is_equal,
size: $3,
})
}
;

ts_option_redo_buffer_size -> LogFileGroupOption:
'REDO_BUFFER_SIZE' opt_equal size_number
{
let is_equal = match $2 {
Some(_) => true,
None => false,
};
LogFileGroupOption::SizeOption(SizeOption {
span: $span,
is_equal: is_equal,
size: $3,
})
}
;

ts_option_nodegroup -> LogFileGroupOption:
'NODEGROUP' opt_equal real_ulong_num
{
let is_equal = match $2 {
Some(_) => true,
None => false,
};
LogFileGroupOption::NodeGroupOption(NodeGroupOption {
span: $span,
is_equal: is_equal,
nodegroup_id: $3,
})
}
;

ts_option_comment -> LogFileGroupOption:
'COMMENT' opt_equal 'TEXT_STRING'
{
let is_equal = match $2 {
Some(_) => true,
None => false,
};
LogFileGroupOption::CommentOption(CommentOption {
span: $span,
is_equal: is_equal,
comment: String::from($lexer.span_str($3.as_ref().unwrap().span())),
})
}
;

ts_option_engine -> LogFileGroupOption:
opt_storage 'ENGINE' opt_equal ident_or_text
{
let is_equal = match $3 {
Some(_) => true,
None => false,
};
LogFileGroupOption::EngineOption(EngineOption {
span: $span,
opt_storage: $1,
is_equal: is_equal,
engine_name: $4,
})
}
;

ts_option_wait -> LogFileGroupOption:
'WAIT'
{
LogFileGroupOption::WaitOption(WaitOption::Wait)
}
| 'NO_WAIT'
{
LogFileGroupOption::WaitOption(WaitOption::NoWait)
}
;

size_number -> String:
real_ulonglong_num { $1 }
| IDENT_sys { $1.0 }
;

create_index_stmt -> CreateIndexStmt:
'CREATE' opt_unique 'INDEX' ident opt_index_type_clause 'ON' table_ident '(' key_list_with_expression ')'
opt_index_options opt_index_lock_and_algorithm
Expand Down Expand Up @@ -7002,7 +7169,7 @@ common_index_option -> CommonIndexOption:
}
| 'COMMENT' TEXT_STRING_sys
{
CommonIndexOption::CommentOption(CommentOption{
CommonIndexOption::CommentOption(IndexCommentOption{
span: $span,
comment: $2,
})
Expand Down
2 changes: 2 additions & 0 deletions pisa-proxy/parser/mysql/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ macro_rules! keyword_size {
"ACCOUNT",
"ACTION",
"ACTIVE",
"ADD",
"ADDDATE",
"ADMIN",
"AFTER",
Expand Down Expand Up @@ -730,6 +731,7 @@ macro_rules! keyword_size {
(T_ACCOUNT, 7),
(T_ACTION, 6),
(T_ACTIVE, 6),
(T_ADD, 3),
(T_ADDDATE, 7),
(T_ADMIN, 5),
(T_AFTER, 5),
Expand Down
2 changes: 2 additions & 0 deletions pisa-proxy/parser/mysql/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ mod test {
"CREATE SPATIAL INDEX idx_order_name ON t_order (name) INVISIBLE;",
"CREATE FULLTEXT INDEX idx_order_name ON t_order (name) WITH PARSER parser_name ALGORITHM DEFAULT;",
"CREATE FULLTEXT INDEX idx_order_name ON t_order (name) WITH PARSER parser_name LOCK = EXCLUSIVE;",
"CREATE LOGFILE GROUP logfile_group ADD UNDOFILE 'undo_file' INITIAL_SIZE = 1M UNDO_BUFFER_SIZE = 2M REDO_BUFFER_SIZE = 3M;",
"CREATE LOGFILE GROUP logfile_group ADD UNDOFILE 'undo_file' NODEGROUP 1234, WAIT, COMMENT 'logfile_group_comment', ENGINE = 'logfile_group_engine';",
];

let p = Parser::new();
Expand Down