Skip to content

Update description and error types for split-by#10865

Merged
sholderbach merged 4 commits intonushell:mainfrom
drbrain:fix-split-by-error-type
Nov 7, 2023
Merged

Update description and error types for split-by#10865
sholderbach merged 4 commits intonushell:mainfrom
drbrain:fix-split-by-error-type

Conversation

@drbrain
Copy link
Copy Markdown
Contributor

@drbrain drbrain commented Oct 28, 2023

Description

split-by only works on a Record, the error type was updated to match, and now uses a more-specific type. (Two type fixes for the price of one!)

The usage was updated to say "record" as well

User-Facing Changes

  • Providing the wrong type to split-by now gives an error messages with the correct required input type

Previously:

❯ ls | get name | split-by type
Error:   × unsupported input
   ╭─[entry #267:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a table with one row for splitting
   ╰────

With this PR:

❯ ls | get name | split-by type
Error: nu::shell::type_mismatch

  × Type mismatch.
   ╭─[entry #1:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a record to split
   ╰────

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

Only generated commands need to be updated

`split-by` only works on a `Record`, the error was updated to match, and
now uses a more-specific type

The `usage` was updated to say "record" as well
Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

Thanks for improving the messages here!

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 28, 2023

Wait, split-by doesn't work on tables? I thought all the blah-by commands did?

@drbrain
Copy link
Copy Markdown
Contributor Author

drbrain commented Oct 28, 2023

Wait, split-by doesn't work on tables? I thought all the blah-by commands did?

❯ nu --version
0.86.0
❯ ls | split-by type
Error: nu::parser::input_type_mismatch

  × Command does not support table input.
   ╭─[entry #4:1:1]
 1 │ ls | split-by type
   ·      ────┬───
   ·          ╰── command doesn't support table input
   ╰────

❯ ls | describe
table<name: string, type: string, size: filesize, modified: date> (stream)

PS: I'm unclear on what the difference between group-by and split-by in terms of functionality is supposed to be, they seem to be sibling commands that maybe could be merged into one?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 28, 2023

ya, I've never used split-by. By the example it has, it looks like it reads into nested data.

> {
        '2019': [
          { name: 'andres', lang: 'rb', year: '2019' },
          { name: 'jt', lang: 'rs', year: '2019' }
        ],
        '2021': [
          { name: 'storm', lang: 'rs', 'year': '2021' }
        ]
    } | split-by lang
  ╭──┬─────────────────╮
  │rb│{record 1 field} 
  │rs│{record 2 fields}
  ╰──┴─────────────────╯

There are other *-by commands though. group-by, split-by, sort-by, uniq-by. I figured they'd all work on tables, but I guess not. Seems like split-by is a bit niche.

@drbrain drbrain requested a review from sholderbach October 28, 2023 23:45
@amtoine
Copy link
Copy Markdown
Member

amtoine commented Oct 29, 2023

sounds good 👌
if we can get the review threads to close, i'm all for this better error 🙏

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Oct 29, 2023

Looking at the example some more after playing around with input_output_types() in this command, I'm wondering if the only way this command works is if it's a record with tables as values?

I'd love to see more examples in the help of how this command works.

Copy link
Copy Markdown
Contributor

@fdncred fdncred left a comment

Choose a reason for hiding this comment

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

Thanks for working on this error.

Vec::new(),
))
}
_ => return Err(ShellError::PipelineEmpty { dst_span }),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I read the code leading to this point correctly this could still be more than PipelineData::Empty e.g. an ExternalStream, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. In 84661a5 I split PipelineData::Empty out from the other types which return a PipelineMismatch. I looked around and this seems most appropriate as merge treats a ListStream as a List and ExternalStream currently can't produce a Record.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Nov 3, 2023

@drbrain Are you still looking into this?

Neither of these pipeline types produce a single Record which is all split-by
can handle.
@drbrain
Copy link
Copy Markdown
Contributor Author

drbrain commented Nov 4, 2023

I had a busy week.

It should be ready to go with 84661a5

@drbrain drbrain requested a review from sholderbach November 6, 2023 23:13
Copy link
Copy Markdown
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

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

Awesome thanks, this looks good and well covered

@sholderbach sholderbach merged commit c039e4b into nushell:main Nov 7, 2023
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# Description

`split-by` only works on a `Record`, the error type was updated to
match, and now uses a more-specific type. (Two type fixes for the price
of one!)

The `usage` was updated to say "record" as well

# User-Facing Changes

* Providing the wrong type to `split-by` now gives an error messages
with the correct required input type

Previously:

```
❯ ls | get name | split-by type
Error:   × unsupported input
   ╭─[entry nushell#267:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a table with one row for splitting
   ╰────
```

With this PR:

```
❯ ls | get name | split-by type
Error: nu:🐚:type_mismatch

  × Type mismatch.
   ╭─[entry #1:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a record to split
   ╰────
```

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

Only generated commands need to be updated

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# Description

`split-by` only works on a `Record`, the error type was updated to
match, and now uses a more-specific type. (Two type fixes for the price
of one!)

The `usage` was updated to say "record" as well

# User-Facing Changes

* Providing the wrong type to `split-by` now gives an error messages
with the correct required input type

Previously:

```
❯ ls | get name | split-by type
Error:   × unsupported input
   ╭─[entry nushell#267:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a table with one row for splitting
   ╰────
```

With this PR:

```
❯ ls | get name | split-by type
Error: nu:🐚:type_mismatch

  × Type mismatch.
   ╭─[entry nushell#1:1:1]
 1 │ ls | get name | split-by type
   ·      ─┬─
   ·       ╰── requires a record to split
   ╰────
```

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting

Only generated commands need to be updated

---------

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
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.

4 participants