Package org.apache.druid.segment.column
Interface TypeSignature<Type extends TypeDescriptor>
-
- All Known Subinterfaces:
ColumnCapabilities
- All Known Implementing Classes:
BaseTypeSignature
,ColumnCapabilitiesImpl
,ColumnType
,ExpressionType
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 byTypes
utility. 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 implementsTypeDescriptor
such asValueType
for the general query engines andExprType
for low level expression processing. This is exposed viagetType()
, and will be most callers first point of contact with theTypeSignature
when 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 anotherTypeSignature
through 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.TypeSignature
is currently manifested in 3 forms:ColumnType
which 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 aColumnType
but 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 ofValueType
usesExprType
, and is used exclusively for handling Druid native expression evaluation.ExpressionType
exists because the Druid expression system does not natively handle float types, so it is essentially a mapping ofColumnType
where floats are coerced to double typed values. Ideally at some point Druid expressions can just handle floats directly, and these twoTypeSignature
can be merged, which will simplify this interface to no longer need be generic, allowColumnType
to 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 boolean
anyOf(Type... types)
Check if the value ofgetType()
matches any of theTypeDescriptor
specified.default String
asTypeString()
Convert aTypeSignature
into a simple string.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.TypeSignature<Type>
getElementType()
default <T> NullableTypeStrategy<T>
getNullableStrategy()
ANullableTypeStrategy
is aTypeStrategy
which 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_BYTE
orNullHandling.IS_NOT_NULL_BYTE
as appropriate.<T> TypeStrategy<T>
getStrategy()
ATypeStrategy
provides facilities to reading and writing values to buffers, as well as basic value comparators and byte size estimation.Type
getType()
TypeDescriptor
enumeration used to handle different classes of typesdefault boolean
is(Type candidate)
Check if the value ofgetType()
is equal to the candidateTypeDescriptor
.default boolean
isArray()
Check if the type is an array (TypeDescriptor.isArray()
)default boolean
isNumeric()
Check if the type is numeric (TypeDescriptor.isNumeric()
)default boolean
isPrimitive()
Check if the type is a primitive (TypeDescriptor.isPrimitive()
, e.g.default boolean
isPrimitiveArray()
-
-
-
Method Detail
-
getType
Type getType()
TypeDescriptor
enumeration 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()
TypeSignature
for 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()
ATypeStrategy
provides 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()
ANullableTypeStrategy
is aTypeStrategy
which 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_BYTE
orNullHandling.IS_NOT_NULL_BYTE
as 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 theTypeDescriptor
specified.
-
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 aTypeSignature
into a simple string. This value can be converted back into aTypeSignature
withTypes.fromString(TypeFactory, String)
.
-
-