mirror of https://github.com/apache/druid.git
formatting changes
This commit is contained in:
parent
de5b1749bc
commit
c1e6f6d83e
|
@ -45,8 +45,8 @@ public class CardinalityAggregator implements Aggregator
|
||||||
{
|
{
|
||||||
final Hasher hasher = hashFn.newHasher();
|
final Hasher hasher = hashFn.newHasher();
|
||||||
for (int k = 0; k < selectorList.size(); ++k) {
|
for (int k = 0; k < selectorList.size(); ++k) {
|
||||||
if(k != 0) {
|
if (k != 0) {
|
||||||
hasher.putByte((byte)0);
|
hasher.putByte((byte) 0);
|
||||||
}
|
}
|
||||||
final DimensionSelector selector = selectorList.get(k);
|
final DimensionSelector selector = selectorList.get(k);
|
||||||
final IndexedInts row = selector.getRow();
|
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
|
// Values need to be sorted to ensure consistent multi-value ordering across different segments
|
||||||
Arrays.sort(values);
|
Arrays.sort(values);
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
if(i != 0) {
|
if (i != 0) {
|
||||||
hasher.putChar(SEPARATOR);
|
hasher.putChar(SEPARATOR);
|
||||||
}
|
}
|
||||||
hasher.putString(values[i]);
|
hasher.putString(values[i]);
|
||||||
|
@ -101,7 +101,7 @@ public class CardinalityAggregator implements Aggregator
|
||||||
@Override
|
@Override
|
||||||
public void aggregate()
|
public void aggregate()
|
||||||
{
|
{
|
||||||
if(byRow) {
|
if (byRow) {
|
||||||
hashRow(selectorList, collector);
|
hashRow(selectorList, collector);
|
||||||
} else {
|
} else {
|
||||||
hashValues(selectorList, collector);
|
hashValues(selectorList, collector);
|
||||||
|
|
|
@ -103,14 +103,14 @@ public class CardinalityAggregatorFactory implements AggregatorFactory
|
||||||
Iterables.filter(
|
Iterables.filter(
|
||||||
Iterables.transform(
|
Iterables.transform(
|
||||||
fieldNames, new Function<String, DimensionSelector>()
|
fieldNames, new Function<String, DimensionSelector>()
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public DimensionSelector apply(@Nullable String input)
|
public DimensionSelector apply(@Nullable String input)
|
||||||
{
|
{
|
||||||
return columnFactory.makeDimensionSelector(input);
|
return columnFactory.makeDimensionSelector(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
), Predicates.notNull()
|
), Predicates.notNull()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class CardinalityBufferAggregator implements BufferAggregator
|
||||||
+ HyperLogLogCollector.getLatestNumBytesForDenseStorage()
|
+ HyperLogLogCollector.getLatestNumBytesForDenseStorage()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if(byRow) {
|
if (byRow) {
|
||||||
CardinalityAggregator.hashRow(selectorList, collector);
|
CardinalityAggregator.hashRow(selectorList, collector);
|
||||||
} else {
|
} else {
|
||||||
CardinalityAggregator.hashValues(selectorList, collector);
|
CardinalityAggregator.hashValues(selectorList, collector);
|
||||||
|
|
|
@ -42,10 +42,13 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
|
||||||
ByteBuffer buf;
|
ByteBuffer buf;
|
||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
@Param({"1", "5"}) int multivaluedSized;
|
@Param({"1", "5"})
|
||||||
@Param({"true", "false"}) boolean byRow;
|
int multivaluedSized;
|
||||||
|
@Param({"true", "false"})
|
||||||
|
boolean byRow;
|
||||||
|
|
||||||
protected void setUp() {
|
protected void setUp()
|
||||||
|
{
|
||||||
Iterable<String[]> values = FluentIterable
|
Iterable<String[]> values = FluentIterable
|
||||||
.from(ContiguousSet.create(Range.closedOpen(0, 500), DiscreteDomain.integers()))
|
.from(ContiguousSet.create(Range.closedOpen(0, 500), DiscreteDomain.integers()))
|
||||||
.transform(
|
.transform(
|
||||||
|
@ -54,13 +57,14 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
|
||||||
@Override
|
@Override
|
||||||
public String[] apply(Integer input)
|
public String[] apply(Integer input)
|
||||||
{
|
{
|
||||||
if(multivaluedSized == 1) {
|
if (multivaluedSized == 1) {
|
||||||
return new String[]{input.toString()};
|
return new String[]{input.toString()};
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
String[] res = new String[multivaluedSized];
|
String[] res = new String[multivaluedSized];
|
||||||
String value = input.toString();
|
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;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,15 +100,15 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
|
||||||
agg.init(buf, pos);
|
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) {
|
for (int i = 0; i < reps; ++i) {
|
||||||
agg.aggregate(buf, pos);
|
agg.aggregate(buf, pos);
|
||||||
|
|
||||||
for (final DimensionSelector selector : selectorList) {
|
for (final DimensionSelector selector : selectorList) {
|
||||||
if(i % (MAX - 1) == 0) {
|
if (i % (MAX - 1) == 0) {
|
||||||
((CardinalityAggregatorTest.TestDimensionSelector) selector).reset();
|
((CardinalityAggregatorTest.TestDimensionSelector) selector).reset();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
((CardinalityAggregatorTest.TestDimensionSelector) selector).increment();
|
((CardinalityAggregatorTest.TestDimensionSelector) selector).increment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,11 +118,13 @@ public class CardinalityAggregatorBenchmark extends SimpleBenchmark
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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);
|
Runner.main(CardinalityAggregatorBenchmark.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,26 +66,26 @@ public class CardinalityAggregatorTest
|
||||||
this.column = Lists.newArrayList(
|
this.column = Lists.newArrayList(
|
||||||
Iterables.transform(
|
Iterables.transform(
|
||||||
values, new Function<String[], Integer[]>()
|
values, new Function<String[], Integer[]>()
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Integer[] apply(@Nullable String[] input)
|
public Integer[] apply(@Nullable String[] input)
|
||||||
{
|
{
|
||||||
return Iterators.toArray(
|
return Iterators.toArray(
|
||||||
Iterators.transform(
|
Iterators.transform(
|
||||||
Iterators.forArray(input), new Function<String, Integer>()
|
Iterators.forArray(input), new Function<String, Integer>()
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public Integer apply(@Nullable String input)
|
public Integer apply(@Nullable String input)
|
||||||
{
|
{
|
||||||
return ids.get(input);
|
return ids.get(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
), Integer.class
|
), Integer.class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -159,25 +159,36 @@ public class CardinalityAggregatorTest
|
||||||
"a", "b", "c", "a", "a", null, "b", "b", "b", "b", "a", "a"
|
"a", "b", "c", "a", "a", null, "b", "b", "b", "b", "a", "a"
|
||||||
);
|
);
|
||||||
private static final List<String[]> values2 = dimensionValues(
|
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)
|
private static List<String[]> dimensionValues(Object... values)
|
||||||
{
|
{
|
||||||
return Lists.transform(
|
return Lists.transform(
|
||||||
Lists.newArrayList(values), new Function<Object, String[]>()
|
Lists.newArrayList(values), new Function<Object, String[]>()
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public String[] apply(@Nullable Object input)
|
public String[] apply(@Nullable Object input)
|
||||||
{
|
{
|
||||||
if (input instanceof String[]) {
|
if (input instanceof String[]) {
|
||||||
return (String[]) input;
|
return (String[]) input;
|
||||||
} else {
|
} else {
|
||||||
return new String[]{(String) input};
|
return new String[]{(String) input};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +320,7 @@ public class CardinalityAggregatorTest
|
||||||
@Test
|
@Test
|
||||||
public void testCombineRows()
|
public void testCombineRows()
|
||||||
{
|
{
|
||||||
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector)dim1);
|
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector) dim1);
|
||||||
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector) dim2);
|
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector) dim2);
|
||||||
|
|
||||||
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, true);
|
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, true);
|
||||||
|
@ -340,8 +351,8 @@ public class CardinalityAggregatorTest
|
||||||
@Test
|
@Test
|
||||||
public void testCombineValues()
|
public void testCombineValues()
|
||||||
{
|
{
|
||||||
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector)dim1);
|
List<DimensionSelector> selector1 = Lists.newArrayList((DimensionSelector) dim1);
|
||||||
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector)dim2);
|
List<DimensionSelector> selector2 = Lists.newArrayList((DimensionSelector) dim2);
|
||||||
|
|
||||||
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, false);
|
CardinalityAggregator agg1 = new CardinalityAggregator("billy", selector1, false);
|
||||||
CardinalityAggregator agg2 = new CardinalityAggregator("billy", selector2, false);
|
CardinalityAggregator agg2 = new CardinalityAggregator("billy", selector2, false);
|
||||||
|
|
Loading…
Reference in New Issue