Skip to content
Closed
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
11 changes: 11 additions & 0 deletions api/src/main/java/io/druid/query/SegmentDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.druid.timeline.DataSegment;
import org.joda.time.Interval;

/**
Expand Down Expand Up @@ -86,6 +87,16 @@ public boolean equals(Object o)
return true;
}

public String getSegmentIdWithoutDataSource()
{
return DataSegment.makeDataSegmentIdentifierWithoutDataSource(
interval.getStart(),
interval.getEnd(),
version,
partitionNumber
);
}

@Override
public int hashCode()
{
Expand Down
39 changes: 32 additions & 7 deletions api/src/main/java/io/druid/timeline/DataSegment.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
*/
public class DataSegment implements Comparable<DataSegment>
{
public static String delimiter = "_";
public final static String DELIMITER = "_";
private final Integer binaryVersion;
private static final Interner<String> interner = Interners.newWeakInterner();
private static final Function<String, String> internFun = new Function<String, String>()
Expand All @@ -70,18 +70,43 @@ public static String makeDataSegmentIdentifier(
{
StringBuilder sb = new StringBuilder();

sb.append(dataSource).append(delimiter)
.append(start).append(delimiter)
.append(end).append(delimiter)
sb.append(dataSource).append(DELIMITER);
updateBuilderWithSegmentIdWithoutDataSource(sb, start, end, version, shardSpec.getPartitionNum());

return sb.toString();
}

private static void updateBuilderWithSegmentIdWithoutDataSource(
StringBuilder sb,
DateTime start,
DateTime end,
String version,
int partitionNum
)
{
sb.append(start).append(DELIMITER)
.append(end).append(DELIMITER)
.append(version);

if (shardSpec.getPartitionNum() != 0) {
sb.append(delimiter).append(shardSpec.getPartitionNum());
if (partitionNum != 0) {
sb.append(DELIMITER).append(partitionNum);
}
}

public static String makeDataSegmentIdentifierWithoutDataSource(
DateTime start,
DateTime end,
String version,
int partitionNum
)
{
StringBuilder sb = new StringBuilder();

updateBuilderWithSegmentIdWithoutDataSource(sb, start, end, version, partitionNum);

return sb.toString();
}

private final String dataSource;
private final Interval interval;
private final String version;
Expand Down
6 changes: 3 additions & 3 deletions api/src/main/java/io/druid/timeline/DataSegmentUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private static SegmentIdentifierParts parse(String dataSource, String identifier
return null;
}
String remaining = identifier.substring(dataSource.length() + 1);
String[] splits = remaining.split(DataSegment.delimiter);
String[] splits = remaining.split(DataSegment.DELIMITER);
if (splits.length < 3) {
LOGGER.info("Invalid identifier %s", identifier);
return null;
Expand All @@ -74,7 +74,7 @@ private static SegmentIdentifierParts parse(String dataSource, String identifier
DateTime start = formatter.parseDateTime(splits[0]);
DateTime end = formatter.parseDateTime(splits[1]);
String version = splits[2];
String trail = splits.length > 3 ? join(splits, DataSegment.delimiter, 3, splits.length) : null;
String trail = splits.length > 3 ? join(splits, DataSegment.DELIMITER, 3, splits.length) : null;

return new SegmentIdentifierParts(
dataSource,
Expand Down Expand Up @@ -169,7 +169,7 @@ public String toString()
{
return join(
new Object[]{dataSource, interval.getStart(), interval.getEnd(), version, trail},
DataSegment.delimiter, 0, version == null ? 3 : trail == null ? 4 : 5
DataSegment.DELIMITER, 0, version == null ? 3 : trail == null ? 4 : 5
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions processing/src/main/java/io/druid/query/BaseQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static <T> int getContextUncoveredIntervalsLimit(Query<T> query, int defa
return parseInt(query, "uncoveredIntervalsLimit", defaultValue);
}

public static <T> boolean getContextDumpSegmentList(Query<T> query, boolean defaultValue)
{
return parseBoolean(query, "dumpSegmentList", defaultValue);
}

private static <T> int parseInt(Query<T> query, String key, int defaultValue)
{
Object val = query.getContextValue(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ public ShardSpec apply(PartitionChunk<ServerSelector> input)
}
}

// Optionally dump all used segmentIds in processing this query
if (BaseQuery.getContextDumpSegmentList(query, false)) {
List<String> segmentIds = new ArrayList<>(segments.size());
for (Pair<ServerSelector, SegmentDescriptor> segment : segments) {
segmentIds.add(segment.rhs.getSegmentIdWithoutDataSource());
}
responseContext.put("segments", segmentIds);
}

final byte[] queryCacheKey;

if ((populateCache || useCache) // implies strategy != null
Expand Down