|
50 | 50 | public class DateHistogramFacetProcessor extends AbstractComponent implements FacetProcessor {
|
51 | 51 |
|
52 | 52 | private final ImmutableMap<String, DateFieldParser> dateFieldParsers;
|
53 |
| - private final TObjectIntHashMap<String> rounding = new TObjectIntHashMap<String>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, MutableDateTime.ROUND_FLOOR); |
| 53 | + private final TObjectIntHashMap<String> rounding = new TObjectIntHashMap<String>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1); |
54 | 54 |
|
55 | 55 | @Inject public DateHistogramFacetProcessor(Settings settings) {
|
56 | 56 | super(settings);
|
@@ -164,15 +164,28 @@ public class DateHistogramFacetProcessor extends AbstractComponent implements Fa
|
164 | 164 | int index = sInterval.indexOf(':');
|
165 | 165 | if (index != -1) {
|
166 | 166 | // set with rounding
|
167 |
| - DateTimeField field = dateFieldParsers.get(sInterval.substring(0, index)).parse(dateTime.getChronology()); |
168 |
| - dateTime.setRounding(field, rounding.get(sInterval.substring(index + 1))); |
| 167 | + DateFieldParser fieldParser = dateFieldParsers.get(sInterval.substring(0, index)); |
| 168 | + if (fieldParser == null) { |
| 169 | + throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "] with custom rounding using built in intervals (year/month/...)"); |
| 170 | + } |
| 171 | + DateTimeField field = fieldParser.parse(dateTime.getChronology()); |
| 172 | + int rounding = this.rounding.get(sInterval.substring(index + 1)); |
| 173 | + if (rounding == -1) { |
| 174 | + throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "], rounding type [" + (sInterval.substring(index + 1)) + "] not found"); |
| 175 | + } |
| 176 | + dateTime.setRounding(field, rounding); |
169 | 177 | } else {
|
170 |
| - DateTimeField field = dateFieldParsers.get(sInterval).parse(dateTime.getChronology()); |
171 |
| - if (field != null) { |
| 178 | + DateFieldParser fieldParser = dateFieldParsers.get(sInterval); |
| 179 | + if (fieldParser != null) { |
| 180 | + DateTimeField field = fieldParser.parse(dateTime.getChronology()); |
172 | 181 | dateTime.setRounding(field, MutableDateTime.ROUND_FLOOR);
|
173 | 182 | } else {
|
174 | 183 | // time interval
|
175 |
| - interval = TimeValue.parseTimeValue(parser.text(), null).millis(); |
| 184 | + try { |
| 185 | + interval = TimeValue.parseTimeValue(parser.text(), null).millis(); |
| 186 | + } catch (Exception e) { |
| 187 | + throw new FacetPhaseExecutionException(facetName, "failed to parse interval [" + sInterval + "], tried both as built in intervals (year/month/...) and as a time format"); |
| 188 | + } |
176 | 189 | }
|
177 | 190 | }
|
178 | 191 | }
|
|
0 commit comments