Search in sources :

Example 56 with MapLookupExtractor

use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class LookupExtractionFnTest method testCacheKey.

@Test
public void testCacheKey() {
    if (retainMissing && !NullHandling.isNullOrEquivalent(replaceMissing)) {
        // skip
        return;
    }
    final Map<String, String> weirdMap = new HashMap<>();
    weirdMap.put("foobar", null);
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    if (NullHandling.isNullOrEquivalent(replaceMissing) || retainMissing) {
        Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), !lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), lookupExtractionFn.isInjective(), false).getCacheKey()));
        Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), !lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), !lookupExtractionFn.isInjective(), false).getCacheKey()));
    }
    Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(new MapLookupExtractor(weirdMap, false), lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), lookupExtractionFn.isInjective(), false).getCacheKey()));
    Assert.assertFalse(Arrays.equals(lookupExtractionFn.getCacheKey(), new LookupExtractionFn(lookupExtractionFn.getLookup(), lookupExtractionFn.isRetainMissingValue(), lookupExtractionFn.getReplaceMissingValueWith(), !lookupExtractionFn.isInjective(), false).getCacheKey()));
}
Also used : HashMap(java.util.HashMap) MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Example 57 with MapLookupExtractor

use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class LookupExtractionFnTest method testEqualsAndHash.

@Test
public void testEqualsAndHash() {
    if (retainMissing && !NullHandling.isNullOrEquivalent(replaceMissing)) {
        // skip
        return;
    }
    final LookupExtractionFn lookupExtractionFn1 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    final LookupExtractionFn lookupExtractionFn2 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), retainMissing, replaceMissing, injective, false);
    final LookupExtractionFn lookupExtractionFn3 = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar2"), false), retainMissing, replaceMissing, injective, false);
    Assert.assertEquals(lookupExtractionFn1, lookupExtractionFn2);
    Assert.assertEquals(lookupExtractionFn1.hashCode(), lookupExtractionFn2.hashCode());
    Assert.assertNotEquals(lookupExtractionFn1, lookupExtractionFn3);
    Assert.assertNotEquals(lookupExtractionFn1.hashCode(), lookupExtractionFn3.hashCode());
}
Also used : MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Example 58 with MapLookupExtractor

use of org.apache.druid.query.extraction.MapLookupExtractor in project druid by druid-io.

the class LookupExtractionFnExpectationsTest method testMissingKeyIsReplaced.

@Test
public void testMissingKeyIsReplaced() {
    final LookupExtractionFn lookupExtractionFn = new LookupExtractionFn(new MapLookupExtractor(ImmutableMap.of("foo", "bar"), false), false, "REPLACE", false, false);
    Assert.assertEquals("REPLACE", lookupExtractionFn.apply(null));
}
Also used : MapLookupExtractor(org.apache.druid.query.extraction.MapLookupExtractor) Test(org.junit.Test)

Aggregations

MapLookupExtractor (org.apache.druid.query.extraction.MapLookupExtractor)58 Test (org.junit.Test)56 LookupExtractionFn (org.apache.druid.query.lookup.LookupExtractionFn)40 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)30 HashMap (java.util.HashMap)25 ExtractionDimensionSpec (org.apache.druid.query.dimension.ExtractionDimensionSpec)20 LongSumAggregatorFactory (org.apache.druid.query.aggregation.LongSumAggregatorFactory)18 SelectorDimFilter (org.apache.druid.query.filter.SelectorDimFilter)14 Result (org.apache.druid.query.Result)13 ExtractionDimFilter (org.apache.druid.query.filter.ExtractionDimFilter)13 ImmutableList (com.google.common.collect.ImmutableList)11 List (java.util.List)11 NullHandlingTest (org.apache.druid.common.config.NullHandlingTest)11 PreJoinableClause (org.apache.druid.query.planning.PreJoinableClause)11 InDimFilter (org.apache.druid.query.filter.InDimFilter)10 DefaultDimensionSpec (org.apache.druid.query.dimension.DefaultDimensionSpec)8 BoundDimFilter (org.apache.druid.query.filter.BoundDimFilter)8 LookupExtractor (org.apache.druid.query.lookup.LookupExtractor)8 JavaScriptDimFilter (org.apache.druid.query.filter.JavaScriptDimFilter)6 RegexDimFilter (org.apache.druid.query.filter.RegexDimFilter)6