Skip to content

Commit

Permalink
More string_view less string (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd authored Jan 22, 2024
1 parent 328f359 commit a5e6b95
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pantab/src/pantab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,13 @@ template <typename OffsetT> class Utf8InsertHelper : public InsertHelper {

const struct ArrowBufferView buffer_view =
ArrowArrayViewGetBytesUnsafe(&array_view_, idx);
#if defined(_WIN32) && defined(_MSC_VER)
const auto result = std::string{
buffer_view.data.as_char, static_cast<size_t>(buffer_view.size_bytes)};
#else
const auto result = std::string_view{
buffer_view.data.as_char, static_cast<size_t>(buffer_view.size_bytes)};
#endif
hyperapi::internal::ValueInserter{*inserter_}.addValue(result);
}
};
Expand Down Expand Up @@ -405,11 +410,13 @@ void write_to_hyper(
for (int64_t i = 0; i < schema.n_children; i++) {
const auto hypertype =
hyperTypeFromArrowSchema(schema.children[i], &error);
const auto name = std::string{schema.children[i]->name};

// Almost all arrow types are nullable
hyper_columns.emplace_back(hyperapi::TableDefinition::Column{
name, hypertype, hyperapi::Nullability::Nullable});
const hyperapi::TableDefinition::Column column{
std::string(schema.children[i]->name), hypertype,
hyperapi::Nullability::Nullable};

hyper_columns.emplace_back(std::move(column));
}

const hyperapi::TableName table_name{hyper_schema, hyper_table};
Expand Down Expand Up @@ -546,9 +553,15 @@ class StringReadHelper : public ReadHelper {
return;
}

#if defined(_WIN32) && defined(_MSC_VER)
const auto strval = value.get<std::string>();
const ArrowStringView arrow_string_view{
strval.c_str(), static_cast<int64_t>(strval.size())};
#else
const auto strval = value.get<std::string_view>();
const ArrowStringView arrow_string_view{
strval.data(), static_cast<int64_t>(strval.size())};
#endif

if (ArrowArrayAppendString(array_, arrow_string_view)) {
throw std::runtime_error("ArrowAppendString failed");
Expand Down

0 comments on commit a5e6b95

Please sign in to comment.