Guava: Multitable interface

Created on 31 Oct 2014  Â·  39Comments  Â·  Source: google/guava

_Original issue created by [email protected] on 2012-02-17 at 05:19 PM_


There are Multisets and Multimaps. Why not Multitables?

P4 package=collect status=research type=addition

All 39 comments

_Original comment posted by wasserman.louis on 2012-02-17 at 05:27 PM_


Because there's not enough demand for them. Multimaps have decent demand and moderate complexity; Tables have some demand and slightly greater complexity, but I think the cost/benefit ratio drops off pretty quickly after that point.

Do you have a use case?


Labels: Type-Enhancement, Package-Collect

_Original comment posted by [email protected] on 2012-02-17 at 05:38 PM_


My just-encountered use case: Searching a set of objects that each have three fields for instances that share the first two fields but not the last. Of course there are many ways of solving this problem (and I just solved it using a regular table). But in the analogous one- and two-field cases I use a Multiset and Multimap, respectively.

I would think that, for conceptual consistency, one would want a Multitable in the API. And, personally, often use Multisets and Multimaps as a builder object to construct sets or maps that satisfy certain properties. The same would be extremely helpful for Tables.

_Original comment posted by wasserman.louis on 2012-02-17 at 06:38 PM_


"Conceptual consistency" is not nearly as relevant to us as the metric of "utility times ubiquity." We can't put in the kind of investment that Multitable would require for the sake of a comparatively tiny number of users. For the same reason, we don't include a "three-keyed map," either.

That said, markaf, I can think of another solution for your specific case: use a normal Multimap, but combine the first two fields into a composite key. It doesn't sound like you need to view the rows or the columns of that table, you just want to look up on multiple keys at once.

_Original comment posted by wasserman.louis on 2012-02-20 at 05:09 PM_


Additionally, the composite-key approach generalizes to arbitrary numbers of fields, in contrast to your proposed Multitable interface, which only get you one extra field.

_Original comment posted by [email protected] on 2012-02-20 at 10:42 PM_


4 is a reasonable answer.

_Original comment posted by wasserman.louis on 2012-03-01 at 07:52 PM_


I'm marking this as Acknowledged for the moment, unless we find another compelling use case.


Status: Acknowledged

_Original comment posted by [email protected] on 2012-05-30 at 07:43 PM_


_(No comment entered for this change.)_


Labels: -Type-Enhancement, Type-Addition

_Original comment posted by [email protected] on 2012-06-22 at 06:16 PM_


_(No comment entered for this change.)_


Status: Research

_Original comment posted by letallecy on 2013-01-28 at 09:50 PM_


Hi Louis, one use case I have is the following:

I would like to store financial instruments tick data in a Table<DateTime, String, Object> where the row is the timestamp, the column is the field retrieved (bid, ask, last, size etc.) and the Object is the value.

However, multiple ticks can occur within the same millisecond (and some exchanges report the ticks with a precision of 1 second, which increases the likelihood of having more than one tick per "cell").

For that specific use case, I would love to have a MultiTable where table.row() and table.column() return MultiMaps instead of Maps.

assylias

_Original comment posted by [email protected] on 2013-01-28 at 10:01 PM_


Do the previously mentioned workarounds not work for you? I still have a tough time imagining this having enough demand to get added to Guava.

_Original comment posted by letallecy on 2013-01-28 at 11:41 PM_


Point taken. FYI, I use another workaround: when there is more than one value in a cell, I store a list in that cell instead. And when querying a particular column or row, I return a MultiMap, instead of a Map, which is created by iterating in the cells and checking which contains single data and which contains multiple data.

_Original comment posted by [email protected] on 2013-02-26 at 06:14 PM_


I've mentioned it before, but I've always been highly skeptical of the argument that a Multitable does not have enough utility as it is exactly the model for one of Google's most popular storage abstractions. I'm pretty sure that Bigtable has proven its utility.

_Original comment posted by [email protected] on 2013-08-22 at 11:47 PM_


_Issue #1227 has been merged into this issue._

_Original comment posted by [email protected] on 2013-08-22 at 11:48 PM_


_(No comment entered for this change.)_


Owner: [email protected]

_Original comment posted by roxton on 2013-09-05 at 09:11 PM_


Use Case:

I have two parameterized fields, with relations. The first field is concrete, and the elements of the second field are being inferred based on valid relations.

I want a table:
Multitable<sourceParameterIndex, targetParameterIndex, CandidateParameters>
That way, based on the relation between each permutation of source and target parameter index, I can add candidate parameters, then take the intersection across sets for each source parameter, instantiate field elements for each permutation of filtered parameters, then filter those permutations based on constraints.

Right now, I've got some ugly code around:
Table<sourceParameterIndex, targetParameterIndex, Set<CandidateParameters>>, but I'd love for Multitable to be part of Guava.

+1 to Multitable

We'd really like a multitable, it is outrageous that there isn't one already.

:+1:

I searched through Google's codebase for instances of Table<R, C, List> and similar.

'\b(Immutable)?Table<.*, .*, (List|Set|Collection|Iterable)<.*>>'

This gave 192 results. That's actually pretty surprisingly small for the Google codebase. But of course there are surely other users who reinvented this themselves with different combinations of collections. (And sometimes that's fine: Louis's suggestion of a Multimap with a composite key is often sufficient.)

Still, the complexity of this type would be large, as previously discussed. This led me to file #2170 for Tables.computeIfAbsent, which is basically the primitive that the JDK added to Map in lieu of adding a full Multimap and Multiset. It may be enough for many users here.

+1

+1

+1

+1

+1

Hmm I'd like to make the attempt to implement one but before I even get to a pull request would you accept it? This issue seems a little dead it doesn't look like a resolution will be satisfactory rather leave it how it is.

+1

As described in https://github.com/google/guava/issues/2170#issuecomment-249962341, people seeking a Multitable class and currently using Table<K, K, Collection<V>> can potentially use ValueGraph<K, Collection<V>> instead (a similar but perhaps simpler data structure in some cases), if that would fit their use case better.

common.graph.Network<K, V> might also be appropriate if your V values are unique and capable of acting as a key to their "endpoints" (aka row and column specifiers).

+1

+1

+1

+1

+1

+1

+1

+1

1+

Naive search for people doing this kind of thing internally:

\b(Immutable)?Table<[^(]*\b(List|Collection|Set)<[^(]*>> case:yes lang:java

Was this page helpful?
0 / 5 - 0 ratings