jacques-n commented on a change in pull request #2603:
URL: https://github.com/apache/calcite/pull/2603#discussion_r747112513



##########
File path: 
core/src/main/java/org/apache/calcite/rel/metadata/lambda/ReflectionToLambdaProvider.java
##########
@@ -0,0 +1,359 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.calcite.rel.metadata.lambda;
+
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.metadata.RelMdAllPredicates;
+import org.apache.calcite.rel.metadata.RelMdCollation;
+import org.apache.calcite.rel.metadata.RelMdColumnOrigins;
+import org.apache.calcite.rel.metadata.RelMdColumnUniqueness;
+import org.apache.calcite.rel.metadata.RelMdDistinctRowCount;
+import org.apache.calcite.rel.metadata.RelMdDistribution;
+import org.apache.calcite.rel.metadata.RelMdExplainVisibility;
+import org.apache.calcite.rel.metadata.RelMdExpressionLineage;
+import org.apache.calcite.rel.metadata.RelMdLowerBoundCost;
+import org.apache.calcite.rel.metadata.RelMdMaxRowCount;
+import org.apache.calcite.rel.metadata.RelMdMemory;
+import org.apache.calcite.rel.metadata.RelMdMinRowCount;
+import org.apache.calcite.rel.metadata.RelMdNodeTypes;
+import org.apache.calcite.rel.metadata.RelMdParallelism;
+import org.apache.calcite.rel.metadata.RelMdPercentageOriginalRows;
+import org.apache.calcite.rel.metadata.RelMdPopulationSize;
+import org.apache.calcite.rel.metadata.RelMdPredicates;
+import org.apache.calcite.rel.metadata.RelMdRowCount;
+import org.apache.calcite.rel.metadata.RelMdSelectivity;
+import org.apache.calcite.rel.metadata.RelMdSize;
+import org.apache.calcite.rel.metadata.RelMdTableReferences;
+import org.apache.calcite.rel.metadata.RelMdUniqueKeys;
+import org.apache.calcite.rel.metadata.RelMetadataQuery;
+import org.apache.calcite.util.BuiltInMethod;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Table;
+import com.google.common.primitives.Primitives;
+
+import java.lang.invoke.CallSite;
+import java.lang.invoke.LambdaMetafactory;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.stream.Collectors;
+import javax.annotation.concurrent.ThreadSafe;
+
+/**
+ * Create a set of lambda handlers via reflection patterns.
+ *
+ * This does reflection to lambda conversion based on a set of singleton 
objects
+ * with appropriate signatures, similar to how ReflectiveRelMetadataProvider 
works.
+ * Any class that can be discovered using ReflectiveRelMetadataProvider should 
also be consumable
+ * using this class. Ultimately, the goal may be to move to direct lambda 
registration as opposed to
+ * the old system of partial reflection discovery.
+ */
+@ThreadSafe
+public class ReflectionToLambdaProvider implements LambdaProvider {
+
+  public static final ImmutableList<Source> DEFAULT_SOURCES = 
ImmutableList.<Source>builder()

Review comment:
       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.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to