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

Create view based on LookML model

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Create a view based on LookML model (more specifically, based on an explore in a LookML model).

      Note: I have no plans to implement this in open source, but it's helpful to set out the requirements.

      For example, the following statement using the LOOKML_VIEW table function

      CREATE VIEW OrdersCube AS
      SELECT *
      FROM TABLE LOOKML_VIEW('orders', '
      model: model_name {
        view: orders {
          sql: SELECT * FROM orders ;;
          dimension: id {
            primary_key: yes
            type: number
          }
          dimension_group: created {
            type: time
            timeframes: [time, date, week, month]
            sql: created_at;;
          }
          dimension: amount {
            type: number
            value_format: “0.00”
          }
          measure: count
          measure: total_amount {
            type: sum
            sql: amount ;;
          }
        }
        view: customers {
          sql_table_name: customers
          label: “Customer”
          dimension: id {
            primary_key: yes
          }
          dimension: zipcode
          dimension: state
        }
        explore: orders {
          from: orders
          join: customers {
            sql_on: customers.id = orders.customer_id ;;
          }
        }
      }');
      

      is equivalent to the following:

      CREATE VIEW OrdersCube AS
      SELECT *
      FROM (
        SELECT `orders.id`, // PK
            `orders.customer_id`,
            TIME(created_at) AS `orders.created_time`,
            DATE(created_at) AS `orders.created_date`,
            WEEK(created_at) AS `orders.created_week`,
            MONTH(created_at) AS `orders.created_month`,
            amount AS `orders.amount`, // value_format: “0.00”
            COUNT(*) AS MEASURE `orders.count`,
            SUM(amount) AS MEASURE `orders.total_amount`
        FROM orders) AS orders
      JOIN (
        SELECT id AS `customers.id`, // PK
            zip_code AS `customers.zip_code`,
            state AS `customers.state`
        FROM customers) AS customers // label: “Customer”
      ON `customers.id` = `orders.customer_id`;
      

      On these views we can execute queries that use the measures, for example

      SELECT `customers.state`,
          AGGREGATE(`orders.total_amount`)
      FROM OrdersCube
      WHERE `orders.created_year` = 2023
      GROUP BY `customers.state`
      ORDER BY 2 DESC LIMIT 5
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              julianhyde Julian Hyde
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: