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

Improved framework for writing parametric functions #3926

Merged
merged 11 commits into from
Feb 23, 2016

Conversation

cberner
Copy link
Contributor

@cberner cberner commented Nov 9, 2015

No description provided.

@cberner
Copy link
Contributor Author

cberner commented Nov 9, 2015

@haozhun can you take a first look, and then assign to @martint?

martint referenced this pull request in Teradata/presto Nov 16, 2015
SqlScalarFunctionBuilder can be used to define
scalar function with multiple
specialization methods. Specialization method
will be selected based on concrete java type parameters, return type
and optionally predicate. It is also possible to define extra
parameters that will be passed to specialization method.
@losipiuk
Copy link
Contributor

Just general comment. A bit more verbose commit messages, explaining what was changed by the commit and why, would be very appreciated. It is great help for us (external devs) when we read the codebase.

@cberner
Copy link
Contributor Author

cberner commented Dec 5, 2015

Addressed your comments, added some details to the commit message, and also added a section to the Developer Guide. Let me know how that looks!

@cberner cberner force-pushed the parametric branch 3 times, most recently from f8f334d to 0de023d Compare December 8, 2015 06:34
@cberner
Copy link
Contributor Author

cberner commented Dec 8, 2015

Updated to remove ComparableTypeParameter and OrderableTypeParameter. I also added more docs to the developer guide

@cberner
Copy link
Contributor Author

cberner commented Dec 16, 2015

Updated with comments

* ``@TypeParameter``:

The ``@TypeParameter`` annotation is used to declare a type parameter which can
be used in the argument types ``@SqlType`` annotaion, or return type of the function.
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: annotaion

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks!

@cberner
Copy link
Contributor Author

cberner commented Dec 29, 2015

Updated to add support for implementations which are instance methods

return methods.build();
}

private static Implementation parseImplementation(String name, Method method, Constructor<?>[] constructors)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think this function is too long? I considered breaking it up, but because of all the different lists that have to be built it would be difficult to do without having the helper methods use out variables

Copy link
Contributor

Choose a reason for hiding this comment

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

You may consider extracting private, builder-like class ImplementationParser. And then store intermediate state as fields.

Then parseImplementation(...) would look like:

private static Implementation parseImplementation(String name, Method method, Constructor<?>[] constructors) {
    return new ImplementationParser(name, method, constructors).parse();
}

And ImplementatinoParser.parse() would call private mathods of ImplementationParser internally.

I do not find this very elegant - but may be still more readable than functional approach with all the lists passed around from method to method.

@cberner
Copy link
Contributor Author

cberner commented Dec 30, 2015

Refactored to introduce an ImplementationParser to break up the giant parseImplementation method

@haozhun haozhun assigned cberner and unassigned haozhun Feb 1, 2016
@haozhun
Copy link
Contributor

haozhun commented Feb 1, 2016

Looks good to me.

@cberner cberner assigned martint and unassigned cberner Feb 16, 2016
@cberner
Copy link
Contributor Author

cberner commented Feb 16, 2016

@martint are we good to merge this?

martint referenced this pull request in Teradata/presto Feb 22, 2016
SqlScalarFunctionBuilder can be used to define
scalar function with multiple
specialization methods. Specialization method
will be selected based on concrete java type parameters, return type
and optionally predicate. It is also possible to define extra
parameters that will be passed to specialization method.
@martint martint assigned dain and cberner and unassigned martint and dain Feb 22, 2016
@martint
Copy link
Contributor

martint commented Feb 22, 2016

Go for it, but check the travis failures first.

martint referenced this pull request in Teradata/presto Feb 22, 2016
For datatypes with multiple binary representations we need to define
same function multiple times depending on actal types of parameters.

E.g.
  add (Slice a, Slice b)
and
  add (long a, long b)

represent + operator for DECIMAL type. First version for longer DECIMAL
values (represented internally as Slice) and second, faster version for
shorter decimals (represented internally as long).

This patch allows multiple versions of same scalar udf/operator to be
defined using annotation syntax. Functions with same name are grouped
together and exposed as single ParametricFunction which internally does
dispatching to proper MethodHandle based on actual parameter types at
runtime.
@cberner cberner force-pushed the parametric branch 2 times, most recently from 0558fa0 to 2966972 Compare February 22, 2016 20:35
@cberner cberner merged commit d8e011b into prestodb:master Feb 23, 2016
@cberner cberner deleted the parametric branch June 22, 2016 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants