Search in sources :

Example 11 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class LikeDimFilterTest method testSerde.

@Test
public void testSerde() throws IOException {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final DimFilter filter = new LikeDimFilter("foo", "bar%", "@", new SubstringDimExtractionFn(1, 2));
    final DimFilter filter2 = objectMapper.readValue(objectMapper.writeValueAsString(filter), DimFilter.class);
    Assert.assertEquals(filter, filter2);
}
Also used : SubstringDimExtractionFn(org.apache.druid.query.extraction.SubstringDimExtractionFn) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 12 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class TimeFormatExtractionFnTest method testSerdeFromJson.

@Test
public void testSerdeFromJson() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String json = "{ \"type\" : \"timeFormat\", \"format\" : \"HH\" }";
    TimeFormatExtractionFn extractionFn = (TimeFormatExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
    Assert.assertEquals("HH", extractionFn.getFormat());
    Assert.assertEquals(null, extractionFn.getLocale());
    Assert.assertEquals(null, extractionFn.getTimeZone());
    // round trip
    Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 13 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class CascadeExtractionFnTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    objectMapper.setInjectableValues(new InjectableValues.Std().addValue(JavaScriptConfig.class, JavaScriptConfig.getEnabledInstance()));
    final String json = "{\"type\" : \"cascade\", \"extractionFns\": [" + regexDimExtractionFnJson + "," + javascriptExtractionFnJson + "," + substringDimExtractionFnJson + "]}";
    CascadeExtractionFn cascadeExtractionFn = (CascadeExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
    RegexDimExtractionFn regexDimExtractionFn = (RegexDimExtractionFn) objectMapper.readValue(regexDimExtractionFnJson, ExtractionFn.class);
    JavaScriptExtractionFn javascriptExtractionFn = (JavaScriptExtractionFn) objectMapper.readValue(javascriptExtractionFnJson, ExtractionFn.class);
    SubstringDimExtractionFn substringDimExtractionFn = (SubstringDimExtractionFn) objectMapper.readValue(substringDimExtractionFnJson, ExtractionFn.class);
    Assert.assertEquals(regexDimExtractionFn, cascadeExtractionFn.getExtractionFns()[0]);
    Assert.assertEquals(javascriptExtractionFn, cascadeExtractionFn.getExtractionFns()[1]);
    Assert.assertEquals(substringDimExtractionFn, cascadeExtractionFn.getExtractionFns()[2]);
    Assert.assertEquals(cascadeExtractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(cascadeExtractionFn), ExtractionFn.class));
}
Also used : JavaScriptConfig(org.apache.druid.js.JavaScriptConfig) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 14 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class MatchingDimExtractionFnTest method testSerde.

@Test
public void testSerde() throws Exception {
    final ObjectMapper objectMapper = new DefaultObjectMapper();
    final String json = "{ \"type\" : \"partial\", \"expr\" : \".(...)?\" }";
    MatchingDimExtractionFn extractionFn = (MatchingDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
    Assert.assertEquals(".(...)?", extractionFn.getExpr());
    // round trip
    Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
Also used : DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Example 15 with DefaultObjectMapper

use of org.apache.druid.jackson.DefaultObjectMapper in project druid by druid-io.

the class SearchQuerySpecDimExtractionFnTest method testSerde.

@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());
}
Also used : SearchQuerySpec(org.apache.druid.query.search.SearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) FragmentSearchQuerySpec(org.apache.druid.query.search.FragmentSearchQuerySpec) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Test(org.junit.Test)

Aggregations

DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)287 Test (org.junit.Test)245 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)177 File (java.io.File)26 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)25 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)21 Before (org.junit.Before)21 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)20 InjectableValues (com.fasterxml.jackson.databind.InjectableValues)16 DataSegment (org.apache.druid.timeline.DataSegment)16 Period (org.joda.time.Period)16 ConstantPostAggregator (org.apache.druid.query.aggregation.post.ConstantPostAggregator)14 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)13 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)12 DimensionsSpec (org.apache.druid.data.input.impl.DimensionsSpec)11 TaskStatus (org.apache.druid.indexer.TaskStatus)11 AvroStreamInputRowParserTest (org.apache.druid.data.input.AvroStreamInputRowParserTest)10 ImmutableList (com.google.common.collect.ImmutableList)9 Injector (com.google.inject.Injector)9 TimestampSpec (org.apache.druid.data.input.impl.TimestampSpec)9