-
Notifications
You must be signed in to change notification settings - Fork 325
Added the exists method to the FileSystem. #909
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
Conversation
@AFFogarty Sorry it took me some time to get this PR out. Please take a look and let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR, @sunildixit. I have left a few comments. 😃
using var tempDirectory = new TemporaryDirectory(); | ||
string path = Path.Combine(tempDirectory.Path, "temp-table"); | ||
|
||
_spark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this fit on one line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added it to one line.
|
||
Assert.NotNull(dataFile); | ||
|
||
Assert.True(fs.Exists(dataFile)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add an assertion to test that fs.Exists()
returns false
on a non-existent path?
For example you could do something like this:
string path = Path.Combine(tempDirectory.Path, "temp-table");
Assert.False(fs.Exists(path));
_spark.Range(25).Write().Csv(path);
Assert.True(fs.Exists(path));
That way, you prove that the Exists()
return value changes after writing to that path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I have added the assertion.
@@ -55,6 +55,14 @@ public bool Delete(string path, bool recursive = true) | |||
return (bool)_jvmObject.Invoke("delete", pathObject, recursive); | |||
} | |||
|
|||
public bool Exists(string path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a documentation comment describing the method? You can copy its content from open-source org.apache.hadoop.fs.FileSystem
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -52,5 +53,28 @@ public void TestDelete() | |||
|
|||
Assert.False(Directory.Exists(path)); | |||
} | |||
|
|||
[Fact] | |||
public void TestExists() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a documentation comment describing the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the documentation about the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks @sunildixit !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @sunildixit !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @sunildixit!
84b3a43
This PR adds the exists(string filePath) api to the FileSystem, which will allow the users to check whether a given folder or file exists in the file system or not.
I'll be adding more methods once I know, that I have done this work correctly.
Example: Check for an existing file
This PR relates to #328