Skip to content

Commit

Permalink
Simplify calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AmatyaAvadhanula committed Oct 18, 2023
1 parent d98453c commit 57b54e6
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,25 +180,27 @@ public List<Pair<DataSegment, String>> retrieveUsedSegmentsAndCreatedDates(Strin
"SELECT created_date, payload FROM %1$s WHERE dataSource = :dataSource AND used = true"
);

final List<Interval> intervals = new ArrayList<>();
// Do not need an interval condition if the interval is ETERNITY
if (!Intervals.isEternity(interval)) {
SqlSegmentsMetadataQuery.appendConditionForIntervalsAndMatchMode(
queryBuilder,
ImmutableList.of(interval),
SqlSegmentsMetadataQuery.IntervalMode.OVERLAPS,
connector
);
intervals.add(interval);
}

SqlSegmentsMetadataQuery.appendConditionForIntervalsAndMatchMode(
queryBuilder,
intervals,
SqlSegmentsMetadataQuery.IntervalMode.OVERLAPS,
connector
);

final String queryString = StringUtils.format(queryBuilder.toString(), dbTables.getSegmentsTable());
return connector.retryWithHandle(
handle -> {
Query<Map<String, Object>> query = handle
.createQuery(queryString)
.bind("dataSource", dataSource);

if (!Intervals.isEternity(interval)) {
SqlSegmentsMetadataQuery.bindQueryIntervals(query, ImmutableList.of(interval));
}
SqlSegmentsMetadataQuery.bindQueryIntervals(query, intervals);

return query
.map((int index, ResultSet r, StatementContext ctx) ->
Expand Down

0 comments on commit 57b54e6

Please sign in to comment.