Catatan
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba masuk atau mengubah direktori.
Akses ke halaman ini memerlukan otorisasi. Anda dapat mencoba mengubah direktori.
Dalam tutorial ini, Anda membangun operator UDF Python untuk Lakeflow Designer yang menjalankan setiap widget UI yang tersedia dalam user-defined-operator-v0.1.0 skema. Gunakan ini sebagai templat saat membuat operator Anda sendiri. Untuk gambaran umum yang lebih luas, lihat Operator yang ditentukan pengguna di Lakeflow Designer.
Ikhtisar
Operator ini adalah UDF demonstrasi yang menerima parameter menggunakan setiap jenis widget UI yang tersedia. Ini menggabungkan semua nilai input ke dalam string deskriptif, sehingga mudah untuk melihat bagaimana setiap widget meneruskan data ke fungsi Anda.
Jenis widget yang tersedia adalah:
| Widget | Description | Jenis Data |
|---|---|---|
expression |
Pemilih kolom/ekspresi dari port masukan | ekspresi |
input |
Input teks baris tunggal | string |
textarea |
Area teks multibaris | string |
checkbox |
Pengalih kotak centang | Boolean |
toggle |
Alihkan tombol | Boolean |
number |
Input angka dengan min/maks | number |
slider |
Penggerak numerik dengan rentang | number |
select |
Daftar tarik-turun pilihan tunggal (nilai statis) | string |
select |
Dropdown pilihan tunggal (dari kolom input) | string |
multi-select |
Pilihan ganda (nilai statis) | string[] |
multi-select |
Pilih beberapa (dari kolom input) | string[] |
Step 1: Menulis dan menguji fungsi Python
Pertama, tentukan fungsi Python yang menerima semua jenis parameter yang berbeda. Fungsi ini hanya menggabungkan semua input ke dalam string deskriptif untuk tujuan demonstrasi.
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)
Uji fungsi dengan kode berikut:
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)
Langkah 2: Membuat konfigurasi YAML
Konfigurasi YAML menentukan bagaimana operator muncul di Lakeflow Designer. Contoh ini menunjukkan setiap jenis widget yang tersedia:
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
Sorotan skema
| Kunci Konfigurasi | Widget | Jenis Data | Kegunaan |
|---|---|---|---|
expr_value |
expression |
ekspresi | Pilih kolom atau ekspresi dari data input. |
text_input |
input |
string | Entri teks baris tunggal. |
text_area |
textarea |
string | Entri teks multibaris. |
checkbox_flag |
checkbox |
Boolean | Kotak centang Boolean. |
toggle_flag |
toggle |
Boolean | Sakelar pengalih Boolean. |
number_value |
number |
number | Input numerik dengan validasi min/maks. |
slider_value |
slider |
number | Penggeser numerik dengan kenaikan bertahap. |
select_static |
select |
string | Menu tarik-turun dengan opsi yang dikodekan secara tetap. |
select_column |
select |
string | Dropdown diisi dari kolom input. |
multi_select_static |
multi-select |
string[] | Pilihan ganda dengan opsi yang dikodekan langsung. |
multi_select_columns |
multi-select |
string[] | Pilihan ganda diisi dari kolom input. |
Jenis sumber opsi
Untuk select widget dan multi-select , Anda harus menentukan optionsSource:
Opsi statis: Daftar nilai tetap:
optionsSource:
type: static
values:
- value1
- value2
- value3
Kolom masukan: Daftar dinamis dari kolom pada port masukan:
optionsSource:
type: inputColumns
port: in
Lihat referensi YAML untuk operator yang ditentukan pengguna untuk panduan lengkap tentang semua properti, jenis data, widget, dan opsi yang tersedia.
Langkah 3: Membuat fungsi Katalog Unity
Gabungkan konfigurasi YAML dan fungsi Python ke dalam satu pernyataan CREATE FUNCTION. Perhatikan bahwa nilai string[] (multi-select) diteruskan sebagai ARRAY<STRING> ke UDF.
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
)
$$
Langkah 4: Uji fungsi
Uji fungsi UC secara langsung dengan SQL:
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;
Langkah 5: Daftarkan operator
Tambahkan operator ke file .user_defined_operators.yaml Anda:
operators:
- catalog: main
schema: my_schema
functionName: all_widgets_demo
Langkah 6: Menyiapkan izin
Berikan akses ke pengguna yang perlu menggunakan operator ini:
GRANT USE SCHEMA ON SCHEMA main.my_schema TO `<user>`;
GRANT EXECUTE ON FUNCTION main.my_schema.all_widgets_demo TO `<user>`;
Menggunakan operator di Lakeflow Designer
Setelah terdaftar, operator muncul di Lakeflow Designer dengan panel konfigurasi komprehensif yang menampilkan:
- Pemilih ekspresi untuk memilih kolom
- Input teks (baris tunggal dan multibaris)
- Kontrol Boolean (kotak centang dan tombol)
- Masukan numerik (kolom angka dan penggeser)
- Menu dropdown dengan opsi statis maupun dinamis
- Kontrol pemilihan ganda untuk memilih beberapa nilai
Operator ini berfungsi sebagai referensi yang berguna untuk memahami bagaimana setiap jenis widget merender dan meneruskan data ke fungsi Anda.
Untuk setiap jenis dan opsi data widget, lihat widget UI.