Skip to content

Add LocationProvider to determine data file locations. - #87

Merged
rdblue merged 2 commits into
apache:masterfrom
rdblue:add-custom-locations
Feb 7, 2019
Merged

rdblue merged 2 commits into
apache:masterfrom
rdblue:add-custom-locations

Conversation

@rdblue

@rdblue rdblue commented Jan 28, 2019

Copy link
Copy Markdown
Contributor

This is a different approach to the same problem that #73 addresses.

@rdblue

rdblue commented Jan 28, 2019

Copy link
Copy Markdown
Contributor Author

@mccheah, here are the LocationProvider changes. Can you take a look? I didn't port your tests over.

@rdblue

rdblue commented Jan 28, 2019

Copy link
Copy Markdown
Contributor Author

@Parth-Brahmbhatt, FYI. This adds an interface that provides data file locations so the table implementation can control them. Eventually, it would be good if Presto supported that pattern.

@mccheah mccheah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall looks good. Had a minor question. Also, should we to write tests that use something other than the default location provider?

public DataWriterFactory<InternalRow> createWriterFactory() {
return new WriterFactory(table.spec(), format, dataLocation(), table.properties(), fileIo);
return new WriterFactory(
table.spec(), format, table.locationProvider(), table.properties(), fileIo);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not just pass table and let WriterFactory extract all the required fields from it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Serialization?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Serialization. WriterFactory has to be Serializable and Table isn't Serializable. We could pass Table to its constructor, assuming that the implementation knows not to keep a reference to it, but I think it is cleaner and more maintainable to not pass non-serializable objects in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah I misread sorry, thought this was at the top level of Writer - this is correct then.

private static String stripTrailingSlash(String path) {
String result = path;
while (result.endsWith("/")) {
result = result.substring(0, path.length() - 1);

@fbocse fbocse Feb 4, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this is a bug - this may not work as expected, I think it goes into an infinite loop for strings ending with more than one slash, i.e. stripTrailingSlash("trailing/slash//////") cause path.length doesn't change when iterating, so decrementing it yields same result every time, right?

To have the iterations converge to the expected result you're probably looking for
result = result.substring(0, result.length() - 1);

trim result=trailing/slash//////
trim result=trailing/slash/////
trim result=trailing/slash////
trim result=trailing/slash///
trim result=trailing/slash//
trim result=trailing/slash/
trailing/slash

P.S. > I could be adding a unit test for this particular case and bring up a PR for this branch, thought that's probably way too ceremonial for this minor fix though

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree. I'll fix this in the PR. Thanks for reviewing!

@mccheah

mccheah commented Feb 6, 2019

Copy link
Copy Markdown
Contributor

Good to merge? (I don't have merge privileges)

@rdblue

rdblue commented Feb 6, 2019

Copy link
Copy Markdown
Contributor Author

I still need a committer +1 on this since the community prefers review-then-commit. I'll ping some people to get reviews. Thanks for bumping this.

}
}

private static String stripTrailingSlash(String path) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't have a direct dependency on commons-lang3 and I'd rather not add one for just a few methods.

* <p>
* Implementations must be {@link Serializable} because instances will be serialized to tasks.
*/
public interface LocationProvider extends Serializable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason the provider always expects a filename? Can we have a method that just takes the tablename and properties as input and returns the top level path as well and metadata location as well? Essentially we should be able to replace metadataFileLocation method from BaseMetastoreTableOperations and all the path related constants can be moved to this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The provider expects a filename so that engines can pass context in the file name. Flink and Spark add context to the file path. Spark, for example, uses the partition number, the task attempt ID, and a UUID that will correspond to the Spark query UUID. That way, we can trace data back to specific tasks and Spark ensures that its attempt files don't conflict.

We (Matt and I) tried different variations of this that accepted metadata and we think that this is the cleanest and most flexible approach because the data passed to the location provider isn't limited to data in the table. The TableOperations that returns a LocationProvider can configure it using any table data or external data. That way, we don't have to keep updating the interface with new metadata that a particular implementation needs. The LocationProvider is created and configured by TableOperations at the time a new write needs one.

metadataFileLocation is handled separately because it doesn't need to be publicly exposed. We may move it eventually, but I want to keep this commit small.

@rdblue
rdblue merged commit 65ffbc4 into apache:master Feb 7, 2019
@rdblue

rdblue commented Feb 7, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for reviewing this, everyone!

InvisibleProgrammer pushed a commit to InvisibleProgrammer/iceberg that referenced this pull request Mar 10, 2023
Updating spring due to a CVE

(cherry picked from commit 07893c3904a21ee149b63c781176ca2fd3ad6799)
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.

4 participants