Repository navigation
Add LocationProvider to determine data file locations. - #87
Conversation
|
@mccheah, here are the LocationProvider changes. Can you take a look? I didn't port your tests over. |
|
@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
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Why not just pass table and let WriterFactory extract all the required fields from it?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
I agree. I'll fix this in the PR. Thanks for reviewing!
|
Good to merge? (I don't have merge privileges) |
|
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) { |
There was a problem hiding this comment.
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Thanks for reviewing this, everyone! |
Updating spring due to a CVE (cherry picked from commit 07893c3904a21ee149b63c781176ca2fd3ad6799)
This is a different approach to the same problem that #73 addresses.