danny0405 commented on a change in pull request #1533: [CALCITE-3446] Make 
RelMetadataQuery extensible
URL: https://github.com/apache/calcite/pull/1533#discussion_r339863234
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/rel/metadata/AbstractRelMetadataQuery.java
 ##########
 @@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import org.apache.calcite.rel.RelNode;
+
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Supplier;
+
+/**
+ * Base class for the RelMetadataQuery that uses the metadata handler class
+ * generated by the Janino.
+ *
+ * <p>To add a new implementation to this interface, follow
+ * these steps:
+ *
+ * <ol>
+ * <li>Extends {@link RelMetadataQuery} (name it MyRelMetadataQuery for 
example)
+ * to reuse the Calcite builtin metadata query interfaces. In this class, 
define all the
+ * extended Handlers for your metadata and implement the metadata query 
interfaces.
+ * <li>Write your customized provider class <code>RelMdXyz</code>. Follow
+ * the pattern from an existing class such as {@link RelMdColumnOrigins},
+ * overloading on all of the logical relational expressions to which the query
+ * applies.
+ * <li>Add a {@code SOURCE} static member to each of your provider class, 
similar to
+ * {@link RelMdColumnOrigins#SOURCE}.
+ * <li>Extends {@link DefaultRelMetadataProvider} (name it 
MyRelMetadataProvider for example)
+ * and supplement the "SOURCE"s into the builtin list
+ * (This is not required, use {@link ChainedRelMetadataProvider} to chain your 
customized
+ * "SOURCE"s with default ones also works).
+ * <li>Set {@code MyRelMetadataProvider} into the cluster instance.
+ * <li>Use
+ * {@link org.apache.calcite.plan.RelOptCluster#setMetadataQuery(Supplier)}
+ * to set the metadata query {@link Supplier} into the cluster instance. This 
{@link Supplier}
+ * should return a <strong>fresh new</strong> instance.
+ * <li>Use the cluster instance to create
+ * {@link org.apache.calcite.sql2rel.SqlToRelConverter}.</li>
+ * <li>Query your metadata within {@link 
org.apache.calcite.plan.RelOptRuleCall} with the
+ * interfaces you defined in {@code MyRelMetadataQuery}.
+ * </ol>
+ */
+public class AbstractRelMetadataQuery {
 
 Review comment:
   I agree with Julian's suggestion:
   
   > Perhaps split RelMetadataQuery into a base class (containing the essential 
mechanism) and a derived class (containing the handlers and methods for each 
kind of built-in metadata). It will be interesting to see which code needs the 
derived class and how which code needs only the base class.
   
   Split out a base class here make all the sub-class more clear, they only 
needs to handle all the `Handler`s and define the metadata interfaces.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to