Skip to content

Dependent columns #3220

Closed
Closed

Description

@kubouch

Is your feature request related to a problem? Please describe.
Consider the following table:

> echo [[filestem extension basename]; [spam txt spam.txt]]

#  filestem  extension  basename
---------------------------------
0  spam      txt        spam.txt

The basename column can be written as a combination of filename and extension:

> echo [[filestem extension]; [spam txt]] | insert basename {
  echo [ $it.filestem $it.extension ] | str collect '.' 
}

#  filestem  extension  basename
---------------------------------
0  spam      txt        spam.txt

Now when we change the filestem:

> echo [[filestem extension]; [spam txt]] | insert basename { 
  echo [ $it.filestem $it.extension ] | str collect '.'
} | update filestem eggs

#  filestem  extension  basename
---------------------------------
0  eggs      txt        spam.txt

, naturally, it updates only the filestem column. To propagate the change into the basename column, we would need to run the insert basename { ... } again to update the derived column. In this case, you could just update the filestem before insert but it could be problematic in more complex pipelines or if you have the table e.g. cached in a variable.

Describe the solution you'd like
My suggestions is to have "dependent columns" -- columns defined as operation on other columns. Modifying the table fields would update the dependent columns without manual intervention. The above example could be written like this:

> let fn = { echo [$it.filestem $it.extension] | str collect '.' }
> echo [ [ filestem  extension  basename = $fn  ]; [spam txt]]

#  filestem  extension  basename
---------------------------------
0  spam      txt        spam.txt

> echo [ [ filestem  extension  basename = $fn ]; [spam txt]] | update filestem eggs

#  filestem  extension  basename
---------------------------------
0  eggs      txt        eggs.txt

So it's basically like a command-line Excel. Notice, I'm supplying values only for the first two columns. The dependent column would be fully automatic and writing to it would throw an error.

Describe alternatives you've considered
None :-D

Additional context
I came across this problem when thinking about the path commands revamp (#3219). It would allow to have duplicate fields in the path table, without worrying about updating basename after updating filename or extension. Apart from the basename example, for example, the column dirname could be constructed from a parts column, where parts column would contain the path pieces split by the a path separator.

Activity

  1. github-actions commented on Jun 24, 2021

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  2. kubouch commented on Jun 24, 2021

    @kubouch
    ContributorAuthor

    Is it is still a good idea? I think it would be cool.

  3. sophiajt commented on Jul 7, 2021

    @sophiajt
    Contributor

    Yeah, it'd be cool. Would need some design, will go ahead and mark it.

  4. added
    status:needs-design
    and removed on Jul 7, 2021
  5. github-actions commented on Oct 6, 2021

    @github-actions

    This issue is being marked stale because it has been open for 90 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.

  6. github-actions commented on Oct 16, 2021

    @github-actions

    This issue has been marked stale for more than 10 days without activity. Closing this issue, but if you find that the issue is still valid, please reopen.

  7. added
    category:enhancement
    and removed on Oct 22, 2021
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

    category:enhancementstatus:needs-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions