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

JENA-1454: Introduce builder pattern for result set reading and writing. #334

Merged
merged 5 commits into from
Dec 31, 2017

Conversation

afs
Copy link
Member

@afs afs commented Dec 22, 2017

Rework the machinery for ResultSet reading and writing to use a builder pattern (in ResultsReader and ResultsWriter). This is styled after RDFParse/RDFParserBuilder and RDFWriter/RDFWriterBuilder.

@afs
Copy link
Member Author

afs commented Dec 22, 2017

Needs some further cleanup before its ready to merge.

The main syntax forms, XML, JSON support read/write with a Context for passing in configuration. Thrift does anyway.

TSV, CSV, Text work in this framework but have not been deeply integrated.

All old mechanisms to access features specific to a syntax should still work.

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

Added a minor comment but change looks good, +1

throw new RiotException("No parser registered for content type: "+ct.getContentType()) ;
return reader.read(in, context) ;
public static ResultSet parse(String uri, Lang hintLang, Context context) {
ResultSet rs = ResultsReader.create().lang(hintLang).context(context).read(uri);
Copy link
Member

Choose a reason for hiding this comment

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

In the #readAny methods, there's a checkLang call to verify whether the language is not null and supported. Do we need this check in all other public methods that use a Lang object? Or just in the #readAny methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

All read public methods of ResultSetMgr that take a Lang use readAny so lang gets checked.

Adding a check to the write methods makes sense (now done in local working copy) because it's necessary (no default included, no legacy requirement).

ResultSetMgrisn't the main API (ResultSetFormatter is, albeit older and clunkier).

For parse, the method is only there because there was one before this upgrade. There isn't a "no lang" version. lang==null makes sense because the uri is used (conneg or file extension).

Some of the if ( rs == null ) checks are actually unnecessary because SPARQLResult does not return null, it throws an exception, but have been left in place in case that changes.

Copy link
Member

Choose a reason for hiding this comment

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

👍 makes sense. Happy to take another look once you say it's complete and ready to be merged. Thanks for the quick reply.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add checks to ResultReader and ResultWriter and use try-resource,

@afs
Copy link
Member Author

afs commented Dec 23, 2017

Cleaning up and switching to new reader/writer code now done.

This PR is now complete.

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

+1 one minor nit-pick. Everything else looking good.

throw new NotImplemented();
/** Write a boolean result, using the configurartion of the {@code ResultWriter}, to a file */
public void write(String filename, boolean booleanResult) {
Objects.requireNonNull(booleanResult);
Copy link
Member

Choose a reason for hiding this comment

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

Only minor nit-pick I found reviewing the commits added after my previous comment was here.

write(String filename, ResultSet resultSet) has requireNonNull(filename), and requireNonNull(resultSet). And in this method the filename is not checked for null. Not sure if it is intentional or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks - fixed. Testing the wrong argument; Objects.requireNonNull(booleanResult) is never null!

@kinow
Copy link
Member

kinow commented Dec 24, 2017

+1

@asfgit asfgit merged commit abb2d2c into apache:master Dec 31, 2017
asfgit pushed a commit that referenced this pull request Dec 31, 2017
@afs afs deleted the resultset-bnode branch December 31, 2017 10:54
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.

3 participants