Skip to content

can't select a column that comes from incomplete record #7558

Closed

Description

@kurokirasama

Describe the bug

This was working till 0.72

[{col1: some, col2: other} {col1: blah}]  | select col2

but now it shows an error saying that it can't find col2. Using select -i just gives empty output

How to reproduce

done

Expected behavior

It should select column 2 showing a ❎ in non existing values

Screenshots

No response

Configuration

key value
version 0.73.0
branch main
commit_hash 1291b64
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel 1.65.0-x86_64-unknown-linux-gnu
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.73.0
build_time 2022-12-21 01:37:16 -03:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins custom-value generate, custom-value generate2, custom-value update, gstat, inc, pnet, query, query json, query web, query xml

Additional context

No response

Activity

  1. rgwood commented on Dec 21, 2022

    @rgwood
    Contributor

    Hi, are you sure that worked until 0.72? [{col1: some, col2: other} {col1: blah}] | select col2 fails for me on 0.71 and 0.72:
    image

    I wonder if this is a dataframe thing.

  2. kurokirasama commented on Dec 21, 2022

    @kurokirasama
    ContributorAuthor

    well, not really sure, but I have this script:

    #get devices connected to network
    export def get-devices [
      device = "wlo1" #wlo1 for wifi (export default), eno1 for lan
      #
      #It needs nmap2json, installable (ubuntu at least) via
      #
      #sudo gem install nmap2json
    ] {
      let ipinfo = (
        if (? | where name == pnet | length) > 0 {
          pnet 
          | where name == ($device) 
          | get 0 
          | get ips 
          | where type == v4 
          | get 0 
          | get addr
          | str replace '(?P<nums>\d+/)' '0/'
        } else {
          ip -json add 
          | from json 
          | where ifname =~ $"($device)" 
          | select addr_info 
          | flatten 
          | find -v inet6 
          | flatten 
          | get local prefixlen 
          | flatten 
          | str collect '/' 
          | str replace '(?P<nums>\d+/)' '0/'
        }
      )
    
      let nmap_output = (sudo nmap -oX nmap.xml -sn $ipinfo --max-parallelism 10)
    
      let nmap_output = (nmap2json convert nmap.xml | from json | get nmaprun | get host | get address)
    
      let this_ip = ($nmap_output | last | get addr)
    
      let ips = ($nmap_output 
        | drop 1 
        | flatten 
        | where addrtype =~ ipv4 
        | select addr 
        | rename ip
      )
      
      let macs_n_names = ($nmap_output 
        | drop 1 
        | flatten 
        | where addrtype =~ mac 
        | select addr vendor 
        | rename mac name
        | update name {|f|
            if ($f.name | is-empty) {
              "Unknown"
            } else {
              $f.name
            }
          }
      )
    
      let devices = ( $ips | merge $macs_n_names )
    
      let known_devices = open ([$env.MY_ENV_VARS.linux_backup "known_devices.csv"] | path join)
      let known_macs = ($known_devices | get mac | str upcase)
    
      let known = ($devices | each {|it| any $it.mac in $known_macs} | wrap known)
    
      let devices = ($devices | merge $known)
    
      let aliases = (
        $devices 
        | each {|row| 
            if $row.known {
              $known_devices | find $row.mac | get alias
            } else {
              " "
            }
          } 
        | flatten 
        | wrap alias
      )
       
      rm nmap.xml | ignore 
    
      $devices | merge $aliases
    }
    

    that started giving me an error after 0.73 update:

    let macs_n_names = ($nmap_output 
        | drop 1 
        | flatten 
        | where addrtype =~ mac 
        | select addr vendor 
        | rename mac name
        | update name {|f|
            if ($f.name | is-empty) {
              "Unknown"
            } else {
              $f.name
            }
          }
      )
    

    and this is the error:

    Error: nu::shell::column_not_found (link)
    
      × Cannot find column
       ╭─[entry #1:1:1]
     1 │ let nmap_output = (nmap2json convert nmap.xml | from json | get nmaprun | get host | get address)
       ·                                                 ────┬────
       ·                                                     ╰── value originates here
       ╰────
       ╭─[entry #6:4:1]
     4 │     | where addrtype =~ mac 
     5 │     | select addr vendor 
       ·                   ───┬──
       ·                      ╰── cannot find column 'vendor'
     6 │     | rename mac name
       ╰────
    

    Looking into it I tried to found the fundamental issue and I thought that it was what I posted

  3. rgwood commented on Dec 22, 2022

    @rgwood
    Contributor

    To investigate this, I think we need to see the table that is being piped to select addr vendor. Maybe you can save it to a temporary variable and print it.

  4. kurokirasama commented on Dec 22, 2022

    @kurokirasama
    ContributorAuthor

    After some exploring, the issue simplifies to what I already established. I don't why it was working before, maybe it was 0.70 the last time I tried, I don't know. I got a temporary fix like this:

     let macs_n_names = (
        $nmap_output 
        | flatten 
        | where addrtype =~ mac  
        | reject addrtype 
        | rename mac name 
      )
    
    let macs_n_names = (
        $macs_n_names
        | select mac
        | into df 
        | append (
            $macs_n_names 
            | get name 
            | wrap name 
            | into df 
          )
        | into nu
      )
    

    I thing it would be nice to have a builtin way to do this.

  5. schmitzli commented on Dec 22, 2022

    @schmitzli

    when you know the column which might be missing you could use default, e.g.
    [{col1: some, col2: other} {col1: blah}] | default null col2 | get col2
    (tested with 0.73.0)

  6. kurokirasama commented on Dec 22, 2022

    @kurokirasama
    ContributorAuthor

    nice!

  7. rgwood commented on Dec 22, 2022

    @rgwood
    Contributor

    If this PR goes through, eventually you'll be able to use ?col2 or ?.col2.

    # get a list<string>
    [{col1: some, col2: other} {col1: blah}]?.col2
    [{col1: some, col2: other} {col1: blah}]  | get ?col2
    [{col1: some, col2: other} {col1: blah}]  | get ?.col2
    
    # get a table with a "col2" column
    [{col1: some, col2: other} {col1: blah}]  | select ?col2
    [{col1: some, col2: other} {col1: blah}]  | select ?.col2
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