From 9b860f75de65c7db6cc0b607073e1cbb94201dfc Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Tue, 11 Jan 2022 15:16:09 -0800 Subject: [PATCH 1/3] Fixes problems found when running latest version of SpotBugs. --- README.md | 20 ++++++-- .../java/org/apache/datasketches/Util.java | 5 +- .../apache/datasketches/fdt/FdtSketch.java | 17 +++++++ .../datasketches/fdt/PostProcessor.java | 2 +- .../quantiles/DirectUpdateDoublesSketch.java | 6 +++ .../sampling/VarOptItemsSketch.java | 4 ++ .../apache/datasketches/theta/AnotBimpl.java | 4 +- .../datasketches/tuple/QuickSelectSketch.java | 25 ++++++++++ .../datasketches/tuple/UpdatableSketch.java | 17 +++++++ .../org/apache/datasketches/tuple/Util.java | 10 +++- .../tuple/strings/ArrayOfStringsSketch.java | 17 +++++++ .../org/apache/datasketches/UtilTest.java | 6 +-- .../datasketches/fdt/FdtSketchTest.java | 11 +++++ .../quantiles/DoublesSketchTest.java | 12 +++-- .../sampling/VarOptItemsSketchTest.java | 10 +--- .../CornerCaseThetaSetOperationsTest.java | 10 ++-- .../theta/HeapifyWrapSerVer1and2Test.java | 2 +- .../apache/datasketches/tuple/MiscTest.java | 21 +++++++-- ...erCaseArrayOfDoublesSetOperationsTest.java | 32 +++++++------ .../strings/ArrayOfStringsSketchTest.java | 12 +++++ tools/FindBugsExcludeFilter.xml | 47 ++++++++++++++++++- 21 files changed, 236 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index 87e089367..10630e981 100644 --- a/README.md +++ b/README.md @@ -92,12 +92,23 @@ See the pom.xml file for test dependencies. Building and running tests using JDK 8 should not be a problem. -However, with JDK 9+, and Eclipse version up to and including 4.22.0 (2021-12), Eclipse fails to translate the required JPMS JVM arguments specified in the POM into the *.classpath* file, causing illegal reflection access errors. +However, with JDK 9+, and Eclipse versions up to and including 4.22.0 (2021-12), Eclipse fails to translate the required JPMS JVM arguments specified in the POM compiler or surefire plugins into the *.classpath* file, causing illegal reflection access errors +[eclipse-m2e/m2e-core Bug 543631](https://github.com/eclipse-m2e/m2e-core/issues/129). There are two ways to fix this: -#### Manually update *.classpath* file: -Open the *.classpath* file in a text editor and insert the following *classpathentry* element (this assumes JDK11, change to suit) then *refresh*.: +#### Method 1: Manually update *.classpath* file: +Open the *.classpath* file in a text editor and find the following *classpathentry* element (this assumes JDK11, change to suit): + +``` + + + + + + +``` +Then edit it as follows: ``` @@ -109,8 +120,9 @@ Open the *.classpath* file in a text editor and insert the following *classpathe ``` +Finally, *refresh*. -#### Manually update *Module Dependencies* +#### Method 2: Manually update *Module Dependencies* In Eclipse, open the project *Properties / Java Build Path / Module Dependencies ...* diff --git a/src/main/java/org/apache/datasketches/Util.java b/src/main/java/org/apache/datasketches/Util.java index 6c4ea5750..5e3f928be 100644 --- a/src/main/java/org/apache/datasketches/Util.java +++ b/src/main/java/org/apache/datasketches/Util.java @@ -33,6 +33,7 @@ import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Objects; /** * Common utility functions. @@ -846,13 +847,15 @@ public static boolean isLessThanUnsigned(final long n1, final long n2) { * @return the absolute path of the given resource file's shortName. */ public static String getResourcePath(final String shortFileName) { + Objects.requireNonNull(shortFileName, "input parameter " + shortFileName + " cannot be null."); try { final URL url = Util.class.getClassLoader().getResource(shortFileName); + Objects.requireNonNull(url, "resource " + shortFileName + " could not be acquired."); final URI uri = url.toURI(); //decodes any special characters final String path = uri.isAbsolute() ? Paths.get(uri).toAbsolutePath().toString() : uri.getPath(); return path; - } catch (final NullPointerException | URISyntaxException e) { + } catch (final URISyntaxException e) { throw new SketchesArgumentException("Cannot find resource: " + shortFileName + LS + e); } } diff --git a/src/main/java/org/apache/datasketches/fdt/FdtSketch.java b/src/main/java/org/apache/datasketches/fdt/FdtSketch.java index 6cf4b3419..4b4617e84 100644 --- a/src/main/java/org/apache/datasketches/fdt/FdtSketch.java +++ b/src/main/java/org/apache/datasketches/fdt/FdtSketch.java @@ -82,6 +82,23 @@ public FdtSketch(final double threshold, final double rse) { super(computeLgK(threshold, rse)); } + /** + * Copy Constructor + * @param sketch the sketch to copy + */ + public FdtSketch(final FdtSketch sketch) { + super(sketch); + } + + /** + * @return a deep copy of this sketch + */ + @SuppressWarnings("unchecked") + @Override + public FdtSketch copy() { + return new FdtSketch(this); + } + /** * Update the sketch with the given string array tuple. * @param tuple the given string array tuple. diff --git a/src/main/java/org/apache/datasketches/fdt/PostProcessor.java b/src/main/java/org/apache/datasketches/fdt/PostProcessor.java index a07deeb2d..5dbff8fe7 100644 --- a/src/main/java/org/apache/datasketches/fdt/PostProcessor.java +++ b/src/main/java/org/apache/datasketches/fdt/PostProcessor.java @@ -58,7 +58,7 @@ public class PostProcessor { * @param sep the separator character */ public PostProcessor(final FdtSketch sketch, final Group group, final char sep) { - this.sketch = sketch; + this.sketch = sketch.copy(); this.sep = sep; final int numEntries = sketch.getRetainedEntries(); mapArrSize = ceilingPowerOf2((int)(numEntries / 0.75)); diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java index 6ee031971..6af0b0ac4 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java @@ -42,6 +42,7 @@ import static org.apache.datasketches.quantiles.Util.computeBitPattern; import org.apache.datasketches.Family; +import org.apache.datasketches.SketchesArgumentException; import org.apache.datasketches.memory.MemoryRequestServer; import org.apache.datasketches.memory.WritableMemory; @@ -250,6 +251,11 @@ private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) { assert needBytes > memBytes; memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr; + if (memReqSvr == null) { + throw new SketchesArgumentException( + "A reequest for more memory has been denied, " + + "or a default MemoryRequestServer has not been provided. Must abort. "); + } final WritableMemory newMem = memReqSvr.request(mem_, needBytes); diff --git a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java index 0d1f83206..9cc1cf212 100644 --- a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java +++ b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java @@ -785,6 +785,10 @@ T getItem(final int idx) { return weights_.get(idx); } + boolean isMarksValid() { + return marks_ != null; + } + // package-private: Relies on ArrayList for bounds checking and assumes caller knows how to // handle a null from the middle of the list. boolean getMark(final int idx) { return marks_.get(idx); } diff --git a/src/main/java/org/apache/datasketches/theta/AnotBimpl.java b/src/main/java/org/apache/datasketches/theta/AnotBimpl.java index d7a2ebe50..ae4c69e4f 100644 --- a/src/main/java/org/apache/datasketches/theta/AnotBimpl.java +++ b/src/main/java/org/apache/datasketches/theta/AnotBimpl.java @@ -78,7 +78,6 @@ public void setA(final Sketch skA) { //process A hashArr_ = getHashArrA(skA); - hashArr_ = (hashArr_ == null) ? new long[0] : hashArr_; empty_ = false; thetaLong_ = skA.getThetaLong(); curCount_ = hashArr_.length; @@ -94,7 +93,6 @@ public void notB(final Sketch skB) { //process B hashArr_ = getResultHashArr(thetaLong_, curCount_, hashArr_, skB); - hashArr_ = (hashArr_ == null) ? new long[0] : hashArr_; curCount_ = hashArr_.length; empty_ = curCount_ == 0 && thetaLong_ == Long.MAX_VALUE; } @@ -135,7 +133,7 @@ public CompactSketch aNotB(final Sketch skA, final Sketch skB, final boolean dst //process A final long[] hashArrA = getHashArrA(skA); - final int countA = (hashArrA == null) ? 0 : hashArrA.length; + final int countA = hashArrA.length; //process B diff --git a/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java b/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java index cba7ff6f6..753bb156c 100644 --- a/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java +++ b/src/main/java/org/apache/datasketches/tuple/QuickSelectSketch.java @@ -134,6 +134,24 @@ private enum Flags { IS_BIG_ENDIAN, IS_IN_SAMPLING_MODE, IS_EMPTY, HAS_ENTRIES, setRebuildThreshold(); } + /** + * Copy constructor + * @param sketch the QuickSelectSketch to be copied. + */ + QuickSelectSketch(final QuickSelectSketch sketch) { + nomEntries_ = sketch.nomEntries_; + lgCurrentCapacity_ = sketch.lgCurrentCapacity_; + lgResizeFactor_ = sketch.lgResizeFactor_; + count_ = sketch.count_; + samplingProbability_ = sketch.samplingProbability_; + rebuildThreshold_ = sketch.rebuildThreshold_; + thetaLong_ = sketch.thetaLong_; + empty_ = sketch.empty_; + summaryFactory_ = sketch.summaryFactory_; + hashTable_ = sketch.hashTable_.clone(); + summaryTable_ = Util.copySummaryArray(sketch.summaryTable_); + } + /** * This is to create an instance of a QuickSelectSketch given a serialized form * @param mem Memory object with serialized QukckSelectSketch @@ -205,6 +223,13 @@ private enum Flags { IS_BIG_ENDIAN, IS_IN_SAMPLING_MODE, IS_EMPTY, HAS_ENTRIES, setRebuildThreshold(); } + /** + * @return a deep copy of this sketch + */ + QuickSelectSketch copy() { + return new QuickSelectSketch(this); + } + long[] getHashTable() { return hashTable_; } diff --git a/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java b/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java index 9df621816..f19439343 100644 --- a/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java +++ b/src/main/java/org/apache/datasketches/tuple/UpdatableSketch.java @@ -75,6 +75,23 @@ public UpdatableSketch(final Memory srcMem, final SummaryDeserializer deseria super(srcMem, deserializer, summaryFactory); } + /** + * Copy Constructor + * @param sketch the sketch to copy + */ + public UpdatableSketch(final UpdatableSketch sketch) { + super(sketch); + } + + /** + * @return a deep copy of this sketch + */ + @SuppressWarnings("unchecked") + @Override + public UpdatableSketch copy() { + return new UpdatableSketch(this); + } + /** * Updates this sketch with a long key and U value. * The value is passed to update() method of the Summary object associated with the key diff --git a/src/main/java/org/apache/datasketches/tuple/Util.java b/src/main/java/org/apache/datasketches/tuple/Util.java index 452347627..58a5afd15 100644 --- a/src/main/java/org/apache/datasketches/tuple/Util.java +++ b/src/main/java/org/apache/datasketches/tuple/Util.java @@ -137,12 +137,20 @@ public static long stringArrHash(final String[] strArray) { return hashCharArr(s.toCharArray(), 0, s.length(), PRIME); } + /** + * Will copy compact summary arrays as well as hashed summary tables (with nulls). + * @param type of summary + * @param summaryArr the given summary array or table + * @return the copy + */ @SuppressWarnings("unchecked") public static S[] copySummaryArray(final S[] summaryArr) { final int len = summaryArr.length; final S[] tmpSummaryArr = newSummaryArray(summaryArr, len); for (int i = 0; i < len; i++) { - tmpSummaryArr[i] = (S) summaryArr[i].copy(); + final S summary = summaryArr[i]; + if (summary == null) { continue; } + tmpSummaryArr[i] = (S) summary.copy(); } return tmpSummaryArr; } diff --git a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketch.java b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketch.java index 5d73319ce..1ac683564 100644 --- a/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketch.java +++ b/src/main/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketch.java @@ -73,6 +73,23 @@ public ArrayOfStringsSketch(final Memory mem) { super(mem, new ArrayOfStringsSummaryDeserializer(), new ArrayOfStringsSummaryFactory()); } + /** + * Copy Constructor + * @param sketch the sketch to copy + */ + public ArrayOfStringsSketch(final ArrayOfStringsSketch sketch) { + super(sketch); + } + + /** + * @return a deep copy of this sketch + */ + @SuppressWarnings("unchecked") + @Override + public ArrayOfStringsSketch copy() { + return new ArrayOfStringsSketch(this); + } + /** * Updates the sketch with String arrays for both key and value. * @param strArrKey the given String array key diff --git a/src/test/java/org/apache/datasketches/UtilTest.java b/src/test/java/org/apache/datasketches/UtilTest.java index 8d575ca5e..c194070db 100644 --- a/src/test/java/org/apache/datasketches/UtilTest.java +++ b/src/test/java/org/apache/datasketches/UtilTest.java @@ -89,7 +89,7 @@ public void numTrailingOnes() { public void checkBoundsTest() { Util.checkBounds(999, 2, 1000); } - + @Test public void checkIsPowerOf2() { Assert.assertEquals(isPowerOf2(0), false); @@ -396,7 +396,7 @@ public void resourcefileExists() { assertTrue(file.exists()); } - @Test(expectedExceptions = SketchesArgumentException.class) + @Test(expectedExceptions = NullPointerException.class) public void resourceFileNotFound() { final String shortFileName = "cpc-empty.sk"; getResourceFile(shortFileName + "123"); @@ -409,7 +409,7 @@ public void resourceBytesCorrect() { assertTrue(bytes.length == 8); } - @Test(expectedExceptions = SketchesArgumentException.class) + @Test(expectedExceptions = NullPointerException.class) public void resourceBytesFileNotFound() { final String shortFileName = "cpc-empty.sk"; getResourceBytes(shortFileName + "123"); diff --git a/src/test/java/org/apache/datasketches/fdt/FdtSketchTest.java b/src/test/java/org/apache/datasketches/fdt/FdtSketchTest.java index dc99e4a09..8cd6d5ba2 100644 --- a/src/test/java/org/apache/datasketches/fdt/FdtSketchTest.java +++ b/src/test/java/org/apache/datasketches/fdt/FdtSketchTest.java @@ -151,6 +151,17 @@ public void checkEstimatingPostProcessing() { } } + @Test + public void checkCopyCtor() { + final int lgK = 14; + final FdtSketch sk = new FdtSketch(lgK); + + final String[] nodesArr = {"abc", "def" }; + sk.update(nodesArr); + assertEquals(sk.getRetainedEntries(), 1); + final FdtSketch sk2 = sk.copy(); + assertEquals(sk2.getRetainedEntries(), 1); + } @Test public void printlnTest() { diff --git a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java index b2f9bf9bb..deb785d1b 100644 --- a/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java +++ b/src/test/java/org/apache/datasketches/quantiles/DoublesSketchTest.java @@ -152,15 +152,17 @@ public void directSketchShouldMoveOntoHeapEventually() { @Test public void directSketchShouldMoveOntoHeapEventually2() { - try (WritableHandle wdh = WritableMemory.allocateDirect(50)) { + int i = 0; + try (WritableHandle wdh = + WritableMemory.allocateDirect(50, ByteOrder.LITTLE_ENDIAN, new DefaultMemoryRequestServer())) { WritableMemory mem = wdh.getWritable(); UpdateDoublesSketch sketch = DoublesSketch.builder().build(mem); Assert.assertTrue(sketch.isSameResource(mem)); - for (int i = 0; i < 1000; i++) { - try { + for (; i < 1000; i++) { + if (sketch.isSameResource(mem)) { sketch.update(i); - if (sketch.isSameResource(mem)) { continue; } - } catch (NullPointerException e) { + } else { + System.out.println("MOVED at i = " + i); break; } } diff --git a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java index d701ce3fd..df45157f3 100644 --- a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java +++ b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java @@ -23,6 +23,7 @@ import static org.apache.datasketches.sampling.PreambleUtil.PREAMBLE_LONGS_BYTE; import static org.apache.datasketches.sampling.PreambleUtil.SER_VER_BYTE; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -515,17 +516,10 @@ public void checkReset() { for (int i = 0; i < (2 * k); ++i) { sketch.update("a", 100.0 + i); } - assertEquals(sketch.getN(), 2 * k); assertEquals(sketch.getHRegionCount(), 0); assertEquals(sketch.getRRegionCount(), k); - try { - sketch.getMark(0); - fail(); - } catch (final NullPointerException e) { - // expected - } - + assertFalse(sketch.isMarksValid()); sketch.reset(); assertEquals(sketch.getN(), 0); assertEquals(sketch.getHRegionCount(), 0); diff --git a/src/test/java/org/apache/datasketches/theta/CornerCaseThetaSetOperationsTest.java b/src/test/java/org/apache/datasketches/theta/CornerCaseThetaSetOperationsTest.java index 8b64a3fcb..4bf41955a 100644 --- a/src/test/java/org/apache/datasketches/theta/CornerCaseThetaSetOperationsTest.java +++ b/src/test/java/org/apache/datasketches/theta/CornerCaseThetaSetOperationsTest.java @@ -115,7 +115,7 @@ public void emptyDegenerate() { } @Test - public void EmptyEstimation() { + public void emptyEstimation() { UpdateSketch thetaA = getSketch(SkType.EMPTY, 0, 0); UpdateSketch thetaB = getSketch(SkType.ESTIMATION, LOWP, LT_LOWP_V); final double expectedIntersectTheta = 1.0; @@ -301,7 +301,7 @@ public void estimationEstimation() { //================================= @Test - public void DegenerateEmpty() { + public void degenerateEmpty() { UpdateSketch thetaA = getSketch(SkType.DEGENERATE, LOWP, GT_LOWP_V); //entries = 0 UpdateSketch thetaB = getSketch(SkType.EMPTY, 0, 0); final double expectedIntersectTheta = 1.0; @@ -321,7 +321,7 @@ public void DegenerateEmpty() { } @Test - public void DegenerateExact() { + public void degenerateExact() { UpdateSketch thetaA = getSketch(SkType.DEGENERATE, LOWP, GT_LOWP_V); //entries = 0 UpdateSketch thetaB = getSketch(SkType.EXACT, 0, LT_LOWP_V); final double expectedIntersectTheta = LOWP_THETA; @@ -341,7 +341,7 @@ public void DegenerateExact() { } @Test - public void DegenerateDegenerate() { + public void degenerateDegenerate() { UpdateSketch thetaA = getSketch(SkType.DEGENERATE, MIDP, GT_MIDP_V); //entries = 0 UpdateSketch thetaB = getSketch(SkType.DEGENERATE, LOWP, GT_LOWP_V); final double expectedIntersectTheta = LOWP_THETA; @@ -361,7 +361,7 @@ public void DegenerateDegenerate() { } @Test - public void DegenerateEstimation() { + public void degenerateEstimation() { UpdateSketch thetaA = getSketch(SkType.DEGENERATE, MIDP, GT_MIDP_V); //entries = 0 UpdateSketch thetaB = getSketch(SkType.ESTIMATION, LOWP, LT_LOWP_V); final double expectedIntersectTheta = LOWP_THETA; diff --git a/src/test/java/org/apache/datasketches/theta/HeapifyWrapSerVer1and2Test.java b/src/test/java/org/apache/datasketches/theta/HeapifyWrapSerVer1and2Test.java index fb042d3b0..82b17d96f 100644 --- a/src/test/java/org/apache/datasketches/theta/HeapifyWrapSerVer1and2Test.java +++ b/src/test/java/org/apache/datasketches/theta/HeapifyWrapSerVer1and2Test.java @@ -378,7 +378,7 @@ public void checkWrapCompactSketchGivenDefaultSeed() { assertEquals(sv3cskResult.getEstimate(), sv3usk.getEstimate()); assertEquals(sv3cskResult.getSeedHash(), seedHash); assertFalse(sv3cskResult.isDirect()); - try { wh.close(); } catch (Exception e) {} + try { wh.close(); } catch (Exception e) {/* ignore */} } @Test diff --git a/src/test/java/org/apache/datasketches/tuple/MiscTest.java b/src/test/java/org/apache/datasketches/tuple/MiscTest.java index 46fe9bb3b..71982afd8 100644 --- a/src/test/java/org/apache/datasketches/tuple/MiscTest.java +++ b/src/test/java/org/apache/datasketches/tuple/MiscTest.java @@ -19,13 +19,13 @@ package org.apache.datasketches.tuple; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import org.apache.datasketches.SetOperationCornerCases.CornerCase; import org.apache.datasketches.tuple.adouble.DoubleSummary; import org.apache.datasketches.tuple.adouble.DoubleSummary.Mode; import org.apache.datasketches.tuple.adouble.DoubleSummaryFactory; -import org.testng.Assert; import org.testng.annotations.Test; /** @@ -52,7 +52,7 @@ public void checkStringToByteArray() { @Test public void checkDoubleToLongArray() { final long[] v = Util.doubleToLongArray(-0.0); - Assert.assertEquals(v[0], 0); + assertEquals(v[0], 0); } //@Test @@ -71,6 +71,20 @@ public void checkById() { } } + @Test + public void checkCopyCtor() { + final DoubleSummary.Mode mode = Mode.Sum; + final UpdatableSketchBuilder bldr = + new UpdatableSketchBuilder<>(new DoubleSummaryFactory(mode)); + bldr.reset(); + final UpdatableSketch sk = bldr.build(); + sk.update(1.0, 1.0); + assertEquals(sk.getRetainedEntries(), 1); + final UpdatableSketch sk2 = sk.copy(); + assertEquals(sk2.getRetainedEntries(), 1); + } + + /** * * @param o object to print @@ -79,7 +93,4 @@ private static void println(final Object o) { //System.out.println(o.toString()); //disable here } - - - } diff --git a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/CornerCaseArrayOfDoublesSetOperationsTest.java b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/CornerCaseArrayOfDoublesSetOperationsTest.java index 38eb14a1a..1ca69dc88 100644 --- a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/CornerCaseArrayOfDoublesSetOperationsTest.java +++ b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/CornerCaseArrayOfDoublesSetOperationsTest.java @@ -58,6 +58,8 @@ public class CornerCaseArrayOfDoublesSetOperationsTest { private static final long LOWP_THETALONG = (long)(MAX_LONG * LOWP_FLT); private static final long HASH_LT_LOWP = getLongHash(LT_LOWP_KEY); + private static final String LS = System.getProperty("line.separator"); + private enum SkType { EMPTY, // { 1.0, 0, T} Bin: 101 Oct: 05 EXACT, // { 1.0, >0, F} Bin: 110 Oct: 06, specify only value @@ -139,7 +141,7 @@ public void emptyDegenerate() { } @Test - public void EmptyEstimation() { + public void emptyEstimation() { ArrayOfDoublesUpdatableSketch thetaA = getSketch(SkType.EMPTY, 0, 0); ArrayOfDoublesUpdatableSketch thetaB = getSketch(SkType.ESTIMATION, LOWP_FLT, LT_LOWP_KEY); final double expectedIntersectTheta = 1.0; @@ -325,7 +327,7 @@ public void estimationEstimation() { //================================= @Test - public void DegenerateEmpty() { + public void degenerateEmpty() { ArrayOfDoublesUpdatableSketch thetaA = getSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_KEY); //entries = 0 ArrayOfDoublesUpdatableSketch thetaB = getSketch(SkType.EMPTY, 0, 0); final double expectedIntersectTheta = 1.0; @@ -345,7 +347,7 @@ public void DegenerateEmpty() { } @Test - public void DegenerateExact() { + public void degenerateExact() { ArrayOfDoublesUpdatableSketch thetaA = getSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_KEY); //entries = 0 ArrayOfDoublesUpdatableSketch thetaB = getSketch(SkType.EXACT, 0, LT_LOWP_KEY); final double expectedIntersectTheta = LOWP_FLT; @@ -365,7 +367,7 @@ public void DegenerateExact() { } @Test - public void DegenerateDegenerate() { + public void degenerateDegenerate() { ArrayOfDoublesUpdatableSketch thetaA = getSketch(SkType.DEGENERATE, MIDP_FLT, GT_MIDP_KEY); //entries = 0 ArrayOfDoublesUpdatableSketch thetaB = getSketch(SkType.DEGENERATE, LOWP_FLT, GT_LOWP_KEY); final double expectedIntersectTheta = LOWP_FLT; @@ -385,7 +387,7 @@ public void DegenerateDegenerate() { } @Test - public void DegenerateEstimation() { + public void degenerateEstimation() { ArrayOfDoublesUpdatableSketch thetaA = getSketch(SkType.DEGENERATE, MIDP_FLT, GT_MIDP_KEY); //entries = 0 ArrayOfDoublesUpdatableSketch thetaB = getSketch(SkType.ESTIMATION, LOWP_FLT, LT_LOWP_KEY); final double expectedIntersectTheta = LOWP_FLT; @@ -540,15 +542,15 @@ private static void checkInvalidUpdate(float p, long updateKey) { //@Test public void printTable() { println(" Top8bits Hex Decimal"); - printf("MAX: %8s, %16x, %19d\n", getTop8(MAX_LONG), MAX_LONG, MAX_LONG); - printf("GT_MIDP: %8s, %16x, %19d\n", getTop8(HASH_GT_MIDP), HASH_GT_MIDP, HASH_GT_MIDP); - printf("MIDP_THETALONG:%8s, %16x, %19d\n", getTop8(MIDP_THETALONG), MIDP_THETALONG, MIDP_THETALONG); - printf("GT_LOWP: %8s, %16x, %19d\n", getTop8(HASH_GT_LOWP), HASH_GT_LOWP, HASH_GT_LOWP); - printf("LOWP_THETALONG:%8s, %16x, %19d\n", getTop8(LOWP_THETALONG), LOWP_THETALONG, LOWP_THETALONG); - printf("LT_LOWP: %8s, %16x, %19d\n", getTop8(HASH_LT_LOWP), HASH_LT_LOWP, HASH_LT_LOWP); - println("\nDoubles"); - - println("\nLongs"); + printf("MAX: %8s, %16x, %19d" + LS, getTop8(MAX_LONG), MAX_LONG, MAX_LONG); + printf("GT_MIDP: %8s, %16x, %19d" + LS, getTop8(HASH_GT_MIDP), HASH_GT_MIDP, HASH_GT_MIDP); + printf("MIDP_THETALONG:%8s, %16x, %19d" + LS, getTop8(MIDP_THETALONG), MIDP_THETALONG, MIDP_THETALONG); + printf("GT_LOWP: %8s, %16x, %19d" + LS, getTop8(HASH_GT_LOWP), HASH_GT_LOWP, HASH_GT_LOWP); + printf("LOWP_THETALONG:%8s, %16x, %19d" + LS, getTop8(LOWP_THETALONG), LOWP_THETALONG, LOWP_THETALONG); + printf("LT_LOWP: %8s, %16x, %19d" + LS, getTop8(HASH_LT_LOWP), HASH_LT_LOWP, HASH_LT_LOWP); + println(LS +"Doubles"); + + println(LS + "Longs"); for (long v = 1L; v < 10; v++) { long hash = (hash(v, DEFAULT_UPDATE_SEED)[0]) >>> 1; printLong(v, hash); @@ -560,7 +562,7 @@ static long getLongHash(long v) { } static void printLong(long v, long hash) { - System.out.printf(" %8d, %8s, %16x, %19d\n",v, getTop8(hash), hash, hash); + System.out.printf(" %8d, %8s, %16x, %19d" + LS,v, getTop8(hash), hash, hash); } static String getTop8(final long v) { diff --git a/src/test/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketchTest.java b/src/test/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketchTest.java index 031417f8d..b8bbd7b35 100644 --- a/src/test/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketchTest.java +++ b/src/test/java/org/apache/datasketches/tuple/strings/ArrayOfStringsSketchTest.java @@ -99,6 +99,18 @@ static void printSummaries(SketchIterator it) { } } + @Test + public void checkCopyCtor() { + ArrayOfStringsSketch sk1 = new ArrayOfStringsSketch(); + String[][] strArrArr = {{"a","b"},{"c","d"},{"e","f"}}; + int len = strArrArr.length; + for (int i = 0; i < len; i++) { + sk1.update(strArrArr[i], strArrArr[i]); + } + assertEquals(sk1.getRetainedEntries(), 3); + final ArrayOfStringsSketch sk2 = sk1.copy(); + assertEquals(sk2.getRetainedEntries(), 3); + } @Test public void printlnTest() { diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml index 2c669f0f2..6b349bbd5 100644 --- a/tools/FindBugsExcludeFilter.xml +++ b/tools/FindBugsExcludeFilter.xml @@ -78,9 +78,52 @@ under the License. - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From b4a727930b220dc87c44375e9cebd225f16e9e27 Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Tue, 11 Jan 2022 16:06:27 -0800 Subject: [PATCH 2/3] Fixed Typo. --- .../datasketches/quantiles/DirectUpdateDoublesSketch.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java index 6af0b0ac4..d61a54d83 100644 --- a/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java +++ b/src/main/java/org/apache/datasketches/quantiles/DirectUpdateDoublesSketch.java @@ -253,7 +253,7 @@ private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) { memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr; if (memReqSvr == null) { throw new SketchesArgumentException( - "A reequest for more memory has been denied, " + "A request for more memory has been denied, " + "or a default MemoryRequestServer has not been provided. Must abort. "); } From 7066e8aad235089238c59d99a704f4a546610abe Mon Sep 17 00:00:00 2001 From: Lee Rhodes Date: Wed, 12 Jan 2022 13:20:11 -0800 Subject: [PATCH 3/3] Removed test and method isMarkValid() as requested. --- .../org/apache/datasketches/sampling/VarOptItemsSketch.java | 4 ---- .../apache/datasketches/sampling/VarOptItemsSketchTest.java | 2 -- 2 files changed, 6 deletions(-) diff --git a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java index 9cc1cf212..0d1f83206 100644 --- a/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java +++ b/src/main/java/org/apache/datasketches/sampling/VarOptItemsSketch.java @@ -785,10 +785,6 @@ T getItem(final int idx) { return weights_.get(idx); } - boolean isMarksValid() { - return marks_ != null; - } - // package-private: Relies on ArrayList for bounds checking and assumes caller knows how to // handle a null from the middle of the list. boolean getMark(final int idx) { return marks_.get(idx); } diff --git a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java index df45157f3..8043cb1fa 100644 --- a/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java +++ b/src/test/java/org/apache/datasketches/sampling/VarOptItemsSketchTest.java @@ -23,7 +23,6 @@ import static org.apache.datasketches.sampling.PreambleUtil.PREAMBLE_LONGS_BYTE; import static org.apache.datasketches.sampling.PreambleUtil.SER_VER_BYTE; import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; @@ -519,7 +518,6 @@ public void checkReset() { assertEquals(sketch.getN(), 2 * k); assertEquals(sketch.getHRegionCount(), 0); assertEquals(sketch.getRRegionCount(), k); - assertFalse(sketch.isMarksValid()); sketch.reset(); assertEquals(sketch.getN(), 0); assertEquals(sketch.getHRegionCount(), 0);