Something

This commit is contained in:
Alexey Milovidov 2024-11-10 01:25:25 +01:00
parent 04a6107966
commit c3f42b7bc7
18 changed files with 132 additions and 17 deletions

View File

@ -3,8 +3,7 @@
set (DEFAULT_LIBS "-nodefaultlibs")
# We need builtins from Clang's RT even without libcxx - for ubsan+int128.
# See https://bugs.llvm.org/show_bug.cgi?id=16404
# We need builtins from Clang
execute_process (COMMAND
${CMAKE_CXX_COMPILER} --target=${CMAKE_CXX_COMPILER_TARGET} --print-libgcc-file-name --rtlib=compiler-rt
OUTPUT_VARIABLE BUILTINS_LIBRARY

View File

@ -276,6 +276,6 @@ private:
{
if (OnEmpty == ReservoirSamplerOnEmpty::THROW)
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Quantile of empty ReservoirSampler");
return NanLikeValueConstructor<ResultType, std::is_floating_point_v<ResultType>>::getValue();
return NanLikeValueConstructor<ResultType, is_floating_point<ResultType>>::getValue();
}
};

View File

@ -16,6 +16,7 @@ template class ColumnUnique<ColumnInt128>;
template class ColumnUnique<ColumnUInt128>;
template class ColumnUnique<ColumnInt256>;
template class ColumnUnique<ColumnUInt256>;
template class ColumnUnique<ColumnBFloat16>;
template class ColumnUnique<ColumnFloat32>;
template class ColumnUnique<ColumnFloat64>;
template class ColumnUnique<ColumnString>;

View File

@ -760,6 +760,7 @@ extern template class ColumnUnique<ColumnInt128>;
extern template class ColumnUnique<ColumnUInt128>;
extern template class ColumnUnique<ColumnInt256>;
extern template class ColumnUnique<ColumnUInt256>;
extern template class ColumnUnique<ColumnBFloat16>;
extern template class ColumnUnique<ColumnFloat32>;
extern template class ColumnUnique<ColumnFloat64>;
extern template class ColumnUnique<ColumnString>;

View File

@ -443,6 +443,7 @@ template class IColumnHelper<ColumnVector<Int32>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<Int64>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<Int128>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<Int256>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<BFloat16>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<Float32>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<Float64>, ColumnFixedSizeHelper>;
template class IColumnHelper<ColumnVector<UUID>, ColumnFixedSizeHelper>;

View File

@ -1,5 +1,4 @@
#include <Common/FieldVisitorConvertToNumber.h>
#include "base/Decimal.h"
namespace DB
{
@ -17,6 +16,7 @@ template class FieldVisitorConvertToNumber<Int128>;
template class FieldVisitorConvertToNumber<UInt128>;
template class FieldVisitorConvertToNumber<Int256>;
template class FieldVisitorConvertToNumber<UInt256>;
//template class FieldVisitorConvertToNumber<BFloat16>;
template class FieldVisitorConvertToNumber<Float32>;
template class FieldVisitorConvertToNumber<Float64>;

View File

@ -129,6 +129,7 @@ extern template class FieldVisitorConvertToNumber<Int128>;
extern template class FieldVisitorConvertToNumber<UInt128>;
extern template class FieldVisitorConvertToNumber<Int256>;
extern template class FieldVisitorConvertToNumber<UInt256>;
//extern template class FieldVisitorConvertToNumber<BFloat16>;
extern template class FieldVisitorConvertToNumber<Float32>;
extern template class FieldVisitorConvertToNumber<Float64>;

View File

@ -96,6 +96,7 @@ enum class BinaryTypeIndex : uint8_t
SimpleAggregateFunction = 0x2E,
Nested = 0x2F,
JSON = 0x30,
BFloat16 = 0x31,
};
/// In future we can introduce more arguments in the JSON data type definition.
@ -151,6 +152,8 @@ BinaryTypeIndex getBinaryTypeIndex(const DataTypePtr & type)
return BinaryTypeIndex::Int128;
case TypeIndex::Int256:
return BinaryTypeIndex::Int256;
case TypeIndex::BFloat16:
return BinaryTypeIndex::BFloat16;
case TypeIndex::Float32:
return BinaryTypeIndex::Float32;
case TypeIndex::Float64:
@ -565,6 +568,8 @@ DataTypePtr decodeDataType(ReadBuffer & buf)
return std::make_shared<DataTypeInt128>();
case BinaryTypeIndex::Int256:
return std::make_shared<DataTypeInt256>();
case BinaryTypeIndex::BFloat16:
return std::make_shared<DataTypeBFloat16>();
case BinaryTypeIndex::Float32:
return std::make_shared<DataTypeFloat32>();
case BinaryTypeIndex::Float64:

View File

@ -112,6 +112,7 @@ template class DataTypeNumber<Int8>;
template class DataTypeNumber<Int16>;
template class DataTypeNumber<Int32>;
template class DataTypeNumber<Int64>;
template class DataTypeNumber<BFloat16>;
template class DataTypeNumber<Float32>;
template class DataTypeNumber<Float64>;

View File

@ -63,6 +63,7 @@ extern template class DataTypeNumber<Int8>;
extern template class DataTypeNumber<Int16>;
extern template class DataTypeNumber<Int32>;
extern template class DataTypeNumber<Int64>;
extern template class DataTypeNumber<BFloat16>;
extern template class DataTypeNumber<Float32>;
extern template class DataTypeNumber<Float64>;

View File

@ -131,7 +131,7 @@ bool tryGetNumericValueFromJSONElement(
switch (element.type())
{
case ElementType::DOUBLE:
if constexpr (std::is_floating_point_v<NumberType>)
if constexpr (is_floating_point<NumberType>)
{
/// We permit inaccurate conversion of double to float.
/// Example: double 0.1 from JSON is not representable in float.
@ -175,7 +175,7 @@ bool tryGetNumericValueFromJSONElement(
return false;
auto rb = ReadBufferFromMemory{element.getString()};
if constexpr (std::is_floating_point_v<NumberType>)
if constexpr (is_floating_point<NumberType>)
{
if (!tryReadFloatText(value, rb) || !rb.eof())
{

View File

@ -110,6 +110,7 @@ template <typename DataType> constexpr bool IsIntegralOrExtendedOrDecimal =
IsDataTypeDecimal<DataType>;
template <typename DataType> constexpr bool IsFloatingPoint = false;
template <> inline constexpr bool IsFloatingPoint<DataTypeBFloat16> = true;
template <> inline constexpr bool IsFloatingPoint<DataTypeFloat32> = true;
template <> inline constexpr bool IsFloatingPoint<DataTypeFloat64> = true;

View File

@ -2930,6 +2930,7 @@ template <> struct FunctionTo<DataTypeInt32> { using Type = FunctionToInt32; };
template <> struct FunctionTo<DataTypeInt64> { using Type = FunctionToInt64; };
template <> struct FunctionTo<DataTypeInt128> { using Type = FunctionToInt128; };
template <> struct FunctionTo<DataTypeInt256> { using Type = FunctionToInt256; };
//template <> struct FunctionTo<DataTypeBFloat16> { using Type = FunctionToBFloat16; };
template <> struct FunctionTo<DataTypeFloat32> { using Type = FunctionToFloat32; };
template <> struct FunctionTo<DataTypeFloat64> { using Type = FunctionToFloat64; };

View File

@ -694,7 +694,7 @@ public:
if (arguments.size() > 1)
{
const ColumnWithTypeAndName & scale_column = arguments[1];
res = Dispatcher<DataType, rounding_mode, tie_breaking_mode>::template apply<ScaleType>(value_arg.column.get(), scale_column.column.get());
res = Dispatcher<DataType, rounding_mode, tie_breaking_mode>::template apply<int>(value_arg.column.get(), scale_column.column.get());
return true;
}
res = Dispatcher<DataType, rounding_mode, tie_breaking_mode>::template apply<int>(value_arg.column.get());

View File

@ -47,26 +47,35 @@ void assertNaN(ReadBuffer & buf)
}
template void readFloatTextPrecise<BFloat16>(BFloat16 &, ReadBuffer &);
template void readFloatTextPrecise<Float32>(Float32 &, ReadBuffer &);
template void readFloatTextPrecise<Float64>(Float64 &, ReadBuffer &);
template bool tryReadFloatTextPrecise<BFloat16>(BFloat16 &, ReadBuffer &);
template bool tryReadFloatTextPrecise<Float32>(Float32 &, ReadBuffer &);
template bool tryReadFloatTextPrecise<Float64>(Float64 &, ReadBuffer &);
template void readFloatTextFast<BFloat16>(BFloat16 &, ReadBuffer &);
template void readFloatTextFast<Float32>(Float32 &, ReadBuffer &);
template void readFloatTextFast<Float64>(Float64 &, ReadBuffer &);
template bool tryReadFloatTextFast<BFloat16>(BFloat16 &, ReadBuffer &);
template bool tryReadFloatTextFast<Float32>(Float32 &, ReadBuffer &);
template bool tryReadFloatTextFast<Float64>(Float64 &, ReadBuffer &);
template void readFloatTextSimple<BFloat16>(BFloat16 &, ReadBuffer &);
template void readFloatTextSimple<Float32>(Float32 &, ReadBuffer &);
template void readFloatTextSimple<Float64>(Float64 &, ReadBuffer &);
template bool tryReadFloatTextSimple<BFloat16>(BFloat16 &, ReadBuffer &);
template bool tryReadFloatTextSimple<Float32>(Float32 &, ReadBuffer &);
template bool tryReadFloatTextSimple<Float64>(Float64 &, ReadBuffer &);
template void readFloatText<BFloat16>(BFloat16 &, ReadBuffer &);
template void readFloatText<Float32>(Float32 &, ReadBuffer &);
template void readFloatText<Float64>(Float64 &, ReadBuffer &);
template bool tryReadFloatText<BFloat16>(BFloat16 &, ReadBuffer &);
template bool tryReadFloatText<Float32>(Float32 &, ReadBuffer &);
template bool tryReadFloatText<Float64>(Float64 &, ReadBuffer &);
template bool tryReadFloatTextNoExponent<BFloat16>(BFloat16 &, ReadBuffer &);
template bool tryReadFloatTextNoExponent<Float32>(Float32 &, ReadBuffer &);
template bool tryReadFloatTextNoExponent<Float64>(Float64 &, ReadBuffer &);

View File

@ -222,7 +222,6 @@ ReturnType readFloatTextPreciseImpl(T & x, ReadBuffer & buf)
break;
}
char tmp_buf[MAX_LENGTH];
int num_copied_chars = 0;
@ -597,22 +596,85 @@ ReturnType readFloatTextSimpleImpl(T & x, ReadBuffer & buf)
return ReturnType(true);
}
template <typename T> void readFloatTextPrecise(T & x, ReadBuffer & in) { readFloatTextPreciseImpl<T, void>(x, in); }
template <typename T> bool tryReadFloatTextPrecise(T & x, ReadBuffer & in) { return readFloatTextPreciseImpl<T, bool>(x, in); }
template <typename T> void readFloatTextPrecise(T & x, ReadBuffer & in)
{
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
readFloatTextPreciseImpl<Float32, void>(tmp, in);
x = BFloat16(tmp);
}
else
readFloatTextPreciseImpl<T, void>(x, in);
}
template <typename T> bool tryReadFloatTextPrecise(T & x, ReadBuffer & in)
{
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextPreciseImpl<Float32, bool>(tmp, in);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextPreciseImpl<T, bool>(x, in);
}
template <typename T> void readFloatTextFast(T & x, ReadBuffer & in)
{
bool has_fractional;
readFloatTextFastImpl<T, void>(x, in, has_fractional);
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
readFloatTextFastImpl<Float32, void>(tmp, in, has_fractional);
x = BFloat16(tmp);
}
else
readFloatTextFastImpl<T, void>(x, in, has_fractional);
}
template <typename T> bool tryReadFloatTextFast(T & x, ReadBuffer & in)
{
bool has_fractional;
return readFloatTextFastImpl<T, bool>(x, in, has_fractional);
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextFastImpl<Float32, bool>(tmp, in, has_fractional);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextFastImpl<T, bool>(x, in, has_fractional);
}
template <typename T> void readFloatTextSimple(T & x, ReadBuffer & in) { readFloatTextSimpleImpl<T, void>(x, in); }
template <typename T> bool tryReadFloatTextSimple(T & x, ReadBuffer & in) { return readFloatTextSimpleImpl<T, bool>(x, in); }
template <typename T> void readFloatTextSimple(T & x, ReadBuffer & in)
{
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
readFloatTextSimpleImpl<Float32, void>(tmp, in);
x = BFloat16(tmp);
}
else
readFloatTextSimpleImpl<T, void>(x, in);
}
template <typename T> bool tryReadFloatTextSimple(T & x, ReadBuffer & in)
{
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextSimpleImpl<Float32, bool>(tmp, in);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextSimpleImpl<T, bool>(x, in);
}
/// Implementation that is selected as default.
@ -624,18 +686,47 @@ template <typename T> bool tryReadFloatText(T & x, ReadBuffer & in) { return try
template <typename T> bool tryReadFloatTextNoExponent(T & x, ReadBuffer & in)
{
bool has_fractional;
return readFloatTextFastImpl<T, bool, false>(x, in, has_fractional);
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextFastImpl<Float32, bool, false>(tmp, in, has_fractional);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextFastImpl<T, bool, false>(x, in, has_fractional);
}
/// With a @has_fractional flag
/// Used for input_format_try_infer_integers
template <typename T> bool tryReadFloatTextExt(T & x, ReadBuffer & in, bool & has_fractional)
{
return readFloatTextFastImpl<T, bool>(x, in, has_fractional);
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextFastImpl<Float32, bool>(tmp, in, has_fractional);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextFastImpl<T, bool>(x, in, has_fractional);
}
template <typename T> bool tryReadFloatTextExtNoExponent(T & x, ReadBuffer & in, bool & has_fractional)
{
return readFloatTextFastImpl<T, bool, false>(x, in, has_fractional);
if constexpr (std::is_same_v<T, BFloat16>)
{
Float32 tmp;
bool res = readFloatTextFastImpl<Float32, bool, false>(tmp, in, has_fractional);
if (res)
x = BFloat16(tmp);
return res;
}
else
return readFloatTextFastImpl<T, bool, false>(x, in, has_fractional);
}
}

View File

@ -580,6 +580,7 @@ template class ParquetPlainValuesReader<ColumnInt32>;
template class ParquetPlainValuesReader<ColumnUInt32>;
template class ParquetPlainValuesReader<ColumnInt64>;
template class ParquetPlainValuesReader<ColumnUInt64>;
template class ParquetPlainValuesReader<ColumnBFloat16>;
template class ParquetPlainValuesReader<ColumnFloat32>;
template class ParquetPlainValuesReader<ColumnFloat64>;
template class ParquetPlainValuesReader<ColumnDecimal<Decimal32>>;
@ -602,6 +603,7 @@ template class ParquetRleDictReader<ColumnInt32>;
template class ParquetRleDictReader<ColumnUInt32>;
template class ParquetRleDictReader<ColumnInt64>;
template class ParquetRleDictReader<ColumnUInt64>;
template class ParquetRleDictReader<ColumnBFloat16>;
template class ParquetRleDictReader<ColumnFloat32>;
template class ParquetRleDictReader<ColumnFloat64>;
template class ParquetRleDictReader<ColumnDecimal<Decimal32>>;

View File

@ -644,6 +644,7 @@ template class ParquetLeafColReader<ColumnInt32>;
template class ParquetLeafColReader<ColumnUInt32>;
template class ParquetLeafColReader<ColumnInt64>;
template class ParquetLeafColReader<ColumnUInt64>;
template class ParquetLeafColReader<ColumnBFloat16>;
template class ParquetLeafColReader<ColumnFloat32>;
template class ParquetLeafColReader<ColumnFloat64>;
template class ParquetLeafColReader<ColumnString>;