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 ColumnCapabilities
DEFAULT_STRING_CAPABILITIES
static ConcurrentHashMap<String,DimensionHandlerProvider>
DIMENSION_HANDLER_PROVIDERS
static Double
ZERO_DOUBLE
static Float
ZERO_FLOAT
static Long
ZERO_LONG
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
compareObjectsAsType(Object lhs, Object rhs, ColumnType type)
static Function<Object,Comparable<?>>
converterFromTypeToType(TypeSignature<ValueType> fromType, TypeSignature<ValueType> toType)
static Double
convertObjectToDouble(Object valObj)
static Double
convertObjectToDouble(Object valObj, boolean reportParseExceptions)
static Float
convertObjectToFloat(Object valObj)
static Float
convertObjectToFloat(Object valObj, boolean reportParseExceptions)
static Long
convertObjectToLong(Object valObj)
static Long
convertObjectToLong(Object valObj, boolean reportParseExceptions)
static String
convertObjectToString(Object valObj)
static Comparable<?>
convertObjectToType(Object obj, TypeSignature<ValueType> type)
static Comparable<?>
convertObjectToType(Object obj, TypeSignature<ValueType> type, boolean reportParseExceptions)
static ComparableStringArray
convertToComparableStringArray(Object obj)
static ComparableList
convertToList(Object obj, 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 Long
getExactLongFromDecimalString(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 boolean
isNumericNull(Object o)
static Double
nullToZero(Double number)
static Float
nullToZero(Float number)
static Long
nullToZero(Long number)
static void
registerDimensionHandlerProvider(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 Comparable<?> convertObjectToType(@Nullable Object obj, TypeSignature<ValueType> type, boolean reportParseExceptions)
-
convertToList
@Nullable public static ComparableList convertToList(Object obj, ValueType elementType)
-
convertToComparableStringArray
@Nullable public static ComparableStringArray convertToComparableStringArray(Object obj)
-
compareObjectsAsType
public static int compareObjectsAsType(@Nullable Object lhs, @Nullable Object rhs, ColumnType type)
-
convertObjectToType
@Nullable public static Comparable<?> convertObjectToType(@Nullable Object obj, TypeSignature<ValueType> type)
-
converterFromTypeToType
public static Function<Object,Comparable<?>> converterFromTypeToType(TypeSignature<ValueType> fromType, TypeSignature<ValueType> toType)
-
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
-
-