Package org.apache.druid.segment.column
Interface TypeSignature<Type extends TypeDescriptor>
-
- All Known Subinterfaces:
ColumnCapabilities
- All Known Implementing Classes:
BaseTypeSignature,ColumnCapabilitiesImpl,ColumnType,ExpressionType
@Immutable public interface TypeSignature<Type extends TypeDescriptor>This interface serves as a common foundation for Druids native type system, and provides common methods for reasoning about and handling type matters. Additional type common type handling methods are provided byTypesutility. This information is used by Druid to make decisions about how to correctly process inputs and determine output types at all layers of the engine, from how to group, filter, aggregate, and transform columns up to how to best plan SQL into native Druid queries. The native Druid type system can currently be broken down at a high level into 'primitive' types, 'array' types, and 'complex' types, and this classification is defined by an enumeration which implementsTypeDescriptorsuch asValueTypefor the general query engines andExprTypefor low level expression processing. This is exposed viagetType(), and will be most callers first point of contact with theTypeSignaturewhen trying to decide how to handle a given input. Druid 'primitive' types includes strings and numeric types. Note: multi-value string columns are still considered 'primitive' string types, because they do not behave as traditional arrays (unless explicitly converted to an array), and are always serialized as opportunistically single valued, so whether or not any particular string column is multi-valued might vary from segment to segment. The concept of multi-valued strings only exists at a very low engine level and are only modeled by the ColumnCapabilities implementation ofTypeSignature. 'array' types contain additional nested type information about the elements of an array, a reference to anotherTypeSignaturethrough thegetElementType()method. IfTypeDescriptor.isArray()is true, thengetElementType()should never return null. 'complex' types are Druids extensible types, which have a registry that allows these types to be defined and associated with a name which is available asgetComplexTypeName(). These type names are unique, so this information is used to allow handling of these 'complex' types to confirm.TypeSignatureis currently manifested in 3 forms:ColumnTypewhich is the high level 'native' Druid type definitions usingValueType, and is used by row signatures and SQL schemas, used by callers as input to various API methods, and most general purpose type handling. In 'druid-processing' there is an additional type ... type, ColumnCapabilities, which is effectively aColumnTypebut includes some additional information for low level query processing, such as details about whether a column has indexes, dictionaries, null values, is a multi-value string column, and more. The third isExpressionType, which instead ofValueTypeusesExprType, and is used exclusively for handling Druid native expression evaluation.ExpressionTypeexists because the Druid expression system does not natively handle float types, so it is essentially a mapping ofColumnTypewhere floats are coerced to double typed values. Ideally at some point Druid expressions can just handle floats directly, and these twoTypeSignaturecan be merged, which will simplify this interface to no longer need be generic, allowColumnTypeto be collapsed intoBaseTypeSignature, and finally unify the type system.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleananyOf(Type... types)Check if the value ofgetType()matches any of theTypeDescriptorspecified.default StringasTypeString()Convert aTypeSignatureinto a simple string.StringgetComplexTypeName()Type name of 'complex' types (ValueType.COMPLEX,ExprType.COMPLEX), which are 'registered' by their name, acting as a key to get the correct set of serialization, deserialization, and other type specific handling facilties.TypeSignature<Type>getElementType()default <T> NullableTypeStrategy<T>getNullableStrategy()ANullableTypeStrategyis aTypeStrategywhich can handle reading and writing null values, at the very high cost of an additional byte per value, of which a single bit is used to storeNullHandling.IS_NULL_BYTEorNullHandling.IS_NOT_NULL_BYTEas appropriate.<T> TypeStrategy<T>getStrategy()ATypeStrategyprovides facilities to reading and writing values to buffers, as well as basic value comparators and byte size estimation.TypegetType()TypeDescriptorenumeration used to handle different classes of typesdefault booleanis(Type candidate)Check if the value ofgetType()is equal to the candidateTypeDescriptor.default booleanisArray()Check if the type is an array (TypeDescriptor.isArray())default booleanisNumeric()Check if the type is numeric (TypeDescriptor.isNumeric())default booleanisPrimitive()Check if the type is a primitive (TypeDescriptor.isPrimitive(), e.g.default booleanisPrimitiveArray()
-
-
-
Method Detail
-
getType
Type getType()
TypeDescriptorenumeration used to handle different classes of types
-
getComplexTypeName
@Nullable String getComplexTypeName()
Type name of 'complex' types (ValueType.COMPLEX,ExprType.COMPLEX), which are 'registered' by their name, acting as a key to get the correct set of serialization, deserialization, and other type specific handling facilties. For other types, this value will be null.
-
getElementType
@Nullable TypeSignature<Type> getElementType()
TypeSignaturefor the elements contained in an array type (ValueType.ARRAY,ExprType.ARRAY). For non-array types, this value will be null.
-
getStrategy
<T> TypeStrategy<T> getStrategy()
ATypeStrategyprovides facilities to reading and writing values to buffers, as well as basic value comparators and byte size estimation. UsegetNullableStrategy()if you need to read and write values which might possibly be null and aren't handling this in a different (probably better) way.
-
getNullableStrategy
default <T> NullableTypeStrategy<T> getNullableStrategy()
ANullableTypeStrategyis aTypeStrategywhich can handle reading and writing null values, at the very high cost of an additional byte per value, of which a single bit is used to storeNullHandling.IS_NULL_BYTEorNullHandling.IS_NOT_NULL_BYTEas appropriate. This pattern is common among buffer aggregators, which don't have access to an external memory location for more efficient tracking of null values and must store this information inline with the accumulated value.
-
is
default boolean is(Type candidate)
Check if the value ofgetType()is equal to the candidateTypeDescriptor.
-
anyOf
default boolean anyOf(Type... types)
Check if the value ofgetType()matches any of theTypeDescriptorspecified.
-
isNumeric
default boolean isNumeric()
Check if the type is numeric (TypeDescriptor.isNumeric())
-
isPrimitive
default boolean isPrimitive()
Check if the type is a primitive (TypeDescriptor.isPrimitive(), e.g. not an array, not a complex type)
-
isArray
default boolean isArray()
Check if the type is an array (TypeDescriptor.isArray())
-
isPrimitiveArray
default boolean isPrimitiveArray()
-
asTypeString
default String asTypeString()
Convert aTypeSignatureinto a simple string. This value can be converted back into aTypeSignaturewithTypes.fromString(TypeFactory, String).
-
-