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

Find By Atlas Identifier Sub Command #209

Merged
merged 15 commits into from
Sep 17, 2018

Conversation

Bentleysb
Copy link
Contributor

Description:

This adds an AtlasFindByAtlasIdentifierSubCommand. The command has two required and one optional parameter. Required are an input directory of Atlas shards, and a list of Atlas identifiers that are to be found. Optional is a output file. This command will output information to the console about each Atlas identifier found. This information includes the item type, containing shard, and tags. Additionally, the shards that contain the matched Atlas identifiers will be joined and saved if an output file is specified.

This command is based on the AtlasFindByFeatureIdentifierLocatorSubCommand, but differs in 3 mayor ways. First, the new command takes Atlas identifiers, instead of feature identifiers. This means that you need not know an entities type to search for it. Second, the feature identifier search only uses the OSM part of the numeric identifier. The Atlas identifier search uses all of the identifier, allowing for specific edges to be searched for (as opposed to all edges with that OSM id). Finally, the new command has an option to merge the shards where matching entities were found and output them as a single atlas. This is very useful when analyzing large areas that have been sharded, and that otherwise would be un-viewable due to memory constraints.

To accommodate the combining of the matched shards, the AtlasJoinerSubCommand is updated to have an optional parameter where shard names can be specified. When present, the shard names are used as a filter whereby only those shards from the specified input directory are joined.

Potential Impact:

Adds a useful command.
The AtlasJoinerSubCommand update is fully backwards compatible.

Unit Test Approach:

The AtlasFindByAtlasIdentifierSubCommand has its console output tested by capturing the output stream (using an new helper class) and searching for the expected Atlas shard names.

The original function of AtlasJoinerSubCommand and the new use in combination with AtlasFindByAtlasIdentifierSubCommand are tested by joining 3 and 2 tiny Atlas shards, respectively. The results are saved to temporary files and checked for any contents.

Test Results:

Verification of search and joining actions were verified using known shard names and visual inspection of new Atlas files in JOSM. All test results were positive.


In doubt: Contributing Guidelines

@Bentleysb
Copy link
Contributor Author

Closing and reopening to rerun Travis.

Copy link
Collaborator

@matthieun matthieun left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great @Bentleysb!
Only request is to translate the binary atlas files for testing into text atlas files (atlas.saveAsText(WritableResource)) so those can be Diffed in the future. Also you can use @TestAtlas(loadFromTextResource = "blah.atlas.txt") to get direct access to the Atlas files!

Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

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

Great stuff @Bentleysb - minor nits and suggestions along the way.

// If joining is requested and there are shards to join...
if (output.isPresent() && !this.shardNames.isEmpty())
{
System.out.printf("Joining...");
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe something more descriptive like "Stitching shards and saving to output {}"

* Object type
* @return {@link Predicate}
*/
private <T extends AtlasObject> Predicate<T> idCheck()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: id --> identifier to stay consistent with lack of abbreviations

*/
private <T extends AtlasObject> Predicate<T> idCheck()
{
return object -> this.ids.contains(((Long) object.getIdentifier()).toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to cast as Long and do a toString()? Why not just see if the Set of type Long contains the object identifier?

* {@link AtlasEntity} to create the string for
* @return formatted string
*/
private String formatAtlasObject(final Atlas atlas, final AtlasEntity entity)
Copy link
Contributor

Choose a reason for hiding this comment

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

We might be able to get away without passing in the Atlas, I believe every AtlasEntity should have a getAtlas() method, which will return the Atlas it belongs to.

new AtlasReader(args).runWithoutQuitting(args);

// Reset System.out
System.setOut(originalOut);
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance something goes wrong on lines 29-31 and we never reset System.out? Possible solution could be a try/catch/finally block.

@Bentleysb
Copy link
Contributor Author

@matthieun, unfortunately I don't think text atlases can be used here. AtlasFindByAtlasIdentifierSubCommand extends AbstractAtlasSubCommand and uses its execute method to load the atlas files from the -input flag. This method calls AtlasResourceLoader().load() to load the atlas files, and this only takes binary atlas files.
I would just recreate the execute method in the test code and change it to accept a text atlas, but all the methods it calls are protected. If you have any ideas about how to get around this (without changing AbstractAtlasSubCommand and all of its sub classes) that would be great, because even making those tiny binary atlases was a bit of a pain.

@matthieun
Copy link
Collaborator

The issue here is we cannot have tests rely on the current binary representation of Atlas files. Once default Atlas binary relies on protobuf arrays for example, those tests would fail. I see the problem you have here, those Atlas files need to be binary in a folder. What I'd suggest is still store them as text in Github, but have your test create a temporary folder in which to save the binary version from text, then run your test, and finally do a cleanup. Does that sound ok?

@Bentleysb
Copy link
Contributor Author

That makes sense and sounds like a plan. I will make that change.

MikeGost
MikeGost previously approved these changes Sep 15, 2018
Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

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

Thanks for the changes. Code looks good, barring a few nits.

}

@AfterClass
public static void deleteBianaryAtlases()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Bianary --> Binary

"The Atlas file to save the joined output to (optional). If not passed the found shards will not be joined and only appear in the console.",
String::toString, Command.Optionality.OPTIONAL);

private final Set<Long> ids = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: ids --> identifiers, to follow repo convention of no abbreviations.

@MikeGost MikeGost dismissed matthieun’s stale review September 17, 2018 16:11

Requested changes (txt files) were made.

Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

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

Final changes look good, thanks!

@MikeGost MikeGost merged commit d93f10b into osmlab:dev Sep 17, 2018
@matthieun
Copy link
Collaborator

Owww, the binary Atlas files stayed in the PR :( Will have to remove them later.

@Bentleysb Bentleysb mentioned this pull request Sep 19, 2018
@MikeGost
Copy link
Contributor

That was my mistake @matthieun - saw the txt files commit, but didn't check if the binary files were removed. Looks like @Bentleysb has followed up with a PR to remove them here: #222. Thanks!

@matthieun matthieun added this to the 5.1.12 milestone Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants