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.table.format.cow;

import java.util.Comparator;
import org.apache.hudi.common.fs.FSUtils;
import org.apache.hudi.table.format.cow.vector.reader.ParquetColumnarRowSplitReader;
import org.apache.hudi.util.DataTypeUtils;
Expand All @@ -42,7 +43,6 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -214,13 +214,7 @@ public FileInputSplit[] createInputSplits(int minNumSplits) throws IOException {

// get the block locations and make sure they are in order with respect to their offset
final BlockLocation[] blocks = fs.getFileBlockLocations(file, 0, len);
Arrays.sort(blocks, new Comparator<BlockLocation>() {
@Override
public int compare(BlockLocation o1, BlockLocation o2) {
long diff = o1.getLength() - o2.getOffset();
return Long.compare(diff, 0L);
}
});
Arrays.sort(blocks, Comparator.comparingLong(BlockLocation::getOffset));

Copy link
Contributor

Choose a reason for hiding this comment

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

Does Arrays.sort(blocks, Comparator.comparingLong(BlockLocation::getOffset)); work here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, should work fine here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added the change

Copy link
Contributor

Choose a reason for hiding this comment

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

@voonhous I don't see the change of using comparingLong in the latest commit. Have you pushed your changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

My bad, i modified it to comparing instead of comparingLong.

I have added the required changes. Apologies.

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries. I'll merge this PR once CI passes. Thanks for the fix!

long bytesUnassigned = len;
long position = 0;
Expand Down Expand Up @@ -393,4 +387,5 @@ private InflaterInputStreamFactory<?> getInflaterInputStreamFactory(org.apache.h
return null;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hudi.table.format.cow;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

import java.util.Arrays;
import java.util.Comparator;
import org.apache.hadoop.fs.BlockLocation;
import org.junit.jupiter.api.Test;

public class TestBlockLocationSort {

private static BlockLocation createBlockLocation(int offset, int length) {
return new BlockLocation(new String[0], new String[0], offset, length);
}

@Test
void testBlockLocationSort() {
BlockLocation o1 = createBlockLocation(0, 5);
BlockLocation o2 = createBlockLocation(6, 4);
BlockLocation o3 = createBlockLocation(5, 5);

BlockLocation[] blocks = {o1, o2, o3};
BlockLocation[] sortedBlocks = {o1, o3, o2};

Arrays.sort(blocks, Comparator.comparingLong(BlockLocation::getOffset));
assertThat(blocks, equalTo(sortedBlocks));

// Sort again to ensure idempotency
Arrays.sort(blocks, Comparator.comparingLong(BlockLocation::getOffset));
assertThat(blocks, equalTo(sortedBlocks));
}

}