nextflow-io / nextflow-io/nextflow
`record.subMap` can return either a `RecordMap` or a `LinkedHashMap` depending on key input
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 3.5k
- Forks
- 811
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 61
Description
Bug report
The record.subMap method accepts a key iterable with the expectation that a record is returned. However, this is only the case if the keys are enclosed in [..]. In the event that it is not provided as a list, the type is silently converted to a LinkedHashMap.
Expected behavior and actual behavior
nextflow.enable.types = true
workflow {
main:
def records: Channel<Record> = channel.of(record(id: "example", value: "value1"))
records.map{ r: Record ->
def subMapFromList: Record = r.subMap(["id"])
def subMapFromString: Record = r.subMap("id")
println("subMap(['id']) -> value: ${subMapFromList}, type: ${subMapFromList.getClass()}")
println("subMap('id') -> value: ${subMapFromString}, type: ${subMapFromString.getClass()}")
}
}
In the above code, the first output is the expected behavior. Keys provided in the subMap call for a record return a record as the output.
The 2nd output shows the actual behavior when subMap is provided a key / set of keys outside of a list. Instead of returning a record, this is silently converted to a LinkedHashMap.
Steps to reproduce the problem
See above.
Program output
N E X T F L O W ~ version 26.04.6
Launching `tmp.nf` [gloomy_minsky] revision: 6cce971aed
WARN: Static typing is a preview feature -- syntax and behavior may change in future releases
subMap(['id']) -> value: [id:example], type: class nextflow.util.RecordMap
subMap('id') -> value: [id:example], type: class java.util.LinkedHashMap
Environment
- Nextflow version: 26.04.6
- Java version: openjdk 17
- Operating system: Linux
- Bash version: zsh 5.8.1 (x86_64-ubuntu-linux-gnu)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducer in the issue and inspect the implementation of record.subMap and the RecordMap type, comparing calls with a list key and a string key. Done means both forms return a RecordMap-compatible record with the same selected values, with coverage for the two key-input cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100