How to describe COPY INTO <location> in new planner? #6026
-
I'm working on #5781 now but don't know how to describe the following AST in the new planner: COPY INTO [<database>.]<table_name>
FROM { internalStage | externalStage | externalLocation }
[ FILES = ( '<file_name>' [ , '<file_name>' ] [ , ... ] ) ]
[ PATTERN = '<regex_pattern>' ]
[ FILE_FORMAT = ( TYPE = { CSV | JSON | PARQUET } [ formatTypeOptions ] } ) ]
[ copyOptions ]
COPY INTO { internalStage | externalStage | externalLocation }
FROM { [<database_name>.]<table_name> | ( <query> ) } <-- this line
[ FILE_FORMAT = ( { TYPE = { CSV | JSON | PARQUET } [ formatTypeOptions ] } ) ]
[ copyOptions ]
[ VALIDATION_MODE = RETURN_ROWS ] the I tried to describe them like the following: pub enum Statement<'a> {
...
CopyInto {
src: Identifier<'a>,
dst: Identifier<'a>,
files: Vec<String>,
pattern: String,
file_format: BTreeMap<String, String>,
validation_mode: String,
size_limit: usize,
},
...
}
let copy_into = map(
rule! {
COPY
~ INTO ~ #ident
~ FROM ~ ( #ident | "(" ~ #literal_string ~ ")" )
~ ( FILES ~ "=" ~ "(" ~ #comma_separated_list0(literal_string) ~ ")")?
~ ( PATTERN ~ "=" ~ #literal_string)?
~ ( FILE_FORMAT ~ "=" ~ #options)?
~ ( VALIDATION_MODE ~ "=" ~ #literal_string)?
~ ( SIZE_LIMIT ~ "=" ~ #literal_u64)?
},
|(_, _, dst, _, src, files, pattern, file_format, validation_mode, size_limit)| {
Statement::CopyInto {
src,
dst,
files: files.map(|v| v.3).unwrap_or_default(),
pattern: pattern.map(|v| v.2).unwrap_or_default(),
file_format: file_format.map(|v| v.2).unwrap_or_default(),
validation_mode: validation_mode.map(|v| v.2).unwrap_or_default(),
size_limit: size_limit.map(|v| v.2).unwrap_or_default() as usize,
}
},
); Failed will compiling errors: :( cargo c
Checking common-ast v0.1.0 (/home/xuanwo/Code/datafuselabs/databend/common/ast)
error[E0271]: type mismatch resolving `<impl FnMut(util::Input<'_>)-> Result<(util::Input<'_>, (&token::Token<'_>, std::string::String, &token::Token<'_>)), nom::Err<parser::error::Error<'_>>> as FnOnce<(util::Input<'_>,)>>::Output == Result<(util::Input<'_>, ast::Identifier<'_>), nom::Err<parser::error::Error<'_>>>`
--> common/ast/src/parser/util.rs:63:23
|
63 | ($($tt:tt)*) => { nom_rule::rule!(
| _______________________^
64 | | $crate::parser::util::match_text,
65 | | $crate::parser::util::match_token,
66 | | $($tt)*)
| |________________^ expected struct `ast::Identifier`, found tuple
|
::: common/ast/src/parser/statement.rs:595:9
|
595 | / rule! {
596 | | COPY
597 | | ~ INTO ~ #ident
598 | | ~ FROM ~ ( #ident | "(" ~ #literal_string ~ ")" )
... |
603 | | ~ ( SIZE_LIMIT ~ "=" ~ #literal_u64)?
604 | | },
| |_________- in this macro invocation
|
= note: expected enum `Result<(util::Input<'_>, ast::Identifier<'_>), _>`
found enum `Result<(util::Input<'_>, (&token::Token<'_>, std::string::String, &token::Token<'_>)), _>`
= note: required because of the requirements on the impl of `nom::Parser<util::Input<'_>, ast::Identifier<'_>, parser::error::Error<'_>>` for `impl FnMut(util::Input<'_>)-> Result<(util::Input<'_>, (&token::Token<'_>, std::string::String, &token::Token<'_>)), nom::Err<parser::error::Error<'_>>>`
= note: required because of the requirements on the impl of `nom::branch::Alt<util::Input<'_>, ast::Identifier<'_>, parser::error::Error<'_>>` for `(for<'r> fn(util::Input<'r>) -> Result<(util::Input<'r>, ast::Identifier<'r>), nom::Err<parser::error::Error<'r>>> {util::ident}, impl FnMut(util::Input<'_>)-> Result<(util::Input<'_>, (&token::Token<'_>, std::string::String, &token::Token<'_>)), nom::Err<parser::error::Error<'_>>>)`
note: required by a bound in `alt`
--> /home/xuanwo/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.1/src/branch/mod.rs:71:49
|
71 | pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>(
| ^^^^^^^^^^^^ required by this bound in `alt`
= note: this error originates in the macro `nom_rule::rule` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0271`.
error: could not compile `common-ast` due to previous error Asking @andylokandy for help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The output type of parsers of |
Beta Was this translation helpful? Give feedback.
-
BTW, |
Beta Was this translation helpful? Give feedback.
The output type of parsers of
alt
must be the same. But"(" ~ #literal_string ~ ")"
has a return type of(Token, String, Token)
while#ident
has a return type ofToken
.