0

What is the opposite of a groupby or Bag sort? Is there a specific term used for an operation like this in programming lingo?

As in an aggregation in which items are sorted by family and summed by counting them, but in reverse.

Examples Python:

>>> grouped = {"a": 2,
...            "b": 1,
...            "c": 3}
>>> ungrouped = [[key]*grouped[key] for key in grouped.keys()]
>>> ungrouped
[['a', 'a'], ['c', 'c', 'c'], ['b']]
>>> 

Or MySql:

SELECT thing,COUNT(*) FROM a.table WHERE thing='isafamilygroupbag';

Or Bash:

declare -A grouped
grouped=( [a]=2 [b]=1 [c]=3 )
ungrouped=()
for k in "${!grouped[@]}"; do
    v=$(echo "${grouped[$k]}")
    for count in $(seq 1 ${v[0]}); do
        ungrouped+=" $k "
    done
done
echo "${ungrouped[@]}"

I am not so much interested in the implementation of doing such a process, but what it is called.

Similar:

update

Also related:

Community
  • 1
  • 1
jmunsch
  • 22,771
  • 11
  • 93
  • 114
  • "Group expansion"? I'm not sure, I haven't seen a name coined with this concept. – Cory Kramer Nov 25 '14 at 19:46
  • so, given a count of (say) 42, figure out what records were counted to make up that 42? Unless you've got specially massaged data, that's not really possible: given 5, which of the following were added togehter? `1,2,3,4,5`. 1+4? 2+3? 5? – Marc B Nov 25 '14 at 19:47
  • 2
    Python's [`Counter()`](https://docs.python.org/2/library/collections.html#collections.Counter.elements) just calls these the elements. – Martijn Pieters Nov 25 '14 at 19:48
  • @MarcB `{"uniqrecord":42}` each record being a unique id/element and a uniqrecord with a count of 42 like `["uniqrecord"]*42` – jmunsch Nov 25 '14 at 19:52
  • Remember that your output is the result of some aggregate operation (whether that be count, average, max etc). The inverse is going to depend on what that operation was - it's not enough to know that's its an aggregation, you need to know what sort. You might be able to name the operation, but I don't know of a name that means inverting any arbitrary aggregate operation. It's essentially meaningless? – AndySavage Nov 25 '14 at 19:54
  • deaggregate? decompose? but yeah, exactly. unless you know exactly which aggregate functions were used, and the grouping conditions, you're not going to be able to figure out what records were aggregated in the first place. – Marc B Nov 25 '14 at 19:57
  • Thanks for the heads up on arbitrary aggregations. Since I definitely lacked the vocabulary to even ask the question. I did find what it was I was looking for in the above update. I just had no idea what to look for. But I was looking for the python `Counter()` but for MySql : http://stackoverflow.com/questions/7411639/opposite-of-distinct-in-mysql – jmunsch Nov 25 '14 at 20:20
  • A `HAVING` clause is just a `WHERE` clause designed for aggregates, it's not really an opposite to the aggregate itself. – AndySavage Nov 25 '14 at 23:21

0 Answers0