Class 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.
    • Constructor Detail

      • NullHandling

        public NullHandling()
    • 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 initialize INSTANCE
      • 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()
      • defaultLongValue

        @Nullable
        public static Long defaultLongValue()
      • defaultFloatValue

        @Nullable
        public static Float defaultFloatValue()
      • 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 given ValueType. May be null or non-null based on the current SQL-compatible null handling mode.
      • isNullOrEquivalent

        public static boolean isNullOrEquivalent​(@Nullable
                                                 String value)
      • 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 and mustReplaceFirstValueWithNullInDictionary(Indexed) are never both true. Provided to enable compatibility for segments written under sqlCompatible() mode but read under replaceWithDefault() 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 and mustCombineNullAndEmptyInDictionary(Indexed) are never both true. Provided to enable compatibility for segments written under sqlCompatible() mode but read under replaceWithDefault() mode.