Skip to content

Commit 9274a4c

Browse files
committed
Resolve PyObject* conversion warnings
The `Read as arrow` commit introduced a `UTF_DYNAMIC32` type whose value types can't safely be converted to pointers.
1 parent 8b6b5e6 commit 9274a4c

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

cpp/arcticdb/column_store/statistics.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ FieldStatsImpl generate_column_statistics(ColumnData column_data) {
187187
const size_t count = block->row_count();
188188
if constexpr (is_numeric_type(TagType::DataTypeTag::data_type)) {
189189
return generate_numeric_statistics<RawType>(std::span{ptr, count});
190-
} else if constexpr (is_dynamic_string_type(TagType::DataTypeTag::data_type) && !is_output_only_type(TagType::DataTypeTag::data_type)) {
190+
} else if constexpr (is_dynamic_string_type(TagType::DataTypeTag::data_type) && !is_arrow_output_only_type(TagType::DataTypeTag::data_type)) {
191191
return generate_string_statistics(std::span{ptr, count});
192192
} else {
193193
util::raise_rte("Cannot generate statistics for data type");
@@ -200,7 +200,7 @@ FieldStatsImpl generate_column_statistics(ColumnData column_data) {
200200
if constexpr (is_numeric_type(TagType::DataTypeTag::data_type)) {
201201
auto local_stats = generate_numeric_statistics<RawType>(std::span{ptr, count});
202202
stats.compose<RawType>(local_stats);
203-
} else if constexpr (is_dynamic_string_type(TagType::DataTypeTag::data_type) && !is_output_only_type(TagType::DataTypeTag::data_type)) {
203+
} else if constexpr (is_dynamic_string_type(TagType::DataTypeTag::data_type) && !is_arrow_output_only_type(TagType::DataTypeTag::data_type)) {
204204
auto local_stats = generate_string_statistics(std::span{ptr, count});
205205
stats.compose<RawType>(local_stats);
206206
} else {

cpp/arcticdb/entity/types.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ constexpr bool is_dynamic_string_type(DataType v) {
297297
return is_dynamic_string_type(slice_value_type(v));
298298
}
299299

300-
constexpr bool is_output_only_type(DataType d) {
300+
constexpr bool is_arrow_output_only_type(DataType d) {
301301
return d == DataType::UTF_DYNAMIC32;
302302
}
303303

@@ -500,6 +500,10 @@ constexpr bool is_object_type(TypeDescriptor td) {
500500
|| is_array_type(td);
501501
}
502502

503+
constexpr bool is_arrow_output_only_type(TypeDescriptor td) {
504+
return is_arrow_output_only_type(td.data_type());
505+
}
506+
503507
inline void set_data_type(DataType data_type, TypeDescriptor &type_desc) {
504508
type_desc.data_type_ = data_type;
505509
}

cpp/arcticdb/pipeline/pandas_output_frame.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,29 @@ PandasOutputFrame::~PandasOutputFrame() {
4040
column_data.type().visit_tag([&](auto type_desc_tag) {
4141
using TDT = decltype(type_desc_tag);
4242
constexpr auto td = TypeDescriptor(type_desc_tag);
43-
if constexpr (is_object_type(TypeDescriptor(type_desc_tag))) {
43+
if constexpr (is_object_type(td)) {
4444
if constexpr(is_array_type(td)) {
4545
auto it = column_data.buffer().iterator(sizeof(PyObject*));
4646
while(!it.finished()) {
47-
util::check(reinterpret_cast<PyObject*>(it.value()) != nullptr, "Can't delete null item");
48-
Py_DECREF(reinterpret_cast<PyObject*>(it.value()));
47+
if (reinterpret_cast<PyObject*>(it.value()) != nullptr) {
48+
Py_DECREF(reinterpret_cast<PyObject*>(it.value()));
49+
} else {
50+
log::version().error("Unexpected nullptr to DecRef in PandasOutputFrame destructor");
51+
}
4952
it.next();
5053
}
51-
} else {
54+
} else if constexpr (!is_arrow_output_only_type(td)) {
5255
while (auto block = column_data.next<TDT>()) {
5356
for (auto item : *block) {
54-
util::check(reinterpret_cast<PyObject *>(item) != nullptr, "Can't delete null item");
55-
Py_DECREF(reinterpret_cast<PyObject *>(item));
57+
if (reinterpret_cast<PyObject*>(item) != nullptr) {
58+
Py_DECREF(reinterpret_cast<PyObject*>(item));
59+
} else {
60+
log::version().error("Unexpected nullptr to DecRef in PandasOutputFrame destructor");
61+
}
5662
}
5763
}
64+
} else {
65+
log::version().error("Unexpected arrow output format seen in PandasOutputFrame");
5866
}
5967
}
6068
});

0 commit comments

Comments
 (0)