mirror of https://github.com/apache/druid.git
correct reference in docs + more tests / examples
This commit is contained in:
parent
9616c10b1d
commit
2c464ad936
|
@ -47,7 +47,7 @@ The grammar for dimension values sorted lexicographically is as follows:
|
|||
## AlphaNumeric TopNMetricSpec
|
||||
|
||||
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
|
||||
"metric": {
|
||||
|
|
|
@ -18,12 +18,16 @@
|
|||
package io.druid.query.topn;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.druid.jackson.DefaultObjectMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class AlphaNumericTopNMetricSpecTest
|
||||
{
|
||||
|
@ -61,6 +65,28 @@ public class AlphaNumericTopNMetricSpecTest
|
|||
// ... don't work too well
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue