Xiao-zhen-Liu commented on code in PR #8671:
URL: https://github.com/apache/texera/pull/8671#discussion_r4533282704


##########
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:
   Inside a loop, SVM Regressor with Ground Truth Attribute Column `$y` and 
Selected Features "Unit Price" compiles; when y is "Unit Price" it fits Unit 
Price on itself without error, which it refuses outside a loop, since its check 
saw `$y`, not the value. Sklearn Prediction with ground truth `$g` gets "Ground 
Truth column '$g' is not in the input table". Could a text the operator checks 
before the run be refused, as #9359 does for numbers?



-- 
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]

Reply via email to