@Nullable @Override public IdLookup idLookup() { return selector.idLookup(); }
@Nullable @Override public IdLookup idLookup() { return Objects.requireNonNull(keptSelector).idLookup(); }
public BaseArrayProvider( DimensionSelector dimSelector, TopNQuery query, StorageAdapter storageAdapter ) { this.idLookup = dimSelector.idLookup(); this.query = query; this.storageAdapter = storageAdapter; previousStop = null; ignoreAfterThreshold = false; ignoreFirstN = 0; keepOnlyN = dimSelector.getValueCardinality(); if (keepOnlyN < 0) { throw new IAE("Cannot operate on a dimension with no dictionary"); } }
/** * @param selector must return true from {@link DimensionSelector#nameLookupPossibleInAdvance()} * @param forwardMapping must have {@link Int2IntOpenHashMap#defaultReturnValue(int)} configured to -1. */ ForwardingFilteredDimensionSelector( DimensionSelector selector, Int2IntOpenHashMap forwardMapping, int[] reverseMapping ) { this.selector = Preconditions.checkNotNull(selector); if (!selector.nameLookupPossibleInAdvance()) { throw new IAE("selector.nameLookupPossibleInAdvance() should return true"); } this.baseIdLookup = selector.idLookup(); this.forwardMapping = Preconditions.checkNotNull(forwardMapping); if (forwardMapping.defaultReturnValue() != -1) { throw new IAE("forwardMapping.defaultReturnValue() should be -1"); } this.reverseMapping = Preconditions.checkNotNull(reverseMapping); }
@Nullable @Override public IdLookup idLookup() { final DimensionSelector valueSelector = getValueSelector(); final IdLookup valueLookup = valueSelector.idLookup(); if (valueLookup != null) { final int valueIndex = findValueIndicesIndexForSubColumn(); return name -> { final int candidate = valueLookup.lookupId(name); if (candidate == valueIndex) { return candidate; } return -1; }; } else { return null; } }
/** * Generic implementation of {@link DimensionSelector#makeValueMatcher(String)}, uses {@link * DimensionSelector#getRow()} of the given {@link DimensionSelector}. "Lazy" DimensionSelectors could delegate * {@code makeValueMatcher()} to this method, but encouraged to implement {@code makeValueMatcher()} themselves, * bypassing the {@link IndexedInts} abstraction. */ public static ValueMatcher makeValueMatcherGeneric(DimensionSelector selector, @Nullable String value) { IdLookup idLookup = selector.idLookup(); if (idLookup != null) { return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null); } else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) { // Employ caching BitSet optimization return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value)); } else { return makeNonDictionaryEncodedValueMatcherGeneric(selector, value); } }
private DimensionSelector filterWhiteList(DimensionSelector selector) { final int selectorCardinality = selector.getValueCardinality(); if (selectorCardinality < 0 || (selector.idLookup() == null && !selector.nameLookupPossibleInAdvance())) { return new PredicateFilteredDimensionSelector(selector, Predicates.in(values)); } final int maxPossibleFilteredCardinality = values.size(); int count = 0; final Int2IntOpenHashMap forwardMapping = new Int2IntOpenHashMap(maxPossibleFilteredCardinality); forwardMapping.defaultReturnValue(-1); final int[] reverseMapping = new int[maxPossibleFilteredCardinality]; IdLookup idLookup = selector.idLookup(); if (idLookup != null) { for (String value : values) { int i = idLookup.lookupId(value); if (i >= 0) { forwardMapping.put(i, count); reverseMapping[count++] = i; } } } else { for (int i = 0; i < selectorCardinality; i++) { if (values.contains(NullHandling.nullToEmptyIfNeeded(selector.lookupName(i)))) { forwardMapping.put(i, count); reverseMapping[count++] = i; } } } return new ForwardingFilteredDimensionSelector(selector, forwardMapping, reverseMapping); }
@Test public void testLookupId() { Assert.assertEquals(0, NULL_SELECTOR.idLookup().lookupId(null)); Assert.assertEquals(NullHandling.replaceWithDefault() ? 0 : -1, NULL_SELECTOR.idLookup().lookupId("")); Assert.assertEquals(-1, NULL_SELECTOR.idLookup().lookupId("billy")); Assert.assertEquals(-1, NULL_SELECTOR.idLookup().lookupId("bob")); Assert.assertEquals(-1, CONST_SELECTOR.idLookup().lookupId(null)); Assert.assertEquals(-1, CONST_SELECTOR.idLookup().lookupId("")); Assert.assertEquals(0, CONST_SELECTOR.idLookup().lookupId("billy")); Assert.assertEquals(-1, CONST_SELECTOR.idLookup().lookupId("bob")); Assert.assertEquals(-1, NULL_EXTRACTION_SELECTOR.idLookup().lookupId(null)); Assert.assertEquals(-1, NULL_EXTRACTION_SELECTOR.idLookup().lookupId("")); Assert.assertEquals(0, NULL_EXTRACTION_SELECTOR.idLookup().lookupId("billy")); Assert.assertEquals(-1, NULL_EXTRACTION_SELECTOR.idLookup().lookupId("bob")); Assert.assertEquals(-1, CONST_EXTRACTION_SELECTOR.idLookup().lookupId(null)); Assert.assertEquals(-1, CONST_EXTRACTION_SELECTOR.idLookup().lookupId("")); Assert.assertEquals(0, CONST_EXTRACTION_SELECTOR.idLookup().lookupId("billy")); Assert.assertEquals(-1, CONST_EXTRACTION_SELECTOR.idLookup().lookupId("bob")); } }
IdLookup keyIdLookup = keySelector.idLookup(); if (keyIdLookup != null) { final int keyId = keyIdLookup.lookupId(subColumnName);
@Test public void testDecoratorWithBlacklist() { ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec( new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "g"), false ); DimensionSelector selector = spec.decorate(TestDimensionSelector.instance); Assert.assertEquals(24, selector.getValueCardinality()); IndexedInts row = selector.getRow(); Assert.assertEquals(1, row.size()); Assert.assertEquals(3, row.get(0)); Assert.assertEquals("a", selector.lookupName(0)); Assert.assertEquals("z", selector.lookupName(23)); Assert.assertEquals(0, selector.idLookup().lookupId("a")); Assert.assertEquals(23, selector.idLookup().lookupId("z")); }
@Test public void testDecoratorWithWhitelist() { ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec( new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "g"), true ); DimensionSelector selector = spec.decorate(TestDimensionSelector.instance); Assert.assertEquals(2, selector.getValueCardinality()); IndexedInts row = selector.getRow(); Assert.assertEquals(2, row.size()); Assert.assertEquals(0, row.get(0)); Assert.assertEquals(1, row.get(1)); Assert.assertEquals("c", selector.lookupName(0)); Assert.assertEquals("g", selector.lookupName(1)); Assert.assertEquals(0, selector.idLookup().lookupId("c")); Assert.assertEquals(1, selector.idLookup().lookupId("g")); }
@Test public void testDecorator() { RegexFilteredDimensionSpec spec = new RegexFilteredDimensionSpec( new DefaultDimensionSpec("foo", "bar"), "[c,g]" ); DimensionSelector selector = spec.decorate(TestDimensionSelector.instance); Assert.assertEquals(2, selector.getValueCardinality()); IndexedInts row = selector.getRow(); Assert.assertEquals(2, row.size()); Assert.assertEquals(0, row.get(0)); Assert.assertEquals(1, row.get(1)); Assert.assertEquals("c", selector.lookupName(0)); Assert.assertEquals("g", selector.lookupName(1)); Assert.assertEquals(0, selector.idLookup().lookupId("c")); Assert.assertEquals(1, selector.idLookup().lookupId("g")); } }
@Test public void testDecoratorWithBlacklistUsingNonPresentValues() { ListFilteredDimensionSpec spec = new ListFilteredDimensionSpec( new DefaultDimensionSpec("foo", "bar"), ImmutableSet.of("c", "gx"), false ); DimensionSelector selector = spec.decorate(TestDimensionSelector.instance); Assert.assertEquals(25, selector.getValueCardinality()); IndexedInts row = selector.getRow(); Assert.assertEquals(2, row.size()); Assert.assertEquals(3, row.get(0)); Assert.assertEquals(5, row.get(1)); Assert.assertEquals("e", selector.lookupName(row.get(0))); Assert.assertEquals("g", selector.lookupName(row.get(1))); Assert.assertEquals("a", selector.lookupName(0)); Assert.assertEquals("z", selector.lookupName(24)); Assert.assertEquals(0, selector.idLookup().lookupId("a")); Assert.assertEquals(24, selector.idLookup().lookupId("z")); } }
@Test public void testDecorator() { PrefixFilteredDimensionSpec spec = new PrefixFilteredDimensionSpec( new DefaultDimensionSpec("foo", "far"), "c" ); DimensionSelector selector = spec.decorate(TestDimensionSelector.instance); Assert.assertEquals(1, selector.getValueCardinality()); IndexedInts row = selector.getRow(); Assert.assertEquals(1, row.size()); Assert.assertEquals(0, row.get(0)); Assert.assertEquals("c", selector.lookupName(0)); Assert.assertEquals(0, selector.idLookup().lookupId("c")); } }
@Nullable @Override public IdLookup idLookup() { return selector.idLookup(); }
@Nullable @Override public IdLookup idLookup() { return Objects.requireNonNull(keptSelector).idLookup(); }
public BaseArrayProvider( DimensionSelector dimSelector, TopNQuery query, StorageAdapter storageAdapter ) { this.idLookup = dimSelector.idLookup(); this.query = query; this.storageAdapter = storageAdapter; previousStop = null; ignoreAfterThreshold = false; ignoreFirstN = 0; keepOnlyN = dimSelector.getValueCardinality(); if (keepOnlyN < 0) { throw new IAE("Cannot operate on a dimension with no dictionary"); } }
/** * @param selector must return true from {@link DimensionSelector#nameLookupPossibleInAdvance()} * @param forwardMapping must have {@link Int2IntOpenHashMap#defaultReturnValue(int)} configured to -1. */ ForwardingFilteredDimensionSelector( DimensionSelector selector, Int2IntOpenHashMap forwardMapping, int[] reverseMapping ) { this.selector = Preconditions.checkNotNull(selector); if (!selector.nameLookupPossibleInAdvance()) { throw new IAE("selector.nameLookupPossibleInAdvance() should return true"); } this.baseIdLookup = selector.idLookup(); this.forwardMapping = Preconditions.checkNotNull(forwardMapping); if (forwardMapping.defaultReturnValue() != -1) { throw new IAE("forwardMapping.defaultReturnValue() should be -1"); } this.reverseMapping = Preconditions.checkNotNull(reverseMapping); }
/** * Generic implementation of {@link DimensionSelector#makeValueMatcher(String)}, uses {@link * DimensionSelector#getRow()} of the given {@link DimensionSelector}. "Lazy" DimensionSelectors could delegate * {@code makeValueMatcher()} to this method, but encouraged to implement {@code makeValueMatcher()} themselves, * bypassing the {@link IndexedInts} abstraction. */ public static ValueMatcher makeValueMatcherGeneric(DimensionSelector selector, @Nullable String value) { IdLookup idLookup = selector.idLookup(); if (idLookup != null) { return makeDictionaryEncodedValueMatcherGeneric(selector, idLookup.lookupId(value), value == null); } else if (selector.getValueCardinality() >= 0 && selector.nameLookupPossibleInAdvance()) { // Employ caching BitSet optimization return makeDictionaryEncodedValueMatcherGeneric(selector, Predicates.equalTo(value)); } else { return makeNonDictionaryEncodedValueMatcherGeneric(selector, value); } }
private DimensionSelector filterWhiteList(DimensionSelector selector) { final int selectorCardinality = selector.getValueCardinality(); if (selectorCardinality < 0 || (selector.idLookup() == null && !selector.nameLookupPossibleInAdvance())) { return new PredicateFilteredDimensionSelector(selector, Predicates.in(values)); } final int maxPossibleFilteredCardinality = values.size(); int count = 0; final Int2IntOpenHashMap forwardMapping = new Int2IntOpenHashMap(maxPossibleFilteredCardinality); forwardMapping.defaultReturnValue(-1); final int[] reverseMapping = new int[maxPossibleFilteredCardinality]; IdLookup idLookup = selector.idLookup(); if (idLookup != null) { for (String value : values) { int i = idLookup.lookupId(value); if (i >= 0) { forwardMapping.put(i, count); reverseMapping[count++] = i; } } } else { for (int i = 0; i < selectorCardinality; i++) { if (values.contains(NullHandling.nullToEmptyIfNeeded(selector.lookupName(i)))) { forwardMapping.put(i, count); reverseMapping[count++] = i; } } } return new ForwardingFilteredDimensionSelector(selector, forwardMapping, reverseMapping); }