aglinxinyuan commented on code in PR #8671:
URL: https://github.com/apache/texera/pull/8671#discussion_r4533866043
##########
common/workflow-compiler/src/main/scala/org/apache/texera/common/compiler/WorkflowCompiler.scala:
##########
@@ -167,20 +171,97 @@ object WorkflowCompiler {
* A reference is bound in the executor that `ExecFactory` builds from the
descriptor's JSON: the
* state message writes the loop variable into the descriptor that executor
parsed. An operator
* whose executor runs code instead -- a UDF, or a descriptor that
generates Python from its
- * properties, such as the sklearn operators -- never takes that path: its
code is built from the
- * placeholders before the loop runs, and nothing binds them.
+ * properties, such as the sklearn operators -- never takes that path: its
code is built before
+ * the loop runs. A UDF's code and properties are the user's, and nothing
binds them. In
+ * generated code a typed placeholder is a value, so nothing binds it
either. A String
+ * property's `$name` is bound only where pyb's decoder rendered it, which
+ * `PythonOperatorDescriptor` turned into a read of the loop state,
`loopVariableLookup(name)`,
+ * and then only if the code holds the text `$name` nowhere (where it does,
the code pastes it
+ * in as it is), the code reads it nowhere when the operator starts (in
`open` or `__init__`,
+ * `PythonOperatorDescriptor.runsAtStartup`), before the iteration's state
can arrive, and no
+ * output column the operator adds holds the text (its schema is computed
from the literal).
+ * When the generation failed there is no code to read either way, and the
code-generation
+ * check reports why it failed instead.
+ *
+ * @param physicalOps the operator's own physical operators, their schemas
propagated.
*/
- def unbindableStateReferences(logicalOp: LogicalOp, subPlan: PhysicalPlan):
Option[Throwable] =
- Option.when(
- logicalOp.stateReferences.nonEmpty &&
- subPlan.operators.exists(_.opExecInitInfo.isInstanceOf[OpExecWithCode])
- ) {
- new UnsupportedOperationException(
- s"${logicalOp.operatorInfo.userFriendlyName} cannot refer to loop
variables yet " +
- s"(${formatReferences(logicalOp.stateReferences)}): its code is
generated before " +
- "the loop runs"
- )
+ def unbindableStateReferences(
+ logicalOp: LogicalOp,
+ physicalOps: Iterable[PhysicalOp]
+ ): Option[Throwable] = {
+ val codes = physicalOps.toSeq.map(_.opExecInitInfo).collect {
+ case OpExecWithCode(code, language) => (code, language)
}
+ if (logicalOp.stateReferences.isEmpty || codes.isEmpty) {
+ None
+ } else {
+ val generated =
+ logicalOp.isInstanceOf[PythonOperatorDescriptor] && codes.forall(_._2
== "python")
+ val unbound: Seq[(Iterable[String], String)] =
+ if (!generated) {
+ Seq(logicalOp.stateReferences.keys -> fixedInUdf)
+ } else {
+ val tree = objectMapper.valueToTree[ObjectNode](logicalOp)
+ val text = textReferences(tree, logicalOp.stateReferences)
+ val scripts = codes.map(_._1)
+ val added = addedColumns(physicalOps)
+ def whyUnbound(name: String): Option[String] = {
+ val lookup = loopVariableLookup(name)
+ if (scripts.exists(_.contains("$" + name))) Some(pastedIntoCode)
+ else if (!scripts.exists(_.contains(lookup))) Some(unreadByCode)
+ else if (scripts.exists(code => offsetsOf(code,
lookup).exists(runsAtStartup(code, _))))
+ Some(readAtStartup)
+ else if (added.exists(_.contains("$" + name)))
Some(namesOutputColumn)
Review Comment:
Yes, in 4d843d51ba (cases in 61fcfc679b): the compiler now tries each text
reference with other texts in its place, a column of each type from the inputs
and the operator's other texts, and refuses it with "it checks the text before
the loop runs" (or "the text decides its output schema") when the operator's
schema or check comes out differently. So SVM Regressor's `$y` and Sklearn
Prediction's `$g` are refused, as are the other trainers' ground truth and
features, a classic trainer's target and text with Count Vectorizer on, and the
Scorer's columns.
--
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]