ColinLeeo commented on code in PR #739:
URL: https://github.com/apache/tsfile/pull/739#discussion_r2958752878
##########
cpp/src/cwrapper/arrow_c.cc:
##########
@@ -247,52 +297,62 @@ inline int BuildFixedLengthArrowArrayC(common::Vector*
vec, uint32_t row_count,
uint8_t* packed_buffer = static_cast<uint8_t*>(
common::mem_alloc(packed_size, common::MOD_TSBLOCK));
if (packed_buffer == nullptr) {
- if (null_bitmap != nullptr) {
- common::mem_free(null_bitmap);
- }
- common::mem_free(array_data->buffers);
- common::mem_free(array_data);
+ FreeArrowArrayData(array_data);
return common::E_OOM;
}
std::memset(packed_buffer, 0, packed_size);
+ // Vector stores booleans as one byte each, densely packed
+ // (null rows have no entry). Scatter into Arrow bit-packed format.
+ common::BitMap& bm = vec->get_bitmap();
+ uint32_t src_idx = 0;
const uint8_t* src = reinterpret_cast<const uint8_t*>(vec_data);
for (uint32_t i = 0; i < row_count; ++i) {
- if (src[i] != 0) {
+ if (has_null && bm.test(i)) {
+ continue; // null row, no data in value buffer
+ }
+ if (src[src_idx] != 0) {
uint32_t byte_idx = i / 8;
uint32_t bit_idx = i % 8;
packed_buffer[byte_idx] |= (1 << bit_idx);
}
+ src_idx++;
}
data_buffer = packed_buffer;
} else {
size_t data_size = type_size * row_count;
data_buffer = common::mem_alloc(data_size, common::MOD_TSBLOCK);
if (data_buffer == nullptr) {
- if (null_bitmap != nullptr) {
- common::mem_free(null_bitmap);
- }
- common::mem_free(array_data->buffers);
- common::mem_free(array_data);
+ FreeArrowArrayData(array_data);
return common::E_OOM;
}
- std::memcpy(data_buffer, vec_data, data_size);
+
+ if (has_null) {
+ // Value buffer is densely packed (no slots for null rows).
+ // Scatter non-null values into their correct Arrow positions.
+ common::BitMap& bm = vec->get_bitmap();
+ uint32_t src_offset = 0;
+ for (uint32_t i = 0; i < row_count; ++i) {
+ if (bm.test(i)) {
+ // null row: write zero placeholder in Arrow buffer
+ std::memset(static_cast<char*>(data_buffer) + i *
type_size,
+ 0, type_size);
Review Comment:
Fixed
##########
cpp/src/common/tablet.cc:
##########
@@ -163,6 +163,89 @@ int Tablet::add_timestamp(uint32_t row_index, int64_t
timestamp) {
return E_OK;
}
+int Tablet::set_timestamps(const int64_t* timestamps, uint32_t count) {
+ if (err_code_ != E_OK) {
+ return err_code_;
+ }
+ ASSERT(timestamps_ != NULL);
+ if (UNLIKELY(count > static_cast<uint32_t>(max_row_num_))) {
+ return E_OUT_OF_RANGE;
+ }
+ std::memcpy(timestamps_, timestamps, count * sizeof(int64_t));
+ cur_row_size_ = std::max(count, cur_row_size_);
+ return E_OK;
+}
+
+int Tablet::set_column_values(uint32_t schema_index, const void* data,
+ const uint8_t* null_bitmap, uint32_t count) {
+ if (err_code_ != E_OK) {
+ return err_code_;
+ }
+ if (UNLIKELY(schema_index >= schema_vec_->size())) {
+ return E_OUT_OF_RANGE;
+ }
+ if (UNLIKELY(count > static_cast<uint32_t>(max_row_num_))) {
+ return E_OUT_OF_RANGE;
+ }
+
+ const MeasurementSchema& schema = schema_vec_->at(schema_index);
+ size_t elem_size = 0;
+ void* dst = nullptr;
+ switch (schema.data_type_) {
+ case BOOLEAN:
+ elem_size = sizeof(bool);
+ dst = value_matrix_[schema_index].bool_data;
+ break;
+ case DATE:
+ case INT32:
+ elem_size = sizeof(int32_t);
+ dst = value_matrix_[schema_index].int32_data;
+ break;
+ case TIMESTAMP:
+ case INT64:
+ elem_size = sizeof(int64_t);
+ dst = value_matrix_[schema_index].int64_data;
+ break;
+ case FLOAT:
+ elem_size = sizeof(float);
+ dst = value_matrix_[schema_index].float_data;
+ break;
+ case DOUBLE:
+ elem_size = sizeof(double);
+ dst = value_matrix_[schema_index].double_data;
+ break;
+ default:
+ return E_TYPE_NOT_SUPPORTED;
+ }
+
+ if (null_bitmap == nullptr) {
+ // All valid: bulk copy + mark all as non-null
+ std::memcpy(dst, data, count * elem_size);
+ bitmaps_[schema_index].clear_all();
+ } else {
+ // Bulk copy all data (null positions will have garbage but won't be
+ // read).
+ std::memcpy(dst, data, count * elem_size);
+
+ // Convert Arrow bitmap (1=valid, 0=null) to TsFile bitmap (1=null,
+ // 0=valid) by inverting and writing directly.
+ char* tsfile_bm = bitmaps_[schema_index].get_bitmap();
+ uint32_t full_bytes = count / 8;
+ for (uint32_t i = 0; i < full_bytes; i++) {
+ tsfile_bm[i] = ~static_cast<char>(null_bitmap[i]);
+ }
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]