Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-131

Add interfaces for metadata (statistics)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:

      Description

      Metadata is an umbrella term for various kinds of information used about relational expressions during the query-planning process. The most common kinds of metadata are statistics, such as the number of rows or whether a given set of columns uniquely identify a relational expression. But there are other kinds of metadata, and users (i.e. the people writing their own rules and adapters for Optiq) may want to write their own.

      All such metadata is accessed via a `RelMetadataProvider`. There are implementations that find metadata reflectively (by looking for methods with particular signatures), walk a chain of providers, and cache results.

      The metadata request is currently a string (method name) and an array of objects (arguments). This feature would convert the metadata request to an actual method. The method belongs to an interface that extends Metadata. Here is an example user-defined metadata:

      ```java
      public interface ColType extends Metadata

      { String getColType(int column); }

      ```

      The easiest way to implement this interface is using a reflective provider:

      ```java
      public static class ColTypeImpl {
      static final Method METHOD;
      static {
      try

      { METHOD = ColType.class.getMethod("getColType", int.class); }

      catch (NoSuchMethodException e)

      { throw new RuntimeException(e); }

      }

      public static final RelMetadataProvider SOURCE =
      ReflectiveRelMetadataProvider.reflectiveSource(
      METHOD, new ColTypeImpl());

      public String getColType(AggregateRelBase rel, int column)

      { ... }
      public String getColType(RelNode rel, int column) { ... }

      }
      ```

      Then call `RelOptCluster.getMetadataProvider()` to add it.

      User code, accessing the metadata, can use the user's interface and the new `T RelNode.metadata(Class<T>)` method and is type-safe:

      ```
      RelNode rel;
      String colType = rel.metadata(ColType.class);
      ```

      Currently each request to a RelMetadataProvider is passed to all of its sub-providers, an expensive process. We will change this so that RelMetadataProvider.apply(Class<RelNode>, Class<Metadata>) returns a function, or null if it could never supply that metadata. Thus a lot of the sub-providers are eliminated at 'compile time', when acquiring the metadata interface. At run-time probably only one or two providers will be queried. This should yield significant performance improvements, and ease of debugging.

      ---------------- Imported from GitHub ----------------
      Url: https://github.com/julianhyde/optiq/issues/131
      Created by: julianhyde
      Labels:
      Created at: Wed Feb 12 20:58:20 CET 2014
      State: closed

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Unassigned
            Reporter:
            github-import GitHub Import
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development