public final class CompositeValue extends Object implements Comparable<CompositeValue>, IdentifiedDataSerializable
Composite values are IdentifiedDataSerializable
to facilitate the
storage of composite values in composite indexes, but they are never
transferred over the wire.
Composite values are Comparable
and ordered according to a
lexicographical order defined by the ordering of their individual components.
There are 3 special values defined for components:
NEGATIVE_INFINITY
which represents a value that is equal to
itself and less than any other value. Negative infinities are never stored in
indexes and used only for querying.
AbstractIndex.NULL
which represents a null-like value that is
equal to itself and less than any other value except NEGATIVE_INFINITY
. Null values may be stored in indexes.
POSITIVE_INFINITY
which represents a value that is equal to
itself and greater than any other value. Positive infinities are never stored
in indexes and used only for querying.
A typical ordered index key space layout for the attributes a, b and c looks like this:
a b c null null null null null 1.0 1 'b' 0.0 1 'b' 0.5 2 'a' nullNotice that the ordering of the keys is suitable for the purpose of querying only if keys share some common prefix. In the most general case, any query to an ordered index may be reduced to a range query:
a = null and b = null and c = null [null, null, null] <= [a, b, c] <= [null, null, null] a = 2 [2, -inf, -inf] < [a, b, c] < [2, +inf, +inf] a = 1 and b = 'b' and c > 0.0 [1, 'b', 0.0] < [a, b, c] < [1, 'b', +inf] a < 2 [null, -inf, -inf] < [a, b, c] < [2, -inf, -inf] a = 1 and b >= 'a' and b < 'z' [1, 'a', -inf] < [a, b, c] < [1, 'z', -inf]The later two examples may look counterintuitive at first, but consider what is the first key that is greater than any other key having [1, 'a'] as a prefix? It's [1, 'a', -inf]. The same applies to [1, 'z', -inf], it's the first key that is less than any other key having [1, 'z'] prefix.
For unordered indexes, there is no order defined for index keys. The only comparison operation supported is the full equality of keys expressed as composite values. Partial key matching is impossible.
Modifier and Type | Field and Description |
---|---|
static ComparableIdentifiedDataSerializable |
NEGATIVE_INFINITY
Represents a value that is equal to itself and less than any other value.
|
static ComparableIdentifiedDataSerializable |
POSITIVE_INFINITY
Represents a value that is equal to itself and greater than any other value.
|
Constructor and Description |
---|
CompositeValue()
Constructs a new composite value for the deserialization purposes.
|
CompositeValue(Comparable[] components)
Constructs a new composite value from the given components.
|
CompositeValue(int width,
Comparable prefix,
Comparable filler)
Constructs a new composite value of the given width having the given
prefix value as its first component and the filler value as its
remaining components.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(CompositeValue that) |
boolean |
equals(Object o) |
Comparable[] |
getComponents()
Returns the components of this composite value.
|
int |
getFactoryId()
Returns DataSerializableFactory factory ID for this class.
|
int |
getId()
Returns type identifier for this class.
|
int |
hashCode() |
void |
readData(ObjectDataInput in)
Reads fields from the input stream
|
String |
toString() |
void |
writeData(ObjectDataOutput out)
Writes object fields to output stream
|
public static final ComparableIdentifiedDataSerializable NEGATIVE_INFINITY
public static final ComparableIdentifiedDataSerializable POSITIVE_INFINITY
public CompositeValue()
public CompositeValue(Comparable[] components)
For performance reasons, the ownership of the passed components array is transferred to the newly constructed composite value.
public CompositeValue(int width, Comparable prefix, Comparable filler)
public Comparable[] getComponents()
For performance reasons, the internal components array is directly exposed to the caller.
public int compareTo(CompositeValue that)
compareTo
in interface Comparable<CompositeValue>
public int getFactoryId()
IdentifiedDataSerializable
getFactoryId
in interface IdentifiedDataSerializable
public int getId()
IdentifiedDataSerializable
getId
in interface IdentifiedDataSerializable
public void writeData(ObjectDataOutput out) throws IOException
DataSerializable
writeData
in interface DataSerializable
out
- outputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
output stream has been closed.public void readData(ObjectDataInput in) throws IOException
DataSerializable
readData
in interface DataSerializable
in
- inputIOException
- if an I/O error occurs. In particular,
an IOException
may be thrown if the
input stream has been closed.Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.