metafacture / metafacture-fix

Work in progress towards an implementation of the Fix language for Metafacture
Apache License 2.0
6 stars 2 forks source link

`paste` outputs values even when not all fields are provided #226

Open TobiasNx opened 2 years ago

TobiasNx commented 2 years ago

See here

I assumed that paste only outputs if all elements are provided. But it always pasts when a string is added even when none is provided.

Input:

1{a: Faust, b {n: Goethe, v: JW}, c: Weimar}
2{a: Räuber, b {n: Schiller, v: F}}

fix:

paste(author, b.v, b.n, '~aus', c)
retain(author)

output:

---
author: "JW Goethe aus Weimar"

---
author: "F Schiller aus"

expected:

---
author: "JW Goethe aus Weimar"

---
blackwinter commented 2 years ago

You marked this as a bug, but I for one am not entirely sure that it is. What is your expectation based on?

TobiasNx commented 2 years ago

okay, @blackwinter you are probably right this is no bug in the sense that Catmandu is behaving similarly: 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
...

None the less in my opinion this is not an intuitive behavior. As other functions paste demands path-references but instead of waiting to process until all paths are met it always creates output.

blackwinter commented 2 years ago

Let's see what LibreCat/Catmandu#392 yields. Or maybe we could add an option instead of changing the behaviour outright (similar in spirit to Metamorph's flushIncomplete="false", see metafacture/metafacture-core#332).

TobiasNx commented 2 years ago

Let's see what LibreCat/Catmandu#392 yields. Or maybe we could add an option instead of changing the behaviour outright (similar in spirit to Metamorph's flushIncomplete="false", see metafacture/metafacture-core#332).

I like the idea to add an option.