You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/30 11:38:51 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4022: Implement current_date scalar function

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


##########
datafusion/expr/src/built_in_function.rs:
##########
@@ -254,6 +258,7 @@ impl BuiltinScalarFunction {
 
             // Stable builtin functions
             BuiltinScalarFunction::Now => Volatility::Stable,
+            BuiltinScalarFunction::CurrentDate => Volatility::Stable,

Review Comment:
   👍 



##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -452,6 +452,14 @@ pub fn now() -> Expr {
     }
 }
 
+/// Returns current UTC date in default format yyyy-MM-dd

Review Comment:
   ```suggestion
   /// Returns current UTC date as a [`DataType::Date32`] value
   ```



##########
datafusion/core/tests/sql/timestamp.rs:
##########
@@ -1619,3 +1619,35 @@ async fn test_cast_to_timetz_should_not_work() -> Result<()> {
     );
     Ok(())
 }
+
+#[tokio::test]
+async fn test_current_date() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let sql = "select current_date() dt";
+    let results = execute_to_batches(&ctx, sql).await;
+    assert_eq!(
+        results[0]
+            .schema()
+            .field_with_name("dt")
+            .unwrap()
+            .data_type()
+            .to_owned(),
+        DataType::Date32
+    );
+
+    let sql = "select case when current_date() = cast(now() as date) then 'OK' else 'FAIL' end result";

Review Comment:
   Nice!



##########
datafusion/physical-expr/src/functions.rs:
##########
@@ -427,6 +427,12 @@ pub fn create_physical_fun(
                 execution_props.query_execution_start_time,
             ))
         }
+        BuiltinScalarFunction::CurrentDate => {
+            // bind value for now at plan time

Review Comment:
   ```suggestion
               // bind value for current_date at plan time
   ```



-- 
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-unsubscribe@arrow.apache.org

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