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

Function parse_create_dataflow

src/clusterd-test-driver/src/text.rs:375–424  ·  view source on GitHub ↗

Parse a `create-dataflow` body of `import`/`build`/`export` sub-commands. The directive's bare flags carry the dataflow-level options (`optimize`).

(
    args: &BTreeMap<String, String>,
    flags: &[String],
    body: &[Line],
)

Source from the content-addressed store, hash-verified

373/// Parse a `create-dataflow` body of `import`/`build`/`export` sub-commands. The
374/// directive's bare flags carry the dataflow-level options (`optimize`).
375fn parse_create_dataflow(
376 args: &BTreeMap<String, String>,
377 flags: &[String],
378 body: &[Line],
379) -> anyhow::Result<Command> {
380 let name = opt_string(args, "name");
381 let as_of = req_u64(args, "as-of")?;
382 let optimize = flags.iter().any(|f| f == "optimize");
383 let mut imports = Vec::new();
384 let mut builds = Vec::new();
385 let mut exports = Vec::new();
386 for (header, sub_body) in group(body)? {
387 let (verb, args, _flags) = parse_header(&header.text)?;
388 match verb.as_str() {
389 "import" => {
390 if let Some(index_id) = args.get("index") {
391 imports.push(ImportSpec::Index {
392 index_id: index_id
393 .parse()
394 .with_context(|| format!("bad index id `{index_id}`"))?,
395 });
396 } else {
397 imports.push(ImportSpec::Source {
398 id: req_u64(&args, "source")?,
399 shard: req(&args, "shard")?.to_string(),
400 schema: opt_string(&args, "schema"),
401 upper: req_u64(&args, "upper")?,
402 });
403 }
404 }
405 "build" => {
406 ensure!(!sub_body.is_empty(), "`build` needs a MIR body");
407 builds.push(BuildSpec {
408 id: req_u64(&args, "id")?,
409 expr: body_text(sub_body),
410 });
411 }
412 "export" => exports.push(parse_export(&args)?),
413 other => bail!("unknown `create-dataflow` sub-command `{other}`"),
414 }
415 }
416 Ok(Command::CreateDataflow {
417 name,
418 imports,
419 builds,
420 exports,
421 as_of,
422 optimize,
423 })
424}
425
426/// Parse one command block (directive line plus indentation-structured body).
427fn parse_command(input: &str) -> anyhow::Result<Command> {

Callers 1

parse_commandFunction · 0.85

Calls 15

opt_stringFunction · 0.85
req_u64Function · 0.85
groupFunction · 0.85
parse_headerFunction · 0.85
body_textFunction · 0.85
parse_exportFunction · 0.85
anyMethod · 0.80
reqFunction · 0.70
iterMethod · 0.45
as_strMethod · 0.45
getMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected