Skip to content

Commit

Permalink
move make_and_append_view to common.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachelint committed Sep 11, 2024
1 parent 06d104d commit 48cb4db
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
3 changes: 1 addition & 2 deletions datafusion/functions/src/string/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ use datafusion_expr::ColumnarValue;

/// Make a `u128` based on the given substr, start(offset to view.offset), and
/// push into to the given buffers
// TODO: tmp copy, remove after #12383 is merged
fn make_and_append_view(
pub(crate) fn make_and_append_view(
views_buffer: &mut Vec<u128>,
null_builder: &mut NullBufferBuilder,
raw: &u128,
Expand Down
26 changes: 3 additions & 23 deletions datafusion/functions/src/unicode/substr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use std::any::Any;
use std::cmp::max;
use std::sync::Arc;

use crate::string::common::make_and_append_view;
use crate::utils::{make_scalar_function, utf8_to_str_type};
use arrow::array::{
make_view, Array, ArrayAccessor, ArrayIter, ArrayRef, AsArray, ByteView,
GenericStringArray, OffsetSizeTrait, StringViewArray,
Array, ArrayAccessor, ArrayIter, ArrayRef, AsArray, GenericStringArray,
OffsetSizeTrait, StringViewArray,
};
use arrow::datatypes::DataType;
use arrow_buffer::{NullBufferBuilder, ScalarBuffer};
Expand Down Expand Up @@ -165,27 +166,6 @@ fn get_true_start_end(input: &str, start: i64, count: Option<u64>) -> (usize, us
(st, ed)
}

/// Make a `u128` based on the given substr, start(offset to view.offset), and
/// push into to the given buffers
pub fn make_and_append_view(
views_buffer: &mut Vec<u128>,
null_builder: &mut NullBufferBuilder,
raw: &u128,
substr: &str,
start: u32,
) {
let substr_len = substr.len();
let sub_view = if substr_len > 12 {
let view = ByteView::from(*raw);
make_view(substr.as_bytes(), view.buffer_index, view.offset + start)
} else {
// inline value does not need block id or offset
make_view(substr.as_bytes(), 0, 0)
};
views_buffer.push(sub_view);
null_builder.append_non_null();
}

// The decoding process refs the trait at: arrow/arrow-data/src/byte_view.rs:44
// From<u128> for ByteView
fn string_view_substr(
Expand Down

0 comments on commit 48cb4db

Please sign in to comment.