From 5822f49688aaaa3e848f49af1b31e8c83857b017 Mon Sep 17 00:00:00 2001 From: Deepak Babu Date: Thu, 17 May 2018 13:01:44 -0500 Subject: [PATCH] fixing the NoSuchElementException when availability is empty --- CHANGELOG.md | 8 ++++++-- .../web/apirequest/DataApiRequestImpl.java | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 99a5e9f735..db325f9f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ pull request if there was one. ### Fixed: +- [Fix generate intervals logic when availability is empty](https://github.com/yahoo/fili/pull/698) + * Logic to generate intervals when `CURRENT_MACRO_USES_LATEST` flag is turned on has a bug. The code throws `NoSuchElementException` when the table has no availabilities. This PR fixes the bug by checking if the availability of the underlying table is empty. - [Correct Druid coordinator URL in Wikipedia example](https://github.com/yahoo/fili/pull/683) * Config value for Druid coordinator URL is mis-typed. @@ -156,8 +158,10 @@ Thanks to everyone who contributed to this release! ### Added: -- [Logical Table Availability](https://github.com/yahoo/fili/pull/697) - * Added `logicalTableAvailability` to `TableUtils` which returns the union of availabilities for the logical table. +- [Latest Time Macro](https://github.com/yahoo/fili/pull/697) + * Added `logicalTableAvailability` to `TableUtils` which returns the union of intervals for the logical table. + * Added `now` parameter to `generateIntervals` for which time macros will be relatively calculated. + * Added `CURRENT_MACRO_USES_LATEST` flag which when turned on uses the first unavailable availability to generate the intervals. - [Annotate Functional Interface](https://github.com/yahoo/fili/pull/606) * Add `@FunctionalInterface` annotation to all functional interfaces. diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/apirequest/DataApiRequestImpl.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/apirequest/DataApiRequestImpl.java index 79ff4d308b..264231431c 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/apirequest/DataApiRequestImpl.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/apirequest/DataApiRequestImpl.java @@ -39,6 +39,7 @@ import com.yahoo.bard.webservice.table.LogicalTable; import com.yahoo.bard.webservice.table.LogicalTableDictionary; import com.yahoo.bard.webservice.table.TableIdentifier; +import com.yahoo.bard.webservice.util.SimplifiedIntervalList; import com.yahoo.bard.webservice.util.StreamUtils; import com.yahoo.bard.webservice.util.TableUtils; import com.yahoo.bard.webservice.web.ApiFilter; @@ -297,9 +298,14 @@ public DataApiRequestImpl( DateTimeFormatter dateTimeFormatter = generateDateTimeFormatter(timeZone); if (BardFeatureFlag.CURRENT_MACRO_USES_LATEST.isOn()) { - DateTime firstUnavailableInstant = TableUtils.logicalTableAvailability(getTable()).getLast().getEnd(); - DateTime adjustedNow = firstUnavailableInstant.isBeforeNow() ? firstUnavailableInstant : new DateTime(); - + SimplifiedIntervalList availability = TableUtils.logicalTableAvailability(getTable()); + DateTime adjustedNow = new DateTime(); + if (! availability.isEmpty()) { + DateTime firstUnavailable = availability.getLast().getEnd(); + if (firstUnavailable.isBeforeNow() ) { + adjustedNow = firstUnavailable; + } + } this.intervals = generateIntervals(adjustedNow, intervals, this.granularity, dateTimeFormatter); } else { this.intervals = generateIntervals(intervals, this.granularity, dateTimeFormatter);