Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of bind list is not a correct if array provided contains only one item #331

Open
aquast opened this issue Nov 8, 2023 · 8 comments

Comments

@aquast
Copy link

aquast commented Nov 8, 2023

If I use the do list command with an array of one item the result differs from an array of n items.

It looks like the command can not be executed correctly with an array of one.

Please see attached files

Attachments.zip

@aquast aquast changed the title Behavior of list bind is not the same (correct) if array contains only one item Behavior of bind list is not a correct if array provided contains only one item Nov 8, 2023
@TobiasNx
Copy link
Collaborator

TobiasNx commented Nov 8, 2023

I had a quick look at the transformation.
Try to use the list-bind like this:

input:

  "test" : [ {
    "key" : [ "value", "more_value", "even_more_value" ],
    "foo" : "bar1",
    "test": "test1"
  }, {
    "key" : [ "less_value", "little_value", "no_value" ],
    "foo" : "bar2",
    "test": "test2"
  } ]
do list(path:"test[]","var":"$i")
  move_field("$i.foo","$i.dc:foo")
end

output:

  "test" : [ {
    "key" : [ "value", "more_value", "even_more_value" ],
    "dc:foo" : "bar1",
    "test": "test1"
  }, {
    "key" : [ "less_value", "little_value", "no_value" ],
    "dc:foo" : "bar2",
    "test": "test2"
  } ]

You do not have root access if you do not use the "var" option. (Hint: unfortunatly the only option in fix that needs " is var)

@TobiasNx
Copy link
Collaborator

TobiasNx commented Nov 8, 2023

@aquast I tried to fix your workflow:

https://metafacture.org/playground/?flux=%22https%3A//raw.githubusercontent.com/TobiasNx/metafacture_workflows/master/EDM2ESJsonBulk/Attachments/example1.xml%22%0A%7C+open-http%0A%7C+decode-xml%0A%7C+handle-generic-xml%28emitnamespace%3D%22true%22%29%0A%7C+fix%28transformationFile%29%0A%7C+encode-yaml%0A%7C+print%0A%3B&transformation=copy_field%28%22header.identifier.value%22%2C+%22id%22%29%0Aremove_field%28%22header%22%29%0A%0Amove_field%28%22metadata.ns1%3ARDF.ns2%3AProvidedCHO%22%2C+%22rdf%3ARDF.edm%3AProvidedCHO%5B%5D%22%29%0A%0Ado+list%28path%3A+%22rdf%3ARDF.edm%3AProvidedCHO%5B%5D%22%2C%22var%22%3A%22%24i%22%29%0A++set_array%28%22%24i.dc%3Atitle%5B%5D%22%29%0A++set_array%28%22%24i.dc%3Atitle%5B%5D.%24append%22%29%0A++move_field%28%22%24i.ns3%3Atitle.value%22%2C+%22%24i.dc%3Atitle%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Atitle%22%29%0A%0A++set_array%28%22%24i.dcterms%3Aalternative%5B%5D%22%29%0A++move_field%28%22%24i.dcterms%3Aalternative.value%22%2C+%22%24i.dcterms%3Aalternative%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.dcterms%3Aalternative%22%29%0A++set_array%28%22%24i.dc%3Acreator%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Acreator.value%22%2C+%22%24i.dc%3Acreator%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Acreator%22%29%0A++set_array%28%22%24i.dc%3Acontributor%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Acontributor.value%22%2C+%22%24i.dc%3Acontributor%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Acontributor%22%29%0A++set_array%28%22%24i.dc%3Adescription%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Adescription.value%22%2C+%22%24i.dc%3Adescription%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Adescription%22%29%0A++set_array%28%22%24i.dc%3Asubject%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Asubject.value%22%2C+%22%24i.dc%3Asubject%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Asubject%22%29%0A++set_array%28%22%24i.dc%3Acoverage%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Acoverage.value%22%2C+%22%24i.dc%3Acoverage%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Acoverage%22%29%0A++set_array%28%22%24i.dc%3Apublisher%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Apublisher.value%22%2C+%22%24i.dc%3Apublisher%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Apublisher%22%29%0A++move_field%28%22%24i.ns3%3ArightsHolder.value%22+%2C%22%24i.dc%3ArightsHolder%22%29++%0A++remove_field%28%22%24i.ns3%3ArightsHolder%22%29%0A++set_array%28%22%24i.dcterms%3Aextent%5B%5D%22%29%0A++move_field%28%22%24i.dcterms%3Aextent.value%22%2C+%22%24i.dcterms%3Aextent%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3Aextent%22%29%0A++set_array%28%22%24i.dc%3Alanguage%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Alanguage.value%22%2C+%22%24i.dc%3Alanguage%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Alanguage%22%29%0A++set_array%28%22%24i.dcterms%3Aprovenance%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Aprovenance.value%22%2C+%22%24i.dcterms%3Aprovenance%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3Aprovenance%22%29%0A++set_array%28%22%24i.dcterms%3Amedium%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Amedium.value%22%2C+%22%24i.dcterms%3Amedium%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.dcterms%3Amedium%22%29%0A++set_array%28%22%24i.dcterms%3AtableOfContent%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3AtableOfContent.value%22%2C+%22%24i.dcterms%3AtableOfContent%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3AtableOfContent%22%29%0A++%0A%0A++move_field%28%22%24i.ns3%3Aidentifier.value%22+%2C%22%24i.dc%3Aidentifier%5B%5D%22%29%0A++remove_field%28%22%24i.ns3%3Aidentifier%22%29%0A++set_array%28%22%24i.dc%3Aformat%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Aformat.value%22%2C+%22%24i.dc%3Aformat%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Aformat%22%29%0A++set_array%28%22%24i.dcterms%3AhasFormat%5B%5D%22%29%0A++move_field%28%22%24i.dcterms%3AhasFormat.value%22%2C+%22%24i.dcterms%3AhasFormat%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3AhasFormatvalue%22%29%0A++set_array%28%22%24i.dc%3Arights%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Arights.value%22%2C+%22%24i.dc%3Arights%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Arights%22%29%0A++set_array%28%22%24i.dcterms%3AisPartOf%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3AisPartOf.value%22%2C+%22%24i.dcterms%3AisPartOf%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3AisPartOf%22%29%0A++move_field%28%22%24i.ns2%3Atype.value%22+%2C%22%24i.edm%3Atype%22%29++%0A++remove_field%28%22%24i.ns2%3Atype%22%29%0A++move_field%28%22%24i.ns3%3Atype.value%22+%2C%22%24i.dc%3Atype%22%29++%0A++remove_field%28%22%24i.ns3%3Atype%22%29%0A++set_array%28%22%24i.dcterms%3Aspatial%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Aspatial.value%22+%2C%22%24i.dcterms%3Aspatial%5B%5D.%24append%22%29++%0A++remove_field%28%22%24i.ns4%3Aspatial%22%29%0A++set_array%28%22%24i.dcterms%3Atemporal%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Atemporal.value%22+%2C%22%24i.dcterms%3Atemporal%5B%5D.%24append%22%29++%0A++remove_field%28%22%24i.ns4%3Atemporal%22%29%0A++set_array%28%22%24i.dc_source%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Asource.value%22%2C+%22%24i.dc_source%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Asource%22%29%0A%0A++set_array%28%22%24i.dc%3Adate%5B%5D%22%29%0A++move_field%28%22%24i.ns3%3Adate.value%22%2C+%22%24i.dc%3Adate%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns3%3Adate%22%29%0A++set_array%28%22%24i.dcterms%3Acreated%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Acreated.value%22%2C+%22%24i.dcterms%3Acreated%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3Acreated%22%29%0A++set_array%28%22%24i.dcterms%3Aissued%5B%5D%22%29%0A++move_field%28%22%24i.ns4%3Aissued.value%22%2C+%22%24i.dcterms%3Aissued%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.ns4%3Aissued%22%29%0A++%0A++remove_field%28%22%24i.ns4%3AhasPart%22%29%0A++remove_field%28%22%24i.ns2%3AhasType%22%29%0A++%0Aend%0A%0Amove_field%28%22metadata.ns1%3ARDF.ns10%3AAggregation%22%2C+%22rdf%3ARDF.ore%3AAggregation%5B%5D%22%29%0A%0Ado+list%28path%3A+%22rdf.ore%3AAggregation%5B%5D%22%2C+%22var%22%3A%22%24i%22%29%0A++set_array%28%22%24i.edm%3Arights%5B%5D%22%29%0A++move_field%28%22%24i.rights.resource%22%2C+%22%24i.edm%3Arights%5B%5D.%24append%22%29%0A++remove_field%28%22%24i.rights%22%29%0A++move_field%28%22%24i.dataProvider.1.value%22%2C+%22%24i.edm%3AdataProvider%22%29++%0A++remove_field%28%22%24i.dataProvider%22%29%0Aend%0A%0Avacuum%28%29%0A

If you want to create a new array, it is best to use a set_array and move the field with an $append into the new array.

@aquast
Copy link
Author

aquast commented Nov 8, 2023

Hi @TobiasNx ,

your proposal with "var" solved the issue for me. So maybe it's an issue of documentation rather than coding

Thank you : (thumbs up)

@TobiasNx
Copy link
Collaborator

TobiasNx commented Nov 8, 2023

Hi @TobiasNx ,

your proposal with "var" solved the issue for me. So maybe it's an issue of documentation rather than coding

Thank you : (thumbs up)

@aquast
also have a look at my playground link.
if you are working with newly created arrays, you should use set_array("newArray[]") and copy or move values like this into it: copy_field("oldField.value","newArray[].$append")

@TobiasNx
Copy link
Collaborator

TobiasNx commented Nov 8, 2023

@blackwinter: should we delete the documentation of the list-bind without variable since it is not very useful?

@blackwinter
Copy link
Member

should we delete the documentation of the list-bind without variable since it is not very useful?

No, I don't think so. It's certainly limited as long as we don't support the . path operator, but there might still be legitimate use cases (which I don't recall off the top of my head).

@aquast
Copy link
Author

aquast commented Nov 8, 2023

Thank you for all your feedback.

If you asked me as a newbie user I'd like to have the list-bind without var with respect to my growing learners skills. Additionaly having a code example with "var":"value" as parameter would serve me better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants