From 2c464ad9367de51ab42607072beaad14be3df592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Thu, 16 Jul 2015 17:47:16 -0700 Subject: [PATCH] correct reference in docs + more tests / examples --- docs/content/querying/topnmetricspec.md | 2 +- .../topn/AlphaNumericTopNMetricSpecTest.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docs/content/querying/topnmetricspec.md b/docs/content/querying/topnmetricspec.md index 978c80b5005..7ae63c91545 100644 --- a/docs/content/querying/topnmetricspec.md +++ b/docs/content/querying/topnmetricspec.md @@ -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": { diff --git a/processing/src/test/java/io/druid/query/topn/AlphaNumericTopNMetricSpecTest.java b/processing/src/test/java/io/druid/query/topn/AlphaNumericTopNMetricSpecTest.java index 2a6c06322d1..f4333f9652b 100644 --- a/processing/src/test/java/io/druid/query/topn/AlphaNumericTopNMetricSpecTest.java +++ b/processing/src/test/java/io/druid/query/topn/AlphaNumericTopNMetricSpecTest.java @@ -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 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 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