mirror of
https://github.com/apache/druid.git
synced 2025-02-26 04:55:24 +00:00
Fix serde for FragmentSearchQuerySpec and add some tests.
This commit is contained in:
parent
bad96537a9
commit
cd2cff24ff
@ -38,9 +38,8 @@ public class FragmentSearchQuerySpec implements SearchQuerySpec
|
|||||||
|
|
||||||
private final String[] target;
|
private final String[] target;
|
||||||
|
|
||||||
@JsonCreator
|
|
||||||
public FragmentSearchQuerySpec(
|
public FragmentSearchQuerySpec(
|
||||||
@JsonProperty("values") List<String> values
|
List<String> values
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this(values, false);
|
this(values, false);
|
||||||
@ -54,7 +53,7 @@ public class FragmentSearchQuerySpec implements SearchQuerySpec
|
|||||||
{
|
{
|
||||||
this.values = values;
|
this.values = values;
|
||||||
this.caseSensitive = caseSensitive;
|
this.caseSensitive = caseSensitive;
|
||||||
Set<String> set = new TreeSet();
|
Set<String> set = new TreeSet<>();
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
for (String value : values) {
|
for (String value : values) {
|
||||||
set.add(value);
|
set.add(value);
|
||||||
|
@ -17,7 +17,12 @@
|
|||||||
|
|
||||||
package io.druid.query.extraction;
|
package io.druid.query.extraction;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import io.druid.jackson.DefaultObjectMapper;
|
||||||
|
import io.druid.query.dimension.ExtractionDimensionSpec;
|
||||||
import io.druid.query.search.search.FragmentSearchQuerySpec;
|
import io.druid.query.search.search.FragmentSearchQuerySpec;
|
||||||
import io.druid.query.search.search.SearchQuerySpec;
|
import io.druid.query.search.search.SearchQuerySpec;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@ -46,11 +51,11 @@ public class SearchQuerySpecDimExtractionFnTest
|
|||||||
public void testExtraction()
|
public void testExtraction()
|
||||||
{
|
{
|
||||||
SearchQuerySpec spec = new FragmentSearchQuerySpec(
|
SearchQuerySpec spec = new FragmentSearchQuerySpec(
|
||||||
Arrays.asList("to", "yo")
|
Arrays.asList("tO", "yO")
|
||||||
);
|
);
|
||||||
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
|
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
|
||||||
List<String> expected = Arrays.asList("Kyoto", "Tokyo", "Toyokawa", "Yorktown");
|
List<String> expected = ImmutableList.of("Kyoto", "Tokyo", "Toyokawa", "Yorktown");
|
||||||
Set<String> extracted = Sets.newHashSet();
|
List<String> extracted = Lists.newArrayList();
|
||||||
|
|
||||||
for (String str : testStrings) {
|
for (String str : testStrings) {
|
||||||
String res = extractionFn.apply(str);
|
String res = extractionFn.apply(str);
|
||||||
@ -59,10 +64,68 @@ public class SearchQuerySpecDimExtractionFnTest
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert.assertEquals(4, extracted.size());
|
Assert.assertEquals(expected, extracted);
|
||||||
|
}
|
||||||
|
|
||||||
for (String str : extracted) {
|
@Test
|
||||||
Assert.assertTrue(expected.contains(str));
|
public void testCaseSensitiveExtraction()
|
||||||
|
{
|
||||||
|
SearchQuerySpec spec = new FragmentSearchQuerySpec(
|
||||||
|
Arrays.asList("to", "yo"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
|
||||||
|
List<String> expected = ImmutableList.of("Kyoto");
|
||||||
|
List<String> extracted = Lists.newArrayList();
|
||||||
|
|
||||||
|
for (String str : testStrings) {
|
||||||
|
String res = extractionFn.apply(str);
|
||||||
|
if (res != null) {
|
||||||
|
extracted.add(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(expected, extracted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCaseSensitiveExtraction2()
|
||||||
|
{
|
||||||
|
SearchQuerySpec spec = new FragmentSearchQuerySpec(
|
||||||
|
Arrays.asList("To", "yo"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
|
||||||
|
List<String> expected = ImmutableList.of("Tokyo", "Toyokawa");
|
||||||
|
List<String> extracted = Lists.newArrayList();
|
||||||
|
|
||||||
|
for (String str : testStrings) {
|
||||||
|
String res = extractionFn.apply(str);
|
||||||
|
if (res != null) {
|
||||||
|
extracted.add(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(expected, extracted);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerde() throws Exception
|
||||||
|
{
|
||||||
|
ObjectMapper objectMapper = new DefaultObjectMapper();
|
||||||
|
SearchQuerySpec spec = new FragmentSearchQuerySpec(
|
||||||
|
Arrays.asList("to", "yo"),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
ExtractionFn extractionFn = new SearchQuerySpecDimExtractionFn(spec);
|
||||||
|
|
||||||
|
ExtractionFn extractionFn2 = objectMapper.readValue(
|
||||||
|
objectMapper.writeValueAsBytes(extractionFn),
|
||||||
|
ExtractionFn.class
|
||||||
|
);
|
||||||
|
FragmentSearchQuerySpec spec2 = (FragmentSearchQuerySpec) ((SearchQuerySpecDimExtractionFn) extractionFn2).getSearchQuerySpec();
|
||||||
|
Assert.assertEquals(extractionFn, extractionFn2);
|
||||||
|
Assert.assertEquals(true, spec2.isCaseSensitive());
|
||||||
|
Assert.assertEquals(ImmutableList.of("to", "yo"), spec2.getValues());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user