-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
'Rename array()
function to make_array()
, extend array[]
#3122
Conversation
5dd736e
to
a882e34
Compare
a882e34
to
65ab517
Compare
/// Create an array of FixedSizeList from a set of individual Arrays | ||
/// where each element in the output FixedSizeList is the result of | ||
/// concatenating the corresponding values in the input Arrays | ||
macro_rules! make_fixed_size_list { |
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.
I renamed this to be more descriptive of what it does (there are too may arrays in DataFusion already ;)
"| [aaa, 3] |", | ||
"+--------------------------------------+", | ||
"+----------+", | ||
"| array |", |
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.
using array
for the column name is consistent with postgres
@@ -111,8 +111,8 @@ async fn query_concat() -> Result<()> { | |||
Ok(()) | |||
} | |||
|
|||
#[tokio::test] | |||
async fn query_array() -> Result<()> { | |||
// Return a session context with table "test" registered with 2 columns |
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.
The changes in this file illustrate the change in behavior that this PR makes
#[tokio::test] | ||
async fn query_array() { | ||
let ctx = array_context(); | ||
let sql = "SELECT array[c1, cast(c2 as varchar)] FROM test"; |
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.
Prior to this PR, this query would error (only constants were supported in array[]
syntax. cc @ovr
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.
👍
async fn query_make_array_scalar() { | ||
let ctx = SessionContext::new(); | ||
|
||
let sql = "SELECT make_array(1, 2, 3);"; |
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.
This is the equivalent of SELECT array(1,2, 3)
on master
array_expressions::SUPPORTED_ARRAY_TYPES.to_vec(), | ||
fun.volatility(), | ||
), | ||
BuiltinScalarFunction::MakeArray => Signature::variadic_equal(fun.volatility()), |
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.
This requires all arguments to make_array
be the same type
/// Create an array of FixedSizeList from a set of individual Arrays | ||
/// where each element in the output FixedSizeList is the result of | ||
/// concatenating the corresponding values in the input Arrays | ||
macro_rules! make_fixed_size_list { |
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.
I simply renamed this macro to something that shows more of what it is doing
} | ||
let fun = BuiltinScalarFunction::MakeArray; | ||
// follow postgres convention and name result "array" | ||
Ok(Expr::ScalarFunction { fun, args }.alias("array")) |
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.
This is the rewrite in the planner to write array[]
syntax to a make_array
function call
// HashSet doesn't guarantee order | ||
assert_contains!( | ||
err.to_string(), | ||
r#"Arrays with different types are not supported: "# |
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.
this test is moved to function.rs
65ab517
to
23845c8
Compare
@alamb I believe this is the next PR in line to be merged into |
Never mind. These changes are not required in order to upgrade. |
Update on this PR: I think I may have gotten too ambitious in this PR: Maybe we can just settle for updating the name of the |
I went ahead and created a PR just to do the rename: #3199 |
Thanks @andygrove -- I am going to abandon this PR for now. I learned a lot but I don't have time to figure out the implementation details of ListArrays more ;) |
Draft until:array
test #3121Which issue does this PR close?
Closes #3115
Closes #3123
Rationale for this change
The core rationale is that this change is needed to support the next release of sqlparser-rs (which includes apache/datafusion-sqlparser-rs#566) which makes it impossible to use
array
as a functionMore details here: apache/datafusion-sqlparser-rs#566 (comment)
The
array()
function is Spark syntax.Postgres syntax is
array[]
and postgres actually treats thearray
keyword specially (it can not be used as a function)What changes are included in this PR?
array()
tomake_array()
(so it doesn't conflict with postgres)array[]
call make_array forarray[]
syntaxmake_array
andarray[]
be the same type (as arrays have a single type for all elements)Are there any user-facing changes?
array()
is now writtenmake_array()
array[]
supports columns rather than just constants (e.g.array[column, column, ..]
now works)make_array()
will error if the types are not exactly the same