static ToType applyGeneric()

in cpp-ch/local-engine/Functions/SparkFunctionHashingExtended.h [92:177]


    static ToType applyGeneric(const Field & field, UInt64 seed, const DataTypePtr & type)
    {
        /// Do nothing when field is null
        if (field.isNull())
            return seed;

        DataTypePtr non_nullable_type = removeNullable(type);
        WhichDataType which(non_nullable_type);
        if (which.isNothing())
            return seed;
        else if (which.isUInt8())
            return applyNumber<UInt8>(field.get<UInt8>(), seed);
        else if (which.isUInt16())
            return applyNumber<UInt16>(field.get<UInt16>(), seed);
        else if (which.isUInt32())
            return applyNumber<UInt32>(field.get<UInt32>(), seed);
        else if (which.isUInt64())
            return applyNumber<UInt64>(field.get<UInt64>(), seed);
        else if (which.isInt8())
            return applyNumber<Int8>(field.get<Int8>(), seed);
        else if (which.isInt16())
            return applyNumber<Int16>(field.get<Int16>(), seed);
        else if (which.isInt32())
            return applyNumber<Int32>(field.get<Int32>(), seed);
        else if (which.isInt64())
            return applyNumber<Int64>(field.get<Int64>(), seed);
        else if (which.isFloat32())
            return applyNumber<Float32>(field.get<Float32>(), seed);
        else if (which.isFloat64())
            return applyNumber<Float64>(field.get<Float64>(), seed);
        else if (which.isDate())
            return applyNumber<UInt16>(field.get<UInt16>(), seed);
        else if (which.isDate32())
            return applyNumber<Int32>(field.get<Int32>(), seed);
        else if (which.isDateTime())
            return applyNumber<UInt32>(field.get<UInt32>(), seed);
        else if (which.isDateTime64())
            return applyDecimal<DateTime64>(field.get<DateTime64>(), seed);
        else if (which.isDecimal32())
            return applyDecimal<Decimal32>(field.get<Decimal32>(), seed);
        else if (which.isDecimal64())
            return applyDecimal<Decimal64>(field.get<Decimal64>(), seed);
        else if (which.isDecimal128())
            return applyDecimal<Decimal128>(field.get<Decimal128>(), seed);
        else if (which.isStringOrFixedString())
        {
            const String & str = field.get<String>();
            return applyUnsafeBytes(str.data(), str.size(), seed);
        }
        else if (which.isTuple())
        {
            const auto * tuple_type = checkAndGetDataType<DataTypeTuple>(non_nullable_type.get());
            assert(tuple_type);

            const auto & elements = tuple_type->getElements();
            const Tuple & tuple = field.get<Tuple>();
            assert(tuple.size() == elements.size());

            for (size_t i = 0; i < elements.size(); ++i)
            {
                seed = applyGeneric(tuple[i], seed, elements[i]);
            }
            return seed;
        }
        else if (which.isArray())
        {
            const auto * array_type = checkAndGetDataType<DataTypeArray>(non_nullable_type.get());
            assert(array_type);

            const auto & nested_type = array_type->getNestedType();
            const Array & array = field.get<Array>();
            for (size_t i=0; i < array.size(); ++i)
            {
                seed = applyGeneric(array[i], seed, nested_type);
            }
            return seed;
        }
        else
        {
            /// Note: No need to implement for big int type in gluten
            /// Note: No need to implement for uuid/ipv4/ipv6/enum* type in gluten
            /// Note: No need to implement for decimal256 type in gluten
            /// Note: No need to implement for map type as long as spark.sql.legacy.allowHashOnMapType is false(default)
            throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Unsupported type {}", type->getName());
        }
    }