-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for array_to_string and array_to_string_null array functions #4171
Conversation
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.
Thanks for opening this PR. It looks like a first step in the right direction. It's definitively a good job for your first PR 👍
I've left a few comments that hopefully should help to address the test failures and I also added some suggestions on how to improve the code.
I also resolved the merge conflict caused by merging some other PR's, so be sure to pull the changes before continuing to work on this PR.
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
fn array_to_string_null<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( |
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.
fn array_to_string_null<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( | |
#[sql_name = "array_to_string"] | |
fn array_to_string_null<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( |
as otherwise no sql function with that name exists
Also what's about naming this function: array_to_string_with_null_string
?
fn array_to_string_null<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( | ||
arr: Arr, | ||
delim: Text, | ||
null_str: Nullable<Text> |
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.
null_str: Nullable<Text> | |
null_str: Text |
As we want to require that optional argument here
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
fn array_to_string<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( |
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 bound can be simplified to
fn array_to_string<Arr: ArrayOrNullableArray<Inner=Elem> + SingleValue, Elem: SingleValue>( | |
fn array_to_string<Arr: ArrayOrNullableArray>( |
We don't use Elem
anywhere.
Will look at the fails, |
/// Converts each array element to its text representation, and concatenates those separated by the delimiter string. | ||
/// This variant omits the `null_str` argument. | ||
/// This variant omits the `null_str` argument. See [array_to_string_null] for a variant with that argument |
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.
As you rename this function, new name should be used:
/// This variant omits the `null_str` argument. See [array_to_string_null] for a variant with that argument | |
/// This variant omits the `null_str` argument. See [`array_to_string_with_null_string`] for a variant with that argument |
Need some help I think... I'm a bit stuck and banging my head against a wall at this point, @weiznich can you please review and try to point me in the right direction? |
I'm away for a few days. I will have a look as soon as I'm back. |
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.
Thanks for updating this PR. I've left a few comments that should help to explain how to proceed with this. If something is still unclear do not hesitate to ask for more details. It's sometimes hard for me to get the level of detail for information included in such comments correct.
fn array_to_string<Arr: ArrayOrNullableArray<Inner=Nullable<Text>> + SingleValue, T: SingleValue>( | ||
a: Arr, | ||
e: T | ||
) -> Text; |
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.
fn array_to_string<Arr: ArrayOrNullableArray<Inner=Nullable<Text>> + SingleValue, T: SingleValue>( | |
a: Arr, | |
e: T | |
) -> Text; | |
fn array_to_string<Arr: ArrayOrNullableArray +SingleValue>(array: Arr, del: Text)) -> Text; |
We do not need to make this function generic over the type of del
here, as we only want to accept anything that is compatible with Text
there. Therefore we can just write the sql side type (Text
) there and do not need to care about generics.
Also we want to accept any array type there, not only arrays of the type Text
, which means we do not care about the Inner
associated type here.
fn array_to_string_with_null_string<Arr: ArrayOrNullableArray<Inner=Nullable<Text>> + SingleValue, T: SingleValue, N: SingleValue>( | ||
a: Arr, | ||
e: T, | ||
n: N | ||
) -> Text; |
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.
fn array_to_string_with_null_string<Arr: ArrayOrNullableArray<Inner=Nullable<Text>> + SingleValue, T: SingleValue, N: SingleValue>( | |
a: Arr, | |
e: T, | |
n: N | |
) -> Text; | |
#[sql_name = "array_to_string"] | |
fn array_to_string_with_null_string<Arr: ArrayOrNullableArray + SingleValue>(array: Arr, del: Text, null: Text) -> Text; |
For similar reasons as outlined for the array_to_string
function. The #[sql_name]
attribute is required to use the right sql function name in the generated sql
@weiznich Need to resolve these merge conflicts though, its my bad 😢 |
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.
Thanks for the update, looks good now 👍
I've just done another merge as merge conflicts currently appear faster than they can be resolved. (No worries about that, it's just that a lot of PR's touch the same code)
Attempt to achieve
array_to_string
function for postgres listed in Issue #4153 https://www.postgresql.org/docs/current/functions-array.htmlSince it contained atleast one one optional argument of type
Nullable<Text>
I've defined two separate variantsarray_to_string_null
andarray_to_string
as per recommendation.First PR here and first PR ever to open source so feel free to be harsh if this does not achieve intended goals as I understood them or does not follow best practices, open to suggestions.