Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.hudi.client.functional;

import org.apache.hadoop.fs.Path;
import org.apache.hudi.common.model.HoodieTableType;
import org.apache.hudi.common.table.view.TableFileSystemView;
import org.apache.hudi.common.testutils.HoodieTestTable;
Expand Down Expand Up @@ -109,4 +110,17 @@ public void testMetadataTableKeyGenerator(final HoodieTableType tableType) throw
tableMetadata.getMetadataMetaClient().getTableConfig().getKeyGeneratorClassName());
}

/**
* [HUDI-2852] Table metadata returns empty for non-exist partition.
*/
@ParameterizedTest
@EnumSource(HoodieTableType.class)
public void testNotExistPartition(final HoodieTableType tableType) throws Exception {
init(tableType);
HoodieBackedTableMetadata tableMetadata = new HoodieBackedTableMetadata(context,
writeConfig.getMetadataConfig(), writeConfig.getBasePath(), writeConfig.getSpillableMapBasePath(), false);
FileStatus[] allFilesInPartition =
tableMetadata.getAllFilesInPartition(new Path(writeConfig.getBasePath() + "dummy"));
assertEquals(allFilesInPartition.length, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ private void initIfNeeded() {

@Override
protected Option<HoodieRecord<HoodieMetadataPayload>> getRecordByKey(String key, String partitionName) {
return getRecordsByKeys(Collections.singletonList(key), partitionName).get(0).getValue();
List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> recordsByKeys = getRecordsByKeys(Collections.singletonList(key), partitionName);
Copy link
Member

Choose a reason for hiding this comment

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

we get an exception now? is that the behavior?

return recordsByKeys.size() == 0 ? Option.empty() : recordsByKeys.get(0).getValue();
}

protected List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> getRecordsByKeys(List<String> keys, String partitionName) {
Expand All @@ -131,6 +132,10 @@ protected List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> getRec
HoodieFileReader baseFileReader = readers.getKey();
HoodieMetadataMergedLogRecordReader logRecordScanner = readers.getRight();

if (baseFileReader == null && logRecordScanner == null) {
return Collections.emptyList();
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't this return Collections.singletonList(Pair.of(key, Option.empty()))

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should not, the original code returns key based on the metadata data file content, but here we do not have any data file actually.

Copy link
Member

Choose a reason for hiding this comment

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

agree. with @danny0405 . that should be for empty partitions say.

}

// local map to assist in merging with base file records
Map<String, Option<HoodieRecord<HoodieMetadataPayload>>> logRecords = readLogRecords(logRecordScanner, keys, timings);
List<Pair<String, Option<HoodieRecord<HoodieMetadataPayload>>>> result = readFromBaseAndMergeWithLogRecords(
Expand Down Expand Up @@ -241,6 +246,10 @@ private Pair<HoodieFileReader, HoodieMetadataMergedLogRecordReader> openReadersI
// Metadata is in sync till the latest completed instant on the dataset
HoodieTimer timer = new HoodieTimer().startTimer();
List<FileSlice> latestFileSlices = HoodieTableMetadataUtil.loadPartitionFileGroupsWithLatestFileSlices(metadataMetaClient, partitionName);
if (latestFileSlices.size() == 0) {
// empty partition
return Pair.of(null, null);
Copy link
Member

Choose a reason for hiding this comment

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

returns nulls always make me nervous. Can we make the return type Option<Pair<>>? and return empty?

}
ValidationUtils.checkArgument(latestFileSlices.size() == 1, String.format("Invalid number of file slices: found=%d, required=%d", latestFileSlices.size(), 1));
final FileSlice slice = latestFileSlices.get(HoodieTableMetadataUtil.mapRecordKeyToFileGroupIndex(key, latestFileSlices.size()));

Expand Down