Closed axtimwalde closed 1 year ago
There are currently two nearly identical methods in N5KeyValueReader
public JsonElement getAttributes(String)
protected JsonElement readAttributes(String)
There are currently two nearly identical methods in
N5KeyValueReader
public JsonElement getAttributes(String)
protected JsonElement readAttributes(String)
- we should get rid of this one
I agree, I removed that one.
Working with the KeyValueAccess
API, I wanted to suggest some changes. There are quite a few methods that are fairly specific to file systems, and don't abstract well. For example:
public boolean isDirectory(String normalPath);
public boolean isFile(String normalPath);
public String[] listDirectories(final String normalPath) throws IOException;
public void createDirectories(final String normalPath) throws IOException;
I think it would be more general to remove isFile
and to change the Directory
related methods to isGroup
, listGroups
, and createGroups
. These will still be directories in the case of FS based N5, but may be non-directory backed keys for other access backends (S3, H5, etc.)
Working with the
KeyValueAccess
API, I wanted to suggest some changes. There are quite a few methods that are fairly specific to file systems, and don't abstract well. For example:public boolean isDirectory(String normalPath); public boolean isFile(String normalPath); public String[] listDirectories(final String normalPath) throws IOException; public void createDirectories(final String normalPath) throws IOException;
I think it would be more general to remove
isFile
and to change theDirectory
related methods toisGroup
,listGroups
, andcreateGroups
. These will still be directories in the case of FS based N5, but may be non-directory backed keys for other access backends (S3, H5, etc.)
Per a chat with @axtimwalde and @bogovicj, there are reasons to keep directory related methods. Namely, to emulate some of the FileSystem primitives that are necessary to abstract the backend storage as a KeyValue Access
Good catch, I'll fix that!
Found an issue with removeAttribute
- it seems only to work for the root directory right now.
If I add this to the test it fails:
writer.createGroup("foo");
writer.setAttribute("foo", "a", 100);
writer.removeAttribute("foo", "a");
assertNull(writer.getAttribute("foo", "a", Integer.class));
expect it to be a simple fix. Fixed by 36ba7ae below.
assorted thoughts:
datasetExists
currently throws IOException
because it calls getDatasetAttributes
which also does.
Why not have datasetExists
catch the exception and return false in that case?
the key value reader implementation probably doesn't need to check if dataset attributes exist, and can just let it fail if it doesn't - from @cmhulbert
datasetExists
can call getDatasetAttributes
only without checking for group existence. Consider making N5KeyValueReader
and N5KeyValueWriter
abstract with abstract checkVersion
method.
N5Factory
upstreamIn discussion with
Separate Gson and KeyValueReader
elements. Make an interface called : CachedGsonN5KeyValueReader
or similar that N5KeyValueReader
implements.
Edit: we decided against this. For one 550fe32, replaces the GsonN5Reader/Writer interfaces with GsonUtils
In talking with @cmhulbert , it may be that we want to use N5URL.normalizePath
in the N5Readers / Writers, and keyValueAccess.normalize
(and remove leading slashes) for paths within the container that are used by the cache.
Edit: see https://github.com/saalfeldlab/n5/tree/cache-normalization
Currently we're seeing this behavior here
N5Writer n5 = ...
n5.setAttribute(groupName, "key", 0.1);
n5.getAttribute(groupName, "key", Integer.class )); // returns 0 (i.e. rounds rather than return null)
The issue seems to be deep in Gson https://github.com/google/gson/blob/29c93895bbcaed02178abc9e3d47b73878aaca73/gson/src/main/java/com/google/gson/internal/LazilyParsedNumber.java#L42
@cmhulbert will want to ask you about this when you have time https://github.com/saalfeldlab/n5/pull/77/commits/7c37cf9f6b6f05df143eb00ae58f97dc04e3dd25
Re the discussion on zulip,
We could consider adding a protected constructor to N5KeyValueReader
that skips the version check. This could let us avoid sneaking in the static initializeContainer
in the N5KeyValueWriter
constructor before its superclass (N5KeyValueReader
) constructor is called. See here:
@axtimwalde , branch of interest: https://github.com/saalfeldlab/n5/tree/wip/KeyValueInterface
N5KeyValueReader
and no longer needs a static initializeContainer
method (details above and on zulip)@cmhulbert , Looking at the cache again, I think some (hopefully small) edits are needed for writing. Specifically, what happens now on on group / dataset creation (I think), is:
N5JsonCachableContainer
) instead of funcitons / consumers for the cache: https://github.com/saalfeldlab/n5/commit/069ceda0a745c1f343499ae3904a7982c66f3155I ran this benchmark comparing the current master https://github.com/saalfeldlab/n5/commit/a1fcd2f6b3be7e1e10b08aaeba3912ffb5707d8c to the latest development commit https://github.com/saalfeldlab/n5/commit/d14fe554178b180cea4aeba50013c245c0b39b8b . In summary: they're comparable.
Filesystem abstraction and meta data caching