correct reference in docs + more tests / examples

This commit is contained in:
Xavier Léauté 2015-07-16 17:47:16 -07:00
parent 9616c10b1d
commit 2c464ad936
2 changed files with 27 additions and 1 deletions

View File

@ -47,7 +47,7 @@ The grammar for dimension values sorted lexicographically is as follows:
## AlphaNumeric TopNMetricSpec ## AlphaNumeric TopNMetricSpec
Sort dimension values in alpha-numeric order, i.e treating numbers differently from other characters in sorting the values. Sort dimension values in alpha-numeric order, i.e treating numbers differently from other characters in sorting the values.
See [http://www.davekoelle.com/alphanum.html](http://www.davekoelle.com/alphanum.html) for details on how the algorithm works. The algorithm is based on [https://github.com/amjjd/java-alphanum](https://github.com/amjjd/java-alphanum).
```json ```json
"metric": { "metric": {

View File

@ -18,12 +18,16 @@
package io.druid.query.topn; package io.druid.query.topn;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import io.druid.jackson.DefaultObjectMapper; import io.druid.jackson.DefaultObjectMapper;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
public class AlphaNumericTopNMetricSpecTest public class AlphaNumericTopNMetricSpecTest
{ {
@ -61,6 +65,28 @@ public class AlphaNumericTopNMetricSpecTest
// ... don't work too well // ... don't work too well
Assert.assertTrue(comparator.compare("1.3", "1.15") < 0); Assert.assertTrue(comparator.compare("1.3", "1.15") < 0);
// but you can sort ranges
List<String> sorted = Lists.newArrayList("1-5", "11-15", "16-20", "21-25", "26-30", "6-10", "Other");
Collections.sort(sorted, comparator);
Assert.assertEquals(
ImmutableList.of("1-5", "6-10", "11-15", "16-20", "21-25", "26-30", "Other"),
sorted
);
List<String> sortedFixedDecimal = Lists.newArrayList(
"Other", "[0.00-0.05)", "[0.05-0.10)", "[0.10-0.50)", "[0.50-1.00)",
"[1.00-5.00)", "[5.00-10.00)", "[10.00-20.00)"
);
Collections.sort(sortedFixedDecimal, comparator);
Assert.assertEquals(
ImmutableList.of(
"[0.00-0.05)", "[0.05-0.10)", "[0.10-0.50)", "[0.50-1.00)",
"[1.00-5.00)", "[5.00-10.00)", "[10.00-20.00)", "Other"
),
sortedFixedDecimal
);
} }
@Test @Test