Skip to content

Latest commit

 

History

History
144 lines (98 loc) · 9.45 KB

File metadata and controls

144 lines (98 loc) · 9.45 KB

sml-models-tasty-bytes

This repository contains the Tasty Bytes sample, packaged as a Semantic Modeling Language (SML) model that is the structural equivalent of the Snowflake TASTY_BYTES_SVA Semantic View. The same conceptual model — the food-truck business of the fictional "Tasty Bytes" company — is presented two ways:

  1. As a Snowflake Semantic View defined in SQL.
  2. As an SML model (datasets, dimensions, metrics, relationships, and a top-level model file) that can be deployed to a semantic layer such as AtScale.

The goal is to provide a side-by-side reference for teams migrating Snowflake Semantic Views into SML, or evaluating how the two representations relate to one another.


About the Snowflake Tasty Bytes sample

The Tasty Bytes story and dataset come from the official Snowflake tutorial:

Tutorial: Tasty Bytes — Sample data and the Snowflake SQL Worksheet

Tasty Bytes models a global food-truck company. The data covers customers, franchises, menus, individual food trucks, locations they operate at, and the order line items they sell. It is widely used by Snowflake as a teaching dataset for SQL, semantic views, and Cortex Analyst.

The version of the dataset in this repo is a Summit 2026 variant of that tutorial sample; it includes additional supporting tables (campaigns, menu tags, ingredients) and the Power BI–compatible views needed to back a Snowflake Semantic View.


Repository contents

assets/                Snowflake setup script (DDL + INSERTs + Semantic View)
connections/           SML connection definition pointing at SUMMIT_2026.TASTY_BYTES
datasets/              SML datasets — one per source table/view
dimensions/            SML dimensions (with hierarchies and levels)
metrics/               SML measures (sums, distinct counts)
calculations/          SML calculated measures (e.g. AVG_ORDER_VALUE)
models/                SML model file that wires everything together
catalog.yml            SML catalog definition
README.md              This file

The Snowflake source: assets/setup_tasty_bytes.sql

setup_tasty_bytes.sql is a self-contained Snowflake script. Running it in any Snowflake account will:

  1. Create the database and schemas

    • Database SUMMIT_2026
    • Schemas SUMMIT_2026.TASTY_BYTES (base tables) and SUMMIT_2026.TASTY_BYTES_DEV (mirror views)
  2. Create and populate the base tables in SUMMIT_2026.TASTY_BYTES:

    Table Description
    CAMPAIGN Marketing campaigns with type, channel, target item, budget and date window
    CAMPAIGN_PERFORMANCE Daily impressions, clicks, conversions, spend and attributed revenue per campaign
    CUSTOMER Customer demographic and contact details
    DATE_DIM Calendar date dimension
    DIM_TIME Sub-daily time-of-day dimension (hour / minute / second / AM-PM)
    FRANCHISE Franchise owners and locations
    INGREDIENT Ingredient master list
    LOCATION Physical locations where trucks operate (city / region / country)
    MENU_CATEGORY Menu category lookup
    MENU_ITEM Menu items with category, pricing, COGS and dietary flags
    MENU_ITEM_INGREDIENTS Item ↔ ingredient mapping
    MENU_ITEM_TAGS Item ↔ tag mapping
    MENU_TYPE Menu type / cuisine style
    ORDER_DETAIL Order line items — the central fact table
    TAG Tag master list
    TRUCK Individual food trucks, with make, model, year, franchise affiliation and EV flag
  3. Create mirror views in SUMMIT_2026.TASTY_BYTES_DEV — one-to-one passthroughs of every base table, intended for downstream development environments.

  4. Create the Power BI–compatible views (DT_DIM_* and DT_FACT_ORDER_DETAIL) in SUMMIT_2026.TASTY_BYTES. These reshape the base tables — splitting names, deriving ISO codes, computing truck age, exposing the order fact with a TIME_ID column — into the shape expected by the Semantic View.

  5. Create the Semantic View TASTY_BYTES_SVA.


The Snowflake Semantic View TASTY_BYTES_SVA

The semantic view is the focal point of the Snowflake side of this sample. It declares, in a single SQL DDL statement:

  • Tables (logical): CUSTOMER, DATE, FRANCHISE, LOCATION, MENU_ITEM, TIME, TRUCK, and ORDER_DETAILS — each bound to one of the DT_DIM_* / DT_FACT_* views above, with primary keys and descriptive comments.
  • Relationships: Seven many_to_one joins from ORDER_DETAILS to each of the dimension tables (CUSTOMER, DATE, FRANCHISE, LOCATION, MENU_ITEM, TIME, TRUCK).
  • Facts: Row-level numeric columns such as ORDER_DETAILS.LINE_TOTAL, ORDER_DETAILS.QUANTITY, ORDER_DETAILS.UNIT_PRICE, TRUCK.TRUCK_AGE, calendar parts on DATE, and clock parts on TIME.
  • Dimensions: All descriptive attributes — customer name / city / country, menu item name / category / dietary flags, truck brand / make / model / region, location city / region / country, calendar attributes, time-of-day attributes, etc.
  • Metrics: Three aggregated measures on ORDER_DETAILS:
    • ORDER_AMTSUM(LINE_TOTAL) — total revenue
    • ORDER_COUNTCOUNT(DISTINCT ORDER_ID) — number of orders
    • ORDER_QTYSUM(QUANTITY) — total items sold

Each column carries a human-readable comment and representative sample_values, which is what makes the view consumable by Snowflake Cortex Analyst.


The SML conversion

The SML model in this repo is a faithful conversion of TASTY_BYTES_SVA into the SML object model:

Snowflake Semantic View concept SML object
Logical table (tables (...)) bound to a view A file under datasets/ (e.g. ORDER_DETAILS.yml) with connection_id: con_SUMMIT_2026_TASTY_BYTES and table: DT_FACT_ORDER_DETAIL
Primary key on a logical table The key columns on the corresponding dimension under dimensions/
Relationship (relationships (...)) A relationships: entry in Tasty Bytes.yml joining the fact dataset to a dimension's lowest level
Dimension column on a logical table A level attribute inside the matching *_dimension.yml file
Fact column on a logical table A numeric attribute or a degenerate dimension on the dataset
Metric (metrics (...)) — sum / count distinct A file under metrics/ (e.g. ORDER_DETAILS.ORDER_AMT.yml)
Comments and sample_values description: fields on datasets, dimensions, and metrics
Semantic View itself The top-level models/Tasty Bytes.yml file, which assembles the dimensions, metrics, and relationships

Datasets

One dataset per Snowflake logical table, pointing at the same DT_DIM_* / DT_FACT_* view that backs the semantic view. The dataset describes the physical columns only — semantics live in the dimension and metric files.

Dimensions

Each *_dimension.yml defines a dimension with a hierarchy and at least one level keyed on the same column used as the semantic view's primary key. Attributes that appear under dimensions (...) in the semantic view become level attributes; date/time attributes are organised on the DATE_dimension and TIME_dimension hierarchies.

Metrics and calculations

  • The three semantic-view metrics (ORDER_AMT, ORDER_COUNT, ORDER_QTY) are converted to plain SML measures under metrics/.
  • The SML model extends the Snowflake original with a calculated measure, ORDER_DETAILS.AVG_ORDER_VALUE (calculations/), implemented in terms of two helper sub-measures (AVG_ORDER_VALUE_SUB_0, AVG_ORDER_VALUE_SUB_1). This is one of the practical benefits of moving from a Snowflake Semantic View to SML — the SML calculation engine supports arithmetic across measures, which the Snowflake Semantic View does not express directly.

Relationships

The seven ORDER_DETAILS → dimension joins from the semantic view are reproduced verbatim as SML relationships. Additional self-relationships are declared on each dimension table so that the dimensions can also be queried independently of the order fact.

Connection

Everything points at the same physical schema as the Snowflake setup script via con_SUMMIT_2026_TASTY_BYTES.yml (database: SUMMIT_2026, schema: TASTY_BYTES).


Getting started

  1. Load the data into Snowflake. Run assets/setup_tasty_bytes.sql in any Snowflake account. This creates the database, schemas, tables, mirror views, Power BI–compatible views, and the TASTY_BYTES_SVA Semantic View.
  2. (Optional) Query the Snowflake Semantic View directly with SELECT ... FROM SEMANTIC_VIEW(SUMMIT_2026.TASTY_BYTES.TASTY_BYTES_SVA ...) to see the original semantic surface.
  3. Deploy the SML model by pointing your semantic-layer tool at this repository and configuring the con_SUMMIT_2026_TASTY_BYTES connection to your Snowflake account. The model expects the views created in step 1 to exist in SUMMIT_2026.TASTY_BYTES.

References