| 169 | |
| 170 | |
| 171 | Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const IDataType * from_type_hint) |
| 172 | { |
| 173 | if (from_type_hint && from_type_hint->equals(type)) |
| 174 | { |
| 175 | return src; |
| 176 | } |
| 177 | |
| 178 | WhichDataType which_type(type); |
| 179 | WhichDataType which_from_type; |
| 180 | |
| 181 | if (from_type_hint) |
| 182 | { |
| 183 | which_from_type = WhichDataType(*from_type_hint); |
| 184 | } |
| 185 | |
| 186 | /// Conversion between Date and DateTime and vice versa. |
| 187 | if (which_type.isDate() && which_from_type.isDateTime()) |
| 188 | { |
| 189 | return static_cast<UInt16>(static_cast<const DataTypeDateTime &>(*from_type_hint).getTimeZone().toDayNum(src.get<UInt64>()).toUnderType()); |
| 190 | } |
| 191 | else if (which_type.isDate32() && which_from_type.isDateTime()) |
| 192 | { |
| 193 | return static_cast<Int32>(static_cast<const DataTypeDateTime &>(*from_type_hint).getTimeZone().toDayNum(src.get<UInt64>()).toUnderType()); |
| 194 | } |
| 195 | else if (which_type.isDateTime() && which_from_type.isDate()) |
| 196 | { |
| 197 | return static_cast<const DataTypeDateTime &>(type).getTimeZone().fromDayNum(DayNum(src.get<UInt64>())); |
| 198 | } |
| 199 | else if (which_type.isDateTime() && which_from_type.isDate32()) |
| 200 | { |
| 201 | return static_cast<const DataTypeDateTime &>(type).getTimeZone().fromDayNum(DayNum(src.get<Int32>())); |
| 202 | } |
| 203 | else if (which_type.isDateTime64() && which_from_type.isDate()) |
| 204 | { |
| 205 | const auto & date_time64_type = static_cast<const DataTypeDateTime64 &>(type); |
| 206 | const auto value = date_time64_type.getTimeZone().fromDayNum(DayNum(src.get<UInt16>())); |
| 207 | return DecimalField( |
| 208 | DecimalUtils::decimalFromComponentsWithMultiplier<DateTime64>(value, 0, date_time64_type.getScaleMultiplier()), |
| 209 | date_time64_type.getScale()); |
| 210 | } |
| 211 | else if (which_type.isDateTime64() && which_from_type.isDate32()) |
| 212 | { |
| 213 | const auto & date_time64_type = static_cast<const DataTypeDateTime64 &>(type); |
| 214 | const auto value = date_time64_type.getTimeZone().fromDayNum(ExtendedDayNum(static_cast<Int32>(src.get<Int32>()))); |
| 215 | return DecimalField( |
| 216 | DecimalUtils::decimalFromComponentsWithMultiplier<DateTime64>(value, 0, date_time64_type.getScaleMultiplier()), |
| 217 | date_time64_type.getScale()); |
| 218 | } |
| 219 | else if (type.isValueRepresentedByNumber() && src.getType() != Field::Types::String) |
| 220 | { |
| 221 | if (which_type.isUInt8()) return convertNumericType<UInt8>(src, type); |
| 222 | if (which_type.isUInt16()) return convertNumericType<UInt16>(src, type); |
| 223 | if (which_type.isUInt32()) return convertNumericType<UInt32>(src, type); |
| 224 | if (which_type.isUInt64()) return convertNumericType<UInt64>(src, type); |
| 225 | if (which_type.isUInt128()) return convertNumericType<UInt128>(src, type); |
| 226 | if (which_type.isUInt256()) return convertNumericType<UInt256>(src, type); |
| 227 | if (which_type.isInt8()) return convertNumericType<Int8>(src, type); |
| 228 | if (which_type.isInt16()) return convertNumericType<Int16>(src, type); |
no test coverage detected