Skip to content

Commit 5294b61

Browse files
committed
refactor
1 parent d2c2efe commit 5294b61

File tree

6 files changed

+26
-1112
lines changed

6 files changed

+26
-1112
lines changed

src/dds/create_table.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ use nom::IResult;
1212

1313
use base::column::{Column, ColumnSpecification};
1414
use base::table::Table;
15-
use common::{KeyPart, sql_identifier, statement_terminator, ws_sep_comma};
1615
use common::index_option::IndexOption;
1716
use common::table_option::TableOption;
1817
use common::{
1918
opt_index_name, CheckConstraintDefinition, FulltextOrSpatialType, IndexOrKeyType, IndexType,
2019
ReferenceDefinition,
2120
};
21+
use common::{sql_identifier, statement_terminator, ws_sep_comma, KeyPart};
2222

2323
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
2424
pub struct CreateTableStatement {
@@ -178,15 +178,17 @@ fn create_as_query(i: &str) -> IResult<&str, CreateTableStatement, VerboseError<
178178
))),
179179
multispace0,
180180
opt(tag_no_case("AS")),
181-
multispace0,
181+
multispace1,
182+
tag_no_case("SELECT"),
183+
multispace1,
182184
map(rest, |x| String::from(x)),
183185
statement_terminator,
184186
)),
185187
|(x)| {
186188
let table = x.0 .2;
187189
let if_not_exists = x.0 .1;
188190
let temporary = x.0 .0;
189-
let create_type = CreateTableType::AsQuery(x.2, x.4, x.6, x.8, x.12);
191+
let create_type = CreateTableType::AsQuery(x.2, x.4, x.6, x.8, x.14);
190192
CreateTableStatement {
191193
table,
192194
temporary,
@@ -420,7 +422,7 @@ fn primary_key(i: &str) -> IResult<&str, CreateDefinition, VerboseError<&str>> {
420422
tag_no_case("KEY"),
421423
)), // PRIMARY KEY
422424
IndexType::opt_index_type, // [index_type]
423-
KeyPart::key_part_list, // (key_part,...)
425+
KeyPart::key_part_list, // (key_part,...)
424426
IndexOption::opt_index_option, // [index_option]
425427
)),
426428
|(opt_symbol, _, opt_index_type, key_part, opt_index_option)| {
@@ -445,7 +447,7 @@ fn unique(i: &str) -> IResult<&str, CreateDefinition, VerboseError<&str>> {
445447
), // UNIQUE [INDEX | KEY]
446448
opt_index_name, // [index_name]
447449
IndexType::opt_index_type, // [index_type]
448-
KeyPart::key_part_list, // (key_part,...)
450+
KeyPart::key_part_list, // (key_part,...)
449451
IndexOption::opt_index_option, // [index_option]
450452
)),
451453
|(

src/dms/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,3 @@ pub mod delete;
33
pub mod insert;
44
pub mod select;
55
pub mod update;
6-
pub mod zz_create;
7-
mod zz_create_table_options;

src/dms/select.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use nom::sequence::{delimited, terminated, tuple};
1212
use base::column::Column;
1313
use base::FieldDefinitionExpression;
1414
use base::table::Table;
15-
use common::{JoinConstraint, JoinOperator, JoinRightSide, OrderClause, statement_terminator, unsigned_number};
15+
use common::{
16+
JoinConstraint, JoinOperator, JoinRightSide, OrderClause, statement_terminator, unsigned_number,
17+
};
1618
use common::condition::ConditionExpression;
1719

1820
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize)]
@@ -126,7 +128,7 @@ impl GroupByClause {
126128
pub fn parse(i: &str) -> IResult<&str, GroupByClause, VerboseError<&str>> {
127129
let (remaining_input, (_, _, _, columns, having)) = tuple((
128130
multispace0,
129-
tag_no_case("group by"),
131+
tag_no_case("GROUP BY"),
130132
multispace1,
131133
Column::field_list,
132134
opt(ConditionExpression::having_clause),
@@ -166,7 +168,7 @@ impl JoinClause {
166168
pub fn parse(i: &str) -> IResult<&str, JoinClause, VerboseError<&str>> {
167169
let (remaining_input, (_, _natural, operator, _, right, _, constraint)) = tuple((
168170
multispace0,
169-
opt(terminated(tag_no_case("natural"), multispace1)),
171+
opt(terminated(tag_no_case("NATURAL"), multispace1)),
170172
JoinOperator::parse,
171173
multispace1,
172174
JoinRightSide::parse,
@@ -204,15 +206,26 @@ impl LimitClause {
204206
pub fn parse(i: &str) -> IResult<&str, LimitClause, VerboseError<&str>> {
205207
let (remaining_input, (_, _, _, limit, opt_offset)) = tuple((
206208
multispace0,
207-
tag_no_case("limit"),
209+
tag_no_case("LIMIT"),
208210
multispace1,
209211
unsigned_number,
210-
opt(offset),
212+
opt(Self::offset),
211213
))(i)?;
212214
let offset = opt_offset.unwrap_or_else(|| 0);
213215

214216
Ok((remaining_input, LimitClause { limit, offset }))
215217
}
218+
219+
fn offset(i: &str) -> IResult<&str, u64, VerboseError<&str>> {
220+
let (remaining_input, (_, _, _, val)) = tuple((
221+
multispace0,
222+
tag_no_case("OFFSET"),
223+
multispace1,
224+
unsigned_number,
225+
))(i)?;
226+
227+
Ok((remaining_input, val))
228+
}
216229
}
217230

218231
impl fmt::Display for LimitClause {
@@ -225,26 +238,15 @@ impl fmt::Display for LimitClause {
225238
}
226239
}
227240

228-
fn offset(i: &str) -> IResult<&str, u64, VerboseError<&str>> {
229-
let (remaining_input, (_, _, _, val)) = tuple((
230-
multispace0,
231-
tag_no_case("OFFSET"),
232-
multispace1,
233-
unsigned_number,
234-
))(i)?;
235-
236-
Ok((remaining_input, val))
237-
}
238-
239241
#[cfg(test)]
240242
mod tests {
241243
use base::{FieldValueExpression, ItemPlaceholder, Operator};
242244
use base::column::{Column, FunctionArgument, FunctionArguments, FunctionExpression};
243245
use base::Literal;
244246
use base::table::Table;
245247
use common::{JoinConstraint, JoinOperator, JoinRightSide, OrderClause, OrderType};
246-
use common::case::{CaseWhenExpression, ColumnOrLiteral};
247248
use common::arithmetic::{ArithmeticBase, ArithmeticExpression, ArithmeticOperator};
249+
use common::case::{CaseWhenExpression, ColumnOrLiteral};
248250
use common::condition::{ConditionExpression, ConditionTree};
249251
use common::condition::ConditionBase;
250252
use common::condition::ConditionBase::LiteralList;

0 commit comments

Comments
 (0)