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

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

    test(workflow-operator): add unit test coverage for Sklearn tree-based 
classifier descriptors (#5939)
    
    ### What changes were proposed in this PR?
    
    Pin behavior of four previously-untested Sklearn tree-based classifier
    descriptors in `common/workflow-operator`. No production-code changes.
    
    | Spec | Source class | Tests |
    | --- | --- | --- |
    | `SklearnDecisionTreeOpDescSpec` | `SklearnDecisionTreeOpDesc` | 5 |
    | `SklearnExtraTreeOpDescSpec` | `SklearnExtraTreeOpDesc` | 5 |
    | `SklearnExtraTreesOpDescSpec` | `SklearnExtraTreesOpDesc` | 5 |
    | `SklearnRandomForestOpDescSpec` | `SklearnRandomForestOpDesc` | 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 *SklearnDecisionTreeOpDescSpec
    *SklearnExtraTreeOpDescSpec *SklearnExtraTreesOpDescSpec
    *SklearnRandomForestOpDescSpec"` — 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])
---
 .../sklearn/SklearnDecisionTreeOpDescSpec.scala    | 79 ++++++++++++++++++++++
 .../sklearn/SklearnExtraTreeOpDescSpec.scala       | 79 ++++++++++++++++++++++
 .../sklearn/SklearnExtraTreesOpDescSpec.scala      | 79 ++++++++++++++++++++++
 .../sklearn/SklearnRandomForestOpDescSpec.scala    | 79 ++++++++++++++++++++++
 4 files changed, 316 insertions(+)

diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnDecisionTreeOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnDecisionTreeOpDescSpec.scala
new file mode 100644
index 0000000000..44fbf1aeed
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnDecisionTreeOpDescSpec.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 SklearnDecisionTreeOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnDecisionTreeOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnDecisionTreeOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Decision Tree"
+    info.operatorDescription shouldBe "Sklearn Decision Tree 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
+  }
+
+  "SklearnDecisionTreeOpDesc" should "default its config fields" in {
+    val d = new SklearnDecisionTreeOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnDecisionTreeOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnDecisionTreeOpDesc
+    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
+  }
+
+  "SklearnDecisionTreeOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnDecisionTreeOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.tree import DecisionTreeClassifier")
+    code should include("make_pipeline")
+    code should include("Decision Tree")
+  }
+
+  "SklearnDecisionTreeOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnDecisionTreeOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnDecisionTree\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnDecisionTreeOpDesc]
+    val r = restored.asInstanceOf[SklearnDecisionTreeOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreeOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreeOpDescSpec.scala
new file mode 100644
index 0000000000..96b9ec470b
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreeOpDescSpec.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 SklearnExtraTreeOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnExtraTreeOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnExtraTreeOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Extra Tree"
+    info.operatorDescription shouldBe "Sklearn Extra Tree 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
+  }
+
+  "SklearnExtraTreeOpDesc" should "default its config fields" in {
+    val d = new SklearnExtraTreeOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnExtraTreeOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnExtraTreeOpDesc
+    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
+  }
+
+  "SklearnExtraTreeOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnExtraTreeOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.tree import ExtraTreeClassifier")
+    code should include("make_pipeline")
+    code should include("Extra Tree")
+  }
+
+  "SklearnExtraTreeOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnExtraTreeOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnExtraTree\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnExtraTreeOpDesc]
+    val r = restored.asInstanceOf[SklearnExtraTreeOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreesOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreesOpDescSpec.scala
new file mode 100644
index 0000000000..332bee1ee3
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnExtraTreesOpDescSpec.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 SklearnExtraTreesOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnExtraTreesOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnExtraTreesOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Extra Trees"
+    info.operatorDescription shouldBe "Sklearn Extra Trees 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
+  }
+
+  "SklearnExtraTreesOpDesc" should "default its config fields" in {
+    val d = new SklearnExtraTreesOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnExtraTreesOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnExtraTreesOpDesc
+    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
+  }
+
+  "SklearnExtraTreesOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnExtraTreesOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.ensemble import ExtraTreesClassifier")
+    code should include("make_pipeline")
+    code should include("Extra Trees")
+  }
+
+  "SklearnExtraTreesOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnExtraTreesOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnExtraTrees\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnExtraTreesOpDesc]
+    val r = restored.asInstanceOf[SklearnExtraTreesOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}
diff --git 
a/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnRandomForestOpDescSpec.scala
 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnRandomForestOpDescSpec.scala
new file mode 100644
index 0000000000..2f19aff0ad
--- /dev/null
+++ 
b/common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/sklearn/SklearnRandomForestOpDescSpec.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 SklearnRandomForestOpDescSpec extends AnyFlatSpec with Matchers {
+
+  "SklearnRandomForestOpDesc.operatorInfo" should
+    "advertise the model name, Sklearn group, and the training/testing port 
shape" in {
+    val info = (new SklearnRandomForestOpDesc).operatorInfo
+    info.userFriendlyName shouldBe "Random Forest"
+    info.operatorDescription shouldBe "Sklearn Random Forest 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
+  }
+
+  "SklearnRandomForestOpDesc" should "default its config fields" in {
+    val d = new SklearnRandomForestOpDesc
+    d.countVectorizer shouldBe false
+    d.tfidfTransformer shouldBe false
+    d.target shouldBe null
+    d.text shouldBe null
+  }
+
+  "SklearnRandomForestOpDesc.getOutputSchemas" should
+    "emit the model_name/model schema keyed by the declared output port" in {
+    val d = new SklearnRandomForestOpDesc
+    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
+  }
+
+  "SklearnRandomForestOpDesc.generatePythonCode" should "import the configured 
sklearn estimator" in {
+    val d = new SklearnRandomForestOpDesc
+    d.target = "y"
+    val code = d.generatePythonCode()
+    code should include("from sklearn.ensemble import RandomForestClassifier")
+    code should include("make_pipeline")
+    code should include("Random Forest")
+  }
+
+  "SklearnRandomForestOpDesc" should "round-trip its config fields through the 
polymorphic base" in {
+    val d = new SklearnRandomForestOpDesc
+    d.target = "label"
+    d.countVectorizer = true
+    val json = objectMapper.writeValueAsString(d)
+    json should include("\"operatorType\":\"SklearnRandomForest\"")
+    val restored = objectMapper.readValue(json, classOf[LogicalOp])
+    restored shouldBe a[SklearnRandomForestOpDesc]
+    val r = restored.asInstanceOf[SklearnRandomForestOpDesc]
+    r.target shouldBe "label"
+    r.countVectorizer shouldBe true
+  }
+}

Reply via email to