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);
}
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);
}
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);
}
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);
}
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"))));
}
Aggregations