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

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

commit 2779df91c44418eed60ec257f5f7b77653a8552c
Author: Xinyuan Lin <[email protected]>
AuthorDate: Thu Jun 25 00:19:44 2026 -0700

    test(workflow-operator): add unit test coverage for Sklearn linear 
classifier descriptors (#5941)
    
    ### What changes were proposed in this PR?
    
    Pin behavior of four previously-untested Sklearn linear classifier
    descriptors in `common/workflow-operator`. No production-code changes.
    
    | Spec | Source class | Tests |
    | --- | --- | --- |
    | `SklearnLogisticRegressionOpDescSpec` |
    `SklearnLogisticRegressionOpDesc` | 5 |
    | `SklearnLogisticRegressionCVOpDescSpec` |
    `SklearnLogisticRegressionCVOpDesc` | 5 |
    | `SklearnPerceptronOpDescSpec` | `SklearnPerceptronOpDesc` | 5 |
    | `SklearnPassiveAggressiveOpDescSpec` |
    `SklearnPassiveAggressiveOpDesc` | 5 |
    
    **Behavior pinned**
    
    | Surface | Contract |
    | --- | --- |
    | `operatorInfo` | exact model name + `Sklearn <name> Operator`
    description; Sklearn group; training/testing input ports + one blocking
    output |
    | field defaults | `countVectorizer`/`tfidfTransformer` `false`;
    `target`/`text` `null` |
    | `getOutputSchemas` | `model_name` (STRING) + `model` (BINARY) keyed by
    the declared output port |
    | `generatePythonCode` | imports the matching sklearn estimator and
    builds the `make_pipeline` model |
    | Round-trip | config fields preserved through the polymorphic
    `LogicalOp` base, with the correct `operatorType` discriminator |
    
    ### Any related issues, documentation, discussions?
    
    Part of the ongoing `workflow-operator` unit-test coverage effort
    (follow-up to the Sklearn Naive Bayes coverage in #5925).
    
    ### How was this PR tested?
    
    - `sbt "WorkflowOperator/testOnly *SklearnLogisticRegressionOpDescSpec
    *SklearnLogisticRegressionCVOpDescSpec *SklearnPerceptronOpDescSpec
    *SklearnPassiveAggressiveOpDescSpec"` — 20 tests, all green
    - `sbt "WorkflowOperator/Test/scalafmtCheck"` and `sbt
    "WorkflowOperator/scalafixAll --check"` — clean
    - CI to confirm
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (Opus 4.8 [1M context])
---
 .../SklearnLogisticRegressionCVOpDescSpec.scala    | 79 ++++++++++++++++++++++
 .../SklearnLogisticRegressionOpDescSpec.scala      | 79 ++++++++++++++++++++++
 .../SklearnPassiveAggressiveOpDescSpec.scala       | 79 ++++++++++++++++++++++
 .../sklearn/SklearnPerceptronOpDescSpec.scala      | 79 ++++++++++++++++++++++
 4 files changed, 316 insertions(+)

diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionCVOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionCVOpDescSpec.scala
new file mode 100644
index 0000000000..24589453ed
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionCVOpDescSpec.scala
@@ -0,0 +1,79 @@
+/*
+ * 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.sklearn
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.operator.LogicalOp
+import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class SklearnLogisticRegressionCVOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnLogisticRegressionCVOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnLogisticRegressionCVOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Logistic Regression Cross Validation"
+    info.operatorDescription shouldBe "Sklearn Logistic Regression Cross 
Validation Operator"
+    info.operatorGroupName shouldBe OperatorGroupConstants.SKLEARN_GROUP
+    info.inputPorts.map(_.displayName) shouldBe List("training", "testing")
+    info.outputPorts should have length 1
+    info.outputPorts.head.blocking shouldBe true
+  }
+
+  "SklearnLogisticRegressionCVOpDesc" should "default its config fields" in {
+    val d = new SklearnLogisticRegressionCVOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnLogisticRegressionCVOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnLogisticRegressionCVOpDesc
+    val schema = 
d.getOutputSchemas(Map.empty)(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("model_name").getType shouldBe AttributeType.STRING
+    schema.getAttribute("model").getType shouldBe AttributeType.BINARY
+  }
+
+  "SklearnLogisticRegressionCVOpDesc.generatePythonCode" should "import the 
configured sklearn estimator" in {
+    val d = new SklearnLogisticRegressionCVOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.linear_model import 
LogisticRegressionCV")
+    code should include("make_pipeline")
+    code should include("Logistic Regression Cross Validation")
+  }
+
+  "SklearnLogisticRegressionCVOpDesc" should "round-trip its config fields 
through the polymorphic base" in {
+    val d = new SklearnLogisticRegressionCVOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnLogisticRegressionCV\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnLogisticRegressionCVOpDesc]
+    val r = restored.asInstanceOf[SklearnLogisticRegressionCVOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionOpDescSpec.scala
new file mode 100644
index 0000000000..077ecb9ac4
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLogisticRegressionOpDescSpec.scala
@@ -0,0 +1,79 @@
+/*
+ * 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.sklearn
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.operator.LogicalOp
+import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class SklearnLogisticRegressionOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnLogisticRegressionOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnLogisticRegressionOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Logistic Regression"
+    info.operatorDescription shouldBe "Sklearn Logistic Regression Operator"
+    info.operatorGroupName shouldBe OperatorGroupConstants.SKLEARN_GROUP
+    info.inputPorts.map(_.displayName) shouldBe List("training", "testing")
+    info.outputPorts should have length 1
+    info.outputPorts.head.blocking shouldBe true
+  }
+
+  "SklearnLogisticRegressionOpDesc" should "default its config fields" in {
+    val d = new SklearnLogisticRegressionOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnLogisticRegressionOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnLogisticRegressionOpDesc
+    val schema = 
d.getOutputSchemas(Map.empty)(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("model_name").getType shouldBe AttributeType.STRING
+    schema.getAttribute("model").getType shouldBe AttributeType.BINARY
+  }
+
+  "SklearnLogisticRegressionOpDesc.generatePythonCode" should "import the 
configured sklearn estimator" in {
+    val d = new SklearnLogisticRegressionOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.linear_model import LogisticRegression")
+    code should include("make_pipeline")
+    code should include("Logistic Regression")
+  }
+
+  "SklearnLogisticRegressionOpDesc" should "round-trip its config fields 
through the polymorphic base" in {
+    val d = new SklearnLogisticRegressionOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnLogisticRegression\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnLogisticRegressionOpDesc]
+    val r = restored.asInstanceOf[SklearnLogisticRegressionOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPassiveAggressiveOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPassiveAggressiveOpDescSpec.scala
new file mode 100644
index 0000000000..d184eb4367
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPassiveAggressiveOpDescSpec.scala
@@ -0,0 +1,79 @@
+/*
+ * 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.sklearn
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.operator.LogicalOp
+import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class SklearnPassiveAggressiveOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnPassiveAggressiveOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnPassiveAggressiveOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Passive Aggressive"
+    info.operatorDescription shouldBe "Sklearn Passive Aggressive Operator"
+    info.operatorGroupName shouldBe OperatorGroupConstants.SKLEARN_GROUP
+    info.inputPorts.map(_.displayName) shouldBe List("training", "testing")
+    info.outputPorts should have length 1
+    info.outputPorts.head.blocking shouldBe true
+  }
+
+  "SklearnPassiveAggressiveOpDesc" should "default its config fields" in {
+    val d = new SklearnPassiveAggressiveOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnPassiveAggressiveOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnPassiveAggressiveOpDesc
+    val schema = 
d.getOutputSchemas(Map.empty)(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("model_name").getType shouldBe AttributeType.STRING
+    schema.getAttribute("model").getType shouldBe AttributeType.BINARY
+  }
+
+  "SklearnPassiveAggressiveOpDesc.generatePythonCode" should "import the 
configured sklearn estimator" in {
+    val d = new SklearnPassiveAggressiveOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.linear_model import 
PassiveAggressiveClassifier")
+    code should include("make_pipeline")
+    code should include("Passive Aggressive")
+  }
+
+  "SklearnPassiveAggressiveOpDesc" should "round-trip its config fields 
through the polymorphic base" in {
+    val d = new SklearnPassiveAggressiveOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnPassiveAggressive\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnPassiveAggressiveOpDesc]
+    val r = restored.asInstanceOf[SklearnPassiveAggressiveOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPerceptronOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPerceptronOpDescSpec.scala
new file mode 100644
index 0000000000..b28a57c582
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnPerceptronOpDescSpec.scala
@@ -0,0 +1,79 @@
+/*
+ * 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.sklearn
+
+import org.apache.texera.amber.core.tuple.AttributeType
+import org.apache.texera.amber.operator.LogicalOp
+import org.apache.texera.amber.operator.metadata.OperatorGroupConstants
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+class SklearnPerceptronOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnPerceptronOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnPerceptronOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Linear Perceptron"
+    info.operatorDescription shouldBe "Sklearn Linear Perceptron Operator"
+    info.operatorGroupName shouldBe OperatorGroupConstants.SKLEARN_GROUP
+    info.inputPorts.map(_.displayName) shouldBe List("training", "testing")
+    info.outputPorts should have length 1
+    info.outputPorts.head.blocking shouldBe true
+  }
+
+  "SklearnPerceptronOpDesc" should "default its config fields" in {
+    val d = new SklearnPerceptronOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnPerceptronOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnPerceptronOpDesc
+    val schema = 
d.getOutputSchemas(Map.empty)(d.operatorInfo.outputPorts.head.id)
+    schema.getAttribute("model_name").getType shouldBe AttributeType.STRING
+    schema.getAttribute("model").getType shouldBe AttributeType.BINARY
+  }
+
+  "SklearnPerceptronOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnPerceptronOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.linear_model import Perceptron")
+    code should include("make_pipeline")
+    code should include("Linear Perceptron")
+  }
+
+  "SklearnPerceptronOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnPerceptronOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnPerceptron\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnPerceptronOpDesc]
+    val r = restored.asInstanceOf[SklearnPerceptronOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}

Reply via email to