Search in sources :

Example 1 with MatchingDimExtractionFn

use of org.apache.druid.query.extraction.MatchingDimExtractionFn 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);
}
Also used : MatchingDimExtractionFn(org.apache.druid.query.extraction.MatchingDimExtractionFn) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) RegexDimExtractionFn(org.apache.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DefaultObjectMapper (org.apache.druid.jackson.DefaultObjectMapper)1 MatchingDimExtractionFn (org.apache.druid.query.extraction.MatchingDimExtractionFn)1 RegexDimExtractionFn (org.apache.druid.query.extraction.RegexDimExtractionFn)1 Test (org.junit.Test)1