Skip to content

Add export command for data loader CLI #2617

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 40 commits into from
May 22, 2025
Merged

Conversation

inv-jishnu
Copy link
Contributor

Description

In this PR I am adding data loader export command and command options for data export.

Related issues and/or PRs

Please review this PR once the below PRs is merged and latest changes from master are merged to this branch

Changes made

I have added the export command options and export command as a CLI command for data export

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 2nd PR for dataloader CLI

Release notes

NA

@inv-jishnu inv-jishnu added the enhancement New feature or request label Apr 30, 2025
@inv-jishnu inv-jishnu self-assigned this Apr 30, 2025
@inv-jishnu inv-jishnu changed the title Feat/data loader/cli export 2 Add export command for data loader CLI Apr 30, 2025
@inv-jishnu inv-jishnu marked this pull request as draft April 30, 2025 12:16
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

This PR adds a new export command to the data-loader CLI, implements related parsing utilities and converters, and updates tests and error definitions.

  • Introduces parseMultipleKeyValues in KeyUtils and related tests for multi-column key parsing.
  • Adds CLI parsing utilities (CommandLineInputUtils) and converters (SingleColumnKeyValueConverter, MultiColumnKeyValueConverter, ScanOrderingConverter).
  • Implements ExportCommand and ExportCommandOptions to handle export logic, file/path validation, and output formatting; updates tests and error codes.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
data-loader/core/src/main/java/com/scalar/db/dataloader/core/util/KeyUtils.java Added parseMultipleKeyValues to build a Key from multiple values
data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/KeyUtilsTest.java Added test for parseMultipleKeyValues
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/util/CommandLineInputUtils.java Added parseKeyValue and splitByDelimiter with error handling
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/SingleColumnKeyValueConverter.java New converter for single key-value CLI inputs
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/MultiColumnKeyValueConverter.java New converter for multi key-value CLI inputs
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ScanOrderingConverter.java New converter for scan ordering
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandOptions.java Defined CLI options for export command
data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommand.java Implemented export logic, path validation, manager creation
data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandTest.java Updated tests for blank and invalid config paths
core/src/main/java/com/scalar/db/common/error/CoreError.java Added new error codes for data loader CLI
Comments suppressed due to low confidence (2)

data-loader/core/src/test/java/com/scalar/db/dataloader/core/util/KeyUtilsTest.java:249

  • The test only asserts the column name; consider also verifying the parsed column value and the total number of columns to improve coverage for parseMultipleKeyValues.
assertEquals(c1, key.getColumnName(0));

data-loader/cli/src/test/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandTest.java:16

  • This cleanup method is not annotated (e.g., @AfterEach), so it won't run. Add the appropriate JUnit annotation to ensure test artifacts are removed.
void removeFileIfCreated() {

Comment on lines 218 to 220
* Convert a keyValue, in the format of <key>=<value>, to a ScalarDB Key instance.
*
* @param keyValues A list of key values in the format of <key>=<value>
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

The @param description is misleading: keyValues is a list of ColumnKeyValue objects, not raw strings. Update the documentation to reflect that.

Suggested change
* Convert a keyValue, in the format of <key>=<value>, to a ScalarDB Key instance.
*
* @param keyValues A list of key values in the format of <key>=<value>
* Convert a list of ColumnKeyValue objects to a ScalarDB Key instance.
*
* @param keyValues A list of ColumnKeyValue objects, where each object contains a column name
* and its corresponding value

Copilot uses AI. Check for mistakes.

validateOutputDirectory(outputFilePath);
return 0;
}
String scalarDbPropertiesFilePath = getScalarDbPropertiesFilePath();
Copy link
Preview

Copilot AI May 20, 2025

Choose a reason for hiding this comment

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

Tests expect an IllegalArgumentException when configFilePath is blank, but the current implementation catches all invalid file paths and returns an exit code. Add an explicit check for blank configFilePath and throw IllegalArgumentException with CoreError.DATA_LOADER_FILE_PATH_IS_BLANK to match test expectations.

Copilot uses AI. Check for mistakes.

* @return a {@link ColumnKeyValue} object representing the parsed key-value pair
* @throws IllegalArgumentException if the input is null, empty, or not in the expected format
*/
public static ColumnKeyValue parseKeyValue(String keyValue) {
Copy link
Contributor

@komamitsu komamitsu May 21, 2025

Choose a reason for hiding this comment

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

This class is CommandLineInputUtils and the method name is parseKeyValue(). So, it doesn't seem to return the specific type ColumnKeyValue. How about returning more generic type like Pair<K, V> or Tuple<K, V> (or Map.Entry<K, V>?) ?

See also #2617 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komamitsu san,
I have updated the util method implementation and also made changes to use the function to parse the scan order.
Thank you.

@inv-jishnu
Copy link
Contributor Author

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

@inv-jishnu inv-jishnu requested a review from komamitsu May 21, 2025 09:05
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! 👍

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 a minor comment. Other than that, LGTM! Thank you!

DATA_LOADER_INVALID_KEY_VALUE_INPUT(
Category.USER_ERROR, "0201", "Invalid key-value format: %s", "", ""),
DATA_LOADER_SPLIT_INPUT_VALUE_NULL(Category.USER_ERROR, "0202", "Value must not be null", "", ""),

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove this empty line.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brfrn169 san,
I have removed the empty line.
Thank you.

Copy link
Contributor

@ypeckstadt ypeckstadt 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

@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!

@ypeckstadt ypeckstadt merged commit 32179a6 into master May 22, 2025
55 checks passed
@ypeckstadt ypeckstadt deleted the feat/data-loader/cli-export-2 branch May 22, 2025 05:58
feeblefakie pushed a commit that referenced this pull request May 22, 2025
Co-authored-by: Peckstadt Yves <[email protected]>
Co-authored-by: Toshihiro Suzuki <[email protected]>
feeblefakie pushed a commit that referenced this pull request May 22, 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 22, 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 22, 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 22, 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