Skip to content

Commit 9255b50

Browse files
authored
Merge pull request #733 from proost/fix-inconsistency-in-sorted-view
fix: inconsistency in sorted view
2 parents 67c3b91 + 69e1b77 commit 9255b50

9 files changed

Lines changed: 133 additions & 25 deletions

File tree

src/main/java/org/apache/datasketches/quantilescommon/DoublesSketchSortedView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ public long[] getCumulativeWeights() {
7474

7575
@Override
7676
public double getMaxItem() {
77+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
7778
final int top = quantiles.length - 1;
7879
return quantiles[top];
7980
}
8081

8182
@Override
8283
public double getMinItem() {
84+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
8385
return quantiles[0];
8486
}
8587

src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.datasketches.quantilescommon;
2121

22+
import org.apache.datasketches.common.SketchesArgumentException;
23+
2224
/**
2325
* The Sorted View for quantile sketches of primitive type double.
2426
* @see SortedView
@@ -58,7 +60,7 @@ public interface DoublesSortedView extends SortedView {
5860
* </blockquote>
5961
* @param searchCrit the desired search criteria.
6062
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
61-
* @throws IllegalArgumentException if sketch is empty.
63+
* @throws SketchesArgumentException if sketch is empty.
6264
*/
6365
default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria searchCrit) {
6466
QuantilesUtil.checkDoublesSplitPointsOrder(splitPoints);
@@ -76,7 +78,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
7678
* sketch algorithm.
7779
*
7880
* @return the maximum item of the stream
79-
* @throws IllegalArgumentException if sketch is empty.
81+
* @throws SketchesArgumentException if sketch is empty.
8082
*/
8183
double getMaxItem();
8284

@@ -85,7 +87,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
8587
* sketch algorithm.
8688
*
8789
* @return the minimum item of the stream
88-
* @throws IllegalArgumentException if sketch is empty.
90+
* @throws SketchesArgumentException if sketch is empty.
8991
*/
9092
double getMinItem();
9193

@@ -127,7 +129,7 @@ default double[] getCDF(final double[] splitPoints, final QuantileSearchCriteria
127129
* </blockquote>
128130
* @param searchCrit the desired search criteria.
129131
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
130-
* @throws IllegalArgumentException if sketch is empty.
132+
* @throws SketchesArgumentException if sketch is empty.
131133
*/
132134
default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteria searchCrit) {
133135
final double[] buckets = getCDF(splitPoints, searchCrit);
@@ -147,7 +149,7 @@ default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteri
147149
* If EXCLUSIVE, he given rank includes all quantiles &lt;
148150
* the quantile directly corresponding to the given rank.
149151
* @return the approximate quantile given the normalized rank.
150-
* @throws IllegalArgumentException if sketch is empty.
152+
* @throws SketchesArgumentException if sketch is empty.
151153
* @see QuantileSearchCriteria
152154
*/
153155
double getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -164,7 +166,7 @@ default double[] getPMF(final double[] splitPoints, final QuantileSearchCriteri
164166
* @param quantile the given quantile
165167
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
166168
* @return the normalized rank corresponding to the given quantile.
167-
* @throws IllegalArgumentException if sketch is empty.
169+
* @throws SketchesArgumentException if sketch is empty.
168170
* @see QuantileSearchCriteria
169171
*/
170172
double getRank(double quantile, QuantileSearchCriteria searchCrit);

src/main/java/org/apache/datasketches/quantilescommon/FloatsSketchSortedView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ public long[] getCumulativeWeights() {
7474

7575
@Override
7676
public float getMaxItem() {
77+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
7778
final int top = quantiles.length - 1;
7879
return quantiles[top];
7980
}
8081

8182
@Override
8283
public float getMinItem() {
84+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
8385
return quantiles[0];
8486
}
8587

src/main/java/org/apache/datasketches/quantilescommon/FloatsSortedView.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.datasketches.quantilescommon;
2121

22+
import org.apache.datasketches.common.SketchesArgumentException;
23+
2224
/**
2325
* The Sorted View for quantiles of primitive type float.
2426
* @see SortedView
@@ -58,7 +60,7 @@ public interface FloatsSortedView extends SortedView {
5860
* </blockquote>
5961
* @param searchCrit the desired search criteria.
6062
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
61-
* @throws IllegalArgumentException if sketch is empty.
63+
* @throws SketchesArgumentException if sketch is empty.
6264
*/
6365
default double[] getCDF(final float[] splitPoints, final QuantileSearchCriteria searchCrit) {
6466
QuantilesUtil.checkFloatsSplitPointsOrder(splitPoints);
@@ -76,7 +78,7 @@ default double[] getCDF(final float[] splitPoints, final QuantileSearchCriteria
7678
* sketch algorithm.
7779
*
7880
* @return the maximum item of the stream
79-
* @throws IllegalArgumentException if sketch is empty.
81+
* @throws SketchesArgumentException if sketch is empty.
8082
*/
8183
float getMaxItem();
8284

@@ -85,7 +87,7 @@ default double[] getCDF(final float[] splitPoints, final QuantileSearchCriteria
8587
* sketch algorithm.
8688
*
8789
* @return the minimum item of the stream
88-
* @throws IllegalArgumentException if sketch is empty.
90+
* @throws SketchesArgumentException if sketch is empty.
8991
*/
9092
float getMinItem();
9193

@@ -127,7 +129,7 @@ default double[] getCDF(final float[] splitPoints, final QuantileSearchCriteria
127129
* </blockquote>
128130
* @param searchCrit the desired search criteria.
129131
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
130-
* @throws IllegalArgumentException if sketch is empty.
132+
* @throws SketchesArgumentException if sketch is empty.
131133
*/
132134
default double[] getPMF(final float[] splitPoints, final QuantileSearchCriteria searchCrit) {
133135
final double[] buckets = getCDF(splitPoints, searchCrit);
@@ -147,7 +149,7 @@ default double[] getPMF(final float[] splitPoints, final QuantileSearchCriteria
147149
* If EXCLUSIVE, he given rank includes all quantiles &lt;
148150
* the quantile directly corresponding to the given rank.
149151
* @return the approximate quantile given the normalized rank.
150-
* @throws IllegalArgumentException if sketch is empty.
152+
* @throws SketchesArgumentException if sketch is empty.
151153
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
152154
*/
153155
float getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -164,7 +166,7 @@ default double[] getPMF(final float[] splitPoints, final QuantileSearchCriteria
164166
* @param quantile the given quantile
165167
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
166168
* @return the normalized rank corresponding to the given quantile.
167-
* @throws IllegalArgumentException if sketch is empty.
169+
* @throws SketchesArgumentException if sketch is empty.
168170
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
169171
*/
170172
double getRank(float quantile, QuantileSearchCriteria searchCrit);
@@ -173,4 +175,3 @@ default double[] getPMF(final float[] splitPoints, final QuantileSearchCriteria
173175
FloatsSortedViewIterator iterator();
174176

175177
}
176-

src/main/java/org/apache/datasketches/quantilescommon/GenericSortedView.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public interface GenericSortedView<T> extends PartitioningFeature<T>, SketchPar
6767
* </blockquote>
6868
* @param searchCrit the desired search criteria.
6969
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
70-
* @throws IllegalArgumentException if sketch is empty.
70+
* @throws SketchesArgumentException if sketch is empty.
7171
*/
7272
default double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria searchCrit) {
7373
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
@@ -92,7 +92,7 @@ default double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria sear
9292
* sketch algorithm.
9393
*
9494
* @return the maximum item of the stream
95-
* @throws IllegalArgumentException if sketch is empty.
95+
* @throws SketchesArgumentException if sketch is empty.
9696
*/
9797
T getMaxItem();
9898

@@ -101,7 +101,7 @@ default double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria sear
101101
* sketch algorithm.
102102
*
103103
* @return the minimum item of the stream
104-
* @throws IllegalArgumentException if sketch is empty.
104+
* @throws SketchesArgumentException if sketch is empty.
105105
*/
106106
T getMinItem();
107107

@@ -143,7 +143,7 @@ default double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria sear
143143
* </blockquote>
144144
* @param searchCrit the desired search criteria.
145145
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
146-
* @throws IllegalArgumentException if sketch is empty.
146+
* @throws SketchesArgumentException if sketch is empty.
147147
*/
148148
default double[] getPMF(final T[] splitPoints, final QuantileSearchCriteria searchCrit) {
149149
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
@@ -164,7 +164,7 @@ default double[] getPMF(final T[] splitPoints, final QuantileSearchCriteria sear
164164
* If EXCLUSIVE, he given rank includes all quantiles &lt;
165165
* the quantile directly corresponding to the given rank.
166166
* @return the approximate quantile given the normalized rank.
167-
* @throws IllegalArgumentException if sketch is empty.
167+
* @throws SketchesArgumentException if sketch is empty.
168168
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
169169
*/
170170
T getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -181,7 +181,7 @@ default double[] getPMF(final T[] splitPoints, final QuantileSearchCriteria sear
181181
* @param quantile the given quantile
182182
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
183183
* @return the normalized rank corresponding to the given quantile.
184-
* @throws IllegalArgumentException if sketch is empty.
184+
* @throws SketchesArgumentException if sketch is empty.
185185
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
186186
*/
187187
double getRank(T quantile, QuantileSearchCriteria searchCrit);

src/main/java/org/apache/datasketches/quantilescommon/ItemsSketchSortedView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public long[] getCumulativeWeights() {
104104

105105
@Override
106106
public T getMaxItem() {
107+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
107108
final int top = quantiles.length - 1;
108109
return quantiles[top];
109110
}
110111

111112
@Override
112113
public T getMinItem() {
114+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
113115
return quantiles[0];
114116
}
115117

src/main/java/org/apache/datasketches/quantilescommon/LongsSketchSortedView.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,14 @@ public long[] getCumulativeWeights() {
7474

7575
@Override
7676
public long getMaxItem() {
77+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
7778
final int top = quantiles.length - 1;
7879
return quantiles[top];
7980
}
8081

8182
@Override
8283
public long getMinItem() {
84+
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
8385
return quantiles[0];
8486
}
8587

src/main/java/org/apache/datasketches/quantilescommon/LongsSortedView.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.apache.datasketches.quantilescommon;
2121

22+
import org.apache.datasketches.common.SketchesArgumentException;
23+
2224
/**
2325
* The Sorted View for quantile sketches of primitive type long.
2426
* @see SortedView
@@ -58,7 +60,7 @@ public interface LongsSortedView extends SortedView {
5860
* </blockquote>
5961
* @param searchCrit the desired search criteria.
6062
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
61-
* @throws IllegalArgumentException if sketch is empty.
63+
* @throws SketchesArgumentException if sketch is empty.
6264
*/
6365
default double[] getCDF(final long[] splitPoints, final QuantileSearchCriteria searchCrit) {
6466
QuantilesUtil.checkLongsSplitPointsOrder(splitPoints);
@@ -76,7 +78,7 @@ default double[] getCDF(final long[] splitPoints, final QuantileSearchCriteria s
7678
* sketch algorithm.
7779
*
7880
* @return the maximum item of the stream
79-
* @throws IllegalArgumentException if sketch is empty.
81+
* @throws SketchesArgumentException if sketch is empty.
8082
*/
8183
long getMaxItem();
8284

@@ -85,7 +87,7 @@ default double[] getCDF(final long[] splitPoints, final QuantileSearchCriteria s
8587
* sketch algorithm.
8688
*
8789
* @return the minimum item of the stream
88-
* @throws IllegalArgumentException if sketch is empty.
90+
* @throws SketchesArgumentException if sketch is empty.
8991
*/
9092
long getMinItem();
9193

@@ -127,7 +129,7 @@ default double[] getCDF(final long[] splitPoints, final QuantileSearchCriteria s
127129
* </blockquote>
128130
* @param searchCrit the desired search criteria.
129131
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
130-
* @throws IllegalArgumentException if sketch is empty.
132+
* @throws SketchesArgumentException if sketch is empty.
131133
*/
132134
default double[] getPMF(final long[] splitPoints, final QuantileSearchCriteria searchCrit) {
133135
final double[] buckets = getCDF(splitPoints, searchCrit);
@@ -147,7 +149,7 @@ default double[] getPMF(final long[] splitPoints, final QuantileSearchCriteria s
147149
* If EXCLUSIVE, he given rank includes all quantiles &lt;
148150
* the quantile directly corresponding to the given rank.
149151
* @return the approximate quantile given the normalized rank.
150-
* @throws IllegalArgumentException if sketch is empty.
152+
* @throws SketchesArgumentException if sketch is empty.
151153
* @see QuantileSearchCriteria
152154
*/
153155
long getQuantile(double rank, QuantileSearchCriteria searchCrit);
@@ -164,7 +166,7 @@ default double[] getPMF(final long[] splitPoints, final QuantileSearchCriteria s
164166
* @param quantile the given quantile
165167
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
166168
* @return the normalized rank corresponding to the given quantile.
167-
* @throws IllegalArgumentException if sketch is empty.
169+
* @throws SketchesArgumentException if sketch is empty.
168170
* @see QuantileSearchCriteria
169171
*/
170172
double getRank(long quantile, QuantileSearchCriteria searchCrit);

0 commit comments

Comments
 (0)