Cube Logo0.33.4

Syntax

Entities within the data model (e.g., cubes, views, etc.) should be placed under the model folder, follow naming conventions, and be defined using a supported syntax.

Data model files should be placed inside the model folder. You can use the schemaPath configuration option to override the folder name or the repositoryFactory configuration option to dynamically define the folder name and data model file contents.

It's recommended to place each cube or view in a separate file, in model/cubes and model/views folders, respectively. Example:

model
├── cubes
├── orders.yml
├── products.yml
└── users.yml
└── views
    └── revenue.yml

Common rules apply to names of entities within the data model. All names must:

  • start with a letter
  • consist of letters, numbers, and underscore (_) symbols only

It is also recommended that names use snake case.

Good examples of names:

  • orders, stripe_invoices, or base_payments (cubes)
  • opportunities, cloud_accounts, or arr (views)
  • count, avg_price, or total_amount_shipped (measures)
  • name, is_shipped, or created_at (dimensions)
  • main, orders_by_status, or lambda_invoices (pre-aggregations)

Cube supports two ways to define data model files: with YAML or JavaScript syntax.

YAML syntax is supported since v0.31.0.

YAML data model files should have the .yml extension, whereas JavaScript data model files should end with .js.

It's recommended to use YAML syntax by default. Opt to JavaScript syntax when you need to have a dynamic data model.

YAML
JS
cubes:
  - name: orders
    sql: >
      SELECT * FROM orders, line_items WHERE orders.id = line_items.order_id

Syntax comparison

YAML syntax is very similar to JavaScript syntax, with a few key differences:

  • In YAML syntax, cubes, views, and context variables should be wrapped in {}, e.g., {FILTER_PARAMS.orders.created_at.filter('created_at')}.
  • In YAML syntax, string values only need to have quotes around them if they contain special values, e.g., "{CUBE}.user_id = {users.id}". Special values include references to CUBE and other declared cubes, FILTER_PARAMS, COMPILE_CONTEXT, and SECURITY_CONTEXT.

Did you find this page useful?