Search in sources :

Example 36 with ExtractionFn

use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.

the class SearchQueryRunnerTest method testSearchOnLongColumnWithExFn.

@Test
public void testSearchOnLongColumnWithExFn() {
    String jsFn = "function(str) { return 'super-' + str; }";
    ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new ExtractionDimensionSpec(Column.TIME_COLUMN_NAME, Column.TIME_COLUMN_NAME, jsExtractionFn)).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("1297123200000").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(Column.TIME_COLUMN_NAME, "super-1297123200000", 13));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) SearchHit(io.druid.query.search.search.SearchHit) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 37 with ExtractionFn

use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.

the class SearchQueryRunnerTest method testSearchOnFloatColumnWithExFn.

@Test
public void testSearchOnFloatColumnWithExFn() {
    String jsFn = "function(str) { return 'super-' + str; }";
    ExtractionFn jsExtractionFn = new JavaScriptExtractionFn(jsFn, false, JavaScriptConfig.getEnabledInstance());
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new ExtractionDimensionSpec(QueryRunnerTestHelper.indexMetric, QueryRunnerTestHelper.indexMetric, jsExtractionFn)).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).query("100.7").build();
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "super-100.7060546875", 1));
    expectedHits.add(new SearchHit(QueryRunnerTestHelper.indexMetric, "super-100.77559661865234", 1));
    checkSearchQuery(searchQuery, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) LookupExtractionFn(io.druid.query.lookup.LookupExtractionFn) ExtractionFn(io.druid.query.extraction.ExtractionFn) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) TimeFormatExtractionFn(io.druid.query.extraction.TimeFormatExtractionFn) SearchHit(io.druid.query.search.search.SearchHit) JavaScriptExtractionFn(io.druid.query.extraction.JavaScriptExtractionFn) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 38 with ExtractionFn

use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.

the class DimensionSelectorHavingSpecTest method testEquals.

@Test
public void testEquals() throws Exception {
    ExtractionFn extractionFn1 = new RegexDimExtractionFn("^([^,]*),", false, "");
    ExtractionFn extractionFn2 = new RegexDimExtractionFn(",(.*)", false, "");
    ExtractionFn extractionFn3 = new RegexDimExtractionFn("^([^,]*),", false, "");
    HavingSpec dimHavingSpec1 = new DimensionSelectorHavingSpec("dim", "v", extractionFn1);
    HavingSpec dimHavingSpec2 = new DimensionSelectorHavingSpec("dim", "v", extractionFn3);
    HavingSpec dimHavingSpec3 = new DimensionSelectorHavingSpec("dim1", "v", null);
    HavingSpec dimHavingSpec4 = new DimensionSelectorHavingSpec("dim2", "v", null);
    HavingSpec dimHavingSpec5 = new DimensionSelectorHavingSpec("dim", "v1", null);
    HavingSpec dimHavingSpec6 = new DimensionSelectorHavingSpec("dim", "v2", null);
    HavingSpec dimHavingSpec7 = new DimensionSelectorHavingSpec("dim", null, null);
    HavingSpec dimHavingSpec8 = new DimensionSelectorHavingSpec("dim", null, null);
    HavingSpec dimHavingSpec9 = new DimensionSelectorHavingSpec("dim1", null, null);
    HavingSpec dimHavingSpec10 = new DimensionSelectorHavingSpec("dim2", null, null);
    HavingSpec dimHavingSpec11 = new DimensionSelectorHavingSpec("dim1", "v", null);
    HavingSpec dimHavingSpec12 = new DimensionSelectorHavingSpec("dim2", null, null);
    HavingSpec dimHavingSpec13 = new DimensionSelectorHavingSpec("dim", "value", extractionFn1);
    HavingSpec dimHavingSpec14 = new DimensionSelectorHavingSpec("dim", "value", extractionFn2);
    assertEquals(dimHavingSpec1, dimHavingSpec2);
    assertNotEquals(dimHavingSpec3, dimHavingSpec4);
    assertNotEquals(dimHavingSpec5, dimHavingSpec6);
    assertEquals(dimHavingSpec7, dimHavingSpec8);
    assertNotEquals(dimHavingSpec9, dimHavingSpec10);
    assertNotEquals(dimHavingSpec11, dimHavingSpec12);
    assertNotEquals(dimHavingSpec13, dimHavingSpec14);
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 39 with ExtractionFn

use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.

the class DimensionSelectorHavingSpecTest method testToString.

@Test
public void testToString() {
    ExtractionFn extractionFn = new RegexDimExtractionFn("^([^,]*),", false, "");
    String expected = "DimensionSelectorHavingSpec{" + "dimension='gender'," + " value='m'," + " extractionFunction='regex(^([^,]*),)'}";
    Assert.assertEquals(new DimensionSelectorHavingSpec("gender", "m", extractionFn).toString(), expected);
    expected = "DimensionSelectorHavingSpec{" + "dimension='gender'," + " value='m'," + " extractionFunction='Identity'}";
    Assert.assertEquals(new DimensionSelectorHavingSpec("gender", "m", null).toString(), expected);
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Example 40 with ExtractionFn

use of io.druid.query.extraction.ExtractionFn in project druid by druid-io.

the class DimensionSelectorHavingSpecTest method testDimensionFilterSpec.

@Test
public void testDimensionFilterSpec() {
    DimensionSelectorHavingSpec spec = new DimensionSelectorHavingSpec("dimension", "v", null);
    assertTrue(spec.eval(getTestRow("v")));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of())));
    assertFalse(spec.eval(getTestRow("v1")));
    spec = new DimensionSelectorHavingSpec("dimension", null, null);
    assertTrue(spec.eval(getTestRow(ImmutableList.of())));
    assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    spec = new DimensionSelectorHavingSpec("dimension", "", null);
    assertTrue(spec.eval(getTestRow(ImmutableList.of())));
    assertTrue(spec.eval(getTestRow(ImmutableList.of(""))));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v", "v1", ""))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v", "v1"))));
    ExtractionFn extractionFn = new RegexDimExtractionFn("^([^,]*),", true, "default");
    spec = new DimensionSelectorHavingSpec("dimension", "v", extractionFn);
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v,v1", "v2,v3"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v1,v4"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v"))));
    assertFalse(spec.eval(getTestRow(ImmutableList.of("v1", "default"))));
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v,default", "none"))));
    spec = new DimensionSelectorHavingSpec("dimension", "default", extractionFn);
    assertTrue(spec.eval(getTestRow(ImmutableList.of("v1,v2", "none"))));
}
Also used : ExtractionFn(io.druid.query.extraction.ExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) IdentityExtractionFn(io.druid.query.extraction.IdentityExtractionFn) RegexDimExtractionFn(io.druid.query.extraction.RegexDimExtractionFn) Test(org.junit.Test)

Aggregations

ExtractionFn (io.druid.query.extraction.ExtractionFn)40 Test (org.junit.Test)32 JavaScriptExtractionFn (io.druid.query.extraction.JavaScriptExtractionFn)29 TimeFormatExtractionFn (io.druid.query.extraction.TimeFormatExtractionFn)24 LookupExtractionFn (io.druid.query.lookup.LookupExtractionFn)24 RegexDimExtractionFn (io.druid.query.extraction.RegexDimExtractionFn)21 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)19 DimExtractionFn (io.druid.query.extraction.DimExtractionFn)17 StrlenExtractionFn (io.druid.query.extraction.StrlenExtractionFn)17 DateTime (org.joda.time.DateTime)12 Result (io.druid.query.Result)10 Row (io.druid.data.input.Row)9 DimensionSpec (io.druid.query.dimension.DimensionSpec)9 CascadeExtractionFn (io.druid.query.extraction.CascadeExtractionFn)9 LongSumAggregatorFactory (io.druid.query.aggregation.LongSumAggregatorFactory)8 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)8 SelectorDimFilter (io.druid.query.filter.SelectorDimFilter)8 ListFilteredDimensionSpec (io.druid.query.dimension.ListFilteredDimensionSpec)5 DoubleMaxAggregatorFactory (io.druid.query.aggregation.DoubleMaxAggregatorFactory)4 DoubleMinAggregatorFactory (io.druid.query.aggregation.DoubleMinAggregatorFactory)4