Skip to content

Commit

Permalink
Avoid Offset object wrapping in QueryableIndexStorageAdapter when que…
Browse files Browse the repository at this point in the history
…ry granularity / interval is coarser than data (i. e. segment) interval, that is typical for topN queries (BACKEND-319)
  • Loading branch information
leventov committed Sep 28, 2016
1 parent d97127a commit d030c08
Showing 1 changed file with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,28 @@ public Cursor apply(final Long input)
}
}

final Offset offset = descending ?
new DescendingTimestampCheckingOffset(
baseOffset,
timestamps,
timeStart,
minDataTimestamp >= timeStart
) :
new AscendingTimestampCheckingOffset(
baseOffset,
timestamps,
timeEnd,
maxDataTimestamp < timeEnd
);
final Offset offset;
if (descending) {
if (minDataTimestamp >= timeStart) {
offset = baseOffset;
} else {
offset = new DescendingTimestampCheckingOffset(
baseOffset,
timestamps,
timeStart
);
}
} else {
if (maxDataTimestamp < timeEnd) {
offset = baseOffset;
} else {
offset = new AscendingTimestampCheckingOffset(
baseOffset,
timestamps,
timeEnd
);
}
}


final Offset initOffset = offset.clone();
Expand Down Expand Up @@ -1178,20 +1187,16 @@ private abstract static class TimestampCheckingOffset implements Offset
protected final Offset baseOffset;
protected final GenericColumn timestamps;
protected final long timeLimit;
protected final boolean allWithinThreshold;

public TimestampCheckingOffset(
Offset baseOffset,
GenericColumn timestamps,
long timeLimit,
boolean allWithinThreshold
long timeLimit
)
{
this.baseOffset = baseOffset;
this.timestamps = timestamps;
this.timeLimit = timeLimit;
// checks if all the values are within the Threshold specified, skips timestamp lookups and checks if all values are within threshold.
this.allWithinThreshold = allWithinThreshold;
}

@Override
Expand All @@ -1206,9 +1211,6 @@ public boolean withinBounds()
if (!baseOffset.withinBounds()) {
return false;
}
if (allWithinThreshold) {
return true;
}
return timeInRange(timestamps.getLongSingleValueRow(baseOffset.getOffset()));
}

Expand All @@ -1231,11 +1233,10 @@ private static class AscendingTimestampCheckingOffset extends TimestampCheckingO
public AscendingTimestampCheckingOffset(
Offset baseOffset,
GenericColumn timestamps,
long timeLimit,
boolean allWithinThreshold
long timeLimit
)
{
super(baseOffset, timestamps, timeLimit, allWithinThreshold);
super(baseOffset, timestamps, timeLimit);
}

@Override
Expand All @@ -1254,7 +1255,7 @@ public String toString()
@Override
public Offset clone()
{
return new AscendingTimestampCheckingOffset(baseOffset.clone(), timestamps, timeLimit, allWithinThreshold);
return new AscendingTimestampCheckingOffset(baseOffset.clone(), timestamps, timeLimit);
}
}

Expand All @@ -1263,11 +1264,10 @@ private static class DescendingTimestampCheckingOffset extends TimestampChecking
public DescendingTimestampCheckingOffset(
Offset baseOffset,
GenericColumn timestamps,
long timeLimit,
boolean allWithinThreshold
long timeLimit
)
{
super(baseOffset, timestamps, timeLimit, allWithinThreshold);
super(baseOffset, timestamps, timeLimit);
}

@Override
Expand All @@ -1287,7 +1287,7 @@ public String toString()
@Override
public Offset clone()
{
return new DescendingTimestampCheckingOffset(baseOffset.clone(), timestamps, timeLimit, allWithinThreshold);
return new DescendingTimestampCheckingOffset(baseOffset.clone(), timestamps, timeLimit);
}
}

Expand Down

0 comments on commit d030c08

Please sign in to comment.