All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.org.apache.calcite.rel.metadata.RelMetadataQueryBase Maven / Gradle / Ivy

There is a newer version: 5.4.0
Show newest version
/*
 * 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 com.hazelcast.com.liance with
 * the License.  You may obtain a copy of the License at
 *
 * http://www.apache.com.hazelcast.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 com.hazelcast.org.apache.calcite.rel.metadata;

import com.hazelcast.org.apache.calcite.rel.RelNode;

import com.hazelcast.com.google.com.hazelcast.com.on.collect.HashBasedTable;
import com.hazelcast.com.google.com.hazelcast.com.on.collect.Table;

import java.lang.reflect.Proxy;
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.
 *
 * 

To add a new implementation to this interface, follow * these steps: * *

    *
  1. 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. *
  2. Write your customized provider class RelMdXyz. Follow * the pattern from an existing class such as {@link RelMdColumnOrigins}, * overloading on all of the logical relational expressions to which the query * applies. *
  3. Add a {@code SOURCE} static member to each of your provider class, similar to * {@link RelMdColumnOrigins#SOURCE}. *
  4. 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). *
  5. Set {@code MyRelMetadataProvider} into the cluster instance. *
  6. Use * {@link com.hazelcast.org.apache.calcite.plan.RelOptCluster#setMetadataQuerySupplier(Supplier)} * to set the metadata query {@link Supplier} into the cluster instance. This {@link Supplier} * should return a fresh new instance. *
  7. Use the cluster instance to create * {@link com.hazelcast.org.apache.calcite.sql2rel.SqlToRelConverter}.
  8. *
  9. Query your metadata within {@link com.hazelcast.org.apache.calcite.plan.RelOptRuleCall} with the * interfaces you defined in {@code MyRelMetadataQuery}. *
*/ public class RelMetadataQueryBase { //~ Instance fields -------------------------------------------------------- /** Set of active metadata queries, and cache of previous results. */ public final Table map = HashBasedTable.create(); public final JaninoRelMetadataProvider metadataProvider; //~ Static fields/initializers --------------------------------------------- public static final ThreadLocal THREAD_PROVIDERS = new ThreadLocal<>(); //~ Constructors ----------------------------------------------------------- protected RelMetadataQueryBase(JaninoRelMetadataProvider metadataProvider) { this.metadataProvider = metadataProvider; } protected static H initialHandler(Class handlerClass) { return handlerClass.cast( Proxy.newProxyInstance(RelMetadataQuery.class.getClassLoader(), new Class[] {handlerClass}, (proxy, method, args) -> { final RelNode r = (RelNode) args[0]; throw new JaninoRelMetadataProvider.NoHandler(r.getClass()); })); } //~ Methods ---------------------------------------------------------------- /** Re-generates the handler for a given kind of metadata, adding support for * {@code class_} if it is not already present. */ protected > H revise(Class class_, MetadataDef def) { return metadataProvider.revise(class_, def); } /** * Removes cached metadata values for specified RelNode. * * @param rel RelNode whose cached metadata should be removed * @return true if cache for the provided RelNode was not empty */ public boolean clearCache(RelNode rel) { Map row = map.row(rel); if (row.isEmpty()) { return false; } row.clear(); return true; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy