SOLR-9066: Make CountMetric return long instead of double

This commit is contained in:
Kevin Risden 2016-05-04 08:36:43 -05:00
parent b5acdabe53
commit e15bab37a1
8 changed files with 35 additions and 63 deletions

View File

@ -243,6 +243,8 @@ Other Changes
* SOLR-9053: Upgrade commons-fileupload to 1.3.1, fixing a potential vulnerability (Jeff Field, janhoy) * 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 ================== ================== 6.0.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -16,20 +16,14 @@
*/ */
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.Serializable;
import org.apache.solr.client.solrj.io.Tuple; 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 static final String NULL_VALUE = "NULL";
private String bucketKey; private String bucketKey;
public Bucket() {
}
public Bucket(String bucketKey) { public Bucket(String bucketKey) {
this.bucketKey = bucketKey; this.bucketKey = bucketKey;
} }

View File

@ -16,7 +16,6 @@
*/ */
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import org.apache.solr.client.solrj.io.Tuple; 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.StreamExpressionParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class CountMetric extends Metric implements Serializable { public class CountMetric extends Metric {
private static final long serialVersionUID = 1;
private long count; private long count;
public CountMetric(){ public CountMetric(){
init("count"); init("count");
} }
public CountMetric(StreamExpression expression, StreamFactory factory) throws IOException{ public CountMetric(StreamExpression expression, StreamFactory factory) throws IOException{
// grab all parameters out // grab all parameters out
String functionName = expression.getFunctionName(); String functionName = expression.getFunctionName();
@ -63,7 +60,7 @@ public class CountMetric extends Metric implements Serializable {
++count; ++count;
} }
public double getValue() { public Long getValue() {
return count; return count;
} }

View File

@ -17,7 +17,6 @@
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import org.apache.solr.client.solrj.io.Tuple; 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.StreamExpressionParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class MaxMetric extends Metric implements Serializable { public class MaxMetric extends Metric {
private static final long serialVersionUID = 1;
public static final String MAX = "max";
private long longMax = -Long.MIN_VALUE; private long longMax = -Long.MIN_VALUE;
private double doubleMax = -Double.MAX_VALUE; private double doubleMax = -Double.MAX_VALUE;
private String columnName; private String columnName;
@ -37,6 +32,7 @@ public class MaxMetric extends Metric implements Serializable {
public MaxMetric(String columnName){ public MaxMetric(String columnName){
init("max", columnName); init("max", columnName);
} }
public MaxMetric(StreamExpression expression, StreamFactory factory) throws IOException{ public MaxMetric(StreamExpression expression, StreamFactory factory) throws IOException{
// grab all parameters out // grab all parameters out
String functionName = expression.getFunctionName(); String functionName = expression.getFunctionName();
@ -59,7 +55,7 @@ public class MaxMetric extends Metric implements Serializable {
setIdentifier(functionName, "(", columnName, ")"); setIdentifier(functionName, "(", columnName, ")");
} }
public double getValue() { public Number getValue() {
if(longMax == Long.MIN_VALUE) { if(longMax == Long.MIN_VALUE) {
return doubleMax; return doubleMax;
} else { } else {
@ -68,8 +64,7 @@ public class MaxMetric extends Metric implements Serializable {
} }
public String[] getColumns() { public String[] getColumns() {
String[] cols = {columnName}; return new String[]{columnName};
return cols;
} }
public void update(Tuple tuple) { public void update(Tuple tuple) {

View File

@ -17,7 +17,6 @@
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import org.apache.solr.client.solrj.io.Tuple; 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.StreamExpressionParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; 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? // How'd the MeanMetric get to be so mean?
// Maybe it was born with it. // Maybe it was born with it.
// Maybe it was mayba-mean. // Maybe it was mayba-mean.
// //
// I'll see myself out. // I'll see myself out.
private static final long serialVersionUID = 1;
private String columnName; private String columnName;
private double doubleSum; private double doubleSum;
private long longSum; private long longSum;
@ -42,6 +39,7 @@ public class MeanMetric extends Metric implements Serializable {
public MeanMetric(String columnName){ public MeanMetric(String columnName){
init("avg", columnName); init("avg", columnName);
} }
public MeanMetric(StreamExpression expression, StreamFactory factory) throws IOException{ public MeanMetric(StreamExpression expression, StreamFactory factory) throws IOException{
// grab all parameters out // grab all parameters out
String functionName = expression.getFunctionName(); String functionName = expression.getFunctionName();
@ -69,10 +67,10 @@ public class MeanMetric extends Metric implements Serializable {
Object o = tuple.get(columnName); Object o = tuple.get(columnName);
if(o instanceof Double) { if(o instanceof Double) {
Double d = (Double)tuple.get(columnName); Double d = (Double)tuple.get(columnName);
doubleSum += d.doubleValue(); doubleSum += d;
} else { } else {
Long l = (Long)tuple.get(columnName); 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() { public String[] getColumns() {
String[] cols = {columnName}; return new String[]{columnName};
return cols;
} }
public double getValue() { public Double getValue() {
double dcount = (double)count; double dcount = (double)count;
if(longSum == 0) { if(longSum == 0) {
double ave = doubleSum/dcount; return doubleSum/dcount;
return ave;
} else { } else {
double ave = longSum/dcount; return longSum/dcount;
return ave;
} }
} }

View File

@ -17,7 +17,6 @@
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.UUID; import java.util.UUID;
import org.apache.solr.client.solrj.io.Tuple; 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.Expressible;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; 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 UUID metricNodeId = UUID.randomUUID();
private String functionName; private String functionName;
private String identifier; private String identifier;
// @Override
public String getFunctionName(){ public String getFunctionName(){
return functionName; return functionName;
} }
// @Override
public void setFunctionName(String functionName){ public void setFunctionName(String functionName){
this.functionName = functionName; this.functionName = functionName;
} }
@ -59,7 +55,7 @@ public abstract class Metric implements Serializable, Expressible {
@Override @Override
public Explanation toExplanation(StreamFactory factory) throws IOException { public Explanation toExplanation(StreamFactory factory) throws IOException {
return new Explanation(metricNodeId.toString()) return new Explanation(getMetricNodeId().toString())
.withFunctionName(functionName) .withFunctionName(functionName)
.withImplementingClass(getClass().getName()) .withImplementingClass(getClass().getName())
.withExpression(toExpression(factory).toString()) .withExpression(toExpression(factory).toString())
@ -70,7 +66,7 @@ public abstract class Metric implements Serializable, Expressible {
return metricNodeId; return metricNodeId;
} }
public abstract double getValue(); public abstract Number getValue();
public abstract void update(Tuple tuple); public abstract void update(Tuple tuple);
public abstract Metric newInstance(); public abstract Metric newInstance();
public abstract String[] getColumns(); public abstract String[] getColumns();

View File

@ -26,8 +26,6 @@ import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class MinMetric extends Metric { public class MinMetric extends Metric {
private static final long serialVersionUID = 1L;
private long longMin = Long.MAX_VALUE; private long longMin = Long.MAX_VALUE;
private double doubleMin = Double.MAX_VALUE; private double doubleMin = Double.MAX_VALUE;
private String columnName; private String columnName;
@ -35,6 +33,7 @@ public class MinMetric extends Metric {
public MinMetric(String columnName){ public MinMetric(String columnName){
init("min", columnName); init("min", columnName);
} }
public MinMetric(StreamExpression expression, StreamFactory factory) throws IOException{ public MinMetric(StreamExpression expression, StreamFactory factory) throws IOException{
// grab all parameters out // grab all parameters out
String functionName = expression.getFunctionName(); String functionName = expression.getFunctionName();
@ -57,13 +56,11 @@ public class MinMetric extends Metric {
setIdentifier(functionName, "(", columnName, ")"); setIdentifier(functionName, "(", columnName, ")");
} }
public String[] getColumns() { public String[] getColumns() {
String[] cols = {columnName}; return new String[]{columnName};
return cols;
} }
public double getValue() { public Number getValue() {
if(longMin == Long.MAX_VALUE) { if(longMin == Long.MAX_VALUE) {
return doubleMin; return doubleMin;
} else { } else {

View File

@ -17,7 +17,6 @@
package org.apache.solr.client.solrj.io.stream.metrics; package org.apache.solr.client.solrj.io.stream.metrics;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Locale; import java.util.Locale;
import org.apache.solr.client.solrj.io.Tuple; 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.StreamExpressionParameter;
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory; import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
public class SumMetric extends Metric implements Serializable { public class SumMetric extends Metric {
private static final long serialVersionUID = 1;
private String columnName; private String columnName;
private double doubleSum; private double doubleSum;
private long longSum; private long longSum;
@ -36,6 +32,7 @@ public class SumMetric extends Metric implements Serializable {
public SumMetric(String columnName){ public SumMetric(String columnName){
init("sum", columnName); init("sum", columnName);
} }
public SumMetric(StreamExpression expression, StreamFactory factory) throws IOException{ public SumMetric(StreamExpression expression, StreamFactory factory) throws IOException{
// grab all parameters out // grab all parameters out
String functionName = expression.getFunctionName(); String functionName = expression.getFunctionName();
@ -59,18 +56,17 @@ public class SumMetric extends Metric implements Serializable {
} }
public String[] getColumns() { public String[] getColumns() {
String[] cols = {columnName}; return new String[]{columnName};
return cols;
} }
public void update(Tuple tuple) { public void update(Tuple tuple) {
Object o = tuple.get(columnName); Object o = tuple.get(columnName);
if(o instanceof Double) { if(o instanceof Double) {
Double d = (Double)o; Double d = (Double)o;
doubleSum += d.doubleValue(); doubleSum += d;
} else { } else {
Long l = (Long)o; Long l = (Long)o;
longSum += l.longValue(); longSum += l;
} }
} }
@ -78,11 +74,11 @@ public class SumMetric extends Metric implements Serializable {
return new SumMetric(columnName); return new SumMetric(columnName);
} }
public double getValue() { public Number getValue() {
if(longSum == 0) { if(longSum == 0) {
return doubleSum; return doubleSum;
} else { } else {
return (double)longSum; return longSum;
} }
} }