forked from databendlabs/databend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.rs
More file actions
130 lines (124 loc) · 4.08 KB
/
Copy pathstream.rs
File metadata and controls
130 lines (124 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use nom::Parser;
use nom_rule::rule;
use crate::ast::CreateStreamStmt;
use crate::ast::DescribeStreamStmt;
use crate::ast::DropStreamStmt;
use crate::ast::ShowStreamsStmt;
use crate::ast::Statement;
use crate::parser::Input;
use crate::parser::common::IResult;
use crate::parser::common::dot_separated_idents_1_to_2;
use crate::parser::common::dot_separated_idents_1_to_3;
use crate::parser::common::map_res;
use crate::parser::common::*;
use crate::parser::expr::literal_bool;
use crate::parser::expr::literal_string;
use crate::parser::query::travel_point;
use crate::parser::statement::parse_create_option;
use crate::parser::statement::show_limit;
use crate::parser::token::TokenKind::*;
pub fn create_stream(i: Input) -> IResult<Statement> {
map_res(
rule! {
CREATE ~ ( OR ~ ^REPLACE )? ~ STREAM ~ ( IF ~ ^NOT ~ ^EXISTS )?
~ #dot_separated_idents_1_to_3
~ ON ~ TABLE ~ #dot_separated_idents_1_to_2
~ ( AT ~ ^#travel_point )?
~ ( APPEND_ONLY ~ "=" ~ #literal_bool )?
~ ( COMMENT ~ "=" ~ #literal_string )?
},
|(
_,
opt_or_replace,
_,
opt_if_not_exists,
(catalog, database, stream),
_,
_,
(table_database, table),
opt_travel_point,
opt_append_only,
opt_comment,
)| {
let create_option =
parse_create_option(opt_or_replace.is_some(), opt_if_not_exists.is_some())?;
Ok(Statement::CreateStream(CreateStreamStmt {
create_option,
catalog,
database,
stream,
table_database,
table,
travel_point: opt_travel_point.map(|p| p.1),
append_only: opt_append_only
.map(|(_, _, append_only)| append_only)
.unwrap_or(true),
comment: opt_comment.map(|(_, _, comment)| comment),
}))
},
)(i)
}
pub fn drop_stream(i: Input) -> IResult<Statement> {
map(
rule! {
DROP ~ STREAM ~ ( IF ~ ^EXISTS )? ~ #dot_separated_idents_1_to_3
},
|(_, _, opt_if_exists, (catalog, database, stream))| {
Statement::DropStream(DropStreamStmt {
if_exists: opt_if_exists.is_some(),
catalog,
database,
stream,
})
},
)
.parse(i)
}
pub fn show_streams(i: Input) -> IResult<Statement> {
map(
rule! {
SHOW ~ FULL? ~ STREAMS ~ ( ( FROM | IN ) ~ #dot_separated_idents_1_to_2 )? ~ #show_limit?
},
|(_, opt_full, _, ctl_db, limit)| {
let (catalog, database) = match ctl_db {
Some((_, (Some(c), d))) => (Some(c), Some(d)),
Some((_, (None, d))) => (None, Some(d)),
_ => (None, None),
};
Statement::ShowStreams(ShowStreamsStmt {
catalog,
database,
full: opt_full.is_some(),
limit,
})
},
).parse(i)
}
pub fn describe_stream(i: Input) -> IResult<Statement> {
map(
rule! {
( DESC | DESCRIBE ) ~ STREAM ~ #dot_separated_idents_1_to_3
},
|(_, _, (catalog, database, stream))| {
Statement::DescribeStream(DescribeStreamStmt {
catalog,
database,
stream,
})
},
)
.parse(i)
}