use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class GroupByQueryRunnerTest method testSubqueryWithExtractionFnInOuterQuery.
@Test
public void testSubqueryWithExtractionFnInOuterQuery() {
// https://github.com/apache/druid/issues/2556
GroupByQuery subquery = makeQueryBuilder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setQuerySegmentSpec(QueryRunnerTestHelper.FIRST_TO_THIRD).setDimensions(new DefaultDimensionSpec("quality", "alias")).setDimFilter(new JavaScriptDimFilter("quality", "function(dim){ return true; }", null, JavaScriptConfig.getEnabledInstance())).setAggregatorSpecs(QueryRunnerTestHelper.ROWS_COUNT, new LongSumAggregatorFactory("idx", "index"), new LongSumAggregatorFactory("indexMaxPlusTen", "indexMaxPlusTen")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
GroupByQuery query = makeQueryBuilder().setDataSource(subquery).setQuerySegmentSpec(new MultipleIntervalSegmentSpec(ImmutableList.of(Intervals.of("2011-04-01T00:00:00.000Z/2011-04-03T00:00:00.000Z")))).setDimensions(new ExtractionDimensionSpec("alias", "alias", new RegexDimExtractionFn("(a).*", true, "a"))).setAggregatorSpecs(new LongSumAggregatorFactory("rows", "rows"), new LongSumAggregatorFactory("idx", "idx")).setGranularity(QueryRunnerTestHelper.DAY_GRAN).build();
List<ResultRow> expectedResults = Arrays.asList(makeRow(query, "2011-04-01", "alias", "a", "rows", 13L, "idx", 6619L), makeRow(query, "2011-04-02", "alias", "a", "rows", 13L, "idx", 5827L));
// Subqueries are handled by the ToolChest
Iterable<ResultRow> results = GroupByQueryRunnerTestHelper.runQuery(factory, runner, query);
TestHelper.assertExpectedObjects(expectedResults, results, "subquery-extractionfn");
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn 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(ColumnType.STRING, extractionDimensionSpec.getOutputType());
Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class CardinalityAggregatorTest method testSerde.
@Test
public void testSerde() throws Exception {
CardinalityAggregatorFactory factory = new CardinalityAggregatorFactory("billy", null, ImmutableList.of(new DefaultDimensionSpec("b", "b"), new DefaultDimensionSpec("a", "a"), new DefaultDimensionSpec("c", "c")), true, true);
ObjectMapper objectMapper = new DefaultObjectMapper();
Assert.assertEquals(factory, objectMapper.readValue(objectMapper.writeValueAsString(factory), AggregatorFactory.class));
String fieldNamesOnly = "{" + "\"type\":\"cardinality\"," + "\"name\":\"billy\"," + "\"fields\":[\"b\",\"a\",\"c\"]," + "\"byRow\":true," + "\"round\":true" + "}";
Assert.assertEquals(factory, objectMapper.readValue(fieldNamesOnly, AggregatorFactory.class));
CardinalityAggregatorFactory factory2 = new CardinalityAggregatorFactory("billy", ImmutableList.of(new ExtractionDimensionSpec("b", "b", new RegexDimExtractionFn(".*", false, null)), new RegexFilteredDimensionSpec(new DefaultDimensionSpec("a", "a"), ".*"), new DefaultDimensionSpec("c", "c")), true);
Assert.assertEquals(factory2, objectMapper.readValue(objectMapper.writeValueAsString(factory2), AggregatorFactory.class));
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn 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(ColumnType.LONG, extractionDimensionSpec.getOutputType());
Assert.assertTrue(extractionDimensionSpec.getExtractionFn() instanceof RegexDimExtractionFn);
Assert.assertEquals(extractionDimensionSpec, objectMapper.readValue(objectMapper.writeValueAsBytes(extractionDimensionSpec), DimensionSpec.class));
}
use of org.apache.druid.query.extraction.RegexDimExtractionFn in project druid by druid-io.
the class TopNQueryRunnerTest method testTopNDimExtractionNoAggregators.
@Test
public void testTopNDimExtractionNoAggregators() {
TopNQuery query = new TopNQueryBuilder().dataSource(QueryRunnerTestHelper.DATA_SOURCE).granularity(QueryRunnerTestHelper.ALL_GRAN).dimension(new ExtractionDimensionSpec(QueryRunnerTestHelper.MARKET_DIMENSION, QueryRunnerTestHelper.MARKET_DIMENSION, new RegexDimExtractionFn("(.)", false, null))).metric(new LexicographicTopNMetricSpec(QueryRunnerTestHelper.MARKET_DIMENSION)).threshold(4).intervals(QueryRunnerTestHelper.FIRST_TO_THIRD).build();
List<Result<TopNResultValue>> expectedResults = Collections.singletonList(new Result<>(DateTimes.of("2011-04-01T00:00:00.000Z"), new TopNResultValue(Arrays.<Map<String, Object>>asList(ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "s"), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "t"), ImmutableMap.of(QueryRunnerTestHelper.MARKET_DIMENSION, "u")))));
assertExpectedResults(expectedResults, query);
}
Aggregations