Skip to content

Conversation

@ozankabak
Copy link
Contributor

Which issue does this PR close?

Takes a first step at addressing this concern.

Rationale for this change

Function signatures involving types related to expression ordering are starting to get overly verbose/complex. We would like to have simpler types/function signatures for readability and maintainability reasons.

What changes are included in this PR?

We are introducing the following aliases:

pub type ExprOrdering = Vec<PhysicalSortExpr>;
pub type ExprOrderingRef<'a> = &'a [PhysicalSortExpr];
pub type OrderingRequirement = Vec<PhysicalSortRequirement>;

to simplify function signatures. If these aliases don't suffice in the future and we decide to use full-fledged types for this purpose, this PR will serve as a first step in that refactoring too.

Are these changes tested?

Yes, all existing tests pass.

Are there any user-facing changes?

Yes and no. Type-wise, nothing has changed (as these are type aliases). But a cursory look at traits and function signatures may give the impression that they have changed.

@github-actions github-actions bot added core Core DataFusion crate physical-expr Changes to the physical-expr crates labels Apr 4, 2023
Comment on lines +119 to +121
pub type ExprOrdering = Vec<PhysicalSortExpr>;
pub type ExprOrderingRef<'a> = &'a [PhysicalSortExpr];
pub type OrderingRequirement = Vec<PhysicalSortRequirement>;
Copy link
Contributor

Choose a reason for hiding this comment

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

While these do simplify the signatures, I am a little worried about just adding a type signature without additional supporting documentation.

If we are going to change the signatures again what do you think about going all the way and actually making structures

struct ExprOrdering {
  exprs: Vec<PhysicalSortExpr>;
}

And then make functions like (with documentation):

impl ExprOrdering {
  fn new (exprs: Vec<PhysicalSortExpr>) -> Self {.._

  fn from_requirements(requirements: OrderingRequirement -> Self {..}
}

For example, here is a PR that tries to encapsulate more of the PhysicalSortRequirements along with a bunch of docs: #5863

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried a refactor using full-fledged types but the resulting changes were more involved/time-consuming, so I opted to go with aliases until we know there are concrete use cases requiring multiple attributes in types such as ExprOrdering.

I see two options:

I am OK with both, up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

I tried a refactor using full-fledged types but the resulting changes were more involved/time-consuming, so I opted to go with aliases until we know there are concrete use cases requiring multiple attributes in types such as ExprOrdering.

This makes sense -- thank you for trying. It definitely took me far more time to make #5863 than I expected -- mostly to come up with coherent description of what the structures did.

We can just merge #5863 and defer/revisit this kind of a refactor when we have a real use case for multiple fields in types such as ExprOrdering.

I think this is my preference for the moment. Let's wait to see if anyone else has comments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mingmwang, what do you think? Any preference on your side?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will close this for now, we can revisit this issue in the future if we like.

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.

Thank you @ozankabak -- I appreciate your attention to trying to make the code easier to work with

@ozankabak ozankabak closed this Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants