jiangzhx commented on issue #5635:
URL: 
https://github.com/apache/arrow-datafusion/issues/5635#issuecomment-1475087150

   > 
   
   @BubbaJoe 
   based on your code, I made some modifications. Now everything looks normal.
   
   ```
       pub fn to_date(args: &[ArrayRef]) -> Result<ArrayRef> {
           if args.is_empty() || args.len() > 1 {
               return Err(DataFusionError::Internal(format!(
                   "to_date was called with {} arguments. It requires only 1.",
                   args.len()
               )));
           }
           let arg = &args[0].as_any().downcast_ref::<StringArray>().unwrap();
           let mut builder = Date32Builder::new();
           for date_string in arg.iter() {
               let date_time = match DateTime::parse_from_rfc3339(
                   date_string.expect("date_string is null"),
               ) {
                   Ok(dt) => dt,
                   Err(e) => {
                       return 
Result::Err(DataFusionError::Internal(e.to_string()));
                   }
               };
               builder.append_value((date_time.timestamp() / 86400) as i32);
           }
           Ok(Arc::new(builder.finish()))
       }
   
       let to_date = make_scalar_function(to_date);
       let to_date = create_udf(
           "to_date",
           vec![DataType::Utf8],
           Arc::new(DataType::Date32),
           Volatility::Immutable,
           to_date,
       );
   
       ctx.register_udf(to_date.clone());
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to