GitHub user carloea2 added a comment to the discussion: Supporting non-coding users in configuring parameters in Python UDF code
<img width="1594" height="601" alt="image" src="https://github.com/user-attachments/assets/771f2c85-1442-4c9a-98cf-f5c41e8d2707" /> @chenlica Here’s what I have working now, end to end, for **Option 2**. ### What the user writes (Python) Users declare UI parameters once in `open()`, and then use the typed value directly: ```python from pytexera import * from typing import Iterator, Optional class ProcessTupleOperator(UDFOperatorV2): @overrides def open(self): # declare UiParameters once, store the parsed runtime values self.value1 = self.UiParameter(name="param1", type=AttributeType.DOUBLE).value self.value2 = self.UiParameter(name="param2", type=AttributeType.INT).value self.value3 = self.UiParameter(name="param3", type=AttributeType.STRING).value self.value4 = self.UiParameter(name="param4", type=AttributeType.TIMESTAMP).value @overrides def process_tuple(self, tuple_: Tuple, port: int) -> Iterator[Optional[TupleLike]]: print(self.value1) print(self.value2) print(self.value3) print(self.value4) yield tuple_ ``` ### What shows up in the UI >From those `self.UiParameter(...)` lines, the property panel automatically >generates a **Parameters** section with one row per parameter: * **Name** + **Type** are read-only (so they stay consistent with the code) * **Value** is editable (so users can change runtime values without touching the script) ### How the values get into Python When the workflow runs, we inject the UI values into the UDF and the base class applies them right before `open()` executes. That way, when the user calls `UiParameter(...).value`, they get the current value from the UI. ### I think this is a good approach: * It’s **safer than passing raw strings around** because the `AttributeType` declaration is actually enforcing the schema as any other property in other operators. We parse and enforce types (int/double/timestamp/etc.) instead of leaving it to user code. * The UI stays in sync with the script, and users can tweak values without editing code. ### Next improvements This can be extended pretty naturally with: * **default values** (so params can be optional and still have sensible behavior) * more validation (required, ranges, patterns) * better widgets (timestamp picker, file picker, etc.) GitHub link: https://github.com/apache/texera/discussions/4154#discussioncomment-15938613 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected]
