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

[CALCITE-4882] Introduce new Lambda-based Metadata framework #2603

Closed
wants to merge 1 commit into from

Conversation

jacques-n
Copy link
Contributor

  • Introduce a Lambda-based RelMetadataQuery creator for AOT environments
  • Add new microbenchmark for metadata retrieval on a five-way-join
  • Fix incorrect results for disabled test JdbcTest.testJoinFiveWay()
  • Update jmh-gradle-plugin version.

@jacques-n
Copy link
Contributor Author

jacques-n commented Nov 10, 2021

Working to update RelMetadataTest to be parameterized. (I've run the test locally with a hardcoded change to use the alternative metadata supplier.)

- Introduce a Lambda-based RelMetadataQuery creator for AOT environments
- Add new microbenchmark for metadata retrieval on a five-way-join
- Fix incorrect results for disabled test JdbcTest.testJoinFiveWay()
- Add support for multiple RelMetadataQuery test versions.
- Update jmh-gradle-plugin version.
@jacques-n
Copy link
Contributor Author

Added reuse of RelMetdataTest. Will work on null checker next...

@ThreadSafe
public class ReflectionToLambdaProvider implements LambdaProvider {

public static final ImmutableList<Source> DEFAULT_SOURCES = ImmutableList.<Source>builder()
Copy link
Contributor

Choose a reason for hiding this comment

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

If all handlers were refactored to only have 1 methods, couldn't we drive this off RelMetadataProvider, if a visiter pattern was exposed?

Copy link
Contributor Author

@jacques-n jacques-n Nov 10, 2021

Choose a reason for hiding this comment

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

This is effectively a reimagining of MetadataHandler as a functional interface with a more useful hierarchy/generic definition. Could we convert MetadataHandler to provide this functionality: yes, we probably could.

I haven't spent time trying to untangle the way we would get there. I would expect that it would take many releases to try minimize disruption while slowly converting all the interfaces/impls/etc.

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'll add, in general the whole pattern of arbitrary classes carrying arbitrary methods that name match and arguments kind-of match seems like something that wouldn't translate well to a lambda pattern (which is why the concrete RelNode argument is part of the generic interface definition in this lambda pattern).

Copy link
Contributor

Choose a reason for hiding this comment

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

The Lambda API is leaking the dispatch implementation into the API for binding in custom implementations. These APIs should be separate. It is actually fairly easy to adept this approach to use handlers and not be distributive to down stream projects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you expound on your comments. They are a bit brief.

Lambda API is leaking the dispatch implementation into the API for binding in custom implementations
Please be more specific about what exactly you think is leaking where. I think we may have different perspectives of what functionality is trying to be provided and how. The design here is that the declaration of a specific MetadataLambda implementation gives all the information about what RelNode types it applies to and what metadata it provides. I haven't yet posted the simple provider that simply returns hardcoded lambdas, but that was part of the goal for this design.

It is actually fairly easy to adept this approach to use handlers
I assume you mean adapt. I can see how one could make MetadataLambdas pretend to be handlers with a bunch of boilerplate but I don't see why that is a good idea. What exactly would this buy? Using janino on top of lambdas?

and not be distributive to down stream projects.
I assume you mean disruptive? I don't see how any of these changes are disruptive. This is just an alternative way to create RelMetadataQuery instances and specify metadata (via lambdas).

FYI, I will be updating this patch that to also include my vision for how to handle custom metadata types without any reflection and without excessive subclassing.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is not the purposed end api, then we should not waste too much time discussing this implementation. But just as the API for metadata retrieval should not expose internals, the API for registering metadata implementations. This has not been the case for the previous api.

If your purposed API for this is to register every method the RelNode type instead of discovering them reflectively, then my questions is why do we need some convoluted framework for handling the dispatch instead of just harding coding in the dispatch. Their is pretty much a one to one mapping at that point of the amount of configuration needed compare to explicitly maintaining the implementation.

@vlsi
Copy link
Contributor

vlsi commented Nov 23, 2021

Just wondering, does it have something in common with https://github.com/forax/exotic#structuralcall---javadoc ?

@jacques-n
Copy link
Contributor Author

Just wondering, does it have something in common with https://github.com/forax/exotic#structuralcall---javadoc ?

Similar, but not the same. Here we're using LambdaMetafactory and actually convert the function call to a generic version. Core of that work is here.

@linghengqian
Copy link
Member

I'm curious, what is the reason why this PR is blocked?

@jacques-n
Copy link
Contributor Author

I'm curious, what is the reason why this PR is blocked?

I was waiting for CALCITE-4942 to be resolved since it could potentially substantially reduce the amount of boilerplate and reimplementation in this patch. Note that I did get [ProxyingMetadataHandlerProvider|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/metadata/ProxyingMetadataHandlerProvider.java] which allows one to use metadata without runtime compilation. It isn't fast but at least it is functional in things like GraalVM.

@jamesstarr
Copy link
Contributor

I'm curious, what is the reason why this PR is blocked?

I was waiting for CALCITE-4942 to be resolved since it could potentially substantially reduce the amount of boilerplate and reimplementation in this patch. Note that I did get [ProxyingMetadataHandlerProvider|https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/metadata/ProxyingMetadataHandlerProvider.java] which allows one to use metadata without runtime compilation. It isn't fast but at least it is functional in things like GraalVM.

I thought there was not agreement on how to go forward with CALCITE-4942. From what I recall their was disagreement on wether to expose the lambda implementation classes or to use the ProxyingMetadataHandlerProvider to bridge interfaces between the metadata query and the handler generator.

@jacques-n
Copy link
Contributor Author

I thought there was not agreement on how to go forward with CALCITE-4942

I posted a comment on the JIRA for CALCITE-4942 in late December but never saw a response (afaik).

@jacques-n
Copy link
Contributor Author

Abandoning this work as there was too much contention around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants