mirror of https://github.com/apache/lucene.git
SOLR-9066: Make CountMetric return long instead of double
This commit is contained in:
parent
b5acdabe53
commit
e15bab37a1
|
@ -243,6 +243,8 @@ Other Changes
|
|||
|
||||
* SOLR-9053: Upgrade commons-fileupload to 1.3.1, fixing a potential vulnerability (Jeff Field, janhoy)
|
||||
|
||||
* SOLR-9066 Make CountMetric return long instead of double (Kevin Risden)
|
||||
|
||||
================== 6.0.0 ==================
|
||||
|
||||
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release
|
||||
|
|
|
@ -16,20 +16,14 @@
|
|||
*/
|
||||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
||||
public class Bucket implements Serializable {
|
||||
public class Bucket {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
private static final String NULL_VALUE = "NULL";
|
||||
|
||||
private String bucketKey;
|
||||
|
||||
public Bucket() {
|
||||
|
||||
}
|
||||
|
||||
public Bucket(String bucketKey) {
|
||||
this.bucketKey = bucketKey;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
@ -24,15 +23,13 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
|||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
||||
public class CountMetric extends Metric implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public class CountMetric extends Metric {
|
||||
private long count;
|
||||
|
||||
public CountMetric(){
|
||||
init("count");
|
||||
}
|
||||
|
||||
public CountMetric(StreamExpression expression, StreamFactory factory) throws IOException{
|
||||
// grab all parameters out
|
||||
String functionName = expression.getFunctionName();
|
||||
|
@ -63,7 +60,7 @@ public class CountMetric extends Metric implements Serializable {
|
|||
++count;
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public Long getValue() {
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
@ -25,11 +24,7 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
|||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
||||
public class MaxMetric extends Metric implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public static final String MAX = "max";
|
||||
public class MaxMetric extends Metric {
|
||||
private long longMax = -Long.MIN_VALUE;
|
||||
private double doubleMax = -Double.MAX_VALUE;
|
||||
private String columnName;
|
||||
|
@ -37,6 +32,7 @@ public class MaxMetric extends Metric implements Serializable {
|
|||
public MaxMetric(String columnName){
|
||||
init("max", columnName);
|
||||
}
|
||||
|
||||
public MaxMetric(StreamExpression expression, StreamFactory factory) throws IOException{
|
||||
// grab all parameters out
|
||||
String functionName = expression.getFunctionName();
|
||||
|
@ -59,7 +55,7 @@ public class MaxMetric extends Metric implements Serializable {
|
|||
setIdentifier(functionName, "(", columnName, ")");
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public Number getValue() {
|
||||
if(longMax == Long.MIN_VALUE) {
|
||||
return doubleMax;
|
||||
} else {
|
||||
|
@ -68,8 +64,7 @@ public class MaxMetric extends Metric implements Serializable {
|
|||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
String[] cols = {columnName};
|
||||
return cols;
|
||||
return new String[]{columnName};
|
||||
}
|
||||
|
||||
public void update(Tuple tuple) {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
@ -25,15 +24,13 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
|||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
||||
public class MeanMetric extends Metric implements Serializable {
|
||||
public class MeanMetric extends Metric {
|
||||
// How'd the MeanMetric get to be so mean?
|
||||
// Maybe it was born with it.
|
||||
// Maybe it was mayba-mean.
|
||||
//
|
||||
// I'll see myself out.
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
private String columnName;
|
||||
private double doubleSum;
|
||||
private long longSum;
|
||||
|
@ -42,6 +39,7 @@ public class MeanMetric extends Metric implements Serializable {
|
|||
public MeanMetric(String columnName){
|
||||
init("avg", columnName);
|
||||
}
|
||||
|
||||
public MeanMetric(StreamExpression expression, StreamFactory factory) throws IOException{
|
||||
// grab all parameters out
|
||||
String functionName = expression.getFunctionName();
|
||||
|
@ -69,10 +67,10 @@ public class MeanMetric extends Metric implements Serializable {
|
|||
Object o = tuple.get(columnName);
|
||||
if(o instanceof Double) {
|
||||
Double d = (Double)tuple.get(columnName);
|
||||
doubleSum += d.doubleValue();
|
||||
doubleSum += d;
|
||||
} else {
|
||||
Long l = (Long)tuple.get(columnName);
|
||||
longSum += l.doubleValue();
|
||||
longSum += l;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,19 +79,16 @@ public class MeanMetric extends Metric implements Serializable {
|
|||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
String[] cols = {columnName};
|
||||
return cols;
|
||||
return new String[]{columnName};
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public Double getValue() {
|
||||
double dcount = (double)count;
|
||||
if(longSum == 0) {
|
||||
double ave = doubleSum/dcount;
|
||||
return ave;
|
||||
return doubleSum/dcount;
|
||||
|
||||
} else {
|
||||
double ave = longSum/dcount;
|
||||
return ave;
|
||||
return longSum/dcount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
@ -26,19 +25,16 @@ import org.apache.solr.client.solrj.io.stream.expr.Explanation.ExpressionType;
|
|||
import org.apache.solr.client.solrj.io.stream.expr.Expressible;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
||||
public abstract class Metric implements Serializable, Expressible {
|
||||
public abstract class Metric implements Expressible {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private UUID metricNodeId = UUID.randomUUID();
|
||||
private String functionName;
|
||||
private String identifier;
|
||||
|
||||
// @Override
|
||||
public String getFunctionName(){
|
||||
return functionName;
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void setFunctionName(String functionName){
|
||||
this.functionName = functionName;
|
||||
}
|
||||
|
@ -59,7 +55,7 @@ public abstract class Metric implements Serializable, Expressible {
|
|||
|
||||
@Override
|
||||
public Explanation toExplanation(StreamFactory factory) throws IOException {
|
||||
return new Explanation(metricNodeId.toString())
|
||||
return new Explanation(getMetricNodeId().toString())
|
||||
.withFunctionName(functionName)
|
||||
.withImplementingClass(getClass().getName())
|
||||
.withExpression(toExpression(factory).toString())
|
||||
|
@ -70,7 +66,7 @@ public abstract class Metric implements Serializable, Expressible {
|
|||
return metricNodeId;
|
||||
}
|
||||
|
||||
public abstract double getValue();
|
||||
public abstract Number getValue();
|
||||
public abstract void update(Tuple tuple);
|
||||
public abstract Metric newInstance();
|
||||
public abstract String[] getColumns();
|
||||
|
|
|
@ -26,8 +26,6 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
|||
|
||||
public class MinMetric extends Metric {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private long longMin = Long.MAX_VALUE;
|
||||
private double doubleMin = Double.MAX_VALUE;
|
||||
private String columnName;
|
||||
|
@ -35,6 +33,7 @@ public class MinMetric extends Metric {
|
|||
public MinMetric(String columnName){
|
||||
init("min", columnName);
|
||||
}
|
||||
|
||||
public MinMetric(StreamExpression expression, StreamFactory factory) throws IOException{
|
||||
// grab all parameters out
|
||||
String functionName = expression.getFunctionName();
|
||||
|
@ -57,13 +56,11 @@ public class MinMetric extends Metric {
|
|||
setIdentifier(functionName, "(", columnName, ")");
|
||||
}
|
||||
|
||||
|
||||
public String[] getColumns() {
|
||||
String[] cols = {columnName};
|
||||
return cols;
|
||||
return new String[]{columnName};
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public Number getValue() {
|
||||
if(longMin == Long.MAX_VALUE) {
|
||||
return doubleMin;
|
||||
} else {
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.apache.solr.client.solrj.io.stream.metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.apache.solr.client.solrj.io.Tuple;
|
||||
|
@ -25,10 +24,7 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamExpression;
|
|||
import org.apache.solr.client.solrj.io.stream.expr.StreamExpressionParameter;
|
||||
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
|
||||
|
||||
public class SumMetric extends Metric implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
|
||||
public class SumMetric extends Metric {
|
||||
private String columnName;
|
||||
private double doubleSum;
|
||||
private long longSum;
|
||||
|
@ -36,6 +32,7 @@ public class SumMetric extends Metric implements Serializable {
|
|||
public SumMetric(String columnName){
|
||||
init("sum", columnName);
|
||||
}
|
||||
|
||||
public SumMetric(StreamExpression expression, StreamFactory factory) throws IOException{
|
||||
// grab all parameters out
|
||||
String functionName = expression.getFunctionName();
|
||||
|
@ -59,18 +56,17 @@ public class SumMetric extends Metric implements Serializable {
|
|||
}
|
||||
|
||||
public String[] getColumns() {
|
||||
String[] cols = {columnName};
|
||||
return cols;
|
||||
return new String[]{columnName};
|
||||
}
|
||||
|
||||
public void update(Tuple tuple) {
|
||||
Object o = tuple.get(columnName);
|
||||
if(o instanceof Double) {
|
||||
Double d = (Double)o;
|
||||
doubleSum += d.doubleValue();
|
||||
doubleSum += d;
|
||||
} else {
|
||||
Long l = (Long)o;
|
||||
longSum += l.longValue();
|
||||
longSum += l;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,11 +74,11 @@ public class SumMetric extends Metric implements Serializable {
|
|||
return new SumMetric(columnName);
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
public Number getValue() {
|
||||
if(longSum == 0) {
|
||||
return doubleSum;
|
||||
} else {
|
||||
return (double)longSum;
|
||||
return longSum;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue