goldmedal commented on code in PR #10956:
URL: https://github.com/apache/datafusion/pull/10956#discussion_r1644370623


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -859,6 +878,35 @@ impl Unparser<'_> {
         }
     }
 
+    fn process_interval_nanosecond(nano: i64) -> String {

Review Comment:
   @alamb After using ArrayFormatter, I noticed that the results contain many 
redundant words. For example:
   
   ```
   input expr: interval_month_day_nano_lit("-3 MONTH"),
   output result: r#"INTERVAL '0 YEARS -3 MONS 0 DAYS 0 HOURS 0 MINS 
0.000000000 SECS'"#,
   ---
   input expr: interval_month_day_nano_lit("1 YEAR 1 MONTH 1 DAY 3 HOUR 10 
MINUTE 20 SECOND"),
   output result: r#"INTERVAL '0 YEARS 13 MONS 1 DAYS 3 HOURS 10 MINS 
20.000000000 SECS'"#,
   ```
   I think both of these are valid SQL. They just don't look very smart, but 
it's okay with me. 
   
   I implemented the code like
   ```rust
               ScalarValue::IntervalMonthDayNano(Some(_i)) => {
                   let wrap_array = v.to_array()?;
                   let Some(result) = array_value_to_string(&wrap_array, 
0).ok() else {
                       return internal_err!("Unable to convert 
IntervalMonthDayNano to string");
                   };
                   let interval = Interval {
                       value: 
Box::new(ast::Expr::Value(SingleQuotedString(result.to_uppercase()))),
                       leading_field: None,
                       leading_precision: None,
                       last_field: None,
                       fractional_seconds_precision: None,
                   };
                   Ok(ast::Expr::Interval(interval))
               }
   ```
   What do you think? Does it make sense?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to