MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / parse_simple

Method parse_simple

src/sqllogictest/src/parser.rs:404–474  ·  view source on GitHub ↗
(
        &mut self,
        mut words: std::iter::Peekable<impl Iterator<Item = &'a str>>,
    )

Source from the content-addressed store, hash-verified

402 }
403
404 fn parse_simple(
405 &mut self,
406 mut words: std::iter::Peekable<impl Iterator<Item = &'a str>>,
407 ) -> Result<Record<'a>, anyhow::Error> {
408 let location = self.location();
409 let mut conn = None;
410 let mut user = None;
411 let mut password = None;
412 let mut multiline = false;
413 let mut sort = Sort::No;
414 if let Some(options) = words.next() {
415 for option in options.split(',') {
416 if let Some(value) = option.strip_prefix("conn=") {
417 conn = Some(value);
418 } else if let Some(value) = option.strip_prefix("user=") {
419 user = Some(value);
420 } else if let Some(value) = option.strip_prefix("password=") {
421 password = Some(value);
422 } else if option == "rowsort" {
423 sort = Sort::Row;
424 } else if option == "multiline" {
425 multiline = true;
426 } else {
427 bail!("Unrecognized option {:?} in {:?}", option, options);
428 }
429 }
430 }
431 if user.is_some() && conn.is_none() {
432 bail!("cannot set user without also setting conn");
433 }
434 if password.is_some() && user.is_none() {
435 bail!("cannot set password without also setting user");
436 }
437 let sql = self.split_at(&QUERY_OUTPUT_REGEX)?;
438 let output_str = self
439 .split_at(if multiline {
440 &EOF_REGEX
441 } else {
442 &DOUBLE_LINE_REGEX
443 })?
444 .trim_start();
445 let output = if multiline {
446 Output::Values({
447 let mut v = vec![output_str.to_owned()];
448 // for simple queries we still have to pass the COMPLETE string after the EOF
449 let complete_str = self.split_at(&DOUBLE_LINE_REGEX)?.trim_start();
450 v.extend(complete_str.lines().map(String::from));
451 v
452 })
453 } else {
454 // We only apply rowsort in mode cockroach, for "query" statements,
455 // so mirror that here.
456 let mut output_lines: Vec<String> = output_str.lines().map(String::from).collect();
457
458 if self.mode == Mode::Cockroach && sort == Sort::Row {
459 output_lines.sort();
460 }
461

Callers 1

parse_recordMethod · 0.45

Calls 11

is_someMethod · 0.80
is_noneMethod · 0.80
sortMethod · 0.80
ValuesClass · 0.50
locationMethod · 0.45
nextMethod · 0.45
splitMethod · 0.45
split_atMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected