简体   繁体   中英

Apache Spark class for int array key in Java?

I'm using multiple integers as a key in Spark. Is there an existing class in Apache Spark that has this functionality so I don't need to implement hashCode, etc? This is in Java and not Scala.

public class MultiIntKey
{
  public int key1;
  public int key2;
  ... 
}

I would suggest to take a look at Java tuples or Scala where tuples are part of std library

<dependency>
    <groupId>org.javatuples</groupId>
    <artifactId>javatuples</artifactId>
    <version>1.2</version>
</dependency>

javatuples offers you tuple classes from one to ten elements + they all have equals + hashcode. They all immutable. Your version is mutable btw, and it's really bad practice for class used as key.

Unit<A> (1 element)
Pair<A,B> (2 elements)
Triplet<A,B,C> (3 elements)
Quartet<A,B,C,D> (4 elements)
Quintet<A,B,C,D,E> (5 elements)
Sextet<A,B,C,D,E,F> (6 elements)
Septet<A,B,C,D,E,F,G> (7 elements)
Octet<A,B,C,D,E,F,G,H> (8 elements)
Ennead<A,B,C,D,E,F,G,H,I> (9 elements)
Decade<A,B,C,D,E,F,G,H,I,J> (10 elements)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM