public class VHash
extends java.lang.Object
Constructor and Description |
---|
VHash()
Creates an instance suitable for computing a hash of a chain of values,
for use when a projection is segmented by multiple columns.
|
Modifier and Type | Method and Description |
---|---|
void |
addBoolean(boolean v)
adds hash of boolean value to the chain.
|
void |
addBooleanNull()
adds hash of boolean null value to the chain.
|
void |
addBytes(byte[] v)
adds hash of binary value to the chain.
|
void |
addDate(java.util.Date v,
java.util.Calendar c)
adds hash of Date value to the chain.
|
void |
addDate(java.sql.Date v,
java.util.Calendar c)
adds hash of Date value to the chain.
|
void |
addDouble(double v)
adds hash of double value to the chain.
|
void |
addDoubleNull()
adds hash of double null value to the chain.
|
void |
addLong(long v)
adds hash of long value to the chain.
|
void |
addNull()
Adds hash of null value to the chain.
|
void |
addNumeric(java.math.BigDecimal src,
int typemod)
adds hash of numeric value to the chain
|
void |
addString(java.lang.String v)
adds hash of String value to the chain.
|
void |
addTime(java.util.Date v,
java.util.Calendar c)
adds hash of Time value to the chain.
|
void |
addTime(java.sql.Time v,
java.util.Calendar c)
adds hash of Time value to the chain.
|
void |
addTimestamp(java.util.Date v,
java.util.Calendar c)
adds hash of Timestamp value to the chain.
|
void |
addTimestamp(long v)
adds hash of Timestamp value expressed as milliseconds since Jan 1, 1970 UTC to the chain.
|
void |
addTimestamp(java.sql.Timestamp v,
java.util.Calendar c)
adds hash of Timestamp value to the chain.
|
void |
addUUID(java.util.UUID v)
adds hash of UUID value to the chain.
|
void |
addUUIDNull()
adds hash of null UUID to the chain.
|
long |
getHash()
returns the current hash value
|
static java.lang.String |
getNodeFor(java.sql.Connection conn,
java.lang.String schema,
java.lang.String proj,
long hashValue)
Returns the name of the node that will be responsible for the provided value in the hash space
for a given projection.
|
static java.lang.String |
getNodeFor(java.lang.String getProjSegmentsOutput,
long hashValue)
Given a projection's get_projection_segments() output, this
method will return the node that is responsible for the provided hashValue.
|
static long |
hashBoolean(boolean v)
compute hash of boolean value
|
static long |
hashBooleanNull()
compute hash of boolean null value
|
static long |
hashBytes(byte[] b)
compute hash of a binary value
|
static long |
hashBytesNull()
compute hash of a binary null value
|
static long |
hashBytesNull(long input)
compute hash of a binary null value
|
static long |
hashDate(java.util.Date v)
compute hash of java.util.Date value
|
static long |
hashDate(java.sql.Date v)
compute hash of java.sql.Date value
|
static long |
hashDouble(double v)
compute hash of double value
|
static long |
hashDoubleNull()
compute hash of double null value
|
static long |
hashLong(long v)
compute hash of long value
|
static long |
hashNull()
Compute hash of null value
|
static long |
hashNull(long input)
compute hash of null value.
|
static long |
hashNumeric(java.math.BigDecimal src,
int typemod)
compute hash of a numeric value
|
static long |
hashString(java.lang.String s)
compute hash of String value
|
static long |
hashStringNull()
compute hash of String null value
|
static long |
hashTime(java.sql.Time v)
compute hash of Time value
|
static long |
hashTimestamp(long java_ms)
compute hash of Timestamp value expressed in milliseconds since Jan 1, 1970.
|
static long |
hashTimestamp(java.sql.Timestamp v)
compute hash of java.sql.Timestamp value
|
static long |
hashUUID(java.util.UUID v,
long input)
compute hash of UUID value.
|
static long |
hashUUIDNull()
compute a hash of a null UUID value.
|
static long |
hashUUIDNull(long input)
compute a hash of a null UUID value.
|
void |
reset()
resets hash value for next chain.
|
public VHash()
public static long hashBooleanNull()
public static long hashBoolean(boolean v)
v
- boolean value to hashpublic static long hashLong(long v)
v
- long value to hashpublic static long hashNull(long input)
input
- long value from previous hash function outputpublic static long hashNull()
public static long hashUUID(java.util.UUID v, long input)
v
- fixed binary value to hashpublic static long hashUUIDNull(long input)
input
- long value from previous hash function outputpublic static long hashUUIDNull()
public static long hashDouble(double v)
v
- double value to hashpublic static long hashDoubleNull()
public static long hashTimestamp(long java_ms)
java_ms
- A number of milliseconds since Jan 1, 1970 GMTpublic static long hashDate(java.util.Date v)
v
- Date value to hashpublic static long hashDate(java.sql.Date v)
v
- Date value to hashpublic static long hashTimestamp(java.sql.Timestamp v)
v
- Timestamp value to hashpublic static long hashTime(java.sql.Time v)
v
- Time value to hashpublic static long hashString(java.lang.String s)
s
- String value to hashpublic static long hashStringNull()
public static long hashBytesNull()
public static long hashBytesNull(long input)
input
- long value from previous hash function outputpublic static long hashBytes(byte[] b)
b
- binary value to hashpublic static long hashNumeric(java.math.BigDecimal src, int typemod)
src
- Numeric value to hashtypemod
- The precision and scale of the numeric.public void reset()
public void addNull()
hashBooleanNull()
to hash a boolean null.public void addBoolean(boolean v)
v
- boolean value to hashpublic void addBooleanNull()
public void addLong(long v)
v
- long value to hashpublic void addUUID(java.util.UUID v)
v
- fixed binary value to hashpublic void addUUIDNull()
public void addString(java.lang.String v)
v
- String value to hashpublic void addBytes(byte[] v)
v
- String value to hashpublic void addTimestamp(long v)
v
- long value to hashpublic void addDate(java.util.Date v, java.util.Calendar c)
v
- Date value to hashc
- The calendar to providing a timezone context for v.public void addDate(java.sql.Date v, java.util.Calendar c)
v
- Date value to hash.c
- The calendar to providing a timezone context for v.public void addTimestamp(java.sql.Timestamp v, java.util.Calendar c)
v
- Timestamp value to hashc
- The calendar to providing a timezone context for v.public void addTimestamp(java.util.Date v, java.util.Calendar c)
v
- Timestamp value to hashc
- The calendar to providing a timezone context for v.public void addTime(java.sql.Time v, java.util.Calendar c)
v
- Time value to hashc
- The calendar to providing a timezone context for v. The date component of the calendar will influence the time due to DST.public void addTime(java.util.Date v, java.util.Calendar c)
v
- Time value to hashc
- The calendar to providing a timezone context for v. The date component of the calendar will influence the time due to DST.public void addDouble(double v)
v
- double value to hashpublic void addDoubleNull()
public void addNumeric(java.math.BigDecimal src, int typemod)
typemod
- The precision and scale of the numeric.java.lang.IllegalArgumentException
- if src is too large to fit in a numeric.public long getHash()
public static java.lang.String getNodeFor(java.sql.Connection conn, java.lang.String schema, java.lang.String proj, long hashValue) throws java.sql.SQLException
getNodeFor(String, long)
to determine
which node to use.
In situations where you need to compute many hashes for the same projection, it is
would be much more efficient to call get_projection_segments() once via JDBC and
then pass that output to getNodeFor(String, long)
directly.
Caution: There is no guarantee that connecting to the node returned by
this method will guarantee reduced intra-node traffic for a query or load based on the
input hash value. While that is often true, the Vertica Optmizer may not always construct
such a plan.
Additionally, no check is done to ensure that the input hash value was created in a manner that is consistent with the segmentation of the provided projection. This means, for example, if the projection is segmented by an INTEGER column and the caller provides a hashed DOUBLE PRECISION value, the answer may not be correct.
conn
- A connection to a vertica database containing the projectionschema
- The schema of the projectionproj
- The name of the projectionhashValue
- A hashed data value for this projectionjava.sql.SQLException
- If a database error occursjava.lang.IllegalArgumentException
- if the projection provided is not segmented by HASH(...) ALL NODESpublic static java.lang.String getNodeFor(java.lang.String getProjSegmentsOutput, long hashValue)
Additionally, no check is done to ensure that the input hash value was created in a manner that is consistent with the segmentation of the provided projection. This means, for example, if the projection is segmented by an INTEGER column and the caller provides a hashed DOUBLE PRECISION value, the answer may not be correct.
getProjSegmentsOutput
- -- a String containing the return value of the get_projection_segments() SQL meta-function for a particular projection.hashValue
- -- a hashed data value for the projection.java.lang.IllegalArgumentException
- if getProjSegmentsOutput is malformed in any way, either due to bad input or due to not using a properly segmented projection.