alamb commented on code in PR #8193:
URL: https://github.com/apache/arrow-datafusion/pull/8193#discussion_r1397777134


##########
datafusion/common/src/scalar.rs:
##########
@@ -959,6 +959,9 @@ impl ScalarValue {
             ScalarValue::Decimal256(Some(v), precision, scale) => Ok(
                 ScalarValue::Decimal256(Some(v.neg_wrapping()), *precision, 
*scale),
             ),
+            ScalarValue::TimestampSecond(Some(v), tz) => {

Review Comment:
   I wonder if we should also support `TimestampMillisecond`, 
`TimestampMicrosecond` and `TimestampNanosecond` 🤔 



##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -224,14 +225,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
 
             SQLExpr::Cast {
                 expr, data_type, ..
-            } => Ok(Expr::Cast(Cast::new(
-                Box::new(self.sql_expr_to_logical_expr(
-                    *expr,
-                    schema,
-                    planner_context,
-                )?),
-                self.convert_data_type(&data_type)?,
-            ))),
+            } => {
+                let mut dt = self.convert_data_type(&data_type)?;
+                let expr =
+                    self.sql_expr_to_logical_expr(*expr, schema, 
planner_context)?;
+
+                // int/floats should come as seconds rather as nanoseconds
+                dt = match &dt {

Review Comment:
   It seems strange to special case `CAST AS TIMESTAMP` to produce a 
`Timestamp::Seconds` while anywhere else in SQL `TIMESTAMP` means 
`Timestamp::Nanoseconds`
   
   Did you consider changing
   
   
https://github.com/apache/arrow-datafusion/blob/8fcc5e03147db93d688c2dfa112653191476f2bf/datafusion/sql/src/planner.rs#L335-L348
   
   🤔 



##########
datafusion/sql/src/expr/mod.rs:
##########
@@ -224,14 +225,23 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
 
             SQLExpr::Cast {
                 expr, data_type, ..
-            } => Ok(Expr::Cast(Cast::new(
-                Box::new(self.sql_expr_to_logical_expr(
-                    *expr,
-                    schema,
-                    planner_context,
-                )?),
-                self.convert_data_type(&data_type)?,
-            ))),
+            } => {
+                let mut dt = self.convert_data_type(&data_type)?;
+                let expr =
+                    self.sql_expr_to_logical_expr(*expr, schema, 
planner_context)?;
+
+                // int/floats should come as seconds rather as nanoseconds
+                dt = match &dt {

Review Comment:
   It seems strange to special case `CAST AS TIMESTAMP` to produce a 
`Timestamp::Seconds` while anywhere else in SQL `TIMESTAMP` means 
`Timestamp::Nanoseconds`
   
   Did you consider changing
   
   
https://github.com/apache/arrow-datafusion/blob/8fcc5e03147db93d688c2dfa112653191476f2bf/datafusion/sql/src/planner.rs#L335-L348
   
   🤔 



##########
datafusion/common/src/scalar.rs:
##########
@@ -959,6 +959,9 @@ impl ScalarValue {
             ScalarValue::Decimal256(Some(v), precision, scale) => Ok(
                 ScalarValue::Decimal256(Some(v.neg_wrapping()), *precision, 
*scale),
             ),
+            ScalarValue::TimestampSecond(Some(v), tz) => {

Review Comment:
   I wonder if we should also support `TimestampMillisecond`, 
`TimestampMicrosecond` and `TimestampNanosecond` 🤔 



-- 
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]

Reply via email to