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

Function parse_sql

src/testdrive/src/parser.rs:326–382  ·  view source on GitHub ↗
(line_reader: &mut LineReader)

Source from the content-addressed store, hash-verified

324}
325
326fn parse_sql(line_reader: &mut LineReader) -> Result<SqlCommand, PosError> {
327 let (_, line1) = line_reader.next().unwrap();
328 let query = line1[1..].trim().to_owned();
329 let expected_start = line_reader.consumed_raw_pos;
330 let line2 = slurp_one(line_reader);
331 let line3 = slurp_one(line_reader);
332 let mut column_names = None;
333 let mut expected_rows = Vec::new();
334 static HASH_REGEX: LazyLock<Regex> =
335 LazyLock::new(|| Regex::new(r"^(\S+) values hashing to (\S+)$").unwrap());
336 match (line2, line3) {
337 (Some((pos2, line2)), Some((pos3, line3))) => {
338 if line3.len() >= 3 && line3.chars().all(|c| c == '-') {
339 column_names = Some(split_line(pos2, &line2)?);
340 } else {
341 expected_rows.push(split_line(pos2, &line2)?);
342 expected_rows.push(split_line(pos3, &line3)?);
343 }
344 }
345 (Some((pos2, line2)), None) => match HASH_REGEX.captures(&line2) {
346 Some(captures) => match captures[1].parse::<usize>() {
347 Ok(num_values) => {
348 return Ok(SqlCommand {
349 query,
350 expected_output: SqlOutput::Hashed {
351 num_values,
352 md5: captures[2].to_owned(),
353 },
354 expected_start: 0,
355 expected_end: 0,
356 });
357 }
358 Err(err) => {
359 return Err(PosError {
360 source: anyhow!("Error parsing number of expected rows: {}", err),
361 pos: Some(pos2),
362 });
363 }
364 },
365 None => expected_rows.push(split_line(pos2, &line2)?),
366 },
367 _ => (),
368 }
369 while let Some((pos, line)) = slurp_one(line_reader) {
370 expected_rows.push(split_line(pos, &line)?)
371 }
372 let expected_end = line_reader.consumed_raw_pos;
373 Ok(SqlCommand {
374 query,
375 expected_output: SqlOutput::Full {
376 column_names,
377 expected_rows,
378 },
379 expected_start,
380 expected_end,
381 })
382}
383

Callers 2

parseFunction · 0.70
drop_table_identifiersFunction · 0.50

Calls 9

slurp_oneFunction · 0.85
split_lineFunction · 0.85
unwrapMethod · 0.80
allMethod · 0.80
nextMethod · 0.45
to_ownedMethod · 0.45
trimMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected