use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class ExtractionDimensionSpecTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String oldJson = "{\n" + " \"type\": \"extraction\",\n" + " \"outputName\": \"first3Letters\",\n" + " \"dimension\": \"myDim\"," + " \"extractionFn\": {\n" + " \"type\": \"regex\",\n" + " \"expr\": \"(...).*\"\n" + " }\n" + "}";
final ExtractionDimensionSpec extractionDimensionSpec = (ExtractionDimensionSpec) objectMapper.readValue(oldJson, DimensionSpec.class);
Assert.assertEquals("first3Letters", extractionDimensionSpec.getOutputName());
Assert.assertEquals("myDim", extractionDimensionSpec.getDimension());
Assert.assertNotNull(extractionDimensionSpec.getExtractionFn());
Assert.assertEquals(ValueType.STRING, extractionDimensionSpec.getOutputType());
Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
}
use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class BucketExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json1 = "{ \"type\" : \"bucket\", \"size\" : \"2\", \"offset\" : \"0.5\" }";
BucketExtractionFn extractionFn1 = (BucketExtractionFn) objectMapper.readValue(json1, ExtractionFn.class);
Assert.assertEquals(2, extractionFn1.getSize(), DELTA);
Assert.assertEquals(0.5, extractionFn1.getOffset(), DELTA);
Assert.assertEquals(extractionFn1, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn1), ExtractionFn.class));
final String json2 = "{ \"type\" : \"bucket\"}";
BucketExtractionFn extractionFn2 = (BucketExtractionFn) objectMapper.readValue(json2, ExtractionFn.class);
Assert.assertEquals(1, extractionFn2.getSize(), DELTA);
Assert.assertEquals(0, extractionFn2.getOffset(), DELTA);
Assert.assertEquals(extractionFn2, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn2), ExtractionFn.class));
}
use of io.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));
}
use of io.druid.jackson.DefaultObjectMapper in project druid by druid-io.
the class JavaScriptExtractionFnTest 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\" : \"javascript\", \"function\" : \"function(str) { return str.substring(0,3); }\" }";
JavaScriptExtractionFn extractionFn = (JavaScriptExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals("function(str) { return str.substring(0,3); }", extractionFn.getFunction());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
use of io.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));
}
Aggregations