From fce490b1b3cb411d47cb91868e18e7dfd20a8f93 Mon Sep 17 00:00:00 2001 From: Michael McLawhorn Date: Thu, 2 Mar 2017 11:11:07 -0600 Subject: [PATCH] PR stuff. --- .../yahoo/bard/webservice/async/ResponseException.java | 1 + .../bard/webservice/data/DruidResponseParser.java | 2 +- .../bard/webservice/data/PreResponseDeserializer.java | 4 +--- .../data/metric/mappers/DateTimeSortMapper.java | 10 +++++----- .../data/metric/mappers/SketchRoundUpMapper.java | 2 +- .../yahoo/bard/webservice/table/BasePhysicalTable.java | 1 - .../table/availability/ImmutableAvailability.java | 3 --- .../table/resolver/DefaultPhysicalTableResolver.java | 2 +- .../table/resolver/PartialTimeComparator.java | 2 +- .../table/resolver/PhysicalTableResolver.java | 2 +- .../table/resolver/SchemaPhysicalTableMatcher.java | 2 +- .../yahoo/bard/webservice/web/ErrorMessageFormat.java | 4 ++++ .../responseprocessors/ResultSetResponseProcessor.java | 9 +++++++++ 13 files changed, 26 insertions(+), 18 deletions(-) diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/async/ResponseException.java b/fili-core/src/main/java/com/yahoo/bard/webservice/async/ResponseException.java index cbdfebced3..94d3160101 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/async/ResponseException.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/async/ResponseException.java @@ -84,6 +84,7 @@ public ResponseException( * @param statusType Status type of the response * @param druidQuery The druid query being processed * @param error Exception object with error details + * * @deprecated In order to ensure correct serialization of the Druid Query, an ObjectWriter with all appropriate * configuration should be passed in to the constructor */ diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/data/DruidResponseParser.java b/fili-core/src/main/java/com/yahoo/bard/webservice/data/DruidResponseParser.java index 41bd0704bb..137ec6f5a2 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/data/DruidResponseParser.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/data/DruidResponseParser.java @@ -39,8 +39,8 @@ public class DruidResponseParser { * @param jsonResult Druid results in json * @param schema Schema for results * @param queryType the type of query, note that this implementation only supports instances of - * @param dateTimeZone the time zone used for format the results * {@link DefaultQueryType} + * @param dateTimeZone the time zone used for format the results * * @return the set of results */ diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/data/PreResponseDeserializer.java b/fili-core/src/main/java/com/yahoo/bard/webservice/data/PreResponseDeserializer.java index c0026b601b..6de85b78c0 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/data/PreResponseDeserializer.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/data/PreResponseDeserializer.java @@ -242,9 +242,7 @@ private ResultSetSchema getResultSetSchema(JsonNode schemaNode) { .collect(Collectors.toSet()) ); - return new ResultSetSchema( - generateGranularity(schemaNode.get(SCHEMA_GRANULARITY).asText(), timezone), columns - ); + return new ResultSetSchema(generateGranularity(schemaNode.get(SCHEMA_GRANULARITY).asText(), timezone), columns); } /** diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/DateTimeSortMapper.java b/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/DateTimeSortMapper.java index f8aaf21daa..762d22a22c 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/DateTimeSortMapper.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/DateTimeSortMapper.java @@ -4,9 +4,9 @@ import com.yahoo.bard.webservice.data.Result; import com.yahoo.bard.webservice.data.ResultSet; +import com.yahoo.bard.webservice.data.ResultSetSchema; import com.yahoo.bard.webservice.druid.model.orderby.SortDirection; import com.yahoo.bard.webservice.logging.RequestLog; -import com.yahoo.bard.webservice.table.Schema; import org.joda.time.DateTime; @@ -59,11 +59,11 @@ public ResultSet map(ResultSet resultSet) { Comparator.reverseOrder()); return new ResultSet( + resultSet.getSchema(), dateTimeList.stream() .map(bucketizedResultsMap::get) .flatMap(List::stream) - .collect(Collectors.toList()), - resultSet.getSchema() + .collect(Collectors.toList()) ); } finally { RequestLog.stopTiming("sortResultSet"); @@ -71,14 +71,14 @@ public ResultSet map(ResultSet resultSet) { } @Override - protected Result map(Result result, Schema schema) { + protected Result map(Result result, ResultSetSchema schema) { //Not needed, because this mapper overrides map(ResultSet). So it is just a no-op. return result; } @Override - protected Schema map(Schema schema) { + protected ResultSetSchema map(ResultSetSchema schema) { //Because this method is not necessary, it just returns the schema unchanged. return schema; } diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/SketchRoundUpMapper.java b/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/SketchRoundUpMapper.java index 92796652ae..4aa60094df 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/SketchRoundUpMapper.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/data/metric/mappers/SketchRoundUpMapper.java @@ -44,7 +44,7 @@ protected Result map(Result result, ResultSetSchema schema) { } MetricColumn metricColumn = schema.getColumn(columnName, MetricColumn.class).orElseThrow( - () -> new IllegalStateException("Unexpected missing column") + () -> new IllegalStateException("Unexpected missing column: " + columnName) ); BigDecimal value = result.getMetricValueAsNumber(metricColumn); diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/BasePhysicalTable.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/BasePhysicalTable.java index 6eccb71296..6e7d47eb90 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/BasePhysicalTable.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/BasePhysicalTable.java @@ -179,7 +179,6 @@ public void resetColumns(SegmentMetadata segmentMetadata, DimensionDictionary di Map> metricIntervals = segmentMetadata.getMetricIntervals(); setAvailability(new ImmutableAvailability( name, - schema, dimensionIntervals, metricIntervals, dimensionDictionary diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/availability/ImmutableAvailability.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/availability/ImmutableAvailability.java index ec3e6b75e8..21bdcd834e 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/availability/ImmutableAvailability.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/availability/ImmutableAvailability.java @@ -7,7 +7,6 @@ import com.yahoo.bard.webservice.data.dimension.DimensionDictionary; import com.yahoo.bard.webservice.data.metric.MetricColumn; import com.yahoo.bard.webservice.table.Column; -import com.yahoo.bard.webservice.table.PhysicalTableSchema; import com.yahoo.bard.webservice.util.SimplifiedIntervalList; import com.google.common.collect.ImmutableMap; @@ -73,14 +72,12 @@ public ImmutableAvailability( * Constructor. * * @param tableName The name of the data source associated with this ImmutableAvailability - * @param schema The schema for the availabilities * @param dimensionIntervals The dimension availability map by dimension name * @param metricIntervals The metric availability map * @param dimensionDictionary The dictionary to resolve dimension names against */ public ImmutableAvailability( String tableName, - PhysicalTableSchema schema, Map> dimensionIntervals, Map> metricIntervals, DimensionDictionary dimensionDictionary diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/DefaultPhysicalTableResolver.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/DefaultPhysicalTableResolver.java index 688267bae3..16a9599f15 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/DefaultPhysicalTableResolver.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/DefaultPhysicalTableResolver.java @@ -2,11 +2,11 @@ // Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. package com.yahoo.bard.webservice.table.resolver; -import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.config.BardFeatureFlag; import com.yahoo.bard.webservice.data.PartialDataHandler; import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; import com.yahoo.bard.webservice.data.volatility.VolatileIntervalsService; +import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.util.ChainingComparator; import com.yahoo.bard.webservice.web.DataApiRequest; diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PartialTimeComparator.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PartialTimeComparator.java index 0697f0760d..7b1e1c9127 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PartialTimeComparator.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PartialTimeComparator.java @@ -2,9 +2,9 @@ // Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. package com.yahoo.bard.webservice.table.resolver; -import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.data.PartialDataHandler; import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; +import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.util.IntervalUtils; import com.yahoo.bard.webservice.util.SimplifiedIntervalList; import com.yahoo.bard.webservice.web.DataApiRequest; diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PhysicalTableResolver.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PhysicalTableResolver.java index 6f0301a134..e2b90bb5a7 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PhysicalTableResolver.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/PhysicalTableResolver.java @@ -2,8 +2,8 @@ // Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. package com.yahoo.bard.webservice.table.resolver; -import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; +import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.web.DataApiRequest; import java.util.Collection; diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/SchemaPhysicalTableMatcher.java b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/SchemaPhysicalTableMatcher.java index b9704d47ef..adc1cc8321 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/SchemaPhysicalTableMatcher.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/table/resolver/SchemaPhysicalTableMatcher.java @@ -4,12 +4,12 @@ import static com.yahoo.bard.webservice.web.ErrorMessageFormat.TABLE_SCHEMA_UNDEFINED; -import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.data.dimension.Dimension; import com.yahoo.bard.webservice.data.metric.LogicalMetric; import com.yahoo.bard.webservice.data.metric.TemplateDruidQuery; import com.yahoo.bard.webservice.druid.model.query.Granularity; import com.yahoo.bard.webservice.table.Column; +import com.yahoo.bard.webservice.table.PhysicalTable; import com.yahoo.bard.webservice.util.TableUtils; import com.yahoo.bard.webservice.web.DataApiRequest; import com.yahoo.bard.webservice.web.ErrorMessageFormat; diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/ErrorMessageFormat.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/ErrorMessageFormat.java index 06c0aa9fa1..fccfb20e8d 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/ErrorMessageFormat.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/ErrorMessageFormat.java @@ -212,6 +212,10 @@ public enum ErrorMessageFormat implements MessageFormatter { "Failed to retrieve data.", "Received %s with status code %s for reason %s when sending %s to Druid" ), + + RESULT_MAPPING_FAILURE( + "Error occurred while processing response data: %s" + ) ; private final String messageFormat; diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/responseprocessors/ResultSetResponseProcessor.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/responseprocessors/ResultSetResponseProcessor.java index c18cafba89..dc64466a01 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/responseprocessors/ResultSetResponseProcessor.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/responseprocessors/ResultSetResponseProcessor.java @@ -2,6 +2,7 @@ // Licensed under the terms of the Apache license. Please see LICENSE.md file distributed with this work for terms. package com.yahoo.bard.webservice.web.responseprocessors; +import static com.yahoo.bard.webservice.web.ErrorMessageFormat.RESULT_MAPPING_FAILURE; import static com.yahoo.bard.webservice.web.responseprocessors.ResponseContextKeys.API_METRIC_COLUMN_NAMES; import static com.yahoo.bard.webservice.web.responseprocessors.ResponseContextKeys.HEADERS; import static com.yahoo.bard.webservice.web.responseprocessors.ResponseContextKeys.REQUESTED_API_DIMENSION_FIELDS; @@ -123,6 +124,14 @@ public void processResponse(JsonNode json, DruidAggregationQuery druidQuery, invalidPage, getObjectMappers().getMapper().writer() )); + } catch (IllegalStateException ise) { + LOG.error(RESULT_MAPPING_FAILURE.logFormat(ise.getMessage())); + responseEmitter.onError(new ResponseException( + Status.INTERNAL_SERVER_ERROR, + druidQuery, + new Exception(RESULT_MAPPING_FAILURE.format(ise.getMessage())), + getObjectMappers().getMapper().writer() + )); } catch (Exception exception) { LOG.error("Exception processing druid call in success", exception); responseEmitter.onError(new ResponseException(