Skip to content
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 builders for table function arguments #12350

Merged
merged 1 commit into from
May 13, 2022

Conversation

kasiafi
Copy link
Member

@kasiafi kasiafi commented May 12, 2022

Adds builders for

  • table function argument specifications
  • table function passed arguments

Makes constructors of those classes private.

This is a SPI change. No release notes needed if this change is merged before the upcoming release (the main change has not been yet released)

This change has to be taken into account in the documentation (#12338)

@cla-bot cla-bot bot added the cla-signed label May 12, 2022
@kasiafi kasiafi requested a review from dain May 12, 2022 14:05
}

public DescriptorArgumentSpecification(String name, Descriptor defaultValue)
public static Builder descriptorArgumentBuilder(String name)
Copy link
Member

Choose a reason for hiding this comment

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

I think putting required fields in a builder() constructor kind of defeats of the purposes of a builder, which is readability ("named parameters"). I know we do so in some places, but i don't think we should, especially for code that's written very rarely and read much more often, as the one here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw that pattern in Trino and found it good because it keeps the usage concise. Also, it gives the notion that name is not optional, while the other field is.

Copy link
Member

Choose a reason for hiding this comment

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

You can enforce optionality by throwing in build(). Yet I came ok with SINGLE argument passed to builder() method as we have here.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is enforced anyway by throwing in the DescriptorArgumentSpecification constructor. I wasn't trying here to enforce the semantics, but to convey it clearly to the user of the builder. If you still think that builder shouldn't take name in the constructor, I'll remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Up to me it is fine to have this arg (as stated above) :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@findepi is it acceptable for you to leave the argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

While rebasing, I decided to remove the argument name from the Builder constructor. The code didn't render good that way.


public ScalarArgument build()
{
return new ScalarArgument(type, value);
Copy link
Member

Choose a reason for hiding this comment

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

That looks like a typed value. I wouldn't foresee additional parameters here, and so the builder looks like an overkill

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. At some point, we will allow arbitrary expressions as scalar arguments.

@kasiafi
Copy link
Member Author

kasiafi commented May 13, 2022

Applied or answered all comments. @losipiuk @findepi please take a look and let us decide on the remaining questions. There's another PR pending on this change, and I'm trying to get them both in soon so that we don't have to announce a SPI change in the next release.

@kasiafi kasiafi merged commit 29005a9 into trinodb:master May 13, 2022
@github-actions github-actions bot added this to the 381 milestone May 13, 2022
return this;
}

public Builder pruneWhenEmpty(boolean pruneWhenEmpty)
Copy link
Member

Choose a reason for hiding this comment

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

Generally I prefer boolean methods to have a good default and then a no-arg method to change tha behavior, so I would make this:

public Builder pruneWhenEmpty()
{
    this.pruneWhenEmpty = true;
    return this;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

It was the initial approach. I changed it according to #12350 (comment)

@kasiafi kasiafi mentioned this pull request May 15, 2022
59 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants