Class IncrementalIndex
java.lang.Object
org.apache.druid.segment.incremental.IncrementalIndex
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterable<Row>,Expr.InputBindingInspector,ColumnInspector,IncrementalIndexRowSelector
- Direct Known Subclasses:
OnheapIncrementalIndex
public abstract class IncrementalIndex
extends Object
implements IncrementalIndexRowSelector, ColumnInspector, Iterable<Row>, Closeable
In-memory, row-based data structure used to hold data during ingestion. Realtime tasks query this index using
IncrementalIndexCursorFactory.
Concurrency model: add(InputRow) is not thread-safe, and must be called from a single thread or externally
synchronized. However, the methods that support IncrementalIndexCursorFactory are 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 ClassesModifier and TypeClassDescriptionstatic classstatic final classstatic classstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final IncrementalIndex.InputRowHolderprotected final booleanprotected final intPosition ofColumnHolder.TIME_COLUMN_NAMEin the sort order, relative to elements ofdimensionDescs. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedIncrementalIndex(IncrementalIndexSchema incrementalIndexSchema, boolean preserveExistingMetrics) -
Method Summary
Modifier and TypeMethodDescriptionAdds a new row.protected abstract IncrementalIndex.AddToFactsResultaddToFacts(IncrementalIndexRow key, IncrementalIndex.InputRowHolder inputRowHolder) abstract booleanvoidclose()protected final Comparator<IncrementalIndexRow> getColumnCapabilities(String columnName) Returns capabilities of a particular column.getColumnFormat(String columnName) GetColumnFormatfor a dimension, metrics, or time column, or null if the column does not existReturns all column names, includingColumnHolder.TIME_COLUMN_NAME.static ParseExceptiongetCombinedParseException(InputRow row, List<String> dimParseExceptionMessages, List<String> aggParseExceptionMessages) getDimension(String dimension) Returns the descriptor for a particular dimension.getDimensionNames(boolean includeTime) Returns names of dimension columns.Returns names of time and dimension columns, in persist sort order.Returns a descriptor for each dimension.Returns dimensionsSpec from the ingestionSpec.org.joda.time.Intervalorg.joda.time.DateTimeorg.joda.time.DateTimeGetIncrementalIndex.MetricDescwhich provides column capabilities and position in the aggregators section of the rowReturns list of all metric column names for the row selectororg.joda.time.DateTimeOrdering for the data in the facts tableabstract Stringabstract IncrementalIndexRowSelectorgetProjection(String name) getProjection(CursorBuildSpec buildSpec) intPosition of the time column inIncrementalIndexRowSelector.getOrdering()protected abstract voidinitAggs(AggregatorFactory[] metrics, IncrementalIndex.InputRowHolder rowSupplier) booleanisEmpty()Are there anyIncrementalIndexRowstored in theFactsHolder?booleanisRollup()iterableWithPostAggregations(List<PostAggregator> postAggs, boolean descending) iterator()voidloadDimensionIterable(Iterable<String> oldDimensionOrder, Map<String, ColumnFormat> oldColumnFormats) 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 ColumnSelectorFactorystatic ColumnSelectorFactorymakeColumnSelectorFactory(VirtualColumns virtualColumns, IncrementalIndex.InputRowHolder inputRowHolder, AggregatorFactory agg) Column selector used at ingestion time for inputs to aggregators.static ColumnCapabilitiesImplstatic ColumnValueSelector<?> makeMetricColumnValueSelector(IncrementalIndexRowSelector rowSelector, IncrementalIndexRowHolder currEntry, String metric) intnumRows()Number of rows inFactsHolderMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.druid.segment.ColumnInspector
getTypeMethods inherited from interface org.apache.druid.math.expr.Expr.InputBindingInspector
areNumeric, areNumeric, areSameTypes, areSameTypes, areScalar, areScalar, canVectorize, canVectorizeMethods inherited from interface org.apache.druid.segment.incremental.IncrementalIndexRowSelector
getFacts, getLastRowIndex, getMetricDoubleValue, getMetricFloatValue, getMetricLongValue, getMetricObjectValue, isNullMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
preserveExistingMetrics
protected final boolean preserveExistingMetrics -
timePosition
protected final int timePositionPosition ofColumnHolder.TIME_COLUMN_NAMEin the sort order, relative to elements ofdimensionDescs. For example, for the sort order [x, __time, y], dimensionDescs contains [x, y] and timePosition is 1. -
inputRowHolder
-
-
Constructor Details
-
IncrementalIndex
protected IncrementalIndex(IncrementalIndexSchema incrementalIndexSchema, boolean preserveExistingMetrics) - 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.
-
-
Method Details
-
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
-
getProjection
@Nullable public abstract QueryableProjection<IncrementalIndexRowSelector> getProjection(CursorBuildSpec buildSpec) -
getProjection
-
canAppendRow
public abstract boolean canAppendRow() -
getOutOfRowsReason
-
initAggs
protected abstract void initAggs(AggregatorFactory[] metrics, IncrementalIndex.InputRowHolder rowSupplier) -
addToFacts
protected abstract IncrementalIndex.AddToFactsResult addToFacts(IncrementalIndexRow key, IncrementalIndex.InputRowHolder inputRowHolder) -
iterableWithPostAggregations
public abstract Iterable<Row> iterableWithPostAggregations(@Nullable List<PostAggregator> postAggs, boolean descending) -
isRollup
public boolean isRollup() -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
formatRow
-
getColumnFormats
-
getColumnCapabilities
Description copied from interface:ColumnInspectorReturns capabilities of a particular column.- Specified by:
getColumnCapabilitiesin interfaceColumnInspector- Parameters:
columnName- column name- Returns:
- capabilities, or null
-
getColumnFormat
Description copied from interface:IncrementalIndexRowSelectorGetColumnFormatfor a dimension, metrics, or time column, or null if the column does not exist- Specified by:
getColumnFormatin interfaceIncrementalIndexRowSelector
-
add
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.
-
getCombinedParseException
-
isEmpty
public boolean isEmpty()Description copied from interface:IncrementalIndexRowSelectorAre there anyIncrementalIndexRowstored in theFactsHolder?- Specified by:
isEmptyin interfaceIncrementalIndexRowSelector
-
numRows
public int numRows()Description copied from interface:IncrementalIndexRowSelectorNumber of rows inFactsHolder- Specified by:
numRowsin interfaceIncrementalIndexRowSelector
-
getBytesInMemory
-
getMetricAggs
-
getDimensionsSpec
Returns dimensionsSpec from the ingestionSpec. -
getDimensionNames
Returns names of dimension columns.- Specified by:
getDimensionNamesin interfaceIncrementalIndexRowSelector- Parameters:
includeTime- whether to includeColumnHolder.TIME_COLUMN_NAME.
-
getDimensions
Returns a descriptor for each dimension. Does not inclueColumnHolder.TIME_COLUMN_NAME.- Specified by:
getDimensionsin interfaceIncrementalIndexRowSelector
-
getDimension
Returns the descriptor for a particular dimension.- Specified by:
getDimensionin interfaceIncrementalIndexRowSelector
-
getMetric
Description copied from interface:IncrementalIndexRowSelectorGetIncrementalIndex.MetricDescwhich provides column capabilities and position in the aggregators section of the row- Specified by:
getMetricin interfaceIncrementalIndexRowSelector
-
getOrdering
Description copied from interface:IncrementalIndexRowSelectorOrdering for the data in the facts table- Specified by:
getOrderingin interfaceIncrementalIndexRowSelector
-
getTimePosition
public int getTimePosition()Description copied from interface:IncrementalIndexRowSelectorPosition of the time column inIncrementalIndexRowSelector.getOrdering()- Specified by:
getTimePositionin interfaceIncrementalIndexRowSelector
-
makeMetricColumnValueSelector
public static ColumnValueSelector<?> makeMetricColumnValueSelector(IncrementalIndexRowSelector rowSelector, IncrementalIndexRowHolder currEntry, String metric) -
getInterval
public org.joda.time.Interval getInterval() -
getMinTime
@Nullable public org.joda.time.DateTime getMinTime() -
getMaxTime
@Nullable public org.joda.time.DateTime getMaxTime() -
getDimensionOrder
Returns names of time and dimension columns, in persist sort order. IncludesColumnHolder.TIME_COLUMN_NAME. -
makeDefaultCapabilitiesFromValueType
-
loadDimensionIterable
public void loadDimensionIterable(Iterable<String> oldDimensionOrder, Map<String, ColumnFormat> oldColumnFormats) 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- Parameters:
oldDimensionOrder- dimension order to initializeoldColumnFormats- formats for the dimensions
-
getMetricNames
Description copied from interface:IncrementalIndexRowSelectorReturns list of all metric column names for the row selector- Specified by:
getMetricNamesin interfaceIncrementalIndexRowSelector
-
getColumnNames
Returns all column names, includingColumnHolder.TIME_COLUMN_NAME. -
getMetadata
-
iterator
-
getMaxIngestedEventTime
public org.joda.time.DateTime getMaxIngestedEventTime() -
makeColumnSelectorFactory
protected ColumnSelectorFactory makeColumnSelectorFactory(@Nullable AggregatorFactory agg, IncrementalIndex.InputRowHolder in) -
dimsComparator
-