Repository navigation
Implementing math power function for SQL - #2324
Conversation
|
Implement math POWER function with signatures like https://www.postgresql.org/docs/14/functions-math.html Example usage Output |
| }), | ||
|
|
||
| BuiltinScalarFunction::Power => match &input_expr_types[0] { | ||
| DataType::Int32 | DataType::Int64 => Ok(DataType::Int64), |
There was a problem hiding this comment.
what about Int8,Int16, UInt....
There was a problem hiding this comment.
Now its changed to be like in https://www.postgresql.org/docs/14/functions-math.html
So the signature is either i64 or f64.
If user column is another col type with less size like i32, f32, i16, etc it will work, however the return type is i64 or f64.
Let me know if this is ok
|
Hi @Ted-Jiang @xudong963, can you please review again, I'm looking forward to commence to other datafusion tasks |
| vec![ | ||
| TypeSignature::Exact(vec![DataType::Int64, DataType::Int64]), | ||
| TypeSignature::Exact(vec![DataType::Float64, DataType::Float64]), | ||
| ], |
There was a problem hiding this comment.
It appears that postgres supports dp (aka double precision, aka Float64) and Numeric
I think for the initial implementation it would be fine to support Int64 as well, but longer term we should add coercion rules to convert arguments to Float64 before they are actually passed to power
| arg1.iter() | ||
| .zip(arg2.iter()) | ||
| .map(|(a1, a2)| match (a1, a2) { | ||
| (Some(a1), Some(a2)) => Some($FUNC(a1, a2.try_into().unwrap())), |
There was a problem hiding this comment.
I wonder if .unwrap() is needed here -- it will cause a panic if the argument can't be converted to whatever $FUNC wants
Does it work if you do
| (Some(a1), Some(a2)) => Some($FUNC(a1, a2.try_into().unwrap())), | |
| (Some(a1), Some(a2)) => Some($FUNC(a1, a2.try_into()?)), |
Instead?
There was a problem hiding this comment.
I came up with (Some(a1), Some(a2)) => Some($FUNC(a1, a2.try_into().ok()?)),
| let ctx = SessionContext::new(); | ||
| ctx.register_table("test", Arc::new(table))?; | ||
| let sql = r"SELECT power(i32, 3) as power_i32, | ||
| power(i64, 3) as power_i64, |
There was a problem hiding this comment.
A test that takes two columns in addition to a column and a scalar would also be good -- like power(i64, i64) perhaps
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn case_sensitive_identifiers_aggregates() { |
There was a problem hiding this comment.
I still think this test is accidentally included in this PR. It currently exists in aggregates.rs:
There was a problem hiding this comment.
Fixed, probably a merge issue. Tried to be in sync with fast changing files
|
Thanks again all! |
* Implementing POWER function * Delete pv.yaml * Delete build-ballista-docker.sh * Delete ballista.dockerfile * aligining with latest upstream changes * Readding docker files * Formatting * Leaving only 64bit types * Adding tests, remove type conversion * fix for cast * Update functions.rs (cherry picked from commit c3c02cf) Can drop this after rebase on commit c3c02cf "Implementing math power function for SQL (apache#2324)", first released in 8.0.0 # Conflicts: # datafusion/core/src/logical_plan/mod.rs # datafusion/core/src/physical_plan/functions.rs # datafusion/core/tests/sql/functions.rs # datafusion/cube_ext/Cargo.toml # datafusion/expr/src/built_in_function.rs # datafusion/expr/src/function.rs # datafusion/proto/proto/datafusion.proto # datafusion/proto/src/from_proto.rs # datafusion/proto/src/to_proto.rs # dev/docker/ballista.dockerfile
* Implementing POWER function * Delete pv.yaml * Delete build-ballista-docker.sh * Delete ballista.dockerfile * aligining with latest upstream changes * Readding docker files * Formatting * Leaving only 64bit types * Adding tests, remove type conversion * fix for cast * Update functions.rs (cherry picked from commit c3c02cf) Can drop this after rebase on commit c3c02cf "Implementing math power function for SQL (apache#2324)", first released in 8.0.0 # Conflicts: # datafusion/core/src/logical_plan/mod.rs # datafusion/core/src/physical_plan/functions.rs # datafusion/core/tests/sql/functions.rs # datafusion/cube_ext/Cargo.toml # datafusion/expr/src/built_in_function.rs # datafusion/expr/src/function.rs # datafusion/proto/proto/datafusion.proto # datafusion/proto/src/from_proto.rs # datafusion/proto/src/to_proto.rs # dev/docker/ballista.dockerfile
Which issue does this PR close?
Closes #1493
Rationale for this change
Implementing power function for SQL
What changes are included in this PR?
Implementing power function for SQL
Are there any user-facing changes?
User can use math POWER function in SQL statements