@Override public String lookupName(int id) { return selector.lookupName(id); }
@Override public String lookupName(int id) { return selector.lookupName(reverseMapping[id]); }
@Nullable @Override public String lookupName(int id) { return Objects.requireNonNull(keptSelector).lookupName(id); }
@Nullable @Override public String lookupName(int id) { final int valueIndex = findValueIndicesIndexForSubColumn(); if (valueIndex == id) { return getValueSelector().lookupName(id); } else { return null; } }
/** * Checks if the given selector constantly returns null. This method could be used in the beginning of execution of * some queries and making some aggregations for heuristic shortcuts. */ static boolean isNilSelector(final DimensionSelector selector) { return selector.nameLookupPossibleInAdvance() && selector.getValueCardinality() == 1 && selector.lookupName(0) == null; }
public static BitSet makePredicateMatchingSet(DimensionSelector selector, Predicate<String> predicate) { if (!selector.nameLookupPossibleInAdvance()) { throw new IAE("selector.nameLookupPossibleInAdvance() should return true"); } int cardinality = selector.getValueCardinality(); BitSet valueIds = new BitSet(cardinality); for (int i = 0; i < cardinality; i++) { if (predicate.apply(selector.lookupName(i))) { valueIds.set(i); } } return valueIds; } }
@VisibleForTesting @Nonnull static Supplier<Object> supplierFromDimensionSelector(final DimensionSelector selector) { Preconditions.checkNotNull(selector, "selector"); return () -> { final IndexedInts row = selector.getRow(); if (row.size() == 1) { return selector.lookupName(row.get(0)); } else { // Can't handle non-singly-valued rows in expressions. // Treat them as nulls until we think of something better to do. return null; } }; }
@Override protected void putToMap(Integer key, Map<String, Object> map) { if (dim != null) { if (key != -1) { map.put( dim.getOutputName(), ((DimensionSelector) dim.getSelector()).lookupName(key) ); } else { map.put(dim.getOutputName(), ""); } } } }
@Nullable @Override public String getObject() { final IndexedInts keyIndices = keySelector.getRow(); final IndexedInts valueIndices = valueSelector.getRow(); final int limit = Math.min(keyIndices.size(), valueIndices.size()); for (int i = 0; i < limit; i++) { if (Objects.equals(keySelector.lookupName(keyIndices.get(i)), subColumnName)) { return valueSelector.lookupName(valueIndices.get(i)); } } return null; } };
@Override public Map getObject() { final IndexedInts keyIndices = keySelector.getRow(); final IndexedInts valueIndices = valueSelector.getRow(); final int limit = Math.min(keyIndices.size(), valueIndices.size()); final Map<String, String> map = Maps.newHashMapWithExpectedSize(limit); for (int i = 0; i < limit; i++) { map.put( keySelector.lookupName(keyIndices.get(i)), valueSelector.lookupName(valueIndices.get(i)) ); } return map; } };
@Override public boolean matches() { final IndexedInts row = selector.getRow(); final int size = row.size(); if (size == 0) { // null should match empty rows in multi-value columns return matchNull; } else { for (int i = 0; i < size; ++i) { if (predicate.apply(selector.lookupName(row.get(i)))) { return true; } } return false; } }
@Override public Supplier<Comparable> makeInputRawSupplier(DimensionSelector selector) { return () -> { IndexedInts index = selector.getRow(); return index.size() == 0 ? null : selector.lookupName(index.get(0)); }; } }
@Nullable @Override public Object getObject() { final int valueIndex = findValueIndicesIndexForSubColumn(); if (valueIndex < 0) { return null; } else { final DimensionSelector valueSelector = getValueSelector(); final IndexedInts valueIndices = valueSelector.getRow(); return valueSelector.lookupName(valueIndices.get(valueIndex)); } }
@Override public String lookupName(final int id) { final String value; if (id == 0) { // id 0 is always null for this selector impl. value = null; } else { value = selector.lookupName(id - nullAdjustment); } bindings.set(value); return expression.eval(bindings).asString(); }
@Test public void testLookupName() { Assert.assertEquals(null, NULL_SELECTOR.lookupName(0)); Assert.assertEquals("billy", CONST_SELECTOR.lookupName(0)); Assert.assertEquals("billy", NULL_EXTRACTION_SELECTOR.lookupName(0)); Assert.assertEquals("billy", CONST_EXTRACTION_SELECTOR.lookupName(0)); }
@Nullable @Override public String getObject() { final IndexedInts keyIndices = keySelector.getRow(); final IndexedInts valueIndices = valueSelector.getRow(); final int limit = Math.min(keyIndices.size(), valueIndices.size()); for (int i = 0; i < limit; i++) { if (keyIndices.get(i) == keyId) { return valueSelector.lookupName(valueIndices.get(i)); } } return null; } };
@Override public IndexedInts getRow() { IndexedInts baseRow = selector.getRow(); int baseRowSize = baseRow.size(); row.ensureSize(baseRowSize); int resultSize = 0; for (int i = 0; i < baseRowSize; i++) { if (predicate.apply(selector.lookupName(baseRow.get(i)))) { row.setValue(resultSize, i); resultSize++; } } row.setSize(resultSize); return row; }
@Override public void hashValues(DimensionSelector dimSelector, HyperLogLogCollector collector) { IndexedInts row = dimSelector.getRow(); for (int i = 0, rowSize = row.size(); i < rowSize; i++) { int index = row.get(i); final String value = dimSelector.lookupName(index); // SQL standard spec does not count null values, // Skip counting null values when we are not replacing null with default value. // A special value for null in case null handling is configured to use empty string for null. if (NullHandling.replaceWithDefault() || value != null) { collector.add(CardinalityAggregator.hashFn.hashUnencodedChars(nullToSpecial(value)).asBytes()); } } }
@Override public List<String> apply(Cursor input) { final DimensionSelector selector = input .getColumnSelectorFactory() .makeDimensionSelector(new DefaultDimensionSpec(selectColumn, selectColumn)); final List<String> values = new ArrayList<>(); while (!input.isDone()) { IndexedInts row = selector.getRow(); Preconditions.checkState(row.size() == 1); values.add(selector.lookupName(row.get(0))); input.advance(); } return values; } }
@Test public void testMakeSelectorsWithDotSupport() { final VirtualColumns virtualColumns = makeVirtualColumns(); final BaseObjectColumnValueSelector objectSelector = virtualColumns.makeColumnValueSelector("foo.5", null); final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector( new DefaultDimensionSpec("foo.5", "x"), null ); final BaseFloatColumnValueSelector floatSelector = virtualColumns.makeColumnValueSelector("foo.5", null); final BaseLongColumnValueSelector longSelector = virtualColumns.makeColumnValueSelector("foo.5", null); Assert.assertEquals(5L, objectSelector.getObject()); Assert.assertEquals("5", dimensionSelector.lookupName(dimensionSelector.getRow().get(0))); Assert.assertEquals(5.0f, floatSelector.getFloat(), 0.0f); Assert.assertEquals(5L, longSelector.getLong()); }