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

Ability to "collapse" data #32

Open
astrotars opened this issue Dec 9, 2014 · 7 comments
Open

Ability to "collapse" data #32

astrotars opened this issue Dec 9, 2014 · 7 comments

Comments

@astrotars
Copy link

For POST and PUTS, I feel it would be a great value add to allow for collapse functionality. That would mean taking a tree like data structure and returning it to its original form. Is this on the roadmap and/or do you have any recommendations on how to implementation for the time being?

@kwhitley
Copy link
Owner

kwhitley commented Dec 9, 2014

To be honest Nick, I hadn't considered that... if you're talking about collapsing for the sake of space savings, the tree version should in theory be smaller than any other version. It "looks" bigger, having added structure fluff around the data, but removes all data duplication. Given that treeize was originally designed to remove the duplication from say... a SQL join type dataset (where data from one or more records is repeated for each child row), there can be a lot of duplication without it.

Mind giving me a couple line example of what you're proposing so I understand it better?

@astrotars
Copy link
Author

@kwhitley definitely. The benefit behind having a collapse function would be to put grown data (in tree form) back to a flat data structure. For example, if I was updating a single row of data, it would allow me to take something like:

[
    {
      'director': 'Christopher Nolan',
      'title': 'The Prestige',
      'actors': [
        {
          'as': 'Alfred Borden',
          'name': 'Christian Bale'
        },
        {
          'as': 'Robert Angier',
          'name': 'Hugh Jackman'
        }
      ]
    }
]

to a flat data structure such as:

[
  {
    'title':             'The Prestige',
    'director':          'Christopher Nolan',
    'actors:name':       'Christian Bale',
    'actors:as':         'Alfred Borden'
  },
  {
    'title':             'The Prestige',
    'director':          'Christopher Nolan',
    'actors:name':       'Hugh Jackman',
    'actors:as':         'Robert Angier'
  }
]

This would allow for a super simple create and update on a row. As it stands right now, it's extremely difficult to reverse the grown data into a flat structure. Figured it would be a great value add.

@kwhitley
Copy link
Owner

kwhitley commented Dec 9, 2014

Ah, gotcha. Shouldn't be too difficult to implement... I believe I store the
original data that's inserted but if you mean to reverse a tree that may
have been modified, it'll take a reversing function. Should be easier than
the tree mapping though... I'll check it out!

On Tue, Dec 9, 2014 at 11:53 AM, Nick Parsons [email protected]
wrote:

@kwhitley https://github.com/kwhitley definitely. The benefit behind
having a collapse function would be to put grown data (in tree form) back
to a flat data structure. For example, if I was updating a single row of
data, it would allow me to take something like:

[
{
'director': 'Christopher Nolan',
'title': 'The Prestige',
'actors': [
{
'as': 'Alfred Borden',
'name': 'Christian Bale'
},
{
'as': 'Robert Angier',
'name': 'Hugh Jackman'
}
]
}
]

to a flat data structure such as:

[
{
'title': 'The Prestige',
'director': 'Christopher Nolan',
'actors:name': 'Christian Bale',
'actors:as': 'Alfred Borden'
},
{
'title': 'The Prestige',
'director': 'Christopher Nolan',
'actors:name': 'Hugh Jackman',
'actors:as': 'Robert Angier'
}
]

This would allow for a super simple create and update on a row. As it
stands right now, it's extremely difficult to reverse the grown data into a
flat structure. Figured it would be a great value add.


Reply to this email directly or view it on GitHub
#32 (comment).

@astrotars
Copy link
Author

@kwhitley Awesome! It would be a game changer for me. I look forward to seeing what you come up with.

@kwhitley
Copy link
Owner

Very sorry for the delay @nparsons08 - I've added in a simple .getSeedData() function that should return the original flat rows, but actually creating a complete reversal (opposite of .grow()) to collapse expanded data will have to be a challenge to save for another day. It should certainly be possible though...

@cscalfani
Copy link

I wrote an untreeize library you might find useful: https://www.npmjs.com/package/untreeize

@kwhitley
Copy link
Owner

@cscalfani So awesome!!! I'll do a few tests on it and include your lib in the docs 👍 :)

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

No branches or pull requests

3 participants