Add, fix equals, hashCode, toString on various classes. (#3723)

* TimeFormatExtractionFn: Add toString.

* InDimFilter: Add toString, allow accepting any Collection of values.

* DimensionTopNMetricSpec: Fix toString.

* InvertedTopNMetricSpec: Add toString.

* HyperUniqueFinalizingPostAggregator: Add equals, hashCode, toString.
This commit is contained in:
Gian Merlino 2016-11-30 19:00:14 -08:00 committed by GitHub
parent 477e0cab7c
commit 68735829ca
5 changed files with 74 additions and 3 deletions

View File

@ -89,4 +89,39 @@ public class HyperUniqueFinalizingPostAggregator implements PostAggregator
{ {
return fieldName; return fieldName;
} }
@Override
public boolean equals(Object o)
{
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
HyperUniqueFinalizingPostAggregator that = (HyperUniqueFinalizingPostAggregator) o;
if (name != null ? !name.equals(that.name) : that.name != null) {
return false;
}
return fieldName != null ? fieldName.equals(that.fieldName) : that.fieldName == null;
}
@Override
public int hashCode()
{
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0);
return result;
}
@Override
public String toString()
{
return "HyperUniqueFinalizingPostAggregator{" +
"name='" + name + '\'' +
", fieldName='" + fieldName + '\'' +
'}';
}
} }

View File

@ -34,8 +34,8 @@ import java.util.Locale;
public class TimeFormatExtractionFn implements ExtractionFn public class TimeFormatExtractionFn implements ExtractionFn
{ {
private final DateTimeZone tz;
private final String format; private final String format;
private final DateTimeZone tz;
private final Locale locale; private final Locale locale;
private final QueryGranularity granularity; private final QueryGranularity granularity;
private final DateTimeFormatter formatter; private final DateTimeFormatter formatter;
@ -161,4 +161,10 @@ public class TimeFormatExtractionFn implements ExtractionFn
result = 31 * result + granularity.hashCode(); result = 31 * result + granularity.hashCode();
return result; return result;
} }
@Override
public String toString()
{
return String.format("timeFormat(\"%s\", %s, %s, %s)", format, tz, locale, granularity);
}
} }

View File

@ -22,6 +22,7 @@ package io.druid.query.filter;
import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
@ -40,6 +41,7 @@ import io.druid.segment.filter.InFilter;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -59,7 +61,7 @@ public class InDimFilter implements DimFilter
@JsonCreator @JsonCreator
public InDimFilter( public InDimFilter(
@JsonProperty("dimension") String dimension, @JsonProperty("dimension") String dimension,
@JsonProperty("values") List<String> values, @JsonProperty("values") Collection<String> values,
@JsonProperty("extractionFn") ExtractionFn extractionFn @JsonProperty("extractionFn") ExtractionFn extractionFn
) )
{ {
@ -227,6 +229,26 @@ public class InDimFilter implements DimFilter
return result; return result;
} }
@Override
public String toString()
{
final StringBuilder builder = new StringBuilder();
if (extractionFn != null) {
builder.append(extractionFn).append("(");
}
builder.append(dimension);
if (extractionFn != null) {
builder.append(")");
}
builder.append(" IN (").append(Joiner.on(", ").join(values)).append(")");
return builder.toString();
}
// As the set of filtered values can be large, parsing them as longs should be done only if needed, and only once. // As the set of filtered values can be large, parsing them as longs should be done only if needed, and only once.
// Pass in a common long predicate supplier to all filters created by .toFilter(), so that // Pass in a common long predicate supplier to all filters created by .toFilter(), so that
// we only compute the long hashset/array once per query. // we only compute the long hashset/array once per query.

View File

@ -146,7 +146,7 @@ public class DimensionTopNMetricSpec implements TopNMetricSpec
{ {
return "DimensionTopNMetricSpec{" + return "DimensionTopNMetricSpec{" +
"previousStop='" + previousStop + '\'' + "previousStop='" + previousStop + '\'' +
"ordering='" + ordering + '\'' + ", ordering=" + ordering +
'}'; '}';
} }

View File

@ -165,4 +165,12 @@ public class InvertedTopNMetricSpec implements TopNMetricSpec
{ {
return delegate != null ? delegate.hashCode() : 0; return delegate != null ? delegate.hashCode() : 0;
} }
@Override
public String toString()
{
return "InvertedTopNMetricSpec{" +
"delegate=" + delegate +
'}';
}
} }