Skip to content

Commit e8768d0

Browse files
committed
Implement string view
1 parent e71d09f commit e8768d0

14 files changed

Lines changed: 161 additions & 52 deletions

cpp/src/arrow/util/converter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ struct MakeConverterImpl {
239239
DICTIONARY_CASE(DoubleType);
240240
DICTIONARY_CASE(BinaryType);
241241
DICTIONARY_CASE(StringType);
242+
DICTIONARY_CASE(StringViewType);
242243
DICTIONARY_CASE(FixedSizeBinaryType);
243244
#undef DICTIONARY_CASE
244245
default:

r/NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export(set_io_thread_count)
397397
export(show_exec_plan)
398398
export(starts_with)
399399
export(string)
400+
export(string_view)
400401
export(struct)
401402
export(time32)
402403
export(time64)

r/R/arrowExports.R

Lines changed: 12 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/R/dplyr-funcs-doc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
#' Functions can be called either as `pkg::fun()` or just `fun()`, i.e. both
8585
#' `str_sub()` and `stringr::str_sub()` work.
8686
#'
87-
#' In addition to these functions, you can call any of Arrow's 281 compute
87+
#' In addition to these functions, you can call any of Arrow's 253 compute
8888
#' functions directly. Arrow has many functions that don't map to an existing R
8989
#' function. In other cases where there is an R function mapping, you can still
9090
#' call the Arrow function directly if you don't want the adaptations that the R

r/R/type.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ Utf8 <- R6Class(
203203
code = function(namespace = FALSE) call2("utf8", .ns = if (namespace) "arrow")
204204
)
205205
)
206+
StringView <- R6Class(
207+
"StringView",
208+
inherit = DataType,
209+
public = list(
210+
code = function(namespace = FALSE) call2("string_view", .ns = if (namespace) "arrow")
211+
)
212+
)
206213
LargeUtf8 <- R6Class(
207214
"LargeUtf8",
208215
inherit = DataType,
@@ -505,6 +512,10 @@ bool <- boolean
505512
#' @export
506513
utf8 <- function() Utf8__initialize()
507514

515+
#' @rdname data-type
516+
#' @export
517+
string_view <- function() StringView__initialize()
518+
508519
#' @rdname data-type
509520
#' @export
510521
large_utf8 <- function() LargeUtf8__initialize()
@@ -806,6 +817,8 @@ canonical_type_str <- function(type_str) {
806817
boolean = "bool",
807818
bool = "bool",
808819
utf8 = "string",
820+
utf8_view = "string_view",
821+
string_view = "string_view",
809822
large_utf8 = "large_string",
810823
large_string = "large_string",
811824
binary = "binary",

r/man/data-type.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/man/read_json_arrow.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/man/schema.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

r/src/array_to_vector.cpp

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -290,26 +290,29 @@ struct Converter_String : public Converter {
290290

291291
Status Ingest_some_nulls(SEXP data, const std::shared_ptr<arrow::Array>& array,
292292
R_xlen_t start, R_xlen_t n, size_t chunk_index) const {
293-
auto p_offset = array->data()->GetValues<int32_t>(1);
294-
if (!p_offset) {
295-
return Status::Invalid("Invalid offset buffer");
296-
}
297-
auto p_strings = array->data()->GetValues<char>(2, *p_offset);
298-
if (!p_strings) {
299-
// There is an offset buffer, but the data buffer is null
300-
// There is at least one value in the array and not all the values are null
301-
// That means all values are either empty strings or nulls so there is nothing to do
302-
303-
if (array->null_count()) {
304-
arrow::internal::BitmapReader null_reader(array->null_bitmap_data(),
305-
array->offset(), n);
306-
for (int i = 0; i < n; i++, null_reader.Next()) {
307-
if (null_reader.IsNotSet()) {
308-
SET_STRING_ELT(data, start + i, NA_STRING);
293+
if constexpr (!std::is_same_v<StringArrayType, arrow::StringViewArray>) {
294+
auto p_offset = array->data()->GetValues<int32_t>(1);
295+
if (!p_offset) {
296+
return Status::Invalid("Invalid offset buffer");
297+
}
298+
auto p_strings = array->data()->GetValues<char>(2, *p_offset);
299+
if (!p_strings) {
300+
// There is an offset buffer, but the data buffer is null
301+
// There is at least one value in the array and not all the values are null
302+
// That means all values are either empty strings or nulls so there is nothing to
303+
// do
304+
305+
if (array->null_count()) {
306+
arrow::internal::BitmapReader null_reader(array->null_bitmap_data(),
307+
array->offset(), n);
308+
for (int i = 0; i < n; i++, null_reader.Next()) {
309+
if (null_reader.IsNotSet()) {
310+
SET_STRING_ELT(data, start + i, NA_STRING);
311+
}
309312
}
310313
}
314+
return Status::OK();
311315
}
312-
return Status::OK();
313316
}
314317

315318
StringArrayType* string_array = static_cast<StringArrayType*>(array.get());
@@ -725,7 +728,8 @@ class Converter_Dictionary : public Converter {
725728
// TODO (npr): this coercion should be optional, "dictionariesAsFactors" ;)
726729
// Alternative: preserve the logical type of the dictionary values
727730
// (e.g. if dict is timestamp, return a POSIXt R vector, not factor)
728-
if (dictionary_->type_id() != Type::STRING) {
731+
if (dictionary_->type_id() != Type::STRING &&
732+
dictionary_->type_id() != Type::STRING_VIEW) {
729733
cpp11::safe[Rf_warning]("Coercing dictionary values to R character factor levels");
730734
}
731735

@@ -1262,6 +1266,10 @@ std::shared_ptr<Converter> Converter::Make(
12621266
return std::make_shared<arrow::r::Converter_String<arrow::LargeStringArray>>(
12631267
chunked_array);
12641268

1269+
case Type::STRING_VIEW:
1270+
return std::make_shared<arrow::r::Converter_String<arrow::StringViewArray>>(
1271+
chunked_array);
1272+
12651273
case Type::DICTIONARY:
12661274
return std::make_shared<arrow::r::Converter_Dictionary>(chunked_array);
12671275

r/src/arrowExports.cpp

Lines changed: 26 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)