✨ feat(mq-run): auto-parse structured files by extension when no input format is specified#1749
Merged
Merged
Conversation
…t format is specified When `-I` is not given, automatically prepend the appropriate module import and parse call based on the file extension: - .json → import "json" | json::json_parse() - .yaml/.yml → import "yaml" | yaml::yaml_parse() - .toml → import "toml" | toml::toml_parse() - .xml → import "xml" | xml::xml_parse() - .toon → import "toon" | toon::toon_parse() - .csv → import "csv" | csv::csv_parse(true) - .tsv → import "csv" | csv::tsv_parse(true) - .psv → import "csv" | csv::psv_parse(true)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds mq-run behavior to automatically parse structured input files based on file extension when -I/--input-format is not specified, plus related CLI/help and reference documentation.
Changes:
- Adds extension-to-query-prefix auto parsing for JSON, YAML, TOML, XML, Toon, CSV, TSV, and PSV inputs.
- Prepends the generated import/parse query before executing user queries.
- Documents built-in parsing modules and adds unit/CLI tests for selected auto-parse behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
crates/mq-run/src/cli.rs |
Adds CLI help text, auto-query-prefix logic, execution integration, and tests. |
docs/books/src/reference/modules_and_imports.md |
Adds reference documentation for built-in parsing modules and links to CLI auto-parsing docs. |
Comments suppressed due to low confidence (1)
crates/mq-run/src/cli.rs:585
- Auto-parsing is applied even in
--streammode, whereexecutereceives one line at a time. That makes multi-line.json/.yaml/.tomlfiles fail because each individual line is sent to the structured parser, and it also makes.csvheaders unavailable to later rows. Disable the prefix for streaming input or only apply it when the parser sees the full file content.
let query = match self.auto_query_prefix(file) {
Some(prefix) => {
effective_query = format!("{} | {}", prefix, query);
| | `csv` | `csv::tsv_parse(has_header)` | Parses TSV (`\t` delimiter) | | ||
| | `csv` | `csv::psv_parse(has_header)` | Parses PSV (`\|` delimiter) | | ||
|
|
||
| These modules are also used automatically when you process a file whose extension matches (see [CLI auto-parsing](./cli.md#auto-parsing-by-file-extension)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
-Iis not given, automatically prepend the appropriate module import and parse call based on the file extension: