Skip to content

Conversation

@Blizzara
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

While calling with_alias on MakeArray, we noticed some weird type failures:

Error: Error(Inner { cause: Context("type_coercion", Plan("Coercion from [Int32, Int32, Int32] to the signature OneOf([UserDefined, Any(0)]) failed.

That turned out to be because the AliasedScalarUDFImpl doesn't implement coerce_types, so instead of using MakeArray::coerce_types we'd end up using the default implementation of ScalarUDFImpl which just throws (that throw is then ignored later on, making this a bit hard to debug).

What changes are included in this PR?

Implement the full set of functions in Aliased[Scalar/Aggregate/Window]FunctionUDFImpl to pass through to inner UDF.

Are these changes tested?

No.. any ideas on how to smartly test these? I can add a simple test for the case we hit somewhere, but is there any generic way of guaranteeing that the aliased versions re-implement all of the *UDFImpl methods?

Are there any user-facing changes?

Mostly just fixes

/// requirement aggregators return `Ok(None)`.
fn with_beneficial_ordering(
self: Arc<Self>,
&self,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Arc<Self> was hard to call from the aliased version. Is there a reason why it was Arc'd?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is that passing through the &Arc allows the result to be created without a deep copy., though maybe it is being overly optimized 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, dunno if there is a difference between passing an Arc and &self perf wise - neither should require copy. But I got it work with the Arc<> (by adding a .clone() there, but that should only clone the pointer and not the self so I think that's fine as well), so then I don't need to change this and that's probably safer 😅

fixed in 33b89ce

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the Arc in the API is wonky -- it definitely might be better to remove it. Thank you for considering doing so in a follow on PR

@github-actions github-actions bot added logical-expr Logical plan and expressions functions Changes to functions implementation labels Aug 21, 2024
@Blizzara Blizzara marked this pull request as ready for review August 21, 2024 14:11
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thanks @Blizzara -- the only question I have is related to the change of the Arc in the trait.

Perhaps we can contemplate that change as a separate PR so we can merge this one in?

/// requirement aggregators return `Ok(None)`.
fn with_beneficial_ordering(
self: Arc<Self>,
&self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea is that passing through the &Arc allows the result to be created without a deep copy., though maybe it is being overly optimized 🤔

&self.aliases
}

fn state_fields(&self, args: StateFieldsArgs) -> Result<Vec<Field>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice - to avoid similar bugs in the future maybe we should also add a comment to AggregateUDFImpl that tries to remind people to add an implementation here.

It would be cool if we could tell Rust not to create a default implementation for a particular impl so the compiler could do the check for us, but I don't know how to express that in Rust

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added notes in 175b8d2. And yep - it would be nice to have a way of enforcing this, but I also couldn't figure out any way to do that :/

@github-actions github-actions bot removed the functions Changes to functions implementation label Aug 22, 2024
@alamb
Copy link
Contributor

alamb commented Aug 22, 2024

I took the liberty of pushing a commit to flx clippy

@alamb
Copy link
Contributor

alamb commented Aug 22, 2024

Compilation is failing due to #12108

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thanks @Blizzara

@alamb alamb merged commit 502ce4b into apache:main Aug 22, 2024
@Blizzara Blizzara deleted the avo/with-alias branch August 22, 2024 13:43
@Blizzara
Copy link
Contributor Author

Looks good to me -- thanks @Blizzara

Thanks for the review, fixing clippy, and fixing main! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants