Skip to content

Add FunctionHandle as abstraction for function resolution#12427

Merged
rongrong merged 8 commits intoprestodb:masterfrom
rongrong:function-handle-review
Mar 6, 2019
Merged

Add FunctionHandle as abstraction for function resolution#12427
rongrong merged 8 commits intoprestodb:masterfrom
rongrong:function-handle-review

Conversation

@rongrong
Copy link
Contributor

@rongrong rongrong commented Mar 4, 2019

No description provided.

@rongrong rongrong requested review from hellium01 and highker March 4, 2019 18:45
@highker highker self-assigned this Mar 4, 2019
Copy link

@highker highker left a comment

Choose a reason for hiding this comment

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

Mostly looks good to me % resolveFunction taking session as a param.

Copy link

Choose a reason for hiding this comment

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

Add a simple javadoc maybe to explain the rationale of this abstraction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What should I say? There's no documentation on TableHandle either. I assume once all work are done it should be obvious from code what FunctionHandle is. Maybe commit message is a better place to add some documentation?

Copy link

Choose a reason for hiding this comment

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

/**
 * The necessary metadata to represent the trait of a function.
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Metadata will be a different class. This is just the handle. Eventually this should be something like the TableHandle which is an interface with no methods. And it's up to the function namespace to decide what's the metadata, etc.

Copy link
Contributor

@hellium01 hellium01 Mar 5, 2019

Choose a reason for hiding this comment

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

How about:

/**
 * FunctionHandle is the unique handle to identify a function implementation in all  
 * namespaces.
 */

My understanding is even though FunctionHandle doesn't have to have any detail but we still need to be able to uniquely identify a function by:

  1. the signature of the function (or not?).
  2. which namespace it belong to (or maybe SqlPath?). We probably don't have to know how to make it unique within a namespace.

Then I guess that means we have to have something similar to ConnectorTableHandle for plugin(or namespace to know which function is it)? But that's not the scope of this PR anyway.

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 guess the problem is if we actually want FunctionHandle to behave like TableHandle, FunctionHandle should be an interface, and you should have SystemFunctionHandle, HiveFunctionHandle, etc, as the actual classes, etc. Currently that's not what FunctionHandle look like. I added a comment to the commit message. I can add a comment here if you guys want. You might also want to add a comment when you move this to SPI to say "Will likely be changed in the next few releases, think twice when you introduce dependencies." 😝

Copy link

Choose a reason for hiding this comment

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

session is not used. Also, I think we explicitly disallow user to specify what functions to use through session properties (with the exception of some legacy behaviors like array_agg). All SQL functions do not have access to full session properties today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's introduced in @dain's original PR: trinodb/trino@7915b62. A technical reason to add it now (even it's not used) is otherwise the two resolveFunction would have exactly the same signature. Though I don't think we will give SQL functions access to session, I think session will just be used to resolve which function to use, so it will only be used within FunctionManager/FunctionNamespace.

Copy link
Contributor

Choose a reason for hiding this comment

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

SqlPath maybe more favorable here. Since we are not using Session(or SqlPath) at the moment anyway, this may as well be just an interface?

Copy link

Choose a reason for hiding this comment

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

I insist adding a TODO or javadoc here. At least for others to understand why session is not used at the moment.

Copy link

Choose a reason for hiding this comment

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

Why suffix here? (not prefix or other parts?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's something like catalog.schema.name so it's the last part of the QualifiedName.

Copy link

Choose a reason for hiding this comment

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

ok cool. Maybe add a comment to explain.

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 don't think this needs a comment. It's based on the pretty much the definition of QualifiedName. There's nothing special or unexpected. In general I don't think we add comment unless there's something the code itself doesn't explain or doesn't make sense.

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 with RongRong here, since it is a nameHint, it is quite self explaining why we just use the last part. But to make it more clear, maybe rename it to nameHintForFunction (or not, should be fine for both)?

Copy link

Choose a reason for hiding this comment

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

newline after this line

Copy link

Choose a reason for hiding this comment

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

Even the original statement is with two line; but we can squeeze them into one in this case:

if (functionName.equals("count") || functionName.equals("count_if") || functionName.equals("approx_distinct")) {`

@rongrong rongrong force-pushed the function-handle-review branch from f860b43 to 8fc9691 Compare March 5, 2019 00:19
Copy link

@highker highker left a comment

Choose a reason for hiding this comment

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

Finished the last 3 commits. Overall looks good to me. I will take another pass once we have decided what to do with the session parameter.

Copy link

Choose a reason for hiding this comment

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

hmmmm... Keep one with OperatorType and the other omitted may not be proper?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol i removed both in a later version. Just wait.

Copy link

Choose a reason for hiding this comment

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

operatorHandle

@rongrong rongrong force-pushed the function-handle-review branch 2 times, most recently from 4e7d225 to 9a797d4 Compare March 5, 2019 06:07
Copy link

@highker highker left a comment

Choose a reason for hiding this comment

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

Reviewed all the commits once again. LGTM.

Copy link

Choose a reason for hiding this comment

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

I insist adding a TODO or javadoc here. At least for others to understand why session is not used at the moment.

@highker highker assigned rongrong and unassigned highker Mar 6, 2019
@rongrong rongrong force-pushed the function-handle-review branch from 9a797d4 to 1466285 Compare March 6, 2019 17:36
rongrong added 8 commits March 6, 2019 10:59
Add FunctionHandle abstraction. Eventually FunctionHandle should function similarly
to TableHandle, as an abstraction, with implementation details decided by FunctionNamespace.
Right now this is just a wrapper on Signature to enable further refactor.
@rongrong rongrong force-pushed the function-handle-review branch from 1466285 to de71128 Compare March 6, 2019 19:00
@rongrong rongrong closed this Mar 6, 2019
@rongrong rongrong deleted the function-handle-review branch March 6, 2019 20:00
@rongrong rongrong merged commit de71128 into prestodb:master Mar 6, 2019
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.

4 participants