apache / apache/texera

Make HuggingFaceSpamSMSDetectionOpDesc consistent with the other legacy Hugging Face operators

Open
#8,482 1 comment 0 reactions 1 assignee Claimed by @PG1204 View on GitHub
Dominant language
Scala
Stars
314
Forks
187
Avg merge
1d 21h
Merged PRs (30d)
214

Description

### Task Summary

`HuggingFaceSpamSMSDetectionOpDesc.getOutputSchemas` is the only one of the four legacy Hugging Face operators that neither validates its result-attribute names nor keys the input schema by port id. Bring it in line with its siblings.

### Context

`getOutputSchemas` (HuggingFaceSpamSMSDetectionOpDesc.scala:87-95) is:

override def getOutputSchemas(
inputSchemas: Map[PortIdentity, Schema]
): Map[PortIdentity, Schema] = {
Map(
operatorInfo.outputPorts.head.id -> inputSchemas.values.head
.add(resultAttributeSpam, AttributeType.BOOLEAN)
.add(resultAttributeProbability, AttributeType.DOUBLE)
)
}

Two differences from the other three operators in the same package:

1. **No result-attribute validation.** `HuggingFaceSentimentAnalysisOpDesc` (L112-117) and `HuggingFaceIrisLogisticRegressionOpDesc` (L118-121) both check `x == null || x.trim.isEmpty` and return `null` before building the schema; `HuggingFaceTextSummarizationOpDesc` (L91-92) throws instead. This operator does neither, so an unset or blank name is passed straight into `Schema.add` and surfaces later, and less clearly, than in the sibling operators.

2. **`inputSchemas.values.head` instead of keying by port id.** The sibling operators use `inputSchemas(operatorInfo.inputPorts.head.id)`. With a single input port these are equivalent today, so this is a robustness and consistency point rather than a live defect, `values.head` depends on map iteration order rather than the declared port.

Note `EncodableString` is `String @EncodableStringAnnotation` (`PythonTemplateBuilder.scala:52`), so the sibling null/empty check applies unchanged here.

### Proposed change

Add the same null/empty guard the sibling operators use for `resultAttributeSpam` and `resultAttributeProbability`, and key the input schema by the declared input port id.

Match `HuggingFaceSentimentAnalysisOpDesc`'s `return null` rather than `HuggingFaceTextSummarizationOpDesc`'s throw: it is the majority behavior among the siblings, and `getOutputSchemas` is called while an operator is still being configured, where throwing would be noisy.

Unifying the error contract across all four operators where two return `null`, one throws, one does neither and is a larger discussion and is deliberately out of scope here.

### Required test

Extend `HuggingFaceSpamSMSDetectionOpDescSpec` to cover a null and a blank result-attribute name, and to assert the happy path still adds both columns to the input schema.

### Task Type

- [x] Refactor / Cleanup
- [ ] DevOps / Deployment / CI
- [ ] Testing / QA
- [ ] Documentation
- [ ] Performance
- [ ] Other

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.