From c1e6f6d83efa962d245589eb59ba50a6a32ecd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Fri, 25 Apr 2014 14:51:58 -0700 Subject: [PATCH] formatting changes --- .../cardinality/CardinalityAggregator.java | 8 +- .../CardinalityAggregatorFactory.java | 16 ++-- .../CardinalityBufferAggregator.java | 2 +- .../CardinalityAggregatorBenchmark.java | 32 +++++--- .../CardinalityAggregatorTest.java | 81 +++++++++++-------- 5 files changed, 78 insertions(+), 61 deletions(-) diff --git a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregator.java b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregator.java index e1fbc806fe2..85a07fd0715 100644 --- a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregator.java @@ -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); diff --git a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java index 95303187e8d..609b29fbad2 100644 --- a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java +++ b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorFactory.java @@ -103,14 +103,14 @@ public class CardinalityAggregatorFactory implements AggregatorFactory Iterables.filter( Iterables.transform( fieldNames, new Function() - { - @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() ) ); diff --git a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityBufferAggregator.java b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityBufferAggregator.java index 84143b7870d..8c084f46a83 100644 --- a/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityBufferAggregator.java +++ b/processing/src/main/java/io/druid/query/aggregation/cardinality/CardinalityBufferAggregator.java @@ -59,7 +59,7 @@ public class CardinalityBufferAggregator implements BufferAggregator + HyperLogLogCollector.getLatestNumBytesForDenseStorage() ) ); - if(byRow) { + if (byRow) { CardinalityAggregator.hashRow(selectorList, collector); } else { CardinalityAggregator.hashValues(selectorList, collector); diff --git a/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorBenchmark.java b/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorBenchmark.java index 9adc153fb50..2aee3a9196e 100644 --- a/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorBenchmark.java +++ b/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorBenchmark.java @@ -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 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); } } diff --git a/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorTest.java b/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorTest.java index 239d249a5d6..4d27df07303 100644 --- a/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorTest.java +++ b/processing/src/test/java/io/druid/query/aggregation/cardinality/CardinalityAggregatorTest.java @@ -66,26 +66,26 @@ public class CardinalityAggregatorTest this.column = Lists.newArrayList( Iterables.transform( values, new Function() - { - @Nullable - @Override - public Integer[] apply(@Nullable String[] input) - { - return Iterators.toArray( - Iterators.transform( - Iterators.forArray(input), new Function() - { - @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() + { + @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 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 dimensionValues(Object... values) { return Lists.transform( Lists.newArrayList(values), new Function() - { - @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 selector1 = Lists.newArrayList((DimensionSelector)dim1); + List selector1 = Lists.newArrayList((DimensionSelector) dim1); List selector2 = Lists.newArrayList((DimensionSelector) dim2); CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, true); @@ -340,8 +351,8 @@ public class CardinalityAggregatorTest @Test public void testCombineValues() { - List selector1 = Lists.newArrayList((DimensionSelector)dim1); - List selector2 = Lists.newArrayList((DimensionSelector)dim2); + List selector1 = Lists.newArrayList((DimensionSelector) dim1); + List selector2 = Lists.newArrayList((DimensionSelector) dim2); CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, false); CardinalityAggregator agg2 = new CardinalityAggregator("billy", selector2, false);