Skip to content

Commit

Permalink
apacheGH-38090: [C++][Emscripten][Parquet] Suppress shorten-64-to-32 …
Browse files Browse the repository at this point in the history
…warnings (apache#38129)

### Rationale for this change

We need explicit cast to use `int64_t` for `size_t` on Emscripten.

### What changes are included in this PR?

Explicit casts.

### Are these changes tested?

Yes.

### Are there any user-facing changes?

No.
* Closes: apache#38090

Authored-by: Sutou Kouhei <[email protected]>
Signed-off-by: Sutou Kouhei <[email protected]>
  • Loading branch information
kou authored and loicalleyne committed Nov 13, 2023
1 parent 0951455 commit 8a73c09
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 17 deletions.
3 changes: 2 additions & 1 deletion cpp/src/parquet/arrow/reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,8 @@ Status FileReaderImpl::GetRecordBatchReader(const std::vector<int>& row_groups,
for (int row_group : row_groups) {
int64_t num_rows = parquet_reader()->metadata()->RowGroup(row_group)->num_rows();

batches.insert(batches.end(), num_rows / batch_size, max_sized_batch);
batches.insert(batches.end(), static_cast<size_t>(num_rows / batch_size),
max_sized_batch);

if (int64_t trailing_rows = num_rows % batch_size) {
batches.push_back(max_sized_batch->Slice(0, trailing_rows));
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/arrow/reader_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ Status TransferBool(RecordReader* reader, bool nullable, MemoryPool* pool, Datum
// Transfer boolean values to packed bitmap
auto values = reinterpret_cast<const bool*>(reader->values());
uint8_t* data_ptr = data->mutable_data();
memset(data_ptr, 0, buffer_size);
memset(data_ptr, 0, static_cast<size_t>(buffer_size));

for (int64_t i = 0; i < length; i++) {
if (values[i]) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/bloom_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ BlockSplitBloomFilter BlockSplitBloomFilter::Deserialize(
const auto bloom_filter_bytes_in_header = header_buf->size() - header_size;
if (bloom_filter_bytes_in_header > 0) {
std::memcpy(buffer->mutable_data(), header_buf->data() + header_size,
bloom_filter_bytes_in_header);
static_cast<size_t>(bloom_filter_bytes_in_header));
}

const auto required_read_size = bloom_filter_size - bloom_filter_bytes_in_header;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/parquet/column_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1792,7 +1792,7 @@ class TypedRecordReader : public TypedColumnReaderImpl<DType>,

// Avoid valgrind warnings
memset(valid_bits_->mutable_data() + valid_bytes_old, 0,
valid_bytes_new - valid_bytes_old);
static_cast<size_t>(valid_bytes_new - valid_bytes_old));
}
}
}
Expand Down Expand Up @@ -1935,7 +1935,7 @@ class TypedRecordReader : public TypedColumnReaderImpl<DType>,
// Conservative upper bound
const int64_t possible_num_values =
std::max<int64_t>(num_records, levels_written_ - levels_position_);
ReserveValues(possible_num_values);
ReserveValues(static_cast<size_t>(possible_num_values));

const int64_t start_levels_position = levels_position_;

Expand Down
6 changes: 4 additions & 2 deletions cpp/src/parquet/column_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ class PARQUET_EXPORT Scanner {
value_offset_(0),
values_buffered_(0),
reader_(std::move(reader)) {
def_levels_.resize(descr()->max_definition_level() > 0 ? batch_size_ : 0);
rep_levels_.resize(descr()->max_repetition_level() > 0 ? batch_size_ : 0);
def_levels_.resize(
descr()->max_definition_level() > 0 ? static_cast<size_t>(batch_size_) : 0);
rep_levels_.resize(
descr()->max_repetition_level() > 0 ? static_cast<size_t>(batch_size_) : 0);
}

virtual ~Scanner() {}
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/parquet/column_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,11 +895,13 @@ class ColumnWriterImpl {
void ConcatenateBuffers(int64_t definition_levels_rle_size,
int64_t repetition_levels_rle_size,
const std::shared_ptr<Buffer>& values, uint8_t* combined) {
memcpy(combined, repetition_levels_rle_->data(), repetition_levels_rle_size);
memcpy(combined, repetition_levels_rle_->data(),
static_cast<size_t>(repetition_levels_rle_size));
combined += repetition_levels_rle_size;
memcpy(combined, definition_levels_rle_->data(), definition_levels_rle_size);
memcpy(combined, definition_levels_rle_->data(),
static_cast<size_t>(definition_levels_rle_size));
combined += definition_levels_rle_size;
memcpy(combined, values->data(), values->size());
memcpy(combined, values->data(), static_cast<size_t>(values->size()));
}
};

Expand Down
8 changes: 4 additions & 4 deletions cpp/src/parquet/encoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ std::shared_ptr<Buffer> ByteStreamSplitEncoder<DType>::FlushValues() {
AllocateBuffer(this->memory_pool(), EstimatedDataEncodedSize());
uint8_t* output_buffer_raw = output_buffer->mutable_data();
const uint8_t* raw_values = sink_.data();
::arrow::util::internal::ByteStreamSplitEncode<T>(raw_values, num_values_in_buffer_,
output_buffer_raw);
::arrow::util::internal::ByteStreamSplitEncode<T>(
raw_values, static_cast<size_t>(num_values_in_buffer_), output_buffer_raw);
sink_.Reset();
num_values_in_buffer_ = 0;
return std::move(output_buffer);
Expand Down Expand Up @@ -1018,7 +1018,7 @@ inline int DecodePlain(const uint8_t* data, int64_t data_size, int num_values,
}
// If bytes_to_decode == 0, data could be null
if (bytes_to_decode > 0) {
memcpy(out, data, bytes_to_decode);
memcpy(out, data, static_cast<size_t>(bytes_to_decode));
}
return static_cast<int>(bytes_to_decode);
}
Expand Down Expand Up @@ -1574,7 +1574,7 @@ class DictDecoderImpl : public DecoderImpl, virtual public DictDecoder<Type> {

// XXX(wesm): Cannot append "valid bits" directly to the builder
std::vector<uint8_t> valid_bytes(num_values, 0);
int64_t i = 0;
size_t i = 0;
VisitNullBitmapInline(
valid_bits, valid_bits_offset, num_values, null_count,
[&]() { valid_bytes[i++] = 1; }, [&]() { ++i; });
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/file_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ int64_t ScanFileContents(std::vector<int> columns, const int32_t column_batch_si
ScanAllValues(column_batch_size, def_levels.data(), rep_levels.data(),
values.data(), &values_read, col_reader.get());
if (col_reader->descr()->max_repetition_level() > 0) {
for (int64_t i = 0; i < levels_read; i++) {
for (size_t i = 0; i < static_cast<size_t>(levels_read); i++) {
if (rep_levels[i] == 0) {
total_rows[col]++;
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/parquet/metadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,8 @@ class FileMetaDataBuilder::FileMetaDataBuilderImpl {
key_value_metadata_ = key_value_metadata_->Merge(*key_value_metadata);
}
metadata_->key_value_metadata.clear();
metadata_->key_value_metadata.reserve(key_value_metadata_->size());
metadata_->key_value_metadata.reserve(
static_cast<size_t>(key_value_metadata_->size()));
for (int64_t i = 0; i < key_value_metadata_->size(); ++i) {
format::KeyValue kv_pair;
kv_pair.__set_key(key_value_metadata_->key(i));
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/parquet/statistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ void TypedStatisticsImpl<DType>::PlainEncode(const T& src, std::string* dst) con
encoder->Put(&src, 1);
auto buffer = encoder->FlushValues();
auto ptr = reinterpret_cast<const char*>(buffer->data());
dst->assign(ptr, buffer->size());
dst->assign(ptr, static_cast<size_t>(buffer->size()));
}

template <typename DType>
Expand Down

0 comments on commit 8a73c09

Please sign in to comment.