자습서: 모든 UI 위젯 데모

이 자습서에서는 스키마에서 사용할 수 있는 모든 UI 위젯을 연습하는 Lakeflow Designer용 Python UDF 연산자를 user-defined-operator-v0.1.0 빌드합니다. 고유한 연산자를 만들 때 템플릿으로 사용합니다. 자세한 개요는 Lakeflow Designer의 사용자 정의 연산자를 참조하세요.

Overview

이 연산자는 사용 가능한 모든 UI 위젯 형식을 사용하여 매개 변수를 허용하는 데모 UDF입니다. 모든 입력 값을 설명 문자열에 연결하여 각 위젯이 함수에 데이터를 전달하는 방법을 쉽게 확인할 수 있습니다.

사용 가능한 위젯 유형은 다음과 같습니다.

Widget Description 데이터 형식
expression 입력 포트에서 열/표현식 선택기 expression
input 한 줄 텍스트 입력 string
textarea 여러 줄 텍스트 영역 string
checkbox 체크박스 토글 Boolean
toggle 토글 스위치 Boolean
number 최소/최대값이 있는 숫자 입력 number
slider 범위가 있는 숫자 슬라이더 number
select 단일 선택 드롭다운 (정적 값) string
select 단일 선택형 드롭다운 목록 (입력 열에서) string
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 expression 입력 데이터에서 열 또는 식을 선택합니다.
text_input input string 한 줄 텍스트 항목입니다.
text_area textarea string 여러 줄 텍스트 항목입니다.
checkbox_flag checkbox Boolean 불리언 확인란.
toggle_flag toggle Boolean 불리언 토글 스위치
number_value number number 최소/최대 유효성 검사가 있는 숫자 입력입니다.
slider_value slider number 단계 증분이 있는 숫자 슬라이더입니다.
select_static select string 하드 코딩된 옵션을 사용하여 드롭다운합니다.
select_column select string 입력 열에서 채워진 드롭다운입니다.
multi_select_static multi-select string[] 하드 코딩된 옵션을 사용하여 다중 선택
multi_select_columns multi-select string[] 입력 열의 값으로 채워지는 다중 선택

옵션 원본 형식

selectmulti-select 위젯의 경우 optionsSource를 지정해야 합니다:

정적 옵션: 고정 값 목록:

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

입력 열: 입력 포트 열의 동적 목록:

optionsSource:
  type: inputColumns
  port: in

사용 가능한 모든 속성, 데이터 형식, 위젯 및 옵션에 대한 포괄적인 가이드는 사용자 정의 연산자 YAML 참조 를 참조하세요.

3단계: Unity 카탈로그 함수 만들기

YAML 구성 및 Python 함수를 단일 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에 표시됩니다.

  • 열 선택용 표현식 선택기
  • 텍스트 입력(한 줄 및 여러 줄)
  • 불리언 컨트롤 (확인란 및 토글)
  • 숫자 입력(숫자 필드 및 슬라이더)
  • 정적 및 동적 옵션을 모두 사용하는 드롭다운
  • 여러 값을 선택하기 위한 다중 선택 컨트롤

이 연산자는 각 위젯 형식이 데이터를 렌더링하고 함수에 전달하는 방법을 이해하는 데 유용한 참조 역할을 합니다.

모든 위젯의 데이터 형식 및 옵션은 UI 위젯을 참조하세요.