Skip to content

Commit 7a43860

Browse files
authored
Add deprecated Data Loader CLI arguments (#3041)
1 parent aac0d47 commit 7a43860

File tree

9 files changed

+484
-6
lines changed

9 files changed

+484
-6
lines changed

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommand.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.scalar.db.dataloader.cli.command.dataexport;
22

3+
import static com.scalar.db.dataloader.cli.util.CommandLineInputUtils.validateDeprecatedOptionPair;
34
import static com.scalar.db.dataloader.cli.util.CommandLineInputUtils.validatePositiveValue;
45
import static java.nio.file.StandardOpenOption.APPEND;
56
import static java.nio.file.StandardOpenOption.CREATE;
@@ -51,6 +52,8 @@ public class ExportCommand extends ExportCommandOptions implements Callable<Inte
5152

5253
@Override
5354
public Integer call() throws Exception {
55+
validateDeprecatedOptions();
56+
applyDeprecatedOptions();
5457
String scalarDbPropertiesFilePath = getScalarDbPropertiesFilePath();
5558

5659
try {
@@ -107,6 +110,24 @@ public Integer call() throws Exception {
107110
return 0;
108111
}
109112

113+
/**
114+
* Validates that deprecated and new options are not both specified.
115+
*
116+
* @throws CommandLine.ParameterException if both old and new options are specified
117+
*/
118+
private void validateDeprecatedOptions() {
119+
validateDeprecatedOptionPair(
120+
spec.commandLine(),
121+
DEPRECATED_START_EXCLUSIVE_OPTION,
122+
START_INCLUSIVE_OPTION,
123+
START_INCLUSIVE_OPTION_SHORT);
124+
validateDeprecatedOptionPair(
125+
spec.commandLine(),
126+
DEPRECATED_END_EXCLUSIVE_OPTION,
127+
END_INCLUSIVE_OPTION,
128+
END_INCLUSIVE_OPTION_SHORT);
129+
}
130+
110131
private String getScalarDbPropertiesFilePath() {
111132
if (StringUtils.isBlank(configFilePath)) {
112133
throw new IllegalArgumentException(DataLoaderError.CONFIG_FILE_PATH_BLANK.buildMessage());

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataexport/ExportCommandOptions.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
public class ExportCommandOptions {
1111

1212
protected static final String DEFAULT_CONFIG_FILE_NAME = "scalardb.properties";
13+
public static final String START_INCLUSIVE_OPTION = "--start-inclusive";
14+
public static final String START_INCLUSIVE_OPTION_SHORT = "-si";
15+
public static final String DEPRECATED_START_EXCLUSIVE_OPTION = "--start-exclusive";
16+
public static final String END_INCLUSIVE_OPTION = "--end-inclusive";
17+
public static final String END_INCLUSIVE_OPTION_SHORT = "-ei";
18+
public static final String DEPRECATED_END_EXCLUSIVE_OPTION = "--end-exclusive";
1319

1420
@CommandLine.Option(
1521
names = {"--config", "-c"},
@@ -87,6 +93,14 @@ public class ExportCommandOptions {
8793
// TODO: test that -si false, works
8894
protected boolean scanStartInclusive;
8995

96+
// Deprecated option - kept for backward compatibility
97+
@CommandLine.Option(
98+
names = {DEPRECATED_START_EXCLUSIVE_OPTION},
99+
description = "Deprecated: Use --start-inclusive instead (inverted logic)",
100+
hidden = true)
101+
@Deprecated
102+
protected Boolean startExclusiveDeprecated;
103+
90104
@CommandLine.Option(
91105
names = {"--end-key", "-ek"},
92106
paramLabel = "<KEY=VALUE>",
@@ -100,6 +114,14 @@ public class ExportCommandOptions {
100114
defaultValue = "true")
101115
protected boolean scanEndInclusive;
102116

117+
// Deprecated option - kept for backward compatibility
118+
@CommandLine.Option(
119+
names = {DEPRECATED_END_EXCLUSIVE_OPTION},
120+
description = "Deprecated: Use --end-inclusive instead (inverted logic)",
121+
hidden = true)
122+
@Deprecated
123+
protected Boolean endExclusiveDeprecated;
124+
103125
@CommandLine.Option(
104126
names = {"--sort-by", "-s"},
105127
paramLabel = "<SORT_ORDER>",
@@ -144,4 +166,23 @@ public class ExportCommandOptions {
144166
description = "Size of the data chunk to process in a single task (default: 200)",
145167
defaultValue = "200")
146168
protected int dataChunkSize;
169+
170+
/**
171+
* Applies deprecated option values if they are set.
172+
*
173+
* <p>This method is called AFTER validateDeprecatedOptions(), so we are guaranteed that both the
174+
* deprecated and new options were not specified together. If we reach this point, only the
175+
* deprecated option was provided by the user.
176+
*/
177+
public void applyDeprecatedOptions() {
178+
// If the deprecated option is set, use its value (inverted logic)
179+
if (startExclusiveDeprecated != null) {
180+
scanStartInclusive = !startExclusiveDeprecated;
181+
}
182+
183+
// If the deprecated option is set, use its value (inverted logic)
184+
if (endExclusiveDeprecated != null) {
185+
scanEndInclusive = !endExclusiveDeprecated;
186+
}
187+
}
147188
}

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.scalar.db.dataloader.cli.command.dataimport;
22

3+
import static com.scalar.db.dataloader.cli.util.CommandLineInputUtils.validateDeprecatedOptionPair;
34
import static com.scalar.db.dataloader.cli.util.CommandLineInputUtils.validatePositiveValue;
45

56
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -52,6 +53,8 @@ public class ImportCommand extends ImportCommandOptions implements Callable<Inte
5253

5354
@Override
5455
public Integer call() throws Exception {
56+
validateDeprecatedOptions();
57+
applyDeprecatedOptions();
5558
validateImportTarget(controlFilePath, namespace, tableName);
5659
validateLogDirectory(logDirectory);
5760
validatePositiveValue(
@@ -272,6 +275,19 @@ private Optional<ControlFile> parseControlFileFromPath(String controlFilePath) {
272275
}
273276
}
274277

278+
/**
279+
* Validates that deprecated and new options are not both specified.
280+
*
281+
* @throws ParameterException if both old and new options are specified
282+
*/
283+
private void validateDeprecatedOptions() {
284+
validateDeprecatedOptionPair(
285+
spec.commandLine(),
286+
DEPRECATED_THREADS_OPTION,
287+
MAX_THREADS_OPTION,
288+
MAX_THREADS_OPTION_SHORT);
289+
}
290+
275291
/**
276292
* Generate import options object from provided cli parameter data
277293
*

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/command/dataimport/ImportCommandOptions.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
public class ImportCommandOptions {
1010

1111
public static final String FILE_OPTION_NAME_LONG_FORMAT = "--file";
12+
public static final String MAX_THREADS_OPTION = "--max-threads";
13+
public static final String MAX_THREADS_OPTION_SHORT = "-mt";
14+
public static final String DEPRECATED_THREADS_OPTION = "--threads";
1215

1316
@CommandLine.Option(
1417
names = {"--mode", "-m"},
@@ -39,6 +42,15 @@ public class ImportCommandOptions {
3942
defaultValue = "16")
4043
protected int maxThreads;
4144

45+
// Deprecated option - kept for backward compatibility
46+
@CommandLine.Option(
47+
names = {DEPRECATED_THREADS_OPTION},
48+
paramLabel = "<THREADS>",
49+
description = "Deprecated: Use --max-threads instead",
50+
hidden = true)
51+
@Deprecated
52+
protected Integer threadsDeprecated;
53+
4254
@CommandLine.Option(
4355
names = {"--namespace", "-ns"},
4456
paramLabel = "<NAMESPACE>",
@@ -158,4 +170,18 @@ public class ImportCommandOptions {
158170
description = "Maximum number of data chunks that can be kept at a time for processing",
159171
defaultValue = "256")
160172
protected int dataChunkQueueSize;
173+
174+
/**
175+
* Applies deprecated option values if they are set.
176+
*
177+
* <p>This method is called AFTER validateDeprecatedOptions(), so we are guaranteed that both the
178+
* deprecated and new options were not specified together. If we reach this point, only the
179+
* deprecated option was provided by the user.
180+
*/
181+
public void applyDeprecatedOptions() {
182+
// If the deprecated option is set, use its value
183+
if (threadsDeprecated != null) {
184+
maxThreads = threadsDeprecated;
185+
}
186+
}
161187
}

data-loader/cli/src/main/java/com/scalar/db/dataloader/cli/util/CommandLineInputUtils.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,30 @@ public static void validatePositiveValue(
6161
throw new CommandLine.ParameterException(commandLine, error.buildMessage());
6262
}
6363
}
64+
65+
/**
66+
* Validates that a deprecated option and its replacement are not both specified. If both options
67+
* are detected, it throws a {@link picocli.CommandLine.ParameterException} with an appropriate
68+
* error message.
69+
*
70+
* @param commandLine the {@link CommandLine} instance used to provide context for the exception
71+
* @param deprecatedOption the deprecated option name
72+
* @param newOption the new option name
73+
* @param newOptionShort the short form of the new option name
74+
* @throws CommandLine.ParameterException if both deprecated and new options are specified
75+
*/
76+
public static void validateDeprecatedOptionPair(
77+
CommandLine commandLine, String deprecatedOption, String newOption, String newOptionShort) {
78+
boolean hasDeprecated = commandLine.getParseResult().hasMatchedOption(deprecatedOption);
79+
boolean hasNew =
80+
commandLine.getParseResult().hasMatchedOption(newOption)
81+
|| commandLine.getParseResult().hasMatchedOption(newOptionShort);
82+
83+
if (hasDeprecated && hasNew) {
84+
throw new CommandLine.ParameterException(
85+
commandLine,
86+
DataLoaderError.DEPRECATED_AND_NEW_OPTION_BOTH_SPECIFIED.buildMessage(
87+
deprecatedOption, newOption, newOption));
88+
}
89+
}
6490
}

0 commit comments

Comments
 (0)