LucaCappelletti94 commented on code in PR #2077:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2077#discussion_r2527737433
##########
src/parser/mod.rs:
##########
@@ -9597,6 +9533,178 @@ impl<'a> Parser<'a> {
}
}
+ pub fn parse_csv_body(
+ &mut self,
+ options: &[CopyOption],
+ legacy_options: &[CopyLegacyOption],
+ ) -> Result<Vec<Vec<Option<String>>>, ParserError> {
+ let Token::CopyFromStdin(body) = self.next_token().token else {
+ return self.expected("COPY ... FROM STDIN with CSV body",
self.peek_token());
+ };
+
+ let mut delimiter = '\t';
+ let mut quote = '"';
+ let mut escape = '\\';
+ let mut null_symbol = "\\N";
+
+ // Apply options
+ for option in options {
+ match option {
+ CopyOption::Delimiter(c) => {
+ delimiter = *c;
+ }
+ CopyOption::Quote(c) => {
+ quote = *c;
+ }
+ CopyOption::Escape(c) => {
+ escape = *c;
+ }
+ CopyOption::Null(null) => {
+ null_symbol = null;
+ }
+ _ => {}
+ }
+ }
+
+ // Apply legacy options
+ for option in legacy_options {
+ match option {
+ CopyLegacyOption::Delimiter(c) => {
+ delimiter = *c;
+ }
+ CopyLegacyOption::Null(null) => {
+ null_symbol = null;
+ }
+ CopyLegacyOption::Csv(csv_options) => {
+ for csv_option in csv_options {
+ match csv_option {
+ CopyLegacyCsvOption::Quote(c) => {
+ quote = *c;
+ }
+ CopyLegacyCsvOption::Escape(c) => {
+ escape = *c;
+ }
+ _ => {}
+ }
+ }
+ }
+ _ => {}
+ }
+ }
Review Comment:
It is nearly a duplicate, yes, and that is why I wanted to handle both with
the `csv` crate, but there are some significant differences which I found a bit
hard to normalize.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]