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-5945-abbe7a30244d6e50bc5ce7a89befcbc7a9d31c28
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 0c179ce6af7129442091fdda8d76ab3dc1e08fb7
Author: Xinyuan Lin <[email protected]>
AuthorDate: Thu Jun 25 09:28:56 2026 -0700

    test(workflow-operator): add unit test coverage for Sklearn SVM and 
neighbor classifier descriptors (#5945)
    
    ### What changes were proposed in this PR?
    
    Pin behavior of four previously-untested Sklearn support-vector and
    neighbor classifier descriptors in `common/workflow-operator`. No
    production-code changes.
    
    | Spec | Source class | Tests |
    | --- | --- | --- |
    | `SklearnSVMOpDescSpec` | `SklearnSVMOpDesc` | 5 |
    | `SklearnLinearSVMOpDescSpec` | `SklearnLinearSVMOpDesc` | 5 |
    | `SklearnKNNOpDescSpec` | `SklearnKNNOpDesc` | 5 |
    | `SklearnNearestCentroidOpDescSpec` | `SklearnNearestCentroidOpDesc` |
    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 classifier coverage in #5925, #5939, #5940,
    #5941).
    
    ### How was this PR tested?
    
    - `sbt "WorkflowOperator/testOnly *SklearnSVMOpDescSpec
    *SklearnLinearSVMOpDescSpec *SklearnKNNOpDescSpec
    *SklearnNearestCentroidOpDescSpec"` — 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])
---
 .../operator/sklearn/SklearnKNNOpDescSpec.scala    | 79 ++++++++++++++++++++++
 .../sklearn/SklearnLinearSVMOpDescSpec.scala       | 79 ++++++++++++++++++++++
 .../sklearn/SklearnNearestCentroidOpDescSpec.scala | 79 ++++++++++++++++++++++
 .../operator/sklearn/SklearnSVMOpDescSpec.scala    | 79 ++++++++++++++++++++++
 4 files changed, 316 insertions(+)

diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnKNNOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnKNNOpDescSpec.scala
new file mode 100644
index 0000000000..57dcc06be4
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnKNNOpDescSpec.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 SklearnKNNOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnKNNOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnKNNOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "K-nearest Neighbors"
+    info.operatorDescription shouldBe "Sklearn K-nearest Neighbors 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
+  }
+
+  "SklearnKNNOpDesc" should "default its config fields" in {
+    val d = new SklearnKNNOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnKNNOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnKNNOpDesc
+    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
+  }
+
+  "SklearnKNNOpDesc.generatePythonCode" should "import the configured sklearn 
estimator" in {
+    val d = new SklearnKNNOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.neighbors import KNeighborsClassifier")
+    code should include("make_pipeline")
+    code should include("K-nearest Neighbors")
+  }
+
+  "SklearnKNNOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnKNNOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnKNN\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnKNNOpDesc]
+    val r = restored.asInstanceOf[SklearnKNNOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLinearSVMOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLinearSVMOpDescSpec.scala
new file mode 100644
index 0000000000..d0153ae37f
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnLinearSVMOpDescSpec.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 SklearnLinearSVMOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnLinearSVMOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnLinearSVMOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Linear Support Vector Machine"
+    info.operatorDescription shouldBe "Sklearn Linear Support Vector Machine 
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
+  }
+
+  "SklearnLinearSVMOpDesc" should "default its config fields" in {
+    val d = new SklearnLinearSVMOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnLinearSVMOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnLinearSVMOpDesc
+    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
+  }
+
+  "SklearnLinearSVMOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnLinearSVMOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.svm import LinearSVC")
+    code should include("make_pipeline")
+    code should include("Linear Support Vector Machine")
+  }
+
+  "SklearnLinearSVMOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnLinearSVMOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnLinearSVM\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnLinearSVMOpDesc]
+    val r = restored.asInstanceOf[SklearnLinearSVMOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnNearestCentroidOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnNearestCentroidOpDescSpec.scala
new file mode 100644
index 0000000000..db61804a79
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnNearestCentroidOpDescSpec.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 SklearnNearestCentroidOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnNearestCentroidOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnNearestCentroidOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Nearest Centroid"
+    info.operatorDescription shouldBe "Sklearn Nearest Centroid 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
+  }
+
+  "SklearnNearestCentroidOpDesc" should "default its config fields" in {
+    val d = new SklearnNearestCentroidOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnNearestCentroidOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnNearestCentroidOpDesc
+    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
+  }
+
+  "SklearnNearestCentroidOpDesc.generatePythonCode" should "import the 
configured sklearn estimator" in {
+    val d = new SklearnNearestCentroidOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.neighbors import NearestCentroid")
+    code should include("make_pipeline")
+    code should include("Nearest Centroid")
+  }
+
+  "SklearnNearestCentroidOpDesc" should "round-trip its config fields through 
the polymorphic base" in {
+    val d = new SklearnNearestCentroidOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnNearestCentroid\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnNearestCentroidOpDesc]
+    val r = restored.asInstanceOf[SklearnNearestCentroidOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnSVMOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnSVMOpDescSpec.scala
new file mode 100644
index 0000000000..b1a7e9f3b0
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnSVMOpDescSpec.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 SklearnSVMOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnSVMOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnSVMOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Support Vector Machine"
+    info.operatorDescription shouldBe "Sklearn Support Vector Machine 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
+  }
+
+  "SklearnSVMOpDesc" should "default its config fields" in {
+    val d = new SklearnSVMOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnSVMOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnSVMOpDesc
+    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
+  }
+
+  "SklearnSVMOpDesc.generatePythonCode" should "import the configured sklearn 
estimator" in {
+    val d = new SklearnSVMOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.svm import SVC")
+    code should include("make_pipeline")
+    code should include("Support Vector Machine")
+  }
+
+  "SklearnSVMOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnSVMOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnSVM\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnSVMOpDesc]
+    val r = restored.asInstanceOf[SklearnSVMOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}

Reply via email to