LibreCat / Catmandu

Catmandu - a data processing toolkit
https://librecat.org
175 stars 31 forks source link

`paste` processes when not all or none of the path are provided #392

Closed TobiasNx closed 1 year ago

TobiasNx commented 2 years ago

paste outputs values/elements even if there not all or none of the expected elements are provided by an record. I would expect that it would only process if all elements are provided and not if none or only some are provided.

Is this intentional behaviour of paste?

input:

{
  "name": "Blacky",
  "type" : "bird"
}
{
  "name" : "Test",
  "test_1" : "test_1"
}
{
  "test_1" : "test_1",
  "test_2" : "test_2"
}

without additional string:

$ catmandu convert JSON  --fix 'paste("combine", "name", "type")' to YAML < input.json 
---
combine: Blacky bird
name: Blacky
type: bird
...
---
combine: Test
name: Test
test_1: test_1
...
---
combine: ''
test_1: test_1
test_2: test_2
...

with additional string:

$ catmandu convert JSON  --fix 'paste("combine", "name", "~is a", "type")' to YAML < input.json 
---
combine: Blacky is a bird
name: Blacky
type: bird
...
---
combine: Test is a
name: Test
test_1: test_1
...
---
combine: is a
test_1: test_1
test_2: test_2
...

I would have expected:

---
combine: Blacky is a bird [Blacky bird]
name: Blacky
type: bird
...
---
name: Test
test_1: test_1
...
---
test_1: test_1
test_2: test_2
...
phochste commented 1 year ago

Yes, this is the intended behaviour. The paste command will create a new path with the other arguments as template (even when they don't exist). I'll document this