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

Lookup option default does not work #333

Open
TobiasNx opened this issue Nov 8, 2023 · 4 comments
Open

Lookup option default does not work #333

TobiasNx opened this issue Nov 8, 2023 · 4 comments

Comments

@blackwinter
Copy link
Member

The default key uses two underscores (__default) and it has to be defined on the map, not the lookup() call.

put_map("typeMap",
  "dog": "mammal",
  "parrot": "bird",
  "shark": "fish",
  __default: "other"
)

@TobiasNx
Copy link
Collaborator Author

TobiasNx commented Nov 8, 2023

okay, then this behaviour is different to catmandu:

lookup("title","dict.csv", default:test) # lookup 'marc' in dict.csv and replace the value or set it to 'test'

See: https://librecat.org/Catmandu/

@TobiasNx
Copy link
Collaborator Author

TobiasNx commented Nov 8, 2023

and the documentation is incorrect: https://github.com/metafacture/metafacture-fix#lookup

@blackwinter
Copy link
Member

blackwinter commented Nov 8, 2023

The name difference is a Metamorph relict, the behaviour should be adapted IMO (would be a behaviour change, though).

diff --git metafix/src/main/java/org/metafacture/metafix/FixMethod.java metafix/src/main/java/org/metafacture/metafix/FixMethod.java
index 0b185ca..56de7e9 100644
--- metafix/src/main/java/org/metafacture/metafix/FixMethod.java
+++ metafix/src/main/java/org/metafacture/metafix/FixMethod.java
@@ -516,7 +516,7 @@ public enum FixMethod implements FixFunction { // checkstyle-disable-line ClassD
                 map = metafix.getMap(mapName);
             }
 
-            final String defaultValue = map.get(Maps.DEFAULT_MAP_KEY); // TODO: Catmandu uses 'default'
+            final String defaultValue = options.getOrDefault(Maps.DEFAULT_MAP_KEY, map.get(Maps.DEFAULT_MAP_KEY)); // TODO: Catmandu uses 'default'
             final boolean delete = getBoolean(options, "delete");
             final boolean printUnknown = getBoolean(options, "print_unknown");

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

2 participants