@@ -20,7 +20,7 @@ use std::any::Any;
2020
2121use crate :: utils:: utf8_to_int_type;
2222use arrow:: array:: {
23- Array , ArrayRef , Int32Array , Int32Builder , Int64Builder , LargeStringArray ,
23+ Array , Int32Array , Int32Builder , Int64Builder , LargeStringArray ,
2424 StringArray , StringViewArray ,
2525} ;
2626use datafusion_common:: types:: logical_string;
@@ -95,40 +95,37 @@ impl ScalarUDFImpl for OctetLengthFunc {
9595
9696 match array {
9797 ColumnarValue :: Array ( v) => {
98- let arr: ArrayRef = v. clone ( ) ;
99-
100- if let Some ( arr) = arr. as_any ( ) . downcast_ref :: < StringArray > ( ) {
101- let mut builder = Int32Builder :: with_capacity ( arr. len ( ) ) ;
102- for i in 0 ..arr. len ( ) {
103- if arr. is_null ( i) {
104- builder. append_null ( ) ;
105- } else {
106- builder. append_value ( arr. value_length ( i) as i32 ) ;
107- }
108- }
109- Ok ( ColumnarValue :: Array ( Arc :: new ( builder. finish ( ) ) ) )
110- } else if let Some ( arr) = arr. as_any ( ) . downcast_ref :: < LargeStringArray > ( )
111- {
112- let mut builder = Int64Builder :: with_capacity ( arr. len ( ) ) ;
113- for i in 0 ..arr. len ( ) {
114- if arr. is_null ( i) {
115- builder. append_null ( ) ;
116- } else {
117- builder. append_value ( arr. value_length ( i) as i64 ) ;
118- }
119- }
120- Ok ( ColumnarValue :: Array ( Arc :: new ( builder. finish ( ) ) ) )
121- } else if let Some ( arr) = arr. as_any ( ) . downcast_ref :: < StringViewArray > ( ) {
122- let result = arr
123- . iter ( )
124- . map ( |s| s. map ( |s| s. len ( ) as i32 ) )
125- . collect :: < Int32Array > ( ) ;
126-
127- Ok ( ColumnarValue :: Array ( Arc :: new ( result) ) )
128- } else {
129- unreachable ! ( "octet_length expects string arrays" )
130- }
98+ if let Some ( arr) = v. as_any ( ) . downcast_ref :: < StringArray > ( ) {
99+ let mut builder = Int32Builder :: with_capacity ( arr. len ( ) ) ;
100+ for i in 0 ..arr. len ( ) {
101+ if arr. is_null ( i) {
102+ builder. append_null ( ) ;
103+ } else {
104+ builder. append_value ( arr. value_length ( i) as i32 ) ;
105+ }
106+ }
107+ Ok ( ColumnarValue :: Array ( Arc :: new ( builder. finish ( ) ) ) )
108+ } else if let Some ( arr) = v. as_any ( ) . downcast_ref :: < LargeStringArray > ( ) {
109+ let mut builder = Int64Builder :: with_capacity ( arr. len ( ) ) ;
110+ for i in 0 ..arr. len ( ) {
111+ if arr. is_null ( i) {
112+ builder. append_null ( ) ;
113+ } else {
114+ builder. append_value ( arr. value_length ( i) as i64 ) ;
131115 }
116+ }
117+ Ok ( ColumnarValue :: Array ( Arc :: new ( builder. finish ( ) ) ) )
118+ } else if let Some ( arr) = v. as_any ( ) . downcast_ref :: < StringViewArray > ( ) {
119+ let result = arr
120+ . iter ( )
121+ . map ( |s| s. map ( |s| s. len ( ) as i32 ) )
122+ . collect :: < Int32Array > ( ) ;
123+
124+ Ok ( ColumnarValue :: Array ( Arc :: new ( result) ) )
125+ } else {
126+ unreachable ! ( "octet_length expects string arrays" )
127+ }
128+ }
132129
133130 ColumnarValue :: Scalar ( v) => match v {
134131 ScalarValue :: Utf8 ( v) => Ok ( ColumnarValue :: Scalar ( ScalarValue :: Int32 (
0 commit comments