-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Port arrow_typeof to datafusion-function
#9524
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
513a5c8
c93a9db
cf2fc53
b1798a8
b6a470f
3dbafa7
6330eae
ca2441b
d005717
53fbe23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // 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 arrow::datatypes::DataType; | ||
| use datafusion_common::{exec_err, Result, ScalarValue}; | ||
| use datafusion_expr::ColumnarValue; | ||
| use datafusion_expr::{ScalarUDFImpl, Signature, Volatility}; | ||
| use std::any::Any; | ||
|
|
||
| #[derive(Debug)] | ||
| pub(super) struct ArrowTypeOfFunc { | ||
| signature: Signature, | ||
| } | ||
|
|
||
| impl ArrowTypeOfFunc { | ||
| pub fn new() -> Self { | ||
| Self { | ||
| signature: Signature::any(1, Volatility::Immutable), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl ScalarUDFImpl for ArrowTypeOfFunc { | ||
| fn as_any(&self) -> &dyn Any { | ||
| self | ||
| } | ||
| fn name(&self) -> &str { | ||
| "arrow_typeof" | ||
| } | ||
|
|
||
| fn signature(&self) -> &Signature { | ||
| &self.signature | ||
| } | ||
|
|
||
| fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> { | ||
| Ok(DataType::Utf8) | ||
| } | ||
|
|
||
| fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> { | ||
| if args.len() != 1 { | ||
| return exec_err!( | ||
| "arrow_typeof function requires 1 arguments, got {}", | ||
| args.len() | ||
| ); | ||
| } | ||
|
|
||
| let input_data_type = args[0].data_type(); | ||
| Ok(ColumnarValue::Scalar(ScalarValue::from(format!( | ||
| "{input_data_type}" | ||
| )))) | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,7 +479,7 @@ CREATE TABLE test( | |
| (3, 30); | ||
|
|
||
| # Scalar function | ||
| statement error Did you mean 'arrow_typeof'? | ||
| statement error Invalid function 'arrowtypeof' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is tracked by #9392 @SteveLauC has a PR up for it #9407 which hopefully will land shortly
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #9407 is ready to go -- I think once we merge that one we can revert this change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| SELECT arrowtypeof(v1) from test; | ||
|
|
||
| # Scalar function | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,7 +31,7 @@ the `arrow_typeof` function. For example: | |
| ```sql | ||
| select arrow_typeof(interval '1 month'); | ||
| +-------------------------------------+ | ||
| | arrowtypeof(IntervalYearMonth("1")) | | ||
| | arrow_typeof(IntervalYearMonth("1")) | | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
| +-------------------------------------+ | ||
| | Interval(YearMonth) | | ||
| +-------------------------------------+ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍