Skip to content
Open
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 @@ -407,6 +407,9 @@ protected List<InputSplit> createNInputSplitsUniform(InputSplit split, int n)

// Split Region into n chunks evenly
byte[][] splitKeys = Bytes.split(startRow, endRow, true, n - 1);
// Restore the original boundaries after using synthetic ones to calculate the split keys.
splitKeys[0] = ts.getStartRow();
splitKeys[splitKeys.length - 1] = ts.getEndRow();
for (int i = 0; i < splitKeys.length - 1; i++) {
// In the table input format for single table we do not need to
// store the scan object in table split because it can be memory intensive and redundant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.mapreduce;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
Expand All @@ -27,6 +28,7 @@
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
Expand All @@ -52,6 +54,7 @@
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand All @@ -62,6 +65,24 @@
@Tag(SmallTests.TAG)
public class TestTableInputFormatBase {

@Test
public void testCreateNInputSplitsUniformPreservesOriginalBoundaries() throws IOException {
TableInputFormat inputFormat = new TableInputFormat();
for (byte[] startRow : new byte[][] { HConstants.EMPTY_START_ROW, Bytes.toBytes("start") }) {
TableSplit split =
new TableSplit(TableName.valueOf("test"), startRow, HConstants.EMPTY_END_ROW, "localhost");

List<InputSplit> splits = inputFormat.createNInputSplitsUniform(split, 2);

assertEquals(2, splits.size());
TableSplit first = (TableSplit) splits.get(0);
TableSplit last = (TableSplit) splits.get(1);
assertArrayEquals(startRow, first.getStartRow());
assertArrayEquals(first.getEndRow(), last.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, last.getEndRow());
}
}

@Test
public void testReuseRegionSizeCalculator() throws IOException {
JobContext context = mock(JobContext.class);
Expand Down