Skip to content

Can't convert a 'string' to a 'column'  #2979

Closed

Description

@djvsrose

ls | select name
let column_name = "name"; ls | select $column_name => this will not work. expected column path, found string
ls | get $(= name). => This will not work either

There's no way to convert a string to a column path. This makes it very difficult to manipulate a table from a script.

> version | pivot
───┬────────────────────┬─────────────────────────────────────────────────────────────────────────────────────────────────────────
 # │      Column0       │                                                 Column1                                                 
───┼────────────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────
 0 │ version            │ 0.25.1                                                                                                  
 1 │ build_os           │ macos-x86_64                                                                                            
 2 │ rust_version       │ rustc 1.48.0                                                                                            
 3 │ cargo_version      │ cargo 1.48.0                                                                                            
 4 │ pkg_version        │ 0.25.1                                                                                                  
 5 │ build_time         │ 2021-01-06 16:50:40                                                                                     
 6 │ build_rust_channel │ release                                                                                                 
 7 │ features           │ ctrlc, default, directories, dirs, git, ichwh, ptree, rich-benchmark, rustyline, term, uuid, which, zip 
───┴────────────────────┴─────────────────────────────────────────────────────────────────────────────────────────────────────────

Activity

  1. kubouch commented on Jan 28, 2021

    @kubouch
    Contributor

    I remember running into this earlier, but now it seems to work in 0.26.0 (latest main, commit d0a2a02).

  2. djvsrose commented on Jan 29, 2021

    @djvsrose
    Author

    I just tried in 0.26.0 and I don't think this is fixed.

  3. kubouch commented on Jan 29, 2021

    @kubouch
    Contributor

    How about this: let column_name = "size"; ls -a | sort-by $column_name. This works for me on Linux. (I chose sorting by size since ls is by default sorted by name.)

    In your second example, you're missing spaces around = which throws an error.

  4. djvsrose commented on Feb 1, 2021

    @djvsrose
    Author

    Yes, the 2nd example is bad. I will update the example. Thanks.

  5. andrasio commented on Feb 7, 2021

    @andrasio
    Member

    Fixed. Thanks for reporting it!

  6. hustcer commented on Aug 4, 2021

    @hustcer
    Contributor
    ❯ let column_name = "name"; ls | get $column_name
    error: Type Error
       ┌─ shell:68:19
       │
    68 │ let column_name = "name"; ls | get $column_name
       │                   ^^^^^^ Expected column path, found string
    

    Help! I still get this issue, and my nu version:

    ❯ nu --version
    ───┬────────────────────┬────────────────────────────────────────────────────────────────────────────────────
     # │      Column0       │                                      Column1
    ───┼────────────────────┼────────────────────────────────────────────────────────────────────────────────────
     0 │ version            │ 0.34.0
     1 │ build_os           │ macos-x86_64
     2 │ rust_version       │ rustc 1.53.0
     3 │ cargo_version      │ cargo 1.53.0
     4 │ pkg_version        │ 0.34.0
     5 │ build_time         │ 2021-07-14 06:43:18
     6 │ build_rust_channel │ release
     7 │ features           │ clipboard-cli, ctrlc, dataframe, default, rustyline, term, trash, uuid, which, zip
     8 │ installed_plugins  │
    ───┴────────────────────┴────────────────────────────────────────────────────────────────────────────────────
    
  7. hustcer commented on Aug 4, 2021

    @hustcer
    Contributor

    Fixed. Thanks for reporting it!

    Are you sure it was fixed ?

  8. hustcer commented on Aug 4, 2021

    @hustcer
    Contributor

    @andrasio
    let column_name = "name"; ls | select $column_name and let column_name = "name"; ls | get $column_name didn't work but let column_name = "name"; ls | sort-by $column_name works

  9. andrasio commented on Aug 4, 2021

    @andrasio
    Member

    @hustcer A regression was introduced (on purpose, sort of). We are thinking how to effectively do this by means of cohesion's instead.

    Can you confirm let column_name = "name"; ls | select $column_name and let column_name = "name"; ls | get $column_name these no longer work?

  10. hustcer commented on Aug 5, 2021

    @hustcer
    Contributor

    @hustcer A regression was introduced (on purpose, sort of). We are thinking how to effectively do this by means of cohesion's instead.

    Can you confirm let column_name = "name"; ls | select $column_name and let column_name = "name"; ls | get $column_name these no longer work?

    @andrasio Yes, it's confirmed.

    gaia-mobile on  feature/nu is 📦 v2.0.0-Beta1 via  v14.15.5
    ❯ let column_name = "name"; ls | select $column_name
    error: Type Error
        ┌─ shell:264:19
        │
    264 │ let column_name = "name"; ls | select $column_name
        │                   ^^^^^^ Expected column path, found string
    
    
    gaia-mobile on  feature/nu is 📦 v2.0.0-Beta1 via  v14.15.5
    ❯ let column_name = "name"; ls | get $column_name
    error: Type Error
        ┌─ shell:265:19
        │
    265 │ let column_name = "name"; ls | get $column_name
        │                   ^^^^^^ Expected column path, found string
    
    
    gaia-mobile on  feature/nu is 📦 v2.0.0-Beta1 via  v14.15.5
    ❯ let column_name = "name"; ls | sort-by $column_name | first
    ───┬──────────────┬──────┬──────┬─────────────
     # │     name     │ type │ size │  modified
    ───┼──────────────┼──────┼──────┼─────────────
     0 │ CHANGELOG.md │ File │  0 B │ 1 month ago
    ───┴──────────────┴──────┴──────┴─────────────
    
    
    gaia-mobile on  feature/nu is 📦 v2.0.0-Beta1 via  v14.15.5
    ❯ nu --version
    ───┬────────────────────┬────────────────────────────────────────────────────────────────────────────────────
     # │      Column0       │                                      Column1
    ───┼────────────────────┼────────────────────────────────────────────────────────────────────────────────────
     0 │ version            │ 0.34.0
     1 │ build_os           │ macos-x86_64
     2 │ rust_version       │ rustc 1.53.0
     3 │ cargo_version      │ cargo 1.53.0
     4 │ pkg_version        │ 0.34.0
     5 │ build_time         │ 2021-07-14 06:43:18
     6 │ build_rust_channel │ release
     7 │ features           │ clipboard-cli, ctrlc, dataframe, default, rustyline, term, trash, uuid, which, zip
     8 │ installed_plugins  │
    ───┴────────────────────┴────────────────────────────────────────────────────────────────────────────────────
    
  11. hustcer commented on Sep 28, 2021

    @hustcer
    Contributor

    @andrasio Any plan for this? Thx

  12. alechp commented on Oct 15, 2021

    @alechp

    I'm having a similar issue (resolved, fix appended on this comment)

    Objective

    • Echo out contents of alias (done)
    • Create script to make this easier (failing)

    Static Column (works)

    Screen_Shot_2021-10-15_at_12 04 46_PM
    )

    String/dynamic Column (fails)

    Screen Shot 2021-10-15 at 12 10 06 PM
    Screen Shot 2021-10-15 at 12 13 35 PM


    Update 10/15/2021 12:37PM PST

    This works:

    def als4 [aliasToCheck] {
        echo $scope.aliases | select ($aliasToCheck | into column_path)
    }
    

    Screen Shot 2021-10-15 at 12 38 27 PM

    Convo for context:
    Screen Shot 2021-10-15 at 12 37 40 PM

  13. fdncred commented on Oct 15, 2021

    @fdncred
    Contributor

    ya, i'm closing this because into column_path fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions