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

User-defined table macros

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None

    Description

      A table macro is a function that gets executed at prepare time and that generates a relational expression. It can have arguments, as long as those arguments are constants. Views are a special case of table macros - they have no arguments, so can be invoked using the same syntax as regular tables.

      Table macros can be registered programmatically, using `Schema.add(String name, Function function)`, where function implements `TableMacro`.

      Or they can be declared in the schema, using a class that has an `eval` method (static or non-static) declared to return `Table` or a subclass, and that actually return an object that implements `TranslatableTable`. Like this:

      ```json
      {
      version: '1.0',
      schemas: [
      {
      name: 'ADHOC',
      functions: [

      { name: 'MAC', className: 'com.example.MyTableMacro' }

      ]
      }
      ]
      }
      ```

      ```java
      public class MyTableMacro {
      public Table eval(String s) {
      return new TranslatableTable()

      { ... }

      ;
      }
      }
      ```

      ```sql
      SELECT * FROM TABLE(adhoc.mac('a string'));
      ```

      ---------------- Imported from GitHub ----------------
      Url: https://github.com/julianhyde/optiq/issues/222
      Created by: julianhyde
      Labels:
      Created at: Wed Apr 02 08:15:22 CEST 2014
      State: closed

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: