diff --git a/velox/vector/VectorSaver.cpp b/velox/vector/VectorSaver.cpp index 5c8e5542d3f7..238325d6d286 100644 --- a/velox/vector/VectorSaver.cpp +++ b/velox/vector/VectorSaver.cpp @@ -36,7 +36,7 @@ enum class Encoding : int8_t { template void write(const T& value, std::ostream& out) { - out.write((char*)&value, sizeof(T)); + out.write(reinterpret_cast(&value), sizeof(T)); } template <> @@ -53,7 +53,7 @@ void write(const std::string& value, std::ostream& out) { template T read(std::istream& in) { T value; - in.read((char*)&value, sizeof(T)); + in.read(reinterpret_cast(&value), sizeof(T)); return value; } @@ -78,16 +78,16 @@ void writeEncoding(VectorEncoding::Simple encoding, std::ostream& out) { case VectorEncoding::Simple::ROW: case VectorEncoding::Simple::ARRAY: case VectorEncoding::Simple::MAP: - write((int8_t)Encoding::kFlat, out); + write(static_cast(Encoding::kFlat), out); return; case VectorEncoding::Simple::CONSTANT: - write((int8_t)Encoding::kConstant, out); + write(static_cast(Encoding::kConstant), out); return; case VectorEncoding::Simple::DICTIONARY: - write((int8_t)Encoding::kDictionary, out); + write(static_cast(Encoding::kDictionary), out); return; case VectorEncoding::Simple::LAZY: - write((int8_t)Encoding::kLazy, out); + write(static_cast(Encoding::kLazy), out); return; default: VELOX_UNSUPPORTED("Unsupported encoding: {}", mapSimpleToName(encoding)); @@ -275,7 +275,7 @@ void writeScalarConstant(const BaseVector& vector, std::ostream& out) { using T = typename TypeTraits::NativeType; auto value = vector.as>()->valueAt(0); - out.write((const char*)&value, sizeof(T)); + out.write(reinterpret_cast(&value), sizeof(T)); if constexpr (std::is_same_v) { if (!value.isInline()) { diff --git a/velox/vector/VectorStream.cpp b/velox/vector/VectorStream.cpp index f6de9e6a27b5..32d5886ca457 100644 --- a/velox/vector/VectorStream.cpp +++ b/velox/vector/VectorStream.cpp @@ -323,7 +323,9 @@ RowVectorPtr IOBufToRowVector( for (const auto& range : ioBuf) { ranges.emplace_back(ByteRange{ - const_cast(range.data()), (int32_t)range.size(), 0}); + const_cast(range.data()), + static_cast(range.size()), + 0}); } auto byteStream = std::make_unique(std::move(ranges)); diff --git a/velox/vector/arrow/Bridge.cpp b/velox/vector/arrow/Bridge.cpp index 8645f4bc6dde..fe98c14935da 100644 --- a/velox/vector/arrow/Bridge.cpp +++ b/velox/vector/arrow/Bridge.cpp @@ -72,7 +72,7 @@ class VeloxToArrowBridgeHolder { } const void** getArrowBuffers() { - return (const void**)&(buffers_[0]); + return reinterpret_cast(&(buffers_[0])); } // Allocates space for `numChildren` ArrowArray pointers. @@ -564,7 +564,8 @@ VectorPtr createStringFlatVectorFromUtf8View( "Expecting three or more buffers as input for string view types."); // The last C data buffer stores buffer sizes - auto* bufferSizes = (uint64_t*)arrowArray.buffers[num_buffers - 1]; + auto* bufferSizes = + reinterpret_cast(arrowArray.buffers[num_buffers - 1]); std::vector stringViewBuffers(num_buffers - 3); // Skipping buffer_id = 0 (nulls buffer) and buffer_id = 1 (values buffer) @@ -582,13 +583,15 @@ VectorPtr createStringFlatVectorFromUtf8View( // buffer-index, 4-byte buffer-offset] to 16-byte Velox StringView [4-byte // length, 4-byte prefix, 8-byte buffer-ptr] for (int32_t idx_64 = 0; idx_64 < arrowArray.length; ++idx_64) { - auto* view = (uint32_t*)(&((uint64_t*)arrowArray.buffers[1])[2 * idx_64]); - rawStringViews[2 * idx_64] = *(uint64_t*)view; + auto* view = reinterpret_cast(&( + reinterpret_cast(arrowArray.buffers[1]))[2 * idx_64]); + rawStringViews[2 * idx_64] = *reinterpret_cast(view); if (view[0] > 12) rawStringViews[2 * idx_64 + 1] = - (uint64_t)arrowArray.buffers[2 + view[2]] + view[3]; + reinterpret_cast(arrowArray.buffers[2 + view[2]]) + view[3]; else - rawStringViews[2 * idx_64 + 1] = *(uint64_t*)&view[2]; + rawStringViews[2 * idx_64 + 1] = + *reinterpret_cast(&view[2]); } return std::make_shared>( @@ -777,18 +780,19 @@ void exportViews( stringBufferVec.begin(), stringBufferVec.end(), [&out](const auto& lhs, const auto& rhs) { - return ((uint64_t*)&out.buffers[2])[lhs] < - ((uint64_t*)&out.buffers[2])[rhs]; + return reinterpret_cast(&out.buffers[2])[lhs] < + reinterpret_cast(&out.buffers[2])[rhs]; }); - auto utf8Views = (uint64_t*)out.buffers[1]; + auto utf8Views = reinterpret_cast(out.buffers[1]); int32_t bufferIdxCache = 0; uint64_t bufferAddrCache = 0; rows.apply([&](vector_size_t i) { - auto view = (uint32_t*)&utf8Views[2 * i]; + auto view = const_cast( + reinterpret_cast(&utf8Views[2 * i])); if (!vec.isNullAt(i) && view[0] > 12) { - uint64_t currAddr = *(uint64_t*)&view[2]; + const uint64_t currAddr = *reinterpret_cast(&view[2]); // 2. Search for correct index with the buffer-pointer as key. Cache the // found buffer's address and index in bufferAddrCache and bufferIdxCache // respectively @@ -800,9 +804,9 @@ void exportViews( stringBufferVec.end(), currAddr, [&out](const auto& lhs, const auto& rhs) { - return lhs < ((uint64_t*)&out.buffers[2])[rhs]; + return lhs < (reinterpret_cast(&out.buffers[2]))[rhs]; })); - bufferAddrCache = ((uint64_t*)&out.buffers[2])[*it]; + bufferAddrCache = (reinterpret_cast(&out.buffers[2]))[*it]; bufferIdxCache = *it; } view[2] = bufferIdxCache; diff --git a/velox/vector/fuzzer/examples/EncodingGeneratorExample.cpp b/velox/vector/fuzzer/examples/EncodingGeneratorExample.cpp index 30c99be339eb..22d07cfb91f1 100644 --- a/velox/vector/fuzzer/examples/EncodingGeneratorExample.cpp +++ b/velox/vector/fuzzer/examples/EncodingGeneratorExample.cpp @@ -67,7 +67,9 @@ int main() { } std::cout << "Probability of constant encoding = " - << (double)numConst / ((double)numConst + (double)numDict) << "\n"; + << static_cast(numConst) / + (static_cast(numConst) + static_cast(numDict)) + << "\n"; return 0; }