use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.
the class ExtractionDimensionSpecTest method testSerdeWithType.
@Test
public void testSerdeWithType() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String oldJson = "{\n" + " \"type\": \"extraction\",\n" + " \"outputName\": \"first3Letters\",\n" + " \"outputType\": \"LONG\",\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.LONG, extractionDimensionSpec.getOutputType());
Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.
the class ExtractionDimensionSpecTest method testSerdeBackwardsCompatibility.
@Test
public void testSerdeBackwardsCompatibility() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String oldJson = "{\n" + " \"type\": \"extraction\",\n" + " \"outputName\": \"first3Letters\",\n" + " \"dimension\": \"myDim\"," + " \"dimExtractionFn\": {\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.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
// new trumps old
final String oldAndNewJson = "{\n" + " \"type\": \"extraction\",\n" + " \"outputName\": \"first3Letters\",\n" + " \"dimension\": \"myDim\"," + " \"extractionFn\": {\n" + " \"type\": \"partial\",\n" + " \"expr\": \"(...).*\"\n" + " },\n" + " \"dimExtractionFn\": {\n" + " \"type\": \"regex\",\n" + " \"expr\": \"(...).*\"\n" + " }\n" + "}";
Assert.assertTrue(objectMapper.readValue(oldAndNewJson, DimensionSpec.class).getExtractionFn() instanceof MatchingDimExtractionFn);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.
the class RegexFilteredDimensionSpecTest method testSerde.
@Test
public void testSerde() throws Exception {
ObjectMapper mapper = TestHelper.getObjectMapper();
String jsonStr = "{\n" + " \"type\": \"regexFiltered\",\n" + " \"delegate\": {\n" + " \"type\": \"default\",\n" + " \"dimension\": \"foo\",\n" + " \"outputName\": \"bar\"\n" + " },\n" + " \"pattern\": \"xxx\"\n" + "}";
RegexFilteredDimensionSpec actual = (RegexFilteredDimensionSpec) mapper.readValue(mapper.writeValueAsString(mapper.readValue(jsonStr, DimensionSpec.class)), DimensionSpec.class);
RegexFilteredDimensionSpec expected = new RegexFilteredDimensionSpec(new DefaultDimensionSpec("foo", "bar"), "xxx");
Assert.assertEquals(expected, actual);
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.
the class SubstringDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"substring\", \"index\" : 1, \"length\" : 3 }";
final String jsonNoLength = "{ \"type\" : \"substring\", \"index\" : 1 }";
SubstringDimExtractionFn extractionFn = (SubstringDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
SubstringDimExtractionFn extractionFnNoLength = (SubstringDimExtractionFn) objectMapper.readValue(jsonNoLength, ExtractionFn.class);
Assert.assertEquals(1, extractionFn.getIndex());
Assert.assertEquals(new Integer(3), extractionFn.getLength());
Assert.assertEquals(1, extractionFnNoLength.getIndex());
Assert.assertEquals(null, extractionFnNoLength.getLength());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
Assert.assertEquals(extractionFnNoLength, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFnNoLength), ExtractionFn.class));
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper in project druid by druid-io.
the class TimeDimExtractionFnTest method testSerde.
@Test
public void testSerde() throws Exception {
final ObjectMapper objectMapper = new DefaultObjectMapper();
final String json = "{ \"type\" : \"time\", \"timeFormat\" : \"MM/dd/yyyy\", \"resultFormat\" : \"QQQ/yyyy\" }";
TimeDimExtractionFn extractionFn = (TimeDimExtractionFn) objectMapper.readValue(json, ExtractionFn.class);
Assert.assertEquals("MM/dd/yyyy", extractionFn.getTimeFormat());
Assert.assertEquals("QQQ/yyyy", extractionFn.getResultFormat());
// round trip
Assert.assertEquals(extractionFn, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionFn), ExtractionFn.class));
}
Aggregations