Class ReflectiveRelMetadataProvider

  • All Implemented Interfaces:
    RelMetadataProvider, ReflectiveVisitor

    public class ReflectiveRelMetadataProvider
    extends java.lang.Object
    implements RelMetadataProvider, ReflectiveVisitor
    Implementation of the RelMetadataProvider interface that dispatches metadata methods to methods on a given object via reflection.

    The methods on the target object must be public and non-static, and have the same signature as the implemented metadata method except for an additional first parameter of type RelNode or a sub-class. That parameter gives this provider an indication of that relational expressions it can handle.

    For an example, see RelMdColumnOrigins.SOURCE.

    • Field Detail

      • metadataClass0

        private final java.lang.Class<? extends Metadata> metadataClass0
      • handlerMap

        private final com.google.common.collect.ImmutableMultimap<java.lang.reflect.Method,​MetadataHandler> handlerMap
    • Constructor Detail

      • ReflectiveRelMetadataProvider

        protected ReflectiveRelMetadataProvider​(java.util.concurrent.ConcurrentMap<java.lang.Class<RelNode>,​UnboundMetadata> map,
                                                java.lang.Class<? extends Metadata> metadataClass0,
                                                com.google.common.collect.Multimap<java.lang.reflect.Method,​MetadataHandler> handlerMap)
        Creates a ReflectiveRelMetadataProvider.
        Parameters:
        map - Map
        metadataClass0 - Metadata class
        handlerMap - Methods handled and the objects to call them on
    • Method Detail

      • reflectiveSource

        public static RelMetadataProvider reflectiveSource​(MetadataHandler target,
                                                           java.lang.reflect.Method... methods)
        Returns a reflective metadata provider that implements several methods.
      • reflectiveSource

        private static RelMetadataProvider reflectiveSource​(MetadataHandler target,
                                                            com.google.common.collect.ImmutableList<java.lang.reflect.Method> methods)
      • couldImplement

        private static boolean couldImplement​(java.lang.reflect.Method handlerMethod,
                                              java.lang.reflect.Method method)
      • apply

        public <M extends MetadataUnboundMetadata<M> apply​(java.lang.Class<? extends RelNode> relClass,
                                                             java.lang.Class<? extends M> metadataClass)
        Description copied from interface: RelMetadataProvider
        Retrieves metadata of a particular type and for a particular sub-class of relational expression.

        The object returned is a function. It can be applied to a relational expression of the given type to create a metadata object.

        For example, you might call

         RelMetadataProvider provider;
         LogicalFilter filter;
         RexNode predicate;
         Function<RelNode, Metadata> function =
           provider.apply(LogicalFilter.class, Selectivity.class};
         Selectivity selectivity = function.apply(filter);
         Double d = selectivity.selectivity(predicate);
         
        Specified by:
        apply in interface RelMetadataProvider
        Parameters:
        relClass - Type of relational expression
        metadataClass - Type of metadata
        Returns:
        Function that will field a metadata instance; or null if this provider cannot supply metadata of this type