aglinxinyuan opened a new pull request, #9359:
URL: https://github.com/apache/texera/pull/9359
### What changes were proposed in this PR?
Inside a control block (`Loop Start ... Loop End`), a number or true/false
property of an operator whose Scala descriptor generates Python, such as Radar
Chart's Fill Opacity or Radar Plot's Show Legend, can now hold a loop-variable
reference such as `$o`. The descriptor writes such a value into the code when
the workflow is compiled, before the loop runs. To find where it lands, the
code is generated from copies of the descriptor with probe values in the
reference's place. Where the two codes differ by exactly the value, and nowhere
else, the code reads it from the iteration's state instead:
```
Loop Start (o = 0.25) -> Radar Chart (fill opacity = $o) -> Loop End
generated with 0.25: opacity=0.25
generated with 0.75: opacity=0.75 (the codes differ here, and only
here)
inside a block: opacity=self.loop_variable_value('o', 'number')
```
- **Probes.** 3 and 5, then 70 and 90 for an integer; 0.25 and 0.75, then
2.5 and 7.5 for a number; `True` and `False`. When the descriptor rejects every
pair, as Figure Factory Table does below a Row Height of 30, the code is
generated from the property's default and the value next to it.
- **What stays a compile error.** The value must also land as it is at 0, 1,
-1, 1000000 and the other probes. The reference stays a compile error that
names the property and why for a value the descriptor checks or adjusts
(Histogram2D's bins, Hugging Face's token limit and temperature, Figure Factory
Table's Row Height and Font Size), one that lands in a text, a comment or a
name, one the code computes with, never holds, or reads as the operator starts
(in `open` or `__init__`, before any state message can arrive), and one that
decides the output schema. A value that fails a check and also decides the
schema gets the check's reason. No error quotes the descriptor's own message
about a probe value the user never typed.
- **One probing per compile.** The compile probes the descriptor once: the
physical operator runs the code that probing produced, and `WorkflowCompiler`
decides every reason, for number, true/false and text references, from the same
result. The schema reason waits until every input has a schema, as the schema
propagation does.
- **Reading the value.** `Operator.loop_variable_value(name, kind)` reads
the variable's text as `loop_variable_text` spells it, from the values the
operator fixed when its first tuple arrived, and converts it as a JVM
operator's property takes it (`StateReferenceBinding.coerce`, then Jackson).
The text is trimmed as `String.trim` trims it. An integer is read as `new
BigDecimal(text).longValueExact()` reads it: within 32 bits for an `int` or
`Integer` property (`'integer'`), within 64 for a `long` one (`'long'`). A
number is read as `Double.parseDouble` reads it (`2.5d` and `0x1p3`, but not
`inf`, `nan`, `1_000` or fullwidth digits), and a boolean as `true` or `false`
in any case, never `1` or `0`.
- **What must have arrived by then.** As for text references, the operator
fails at its first tuple or input end, naming each number or true/false
variable its code reads that no state message carried or whose value its
property cannot take, whether or not the code would read it then.
Outside every block nothing changes. The `stateReferences` sidecar from
#8639, which maps each property that holds a reference to its variable, is
empty there, so the code and the schema are the same as on `main`.
This builds on #8671 and #8642.
### Any related issues, documentation, discussions?
Closes #9358.
### How was this PR tested?
The test commit, 959939d084, fails without the feat commit, 9e841f295c: the
Scala specs do not compile, the new Python tests fail with `AttributeError` or
on the values they read, and the two new end-to-end cases fail to compile their
workflow.
- `PythonOperatorDescriptorSpec`: Radar Chart's opacity read as a number,
next to a text reference; Histogram2D's checked bins and Hugging Face's clamped
values stay compile errors, and so does a sklearn boolean that picks the code's
shape; Figure Factory Table's Row Height, which rejects every probe, and Font
Size reported as checked, with no probe value in the code; a generation that
the descriptor's own values fail embeds that failure; nulls the descriptor
holds survive the copies; every descriptor the frontend can send, with each
top-level number and true/false property referring to a loop variable, embeds
no failure but its own.
- `WorkflowCompilerSpec`, with test-only generated operators: an integer, a
number and a Python boolean read from the loop state; an `int` property's
reference read as `'integer'` and a `long` one's as `'long'`; a value the
descriptor rejects at a probe, at an edge value or at every probe, adjusts, or
computes with; a value in a text, a comment or next to a name; a value the code
does not hold, or reads in `open`; two values that land in one place; the next
probe pair; the schema from a probe, and a value that decides it, reported in
one error with the other references, only once every input has a schema, and
after the check's reason when the value also fails a check; the descriptor
probed once per compile.
- `test_operator.py`, `test_executor_manager.py`: `loop_variable_value` for
every kind and scalar type, against tables generated on JDK 17 through the
compiled `State.fromJson` and `StateReferenceBinding.coerce`, and through a
Limit's `int` property for the 32-bit bound. The tables cover trimming, signs,
exponents of any length, hexadecimal numerals with letter digits, `+` exponents
and suffixes, NaN and Infinity spellings, other scripts' digits, numerals that
start or end with a point, the 32-bit and 64-bit limits, and `true`/`false` in
any case. Also: the values fixed at the first tuple, kept when a later state
arrives; the failure for a required value no state carried or one its property
cannot take, the texts named first; errors before any state, for a missing
name, for a non-scalar and for an unknown kind; the values the executor manager
notes from the generated code; snippets shaped like the generated code, run
against a real operator.
- `LoopIntegrationSpec`, end to end: `sales CSV -> Loop Start (o = 0.25,
table) -> Radar Chart (fill opacity = $o) -> Loop End (o += 0.25 while o <=
0.75)` draws three charts whose traces have opacity 0.25, 0.5 and 0.75. Radar
Plot with Show Legend = `$legend` (`True`, then `False`), over the first `i +
1` rows, shows the legend on the first iteration's plot only; each plot is
matched to its iteration by its trace count.
```
sbt "WorkflowCompiler/test" # 125
passed
sbt "WorkflowOperator/testOnly
org.apache.texera.amber.operator.PythonOperatorDescriptorSpec
org.apache.texera.amber.util.PythonCodeRawInvalidTextSpec
org.apache.texera.amber.operator.loop.*
org.apache.texera.amber.operator.metadata.*
org.apache.texera.amber.operator.machineLearning.*
org.apache.texera.amber.operator.sklearn.*
org.apache.texera.amber.operator.visualization.*
org.apache.texera.amber.operator.huggingFace.*"
# 1487 passed, 2 pending; on Windows only, UrlVizOpDescSpec's export check
fails on CRLF, as on main
sbt "PyBuilder/test" # 192
passed
sbt "WorkflowCompilingService/test" # 64 passed
sbt "WorkflowCore/testOnly org.apache.texera.amber.core.state.*
org.apache.texera.amber.core.executor.*" # 76 passed
sbt "WorkflowExecutionService/testOnly
org.apache.texera.amber.engine.e2e.LoopIntegrationSpec -- -z Python"
# 5 passed: Radar Chart and Radar Plot above, #8671's SVR trainer and
#8642's two Python UDF cases
sbt "WorkflowCompiler/scalafmtCheckAll" "WorkflowCompiler/scalafixAll
--check"
# clean; likewise WorkflowOperator and WorkflowExecutionService
cd amber && pytest src/test/python/core/models
src/test/python/core/runnables \
src/test/python/core/architecture/managers/test_state_processing_manager.py \
src/test/python/core/architecture/managers/test_executor_manager.py
# 788 passed, 9 skipped, 1 xfailed; on Windows only, test_tuple.py's
test_hash fails, as on main
ruff check src/main/python src/test/python && ruff format --check
src/main/python src/test/python
# clean
```
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Claude Opus 5.5)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]