formatting changes

This commit is contained in:
Xavier Léauté 2014-04-25 14:51:58 -07:00
parent de5b1749bc
commit c1e6f6d83e
5 changed files with 78 additions and 61 deletions

View File

@ -45,8 +45,8 @@ public class CardinalityAggregator implements Aggregator
{
final Hasher hasher = hashFn.newHasher();
for (int k = 0; k < selectorList.size(); ++k) {
if(k != 0) {
hasher.putByte((byte)0);
if (k != 0) {
hasher.putByte((byte) 0);
}
final DimensionSelector selector = selectorList.get(k);
final IndexedInts row = selector.getRow();
@ -64,7 +64,7 @@ public class CardinalityAggregator implements Aggregator
// Values need to be sorted to ensure consistent multi-value ordering across different segments
Arrays.sort(values);
for (int i = 0; i < size; ++i) {
if(i != 0) {
if (i != 0) {
hasher.putChar(SEPARATOR);
}
hasher.putString(values[i]);
@ -101,7 +101,7 @@ public class CardinalityAggregator implements Aggregator
@Override
public void aggregate()
{
if(byRow) {
if (byRow) {
hashRow(selectorList, collector);
} else {
hashValues(selectorList, collector);

View File

@ -103,14 +103,14 @@ public class CardinalityAggregatorFactory implements AggregatorFactory
Iterables.filter(
Iterables.transform(
fieldNames, new Function<String, DimensionSelector>()
{
@Nullable
@Override
public DimensionSelector apply(@Nullable String input)
{
return columnFactory.makeDimensionSelector(input);
}
}
{
@Nullable
@Override
public DimensionSelector apply(@Nullable String input)
{
return columnFactory.makeDimensionSelector(input);
}
}
), Predicates.notNull()
)
);

View File

@ -59,7 +59,7 @@ public class CardinalityBufferAggregator implements BufferAggregator
+ HyperLogLogCollector.getLatestNumBytesForDenseStorage()
)
);
if(byRow) {
if (byRow) {
CardinalityAggregator.hashRow(selectorList, collector);
} else {
CardinalityAggregator.hashValues(selectorList, collector);

View File

@ -42,10 +42,13 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
ByteBuffer buf;
int pos;
@Param({"1", "5"}) int multivaluedSized;
@Param({"true", "false"}) boolean byRow;
@Param({"1", "5"})
int multivaluedSized;
@Param({"true", "false"})
boolean byRow;
protected void setUp() {
protected void setUp()
{
Iterable<String[]> values = FluentIterable
.from(ContiguousSet.create(Range.closedOpen(0, 500), DiscreteDomain.integers()))
.transform(
@ -54,13 +57,14 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
@Override
public String[] apply(Integer input)
{
if(multivaluedSized == 1) {
if (multivaluedSized == 1) {
return new String[]{input.toString()};
}
else {
} else {
String[] res = new String[multivaluedSized];
String value = input.toString();
for(int i = 0; i < multivaluedSized; ++i) res[i] = value + i;
for (int i = 0; i < multivaluedSized; ++i) {
res[i] = value + i;
}
return res;
}
}
@ -96,15 +100,15 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
agg.init(buf, pos);
}
public Object timeBufferAggregate(int reps) throws Exception {
public Object timeBufferAggregate(int reps) throws Exception
{
for (int i = 0; i < reps; ++i) {
agg.aggregate(buf, pos);
for (final DimensionSelector selector : selectorList) {
if(i % (MAX - 1) == 0) {
if (i % (MAX - 1) == 0) {
((CardinalityAggregatorTest.TestDimensionSelector) selector).reset();
}
else {
} else {
((CardinalityAggregatorTest.TestDimensionSelector) selector).increment();
}
}
@ -114,11 +118,13 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
@Override
protected void tearDown() {
protected void tearDown()
{
}
public static void main(String[] args) throws Exception {
public static void main(String[] args) throws Exception
{
Runner.main(CardinalityAggregatorBenchmark.class, args);
}
}

View File

@ -66,26 +66,26 @@ public class CardinalityAggregatorTest
this.column = Lists.newArrayList(
Iterables.transform(
values, new Function<String[], Integer[]>()
{
@Nullable
@Override
public Integer[] apply(@Nullable String[] input)
{
return Iterators.toArray(
Iterators.transform(
Iterators.forArray(input), new Function<String, Integer>()
{
@Nullable
@Override
public Integer apply(@Nullable String input)
{
return ids.get(input);
}
}
), Integer.class
);
}
}
{
@Nullable
@Override
public Integer[] apply(@Nullable String[] input)
{
return Iterators.toArray(
Iterators.transform(
Iterators.forArray(input), new Function<String, Integer>()
{
@Nullable
@Override
public Integer apply(@Nullable String input)
{
return ids.get(input);
}
}
), Integer.class
);
}
}
)
);
}
@ -159,25 +159,36 @@ public class CardinalityAggregatorTest
"a", "b", "c", "a", "a", null, "b", "b", "b", "b", "a", "a"
);
private static final List<String[]> values2 = dimensionValues(
"a", "b", "c", "x", "a", "e", "b", new String[]{null, "x"}, new String[]{"x", null}, new String[]{"y", "x"}, new String[]{"x", "y"}, new String[] {"x", "y", "a"}
"a",
"b",
"c",
"x",
"a",
"e",
"b",
new String[]{null, "x"},
new String[]{"x", null},
new String[]{"y", "x"},
new String[]{"x", "y"},
new String[]{"x", "y", "a"}
);
private static List<String[]> dimensionValues(Object... values)
{
return Lists.transform(
Lists.newArrayList(values), new Function<Object, String[]>()
{
@Nullable
@Override
public String[] apply(@Nullable Object input)
{
if (input instanceof String[]) {
return (String[]) input;
} else {
return new String[]{(String) input};
{
@Nullable
@Override
public String[] apply(@Nullable Object input)
{
if (input instanceof String[]) {
return (String[]) input;
} else {
return new String[]{(String) input};
}
}
}
}
}
);
}
@ -309,7 +320,7 @@ public class CardinalityAggregatorTest
@Test
public void testCombineRows()
{
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector)dim1);
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector) dim1);
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector) dim2);
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, true);
@ -340,8 +351,8 @@ public class CardinalityAggregatorTest
@Test
public void testCombineValues()
{
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector)dim1);
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector)dim2);
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector) dim1);
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector) dim2);
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, false);
CardinalityAggregator agg2 = new CardinalityAggregator("billy", selector2, false);