Akshay Verma
04/22/2024, 10:43 AMjay
04/22/2024, 5:03 PMAkshay Verma
04/22/2024, 8:53 PMpub fn repeat(&self, n: usize) -> DaftResult {
    let self_arrow = self.as_arrow();
    // Handle empty data case.
    if self.is_empty() {
        return Ok(Utf8Array::empty(self.name(), &DataType::Utf8));
    }
    let arrow_result = self_arrow
        .iter()
        .flat_map(|element| element.map(|w| w.repeat(n)))
        .collect::>>();
    
    Ok(Utf8Array::from((self.name(), Box::new(arrow_result?))))
}
For which I get the following Error output:
rror[E0277]: a value of type `Result<arrow2::array::Utf8Array<i64>, DaftError>` cannot be built from an iterator over elements of type `std::string::String`
   --> src\daft-core\src\array\ops\utf8.rs:510:14
    |
510 |             .collect::<DaftResult<arrow2::array::Utf8Array<i64>>>();
    |              ^^^^^^^ value of type `Result<arrow2::array::Utf8Array<i64>, DaftError>` cannot be built from `std::iter::Iterator<Item=std::string::String>`
    |
    = help: the trait `FromIterator<std::string::String>` is not implemented for `Result<arrow2::array::Utf8Array<i64>, DaftError>`
    = help: the trait `FromIterator<Result<A, E>>` is implemented for `Result<V, E>`Colin Ho
04/22/2024, 11:18 PMflat_map , try using map instead, i.e.
let arrow_result = self_arrow
            .iter()
            .map(|element| element.map(|w| w.repeat(n)))
            .collect::<arrow2::array::Utf8Array<i64>>();
what's happening with your code is that flat_map is filtering out the null values, resulting in an iterator of Strings . This won't work because arrow2 arrays are built from Option<String> , and also because we want to preserve cardinality in the result array.Akshay Verma
04/23/2024, 5:42 AMAkshay Verma
04/28/2024, 9:55 PMerror[E0053]: method `to_field` has an incompatible type for trait
  --> src/daft-dsl/src/functions/utf8/repeat.rs:21:32
   |
21 |     fn to_field(&self, inputs: &[Expr], schema: &Schema, _: &Expr) -> DaftResult<Field> {
   |                                ^^^^^^^
   |                                |
   |                                expected `Arc<Expr>`, found `Expr`
   |                                help: change the parameter type to match the trait: `&[Arc<Expr>]`
   |
note: type in trait
  --> src/daft-dsl/src/functions/mod.rs:55:17
   |
55 |         inputs: &[ExprRef],
   |                 ^^^^^^^^^^
   = note: expected signature `fn(&RepeatEvaluator, &[Arc<Expr>], &Schema, &FunctionExpr) -> Result<_, _>`
              found signature `fn(&RepeatEvaluator, &[Expr], &Schema, &Expr) -> Result<_, _>`jay
04/28/2024, 9:56 PMto_field function signature.
You can reference the other utf8 to_field implementations, but those inputs are now ExprRef!jay
04/28/2024, 9:57 PM&[Expr] with &[ExprRef] that should do the trick ๐Akshay Verma
04/28/2024, 9:58 PMAkshay Verma
04/28/2024, 11:47 PMAkshay Verma
04/28/2024, 11:49 PMevaluate function, the input is misintrepreted as &Series but should be usize , which part should be modified to get this fixed
error[E0308]: mismatched types
  --> src/daft-dsl/src/functions/utf8/repeat.rs:50:34
   |
50 |                 data.utf8_repeat(n)
   |                      ----------- ^ expected `usize`, found `&Series`
   |                      |
   |                      arguments to this method are incorrect
   |
note: method defined here
  --> /home/akshay/projects/oss/Daft/src/daft-core/src/series/ops/utf8.rs:91:12
   |
91 |     pub fn utf8_repeat(&self, n: usize) -> DaftResult<Series> {
   |            ^^^^^^^^^^^jay
04/28/2024, 11:52 PMutf8_repeat function to take a Series instead of a single number
You can reference the other utf8 kernels for an example. A good one to check out might be something like `left`: Daft/src/daft-dsl/src/functions/utf8/left.rsAkshay Verma
04/28/2024, 11:53 PMjay
04/28/2024, 11:54 PMDaft/src/daft-core/src/series/ops/utf8.rs):
pub fn utf8_right(&self, nchars: &Series) -> DaftResult<Series>