Package org.apache.druid.metadata
Class SqlSegmentsMetadataQuery
- java.lang.Object
-
- org.apache.druid.metadata.SqlSegmentsMetadataQuery
-
public class SqlSegmentsMetadataQuery extends Object
An object that helpsSqlSegmentsMetadataManagerandIndexerSQLMetadataStorageCoordinatormake queries to the metadata store segments table. Each instance of this class is scoped to a single handle and is meant to be short-lived.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidappendConditionForIntervalsAndMatchMode(StringBuilder sb, Collection<org.joda.time.Interval> intervals, org.apache.druid.metadata.SqlSegmentsMetadataQuery.IntervalMode matchMode, SQLMetadataConnector connector)Append the condition for the interval and match mode to the given string builder with a partial querystatic voidbindQueryIntervals(org.skife.jdbi.v2.Query<Map<String,Object>> query, Collection<org.joda.time.Interval> intervals)Given a Query object bind the input intervals to itstatic SqlSegmentsMetadataQueryforHandle(org.skife.jdbi.v2.Handle handle, SQLMetadataConnector connector, org.apache.druid.metadata.MetadataStorageTablesConfig dbTables, com.fasterxml.jackson.databind.ObjectMapper jsonMapper)Create a query object.intmarkSegments(Collection<org.apache.druid.timeline.SegmentId> segmentIds, boolean used)Marks the provided segments as either used or unused.intmarkSegmentsUnused(String dataSource, org.joda.time.Interval interval)Marks all segments for a datasource unused that are *fully contained by* a particular interval.org.apache.druid.timeline.DataSegmentretrieveSegmentForId(String id)Retrieve the segment for a given id if it exists in the metadata store and null otherwiseorg.apache.druid.java.util.common.parsers.CloseableIterator<org.apache.druid.timeline.DataSegment>retrieveUnusedSegments(String dataSource, Collection<org.joda.time.Interval> intervals, Integer limit)Retrieves segments for a given datasource that are marked unused and that are *fully contained by* any interval in a particular collection of intervals.org.apache.druid.timeline.DataSegmentretrieveUsedSegmentForId(String id)Retrieve the used segment for a given id if it exists in the metadata store and null otherwiseorg.apache.druid.java.util.common.parsers.CloseableIterator<org.apache.druid.timeline.DataSegment>retrieveUsedSegments(String dataSource, Collection<org.joda.time.Interval> intervals)Retrieves segments for a given datasource that are marked used (i.e.
-
-
-
Method Detail
-
forHandle
public static SqlSegmentsMetadataQuery forHandle(org.skife.jdbi.v2.Handle handle, SQLMetadataConnector connector, org.apache.druid.metadata.MetadataStorageTablesConfig dbTables, com.fasterxml.jackson.databind.ObjectMapper jsonMapper)
Create a query object. This instance is scoped to a single handle and is meant to be short-lived. It is okay to use it for more than one query, though.
-
retrieveUsedSegments
public org.apache.druid.java.util.common.parsers.CloseableIterator<org.apache.druid.timeline.DataSegment> retrieveUsedSegments(String dataSource, Collection<org.joda.time.Interval> intervals)
Retrieves segments for a given datasource that are marked used (i.e. published) in the metadata store, and that *overlap* any interval in a particular collection of intervals. If the collection of intervals is empty, this method will retrieve all used segments. You cannot assume that segments returned by this call are actually active. Because there is some delay between new segment publishing and the marking-unused of older segments, it is possible that some segments returned by this call are overshadowed by other segments. To check for this, useSegmentTimeline.forSegments(Iterable). This call does not return any information about realtime segments. Returns a closeable iterator. You should close it when you are done.
-
retrieveUnusedSegments
public org.apache.druid.java.util.common.parsers.CloseableIterator<org.apache.druid.timeline.DataSegment> retrieveUnusedSegments(String dataSource, Collection<org.joda.time.Interval> intervals, @Nullable Integer limit)
Retrieves segments for a given datasource that are marked unused and that are *fully contained by* any interval in a particular collection of intervals. If the collection of intervals is empty, this method will retrieve all unused segments. This call does not return any information about realtime segments. Returns a closeable iterator. You should close it when you are done.
-
markSegments
public int markSegments(Collection<org.apache.druid.timeline.SegmentId> segmentIds, boolean used)
Marks the provided segments as either used or unused. Returns the number of segments actually modified.
-
markSegmentsUnused
public int markSegmentsUnused(String dataSource, org.joda.time.Interval interval)
Marks all segments for a datasource unused that are *fully contained by* a particular interval. Returns the number of segments actually modified.
-
retrieveUsedSegmentForId
public org.apache.druid.timeline.DataSegment retrieveUsedSegmentForId(String id)
Retrieve the used segment for a given id if it exists in the metadata store and null otherwise
-
retrieveSegmentForId
public org.apache.druid.timeline.DataSegment retrieveSegmentForId(String id)
Retrieve the segment for a given id if it exists in the metadata store and null otherwise
-
appendConditionForIntervalsAndMatchMode
public static void appendConditionForIntervalsAndMatchMode(StringBuilder sb, Collection<org.joda.time.Interval> intervals, org.apache.druid.metadata.SqlSegmentsMetadataQuery.IntervalMode matchMode, SQLMetadataConnector connector)
Append the condition for the interval and match mode to the given string builder with a partial query- Parameters:
sb- - StringBuilder containing the paritial query with SELECT clause and WHERE condition for used, datasourceintervals- - intervals to fetch the segments formatchMode- - Interval match mode - overlaps or containsconnector- - SQL connector
-
bindQueryIntervals
public static void bindQueryIntervals(org.skife.jdbi.v2.Query<Map<String,Object>> query, Collection<org.joda.time.Interval> intervals)
Given a Query object bind the input intervals to it- Parameters:
query- Query to fetch segmentsintervals- Intervals to fetch segments for
-
-