diff --git a/cpp/core/benchmarks/CompressionBenchmark.cc b/cpp/core/benchmarks/CompressionBenchmark.cc index e1aa69ff39a7..cefd035710eb 100644 --- a/cpp/core/benchmarks/CompressionBenchmark.cc +++ b/cpp/core/benchmarks/CompressionBenchmark.cc @@ -109,7 +109,7 @@ class BenchmarkCompression { setCpu(state.range(2) + state.thread_index()); auto ipcWriteOptions = arrow::ipc::IpcWriteOptions::Defaults(); ipcWriteOptions.use_threads = false; - auto compressBufferSize = (uint32_t)state.range(1); + auto compressBufferSize = static_cast(state.range(1)); auto compressionType = state.range(0); switch (compressionType) { case gluten::kLZ4: { @@ -248,7 +248,7 @@ class BenchmarkCompression { GLUTEN_ASSIGN_OR_THROW( auto len, codec->Decompress(buffers[j]->size() - 8, buffers[j]->data() + 8, outputSize, out->mutable_data())); - (void)len; + static_cast(len); } } } diff --git a/cpp/core/memory/MemoryAllocator.cc b/cpp/core/memory/MemoryAllocator.cc index dd5fb8e1974b..f81bc2b1de29 100644 --- a/cpp/core/memory/MemoryAllocator.cc +++ b/cpp/core/memory/MemoryAllocator.cc @@ -161,7 +161,7 @@ bool StdMemoryAllocator::reallocateAligned(void* p, uint64_t alignment, int64_t return false; } if (newSize <= size) { - auto aligned = ROUND_TO_LINE(newSize, alignment); + auto aligned = ROUND_TO_LINE(static_cast(newSize), alignment); if (aligned <= size) { // shrink-to-fit return reallocate(p, size, aligned, out); diff --git a/cpp/core/shuffle/Spill.cc b/cpp/core/shuffle/Spill.cc index 8cc3a9d05ea7..9b60d4bc3e54 100644 --- a/cpp/core/shuffle/Spill.cc +++ b/cpp/core/shuffle/Spill.cc @@ -25,7 +25,7 @@ Spill::Spill(Spill::SpillType type) : type_(type) {} Spill::~Spill() { if (is_) { - (void)is_->Close(); + static_cast(is_->Close()); } } diff --git a/cpp/core/utils/qat/QatCodec.cc b/cpp/core/utils/qat/QatCodec.cc index 1a5fc8ea6db1..14c55600b5c2 100644 --- a/cpp/core/utils/qat/QatCodec.cc +++ b/cpp/core/utils/qat/QatCodec.cc @@ -38,8 +38,8 @@ class QatZipCodec : public arrow::util::Codec { explicit QatZipCodec(int compressionLevel) : compressionLevel_(compressionLevel) {} ~QatZipCodec() { - (void)qzTeardownSession(&qzSession_); - (void)qzClose(&qzSession_); + static_cast(qzTeardownSession(&qzSession_)); + static_cast(qzClose(&qzSession_)); } arrow::Result Decompress(int64_t inputLen, const uint8_t* input, int64_t outputLen, uint8_t* output) diff --git a/cpp/core/utils/qpl/QplCodec.cc b/cpp/core/utils/qpl/QplCodec.cc index 0bf2ec36e72b..f769ebe524b6 100644 --- a/cpp/core/utils/qpl/QplCodec.cc +++ b/cpp/core/utils/qpl/QplCodec.cc @@ -203,7 +203,7 @@ class QplGzipCodec final : public arrow::util::Codec { int64_t MaxCompressedLen(int64_t input_len, const uint8_t* ARROW_ARG_UNUSED(input)) override { ARROW_DCHECK_GE(input_len, 0); /// Aligned with ZLIB - return ((input_len) + ((input_len) >> 12) + ((input_len) >> 14) + ((input_len) >> 25) + 13); + return ((input_len) + ((input_len) >> 12) + ((input_len) >> 14) + ((input_len) >> 25) + static_cast(13)); } arrow::Result> MakeCompressor() override { diff --git a/cpp/velox/jni/JniFileSystem.cc b/cpp/velox/jni/JniFileSystem.cc index 7c2b198bbc61..05e12470322f 100644 --- a/cpp/velox/jni/JniFileSystem.cc +++ b/cpp/velox/jni/JniFileSystem.cc @@ -338,11 +338,11 @@ class JniFileSystem : public facebook::velox::filesystems::FileSystem { JNIEnv* env = nullptr; attachCurrentThreadAsDaemonOrThrow(vm, &env); std::vector out; - jobjectArray jarray = (jobjectArray)env->CallObjectMethod(obj_, jniFileSystemList, createJString(env, path)); + jobjectArray jarray = static_cast(env->CallObjectMethod(obj_, jniFileSystemList, createJString(env, path))); checkException(env); jsize length = env->GetArrayLength(jarray); for (jsize i = 0; i < length; ++i) { - jstring element = (jstring)env->GetObjectArrayElement(jarray, i); + jstring element = static_cast(env->GetObjectArrayElement(jarray, i)); std::string cElement = jStringToCString(env, element); out.push_back(cElement); } diff --git a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc index f9c910a6244a..91ff219a7e00 100644 --- a/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc +++ b/cpp/velox/operators/serializer/VeloxColumnarToRowConverter.cc @@ -80,7 +80,7 @@ void VeloxColumnarToRowConverter::convert(std::shared_ptr cb, int size_t offset = 0; for (auto i = 0; i < numRows_; ++i) { - auto rowSize = fast_->serialize(startRow + i, (char*)(bufferAddress_ + offset)); + auto rowSize = fast_->serialize(startRow + i, reinterpret_cast(bufferAddress_ + offset)); lengths_[i] = rowSize; if (i > 0) { offsets_[i] = offsets_[i - 1] + lengths_[i - 1]; diff --git a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc index 19a2bbafd2c2..da41fb6b58a5 100644 --- a/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc +++ b/cpp/velox/operators/serializer/VeloxRowToColumnarConverter.cc @@ -35,7 +35,8 @@ inline int64_t getFieldOffset(int64_t nullBitsetWidthInBytes, int32_t index) { inline bool isNull(uint8_t* buffer_address, int32_t index) { int64_t mask = 1L << (index & 0x3f); // mod 64 and shift int64_t wordOffset = (index >> 6) * 8; - int64_t value = *((int64_t*)(buffer_address + wordOffset)); + int64_t* valuePtr = buffer_address + wordOffset; + int64_t value = *static_cast(valuePtr); return (value & mask) != 0; } @@ -51,7 +52,8 @@ int32_t getTotalStringSize( continue; } - int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] + fieldOffset); + int64_t* offsetAndSizePtr = reinterpret_cast(memoryAddress + offsets[pos] + fieldOffset); + int64_t offsetAndSize = *(offsetAndSizePtr); int32_t length = static_cast(offsetAndSize); if (!StringView::isInline(length)) { size += length; @@ -98,11 +100,12 @@ VectorPtr createFlatVector( auto column = BaseVector::create>(type, numRows, pool); auto rawValues = column->mutableRawValues(); auto typeWidth = sizeof(int128_t); - auto shift = __builtin_ctz((uint32_t)typeWidth); + auto shift = __builtin_ctz(static_cast(typeWidth)); for (auto pos = 0; pos < numRows; pos++) { if (!isNull(memoryAddress + offsets[pos], columnIdx)) { uint8_t* destptr = rawValues + (pos << shift); - int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] + fieldOffset); + int64_t* offsetAndSizePtr = reinterpret_cast(memoryAddress + offsets[pos] + fieldOffset); + int64_t offsetAndSize = *offsetAndSizePtr; int32_t length = static_cast(offsetAndSize); int32_t wordoffset = static_cast(offsetAndSize >> 32); uint8_t bytesValue[length]; @@ -111,7 +114,7 @@ VectorPtr createFlatVector( for (int k = length - 1; k >= 0; k--) { bytesValue2[length - 1 - k] = bytesValue[k]; } - if (int8_t(bytesValue[0]) < 0) { + if (static_cast(bytesValue[0]) < 0) { memset(bytesValue2 + length, 255, 16 - length); } memcpy(destptr, bytesValue2, typeWidth); @@ -135,7 +138,8 @@ VectorPtr createFlatVector( auto rawValues = column->mutableRawValues(); for (auto pos = 0; pos < numRows; pos++) { if (!isNull(memoryAddress + offsets[pos], columnIdx)) { - bool value = *(bool*)(memoryAddress + offsets[pos] + fieldOffset); + bool* valuePtr = reinterpret_cast(memoryAddress + offsets[pos] + fieldOffset); + bool value = *valuePtr; bits::setBit(rawValues, pos, value); } else { column->setNull(pos, true); @@ -156,7 +160,8 @@ VectorPtr createFlatVector( auto column = BaseVector::create>(type, numRows, pool); for (auto pos = 0; pos < numRows; pos++) { if (!isNull(memoryAddress + offsets[pos], columnIdx)) { - int64_t value = *(int64_t*)(memoryAddress + offsets[pos] + fieldOffset); + int64_t* valuePtr = static_cast(memoryAddress + offsets[pos] + fieldOffset); + int64_t value = *(valuePtr); column->set(pos, Timestamp::fromMicros(value)); } else { column->setNull(pos, true); @@ -178,7 +183,8 @@ VectorPtr createFlatVectorStringView( char* rawBuffer = column->getRawStringBufferWithSpace(size, true); for (auto pos = 0; pos < numRows; pos++) { if (!isNull(memoryAddress + offsets[pos], columnIdx)) { - int64_t offsetAndSize = *(int64_t*)(memoryAddress + offsets[pos] + fieldOffset); + int64_t* offsetAndSizePtr = reinterpret_cast(memoryAddress + offsets[pos] + fieldOffset); + int64_t offsetAndSize = *offsetAndSizePtr; int32_t length = static_cast(offsetAndSize); int32_t wordoffset = static_cast(offsetAndSize >> 32); auto valueSrcPtr = memoryAddress + offsets[pos] + wordoffset; diff --git a/cpp/velox/shuffle/VeloxShuffleReader.cc b/cpp/velox/shuffle/VeloxShuffleReader.cc index 0407be736a70..123c4c4aa869 100644 --- a/cpp/velox/shuffle/VeloxShuffleReader.cc +++ b/cpp/velox/shuffle/VeloxShuffleReader.cc @@ -440,7 +440,7 @@ std::shared_ptr VeloxSortShuffleReaderDeserializer::deserializeTo auto buffer = cur->second; const auto* rawBuffer = buffer->as(); while (rowOffset_ < cur->first && readRows < batchSize_) { - auto rowSize = *(RowSizeType*)(rawBuffer + byteOffset_) - sizeof(RowSizeType); + auto rowSize = *(static_cast(rawBuffer + byteOffset_)) - sizeof(RowSizeType); byteOffset_ += sizeof(RowSizeType); data.push_back(std::string_view(rawBuffer + byteOffset_, rowSize)); byteOffset_ += rowSize; diff --git a/cpp/velox/shuffle/VeloxSortShuffleWriter.cc b/cpp/velox/shuffle/VeloxSortShuffleWriter.cc index 80d0349bc93d..79961b1bb513 100644 --- a/cpp/velox/shuffle/VeloxSortShuffleWriter.cc +++ b/cpp/velox/shuffle/VeloxSortShuffleWriter.cc @@ -34,11 +34,11 @@ constexpr uint32_t kPartitionIdEndByteIndex = 7; uint64_t toCompactRowId(uint32_t partitionId, uint32_t pageNumber, uint32_t offsetInPage) { // |63 partitionId(24) |39 inputIndex(13) |26 rowIndex(27) | - return (uint64_t)partitionId << 40 | (uint64_t)pageNumber << 27 | offsetInPage; + return static_cast(partitionId) << 40 | static_cast(pageNumber) << 27 | offsetInPage; } uint32_t extractPartitionId(uint64_t compactRowId) { - return (uint32_t)(compactRowId >> 40); + return static_cast(compactRowId >> 40); } std::pair extractPageNumberAndOffset(uint64_t compactRowId) { @@ -187,7 +187,7 @@ arrow::Status VeloxSortShuffleWriter::insert(const facebook::velox::RowVectorPtr auto rows = maxRowsToInsert(rowOffset, remainingRows); if (rows == 0) { auto minSizeRequired = fixedRowSize_ ? fixedRowSize_.value() : rowSize_[rowOffset]; - acquireNewBuffer((uint64_t)memLimit, minSizeRequired); + acquireNewBuffer(static_cast(memLimit), minSizeRequired); rows = maxRowsToInsert(rowOffset, remainingRows); ARROW_RETURN_IF( rows == 0, arrow::Status::Invalid("Failed to insert rows. Remaining rows: " + std::to_string(remainingRows))); @@ -294,7 +294,8 @@ arrow::Status VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_ while (index < end) { auto pageIndex = extractPageNumberAndOffset(arrayPtr_[index]); addr = pageAddresses_[pageIndex.first] + pageIndex.second; - size = *(RowSizeType*)addr; + RowSizeType* sizePtr = reinterpret_cast(addr); + size = *sizePtr; if (offset + size > options_.sortEvictBufferSize && offset > 0) { sortTime.stop(); RETURN_NOT_OK(evictPartitionInternal(partitionId, index - begin, rawBuffer_, offset)); @@ -302,7 +303,7 @@ arrow::Status VeloxSortShuffleWriter::evictPartition(uint32_t partitionId, size_ begin = index; offset = 0; } - if (size > options_.sortEvictBufferSize) { + if (size > static_cast(options_.sortEvictBufferSize)) { // Split large rows. sortTime.stop(); RowSizeType bytes = 0; @@ -355,7 +356,7 @@ facebook::velox::vector_size_t VeloxSortShuffleWriter::maxRowsToInsert( } auto remainingBytes = pages_.back()->size() - pageCursor_; if (fixedRowSize_) { - return std::min((facebook::velox::vector_size_t)(remainingBytes / (fixedRowSize_.value())), remainingRows); + return std::min(static_cast(remainingBytes / (fixedRowSize_.value())), remainingRows); } auto beginIter = rowSizePrefixSum_.begin() + 1 + offset; auto bytesWritten = rowSizePrefixSum_[offset]; diff --git a/cpp/velox/substrait/SubstraitParser.cc b/cpp/velox/substrait/SubstraitParser.cc index 006a20c232ea..978d7bde5d36 100644 --- a/cpp/velox/substrait/SubstraitParser.cc +++ b/cpp/velox/substrait/SubstraitParser.cc @@ -327,7 +327,7 @@ int16_t SubstraitParser::getLiteralValue(const ::substrait::Expression::Literal& template <> int32_t SubstraitParser::getLiteralValue(const ::substrait::Expression::Literal& literal) { if (literal.has_date()) { - return int32_t(literal.date()); + return static_cast(literal.date()); } return literal.i32(); } diff --git a/cpp/velox/tests/FunctionTest.cc b/cpp/velox/tests/FunctionTest.cc index c149b2db38fc..a6cdca8eb20a 100644 --- a/cpp/velox/tests/FunctionTest.cc +++ b/cpp/velox/tests/FunctionTest.cc @@ -153,11 +153,11 @@ TEST_F(FunctionTest, setVectorFromVariants) { // Floats are harder to compare because of low-precision. Just making sure // they don't throw. - EXPECT_NO_THROW(setVectorFromVariants(REAL(), {variant(float(0.99L)), variant(float(-1.99L))}, pool_.get())); + EXPECT_NO_THROW(setVectorFromVariants(REAL(), {variant(static_cast(0.99L)), variant(static_cast(-1.99L))}, pool_.get())); - resultVec = setVectorFromVariants(DOUBLE(), {variant(double(0.99L)), variant(double(-1.99L))}, pool_.get()); - ASSERT_EQ(double(0.99L), resultVec->asFlatVector()->valueAt(0)); - ASSERT_EQ(double(-1.99L), resultVec->asFlatVector()->valueAt(1)); + resultVec = setVectorFromVariants(DOUBLE(), {variant(static_cast(0.99L)), variant(static_cast(-1.99L))}, pool_.get()); + ASSERT_EQ(static_cast(0.99L), resultVec->asFlatVector()->valueAt(0)); + ASSERT_EQ(static_cast(-1.99L), resultVec->asFlatVector()->valueAt(1)); resultVec = setVectorFromVariants(VARCHAR(), {variant(""), variant("asdf")}, pool_.get()); ASSERT_EQ("", resultVec->asFlatVector()->valueAt(0).str()); diff --git a/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc b/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc index de338a3c4385..93f28a32ab44 100644 --- a/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc +++ b/cpp/velox/tests/VeloxSubstraitRoundTripTest.cc @@ -368,12 +368,12 @@ TEST_F(VeloxSubstraitRoundTripTest, notNullLiteral) { .addNode([&](std::string id, core::PlanNodePtr input) { std::vector projectNames = {"a", "b", "c", "d", "e", "f", "g", "h"}; std::vector projectExpressions = { - makeConstantExpr(BOOLEAN(), static_cast(1)), - makeConstantExpr(TINYINT(), static_cast(23)), - makeConstantExpr(SMALLINT(), static_cast(45)), - makeConstantExpr(INTEGER(), static_cast(678)), - makeConstantExpr(BIGINT(), static_cast(910)), - makeConstantExpr(REAL(), static_cast(1.23)), + makeConstantExpr(BOOLEAN(), 1), + makeConstantExpr(TINYINT(), 23), + makeConstantExpr(SMALLINT(), 45), + makeConstantExpr(INTEGER(), 678), + makeConstantExpr(BIGINT(), 910), + makeConstantExpr(REAL(), 1.23), makeConstantExpr(DOUBLE(), static_cast(4.56)), makeConstantExpr(VARCHAR(), "789")}; return std::make_shared(