MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / getColumnNativeValue

Function getColumnNativeValue

src/DataTypes/Native.cpp:369–454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367}
368
369llvm::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)

Callers 2

getNativeValueFunction · 0.85
compileMethod · 0.85

Calls 8

toNativeTypeFunction · 0.85
getNestedTypeMethod · 0.80
getFunction · 0.50
ExceptionClass · 0.50
isNullableMethod · 0.45
isNullAtMethod · 0.45
getElementMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected