Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promotes head, improves inspect #118

Merged
merged 6 commits into from
Jun 6, 2024
Merged

Promotes head, improves inspect #118

merged 6 commits into from
Jun 6, 2024

Conversation

zslayton
Copy link
Contributor

@zslayton zslayton commented Jun 6, 2024

  • Promotes head out of the beta namespace
  • Improvements to inspect:
    • Confirms its input is a supported encoding
    • Simplifies (and fixes a bug in) the symbol ID assignment logic
    • Removes workaround for body_span now-fixed bug in ion_rs
    • Makes --no-auto-decompress a supported-by-default flag for
      all subcommands.
  • Hides the dump alias for cat from --help's list of subcommands.
  • Bumps ion_rs dependency to v1.0.0-rc.6

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

* `head` is no longer in the `beta` namespace
* Bumps `ion_rs` dependency to v1.0.0-rc.6
* `inspect` confirms its input is a supported encoding
* Fixes a bug in symbol ID assignments
* Removes workaround for `body_span` now-fixed bug in `ion_rs`
* Makes `--no-auto-decompress` a supported-by-default flag for
  all subcommands.
* Hides the `dump` alias for `cat` from `--help`'s list of subcommands.
Copy link
Contributor Author

@zslayton zslayton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ PR tour 🧭

Cargo.toml Outdated
@@ -17,7 +17,7 @@ clap = { version = "4.0.17", features = ["cargo"] }
colored = "2.0.0"
flate2 = "1.0"
infer = "0.15.0"
ion-rs = { version = "1.0.0-rc.5", features = ["experimental"] }
ion-rs = { version = "1.0.0-rc.6", git = "https://github.com/amazon-ion/ion-rust.git", branch = "version-bump-rc6", features = ["experimental"] }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ This PR depends on amazon-ion/ion-rust#785. Once that's merged/released, I'll update this to point to crates.io.

@@ -21,7 +21,6 @@ impl IonCliCommand for SymtabFilterCommand {
fn configure_args(&self, command: Command) -> Command {
command.with_input()
.with_output()
.with_compression_control()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ Prior to this PR, commands needed to explicitly opt into supporting the --no-auto-decompress flag. Forgetting to do so would cause the program to ugly-crash when the flag was specified. Now the flag is supported universally by default.

Comment on lines +190 to +201
fn confirm_encoding_is_supported(&self, encoding: IonEncoding) -> Result<()> {
use IonEncoding::*;
match encoding {
Text_1_0 | Text_1_1 => {
bail!("`inspect` does not support text Ion streams.");
}
Binary_1_0 => Ok(()),
Binary_1_1 => bail!("`inspect` does not yet support binary Ion v1.1"),
// `IonEncoding` is #[non_exhaustive]
_ => bail!("`inspect does not yet support {}", encoding.name()),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ The latest ion_rs makes it possible to get the IonEncoding from any raw stream item. This allows us to trivially confirm that we're working with what we expect; in inspect's case, that's binary Ion 1.0.

/// Iterates over the items in `reader`, printing a table section for each top level value.
fn inspect_top_level<Input: IonInput>(
&mut self,
reader: &mut SystemReader<AnyEncoding, Input>,
) -> Result<()> {
const TOP_LEVEL_DEPTH: usize = 0;
self.write_table_header()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ We now defer writing the table header until after we've read the first item from the stream and confirmed it's of a supported encoding.

Comment on lines -225 to -230
let is_append = lazy_struct.get("imports")?
== Some(ValueRef::Symbol(SymbolRef::with_text("$ion_symbol_table")));
if !is_append {
next_symbol_id = 10; // First available SID after system symbols in Ion 1.0
}
self.inspect_symbol_table(next_symbol_id, lazy_struct)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ Now that a LazyValue can return a reference to its SymbolTable, the symbol ID assignment logic can be localized to the method where it's displayed.

// TODO: This does not account for shared symbol table imports. However, the CLI does not
// yet support specifying a catalog, so it's correct enough for the moment.
let symtab_value = symtab_struct.as_value();
let mut next_symbol_id = symtab_value.symbol_table().len();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ We don't have to track which ID we were on because we can ask the symbol table what the next ID will be.

BytesKind::ValueBody,
&encoding.span().bytes()[total_len - body_len..],
);
let body_bytes = IonBytes::new(BytesKind::ValueBody, encoding.body_span().bytes());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ ion_rs fixed the bug in body_span(), so I was able to simplify this.

if let Some(flag) = self.args.get_one::<bool>("no-auto-decompress") {
!*flag
if let Some(is_disabled) = self.args.get_one::<bool>("no-auto-decompress") {
!*is_disabled
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ This is just a naming change for clarity.

Box::new(CatCommand),
Box::new(DumpCommand),
Box::new(HeadCommand),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ I put the commands in alphabetical order while I was here.

@@ -201,7 +201,6 @@ fn test_write_all_values(#[case] number: i32, #[case] expected_output: &str) ->
input_file.write_all(test_data.as_bytes())?;
input_file.flush()?;
cmd.args([
"beta",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗺️ This unit test invoked ion beta head and needed to be updated to ion head.

@zslayton
Copy link
Contributor Author

zslayton commented Jun 6, 2024

The CI checks are failing because the ion_rs dependency is pointing to an old commit.

@zslayton zslayton merged commit 52740fe into master Jun 6, 2024
7 checks passed
@zslayton zslayton deleted the promote-head branch June 6, 2024 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants