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],
)
| 373 | /// Parse a `create-dataflow` body of `import`/`build`/`export` sub-commands. The |
| 374 | /// directive's bare flags carry the dataflow-level options (`optimize`). |
| 375 | fn 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). |
| 427 | fn parse_command(input: &str) -> anyhow::Result<Command> { |
no test coverage detected