Skip to content

Commit

Permalink
array_has avoid row converter for string type (#12097)
Browse files Browse the repository at this point in the history
* first draft

Signed-off-by: jayzhan211 <[email protected]>

* avoid row converter for string

Signed-off-by: jayzhan211 <[email protected]>

* cleanup

Signed-off-by: jayzhan211 <[email protected]>

* string view

Signed-off-by: jayzhan211 <[email protected]>

* trigger ci

Signed-off-by: jayzhan211 <[email protected]>

* refactor

Signed-off-by: jayzhan211 <[email protected]>

* cleanup

Signed-off-by: jayzhan211 <[email protected]>

* array_has_all

Signed-off-by: jayzhan211 <[email protected]>

* array_has_any

Signed-off-by: jayzhan211 <[email protected]>

* cleanup

Signed-off-by: jayzhan211 <[email protected]>

* cleanup

Signed-off-by: jayzhan211 <[email protected]>

* fmt

Signed-off-by: jayzhan211 <[email protected]>

* rm unused import

Signed-off-by: jayzhan211 <[email protected]>

* cleanup

Signed-off-by: jayzhan211 <[email protected]>

---------

Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Aug 24, 2024
1 parent 3b90e3e commit 932adab
Show file tree
Hide file tree
Showing 3 changed files with 227 additions and 108 deletions.
1 change: 1 addition & 0 deletions datafusion/common/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
pub mod expr;
pub mod memory;
pub mod proxy;
pub mod string_utils;

use crate::error::{_internal_datafusion_err, _internal_err};
use crate::{arrow_datafusion_err, DataFusionError, Result, ScalarValue};
Expand Down
31 changes: 31 additions & 0 deletions datafusion/common/src/utils/string_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

//! Utilities for working with strings

use arrow::{array::AsArray, datatypes::DataType};
use arrow_array::Array;

/// Convenient function to convert an Arrow string array to a vector of strings
pub fn string_array_to_vec(array: &dyn Array) -> Vec<Option<&str>> {
match array.data_type() {
DataType::Utf8 => array.as_string::<i32>().iter().collect(),
DataType::LargeUtf8 => array.as_string::<i64>().iter().collect(),
DataType::Utf8View => array.as_string_view().iter().collect(),
_ => unreachable!(),
}
}
Loading

0 comments on commit 932adab

Please sign in to comment.