This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9209-607a96cdfbfba7356ff394a30418dc2085639233
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 728d5cd7039257acfb54dfeef73f87db053e21f6
Author: Prateek Ganigi <[email protected]>
AuthorDate: Mon Nov 23 23:02:25 2026 +0000

    fix(workflow-operator): one validation contract for the four legacy Hugging 
Face operators (#9209)
    
    ### What changes were proposed in this PR?
    
    The four legacy Hugging Face operators (Spam Detection, Sentiment
    Analysis, Text Summarization and Iris Logistic Regression) now validate
    their configuration the same way in `getOutputSchemas`, through one
    shared helper, `HuggingFaceSchemaValidation`:
    
    - **They throw and never return `null`,** as @Ma77Ball recommended on
    #8728. Spam and Sentiment used to return `null` for an empty result
    column. The compiler runs `getOutputSchemas` inside a `Try` and stores a
    thrown error on the output port. A returned `null` counted as success,
    then failed one line later in `PhysicalOp.propagateSchema`
    (`schemaMapping.foldLeft`) with a `NullPointerException`, so the user
    saw an NPE instead of a message. Summarization and Iris already threw,
    but with generic messages. All four now name the field, e.g. `Spam
    result attribute cannot be empty`.
    - **Input columns are checked at build time.** The column each operator
    reads (`Attribute` for the three text operators, the two petal columns
    for Iris) must be set and present in the input table. The match is
    exact-case: `Schema` lookups ignore case, but the generated Python does
    not. The error lists the available columns, as #7299's does. Iris's
    petal columns must also be numeric (integer, long or double), matching
    its existing frontend type rule.
    - **Summarization reads its input schema by port id**
    (`inputSchemas(operatorInfo.inputPorts.head.id)`), as the other three
    do, instead of `inputSchemas.values.head`.
    
    Two corrections to the text of #8728. Iris reads two input columns
    (petal length and petal width), not four. And #7299's check runs in the
    generated Python at run time, so it is the precedent for the message
    wording, not for where the check lives.
    
    ### Any related issues?
    
    Closes #8728
    
    ### How was this PR tested?
    
    The tests were written first. 22 new or rewritten tests across the four
    specs failed against `main` for the expected reasons; Spam's and
    Sentiment's propagation tests failed with the `NullPointerException`
    itself. All 22 pass with the change, and reverting the four operators
    makes exactly those 22 fail again. The six tests that asserted `null`
    now assert the thrown message. The Spam and Iris happy-path inputs
    gained the columns those operators read, and their assertions are
    unchanged.
    
    The full `WorkflowOperator` suite passes: 2756 tests, 0 failures, with 1
    cancelled and 2 pending, none of them in the Hugging Face suites. The
    generated Python of all 117 operators compiles, and scalafmt and
    scalafix are clean.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Yes, this PR was co-authored with Claude in compliance with ASF policy.
---
 .../HuggingFaceIrisLogisticRegressionOpDesc.scala  | 16 ++--
 .../huggingFace/HuggingFaceSchemaValidation.scala  | 67 +++++++++++++++
 .../HuggingFaceSentimentAnalysisOpDesc.scala       | 17 ++--
 .../HuggingFaceSpamSMSDetectionOpDesc.scala        | 15 ++--
 .../HuggingFaceTextSummarizationOpDesc.scala       | 11 ++-
 ...ggingFaceIrisLogisticRegressionOpDescSpec.scala | 96 +++++++++++++++++++---
 .../HuggingFaceSentimentAnalysisOpDescSpec.scala   | 94 +++++++++++----------
 .../HuggingFaceSpamSMSDetectionOpDescSpec.scala    | 71 +++++++++++-----
 .../HuggingFaceTextSummarizationOpDescSpec.scala   | 68 ++++++++++++---
 9 files changed, 346 insertions(+), 109 deletions(-)

diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDesc.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDesc.scala
index 42028c7cf6..e2daa5a2d1 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDesc.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDesc.scala
@@ -22,6 +22,10 @@ package org.apache.texera.amber.operator.huggingFace
 import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
 import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject
 import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import 
org.apache.texera.amber.operator.huggingFace.HuggingFaceSchemaValidation.{
+  requireNonEmpty,
+  requireNumericInputColumn
+}
 import org.apache.texera.amber.pybuilder.PyStringTypes.EncodableString
 import 
org.apache.texera.amber.pybuilder.PythonTemplateBuilder.PythonTemplateBuilderStringContext
 import org.apache.texera.amber.core.workflow.{InputPort, OutputPort, 
PortIdentity}
@@ -189,13 +193,13 @@ class HuggingFaceIrisLogisticRegressionOpDesc
   override def getOutputSchemas(
       inputSchemas: Map[PortIdentity, Schema]
   ): Map[PortIdentity, Schema] = {
-    if (
-      predictionClassName == null || predictionClassName.trim.isEmpty ||
-      predictionProbabilityName == null || 
predictionProbabilityName.trim.isEmpty
-    )
-      throw new RuntimeException("Result attribute name should not be empty")
+    val inputSchema = inputSchemas(operatorInfo.inputPorts.head.id)
+    requireNumericInputColumn(inputSchema, "Petal Length Cm Attribute", 
petalLengthCmAttribute)
+    requireNumericInputColumn(inputSchema, "Petal Width Cm Attribute", 
petalWidthCmAttribute)
+    requireNonEmpty("Prediction class name", predictionClassName)
+    requireNonEmpty("Prediction probability name", predictionProbabilityName)
     Map(
-      operatorInfo.outputPorts.head.id -> 
inputSchemas(operatorInfo.inputPorts.head.id)
+      operatorInfo.outputPorts.head.id -> inputSchema
         .add(predictionClassName, AttributeType.STRING)
         .add(predictionProbabilityName, AttributeType.DOUBLE)
     )
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSchemaValidation.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSchemaValidation.scala
new file mode 100644
index 0000000000..e29d235f72
--- /dev/null
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSchemaValidation.scala
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.texera.amber.operator.huggingFace
+
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema}
+
+/**
+  * Configuration checks shared by the Spam Detection, Sentiment Analysis, Text
+  * Summarization and Iris Logistic Regression operators' `getOutputSchemas`.
+  *
+  * Each check throws. The compiler runs `getOutputSchemas` inside a `Try` and 
stores
+  * a thrown error on the operator's output port, which is how an operator 
that is
+  * not configured yet reports why. Messages name the field as the form shows 
it.
+  */
+private[huggingFace] object HuggingFaceSchemaValidation {
+
+  private val NUMERIC_TYPES = Set(AttributeType.INTEGER, AttributeType.LONG, 
AttributeType.DOUBLE)
+
+  /** Require a column-name field to be set and not blank. */
+  def requireNonEmpty(fieldTitle: String, value: String): Unit =
+    if (value == null || value.trim.isEmpty) {
+      throw new RuntimeException(s"$fieldTitle cannot be empty")
+    }
+
+  /**
+    * Require the column a field names to be in the input table, spelled 
exactly as
+    * it is there: Schema lookups ignore case, but the generated Python does 
not.
+    */
+  def requireInputColumn(schema: Schema, fieldTitle: String, column: String): 
Attribute = {
+    requireNonEmpty(fieldTitle, column)
+    schema.attributes
+      .find(_.getName == column)
+      .getOrElse(
+        throw new RuntimeException(
+          s"$fieldTitle '$column' is not in the input table. " +
+            s"Available columns: ${schema.getAttributeNames.mkString(", ")}"
+        )
+      )
+  }
+
+  /** As [[requireInputColumn]], and the column must also be numeric. */
+  def requireNumericInputColumn(schema: Schema, fieldTitle: String, column: 
String): Unit = {
+    val columnType = requireInputColumn(schema, fieldTitle, column).getType
+    if (!NUMERIC_TYPES.contains(columnType)) {
+      throw new RuntimeException(
+        s"$fieldTitle '$column' must be numeric (integer, long or double), not 
${columnType.getName}"
+      )
+    }
+  }
+}
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala
index 6d7c62bff4..722e9b24c1 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDesc.scala
@@ -22,6 +22,10 @@ package org.apache.texera.amber.operator.huggingFace
 import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
 import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject
 import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import 
org.apache.texera.amber.operator.huggingFace.HuggingFaceSchemaValidation.{
+  requireInputColumn,
+  requireNonEmpty
+}
 import org.apache.texera.amber.core.workflow.{InputPort, OutputPort, 
PortIdentity}
 import org.apache.texera.amber.operator.{PythonOperatorDescriptor, 
StandaloneCodeGenerator}
 import 
org.apache.texera.amber.operator.metadata.annotations.{AutofillAttributeName, 
SampleColumn}
@@ -164,14 +168,13 @@ class HuggingFaceSentimentAnalysisOpDesc
   override def getOutputSchemas(
       inputSchemas: Map[PortIdentity, Schema]
   ): Map[PortIdentity, Schema] = {
-    if (
-      resultAttributePositive == null || resultAttributePositive.trim.isEmpty 
||
-      resultAttributeNeutral == null || resultAttributeNeutral.trim.isEmpty ||
-      resultAttributeNegative == null || resultAttributeNegative.trim.isEmpty
-    )
-      return null
+    val inputSchema = inputSchemas(operatorInfo.inputPorts.head.id)
+    requireInputColumn(inputSchema, "Attribute", attribute)
+    requireNonEmpty("Positive result attribute", resultAttributePositive)
+    requireNonEmpty("Neutral result attribute", resultAttributeNeutral)
+    requireNonEmpty("Negative result attribute", resultAttributeNegative)
     Map(
-      operatorInfo.outputPorts.head.id -> 
inputSchemas(operatorInfo.inputPorts.head.id)
+      operatorInfo.outputPorts.head.id -> inputSchema
         .add(resultAttributePositive, AttributeType.DOUBLE)
         .add(resultAttributeNeutral, AttributeType.DOUBLE)
         .add(resultAttributeNegative, AttributeType.DOUBLE)
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDesc.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDesc.scala
index e0a9138d82..818536efbc 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDesc.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDesc.scala
@@ -22,6 +22,10 @@ package org.apache.texera.amber.operator.huggingFace
 import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
 import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject
 import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import 
org.apache.texera.amber.operator.huggingFace.HuggingFaceSchemaValidation.{
+  requireInputColumn,
+  requireNonEmpty
+}
 import org.apache.texera.amber.core.workflow.{InputPort, OutputPort, 
PortIdentity}
 import org.apache.texera.amber.operator.{PythonOperatorDescriptor, 
StandaloneCodeGenerator}
 import 
org.apache.texera.amber.operator.metadata.annotations.{AutofillAttributeName, 
SampleColumn}
@@ -129,13 +133,12 @@ class HuggingFaceSpamSMSDetectionOpDesc
   override def getOutputSchemas(
       inputSchemas: Map[PortIdentity, Schema]
   ): Map[PortIdentity, Schema] = {
-    if (
-      resultAttributeSpam == null || resultAttributeSpam.trim.isEmpty ||
-      resultAttributeProbability == null || 
resultAttributeProbability.trim.isEmpty
-    )
-      return null
+    val inputSchema = inputSchemas(operatorInfo.inputPorts.head.id)
+    requireInputColumn(inputSchema, "Attribute", attribute)
+    requireNonEmpty("Spam result attribute", resultAttributeSpam)
+    requireNonEmpty("Score result attribute", resultAttributeProbability)
     Map(
-      operatorInfo.outputPorts.head.id -> 
inputSchemas(operatorInfo.inputPorts.head.id)
+      operatorInfo.outputPorts.head.id -> inputSchema
         .add(resultAttributeSpam, AttributeType.BOOLEAN)
         .add(resultAttributeProbability, AttributeType.DOUBLE)
     )
diff --git 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDesc.scala
 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDesc.scala
index 2f6b113bff..2fbb59b145 100644
--- 
a/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDesc.scala
+++ 
b/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDesc.scala
@@ -22,6 +22,10 @@ package org.apache.texera.amber.operator.huggingFace
 import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
 import com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject
 import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
+import 
org.apache.texera.amber.operator.huggingFace.HuggingFaceSchemaValidation.{
+  requireInputColumn,
+  requireNonEmpty
+}
 import org.apache.texera.amber.core.workflow.{InputPort, OutputPort, 
PortIdentity}
 import org.apache.texera.amber.operator.{PythonOperatorDescriptor, 
StandaloneCodeGenerator}
 import 
org.apache.texera.amber.operator.metadata.annotations.{AutofillAttributeName, 
SampleColumn}
@@ -134,10 +138,11 @@ class HuggingFaceTextSummarizationOpDesc
   override def getOutputSchemas(
       inputSchemas: Map[PortIdentity, Schema]
   ): Map[PortIdentity, Schema] = {
-    if (resultAttribute == null || resultAttribute.trim.isEmpty)
-      throw new RuntimeException("Result attribute name should be given")
+    val inputSchema = inputSchemas(operatorInfo.inputPorts.head.id)
+    requireInputColumn(inputSchema, "Attribute", attribute)
+    requireNonEmpty("Result attribute name", resultAttribute)
     Map(
-      operatorInfo.outputPorts.head.id -> inputSchemas.values.head
+      operatorInfo.outputPorts.head.id -> inputSchema
         .add(resultAttribute, AttributeType.STRING)
     )
   }
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDescSpec.scala
index bdb587ade2..83d3ab719b 100644
--- 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDescSpec.scala
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceIrisLogisticRegressionOpDescSpec.scala
@@ -65,18 +65,12 @@ class HuggingFaceIrisLogisticRegressionOpDescSpec
   }
 
   "HuggingFaceIrisLogisticRegressionOpDesc.getOutputSchemas" should
-    "reject a blank prediction result name" in {
-    val d = new HuggingFaceIrisLogisticRegressionOpDesc
-    val in = Schema().add("sepal", AttributeType.STRING)
-    val ex = intercept[RuntimeException] {
-      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
-    }
-    ex.getMessage shouldBe "Result attribute name should not be empty"
-  }
-
-  it should "append a STRING class column and a DOUBLE probability column, 
keyed by the output port" in {
+    "append a STRING class column and a DOUBLE probability column, keyed by 
the output port" in {
     val d = configured()
-    val in = Schema().add("sepal", AttributeType.STRING)
+    val in = Schema()
+      .add("sepal", AttributeType.STRING)
+      .add("petalLength", AttributeType.DOUBLE)
+      .add("petalWidth", AttributeType.DOUBLE)
     val out = d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
     val schema = out(d.operatorInfo.outputPorts.head.id)
     schema.getAttribute("sepal").getType shouldBe AttributeType.STRING
@@ -84,6 +78,86 @@ class HuggingFaceIrisLogisticRegressionOpDescSpec
     schema.getAttribute("probability").getType shouldBe AttributeType.DOUBLE
   }
 
+  private def petals(
+      lengthType: AttributeType = AttributeType.DOUBLE,
+      widthType: AttributeType = AttributeType.DOUBLE
+  ): Schema = Schema().add("petalLength", lengthType).add("petalWidth", 
widthType)
+
+  private def schemaError(
+      d: HuggingFaceIrisLogisticRegressionOpDesc,
+      in: Schema = petals()
+  ): String =
+    intercept[RuntimeException] {
+      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
+    }.getMessage
+
+  it should "reject each unset or blank prediction result name, naming the 
field" in {
+    for (empty <- Seq(null, "", "   ")) {
+      withClue(s"[$empty]: ") {
+        val noClass = configured()
+        noClass.predictionClassName = empty
+        schemaError(noClass) shouldBe "Prediction class name cannot be empty"
+
+        val noProbability = configured()
+        noProbability.predictionProbabilityName = empty
+        schemaError(noProbability) shouldBe "Prediction probability name 
cannot be empty"
+      }
+    }
+  }
+
+  it should "reject an unset petal column" in {
+    val noLength = configured()
+    noLength.petalLengthCmAttribute = null
+    schemaError(noLength) shouldBe "Petal Length Cm Attribute cannot be empty"
+
+    val noWidth = configured()
+    noWidth.petalWidthCmAttribute = ""
+    schemaError(noWidth) shouldBe "Petal Width Cm Attribute cannot be empty"
+  }
+
+  it should "reject a petal column that is not in the input table, listing the 
columns" in {
+    val d = configured()
+    d.petalWidthCmAttribute = "petal_width"
+    schemaError(d) shouldBe
+      "Petal Width Cm Attribute 'petal_width' is not in the input table. " +
+        "Available columns: petalLength, petalWidth"
+  }
+
+  it should "match a petal column's case exactly, as the generated Python 
does" in {
+    val d = configured()
+    d.petalLengthCmAttribute = "PetalLength"
+    schemaError(d) should startWith(
+      "Petal Length Cm Attribute 'PetalLength' is not in the input table"
+    )
+  }
+
+  it should "reject a petal column that is not numeric" in {
+    schemaError(configured(), petals(lengthType = AttributeType.STRING)) 
shouldBe
+      "Petal Length Cm Attribute 'petalLength' must be numeric (integer, long 
or double), not string"
+    schemaError(configured(), petals(widthType = AttributeType.BOOLEAN)) 
shouldBe
+      "Petal Width Cm Attribute 'petalWidth' must be numeric (integer, long or 
double), not boolean"
+  }
+
+  it should "accept integer, long and double petal columns" in {
+    for (numeric <- Seq(AttributeType.INTEGER, AttributeType.LONG, 
AttributeType.DOUBLE)) {
+      val d = configured()
+      val in = petals(numeric, numeric)
+      noException should be thrownBy d.getOutputSchemas(
+        Map(d.operatorInfo.inputPorts.head.id -> in)
+      )
+    }
+  }
+
+  it should "leave a readable error on its output port when the compiler 
propagates the schema" in {
+    val d = configured()
+    d.predictionClassName = null
+    val physical = d
+      .getPhysicalOp(workflowId, executionId)
+      .propagateSchema(Some(d.operatorInfo.inputPorts.head.id -> petals()))
+    val port = physical.outputPorts(d.operatorInfo.outputPorts.head.id)._3
+    port.left.map(_.getMessage) shouldBe Left("Prediction class name cannot be 
empty")
+  }
+
   "HuggingFaceIrisLogisticRegressionOpDesc.generatePythonCode" should
     "emit the logistic-regression operator carrying the configured columns 
(encoded)" in {
     val d = configured()
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDescSpec.scala
index 7e6ef12d11..9960792e4f 100644
--- 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDescSpec.scala
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSentimentAnalysisOpDescSpec.scala
@@ -70,63 +70,69 @@ class HuggingFaceSentimentAnalysisOpDescSpec
   }
 
   "HuggingFaceSentimentAnalysisOpDesc.getOutputSchemas" should
-    "return null when any result column is unset" in {
-    val d = new HuggingFaceSentimentAnalysisOpDesc
+    "append the three sentiment columns as DOUBLE, keyed by the declared 
output port" in {
+    val d = configured()
     val in = Schema().add("text", AttributeType.STRING)
-    d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in)) shouldBe 
null
+    val out = d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
+    val schema = out(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("text").getType shouldBe AttributeType.STRING
+    schema.getAttribute("pos").getType shouldBe AttributeType.DOUBLE
+    schema.getAttribute("neu").getType shouldBe AttributeType.DOUBLE
+    schema.getAttribute("neg").getType shouldBe AttributeType.DOUBLE
   }
 
-  it should "return null when a result column is set but blank" in {
-    // Each of the three guards has a null half and a whitespace half. The 
whitespace
-    // half is the one a user actually hits: a cleared-out text box arrives as 
"   ",
-    // not as null, and a schema whose column name is blank is not a usable 
schema.
-    val in = Schema().add("text", AttributeType.STRING)
-    val blanks = Seq("", "   ", "\t")
-    blanks.foreach { blank =>
-      val d = configured()
-      d.resultAttributePositive = blank
-      withClue(s"positive = [$blank]: ") {
-        d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in)) 
shouldBe null
+  private val textInput = Schema().add("text", AttributeType.STRING)
+
+  private def schemaError(d: HuggingFaceSentimentAnalysisOpDesc, in: Schema = 
textInput): String =
+    intercept[RuntimeException] {
+      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
+    }.getMessage
+
+  it should "reject each unset or blank result column, naming the field" in {
+    // Split per column: a copy-pasted guard that re-tests one field in 
another's
+    // clause would pass an all-unset case, and naming the field catches it.
+    val fields: Seq[(String, (HuggingFaceSentimentAnalysisOpDesc, String) => 
Unit)] = Seq(
+      "Positive result attribute" -> ((d, v) => d.resultAttributePositive = v),
+      "Neutral result attribute" -> ((d, v) => d.resultAttributeNeutral = v),
+      "Negative result attribute" -> ((d, v) => d.resultAttributeNegative = v)
+    )
+    for ((title, set) <- fields; empty <- Seq(null, "", "   ", "\t")) {
+      withClue(s"$title = [$empty]: ") {
+        val d = configured()
+        set(d, empty)
+        schemaError(d) shouldBe s"$title cannot be empty"
       }
     }
   }
 
-  it should "return null when only the neutral result column is unset" in {
-    // Split out per column: a copy-pasted guard that re-tests 
`resultAttributePositive`
-    // in the neutral clause passes the "all three unset" case and this one is 
what
-    // catches it.
-    val in = Schema().add("text", AttributeType.STRING)
-
-    val nulled = configured()
-    nulled.resultAttributeNeutral = null
-    nulled.getOutputSchemas(Map(nulled.operatorInfo.inputPorts.head.id -> in)) 
shouldBe null
-
-    val blanked = configured()
-    blanked.resultAttributeNeutral = "   "
-    blanked.getOutputSchemas(Map(blanked.operatorInfo.inputPorts.head.id -> 
in)) shouldBe null
+  it should "reject an unset input attribute" in {
+    val d = configured()
+    d.attribute = "  "
+    schemaError(d) shouldBe "Attribute cannot be empty"
   }
 
-  it should "return null when only the negative result column is unset" in {
-    val in = Schema().add("text", AttributeType.STRING)
-
-    val nulled = configured()
-    nulled.resultAttributeNegative = null
-    nulled.getOutputSchemas(Map(nulled.operatorInfo.inputPorts.head.id -> in)) 
shouldBe null
+  it should "reject an input attribute that is not in the input table, listing 
the columns" in {
+    val d = configured()
+    d.attribute = "review"
+    schemaError(d) shouldBe "Attribute 'review' is not in the input table. 
Available columns: text"
+  }
 
-    val blanked = configured()
-    blanked.resultAttributeNegative = "   "
-    blanked.getOutputSchemas(Map(blanked.operatorInfo.inputPorts.head.id -> 
in)) shouldBe null
+  it should "match the input attribute's case exactly, as the generated Python 
does" in {
+    val d = configured()
+    d.attribute = "TEXT"
+    schemaError(d) should startWith("Attribute 'TEXT' is not in the input 
table")
   }
 
-  it should "append the three sentiment columns as DOUBLE, keyed by the 
declared output port" in {
+  it should "leave a readable error on its output port when the compiler 
propagates the schema" in {
+    // The compiler runs getOutputSchemas inside a Try and stores a thrown 
error on the
+    // output port. A returned null escaped that Try as a NullPointerException 
instead.
     val d = configured()
-    val in = Schema().add("text", AttributeType.STRING)
-    val out = d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
-    val schema = out(d.operatorInfo.outputPorts.head.id)
-    schema.getAttribute("text").getType shouldBe AttributeType.STRING
-    schema.getAttribute("pos").getType shouldBe AttributeType.DOUBLE
-    schema.getAttribute("neu").getType shouldBe AttributeType.DOUBLE
-    schema.getAttribute("neg").getType shouldBe AttributeType.DOUBLE
+    d.resultAttributeNeutral = null
+    val physical = d
+      .getPhysicalOp(workflowId, executionId)
+      .propagateSchema(Some(d.operatorInfo.inputPorts.head.id -> textInput))
+    val port = physical.outputPorts(d.operatorInfo.outputPorts.head.id)._3
+    port.left.map(_.getMessage) shouldBe Left("Neutral result attribute cannot 
be empty")
   }
 
   "HuggingFaceSentimentAnalysisOpDesc.generatePythonCode" should
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDescSpec.scala
index 2f4c6f46e2..eac0a31d91 100644
--- 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDescSpec.scala
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceSpamSMSDetectionOpDescSpec.scala
@@ -64,7 +64,7 @@ class HuggingFaceSpamSMSDetectionOpDescSpec
   "HuggingFaceSpamSMSDetectionOpDesc.getOutputSchemas" should
     "append a BOOLEAN spam column and a DOUBLE score column, keyed by the 
declared output port" in {
     val d = configured()
-    val in = Schema().add("msg", AttributeType.STRING)
+    val in = Schema().add("msg", AttributeType.STRING).add("text", 
AttributeType.STRING)
     val out = d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
     val schema = out(d.operatorInfo.outputPorts.head.id)
     schema.getAttribute("msg").getType shouldBe AttributeType.STRING
@@ -72,33 +72,60 @@ class HuggingFaceSpamSMSDetectionOpDescSpec
     schema.getAttribute("score").getType shouldBe AttributeType.DOUBLE
   }
 
-  it should "return null while a result attribute is still unset" in {
-    // getOutputSchemas is called continuously as the user configures the 
operator,
-    // so an unset name means "no schema yet", not "build one with a null 
column".
-    // The sibling operators (sentiment analysis, iris) already answer this 
way.
-    val in = Schema().add("msg", AttributeType.STRING)
-    val ports = Map((new 
HuggingFaceSpamSMSDetectionOpDesc).operatorInfo.inputPorts.head.id -> in)
+  private val textInput = Schema().add("text", AttributeType.STRING)
 
-    val noSpamCol = configured()
-    noSpamCol.resultAttributeSpam = null
-    noSpamCol.getOutputSchemas(ports) shouldBe null
+  private def schemaError(d: HuggingFaceSpamSMSDetectionOpDesc, in: Schema = 
textInput): String =
+    intercept[RuntimeException] {
+      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
+    }.getMessage
 
-    val noScoreCol = configured()
-    noScoreCol.resultAttributeProbability = null
-    noScoreCol.getOutputSchemas(ports) shouldBe null
+  it should "reject an unset or blank result attribute, naming the field" in {
+    Seq(null, "", "   ").foreach { empty =>
+      withClue(s"[$empty]: ") {
+        val noSpamCol = configured()
+        noSpamCol.resultAttributeSpam = empty
+        schemaError(noSpamCol) shouldBe "Spam result attribute cannot be empty"
+
+        val noScoreCol = configured()
+        noScoreCol.resultAttributeProbability = empty
+        schemaError(noScoreCol) shouldBe "Score result attribute cannot be 
empty"
+      }
+    }
+  }
+
+  it should "reject an unset input attribute" in {
+    val d = configured()
+    d.attribute = null
+    schemaError(d) shouldBe "Attribute cannot be empty"
   }
 
-  it should "return null when a result attribute is blank" in {
-    val in = Schema().add("msg", AttributeType.STRING)
-    val ports = Map((new 
HuggingFaceSpamSMSDetectionOpDesc).operatorInfo.inputPorts.head.id -> in)
+  it should "reject an input attribute that is not in the input table, listing 
the columns" in {
+    val d = configured()
+    d.attribute = "txt"
+    schemaError(
+      d,
+      Schema().add("text", AttributeType.STRING).add("id", 
AttributeType.INTEGER)
+    ) shouldBe
+      "Attribute 'txt' is not in the input table. Available columns: text, id"
+  }
 
-    val blankSpamCol = configured()
-    blankSpamCol.resultAttributeSpam = "   "
-    blankSpamCol.getOutputSchemas(ports) shouldBe null
+  it should "match the input attribute's case exactly, as the generated Python 
does" in {
+    // Schema lookups ignore case, but tuple_[...] and out1df[...] do not.
+    val d = configured()
+    d.attribute = "Text"
+    schemaError(d) should startWith("Attribute 'Text' is not in the input 
table")
+  }
 
-    val blankScoreCol = configured()
-    blankScoreCol.resultAttributeProbability = ""
-    blankScoreCol.getOutputSchemas(ports) shouldBe null
+  it should "leave a readable error on its output port when the compiler 
propagates the schema" in {
+    // The compiler runs getOutputSchemas inside a Try and stores a thrown 
error on the
+    // output port. A returned null escaped that Try as a NullPointerException 
instead.
+    val d = configured()
+    d.resultAttributeSpam = null
+    val physical = d
+      .getPhysicalOp(workflowId, executionId)
+      .propagateSchema(Some(d.operatorInfo.inputPorts.head.id -> textInput))
+    val port = physical.outputPorts(d.operatorInfo.outputPorts.head.id)._3
+    port.left.map(_.getMessage) shouldBe Left("Spam result attribute cannot be 
empty")
   }
 
   "HuggingFaceSpamSMSDetectionOpDesc.generatePythonCode" should
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDescSpec.scala
index 50599e966d..a670611811 100644
--- 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDescSpec.scala
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceTextSummarizationOpDescSpec.scala
@@ -23,6 +23,7 @@ import 
com.kjetland.jackson.jsonSchema.annotations.JsonSchemaInject
 import org.apache.texera.amber.core.executor.OpExecWithCode
 import org.apache.texera.amber.core.tuple.{AttributeType, Schema}
 import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
 import org.apache.texera.amber.operator.LogicalOp
 import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
 import org.apache.texera.amber.util.JSONUtils.objectMapper
@@ -61,16 +62,7 @@ class HuggingFaceTextSummarizationOpDescSpec
   }
 
   "HuggingFaceTextSummarizationOpDesc.getOutputSchemas" should
-    "reject a blank result attribute name" in {
-    val d = new HuggingFaceTextSummarizationOpDesc
-    val in = Schema().add("text", AttributeType.STRING)
-    val ex = intercept[RuntimeException] {
-      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
-    }
-    ex.getMessage shouldBe "Result attribute name should be given"
-  }
-
-  it should "append the summary column as STRING, keyed by the declared output 
port" in {
+    "append the summary column as STRING, keyed by the declared output port" 
in {
     val d = configured()
     val in = Schema().add("text", AttributeType.STRING)
     val out = d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
@@ -79,6 +71,62 @@ class HuggingFaceTextSummarizationOpDescSpec
     schema.getAttribute("summary").getType shouldBe AttributeType.STRING
   }
 
+  private val textInput = Schema().add("text", AttributeType.STRING)
+
+  private def schemaError(d: HuggingFaceTextSummarizationOpDesc, in: Schema = 
textInput): String =
+    intercept[RuntimeException] {
+      d.getOutputSchemas(Map(d.operatorInfo.inputPorts.head.id -> in))
+    }.getMessage
+
+  it should "reject an unset or blank result attribute name, naming the field" 
in {
+    Seq(null, "", "   ").foreach { empty =>
+      withClue(s"[$empty]: ") {
+        val d = configured()
+        d.resultAttribute = empty
+        schemaError(d) shouldBe "Result attribute name cannot be empty"
+      }
+    }
+  }
+
+  it should "reject an unset input attribute" in {
+    val d = configured()
+    d.attribute = null
+    schemaError(d) shouldBe "Attribute cannot be empty"
+  }
+
+  it should "reject an input attribute that is not in the input table, listing 
the columns" in {
+    val d = configured()
+    d.attribute = "body"
+    schemaError(d) shouldBe "Attribute 'body' is not in the input table. 
Available columns: text"
+  }
+
+  it should "match the input attribute's case exactly, as the generated Python 
does" in {
+    val d = configured()
+    d.attribute = "Text"
+    schemaError(d) should startWith("Attribute 'Text' is not in the input 
table")
+  }
+
+  it should "read the input schema from its declared input port" in {
+    // Keyed by port id, as the other three operators do, rather than taking
+    // whichever schema the map yields first.
+    val d = configured()
+    val other = Schema().add("unrelated", AttributeType.INTEGER)
+    val out = d.getOutputSchemas(
+      Map(PortIdentity(7) -> other, d.operatorInfo.inputPorts.head.id -> 
textInput)
+    )
+    out(d.operatorInfo.outputPorts.head.id).getAttributeNames shouldBe 
List("text", "summary")
+  }
+
+  it should "leave a readable error on its output port when the compiler 
propagates the schema" in {
+    val d = configured()
+    d.resultAttribute = null
+    val physical = d
+      .getPhysicalOp(workflowId, executionId)
+      .propagateSchema(Some(d.operatorInfo.inputPorts.head.id -> textInput))
+    val port = physical.outputPorts(d.operatorInfo.outputPorts.head.id)._3
+    port.left.map(_.getMessage) shouldBe Left("Result attribute name cannot be 
empty")
+  }
+
   "HuggingFaceTextSummarizationOpDesc.generatePythonCode" should
     "emit the bert-mini2bert summarizer carrying the configured columns 
(encoded)" in {
     val d = configured()

Reply via email to