Add FunctionHandle as abstraction for function resolution#12427
Add FunctionHandle as abstraction for function resolution#12427rongrong merged 8 commits intoprestodb:masterfrom
Conversation
highker
left a comment
There was a problem hiding this comment.
Mostly looks good to me % resolveFunction taking session as a param.
There was a problem hiding this comment.
Add a simple javadoc maybe to explain the rationale of this abstraction.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
/**
* The necessary metadata to represent the trait of a function.
*/There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- the signature of the function (or not?).
- 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.
There was a problem hiding this comment.
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." 😝
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
I insist adding a TODO or javadoc here. At least for others to understand why session is not used at the moment.
There was a problem hiding this comment.
Why suffix here? (not prefix or other parts?)
There was a problem hiding this comment.
it's something like catalog.schema.name so it's the last part of the QualifiedName.
There was a problem hiding this comment.
ok cool. Maybe add a comment to explain.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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")) {`
f860b43 to
8fc9691
Compare
highker
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
hmmmm... Keep one with OperatorType and the other omitted may not be proper?
There was a problem hiding this comment.
lol i removed both in a later version. Just wait.
4e7d225 to
9a797d4
Compare
highker
left a comment
There was a problem hiding this comment.
Reviewed all the commits once again. LGTM.
There was a problem hiding this comment.
I insist adding a TODO or javadoc here. At least for others to understand why session is not used at the moment.
9a797d4 to
1466285
Compare
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.
1466285 to
de71128
Compare
No description provided.