Package org.apache.druid.segment
Class DimensionHandlerUtils
- java.lang.Object
-
- org.apache.druid.segment.DimensionHandlerUtils
-
public final class DimensionHandlerUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static ColumnCapabilitiesDEFAULT_STRING_CAPABILITIESstatic ConcurrentHashMap<String,DimensionHandlerProvider>DIMENSION_HANDLER_PROVIDERSstatic DoubleZERO_DOUBLEstatic FloatZERO_FLOATstatic LongZERO_LONG
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Object[]coerceToObjectArrayWithElementCoercionFunction(Object obj, Function<Object,Object> coercionFunction)static Object[]coerceToStringArray(Object obj)static intcompareObjectsAsType(Object lhs, Object rhs, ColumnType type)static Function<Object,Object>converterFromTypeToType(TypeSignature<ValueType> fromType, TypeSignature<ValueType> toType)Used by TopN engine for type coercionstatic DoubleconvertObjectToDouble(Object valObj)static DoubleconvertObjectToDouble(Object valObj, boolean reportParseExceptions)static FloatconvertObjectToFloat(Object valObj)static FloatconvertObjectToFloat(Object valObj, boolean reportParseExceptions)static LongconvertObjectToLong(Object valObj)static LongconvertObjectToLong(Object valObj, boolean reportParseExceptions)static StringconvertObjectToString(Object valObj)static ObjectconvertObjectToType(Object obj, TypeSignature<ValueType> type)static ObjectconvertObjectToType(Object obj, TypeSignature<ValueType> type, boolean reportParseExceptions)static Object[]convertToArray(Object obj, TypeSignature<ValueType> elementType)static <Strategy extends ColumnSelectorStrategy>
ColumnSelectorPlus<Strategy>createColumnSelectorPlus(ColumnSelectorStrategyFactory<Strategy> strategyFactory, DimensionSpec dimensionSpec, ColumnSelectorFactory cursor)Convenience function equivalent to callingcreateColumnSelectorPluses(ColumnSelectorStrategyFactory, List, ColumnSelectorFactory)with a singleton list of dimensionSpecs and then retrieving the only element in the returned array.static <Strategy extends ColumnSelectorStrategy>
ColumnSelectorPlus<Strategy>[]createColumnSelectorPluses(ColumnSelectorStrategyFactory<Strategy> strategyFactory, List<DimensionSpec> dimensionSpecs, ColumnSelectorFactory columnSelectorFactory)Creates an array of ColumnSelectorPlus objects, selectors that handle type-specific operations within query processing engines, using a strategy factory provided by the query engine.static LonggetExactLongFromDecimalString(String decimalStr)Convert a string representing a decimal value to a long.static DimensionHandler<?,?,?>getHandlerFromCapabilities(String dimensionName, ColumnCapabilities capabilities, DimensionSchema.MultiValueHandling multiValueHandling)static List<ColumnType>getValueTypesFromDimensionSpecs(List<DimensionSpec> dimSpecs)static booleanisNumericNull(Object o)static DoublenullToZero(Double number)static FloatnullToZero(Float number)static LongnullToZero(Long number)static voidregisterDimensionHandlerProvider(String type, DimensionHandlerProvider provider)
-
-
-
Field Detail
-
ZERO_DOUBLE
public static final Double ZERO_DOUBLE
-
ZERO_FLOAT
public static final Float ZERO_FLOAT
-
ZERO_LONG
public static final Long ZERO_LONG
-
DEFAULT_STRING_CAPABILITIES
public static final ColumnCapabilities DEFAULT_STRING_CAPABILITIES
-
DIMENSION_HANDLER_PROVIDERS
public static final ConcurrentHashMap<String,DimensionHandlerProvider> DIMENSION_HANDLER_PROVIDERS
-
-
Method Detail
-
registerDimensionHandlerProvider
public static void registerDimensionHandlerProvider(String type, DimensionHandlerProvider provider)
-
getHandlerFromCapabilities
public static DimensionHandler<?,?,?> getHandlerFromCapabilities(String dimensionName, @Nullable ColumnCapabilities capabilities, @Nullable DimensionSchema.MultiValueHandling multiValueHandling)
-
getValueTypesFromDimensionSpecs
public static List<ColumnType> getValueTypesFromDimensionSpecs(List<DimensionSpec> dimSpecs)
-
createColumnSelectorPlus
public static <Strategy extends ColumnSelectorStrategy> ColumnSelectorPlus<Strategy> createColumnSelectorPlus(ColumnSelectorStrategyFactory<Strategy> strategyFactory, DimensionSpec dimensionSpec, ColumnSelectorFactory cursor)
Convenience function equivalent to callingcreateColumnSelectorPluses(ColumnSelectorStrategyFactory, List, ColumnSelectorFactory)with a singleton list of dimensionSpecs and then retrieving the only element in the returned array.- Type Parameters:
Strategy- The strategy type created by the provided strategy factory.- Parameters:
strategyFactory- A factory provided by query engines that generates type-handling strategiesdimensionSpec- column to generate a ColumnSelectorPlus object forcursor- Used to create value selectors for columns.- Returns:
- A ColumnSelectorPlus object
- See Also:
which may replace this in the future
-
createColumnSelectorPluses
public static <Strategy extends ColumnSelectorStrategy> ColumnSelectorPlus<Strategy>[] createColumnSelectorPluses(ColumnSelectorStrategyFactory<Strategy> strategyFactory, List<DimensionSpec> dimensionSpecs, ColumnSelectorFactory columnSelectorFactory)
Creates an array of ColumnSelectorPlus objects, selectors that handle type-specific operations within query processing engines, using a strategy factory provided by the query engine. One ColumnSelectorPlus will be created for each column specified in dimensionSpecs.The ColumnSelectorPlus provides access to a type strategy (e.g., how to group on a float column) and a value selector for a single column.
A caller should define a strategy factory that provides an interface for type-specific operations in a query engine. See GroupByStrategyFactory for a reference.
- Type Parameters:
Strategy- The strategy type created by the provided strategy factory.- Parameters:
strategyFactory- A factory provided by query engines that generates type-handling strategiesdimensionSpecs- The set of columns to generate ColumnSelectorPlus objects forcolumnSelectorFactory- Used to create value selectors for columns.- Returns:
- An array of ColumnSelectorPlus objects, in the order of the columns specified in dimensionSpecs
- See Also:
which may replace this in the future
-
convertObjectToString
@Nullable public static String convertObjectToString(@Nullable Object valObj)
-
convertObjectToLong
@Nullable public static Long convertObjectToLong(@Nullable Object valObj, boolean reportParseExceptions)
-
convertObjectToFloat
@Nullable public static Float convertObjectToFloat(@Nullable Object valObj, boolean reportParseExceptions)
-
convertObjectToType
@Nullable public static Object convertObjectToType(@Nullable Object obj, TypeSignature<ValueType> type, boolean reportParseExceptions)
-
convertToArray
@Nullable public static Object[] convertToArray(Object obj, TypeSignature<ValueType> elementType)
-
coerceToObjectArrayWithElementCoercionFunction
@Nullable public static Object[] coerceToObjectArrayWithElementCoercionFunction(@Nullable Object obj, Function<Object,Object> coercionFunction)
-
compareObjectsAsType
public static int compareObjectsAsType(@Nullable Object lhs, @Nullable Object rhs, ColumnType type)
-
convertObjectToType
@Nullable public static Object convertObjectToType(@Nullable Object obj, TypeSignature<ValueType> type)
-
converterFromTypeToType
public static Function<Object,Object> converterFromTypeToType(TypeSignature<ValueType> fromType, TypeSignature<ValueType> toType)
Used by TopN engine for type coercion
-
convertObjectToDouble
@Nullable public static Double convertObjectToDouble(@Nullable Object valObj)
-
convertObjectToDouble
@Nullable public static Double convertObjectToDouble(@Nullable Object valObj, boolean reportParseExceptions)
-
getExactLongFromDecimalString
@Nullable public static Long getExactLongFromDecimalString(String decimalStr)
Convert a string representing a decimal value to a long.If the decimal value is not an exact integral value (e.g. 42.0), or if the decimal value is too large to be contained within a long, this function returns null.
- Parameters:
decimalStr- string representing a decimal value- Returns:
- long equivalent of decimalStr, returns null for non-integral decimals and integral decimal values outside of the values representable by longs
-
-