| 367 | } |
| 368 | |
| 369 | llvm::Constant * getColumnNativeValue(llvm::IRBuilderBase & builder, const DataTypePtr & column_type, const IColumn & column, size_t index) |
| 370 | { |
| 371 | if (const auto * constant = typeid_cast<const ColumnConst *>(&column)) |
| 372 | return getColumnNativeValue(builder, column_type, constant->getDataColumn(), 0); |
| 373 | |
| 374 | auto * type = toNativeType(builder, column_type); |
| 375 | WhichDataType column_data_type(column_type); |
| 376 | if (column_data_type.isNullable()) |
| 377 | { |
| 378 | const auto & nullable_data_type = assert_cast<const DataTypeNullable &>(*column_type); |
| 379 | const auto & nullable_column = assert_cast<const ColumnNullable &>(column); |
| 380 | |
| 381 | auto * value = getColumnNativeValue(builder, nullable_data_type.getNestedType(), nullable_column.getNestedColumn(), index); |
| 382 | auto * is_null = llvm::ConstantInt::get(type->getContainedType(1), nullable_column.isNullAt(index)); |
| 383 | |
| 384 | return llvm::ConstantStruct::get(static_cast<llvm::StructType *>(type), value, is_null); |
| 385 | } |
| 386 | |
| 387 | auto get_numeric_constant = [&type]<typename T>(const IColumn & column_, size_t index_) -> llvm::Constant * |
| 388 | { |
| 389 | const auto & column_vector_decimal = assert_cast<const ColumnVectorOrDecimal<T> &>(column_); |
| 390 | const auto & element = column_vector_decimal.getElement(index_); |
| 391 | |
| 392 | if constexpr (std::is_floating_point_v<T>) |
| 393 | { |
| 394 | return llvm::ConstantFP::get(type, static_cast<double>(element)); |
| 395 | } |
| 396 | else if constexpr (is_integer<T>) |
| 397 | { |
| 398 | if constexpr (std::is_integral_v<T>) |
| 399 | return llvm::ConstantInt::get(type, static_cast<uint64_t>(element), is_signed_v<T>); |
| 400 | else |
| 401 | { |
| 402 | llvm::APInt value(type->getIntegerBitWidth(), element.items); |
| 403 | return llvm::ConstantInt::get(type, value); |
| 404 | } |
| 405 | } |
| 406 | else if constexpr (is_decimal<T>) |
| 407 | { |
| 408 | if constexpr (!is_over_big_decimal<T>) |
| 409 | return llvm::ConstantInt::get(type, static_cast<uint64_t>(element.value), true); |
| 410 | else |
| 411 | { |
| 412 | llvm::APInt value(type->getIntegerBitWidth(), element.value.items); |
| 413 | return llvm::ConstantInt::get(type, value); |
| 414 | } |
| 415 | } |
| 416 | }; |
| 417 | |
| 418 | |
| 419 | #define GET_NUMERIC_CONSTANT(TYPE, DTYPE) \ |
| 420 | if (column_data_type.is##TYPE()) \ |
| 421 | { \ |
| 422 | return get_numeric_constant.operator()<DTYPE>(column, index); \ |
| 423 | } |
| 424 | |
| 425 | GET_NUMERIC_CONSTANT(Float32, Float32) |
| 426 | GET_NUMERIC_CONSTANT(Float64, Float64) |
no test coverage detected