Package org.apache.cassandra.db.marshal
Class TimestampType
- java.lang.Object
-
- org.apache.cassandra.db.marshal.AbstractType<T>
-
- org.apache.cassandra.db.marshal.TemporalType<java.util.Date>
-
- org.apache.cassandra.db.marshal.TimestampType
-
- All Implemented Interfaces:
java.util.Comparator<java.nio.ByteBuffer>
,AssignmentTestable
public class TimestampType extends TemporalType<java.util.Date>
Type for date-time values. This is meant as a replacement for DateType, as DateType wrongly compare pre-unix-epoch dates, sorting them *after* post-unix-epoch ones (due to it's use of unsigned bytes comparison).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.AbstractType
AbstractType.ComparisonType
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult
-
-
Field Summary
Fields Modifier and Type Field Description static TimestampType
instance
-
Fields inherited from class org.apache.cassandra.db.marshal.AbstractType
comparatorSet, comparisonType, isByteOrderComparable, reverseComparator
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CQL3Type
asCQL3Type()
<VL,VR>
intcompareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR)
Implement IFF ComparisonType is CUSTOM Compares the byte representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semanticsTerm
fromJSONObject(java.lang.Object parsed)
Given a parsed JSON string, return a byte representation of the object.java.nio.ByteBuffer
fromString(java.lang.String source)
get a byte representation of the given string.java.nio.ByteBuffer
fromTimeInMillis(long millis)
Returns the temporal value corresponding to the specified UNIX timestamp.TypeSerializer<java.util.Date>
getSerializer()
boolean
isCompatibleWith(AbstractType<?> previous)
Returns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this.boolean
isEmptyValueMeaningless()
boolean
isValueCompatibleWithInternal(AbstractType<?> otherType)
Needed to handle ReversedType in value-compatibility checks.java.lang.String
toJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)
Converts the specified value into its JSON representation.long
toTimeInMillis(java.nio.ByteBuffer value)
Converts this temporal in UNIX timestamp.protected void
validateDuration(Duration duration)
Validates that the duration has the correct precision.int
valueLengthIfFixed()
The length of values for this type if all values are of fixed length, -1 otherwise.-
Methods inherited from class org.apache.cassandra.db.marshal.TemporalType
addDuration, now, substractDuration
-
Methods inherited from class org.apache.cassandra.db.marshal.AbstractType
asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareForCQL, compose, compose, decompose, expandUserTypes, freeze, freezeNestedMulticellTypes, getComponents, getString, getString, getString, isCollection, isCounter, isFreezable, isFrozenCollection, isMultiCell, isReversed, isTuple, isUDT, isValueCompatibleWith, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesDuration, referencesUserType, referencesUserType, skipValue, subTypes, testAssignment, testAssignment, toJSONString, toString, toString, validate, validate, validateCellValue, validateCollectionMember, withUpdatedUserType, writeValue, writeValue, writtenLength, writtenLength
-
-
-
-
Field Detail
-
instance
public static final TimestampType instance
-
-
Method Detail
-
isEmptyValueMeaningless
public boolean isEmptyValueMeaningless()
Description copied from class:AbstractType
- Overrides:
isEmptyValueMeaningless
in classAbstractType<java.util.Date>
-
compareCustom
public <VL,VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR)
Description copied from class:AbstractType
Implement IFF ComparisonType is CUSTOM Compares the byte representation of two instances of this class, for types where this cannot be done by simple in-order comparison of the unsigned bytes Standard Java compare semantics- Overrides:
compareCustom
in classAbstractType<java.util.Date>
-
fromString
public java.nio.ByteBuffer fromString(java.lang.String source) throws MarshalException
Description copied from class:AbstractType
get a byte representation of the given string.- Specified by:
fromString
in classAbstractType<java.util.Date>
- Throws:
MarshalException
-
fromTimeInMillis
public java.nio.ByteBuffer fromTimeInMillis(long millis) throws MarshalException
Description copied from class:TemporalType
Returns the temporal value corresponding to the specified UNIX timestamp.- Overrides:
fromTimeInMillis
in classTemporalType<java.util.Date>
- Parameters:
millis
- the UNIX timestamp to convert- Returns:
- the temporal value corresponding to the specified UNIX timestamp
- Throws:
MarshalException
-
toTimeInMillis
public long toTimeInMillis(java.nio.ByteBuffer value)
Description copied from class:TemporalType
Converts this temporal in UNIX timestamp.- Overrides:
toTimeInMillis
in classTemporalType<java.util.Date>
- Parameters:
value
- the temporal value.- Returns:
- the UNIX timestamp corresponding to this temporal.
-
fromJSONObject
public Term fromJSONObject(java.lang.Object parsed) throws MarshalException
Description copied from class:AbstractType
Given a parsed JSON string, return a byte representation of the object.- Specified by:
fromJSONObject
in classAbstractType<java.util.Date>
- Parameters:
parsed
- the result of parsing a json string- Throws:
MarshalException
-
toJSONString
public java.lang.String toJSONString(java.nio.ByteBuffer buffer, ProtocolVersion protocolVersion)
Description copied from class:AbstractType
Converts the specified value into its JSON representation.The buffer position will stay the same.
- Overrides:
toJSONString
in classAbstractType<java.util.Date>
- Parameters:
buffer
- the value to convertprotocolVersion
- the protocol version to use for the conversion- Returns:
- a JSON string representing the specified value
-
isCompatibleWith
public boolean isCompatibleWith(AbstractType<?> previous)
Description copied from class:AbstractType
Returns true if this comparator is compatible with the provided previous comparator, that is if previous can safely be replaced by this. A comparator cn should be compatible with a previous one cp if forall columns c1 and c2, if cn.validate(c1) and cn.validate(c2) and cn.compare(c1, c2) == v, then cp.validate(c1) and cp.validate(c2) and cp.compare(c1, c2) == v. Note that a type should be compatible with at least itself and when in doubt, keep the default behavior of not being compatible with any other comparator!- Overrides:
isCompatibleWith
in classAbstractType<java.util.Date>
-
isValueCompatibleWithInternal
public boolean isValueCompatibleWithInternal(AbstractType<?> otherType)
Description copied from class:AbstractType
Needed to handle ReversedType in value-compatibility checks. Subclasses should implement this instead of isValueCompatibleWith().- Overrides:
isValueCompatibleWithInternal
in classAbstractType<java.util.Date>
-
asCQL3Type
public CQL3Type asCQL3Type()
- Overrides:
asCQL3Type
in classAbstractType<java.util.Date>
-
getSerializer
public TypeSerializer<java.util.Date> getSerializer()
- Specified by:
getSerializer
in classAbstractType<java.util.Date>
-
valueLengthIfFixed
public int valueLengthIfFixed()
Description copied from class:AbstractType
The length of values for this type if all values are of fixed length, -1 otherwise.- Overrides:
valueLengthIfFixed
in classAbstractType<java.util.Date>
-
validateDuration
protected void validateDuration(Duration duration)
Description copied from class:TemporalType
Validates that the duration has the correct precision.- Overrides:
validateDuration
in classTemporalType<java.util.Date>
- Parameters:
duration
- the duration to validate.
-
-