Fix 8/9 of trash

This commit is contained in:
Alexey Milovidov 2022-09-11 05:38:59 +02:00
parent 42b0d444da
commit 730655d4fd
33 changed files with 88 additions and 77 deletions

View File

@ -161,7 +161,7 @@ private:
Y max_y = data.max_y;
Float64 diff_y = max_y - min_y;
if (diff_y)
if (diff_y != 0.0)
{
for (size_t i = 0; i <= diff_x; ++i)
{
@ -194,7 +194,7 @@ private:
auto upper_bound = [&](size_t bucket_num)
{
bound.second = (bucket_num + 1) * multiple_d;
bound.first = std::floor(bound.second);
bound.first = static_cast<size_t>(std::floor(bound.second));
};
upper_bound(cur_bucket_num);
for (size_t i = 0; i <= (diff_x + 1); ++i)
@ -249,7 +249,7 @@ private:
value += getBar(point_y ? 1 : 0);
};
if (diff_y)
if (diff_y != 0.0)
std::for_each(new_points.begin(), new_points.end(), get_bars);
else
std::for_each(new_points.begin(), new_points.end(), get_bars_for_constant);

View File

@ -225,7 +225,7 @@ public:
ResultType var_value = data.getPopulation();
if (var_value > 0)
dst.push_back(data.getMoment3() / pow(var_value, 1.5));
dst.push_back(static_cast<ResultType>(data.getMoment3() / pow(var_value, 1.5)));
else
dst.push_back(std::numeric_limits<ResultType>::quiet_NaN());
}
@ -234,7 +234,7 @@ public:
ResultType var_value = data.getSample();
if (var_value > 0)
dst.push_back(data.getMoment3() / pow(var_value, 1.5));
dst.push_back(static_cast<ResultType>(data.getMoment3() / pow(var_value, 1.5)));
else
dst.push_back(std::numeric_limits<ResultType>::quiet_NaN());
}
@ -243,7 +243,7 @@ public:
ResultType var_value = data.getPopulation();
if (var_value > 0)
dst.push_back(data.getMoment4() / pow(var_value, 2));
dst.push_back(static_cast<ResultType>(data.getMoment4() / pow(var_value, 2)));
else
dst.push_back(std::numeric_limits<ResultType>::quiet_NaN());
}
@ -252,7 +252,7 @@ public:
ResultType var_value = data.getSample();
if (var_value > 0)
dst.push_back(data.getMoment4() / pow(var_value, 2));
dst.push_back(static_cast<ResultType>(data.getMoment4() / pow(var_value, 2)));
else
dst.push_back(std::numeric_limits<ResultType>::quiet_NaN());
}

View File

@ -216,7 +216,7 @@ public:
for (size_t i = 0; i < keys_vec_size; ++i)
{
auto value = value_column[values_vec_offset + i];
auto key = key_column[keys_vec_offset + i].get<T>();
T key = static_cast<T>(key_column[keys_vec_offset + i].get<T>());
if (!keepKey(key))
continue;

View File

@ -55,7 +55,7 @@ struct QuantileReservoirSampler
/// Get the value of the `level` quantile. The level must be between 0 and 1.
Value get(Float64 level)
{
return Value(data.quantileInterpolated(level));
return static_cast<Value>(data.quantileInterpolated(level));
}
/// Get the `size` values of `levels` quantiles. Write `size` results starting with `result` address.

View File

@ -184,14 +184,17 @@ public:
/// When frequency is too low, replace just one random element with the corresponding probability.
if (frequency * 2 >= sample_count)
{
UInt64 rnd = genRandom(frequency);
UInt64 rnd = genRandom(static_cast<UInt64>(frequency));
if (rnd < sample_count)
samples[rnd] = b.samples[rnd];
}
else
{
for (double i = 0; i < sample_count; i += frequency) /// NOLINT
samples[i] = b.samples[i];
{
size_t idx = static_cast<size_t>(i);
samples[idx] = b.samples[idx];
}
}
}
}
@ -237,14 +240,15 @@ private:
bool sorted = false;
UInt64 genRandom(size_t lim)
UInt64 genRandom(UInt64 limit)
{
assert(lim > 0);
/// With a large number of values, we will generate random numbers several times slower.
if (lim <= static_cast<UInt64>(rng.max()))
return static_cast<UInt32>(rng()) % static_cast<UInt32>(lim);
if (limit <= static_cast<UInt64>(rng.max()))
return static_cast<UInt32>(rng()) % static_cast<UInt32>(limit);
else
return (static_cast<UInt64>(rng()) * (static_cast<UInt64>(rng.max()) + 1ULL) + static_cast<UInt64>(rng())) % lim;
return (static_cast<UInt64>(rng()) * (static_cast<UInt64>(rng.max()) + 1ULL) + static_cast<UInt64>(rng())) % limit;
}
void sortIfNeeded()

View File

@ -358,7 +358,7 @@ public:
* filled buckets with average of res is obtained.
*/
size_t p32 = 1ULL << 32;
size_t fixed_res = round(p32 * (log(p32) - log(p32 - res)));
size_t fixed_res = static_cast<size_t>(round(p32 * (log(p32) - log(p32 - res))));
return fixed_res;
}

View File

@ -444,7 +444,14 @@ struct IntHash32
}
else if constexpr (sizeof(T) <= sizeof(UInt64))
{
return intHash32<salt>(key);
union
{
T in;
DB::UInt64 out;
} u;
u.out = 0;
u.in = key;
return intHash32<salt>(u.out);
}
assert(false);

View File

@ -162,7 +162,7 @@ class __attribute__((__packed__)) Denominator<precision, max_rank, HashValueType
public:
Denominator(DenominatorType initial_value) /// NOLINT
{
rank_count[0] = initial_value;
rank_count[0] = static_cast<UInt32>(initial_value);
}
inline void update(UInt8 cur_rank, UInt8 new_rank)
@ -189,7 +189,7 @@ public:
val /= 2.0;
val += rank_count[i];
}
return val;
return static_cast<DenominatorType>(val);
}
private:

View File

@ -1019,7 +1019,7 @@ INSTANTIATE_TEST_SUITE_P(MonotonicFloat,
Codec("Gorilla")
),
::testing::Values(
generateSeq<Float32>(G(MonotonicGenerator<Float32>(M_E, 5))),
generateSeq<Float32>(G(MonotonicGenerator<Float32>(static_cast<Float32>(M_E), 5))),
generateSeq<Float64>(G(MonotonicGenerator<Float64>(M_E, 5)))
)
)
@ -1032,7 +1032,7 @@ INSTANTIATE_TEST_SUITE_P(MonotonicReverseFloat,
Codec("Gorilla")
),
::testing::Values(
generateSeq<Float32>(G(MonotonicGenerator<Float32>(-1 * M_E, 5))),
generateSeq<Float32>(G(MonotonicGenerator<Float32>(static_cast<Float32>(-1 * M_E), 5))),
generateSeq<Float64>(G(MonotonicGenerator<Float64>(-1 * M_E, 5)))
)
)

View File

@ -276,7 +276,7 @@ private:
attribute,
fetched_columns_index,
fetched_keys,
[&](auto value) { data.push_back(value); },
[&](auto value) { data.push_back(static_cast<AttributeType>(value)); },
default_value_provider);
}
};
@ -338,7 +338,7 @@ private:
}
else
{
container.back() = column_value.get<NearestFieldType<ElementType>>();
container.back() = static_cast<ElementType>(column_value.get<ElementType>());
}
});
}
@ -391,7 +391,7 @@ private:
}
else
{
container[index_to_use] = column_value.get<NearestFieldType<ElementType>>();
container[index_to_use] = static_cast<ElementType>(column_value.get<ElementType>());
}
});
}

View File

@ -317,7 +317,7 @@ public:
if (attribute_default_value.isNull())
default_value_is_null = true;
else
default_value = attribute_default_value.get<NearestFieldType<DictionaryAttributeType>>();
default_value = static_cast<DictionaryAttributeType>(attribute_default_value.get<DictionaryAttributeType>());
}
else
{
@ -689,5 +689,3 @@ static ColumnPtr getColumnFromPODArray(const PaddedPODArray<T> & array, size_t s
}
}

View File

@ -513,7 +513,7 @@ void HashedArrayDictionary<dictionary_key_type>::blockToAttributes(const Block &
}
else
{
auto value_to_insert = column_value_to_insert.get<NearestFieldType<AttributeValueType>>();
auto value_to_insert = static_cast<AttributeValueType>(column_value_to_insert.get<AttributeValueType>());
attribute_container.back() = value_to_insert;
}
};

View File

@ -549,7 +549,7 @@ void HashedDictionary<dictionary_key_type, sparse>::blockToAttributes(const Bloc
}
else
{
auto value_to_insert = column_value_to_insert.get<NearestFieldType<AttributeValueType>>();
auto value_to_insert = static_cast<AttributeValueType>(column_value_to_insert.get<AttributeValueType>());
container.insert({key, value_to_insert});
}

View File

@ -133,7 +133,7 @@ ColumnPtr IPolygonDictionary::getColumn(
getItemsImpl<ValueType>(
requested_key_points,
[&](size_t row) { return attribute_data[row]; },
[&](auto value) { result_data.emplace_back(value); },
[&](auto value) { static_cast<Type>(result_data.emplace_back(value)); },
default_value_provider);
}
};

View File

@ -203,7 +203,7 @@ public:
static constexpr size_t kMultiProcessingDepth = 2;
/** A constant used to avoid errors with points falling on the boundaries of cells. */
static constexpr Coord kEps = 1e-4;
static constexpr Coord kEps = 1e-4f;
private:
std::unique_ptr<ICell<ReturnCell>> root = nullptr;

View File

@ -32,7 +32,7 @@ struct Base58Encode
/// Base58 has efficiency of 73% (8/11) [https://monerodocs.org/cryptography/base58/],
/// and we take double scale to avoid any reallocation.
size_t max_result_size = ceil(2 * src_column.getChars().size() + 1);
size_t max_result_size = static_cast<size_t>(ceil(2 * src_column.getChars().size() + 1));
dst_data.resize(max_result_size);
dst_offsets.resize(input_rows_count);

View File

@ -14,7 +14,7 @@ class FunctionConstantBase : public IFunction
public:
template <typename U>
explicit FunctionConstantBase(U && constant_value_, bool is_distributed_ = false)
: constant_value(std::forward<U>(constant_value_)), is_distributed(is_distributed_)
: constant_value(static_cast<T>(std::forward<U>(constant_value_))), is_distributed(is_distributed_)
{
}
@ -52,4 +52,3 @@ private:
};
}

View File

@ -718,10 +718,10 @@ public:
}
else
{
static_assert("Failed to resolve return type.");
static_assert(sizeof(FromDataType) == 0, "Failed to resolve return type.");
}
//to make PVS and GCC happy.
// To make PVS-Studio and GCC happy.
return nullptr;
}

View File

@ -683,7 +683,7 @@ public:
/// We permit inaccurate conversion of double to float.
/// Example: double 0.1 from JSON is not representable in float.
/// But it will be more convenient for user to perform conversion.
value = element.getDouble();
value = static_cast<NumberType>(element.getDouble());
}
else if (!accurate::convertNumeric(element.getDouble(), value))
return false;

View File

@ -745,7 +745,7 @@ private:
using ValueType = typename Container::value_type;
std::vector<ValueType> boundary_values(boundaries.size());
for (size_t i = 0; i < boundaries.size(); ++i)
boundary_values[i] = boundaries[i].get<ValueType>();
boundary_values[i] = static_cast<ValueType>(boundaries[i].get<ValueType>());
::sort(boundary_values.begin(), boundary_values.end());
boundary_values.erase(std::unique(boundary_values.begin(), boundary_values.end()), boundary_values.end());

View File

@ -52,9 +52,9 @@ struct FunctionDetectTonalityImpl
/// Calculate average value of tonality.
/// Convert values -12..6 to -1..1
if (weight > 0)
return weight / count_words / 6;
return static_cast<Float32>(weight / count_words / 6);
else
return weight / count_words / 12;
return static_cast<Float32>(weight / count_words / 12);
}
static void vector(

View File

@ -380,7 +380,8 @@ private:
for (; prev + VEC_SIZE < off; prev += VEC_SIZE)
{
for (size_t s = 0; s < VEC_SIZE; ++s)
Kernel::template accumulate<ResultType>(states[s], data_x[prev+s], data_y[prev+s], kernel_params);
Kernel::template accumulate<ResultType>(
states[s], static_cast<ResultType>(data_x[prev + s]), static_cast<ResultType>(data_y[prev + s]), kernel_params);
}
typename Kernel::template State<ResultType> state;
@ -390,7 +391,8 @@ private:
/// Process the tail
for (; prev < off; ++prev)
{
Kernel::template accumulate<ResultType>(state, data_x[prev], data_y[prev], kernel_params);
Kernel::template accumulate<ResultType>(
state, static_cast<ResultType>(data_x[prev]), static_cast<ResultType>(data_y[prev]), kernel_params);
}
result_data[row] = Kernel::finalize(state, kernel_params);
row++;
@ -447,7 +449,8 @@ private:
for (; prev + VEC_SIZE < off; i += VEC_SIZE, prev += VEC_SIZE)
{
for (size_t s = 0; s < VEC_SIZE; ++s)
Kernel::template accumulate<ResultType>(states[s], data_x[i+s], data_y[prev+s], kernel_params);
Kernel::template accumulate<ResultType>(
states[s], static_cast<ResultType>(data_x[i + s]), static_cast<ResultType>(data_y[prev + s]), kernel_params);
}
typename Kernel::template State<ResultType> state;
@ -457,7 +460,8 @@ private:
/// Process the tail
for (; prev < off; ++i, ++prev)
{
Kernel::template accumulate<ResultType>(state, data_x[i], data_y[prev], kernel_params);
Kernel::template accumulate<ResultType>(
state, static_cast<ResultType>(data_x[i]), static_cast<ResultType>(data_y[prev]), kernel_params);
}
result_data[row] = Kernel::finalize(state, kernel_params);
row++;

View File

@ -188,7 +188,7 @@ public:
return;
}
UInt64 num_units = value / unit_size;
UInt64 num_units = static_cast<UInt64>(value / unit_size);
if (!num_units)
{

View File

@ -44,17 +44,19 @@ namespace
{
constexpr double PI = 3.14159265358979323846;
constexpr float PI_F = 3.14159265358979323846f;
constexpr float RAD_IN_DEG = static_cast<float>(PI / 180.0);
constexpr float RAD_IN_DEG_HALF = static_cast<float>(PI / 360.0);
constexpr size_t COS_LUT_SIZE = 1024; // maxerr 0.00063%
constexpr float COS_LUT_SIZE_F = 1024.0f; // maxerr 0.00063%
constexpr size_t ASIN_SQRT_LUT_SIZE = 512;
constexpr size_t METRIC_LUT_SIZE = 1024;
/** Earth radius in meters using WGS84 authalic radius.
* We use this value to be consistent with H3 library.
*/
constexpr float EARTH_RADIUS = 6371007.180918475;
constexpr float EARTH_RADIUS = 6371007.180918475f;
constexpr float EARTH_DIAMETER = 2 * EARTH_RADIUS;
@ -98,7 +100,7 @@ void geodistInit()
sphere_metric_meters_lut[i] = static_cast<float>(sqr((EARTH_DIAMETER * PI / 360) * cos(latitude)));
sphere_metric_lut[i] = sqrf(cosf(latitude));
sphere_metric_lut[i] = static_cast<float>(sqr(cos(latitude)));
}
}
@ -118,7 +120,7 @@ inline float geodistDegDiff(float f)
inline float geodistFastCos(float x)
{
float y = fabsf(x) * (COS_LUT_SIZE / PI / 2);
float y = fabsf(x) * (COS_LUT_SIZE_F / PI_F / 2.0f);
size_t i = floatToIndex(y);
y -= i;
i &= (COS_LUT_SIZE - 1);
@ -127,7 +129,7 @@ inline float geodistFastCos(float x)
inline float geodistFastSin(float x)
{
float y = fabsf(x) * (COS_LUT_SIZE / PI / 2);
float y = fabsf(x) * (COS_LUT_SIZE_F / PI_F / 2.0f);
size_t i = floatToIndex(y);
y -= i;
i = (i - COS_LUT_SIZE / 4) & (COS_LUT_SIZE - 1); // cos(x - pi / 2) = sin(x), costable / 4 = pi / 2
@ -202,7 +204,7 @@ float distance(float lon1deg, float lat1deg, float lon2deg, float lat2deg)
}
else if constexpr (method == Method::SPHERE_METERS)
{
k_lat = sqr(EARTH_DIAMETER * PI / 360);
k_lat = sqrf(EARTH_DIAMETER * PI_F / 360.0f);
k_lon = sphere_metric_meters_lut[latitude_midpoint_index]
+ (sphere_metric_meters_lut[latitude_midpoint_index + 1] - sphere_metric_meters_lut[latitude_midpoint_index]) * (latitude_midpoint - latitude_midpoint_index);
@ -227,7 +229,7 @@ float distance(float lon1deg, float lat1deg, float lon2deg, float lat2deg)
+ geodistFastCos(lat1deg * RAD_IN_DEG) * geodistFastCos(lat2deg * RAD_IN_DEG) * sqrf(geodistFastSin(lon_diff * RAD_IN_DEG_HALF));
if constexpr (method == Method::SPHERE_DEGREES)
return (360.0f / PI) * geodistFastAsinSqrt(a);
return (360.0f / PI_F) * geodistFastAsinSqrt(a);
else
return EARTH_DIAMETER * geodistFastAsinSqrt(a);
}

View File

@ -26,7 +26,7 @@ struct IntExp2Impl
if constexpr (is_big_int_v<A>)
throw DB::Exception("intExp2 not implemented for big integers", ErrorCodes::NOT_IMPLEMENTED);
else
return intExp2(a);
return intExp2(static_cast<int>(a));
}
#if USE_EMBEDDED_COMPILER

View File

@ -100,7 +100,7 @@ public:
throw Exception("The maximum sleep time is 3 seconds. Requested: " + toString(seconds), ErrorCodes::TOO_SLOW);
UInt64 count = (variant == FunctionSleepVariant::PerBlock ? 1 : size);
UInt64 microseconds = seconds * count * 1e6;
UInt64 microseconds = static_cast<size_t>(seconds * count * 1e6);
sleepForMicroseconds(microseconds);
ProfileEvents::increment(ProfileEvents::SleepFunctionCalls, count);
ProfileEvents::increment(ProfileEvents::SleepFunctionMicroseconds, microseconds);

View File

@ -418,7 +418,7 @@ private:
if (!out)
return false;
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), cache.const_default_value.get<U>());
executeImplNumToNumWithConstDefault<T, U>(in->getData(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
return true;
}
@ -697,7 +697,8 @@ private:
if (!out)
return false;
executeImplStringToNumWithConstDefault<U>(in->getChars(), in->getOffsets(), out->getData(), cache.const_default_value.get<U>());
executeImplStringToNumWithConstDefault<U>(
in->getChars(), in->getOffsets(), out->getData(), static_cast<U>(cache.const_default_value.get<U>()));
return true;
}
@ -869,6 +870,8 @@ private:
const auto * it = table.find(bit_cast<UInt64>(src[i]));
if (it)
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i])); /// little endian.
else if constexpr (is_decimal<U>)
dst[i] = static_cast<typename U::NativeType>(dst_default[i]);
else
dst[i] = static_cast<U>(dst_default[i]);
}
@ -977,8 +980,10 @@ private:
const auto * it = table.find(ref);
if (it)
memcpy(&dst[i], &it->getMapped(), sizeof(dst[i]));
else if constexpr (is_decimal<U>)
dst[i] = static_cast<typename U::NativeType>(dst_default[i]);
else
dst[i] = dst_default[i]; // NOLINT
dst[i] = static_cast<U>(dst_default[i]);
}
}

View File

@ -29,10 +29,6 @@ auto getTypeName(const ValueType &)
{
return "DateTime64WithScale";
}
else
{
static_assert("unsupported ValueType");
}
}
std::ostream & dump_datetime(std::ostream & ostr, const DayNum & d)
@ -53,10 +49,10 @@ std::ostream & dump_datetime(std::ostream & ostr, const DateTime64WithScale & dt
template <typename ValueType>
struct DateTimeToStringParamTestCase
{
const char* description;
const char * description;
const ValueType input;
const char* expected;
const char* timezone = "UTC";
const char * expected;
const char * timezone = "UTC";
};
template <typename T>
@ -105,10 +101,6 @@ public:
{
writeDateTimeText(input.value, input.scale, out, DateLUT::instance(timezone_name));
}
else
{
static_assert("unsupported ValueType");
}
ASSERT_EQ(expected, out.str());
}

View File

@ -259,7 +259,7 @@ struct Grower : public HashTableGrower<>
static const size_t initial_size_degree = 16;
Grower() { size_degree = initial_size_degree; }
size_t max_fill = (1ULL << initial_size_degree) * 0.9;
size_t max_fill = (1ULL << initial_size_degree) * 9 / 10;
/// The size of the hash table in the cells.
size_t bufSize() const { return 1ULL << size_degree; }
@ -280,7 +280,7 @@ struct Grower : public HashTableGrower<>
void increaseSize()
{
size_degree += size_degree >= 23 ? 1 : 2;
max_fill = (1ULL << size_degree) * 0.9;
max_fill = (1ULL << size_degree) * 9 / 10;
}
/// Set the buffer size by the number of elements in the hash table. Used when deserializing a hash table.

View File

@ -137,13 +137,13 @@ static void insertNumber(IColumn & column, WhichDataType type, T value)
assert_cast<ColumnFloat64 &>(column).insertValue(static_cast<Float64>(value));
break;
case TypeIndex::Decimal32:
assert_cast<ColumnDecimal<Decimal32> &>(column).insertValue(static_cast<Decimal32>(value));
assert_cast<ColumnDecimal<Decimal32> &>(column).insertValue(static_cast<Int32>(value));
break;
case TypeIndex::Decimal64:
assert_cast<ColumnDecimal<Decimal64> &>(column).insertValue(static_cast<Decimal64>(value));
assert_cast<ColumnDecimal<Decimal64> &>(column).insertValue(static_cast<Int64>(value));
break;
case TypeIndex::DateTime64:
assert_cast<ColumnDecimal<DateTime64> &>(column).insertValue(static_cast<DateTime64>(value));
assert_cast<ColumnDecimal<DateTime64> &>(column).insertValue(static_cast<Int64>(value));
break;
default:
throw Exception("Type is not compatible with Avro", ErrorCodes::ILLEGAL_COLUMN);

View File

@ -253,8 +253,8 @@ void ORCBlockOutputFormat::writeDateTimes(
}
timestamp_orc_column.notNull[i] = 1;
timestamp_orc_column.data[i] = get_seconds(timestamp_column.getElement(i));
timestamp_orc_column.nanoseconds[i] = get_nanoseconds(timestamp_column.getElement(i));
timestamp_orc_column.data[i] = static_cast<int64_t>(get_seconds(timestamp_column.getElement(i)));
timestamp_orc_column.nanoseconds[i] = static_cast<int64_t>(get_nanoseconds(timestamp_column.getElement(i)));
}
timestamp_orc_column.numElements = timestamp_column.size();
}

View File

@ -163,7 +163,7 @@ void FinishAggregatingInOrderAlgorithm::addToAggregation()
states[i].current_row = states[i].to_row;
/// We assume that sizes in bytes of rows are almost the same.
accumulated_bytes += static_cast<size_t>(static_cast<double>(states[i].total_bytes) * current_rows / states[i].num_rows));
accumulated_bytes += static_cast<size_t>(static_cast<double>(states[i].total_bytes) * current_rows / states[i].num_rows);
accumulated_rows += current_rows;

View File

@ -115,9 +115,9 @@ int main(int, char **)
double time_to_merge = sum_merged_size / (1048576 * 10.0);
age_passed += time_to_merge;
age_passed = static_cast<size_t>(age_passed + time_to_merge);
for (auto & part : parts)
part.age += time_to_merge;
part.age = static_cast<size_t>(part.age + time_to_merge);
std::cout << "Time passed: " << age_passed << ", num parts: " << parts.size()
<< ", merged " << selected_parts.size() << " parts, " << formatReadableSizeWithBinarySuffix(sum_merged_size)