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

Method parse_query

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

Source from the content-addressed store, hash-verified

237 }
238
239 fn parse_query(
240 &mut self,
241 mut words: std::iter::Peekable<impl Iterator<Item = &'a str>>,
242 first_line: &'a str,
243 ) -> Result<Record<'a>, anyhow::Error> {
244 let location = self.location();
245 if words.peek() == Some(&"error") {
246 let error = parse_expected_error(first_line);
247 let sql = self.split_at(&DOUBLE_LINE_REGEX)?;
248 return Ok(Record::Query {
249 sql,
250 output: Err(error),
251 location,
252 });
253 }
254
255 let types = words.next().map_or(Ok(vec![]), parse_types)?;
256 let mut sort = Sort::No;
257 let mut check_column_names = false;
258 let mut multiline = false;
259 if let Some(options) = words.next() {
260 for option in options.split(',') {
261 match option {
262 "nosort" => sort = Sort::No,
263 "rowsort" => sort = Sort::Row,
264 "valuesort" => sort = Sort::Value,
265 "colnames" => check_column_names = true,
266 "multiline" => multiline = true,
267 other => {
268 if other.starts_with("partialsort") {
269 // TODO(jamii) https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/logic.go#L153
270 // partialsort has comma-separated arguments so our parsing is totally broken
271 // luckily it always comes last in the existing tests, so we can just bail out for now
272 sort = Sort::Row;
273 break;
274 } else {
275 bail!("Unrecognized option {:?} in {:?}", other, options);
276 }
277 }
278 };
279 }
280 }
281 if multiline && (check_column_names || sort.yes()) {
282 bail!("multiline option is incompatible with all other options");
283 }
284 let label = words.next();
285 static LINE_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new("\r?(\n|$)").unwrap());
286 static HASH_REGEX: LazyLock<Regex> =
287 LazyLock::new(|| Regex::new(r"(\S+) values hashing to (\S+)").unwrap());
288 let sql = self.split_at(&QUERY_OUTPUT_REGEX)?;
289 let mut output_str = self.split_at(if multiline {
290 &EOF_REGEX
291 } else {
292 &DOUBLE_LINE_REGEX
293 })?;
294
295 // The `split_at(&QUERY_OUTPUT_REGEX)` stopped at the end of `----`, so `output_str` usually
296 // starts with a newline, which is not actually part of the expected output. Strip off this

Callers 1

parse_recordMethod · 0.45

Calls 15

parse_expected_errorFunction · 0.85
regexp_strip_prefixFunction · 0.85
split_atFunction · 0.85
split_colsFunction · 0.85
yesMethod · 0.80
unwrapMethod · 0.80
sortMethod · 0.80
ValuesClass · 0.50
locationMethod · 0.45
peekMethod · 0.45
split_atMethod · 0.45
nextMethod · 0.45

Tested by

no test coverage detected