Package org.apache.druid.common.config
Class NullHandling
- java.lang.Object
-
- org.apache.druid.common.config.NullHandling
-
public class NullHandling extends Object
Helper class for NullHandling. This class is used to switch between SQL compatible Null Handling behavior introduced as part of https://github.com/apache/druid/issues/4349 and the old druid behavior where null values are replaced with default values e.g Null Strings are replaced with empty values.
-
-
Field Summary
Fields Modifier and Type Field Description static byte
IS_NOT_NULL_BYTE
static byte
IS_NULL_BYTE
static Double
ZERO_DOUBLE
use these values to ensure thatdefaultDoubleValue()
,defaultFloatValue()
,defaultFloatValue()
return the same boxed object when returning a constant zerostatic Float
ZERO_FLOAT
static Long
ZERO_LONG
-
Constructor Summary
Constructors Constructor Description NullHandling()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Double
defaultDoubleValue()
static Float
defaultFloatValue()
static Long
defaultLongValue()
static String
defaultStringValue()
static <T> T
defaultValueForClass(Class<T> clazz)
Returns the default value for an object of the provided class.static Object
defaultValueForType(ValueType type)
Returns the default value for the givenValueType
.static String
emptyToNullIfNeeded(String value)
static boolean
ignoreNullsForStringCardinality()
whether nulls should be counted during String cardinalitystatic void
initializeForTests()
Many unit tests do not setup modules for this value to be injected, this method provides a manual way to initializeINSTANCE
static void
initializeForTestsWithValues(Boolean useDefForNull, Boolean ignoreNullForString)
static void
initializeForTestsWithValues(Boolean useDefForNull, Boolean useThreeValueLogic, Boolean ignoreNullForString)
static boolean
isNullOrEquivalent(String value)
static boolean
isNullOrEquivalent(ByteBuffer buffer)
static boolean
mustCombineNullAndEmptyInDictionary(Indexed<ByteBuffer> dictionaryUtf8)
Given a UTF-8 dictionary, returns whether the first two entries must be coalesced into a single null entry.static boolean
mustReplaceFirstValueWithNullInDictionary(Indexed<ByteBuffer> dictionaryUtf8)
Given a UTF-8 dictionary, returns whether the first entry must be replaced with null.static String
nullToEmptyIfNeeded(String value)
static boolean
replaceWithDefault()
whether nulls should be replaced with default value.static boolean
sqlCompatible()
static boolean
useThreeValueLogic()
-
-
-
Field Detail
-
ZERO_DOUBLE
public static final Double ZERO_DOUBLE
use these values to ensure thatdefaultDoubleValue()
,defaultFloatValue()
,defaultFloatValue()
return the same boxed object when returning a constant zero
-
ZERO_FLOAT
public static final Float ZERO_FLOAT
-
ZERO_LONG
public static final Long ZERO_LONG
-
IS_NULL_BYTE
public static final byte IS_NULL_BYTE
- See Also:
- Constant Field Values
-
IS_NOT_NULL_BYTE
public static final byte IS_NOT_NULL_BYTE
- See Also:
- Constant Field Values
-
-
Method Detail
-
initializeForTests
public static void initializeForTests()
Many unit tests do not setup modules for this value to be injected, this method provides a manual way to initializeINSTANCE
-
initializeForTestsWithValues
public static void initializeForTestsWithValues(Boolean useDefForNull, Boolean ignoreNullForString)
-
initializeForTestsWithValues
public static void initializeForTestsWithValues(Boolean useDefForNull, Boolean useThreeValueLogic, Boolean ignoreNullForString)
-
replaceWithDefault
public static boolean replaceWithDefault()
whether nulls should be replaced with default value.
-
ignoreNullsForStringCardinality
public static boolean ignoreNullsForStringCardinality()
whether nulls should be counted during String cardinality
-
sqlCompatible
public static boolean sqlCompatible()
-
useThreeValueLogic
public static boolean useThreeValueLogic()
-
defaultValueForClass
@Nullable public static <T> T defaultValueForClass(Class<T> clazz)
Returns the default value for an object of the provided class. Will be null in SQL-compatible null handling mode. May be null or some non-null default value when not in SQL-compatible null handling mode.
-
defaultValueForType
@Nullable public static Object defaultValueForType(ValueType type)
Returns the default value for the givenValueType
. May be null or non-null based on the current SQL-compatible null handling mode.
-
isNullOrEquivalent
public static boolean isNullOrEquivalent(@Nullable ByteBuffer buffer)
-
mustCombineNullAndEmptyInDictionary
public static boolean mustCombineNullAndEmptyInDictionary(Indexed<ByteBuffer> dictionaryUtf8)
Given a UTF-8 dictionary, returns whether the first two entries must be coalesced into a single null entry. This happens if we are in default-value mode and the first two entries are null and empty string. This andmustReplaceFirstValueWithNullInDictionary(Indexed)
are never both true. Provided to enable compatibility for segments written undersqlCompatible()
mode but read underreplaceWithDefault()
mode.
-
mustReplaceFirstValueWithNullInDictionary
public static boolean mustReplaceFirstValueWithNullInDictionary(Indexed<ByteBuffer> dictionaryUtf8)
Given a UTF-8 dictionary, returns whether the first entry must be replaced with null. This happens if we are in default-value mode and the first entry is an empty string. (Default-value mode expects it to be null.) This andmustCombineNullAndEmptyInDictionary(Indexed)
are never both true. Provided to enable compatibility for segments written undersqlCompatible()
mode but read underreplaceWithDefault()
mode.
-
-