Skip to content

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

Merged
merged 29 commits into from
May 14, 2025
Merged

Conversation

inv-jishnu
Copy link
Contributor

@inv-jishnu inv-jishnu commented Apr 30, 2025

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

The following is a best-effort checklist. If any items in this checklist are not applicable to this PR or are dependent on other, unmerged PRs, please still mark the checkboxes after you have read and understood each item.

  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation to reflect the changes.
  • Any remaining open issues linked to this PR are documented and up-to-date (Jira, GitHub, etc.).
  • Tests (unit, integration, etc.) have been added for the changes.
  • My changes generate no new warnings.
  • Any dependent changes in other PRs have been merged and published.

Additional notes (optional)

This is the first PR for data loader CLI

Release notes

NA

@inv-jishnu inv-jishnu self-assigned this Apr 30, 2025
@inv-jishnu inv-jishnu marked this pull request as draft April 30, 2025 11:56
@inv-jishnu inv-jishnu added the enhancement New feature or request label Apr 30, 2025
Base automatically changed from feat/data-loader/import-log-2 to master May 8, 2025 04:09
Copy link

@Copilot Copilot AI left a 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.", "", ""),

@ypeckstadt ypeckstadt marked this pull request as ready for review May 12, 2025 05:26
Copy link
Contributor

@Torch3333 Torch3333 left a 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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

@brfrn169 brfrn169 left a 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.");
Copy link
Collaborator

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);
Copy link
Collaborator

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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto.

@inv-jishnu
Copy link
Contributor Author

@komamitsu san, @brfrn169 san,

I have made changes based on the feedback.
Please take a look at this again when you get a chance.
Thank you.

@inv-jishnu inv-jishnu requested review from komamitsu and brfrn169 May 13, 2025 11:08
Copy link
Collaborator

@brfrn169 brfrn169 left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you!

Copy link
Contributor

@komamitsu komamitsu left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@ypeckstadt ypeckstadt merged commit c242d80 into master May 14, 2025
55 checks passed
@ypeckstadt ypeckstadt deleted the feat/data-loader/cli-utils-2 branch May 14, 2025 07:48
feeblefakie pushed a commit that referenced this pull request May 14, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
inv-jishnu added a commit that referenced this pull request May 14, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
inv-jishnu added a commit that referenced this pull request May 14, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
inv-jishnu added a commit that referenced this pull request May 14, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
inv-jishnu added a commit that referenced this pull request May 14, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants