Class IncrementalIndex
- java.lang.Object
-
- org.apache.druid.segment.incremental.IncrementalIndex
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<Row>,Expr.InputBindingInspector,ColumnInspector
- Direct Known Subclasses:
OnheapIncrementalIndex
public abstract class IncrementalIndex extends Object implements Iterable<Row>, Closeable, ColumnInspector
In-memory, row-based data structure used to hold data during ingestion. Realtime tasks query this index usingIncrementalIndexStorageAdapter. Concurrency model:add(InputRow)andadd(InputRow, boolean)are not thread-safe, and must be called from a single thread or externally synchronized. However, the methods that supportIncrementalIndexStorageAdapterare thread-safe, and may be called concurrently with each other, and with the "add" methods. This concurrency model supports real-time queries of the data in the index.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIncrementalIndex.DimensionDescstatic interfaceIncrementalIndex.FactsHolderstatic classIncrementalIndex.InputRowHolderstatic classIncrementalIndex.MetricDesc
-
Field Summary
Fields Modifier and Type Field Description protected booleanpreserveExistingMetrics
-
Constructor Summary
Constructors Modifier Constructor Description protectedIncrementalIndex(IncrementalIndexSchema incrementalIndexSchema, boolean preserveExistingMetrics, boolean useMaxMemoryEstimates)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description IncrementalIndexAddResultadd(InputRow row)Adds a new row.IncrementalIndexAddResultadd(InputRow row, boolean skipMaxRowsInMemoryCheck)Adds a new row.protected abstract org.apache.druid.segment.incremental.IncrementalIndex.AddToFactsResultaddToFacts(IncrementalIndexRow key, IncrementalIndex.InputRowHolder inputRowHolder, boolean skipMaxRowsInMemoryCheck)abstract booleancanAppendRow()voidclose()protected Comparator<IncrementalIndexRow>dimsComparator()InputRowformatRow(InputRow row)AtomicLonggetBytesInMemory()ColumnCapabilitiesgetColumnCapabilities(String columnName)Returns capabilities of a particular column.ColumnFormatgetColumnFormat(String columnName)Map<String,ColumnFormat>getColumnFormats()List<String>getColumnNames()static ParseExceptiongetCombinedParseException(InputRow row, List<String> dimParseExceptionMessages, List<String> aggParseExceptionMessages)IncrementalIndex.DimensionDescgetDimension(String dimension)IntegergetDimensionIndex(String dimension)List<String>getDimensionNames()List<String>getDimensionOrder()List<IncrementalIndex.DimensionDesc>getDimensions()DimensionsSpecgetDimensionsSpec()Returns dimensionsSpec from the ingestionSpec.abstract IncrementalIndex.FactsHoldergetFacts()org.joda.time.IntervalgetInterval()abstract intgetLastRowIndex()org.joda.time.DateTimegetMaxIngestedEventTime()org.joda.time.DateTimegetMaxTime()MetadatagetMetadata()AggregatorFactory[]getMetricAggs()protected abstract doublegetMetricDoubleValue(int rowOffset, int aggOffset)protected abstract floatgetMetricFloatValue(int rowOffset, int aggOffset)protected abstract longgetMetricLongValue(int rowOffset, int aggOffset)List<String>getMetricNames()protected abstract ObjectgetMetricObjectValue(int rowOffset, int aggOffset)org.joda.time.DateTimegetMinTime()abstract StringgetOutOfRowsReason()protected abstract voidinitAggs(AggregatorFactory[] metrics, IncrementalIndex.InputRowHolder rowSupplier)booleanisEmpty()protected abstract booleanisNull(int rowOffset, int aggOffset)booleanisRollup()abstract Iterable<Row>iterableWithPostAggregations(List<PostAggregator> postAggs, boolean descending)Iterator<Row>iterator()voidloadDimensionIterable(Iterable<String> oldDimensionOrder, Map<String,ColumnFormat> oldColumnCapabilities)Currently called to initialize IncrementalIndex dimension order during index creation Index dimension ordering could be changed to initialize from DimensionsSpec after resolution of https://github.com/apache/druid/issues/2011protected ColumnSelectorFactorymakeColumnSelectorFactory(AggregatorFactory agg, IncrementalIndex.InputRowHolder in)static ColumnSelectorFactorymakeColumnSelectorFactory(VirtualColumns virtualColumns, IncrementalIndex.InputRowHolder inputRowHolder, AggregatorFactory agg)Column selector used at ingestion time for inputs to aggregators.static ColumnCapabilitiesImplmakeDefaultCapabilitiesFromValueType(ColumnType type)ColumnValueSelector<?>makeMetricColumnValueSelector(String metric, IncrementalIndexRowHolder currEntry)intsize()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.druid.segment.ColumnInspector
getType
-
Methods inherited from interface org.apache.druid.math.expr.Expr.InputBindingInspector
areNumeric, areNumeric, areSameTypes, areSameTypes, areScalar, areScalar, canVectorize, canVectorize
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
IncrementalIndex
protected IncrementalIndex(IncrementalIndexSchema incrementalIndexSchema, boolean preserveExistingMetrics, boolean useMaxMemoryEstimates)
- Parameters:
incrementalIndexSchema- the schema to use for incremental indexpreserveExistingMetrics- When set to true, for any row that already has metric (with the same name defined in metricSpec), the metric aggregator in metricSpec is skipped and the existing metric is unchanged. If the row does not already have the metric, then the metric aggregator is applied on the source column as usual. This should only be set for DruidInputSource since that is the only case where we can have existing metrics. This is currently only use by auto compaction and should not be use for anything else.useMaxMemoryEstimates- true if max values should be used to estimate memory
-
-
Method Detail
-
makeColumnSelectorFactory
public static ColumnSelectorFactory makeColumnSelectorFactory(VirtualColumns virtualColumns, IncrementalIndex.InputRowHolder inputRowHolder, @Nullable AggregatorFactory agg)
Column selector used at ingestion time for inputs to aggregators.- Parameters:
virtualColumns- virtual columnsinputRowHolder- ingestion-time input row holderagg- the aggregator, or null to make a generic aggregator. Only required if the agg hasAggregatorFactory.getIntermediateType()asValueType.COMPLEX, because in this case we need to do some magic to ensure the correct values show up.- Returns:
- column selector factory
-
getFacts
public abstract IncrementalIndex.FactsHolder getFacts()
-
canAppendRow
public abstract boolean canAppendRow()
-
getOutOfRowsReason
public abstract String getOutOfRowsReason()
-
initAggs
protected abstract void initAggs(AggregatorFactory[] metrics, IncrementalIndex.InputRowHolder rowSupplier)
-
addToFacts
protected abstract org.apache.druid.segment.incremental.IncrementalIndex.AddToFactsResult addToFacts(IncrementalIndexRow key, IncrementalIndex.InputRowHolder inputRowHolder, boolean skipMaxRowsInMemoryCheck) throws IndexSizeExceededException
- Throws:
IndexSizeExceededException
-
getLastRowIndex
public abstract int getLastRowIndex()
-
getMetricFloatValue
protected abstract float getMetricFloatValue(int rowOffset, int aggOffset)
-
getMetricLongValue
protected abstract long getMetricLongValue(int rowOffset, int aggOffset)
-
getMetricObjectValue
protected abstract Object getMetricObjectValue(int rowOffset, int aggOffset)
-
getMetricDoubleValue
protected abstract double getMetricDoubleValue(int rowOffset, int aggOffset)
-
isNull
protected abstract boolean isNull(int rowOffset, int aggOffset)
-
isRollup
public boolean isRollup()
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
getColumnFormats
public Map<String,ColumnFormat> getColumnFormats()
-
getColumnCapabilities
@Nullable public ColumnCapabilities getColumnCapabilities(String columnName)
Description copied from interface:ColumnInspectorReturns capabilities of a particular column.- Specified by:
getColumnCapabilitiesin interfaceColumnInspector- Parameters:
columnName- column name- Returns:
- capabilities, or null
-
getColumnFormat
@Nullable public ColumnFormat getColumnFormat(String columnName)
-
add
public IncrementalIndexAddResult add(InputRow row) throws IndexSizeExceededException
Adds a new row. The row might correspond with another row that already exists, in which case this will update that row instead of inserting a new one. Not thread-safe.- Parameters:
row- the row of data to add- Returns:
- the number of rows in the data set after adding the InputRow. If any parse failure occurs, a
ParseExceptionis returned inIncrementalIndexAddResult. - Throws:
IndexSizeExceededException- this exception is thrown once it reaches max rows limit and skipMaxRowsInMemoryCheck is set to false.
-
add
public IncrementalIndexAddResult add(InputRow row, boolean skipMaxRowsInMemoryCheck) throws IndexSizeExceededException
Adds a new row. The row might correspond with another row that already exists, in which case this will update that row instead of inserting a new one. Not thread-safe.- Parameters:
row- the row of data to addskipMaxRowsInMemoryCheck- whether or not to skip the check of rows exceeding the max rows or bytes limit- Returns:
- the number of rows in the data set after adding the InputRow. If any parse failure occurs, a
ParseExceptionis returned inIncrementalIndexAddResult. - Throws:
IndexSizeExceededException- this exception is thrown once it reaches max rows limit and skipMaxRowsInMemoryCheck is set to false.
-
getCombinedParseException
@Nullable public static ParseException getCombinedParseException(InputRow row, @Nullable List<String> dimParseExceptionMessages, @Nullable List<String> aggParseExceptionMessages)
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
getBytesInMemory
public AtomicLong getBytesInMemory()
-
getMetricAggs
public AggregatorFactory[] getMetricAggs()
-
getDimensionsSpec
public DimensionsSpec getDimensionsSpec()
Returns dimensionsSpec from the ingestionSpec.
-
getDimensions
public List<IncrementalIndex.DimensionDesc> getDimensions()
-
getDimension
@Nullable public IncrementalIndex.DimensionDesc getDimension(String dimension)
-
makeMetricColumnValueSelector
public ColumnValueSelector<?> makeMetricColumnValueSelector(String metric, IncrementalIndexRowHolder currEntry)
-
getInterval
public org.joda.time.Interval getInterval()
-
getMinTime
@Nullable public org.joda.time.DateTime getMinTime()
-
getMaxTime
@Nullable public org.joda.time.DateTime getMaxTime()
-
makeDefaultCapabilitiesFromValueType
public static ColumnCapabilitiesImpl makeDefaultCapabilitiesFromValueType(ColumnType type)
-
loadDimensionIterable
public void loadDimensionIterable(Iterable<String> oldDimensionOrder, Map<String,ColumnFormat> oldColumnCapabilities)
Currently called to initialize IncrementalIndex dimension order during index creation Index dimension ordering could be changed to initialize from DimensionsSpec after resolution of https://github.com/apache/druid/issues/2011
-
getMetadata
public Metadata getMetadata()
-
iterableWithPostAggregations
public abstract Iterable<Row> iterableWithPostAggregations(@Nullable List<PostAggregator> postAggs, boolean descending)
-
getMaxIngestedEventTime
public org.joda.time.DateTime getMaxIngestedEventTime()
-
makeColumnSelectorFactory
protected ColumnSelectorFactory makeColumnSelectorFactory(@Nullable AggregatorFactory agg, IncrementalIndex.InputRowHolder in)
-
dimsComparator
protected final Comparator<IncrementalIndexRow> dimsComparator()
-
-