[HUDI-624]: Split some of the code from PR for HUDI-479 (#1344)
This commit is contained in:
@@ -18,9 +18,8 @@
|
||||
|
||||
package org.apache.hudi.common.model;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* HoodieKey consists of
|
||||
@@ -58,12 +57,12 @@ public class HoodieKey implements Serializable {
|
||||
return false;
|
||||
}
|
||||
HoodieKey otherKey = (HoodieKey) o;
|
||||
return Objects.equal(recordKey, otherKey.recordKey) && Objects.equal(partitionPath, otherKey.partitionPath);
|
||||
return Objects.equals(recordKey, otherKey.recordKey) && Objects.equals(partitionPath, otherKey.partitionPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(recordKey, partitionPath);
|
||||
return Objects.hash(recordKey, partitionPath);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,11 +20,11 @@ package org.apache.hudi.common.model;
|
||||
|
||||
import org.apache.hudi.common.util.Option;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A Single Record managed by Hoodie.
|
||||
@@ -141,13 +141,13 @@ public class HoodieRecord<T extends HoodieRecordPayload> implements Serializable
|
||||
return false;
|
||||
}
|
||||
HoodieRecord that = (HoodieRecord) o;
|
||||
return Objects.equal(key, that.key) && Objects.equal(data, that.data)
|
||||
&& Objects.equal(currentLocation, that.currentLocation) && Objects.equal(newLocation, that.newLocation);
|
||||
return Objects.equals(key, that.key) && Objects.equals(data, that.data)
|
||||
&& Objects.equals(currentLocation, that.currentLocation) && Objects.equals(newLocation, that.newLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(key, data, currentLocation, newLocation);
|
||||
return Objects.hash(key, data, currentLocation, newLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,9 +18,8 @@
|
||||
|
||||
package org.apache.hudi.common.model;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Location of a HoodieRecord within the partition it belongs to. Ultimately, this points to an actual file on disk
|
||||
@@ -44,12 +43,12 @@ public class HoodieRecordLocation implements Serializable {
|
||||
return false;
|
||||
}
|
||||
HoodieRecordLocation otherLoc = (HoodieRecordLocation) o;
|
||||
return Objects.equal(instantTime, otherLoc.instantTime) && Objects.equal(fileId, otherLoc.fileId);
|
||||
return Objects.equals(instantTime, otherLoc.instantTime) && Objects.equals(fileId, otherLoc.fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(instantTime, fileId);
|
||||
return Objects.hash(instantTime, fileId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -268,11 +268,7 @@ public final class BufferedRandomAccessFile extends RandomAccessFile {
|
||||
this.seek(this.currentPosition);
|
||||
|
||||
// if currentPosition is at start, EOF has been reached
|
||||
if (this.currentPosition == this.validLastPosition) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return this.currentPosition != this.validLastPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,6 +47,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
@@ -248,7 +249,7 @@ public class FSUtils {
|
||||
}
|
||||
|
||||
public static String getFileExtension(String fullName) {
|
||||
Preconditions.checkNotNull(fullName);
|
||||
Objects.requireNonNull(fullName);
|
||||
String fileName = (new File(fullName)).getName();
|
||||
int dotIndex = fileName.indexOf('.');
|
||||
return dotIndex == -1 ? "" : fileName.substring(dotIndex);
|
||||
|
||||
@@ -16,12 +16,6 @@
|
||||
|
||||
package org.apache.hudi.common.util;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.MemoryPoolMXBean;
|
||||
import java.lang.reflect.Array;
|
||||
@@ -29,9 +23,13 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Deque;
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -121,16 +119,9 @@ public class ObjectSizeCalculator {
|
||||
// added.
|
||||
private final int superclassFieldPadding;
|
||||
|
||||
private final LoadingCache<Class<?>, ClassSizeInfo> classSizeInfos =
|
||||
CacheBuilder.newBuilder().build(new CacheLoader<Class<?>, ClassSizeInfo>() {
|
||||
@Override
|
||||
public ClassSizeInfo load(Class<?> clazz) {
|
||||
return new ClassSizeInfo(clazz);
|
||||
}
|
||||
});
|
||||
private final Map<Class<?>, ClassSizeInfo> classSizeInfos = new IdentityHashMap<>();
|
||||
|
||||
|
||||
private final Set<Object> alreadyVisited = Sets.newIdentityHashSet();
|
||||
private final Set<Object> alreadyVisited = Collections.newSetFromMap(new IdentityHashMap<>());
|
||||
private final Deque<Object> pending = new ArrayDeque<>(16 * 1024);
|
||||
private long size;
|
||||
|
||||
@@ -140,7 +131,7 @@ public class ObjectSizeCalculator {
|
||||
* @param memoryLayoutSpecification a description of the JVM memory layout.
|
||||
*/
|
||||
public ObjectSizeCalculator(MemoryLayoutSpecification memoryLayoutSpecification) {
|
||||
Preconditions.checkNotNull(memoryLayoutSpecification);
|
||||
Objects.requireNonNull(memoryLayoutSpecification);
|
||||
arrayHeaderSize = memoryLayoutSpecification.getArrayHeaderSize();
|
||||
objectHeaderSize = memoryLayoutSpecification.getObjectHeaderSize();
|
||||
objectPadding = memoryLayoutSpecification.getObjectPadding();
|
||||
@@ -175,6 +166,15 @@ public class ObjectSizeCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
private ClassSizeInfo getClassSizeInfo(final Class<?> clazz) {
|
||||
ClassSizeInfo csi = classSizeInfos.get(clazz);
|
||||
if (csi == null) {
|
||||
csi = new ClassSizeInfo(clazz);
|
||||
classSizeInfos.put(clazz, csi);
|
||||
}
|
||||
return csi;
|
||||
}
|
||||
|
||||
private void visit(Object obj) {
|
||||
if (alreadyVisited.contains(obj)) {
|
||||
return;
|
||||
@@ -187,7 +187,7 @@ public class ObjectSizeCalculator {
|
||||
if (clazz.isArray()) {
|
||||
visitArray(obj);
|
||||
} else {
|
||||
classSizeInfos.getUnchecked(clazz).visit(obj, this);
|
||||
getClassSizeInfo(clazz).visit(obj, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class ObjectSizeCalculator {
|
||||
}
|
||||
final Class<?> superClass = clazz.getSuperclass();
|
||||
if (superClass != null) {
|
||||
final ClassSizeInfo superClassInfo = classSizeInfos.getUnchecked(superClass);
|
||||
final ClassSizeInfo superClassInfo = getClassSizeInfo(superClass);
|
||||
fieldsSize += roundTo(superClassInfo.fieldsSize, superclassFieldPadding);
|
||||
referenceFields.addAll(Arrays.asList(superClassInfo.referenceFields));
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.apache.hudi.common.table.log.block.HoodieAvroDataBlock;
|
||||
import org.apache.hudi.common.table.log.block.HoodieLogBlock;
|
||||
import org.apache.hudi.common.util.SchemaTestUtil;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.avro.generic.IndexedRecord;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
@@ -45,6 +44,7 @@ import org.junit.Test;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -97,7 +97,7 @@ public class TestHoodieLogFormatAppendFailure {
|
||||
|
||||
// Some data & append.
|
||||
List<IndexedRecord> records = SchemaTestUtil.generateTestRecords(0, 10);
|
||||
Map<HoodieLogBlock.HeaderMetadataType, String> header = Maps.newHashMap();
|
||||
Map<HoodieLogBlock.HeaderMetadataType, String> header = new HashMap<>(2);
|
||||
header.put(HoodieLogBlock.HeaderMetadataType.INSTANT_TIME, "100");
|
||||
header.put(HoodieLogBlock.HeaderMetadataType.SCHEMA, getSimpleSchema().toString());
|
||||
HoodieAvroDataBlock dataBlock = new HoodieAvroDataBlock(records, header);
|
||||
|
||||
@@ -199,7 +199,6 @@ public class TestHoodieActiveTimeline extends HoodieCommonTestHarness {
|
||||
checkTimeline.accept(timeline.getCommitsAndCompactionTimeline(),
|
||||
Sets.newHashSet(HoodieTimeline.COMMIT_ACTION, HoodieTimeline.DELTA_COMMIT_ACTION, HoodieTimeline.COMPACTION_ACTION));
|
||||
checkTimeline.accept(timeline.getCommitTimeline(), Collections.singleton(HoodieTimeline.COMMIT_ACTION));
|
||||
|
||||
checkTimeline.accept(timeline.getDeltaCommitTimeline(), Collections.singleton(HoodieTimeline.DELTA_COMMIT_ACTION));
|
||||
checkTimeline.accept(timeline.getCleanerTimeline(), Collections.singleton(HoodieTimeline.CLEAN_ACTION));
|
||||
checkTimeline.accept(timeline.getRollbackTimeline(), Collections.singleton(HoodieTimeline.ROLLBACK_ACTION));
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.apache.hudi.common.util.FSUtils;
|
||||
import org.apache.hudi.common.util.Option;
|
||||
import org.apache.hudi.common.util.collection.Pair;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.hadoop.fs.FileStatus;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.log4j.LogManager;
|
||||
@@ -814,7 +813,7 @@ public class TestHoodieTableFileSystemView extends HoodieCommonTestHarness {
|
||||
roView.getAllBaseFiles("2016/05/01/");
|
||||
|
||||
List<HoodieBaseFile> dataFiles =
|
||||
roView.getLatestBaseFilesInRange(Lists.newArrayList(commitTime2, commitTime3)).collect(Collectors.toList());
|
||||
roView.getLatestBaseFilesInRange(Arrays.asList(commitTime2, commitTime3)).collect(Collectors.toList());
|
||||
assertEquals(isLatestFileSliceOnly ? 2 : 3, dataFiles.size());
|
||||
Set<String> filenames = new HashSet<>();
|
||||
for (HoodieBaseFile status : dataFiles) {
|
||||
@@ -828,7 +827,7 @@ public class TestHoodieTableFileSystemView extends HoodieCommonTestHarness {
|
||||
}
|
||||
|
||||
List<FileSlice> slices =
|
||||
rtView.getLatestFileSliceInRange(Lists.newArrayList(commitTime3, commitTime4)).collect(Collectors.toList());
|
||||
rtView.getLatestFileSliceInRange(Arrays.asList(commitTime3, commitTime4)).collect(Collectors.toList());
|
||||
assertEquals(3, slices.size());
|
||||
for (FileSlice slice : slices) {
|
||||
if (slice.getFileId().equals(fileId1)) {
|
||||
|
||||
@@ -159,13 +159,12 @@ public class TestCompactionUtils extends HoodieCommonTestHarness {
|
||||
Pair<List<Pair<String, FileSlice>>, HoodieCompactionPlan> inputAndPlan = buildCompactionPlan();
|
||||
HoodieCompactionPlan plan = inputAndPlan.getRight();
|
||||
List<HoodieCompactionOperation> originalOps = plan.getOperations();
|
||||
List<HoodieCompactionOperation> regeneratedOps = originalOps.stream().map(op -> {
|
||||
// Convert to CompactionOperation
|
||||
return CompactionUtils.buildCompactionOperation(op);
|
||||
}).map(op2 -> {
|
||||
// Convert back to HoodieCompactionOperation and check for equality
|
||||
return CompactionUtils.buildHoodieCompactionOperation(op2);
|
||||
}).collect(Collectors.toList());
|
||||
// Convert to CompactionOperation
|
||||
// Convert back to HoodieCompactionOperation and check for equality
|
||||
List<HoodieCompactionOperation> regeneratedOps = originalOps.stream()
|
||||
.map(CompactionUtils::buildCompactionOperation)
|
||||
.map(CompactionUtils::buildHoodieCompactionOperation)
|
||||
.collect(Collectors.toList());
|
||||
Assert.assertTrue("Transformation did get tested", originalOps.size() > 0);
|
||||
Assert.assertEquals("All fields set correctly in transformations", originalOps, regeneratedOps);
|
||||
}
|
||||
@@ -247,11 +246,9 @@ public class TestCompactionUtils extends HoodieCommonTestHarness {
|
||||
op.getDataFilePath());
|
||||
}
|
||||
List<String> paths = slice.getLogFiles().map(l -> l.getPath().toString()).collect(Collectors.toList());
|
||||
IntStream.range(0, paths.size()).boxed().forEach(idx -> {
|
||||
Assert.assertEquals("Log File Index " + idx,
|
||||
version == COMPACTION_METADATA_VERSION_1 ? paths.get(idx) : new Path(paths.get(idx)).getName(),
|
||||
op.getDeltaFilePaths().get(idx));
|
||||
});
|
||||
IntStream.range(0, paths.size()).boxed().forEach(idx -> Assert.assertEquals("Log File Index " + idx,
|
||||
version == COMPACTION_METADATA_VERSION_1 ? paths.get(idx) : new Path(paths.get(idx)).getName(),
|
||||
op.getDeltaFilePaths().get(idx)));
|
||||
Assert.assertEquals("Metrics set", METRICS, op.getMetrics());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user