-
Notifications
You must be signed in to change notification settings - Fork 38
Add util classes for data loader CLI #2616
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
This reverts commit 378effb.
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.
Pull Request Overview
A PR to add file and directory utility classes for the data loader CLI along with comprehensive tests and relevant error messages.
- Added FileUtils and DirectoryUtils for file path and directory validations.
- Updated related tests and command usage to reflect the new validation methods.
- Introduced new error codes and messages in CoreError for improved error handling.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
FileUtilsTest.java | Added tests for file path validation using FileUtils. |
DirectoryUtilsTest.java | Updated tests to use the new validateOrCreateTargetDirectory method. |
InvalidFilePathException.java | Introduced a custom exception for invalid file paths. |
FileUtils.java | Implemented a file path validation utility. |
DirectoryUtils.java | Implemented enhanced directory validation/creation and added working directory validation. |
ExportCommand.java | Updated directory validation method calls to use the new utility method. |
CoreError.java | Added multiple new error messages for the data loader CLI. |
Comments suppressed due to low confidence (2)
data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/util/FileUtilsTest.java:10
- [nitpick] Since this is a constant, consider renaming 'currentPath' to all uppercase (e.g., CURRENT_PATH) to follow Java naming conventions.
private static final String currentPath = Paths.get("").toAbsolutePath().toString();
core/src/main/java/com/scalar/db/common/error/CoreError.java:869
- There is a spacing issue in the error message ('and'--table' should likely be 'and '--table'') to improve readability.
DATA_LOADER_IMPORT_TARGET_MISSING( Category.USER_ERROR, "0189", "Missing option: either '--namespace' and'--table' options must be specified.", "", ""),
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, thank you!
if (!pathToCheck.isAbsolute()) { | ||
// If the path is not absolute, it's either a file name or a relative path | ||
Path currentDirectory = Paths.get("").toAbsolutePath(); | ||
Path fileInCurrentDirectory = currentDirectory.resolve(pathToCheck); |
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.
It's not sufficient to use only pathToCheck
without currentDirectory
?
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.
Yes, only need to check pathToCheck
exists. The specific condition is not required. I had added this in an early phase where I tried testing with a file name passed as an argument and that scenario is no longer required.
I have removed this part.
Thank you.
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.
Left several minor comments. PTAL!
*/ | ||
public static void validateFilePath(String filePath) throws InvalidFilePathException { | ||
if (StringUtils.isBlank(filePath)) { | ||
throw new IllegalArgumentException("File path must not be blank."); |
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.
Please move this message to CoreError
.
Path fileInCurrentDirectory = currentDirectory.resolve(pathToCheck); | ||
|
||
if (!fileInCurrentDirectory.toFile().exists()) { | ||
throw new InvalidFilePathException("File not found: " + pathToCheck); |
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.
Ditto.
|
||
// It's an absolute path | ||
if (!pathToCheck.toFile().exists()) { | ||
throw new InvalidFilePathException("File not found: " + pathToCheck); |
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.
Ditto.
@komamitsu san, @brfrn169 san, I have made changes based on the feedback. |
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! Thank you!
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! 👍
Co-authored-by: Peckstadt Yves <[email protected]> Co-authored-by: Toshihiro Suzuki <[email protected]>
Co-authored-by: Peckstadt Yves <[email protected]> Co-authored-by: Toshihiro Suzuki <[email protected]>
Co-authored-by: Peckstadt Yves <[email protected]> Co-authored-by: Toshihiro Suzuki <[email protected]>
Co-authored-by: Peckstadt Yves <[email protected]> Co-authored-by: Toshihiro Suzuki <[email protected]>
Co-authored-by: Peckstadt Yves <[email protected]> Co-authored-by: Toshihiro Suzuki <[email protected]>
Description
Adding file and directory util class for data loader CLI for validation.
Related issues and/or PRs
Please review this PR once the below PR is merged and the changes from master branch is updated in this branch
Changes made
Add a util classs to validate files, file path, log directory, write access to directory etc
Checklist
Additional notes (optional)
This is the first PR for data loader CLI
Release notes
NA