Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,25 +165,25 @@ public String get()
public DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory)
{
// Could probably do something useful here if the column name is dot-style. But for now just return nothing.
return null;
return dimensionSpec.decorate(DimensionSelectorUtils.constantSelector(null, dimensionSpec.getExtractionFn()));
}

@Override
public FloatColumnSelector makeFloatColumnSelector(String columnName, ColumnSelectorFactory factory)
{
return null;
return ZeroFloatColumnSelector.instance();
}

@Override
public LongColumnSelector makeLongColumnSelector(String columnName, ColumnSelectorFactory factory)
{
return null;
return ZeroLongColumnSelector.instance();
}

@Override
public DoubleColumnSelector makeDoubleColumnSelector(String columnName, ColumnSelectorFactory factory)
{
return null;
return ZeroDoubleColumnSelector.instance();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import io.druid.segment.DoubleColumnSelector;
import io.druid.segment.FloatColumnSelector;
import io.druid.segment.LongColumnSelector;
import io.druid.segment.NullDimensionSelector;
import io.druid.segment.Segment;
import io.druid.segment.column.ColumnCapabilities;
import io.druid.segment.column.ValueType;
Expand Down Expand Up @@ -132,7 +131,7 @@ public void updateSearchResultSet(
final Object2IntRBTreeMap<SearchHit> set
)
{
if (selector != null && !(selector instanceof NullDimensionSelector)) {
if (selector != null && !isNilSelector(selector)) {
final IndexedInts vals = selector.getRow();
for (int i = 0; i < vals.size(); ++i) {
final String dimVal = selector.lookupName(vals.get(i));
Expand All @@ -147,6 +146,13 @@ public void updateSearchResultSet(
}
}

private static boolean isNilSelector(final DimensionSelector selector)
{
return selector.nameLookupPossibleInAdvance()
&& selector.getValueCardinality() == 1
&& selector.lookupName(0) == null;
}

public static class LongSearchColumnSelectorStrategy implements SearchColumnSelectorStrategy<LongColumnSelector>
{
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Licensed to Metamarkets Group Inc. (Metamarkets) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Metamarkets licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package io.druid.segment;

import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import io.druid.query.filter.ValueMatcher;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.data.IndexedInts;
import io.druid.segment.data.ZeroIndexedInts;
import io.druid.segment.filter.BooleanValueMatcher;
import io.druid.segment.historical.SingleValueHistoricalDimensionSelector;

import javax.annotation.Nullable;
import java.util.Objects;

public class ConstantDimensionSelector implements SingleValueHistoricalDimensionSelector, IdLookup
{
private final String value;

public ConstantDimensionSelector(final String value)
{
if (Strings.isNullOrEmpty(value)) {
// There's an optimized implementation for nulls that callers should use instead.
throw new IllegalArgumentException("Use NullDimensionSelector or DimensionSelectorUtils.constantSelector");
}

this.value = value;
}

@Override
public IndexedInts getRow()
{
return ZeroIndexedInts.instance();
}

@Override
public int getRowValue()
{
return 0;
}

@Override
public int getRowValue(int offset)
{
return 0;
}

@Override
public IndexedInts getRow(int offset)
{
return getRow();
}

@Override
public ValueMatcher makeValueMatcher(String matchValue)
{
return BooleanValueMatcher.of(Objects.equals(value, matchValue));
}

@Override
public ValueMatcher makeValueMatcher(Predicate<String> predicate)
{
return BooleanValueMatcher.of(predicate.apply(value));
}

@Override
public int getValueCardinality()
{
return 1;
}

@Override
public String lookupName(int id)
{
assert id == 0 : "id = " + id;
return value;
}

@Override
public boolean nameLookupPossibleInAdvance()
{
return true;
}

@Nullable
@Override
public IdLookup idLookup()
{
return this;
}

@Override
public int lookupId(String name)
{
return value.equals(name) ? 0 : -1;
}

@Override
public void inspectRuntimeShape(RuntimeShapeInspector inspector)
{
inspector.visit("value", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Strings;
import io.druid.java.util.common.IAE;
import io.druid.query.extraction.ExtractionFn;
import io.druid.query.filter.ValueMatcher;
import io.druid.query.monomorphicprocessing.RuntimeShapeInspector;
import io.druid.segment.data.IndexedInts;
import io.druid.segment.filter.BooleanValueMatcher;

import javax.annotation.Nullable;
import java.util.BitSet;
import java.util.Objects;

Expand Down Expand Up @@ -246,4 +249,25 @@ public static BitSet makePredicateMatchingSet(DimensionSelector selector, Predic
}
return valueIds;
}

public static DimensionSelector constantSelector(@Nullable final String value)
{
if (Strings.isNullOrEmpty(value)) {
return NullDimensionSelector.instance();
} else {
return new ConstantDimensionSelector(value);
}
}

public static DimensionSelector constantSelector(
@Nullable final String value,
@Nullable final ExtractionFn extractionFn
)
{
if (extractionFn == null) {
return constantSelector(value);
} else {
return constantSelector(extractionFn.apply(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,10 @@ public Sequence<Cursor> build()
public Cursor apply(final Interval inputInterval)
{
final long timeStart = Math.max(interval.getStartMillis(), inputInterval.getStartMillis());
final long timeEnd = Math.min(interval.getEndMillis(), gran.increment(inputInterval.getStart()).getMillis());
final long timeEnd = Math.min(
interval.getEndMillis(),
gran.increment(inputInterval.getStart()).getMillis()
);

if (descending) {
for (; baseOffset.withinBounds(); baseOffset.increment()) {
Expand Down Expand Up @@ -503,7 +506,7 @@ private DimensionSelector makeDimensionSelectorUndecorated(

final Column columnDesc = index.getColumn(dimension);
if (columnDesc == null) {
return NullDimensionSelector.instance();
return DimensionSelectorUtils.constantSelector(null, extractionFn);
}

if (dimension.equals(Column.TIME_COLUMN_NAME)) {
Expand Down Expand Up @@ -534,7 +537,7 @@ private DimensionSelector makeDimensionSelectorUndecorated(

final DictionaryEncodedColumn<String> column = cachedColumn;
if (column == null) {
return NullDimensionSelector.instance();
return DimensionSelectorUtils.constantSelector(null, extractionFn);
} else {
return column.makeDimensionSelector(this, extractionFn);
}
Expand Down Expand Up @@ -883,7 +886,7 @@ public void reset()
return new QueryableIndexBaseCursor<FilteredOffset>()
{
private Offset baseOffset;

{
cursorOffset = new FilteredOffset(this, descending, postFilter, bitmapIndexSelector);
reset();
Expand Down
13 changes: 4 additions & 9 deletions processing/src/main/java/io/druid/segment/VirtualColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.druid.segment.column.ColumnCapabilities;
import io.druid.segment.virtual.ExpressionVirtualColumn;

import javax.annotation.Nullable;
import java.util.List;

/**
Expand Down Expand Up @@ -69,9 +68,8 @@ public interface VirtualColumn extends Cacheable
* @param dimensionSpec the dimensionSpec this column was referenced with
* @param factory column selector factory
*
* @return the selector, or null if we can't make a selector
* @return the selector, must not be null
*/
@Nullable
DimensionSelector makeDimensionSelector(DimensionSpec dimensionSpec, ColumnSelectorFactory factory);

/**
Expand All @@ -81,9 +79,8 @@ public interface VirtualColumn extends Cacheable
* @param columnName the name this virtual column was referenced with
* @param factory column selector factory
*
* @return the selector, or null if we can't make a selector
* @return the selector, must not be null
*/
@Nullable
FloatColumnSelector makeFloatColumnSelector(String columnName, ColumnSelectorFactory factory);

/**
Expand All @@ -93,9 +90,8 @@ public interface VirtualColumn extends Cacheable
* @param columnName the name this virtual column was referenced with
* @param factory column selector factory
*
* @return the selector, or null if we can't make a selector
* @return the selector, must not be null
*/
@Nullable
LongColumnSelector makeLongColumnSelector(String columnName, ColumnSelectorFactory factory);

/**
Expand All @@ -105,9 +101,8 @@ public interface VirtualColumn extends Cacheable
* @param columnName the name this virtual column was referenced with
* @param factory column selector factory
*
* @return the selector, or null if we can't make a selector
* @return the selector, must not be null
*/
@Nullable
DoubleColumnSelector makeDoubleColumnSelector(String columnName, ColumnSelectorFactory factory);

/**
Expand Down
Loading