共用方式為


在度量視圖中使用語意中繼資料

這很重要

這項功能目前處於 公開預覽版。 您可以在 預覽 頁面確認預覽報名。 請參閱 管理 Azure Databricks 預覽。

本頁說明如何在指標檢視中使用語意中繼資料來增強資料視覺化並提高大型語言模型 (LLM) 的準確性。

備註

需要 Databricks Runtime 17.2 或更新版本。 度量檢視 YAML 定義必須使用規格 1.1 版或更新版本。 如需詳細資訊,請參閱 版本規格變更日誌

什麼是語義元資料?

語意中繼資料包括顯示名稱、格式規格和提供額外內容的同義字。 此元資料可協助視覺化工具 (例如 AI/BI 儀表板) 和自然語言工具 ( 例如 Genie 空間) 更有效地解釋和處理您的資料。 語意中繼資料是在度量視圖的 YAML 定義中定義的。

備註

當您使用規格 1.1 版建立或變更度量視圖時,儲存定義時,會移除 YAML 定義中的任何單行註解 (以 表示 #)。 請參閱 將 YAML 升級至 1.1 ,以取得升級現有 YAML 定義時的選項和建議。

顯示名稱

顯示名稱提供人類可讀的標籤,這些標籤出現在視覺化工具中,而不是技術欄名稱。 顯示名稱限制為 255 個字元。

下列範例顯示在order_date維度和total_revenue量值上定義的顯示名稱。

version: 1.1
source: samples.tpch.orders

dimensions:
  - name: order_date
    expr: o_orderdate
    display_name: 'Order Date'

measures:
  - name: total_revenue
    expr: SUM(o_totalprice)
    display_name: 'Total Revenue'

Synonyms

同義詞可協助 LLM 工具 ( 例如 AI/BI Genie) 透過提供替代名稱,透過使用者輸入來發現維度和度量。 您可以使用區塊樣式或流程樣式 YAML 來定義同義字。 每個維度或量值最多可以有 10 個同義字。 每個同義詞限制為 255 個字元。

下列範例顯示在order_date維度上定義的同義字:

version: 1.1
source: samples.tpch.orders

dimensions:
  - name: order_date
    expr: o_orderdate
    # block style
    synonyms:
      - 'order time'
      - 'date of order'

measures:
  - name: total_revenue
    expr: SUM(o_totalprice)
    # flow style
    synonyms: ['revenue', 'total sales']

格式規格

格式規格定義了值在視覺化工具中的顯示方式。 下表包含支援的格式類型和範例。

數值格式

格式類型 必要選項 選用選項
數字:對一般數值使用純數字格式,並具有可選的小數位數控制項和縮寫選項。 type: number
  • decimal_places:控制小數點後顯示的位數。
    • type:(如果指定,則 decimal_places 為必填)
      • max
      • exact
      • all
    • places:0-10 之間的整數值 (如果類型為 maxexact) 則為必要值
  • hide_group_separator:當設定為 true 時,會移除任何適用的數字分組分隔符號,例如 ,
    • true
    • false
  • abbreviation:
    • none
    • compact
    • scientific
貨幣:使用貨幣格式來表示貨幣價值,並配合 ISO-4217 貨幣代碼。 type: currency
  • currency_code:ISO-4217 代碼(必填)。 例如,下列程式碼會分別插入美元、歐元和日圓的符號。
    • USD
    • EUR
    • JPY
  • decimal_places:控制小數點後顯示的位數。
    • type:(如果指定,則 decimal_places 為必填)
      • max
      • exact
      • all
  • hide_group_separator:當設定為 true 時,會移除任何適用的數字分組分隔符號。
    • true
    • false
  • abbreviation:
    • none
    • compact
    • scientific
百分比:對以百分比表示的比率值使用百分比格式。 type: percentage
  • decimal_places:控制小數點後顯示的位數。
    • type:(如果指定,則 decimal_places 為必填)
      • max
      • exact
      • all
  • hide_group_separator:當設定為 true 時,會移除任何適用的數字分組分隔符號。
    • true
    • false

數值格式範例

Number
format:
  type: number
  decimal_places:
    type: max
    places: 2
  hide_group_separator: false
  abbreviation: compact
貨幣
format:
  type: currency
  currency_code: USD
  decimal_places:
    type: exact
    places: 2
  hide_group_separator: false
  abbreviation: compact
百分比
format:
  type: percentage
  decimal_places:
    type: all
  hide_group_separator: true

日期和時間格式

下表說明如何使用日期和時間格式。

格式類型 必要選項 選用選項
日期:使用具有各種顯示選項的日期值的日期格式。
  • type: date
  • date_format:控制日期的顯示方式
    • locale_short_month:顯示帶有縮寫月份的日期
    • locale_long_month:顯示日期和月份的全名
    • year_month_day:將日期格式化為 YYYY-MM-DD
    • locale_number_month:以數字顯示帶有月份的日期
    • year_week:將日期格式化為年和週數。 例如, 2025-W1
  • leading_zeros:控制個位數數字前面是否加上零
  • true
  • false
日期時間:使用日期時間格式來取得結合日期和時間的時間戳記值。
  • type: date_time
  • date_format:控制日期的顯示方式
    • no_date:日期已隱藏
    • locale_short_month:顯示帶有縮寫月份的日期
    • locale_long_month:顯示日期和月份的全名
    • year_month_day:將日期格式化為 YYYY-MM-DD
    • locale_number_month:以數字顯示帶有月份的日期
    • year_week:將日期格式化為年和週數。 例如, 2025-W1
  • time_format:
    • no_time:時間被隱藏
    • locale_hour_minute:顯示小時和分鐘
    • locale_hour_minute_second:顯示時、分和秒
  • leading_zeros:控制個位數數字前面是否加上零
    • true
    • false

備註

使用date_time類型時,至少一個 date_formattime_format 必須指定no_dateno_time以外的值。

日期時間格式範例

Date
format:
  type: date
  date_format: year_month_day
  leading_zeros: true
DateTime
format:
  type: date_time
  date_format: year_month_day
  time_format: locale_hour_minute_second
  leading_zeros: false

完整範例

下列範例顯示包含所有語意中繼資料類型的度量檢視定義:

version: 1.1
source: samples.tpch.orders
comment: Comprehensive sales metrics with enhanced semantic metadata
dimensions:
  - name: order_date
    expr: o_orderdate
    comment: Date when the order was placed
    display_name: Order Date
    format:
      type: date
      date_format: year_month_day
      leading_zeros: true
    synonyms:
      - order time
      - date of order
  - name: customer_segment
    expr: |
      CASE
        WHEN o_totalprice > 100000 THEN 'Enterprise'
        WHEN o_totalprice > 10000 THEN 'Mid-market'
        ELSE 'SMB'
      END
    comment: Customer classification based on order value
    display_name: Customer Segment
    synonyms:
      - segment
      - customer tier
measures:
  - name: total_revenue
    expr: SUM(o_totalprice)
    comment: Total revenue from all orders
    display_name: Total Revenue
    format:
      type: currency
      currency_code: USD
      decimal_places:
        type: exact
        places: 2
      hide_group_separator: false
      abbreviation: compact
    synonyms:
      - revenue
      - total sales
      - sales amount
  - name: order_count
    expr: COUNT(1)
    comment: Total number of orders
    display_name: Order Count
    format:
      type: number
      decimal_places:
        type: all
      hide_group_separator: true
    synonyms:
      - count
      - number of orders
  - name: avg_order_value
    expr: SUM(o_totalprice) / COUNT(1)
    comment: Average revenue per order
    display_name: Average Order Value
    format:
      type: currency
      currency_code: USD
      decimal_places:
        type: exact
        places: 2
    synonyms:
      - aov
      - average revenue