You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Omega359 (via GitHub)" <gi...@apache.org> on 2024/03/10 14:36:16 UTC
[PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Omega359 opened a new pull request, #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #9466
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
Functions are migrated to the new crate and use the new patterns as described in https://github.com/apache/arrow-datafusion/issues/9286 & https://github.com/apache/arrow-datafusion/pull/9216
## What changes are included in this PR?
Code, tests moved to new location, references updated.
## Are these changes tested?
Yes
## Are there any user-facing changes?
No
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1520417551
##########
datafusion/functions/src/datetime/current_date.rs:
##########
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::any::Any;
+
+use arrow::datatypes::DataType;
+use arrow::datatypes::DataType::Date32;
+use chrono::{Datelike, NaiveDate};
+
+use datafusion_common::{internal_err, Result, ScalarValue};
+use datafusion_expr::simplify::{ExprSimplifyResult, SimplifyInfo};
+use datafusion_expr::{ColumnarValue, Expr, ScalarUDFImpl, Signature, Volatility};
+
+#[derive(Debug)]
+pub(super) struct CurrentDateFunc {
+ signature: Signature,
+ aliases: Vec<String>,
+}
+
+impl CurrentDateFunc {
+ pub fn new() -> Self {
+ Self {
+ signature: Signature::uniform(0, vec![], Volatility::Stable),
+ aliases: vec![String::from("today")],
+ }
+ }
+}
+
+/// Create an implementation of `current_date()` that always returns the
+/// specified current date.
+///
+/// The semantics of `current_date()` require it to return the same value
+/// wherever it appears within a single statement. This value is
+/// chosen during planning time.
+impl ScalarUDFImpl for CurrentDateFunc {
+ fn as_any(&self) -> &dyn Any {
+ self
+ }
+
+ fn name(&self) -> &str {
+ "current_date"
+ }
+
+ fn signature(&self) -> &Signature {
+ &self.signature
+ }
+
+ fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+ Ok(Date32)
+ }
+
+ fn invoke(&self, _args: &[ColumnarValue]) -> Result<ColumnarValue> {
+ internal_err!(
+ "invoke should not be called on a simplified current_date() function"
+ )
+ }
+
+ fn aliases(&self) -> &[String] {
+ &self.aliases
+ }
+
+ fn simplify(
+ &self,
+ _args: Vec<Expr>,
+ info: &dyn SimplifyInfo,
+ ) -> Result<ExprSimplifyResult> {
+ let now_ts = info.execution_props().query_execution_start_time;
Review Comment:
👍
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1521386239
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
Thinking about this more - the issue is not test related because we can use dev dependencies. The issue is publishing to crates.io because cargo publishes with dev-dependencies and has been for many many years according to the [bug report](https://github.com/rust-lang/cargo/issues/4242). Would it be possible to just fix that by the use of --no-dev-deps or something similar during publishing?
🤔
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1520416444
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
How much of the optimizer integration test do you think needs Udfs? I am wondering maybe we could just port the tests case for `now()` into core/tests/sql_integration` or something and eave the rest of the optimizer_integration test in the optimizer crate?
The reason it might be good to leave the optimzer tests in the optimizer crate are
1. Easier to run `cargo test -p datafusion_optimizer` and run all the relevant tests
2. Ensure that we could still use `datafusion_optimizer` without the function definitions
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1521469862
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
https://github.com/apache/arrow-datafusion/issues/9579
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1523460945
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
I think moving the tests to the core (what this PR does) is probably the best solution for now, as it correctly reflects the dependencies (the optimizer tests are testing behavior of functions that are not available to optimizer)
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1521370910
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
I'll take a look. 6/20 tests use functions in the test (concat, sum, concat_ws, now(), avg). I can move just those over for sure. I wish this test dependency issue wasn't such an problem in Rust - most of the problems I've seen migrating the functions have been test related.
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#discussion_r1523512074
##########
datafusion/core/tests/optimizer_integration.rs:
##########
@@ -342,7 +343,12 @@ fn test_sql(sql: &str) -> Result<LogicalPlan> {
let statement = &ast[0];
// create a logical query plan
- let context_provider = MyContextProvider::default();
+ let now_udf = datetime::functions()
Review Comment:
I moved all but the tests that required now() back to the datafusion/optimizer/tests folder.
--
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
Re: [PR] Move from_unixtime, now, current_date, current_time functions to datafusion-functions [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #9537:
URL: https://github.com/apache/arrow-datafusion/pull/9537#issuecomment-1994719783
🚀 - thank you @Omega359
--
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