Package org.apache.cassandra.db.marshal
Class IntegerType
- All Implemented Interfaces:
Comparator<ByteBuffer>,AssignmentTestable
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.NumberType
NumberType.NumberArgumentDeserializer<M extends org.apache.commons.lang3.mutable.Mutable<Number>>Nested classes/interfaces inherited from class org.apache.cassandra.db.marshal.AbstractType
AbstractType.ComparisonType, AbstractType.DefaultArgumentDeserializerNested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult -
Field Summary
FieldsFields inherited from class org.apache.cassandra.db.marshal.AbstractType
comparatorSet, comparisonType, isByteOrderComparable, reverseComparator -
Method Summary
Modifier and TypeMethodDescriptionTakes the absolute value of the argument.Adds the left argument to the right one.booleanDefines if the type allows an empty set of bytes (new byte[0]) as valid input.<V> ByteSourceasComparableBytes(ValueAccessor<V> accessor, V data, ByteComparable.Version version) Constructs a byte-comparable representation of the number.<VL,VR> int compareCustom(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 semanticsstatic <VL,VR> int compareIntegers(VL lhs, ValueAccessor<VL> accessorL, VR rhs, ValueAccessor<VR> accessorR) Divides the left argument by the right one.Raises e to the power of the argument.<V> VfromComparableBytes(ValueAccessor<V> accessor, ByteSource.Peekable comparableBytes, ByteComparable.Version version) Translates the given byte-ordered representation to the common, non-byte-ordered binary representation of a payload for this abstract type (the latter, common binary representation is what we mostly work with in the storage engine internals).fromJSONObject(Object parsed) Given a parsed JSON string, return a byte representation of the object.fromString(String source) get a byte representation of the given string.booleanbooleanisValueCompatibleWithInternal(AbstractType<?> otherType) Needed to handle ReversedType in value-compatibility checks.Takes the natural logrithm of the argument.Takes the log base 10 of the arguement.Return the remainder.Multiplies the left argument with the right one.Negates the argument.Rounds the argument to the nearest whole number.Substracts the left argument from the right one.toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion) Converts the specified value into its JSON representation.Methods inherited from class org.apache.cassandra.db.marshal.NumberType
isFloatingPointMethods inherited from class org.apache.cassandra.db.marshal.AbstractType
asComparableBytes, asCQLTypeStringList, checkComparable, compare, compare, compareCollectionMembers, compareForCQL, compose, compose, decompose, decomposeUntyped, expandUserTypes, freeze, freezeNestedMulticellTypes, fromComparableBytes, getCompatibleTypeIfKnown, getComponents, getString, getString, getString, isCollection, isCompatibleWith, isCounter, isFreezable, isFrozenCollection, isMultiCell, isNull, isNull, isReversed, isSerializationCompatibleWith, isTuple, isUDT, isValueCompatibleWith, isValueLengthFixed, isVector, parseDefaultParameters, read, readArray, readBuffer, readBuffer, referencesDuration, referencesUserType, referencesUserType, skipValue, subTypes, testAssignment, testAssignment, toCQLString, toJSONString, toString, toString, udfType, unfreeze, unwrap, validate, validate, validateCellValue, validateCollectionMember, valueLengthIfFixed, withUpdatedUserType, writeValue, writeValue, writtenLength, writtenLengthMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
instance
-
FULL_FORM_THRESHOLD
public static final int FULL_FORM_THRESHOLD- See Also:
-
-
Method Details
-
allowsEmpty
public boolean allowsEmpty()Description copied from class:AbstractTypeDefines if the type allows an empty set of bytes (new byte[0]) as valid input. TheAbstractType.validate(Object, ValueAccessor)andAbstractType.compose(Object, ValueAccessor)methods must allow empty bytes when this returns true, and must reject empty bytes when this is false. As of this writing, the main user of this API is for testing to know what types allow empty values and what types don't, so that the data that gets generated understands whenByteBufferUtil.EMPTY_BYTE_BUFFERis allowed as valid data.- Overrides:
allowsEmptyin classAbstractType<BigInteger>
-
isEmptyValueMeaningless
public boolean isEmptyValueMeaningless()Description copied from class:AbstractType- Overrides:
isEmptyValueMeaninglessin classAbstractType<BigInteger>
-
compareCustom
public <VL,VR> int compareCustom(VL left, ValueAccessor<VL> accessorL, VR right, ValueAccessor<VR> accessorR) Description copied from class:AbstractTypeImplement 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:
compareCustomin classAbstractType<BigInteger>
-
compareIntegers
public static <VL,VR> int compareIntegers(VL lhs, ValueAccessor<VL> accessorL, VR rhs, ValueAccessor<VR> accessorR) -
asComparableBytes
public <V> ByteSource asComparableBytes(ValueAccessor<V> accessor, V data, ByteComparable.Version version) Constructs a byte-comparable representation of the number. In the current format we represent it: directly as varint, if the length is 6 or smaller (the encoding has non-00/FF first byte)<signbyte><length as unsigned integer - 7><7 or more bytes>, otherwise where<signbyte>is 00 for negative numbers and FF for positive ones, and the length's bytes are inverted if the number is negative (so that longer length sorts smaller). Because we present the sign separately, we don't need to include 0x00 prefix for positive integers whose first byte is >= 0x80 or 0xFF prefix for negative integers whose first byte is < 0x80. Note that we do this before taking the length for the purposes of choosing between varint and full-form encoding. The representations are prefix-free, because the choice between varint and full-form encoding is determined by the first byte where varints are properly ordered between full-form negative and full-form positive, varint encoding is prefix-free, and full-form representations of different length always have length bytes that differ. Examples: -1 as 7F 0 as 80 1 as 81 127 as C07F 255 as C0FF 2^32-1 as F8FFFFFFFF 2^32 as F900000000 2^56-1 as FEFFFFFFFFFFFFFF 2^56 as FF000100000000000000 SeeasComparableBytesLegacy(org.apache.cassandra.db.marshal.ValueAccessor<V>, V, int, int, int)for description of the legacy format.- Overrides:
asComparableBytesin classAbstractType<BigInteger>
-
fromComparableBytes
public <V> V fromComparableBytes(ValueAccessor<V> accessor, ByteSource.Peekable comparableBytes, ByteComparable.Version version) Description copied from class:AbstractTypeTranslates the given byte-ordered representation to the common, non-byte-ordered binary representation of a payload for this abstract type (the latter, common binary representation is what we mostly work with in the storage engine internals). If the given bytes don't correspond to the encoding of some payload value for this abstract type, anIllegalArgumentExceptionmay be thrown.- Overrides:
fromComparableBytesin classAbstractType<BigInteger>- Parameters:
accessor- value accessor used to construct the value.comparableBytes- A byte-ordered representation (presumably of a payload for this abstract type).version- The byte-comparable version used to construct the representation.- Returns:
- A of a payload for this abstract type, corresponding to the given byte-ordered representation, constructed using the supplied value accessor.
- See Also:
-
fromString
Description copied from class:AbstractTypeget a byte representation of the given string.- Specified by:
fromStringin classAbstractType<BigInteger>- Throws:
MarshalException
-
fromJSONObject
Description copied from class:AbstractTypeGiven a parsed JSON string, return a byte representation of the object.- Specified by:
fromJSONObjectin classAbstractType<BigInteger>- Parameters:
parsed- the result of parsing a json string- Throws:
MarshalException
-
toJSONString
Description copied from class:AbstractTypeConverts the specified value into its JSON representation.The buffer position will stay the same.
- Overrides:
toJSONStringin classAbstractType<BigInteger>- Parameters:
buffer- the value to convertprotocolVersion- the protocol version to use for the conversion- Returns:
- a JSON string representing the specified value
-
isValueCompatibleWithInternal
Description copied from class:AbstractTypeNeeded to handle ReversedType in value-compatibility checks. Subclasses should implement this instead of isValueCompatibleWith().- Overrides:
isValueCompatibleWithInternalin classAbstractType<BigInteger>
-
asCQL3Type
- Overrides:
asCQL3Typein classAbstractType<BigInteger>
-
getSerializer
- Specified by:
getSerializerin classAbstractType<BigInteger>
-
getArgumentDeserializer
- Overrides:
getArgumentDeserializerin classAbstractType<BigInteger>- Returns:
- the deserializer used to deserialize the function arguments of this type.
-
add
Description copied from class:NumberTypeAdds the left argument to the right one.- Specified by:
addin classNumberType<BigInteger>- Parameters:
left- the left argumentright- the right argument- Returns:
- the addition result
-
substract
Description copied from class:NumberTypeSubstracts the left argument from the right one.- Specified by:
substractin classNumberType<BigInteger>- Parameters:
left- the left argumentright- the right argument- Returns:
- the substraction result
-
multiply
Description copied from class:NumberTypeMultiplies the left argument with the right one.- Specified by:
multiplyin classNumberType<BigInteger>- Parameters:
left- the left argumentright- the right argument- Returns:
- the multiplication result
-
divide
Description copied from class:NumberTypeDivides the left argument by the right one.- Specified by:
dividein classNumberType<BigInteger>- Parameters:
left- the left argumentright- the right argument- Returns:
- the division result
-
mod
Description copied from class:NumberTypeReturn the remainder.- Specified by:
modin classNumberType<BigInteger>- Parameters:
left- the left argumentright- the right argument- Returns:
- the remainder
-
negate
Description copied from class:NumberTypeNegates the argument.- Specified by:
negatein classNumberType<BigInteger>- Parameters:
input- the argument to negate- Returns:
- the negated argument
-
abs
Description copied from class:NumberTypeTakes the absolute value of the argument.- Specified by:
absin classNumberType<BigInteger>- Parameters:
input- the argument to take the absolute value of- Returns:
- a ByteBuffer containing the absolute value of the argument. The type of the contents of the ByteBuffer will match that of the input.
-
exp
Description copied from class:NumberTypeRaises e to the power of the argument.- Specified by:
expin classNumberType<BigInteger>- Parameters:
input- the argument to raise e to- Returns:
- a ByteBuffer containg the value of e (the base of natural logarithms) raised to the power of the argument. The type of the contents of the ByteBuffer will be a double, unless the input is a DecimalType or IntegerType, in which the ByteBuffer will contain a DecimalType.
-
log
Description copied from class:NumberTypeTakes the natural logrithm of the argument.- Specified by:
login classNumberType<BigInteger>- Parameters:
input- the argument to take the natural log (ln) of- Returns:
- a ByteBuffer containg the log base e (ln) of the argument. The type of the contents of the ByteBuffer will be a double, unless the input is a DecimalType or IntegerType, in which the ByteBuffer will contain a DecimalType.
-
log10
Description copied from class:NumberTypeTakes the log base 10 of the arguement.- Specified by:
log10in classNumberType<BigInteger>- Parameters:
input- the argument to take the log base ten of- Returns:
- a ByteBuffer containg the log base 10 of the argument. The type of the contents of the ByteBuffer will be a double, unless the input is a DecimalType or IntegerType, in which the ByteBuffer will contain a DecimalType.
-
round
Description copied from class:NumberTypeRounds the argument to the nearest whole number.- Specified by:
roundin classNumberType<BigInteger>- Parameters:
input- the argument to round- Returns:
- a ByteBuffer containg the rounded argument. If the input is an integral type, the ByteBuffer will contain a copy of the input. If the input is a float, the ByteBuffer will contain an int32. If the input is a double, the output will contain a long. If the input is a DecimalType, the output will contain an IntegerType.
-
getMaskedValue
- Overrides:
getMaskedValuein classAbstractType<BigInteger>- Returns:
- A fixed, serialized value to be used when the column is masked, to be returned instead of the real value.
-