Skip to content

Commit 14fef00

Browse files
committed
[HUDI-3984] Remove mandatory check of partiton path for cli command
1 parent 52953c8 commit 14fef00

5 files changed

Lines changed: 105 additions & 31 deletions

File tree

hudi-cli/src/main/java/org/apache/hudi/cli/commands/CompactionCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public String unscheduleCompaction(
558558
@CliCommand(value = "compaction unscheduleFileId", help = "UnSchedule Compaction for a fileId")
559559
public String unscheduleCompactFile(
560560
@CliOption(key = "fileId", mandatory = true, help = "File Id") final String fileId,
561-
@CliOption(key = "partitionPath", mandatory = true, help = "partition path") final String partitionPath,
561+
@CliOption(key = "partitionPath", unspecifiedDefaultValue = "", help = "partition path") final String partitionPath,
562562
@CliOption(key = "sparkMaster", unspecifiedDefaultValue = "local", help = "Spark Master") String master,
563563
@CliOption(key = "sparkMemory", unspecifiedDefaultValue = "2G", help = "executor memory") String sparkMemory,
564564
@CliOption(key = {"skipValidation"}, help = "skip validation", unspecifiedDefaultValue = "false") boolean skipV,

hudi-cli/src/main/java/org/apache/hudi/cli/commands/FileSystemViewCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public String showAllFileSlices(
119119

120120
@CliCommand(value = "show fsview latest", help = "Show latest file-system view")
121121
public String showLatestFileSlices(
122-
@CliOption(key = {"partitionPath"}, help = "A valid partition path", mandatory = true) String partition,
122+
@CliOption(key = {"partitionPath"}, help = "A valid partition path", unspecifiedDefaultValue = "") String partition,
123123
@CliOption(key = {"baseFileOnly"}, help = "Only display base file view",
124124
unspecifiedDefaultValue = "false") boolean baseFileOnly,
125125
@CliOption(key = {"maxInstant"}, help = "File-Slices upto this instant are displayed",

hudi-cli/src/main/java/org/apache/hudi/cli/commands/HDFSParquetImportCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public String convert(
5353
@CliOption(key = "tableName", mandatory = true, help = "Table name") final String tableName,
5454
@CliOption(key = "tableType", mandatory = true, help = "Table type") final String tableType,
5555
@CliOption(key = "rowKeyField", mandatory = true, help = "Row key field name") final String rowKeyField,
56-
@CliOption(key = "partitionPathField", mandatory = true,
56+
@CliOption(key = "partitionPathField", unspecifiedDefaultValue = "",
5757
help = "Partition path field name") final String partitionPathField,
5858
@CliOption(key = {"parallelism"}, mandatory = true,
5959
help = "Parallelism for hoodie insert") final String parallelism,

hudi-cli/src/main/java/org/apache/hudi/cli/commands/MetadataCommand.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public String listPartitions(
225225

226226
@CliCommand(value = "metadata list-files", help = "Print a list of all files in a partition from the metadata")
227227
public String listFiles(
228-
@CliOption(key = {"partition"}, help = "Name of the partition to list files", mandatory = true) final String partition) throws IOException {
228+
@CliOption(key = {"partition"}, help = "Name of the partition to list files", unspecifiedDefaultValue = "") final String partition) throws IOException {
229229
HoodieCLI.getTableMetaClient();
230230
HoodieMetadataConfig config = HoodieMetadataConfig.newBuilder().enable(true).build();
231231
HoodieBackedTableMetadata metaReader = new HoodieBackedTableMetadata(
@@ -235,8 +235,13 @@ public String listFiles(
235235
return "[ERROR] Metadata Table not enabled/initialized\n\n";
236236
}
237237

238+
Path partitionPath = new Path(HoodieCLI.basePath);
239+
if (partition.length() > 0) {
240+
partitionPath = new Path(HoodieCLI.basePath, partition);
241+
}
242+
238243
HoodieTimer timer = new HoodieTimer().startTimer();
239-
FileStatus[] statuses = metaReader.getAllFilesInPartition(new Path(HoodieCLI.basePath, partition));
244+
FileStatus[] statuses = metaReader.getAllFilesInPartition(partitionPath);
240245
LOG.debug("Took " + timer.endTimer() + " ms");
241246

242247
final List<Comparable[]> rows = new ArrayList<>();

hudi-cli/src/test/java/org/apache/hudi/cli/commands/TestFileSystemViewCommand.java

Lines changed: 95 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,73 @@
5959
@Tag("functional")
6060
public class TestFileSystemViewCommand extends CLIFunctionalTestHarness {
6161

62+
private String unpartitionedTablePath;
63+
private String partitionedTablePath;
6264
private String partitionPath;
63-
private SyncableFileSystemView fsView;
65+
private SyncableFileSystemView unpartitionedFsView;
66+
private SyncableFileSystemView partitionedFsView;
6467

6568
@BeforeEach
6669
public void init() throws IOException {
70+
createUnpartitionedTable();
71+
createPartitionedTable();
72+
}
73+
74+
private void createUnpartitionedTable() throws IOException {
6775
HoodieCLI.conf = hadoopConf();
6876

6977
// Create table and connect
70-
String tableName = tableName();
71-
String tablePath = tablePath(tableName);
78+
String unpartitionedTableName = "unpartitioned_" + tableName();
79+
unpartitionedTablePath = tablePath(unpartitionedTableName);
7280
new TableCommand().createTable(
73-
tablePath, tableName,
74-
"COPY_ON_WRITE", "", 1, "org.apache.hudi.common.model.HoodieAvroPayload");
81+
unpartitionedTablePath, unpartitionedTableName,
82+
"COPY_ON_WRITE", "", 1, "org.apache.hudi.common.model.HoodieAvroPayload");
83+
84+
HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
85+
86+
Files.createDirectories(Paths.get(unpartitionedTablePath));
87+
88+
// Generate 2 commits
89+
String commitTime1 = "3";
90+
String commitTime2 = "4";
91+
92+
String fileId1 = UUID.randomUUID().toString();
93+
94+
// Write date files and log file
95+
String testWriteToken = "2-0-2";
96+
Files.createFile(Paths.get(unpartitionedTablePath, FSUtils
97+
.makeDataFileName(commitTime1, testWriteToken, fileId1)));
98+
Files.createFile(Paths.get(unpartitionedTablePath, FSUtils
99+
.makeLogFileName(fileId1, HoodieLogFile.DELTA_EXTENSION, commitTime1, 0, testWriteToken)));
100+
Files.createFile(Paths.get(unpartitionedTablePath, FSUtils
101+
.makeDataFileName(commitTime2, testWriteToken, fileId1)));
102+
Files.createFile(Paths.get(unpartitionedTablePath, FSUtils
103+
.makeLogFileName(fileId1, HoodieLogFile.DELTA_EXTENSION, commitTime2, 0, testWriteToken)));
104+
105+
// Write commit files
106+
Files.createFile(Paths.get(unpartitionedTablePath, ".hoodie", commitTime1 + ".commit"));
107+
Files.createFile(Paths.get(unpartitionedTablePath, ".hoodie", commitTime2 + ".commit"));
108+
109+
// Reload meta client and create fsView
110+
metaClient = HoodieTableMetaClient.reload(metaClient);
111+
112+
unpartitionedFsView = new HoodieTableFileSystemView(metaClient, metaClient.getActiveTimeline(), true);
113+
}
114+
115+
private void createPartitionedTable() throws IOException {
116+
HoodieCLI.conf = hadoopConf();
117+
118+
// Create table and connect
119+
String partitionedTableName = "partitioned_" + tableName();
120+
partitionedTablePath = tablePath(partitionedTableName);
121+
new TableCommand().createTable(
122+
partitionedTablePath, partitionedTableName,
123+
"COPY_ON_WRITE", "", 1, "org.apache.hudi.common.model.HoodieAvroPayload");
75124

76125
HoodieTableMetaClient metaClient = HoodieCLI.getTableMetaClient();
77126

78127
partitionPath = HoodieTestCommitMetadataGenerator.DEFAULT_FIRST_PARTITION_PATH;
79-
String fullPartitionPath = Paths.get(tablePath, partitionPath).toString();
128+
String fullPartitionPath = Paths.get(partitionedTablePath, partitionPath).toString();
80129
Files.createDirectories(Paths.get(fullPartitionPath));
81130

82131
// Generate 2 commits
@@ -97,13 +146,13 @@ public void init() throws IOException {
97146
.makeLogFileName(fileId1, HoodieLogFile.DELTA_EXTENSION, commitTime2, 0, testWriteToken)));
98147

99148
// Write commit files
100-
Files.createFile(Paths.get(tablePath, ".hoodie", commitTime1 + ".commit"));
101-
Files.createFile(Paths.get(tablePath, ".hoodie", commitTime2 + ".commit"));
149+
Files.createFile(Paths.get(partitionedTablePath, ".hoodie", commitTime1 + ".commit"));
150+
Files.createFile(Paths.get(partitionedTablePath, ".hoodie", commitTime2 + ".commit"));
102151

103152
// Reload meta client and create fsView
104153
metaClient = HoodieTableMetaClient.reload(metaClient);
105154

106-
fsView = new HoodieTableFileSystemView(metaClient, metaClient.getActiveTimeline(), true);
155+
partitionedFsView = new HoodieTableFileSystemView(metaClient, metaClient.getActiveTimeline(), true);
107156
}
108157

109158
/**
@@ -116,7 +165,7 @@ public void testShowCommits() {
116165
assertTrue(cr.isSuccess());
117166

118167
// Get all file groups
119-
Stream<HoodieFileGroup> fileGroups = fsView.getAllFileGroups(partitionPath);
168+
Stream<HoodieFileGroup> fileGroups = partitionedFsView.getAllFileGroups(partitionPath);
120169

121170
List<Comparable[]> rows = new ArrayList<>();
122171
fileGroups.forEach(fg -> fg.getAllFileSlices().forEach(fs -> {
@@ -164,7 +213,7 @@ public void testShowCommitsWithSpecifiedValues() {
164213
assertTrue(cr.isSuccess());
165214

166215
List<Comparable[]> rows = new ArrayList<>();
167-
Stream<HoodieFileGroup> fileGroups = fsView.getAllFileGroups(partitionPath);
216+
Stream<HoodieFileGroup> fileGroups = partitionedFsView.getAllFileGroups(partitionPath);
168217

169218
// Only get instant 1, since maxInstant was specified 2
170219
fileGroups.forEach(fg -> fg.getAllFileSlices().filter(fs -> fs.getBaseInstantTime().equals("1")).forEach(fs -> {
@@ -197,17 +246,7 @@ public void testShowCommitsWithSpecifiedValues() {
197246
assertEquals(expected, got);
198247
}
199248

200-
/**
201-
* Test case for command 'show fsview latest'.
202-
*/
203-
@Test
204-
public void testShowLatestFileSlices() {
205-
// Test show with partition path '2016/03/15'
206-
CommandResult cr = shell().executeCommand("show fsview latest --partitionPath " + partitionPath);
207-
assertTrue(cr.isSuccess());
208-
209-
Stream<FileSlice> fileSlice = fsView.getLatestFileSlices(partitionPath);
210-
249+
private List<Comparable[]> fileSlicesToCRList(Stream<FileSlice> fileSlice, String partitionPath) {
211250
List<Comparable[]> rows = new ArrayList<>();
212251
fileSlice.forEach(fs -> {
213252
int idx = 0;
@@ -245,7 +284,14 @@ public void testShowLatestFileSlices() {
245284
.collect(Collectors.toList()).toString();
246285
rows.add(row);
247286
});
287+
return rows;
288+
}
248289

290+
/**(
291+
* Test case for command 'show fsview latest'.
292+
*/
293+
@Test
294+
public void testShowLatestFileSlices() throws IOException {
249295
Function<Object, String> converterFunction =
250296
entry -> NumericUtils.humanReadableByteCount((Double.parseDouble(entry.toString())));
251297
Map<String, Function<Object, String>> fieldNameToConverterMap = new HashMap<>();
@@ -267,9 +313,32 @@ public void testShowLatestFileSlices() {
267313
.addTableHeaderField(HoodieTableHeaderFields.HEADER_DELTA_BASE_UNSCHEDULED)
268314
.addTableHeaderField(HoodieTableHeaderFields.HEADER_DELTA_FILES_SCHEDULED)
269315
.addTableHeaderField(HoodieTableHeaderFields.HEADER_DELTA_FILES_UNSCHEDULED);
270-
String expected = HoodiePrintHelper.print(header, fieldNameToConverterMap, "", false, -1, false, rows);
271-
expected = removeNonWordAndStripSpace(expected);
272-
String got = removeNonWordAndStripSpace(cr.getResult().toString());
273-
assertEquals(expected, got);
316+
317+
// Test show with partition path '2016/03/15'
318+
new TableCommand().connect(partitionedTablePath, null, false, 0, 0, 0);
319+
CommandResult partitionedTableCR = shell().executeCommand("show fsview latest --partitionPath " + partitionPath);
320+
assertTrue(partitionedTableCR.isSuccess());
321+
322+
Stream<FileSlice> partitionedFileSlice = partitionedFsView.getLatestFileSlices(partitionPath);
323+
324+
List<Comparable[]> partitionedRows = fileSlicesToCRList(partitionedFileSlice, partitionPath);
325+
String partitionedExpected = HoodiePrintHelper.print(header, fieldNameToConverterMap, "", false, -1, false, partitionedRows);
326+
partitionedExpected = removeNonWordAndStripSpace(partitionedExpected);
327+
String partitionedResults = removeNonWordAndStripSpace(partitionedTableCR.getResult().toString());
328+
assertEquals(partitionedExpected, partitionedResults);
329+
330+
// Test show for unpartitioned table
331+
new TableCommand().connect(unpartitionedTablePath, null, false, 0, 0, 0);
332+
CommandResult unpartitionedTableCR = shell().executeCommand("show fsview latest");
333+
assertTrue(unpartitionedTableCR.isSuccess());
334+
335+
Stream<FileSlice> unpartitionedFileSlice = unpartitionedFsView.getLatestFileSlices("");
336+
337+
List<Comparable[]> unpartitionedRows = fileSlicesToCRList(unpartitionedFileSlice, "");
338+
339+
String unpartitionedExpected = HoodiePrintHelper.print(header, fieldNameToConverterMap, "", false, -1, false, unpartitionedRows);
340+
unpartitionedExpected = removeNonWordAndStripSpace(unpartitionedExpected);
341+
String unpartitionedResults = removeNonWordAndStripSpace(unpartitionedTableCR.getResult().toString());
342+
assertEquals(unpartitionedExpected, unpartitionedResults);
274343
}
275344
}

0 commit comments

Comments
 (0)