チュートリアル: すべての UI ウィジェットのデモ

このチュートリアルでは、user-defined-operator-v0.1.0 スキーマで使用可能なすべての UI ウィジェットを実行する、Lakeflow Designer のPython UDF 演算子を構築します。 独自の演算子を作成するときにテンプレートとして使用します。 より広範な概要については、 Lakeflow Designer のユーザー定義演算子に関するページを参照してください。

開始する

この演算子は、使用可能なすべての UI ウィジェットの種類を使用してパラメーターを受け取るデモンストレーション UDF です。 すべての入力値が説明的な文字列に連結されるため、各ウィジェットが関数にデータを渡す方法を簡単に確認できます。

使用可能なウィジェットの種類は次のとおりです。

Widget Description データの種類
expression 入力ポートからの列/式ピッカー
input 1 行テキスト入力 文字列
textarea 複数行テキスト領域 文字列
checkbox チェックボックスの切り替え ブール値
toggle トグル スイッチ ブール値
number 最小/最大の数値入力 number
slider 範囲を持つ数値スライダー number
select 単一選択ドロップダウン (静的な値) 文字列
select 単一選択ドロップダウン(入力列に基づく) 文字列
multi-select 複数選択 (静的な値) string[]
multi-select 複数選択 (入力列から) string[]

手順 1: Python関数を記述してテストする

まず、すべての異なるパラメーター型を受け入れるPython関数を定義します。 この関数は、デモンストレーションのためにすべての入力を説明文字列に連結するだけです。

def concat_all_widgets(
    # expression widget - column value from input
    expr_value: str,
    # input widget - single line text
    text_input: str,
    # textarea widget - multi line text
    text_area: str,
    # checkbox widget - boolean
    checkbox_flag: bool,
    # toggle widget - boolean
    toggle_flag: bool,
    # number widget - numeric input
    number_value: float,
    # slider widget - numeric slider
    slider_value: float,
    # select widget with static options
    select_static: str,
    # select widget with inputColumns options
    select_column: str,
    # multi-select widget with static options (array of strings)
    multi_select_static: list,
    # multi-select widget with inputColumns options (array of strings)
    multi_select_columns: list
) -> str:
    """
    Concatenates all input parameters into a descriptive string.
    This demonstrates all UI widget types available in user-defined operators.
    """
    lines = [
        f"1: Expression (Column Picker) -> {expr_value}",
        f"2: Text Input (Single Line) -> {text_input}",
        f"3: Text Area (Multi-Line) -> {text_area}",
        f"4: Checkbox Option -> {checkbox_flag}",
        f"5: Toggle Switch -> {toggle_flag}",
        f"6: Number Input -> {number_value}",
        f"7: Slider Value -> {slider_value}",
        f"8: Select (Static Options) -> {select_static}",
        f"9: Select (From Input Columns) -> {select_column}",
        f"10: Multi-Select (Static Options) -> [{', '.join(multi_select_static or [])}]",
        f"11: Multi-Select (From Input Columns) -> [{', '.join(multi_select_columns or [])}]"
    ]
    return "\n".join(lines)

次のコードを使用して関数をテストします。

result = concat_all_widgets(
    expr_value="column_value_123",
    text_input="Hello World",
    text_area="Line 1\nLine 2\nLine 3",
    checkbox_flag=True,
    toggle_flag=False,
    number_value=42.5,
    slider_value=75.0,
    select_static="option_b",
    select_column="amount",
    multi_select_static=["tag1", "tag3"],
    multi_select_columns=["col1", "col3"]
)
print(result)

手順 2: YAML 構成を作成する

YAML 構成は、Lakeflow Designer でのオペレーターの表示方法を定義します。 この例では、使用可能なすべてのウィジェットの種類を示します。

schema: user-defined-operator-v0.1.0
type: uc-udf
name: All Widgets Demo
id: demo.all_widgets
version: '1.0.0'
description: >
  A demonstration UDF that showcases all available UI widgets.
config:
  type: object
  properties:
    # ============================================
    # EXPRESSION WIDGET
    # ============================================
    expr_value:
      type: string
      format: expression
      title: 1. Expression (Column Picker)
      examples:
        - 'Select a column or enter an expression'
      x-ui:
        widget: expression
        port: in

    # ============================================
    # INPUT WIDGET (single-line text)
    # ============================================
    text_input:
      type: string
      title: 2. Text Input (Single Line)
      default: default text
      examples:
        - 'Enter a single line of text'
      x-ui:
        widget: input

    # ============================================
    # TEXTAREA WIDGET (multi-line text)
    # ============================================
    text_area:
      type: string
      title: 3. Text Area (Multi-Line)
      default: Sample text
      examples:
        - 'Enter multiple lines of text here...'
      x-ui:
        widget: textarea
        rows: 3

    # ============================================
    # CHECKBOX WIDGET (boolean)
    # ============================================
    checkbox_flag:
      type: boolean
      title: 4. Checkbox Option
      default: true
      x-ui:
        widget: checkbox

    # ============================================
    # TOGGLE WIDGET (boolean switch)
    # ============================================
    toggle_flag:
      type: boolean
      title: 5. Toggle Switch
      default: false
      x-ui:
        widget: toggle

    # ============================================
    # NUMBER WIDGET (numeric input with min/max)
    # ============================================
    number_value:
      type: number
      title: 6. Number Input
      default: 50
      minimum: 0
      maximum: 100
      examples:
        - 'Enter a number (0-100)'
      x-ui:
        widget: number

    # ============================================
    # SLIDER WIDGET (numeric slider)
    # ============================================
    slider_value:
      type: number
      title: 7. Slider Value
      default: 50
      minimum: 0
      maximum: 100
      x-ui:
        widget: slider
        step: 5

    # ============================================
    # SELECT WIDGET with STATIC options
    # ============================================
    select_static:
      type: string
      title: 8. Select (Static Options)
      default: option_a
      examples:
        - 'Choose an option'
      x-ui:
        widget: select
        optionsSource:
          type: static
          values:
            - option_a
            - option_b
            - option_c

    # ============================================
    # SELECT WIDGET with INPUT COLUMNS options
    # ============================================
    select_column:
      type: string
      title: 9. Select (From Input Columns)
      examples:
        - 'Select a column from input'
      x-ui:
        widget: select
        optionsSource:
          type: inputColumns
          port: in

    # ============================================
    # MULTI-SELECT WIDGET with STATIC options
    # ============================================
    multi_select_static:
      type: array
      items:
        type: string
      title: 10. Multi-Select (Static Options)
      default:
        - tag1
        - tag2
      examples:
        - 'Select one or more tags'
      x-ui:
        widget: multi-select
        optionsSource:
          type: static
          values:
            - tag1
            - tag2
            - tag3
            - tag4
            - tag5

    # ============================================
    # MULTI-SELECT WIDGET with INPUT COLUMNS options
    # ============================================
    multi_select_columns:
      type: array
      items:
        type: string
      title: 11. Multi-Select (From Input Columns)
      examples:
        - 'Select one or more columns'
      x-ui:
        widget: multi-select
        optionsSource:
          type: inputColumns
          port: in

  required:
    - expr_value
  additionalProperties: false
ports:
  input:
    - name: in
      title: Input Data
  output:
    - name: out
      title: Output

スキーマの強調表示

設定キー Widget データの種類 Purpose
expr_value expression 入力データから列または式を選択します。
text_input input 文字列 1 行のテキスト 入力。
text_area textarea 文字列 複数行のテキスト入力。
checkbox_flag checkbox ブール値 [ブール値] チェック ボックス。
toggle_flag toggle ブール値 ブール型トグル スイッチ。
number_value number number 最小/最大検証を使用した数値入力。
slider_value slider number ステップの増分を含む数値スライダー。
select_static select 文字列 ハードコーディングされたオプションを含むドロップダウン。
select_column select 文字列 入力列から項目が設定されるドロップダウン。
multi_select_static multi-select string[] ハードコーディングされたオプションを使用して複数選択します。
multi_select_columns multi-select string[] 入力列から設定される複数選択。

オプションのソースの種類

selectウィジェットとmulti-selectウィジェットの場合は、optionsSourceを指定する必要があります。

静的オプション: 値の一覧を修正しました:

optionsSource:
  type: static
  values:
    - value1
    - value2
    - value3

入力列: 入力ポートの列から取得した動的リスト:

optionsSource:
  type: inputColumns
  port: in

使用可能なすべてのプロパティ、データ型、ウィジェット、およびオプションに関する包括的なガイドについては、 ユーザー定義演算子の YAML リファレンスを参照 してください。

手順 3: Unity カタログ関数を作成する

YAML 構成とPython関数を 1 つの CREATE FUNCTION ステートメントに結合します。 string[] (複数選択) 値が UDF にARRAY<STRING>として渡されることに注意してください。

CREATE OR REPLACE FUNCTION main.my_schema.all_widgets_demo(
    expr_value STRING,
    text_input STRING,
    text_area STRING,
    checkbox_flag BOOLEAN,
    toggle_flag BOOLEAN,
    number_value DOUBLE,
    slider_value DOUBLE,
    select_static STRING,
    select_column STRING,
    multi_select_static ARRAY<STRING>,
    multi_select_columns ARRAY<STRING>
)
RETURNS STRING
LANGUAGE PYTHON
AS $$
  """
  schema: user-defined-operator-v0.1.0
  type: uc-udf
  name: All Widgets Demo
  id: demo.all_widgets
  version: "1.0.0"
  description: >
    A demonstration UDF that showcases all available UI widgets.
  config:
    type: object
    properties:
      expr_value:
        type: string
        format: expression
        title: 1. Expression (Column Picker)
        examples:
          - "Select a column or enter an expression"
        x-ui:
          widget: expression
          port: in
      text_input:
        type: string
        title: 2. Text Input (Single Line)
        default: "default text"
        examples:
          - "Enter a single line of text"
        x-ui:
          widget: input
      text_area:
        type: string
        title: 3. Text Area (Multi-Line)
        default: Sample text
        examples:
          - "Enter multiple lines of text here..."
        x-ui:
          widget: textarea
          rows: 3
      checkbox_flag:
        type: boolean
        title: 4. Checkbox Option
        default: true
        x-ui:
          widget: checkbox
      toggle_flag:
        type: boolean
        title: 5. Toggle Switch
        default: false
        x-ui:
          widget: toggle
      number_value:
        type: number
        title: 6. Number Input
        default: 50
        minimum: 0
        maximum: 100
        examples:
          - "Enter a number (0-100)"
        x-ui:
          widget: number
      slider_value:
        type: number
        title: 7. Slider Value
        default: 50
        minimum: 0
        maximum: 100
        x-ui:
          widget: slider
          step: 5
      select_static:
        type: string
        title: 8. Select (Static Options)
        default: option_a
        examples:
          - "Choose an option"
        x-ui:
          widget: select
          optionsSource:
            type: static
            values:
              - option_a
              - option_b
              - option_c
      select_column:
        type: string
        title: 9. Select (From Input Columns)
        examples:
          - "Select a column from input"
        x-ui:
          widget: select
          optionsSource:
            type: inputColumns
            port: in
      multi_select_static:
        type: array
        items:
          type: string
        title: 10. Multi-Select (Static Options)
        default:
          - tag1
          - tag2
        examples:
          - "Select one or more tags"
        x-ui:
          widget: multi-select
          optionsSource:
            type: static
            values:
              - tag1
              - tag2
              - tag3
              - tag4
              - tag5
      multi_select_columns:
        type: array
        items:
          type: string
        title: 11. Multi-Select (From Input Columns)
        examples:
          - "Select one or more columns"
        x-ui:
          widget: multi-select
          optionsSource:
            type: inputColumns
            port: in
    required:
      - expr_value
    additionalProperties: false
  ports:
    input:
      - name: in
        title: Input Data
    output:
      - name: out
        title: Output
  """

  def concat_all_widgets(
      expr_value: str,
      text_input: str,
      text_area: str,
      checkbox_flag: bool,
      toggle_flag: bool,
      number_value: float,
      slider_value: float,
      select_static: str,
      select_column: str,
      multi_select_static: list,
      multi_select_columns: list
  ) -> str:
      lines = [
          f"1: Expression (Column Picker) -> {expr_value}",
          f"2: Text Input (Single Line) -> {text_input}",
          f"3: Text Area (Multi-Line) -> {text_area}",
          f"4: Checkbox Option -> {checkbox_flag}",
          f"5: Toggle Switch -> {toggle_flag}",
          f"6: Number Input -> {number_value}",
          f"7: Slider Value -> {slider_value}",
          f"8: Select (Static Options) -> {select_static}",
          f"9: Select (From Input Columns) -> {select_column}",
          f"10: Multi-Select (Static Options) -> [{', '.join(multi_select_static or [])}]",
          f"11: Multi-Select (From Input Columns) -> [{', '.join(multi_select_columns or [])}]"
      ]
      return "\n".join(lines)

  return concat_all_widgets(
      expr_value,
      text_input,
      text_area,
      checkbox_flag,
      toggle_flag,
      number_value,
      slider_value,
      select_static,
      select_column,
      multi_select_static,
      multi_select_columns
  )
$$

手順 4: 関数をテストする

SQL を使用して UC 関数を直接テストします。

SELECT main.my_schema.all_widgets_demo(
    'my_column_value',             -- expr_value (expression)
    'Hello World',                 -- text_input (input)
    'Multi\nLine\nText',           -- text_area (textarea)
    TRUE,                          -- checkbox_flag (checkbox)
    FALSE,                         -- toggle_flag (toggle)
    42.5,                          -- number_value (number)
    75.0,                          -- slider_value (slider)
    'option_b',                    -- select_static (select with static)
    'amount',                      -- select_column (select with inputColumns)
    array('tag1', 'tag3'),         -- multi_select_static (multi-select with static)
    array('col1', 'col2', 'col3')  -- multi_select_columns (multi-select with inputColumns)
) AS result;

手順 5: オペレーターを登録する

.user_defined_operators.yaml ファイルに演算子を追加します。

operators:
  - catalog: main
    schema: my_schema
    functionName: all_widgets_demo

手順 6: アクセス許可を設定する

このオペレーターを使用する必要があるユーザーにアクセス権を付与します。

GRANT USE SCHEMA ON SCHEMA main.my_schema TO `<user>`;
GRANT EXECUTE ON FUNCTION main.my_schema.all_widgets_demo TO `<user>`;

Lakeflow Designer で演算子を使用する

登録が完了すると、オペレーターは Lakeflow Designer に表示され、包括的な構成ウィンドウに次の情報が表示されます。

  • 列選択用の式ピッカー
  • テキスト入力 (1 行と複数行)
  • ブール型コントロール (チェックボックスとトグル)
  • 数値入力 (数値フィールドとスライダー)
  • 静的オプションと動的オプションの両方を含むドロップダウン
  • 複数の値を選択するための複数選択コントロール

この演算子は、各ウィジェットの種類がデータをレンダリングして関数に渡す方法を理解するための便利な参照として機能します。

すべてのウィジェットのデータ型とオプションについては、 UI ウィジェットを参照してください。