Skip to content

Check if metadata key exists and if so "Remove" before "add" #3611

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

Merged
merged 5 commits into from
Nov 21, 2023

Conversation

aymanhab
Copy link
Member

@aymanhab aymanhab commented Nov 16, 2023

Fixes issue #3589

Brief summary of changes

Actually it's possible to addMetaData for units but only if it doesn't exist. I modified the test case and the method in bindings to exercise this workflow. Will update the c3dExport file once we agree on what to include.

Testing I've completed

Updated Java test case to change units to Meters

Looking for feedback on...

Whether update the .i file considering that the name of the method starting with "add", or leave alone and update the test code/sample accordingly basically leaving door for future confusion!

CHANGELOG.md (choose one)

  • no need to update yet

This change is Reviewable

@aymanhab
Copy link
Member Author

@nickbianco for your review/feedback

@aymanhab aymanhab requested a review from nickbianco November 16, 2023 00:40
@nickbianco
Copy link
Member

@aymanhab, this change seems reasonable, but is there no way to simply update existing metadata values given a key, rather than removing then adding?

@@ -18,6 +18,9 @@ public static void test_C3DFileAdapter() {

// convert data to meters and write a copy
TimeSeriesTableVec3 markerTableInMeters = new TimeSeriesTableVec3(markerTable);
if (markerTableInMeters.hasTableMetaDataKey("Units"))
markerTableInMeters.removeTableMetaDataKey("Units");
Copy link
Member

@nickbianco nickbianco Nov 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the logic in this test necessary given the changes in common.i?

Edit: nevermind, I see that you implemented both possible changes for comparison.

@nickbianco
Copy link
Member

I think the ideal solution is to add a method like setTableMetaDataForKey to DataTable. It would update the table metadata object, which is a typedef'd ValueArrayDictionary, which already has the method setValueForKey. In other words, setTableMetaDataForKey would be a wrapper for setValueForKey.

@aymanhab
Copy link
Member Author

Unfortunately the documentation of the method in ValueArrayDictionary.h states
/** Set the value corresponding to a given key. Value is set only if the key
does not already exist. */

@nickbianco
Copy link
Member

Oh, weird. That's a poorly named method. Okay, I'm mostly fine with the change, it's just odd to have remove then add to just change a value.

One more suggestion: ValueArrayDictionary has updValueForKey which you can use to modify values. We could add a new method to AbstractDataTable called setTableMetaData (templated, in scripting it would be setTableMetaDataString) which modifies the meta data using updValueForKey. There is a mis-match in usages set and upd between the table and the meta data array here, but considering that there's already a mis-match in the current implementation (add versus set), I think this would be fine.

@aymanhab
Copy link
Member Author

aymanhab commented Nov 20, 2023

@nickbianco I agree about the wierdness ;)
Actually there's no updValueForKey there's only updValueArrayForKey, I was going to add the method but considering the unexpected naming (and cloning behavior underneath,) I'd lean to leave it as is and open an issue for future revamp. Please let me know what you think.

Another option is to add new method clearly named e.g. setValueForKeyEvenIfExists?

@nickbianco
Copy link
Member

@aymanhab, I see, updValueArrayForKey is not exactly what we want. In that case, I think your change to common.i is fine, especially since it's just on the bindings side. We can make a proper change sometime in the future.

@aymanhab
Copy link
Member Author

Sounds good, thanks @nickbianco 👍 I'll update changelog and then we can merge.

@nickbianco
Copy link
Member

nickbianco commented Nov 20, 2023

@aymanhab you should update the test to remove the extra code if you're keeping the common.i changes.

@aymanhab
Copy link
Member Author

@nickbianco test failure is another intermittent Moco failure on osx.

Copy link
Member

@nickbianco nickbianco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One quick change in the CHANGELOG, then LGTM

@aymanhab
Copy link
Member Author

Thanks @nickbianco

@aymanhab aymanhab merged commit 4b75cbc into main Nov 21, 2023
@aymanhab aymanhab deleted the fix_add_table_metadata branch November 21, 2023 01:31
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

Successfully merging this pull request may close these issues.

2 participants