diff --git a/CHANGELOG.md b/CHANGELOG.md index ac101e62bb..e1f44086ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,8 @@ Current ### Removed: +- [Remove dependency on org.json](https://github.com/yahoo/fili/pull/416) + * Replace uses of org.json with the jackson equivalent v0.8.69 - 2017/06/06 diff --git a/fili-core/pom.xml b/fili-core/pom.xml index 2eadae0441..d06e5cb38f 100644 --- a/fili-core/pom.xml +++ b/fili-core/pom.xml @@ -133,11 +133,6 @@ com.fasterxml.jackson.dataformat jackson-dataformat-csv - - - org.json - json - diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/DataApiRequest.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/DataApiRequest.java index b96a078cf9..0a7116ee93 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/DataApiRequest.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/DataApiRequest.java @@ -57,15 +57,15 @@ import com.yahoo.bard.webservice.web.util.BardConfigResources; import com.yahoo.bard.webservice.web.util.PaginationParameters; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; + import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import org.joda.time.Duration; import org.joda.time.Interval; import org.joda.time.Period; import org.joda.time.format.DateTimeFormatter; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -802,7 +802,7 @@ protected LinkedHashSet generateLogicalMetrics( //If INTERSECTION_REPORTING_ENABLED flag is true, convert the aggregators into FilteredAggregators and //replace old PostAggs with new postAggs in order to generate a new Filtered Logical Metric if (BardFeatureFlag.INTERSECTION_REPORTING.isOn()) { - JSONArray metricsJsonArray; + ArrayNode metricsJsonArray; try { //For a given metricString, returns an array of json objects contains metric name and associated // filters @@ -811,22 +811,18 @@ protected LinkedHashSet generateLogicalMetrics( } catch (IllegalArgumentException e) { LOG.debug(INCORRECT_METRIC_FILTER_FORMAT.logFormat(e.getMessage())); throw new BadApiRequestException(INCORRECT_METRIC_FILTER_FORMAT.format(apiMetricQuery)); - } catch (JSONException e) { - // This needs to stay here due to a bytecode issue where Java 8 flags JSONException as invalid - LOG.debug(INCORRECT_METRIC_FILTER_FORMAT.logFormat(e.getMessage())); - throw new BadApiRequestException(INCORRECT_METRIC_FILTER_FORMAT.format(apiMetricQuery)); } //check for the duplicate occurrence of metrics in an API FieldConverterSupplier.metricsFilterSetBuilder.validateDuplicateMetrics(metricsJsonArray); - for (int i = 0; i < metricsJsonArray.length(); i++) { - JSONObject jsonObject; + for (int i = 0; i < metricsJsonArray.size(); i++) { + JsonNode jsonObject; try { - jsonObject = metricsJsonArray.getJSONObject(i); - } catch (JSONException e) { + jsonObject = metricsJsonArray.get(i); + } catch (IndexOutOfBoundsException e) { LOG.debug(INCORRECT_METRIC_FILTER_FORMAT.logFormat(e.getMessage())); throw new BadApiRequestException(INCORRECT_METRIC_FILTER_FORMAT.format(apiMetricQuery)); } - String metricName = jsonObject.getString("name"); + String metricName = jsonObject.get("name").asText(); LogicalMetric logicalMetric = metricDictionary.get(metricName); // If metric dictionary returns a null, it means the requested metric is not found. @@ -834,10 +830,10 @@ protected LinkedHashSet generateLogicalMetrics( invalidMetricNames.add(metricName); } else { //metricFilterObject contains all the filters for a given metric - JSONObject metricFilterObject = jsonObject.getJSONObject("filter"); + JsonNode metricFilterObject = jsonObject.get("filter"); //Currently supporting AND operation for metric filters. - if (!metricFilterObject.isNull("AND")) { + if (metricFilterObject.has("AND") && !metricFilterObject.get("AND").isNull()) { //We currently do not support ratio metrics if (logicalMetric.getCategory().equals(RATIO_METRIC_CATEGORY)) { @@ -868,10 +864,10 @@ protected LinkedHashSet generateLogicalMetrics( } //If metric filter isn't empty or it has anything other then 'AND' then throw an exception - } else if (!(metricFilterObject.toString().equals("{}"))) { - LOG.debug(INVALID_METRIC_FILTER_CONDITION.logFormat(metricFilterObject.keySet())); + } else if (!metricFilterObject.asText().isEmpty()) { + LOG.debug(INVALID_METRIC_FILTER_CONDITION.logFormat(metricFilterObject.asText())); throw new BadApiRequestException( - INVALID_METRIC_FILTER_CONDITION.format(metricFilterObject.keySet()) + INVALID_METRIC_FILTER_CONDITION.format(metricFilterObject.asText()) ); } generated.add(logicalMetric); diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredSketchMetricsHelper.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredSketchMetricsHelper.java index 9fe0b6405f..0b1cac163a 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredSketchMetricsHelper.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredSketchMetricsHelper.java @@ -25,8 +25,9 @@ import com.yahoo.bard.webservice.druid.model.postaggregation.WithFields; import com.yahoo.bard.webservice.table.LogicalTable; -import org.json.JSONArray; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,12 +51,12 @@ public class FilteredSketchMetricsHelper implements MetricsFilterSetBuilder { private static final String ALPHANUMERIC_REGEX = "[^a-zA-Z0-9]"; @Override - public void validateDuplicateMetrics(JSONArray metricsJsonArray) { + public void validateDuplicateMetrics(ArrayNode metricsJsonArray) { Set metricsList = new HashSet<>(); List duplicateMetrics = new ArrayList<>(); - for (int i = 0; i < metricsJsonArray.length(); i++) { - String metricName = metricsJsonArray.getJSONObject(i).getString("name"); + for (int i = 0; i < metricsJsonArray.size(); i++) { + String metricName = metricsJsonArray.get(i).get("name").asText(); boolean status = metricsList.add(metricName); if (!status) { duplicateMetrics.add(metricName); @@ -70,7 +71,7 @@ public void validateDuplicateMetrics(JSONArray metricsJsonArray) { @Override public LogicalMetric getFilteredLogicalMetric( LogicalMetric logicalMetric, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -88,7 +89,7 @@ public LogicalMetric getFilteredLogicalMetric( apiRequest ); - String filterSuffix = "-" + metricFilterObject.get("AND").toString().replaceAll(ALPHANUMERIC_REGEX, ""); + String filterSuffix = "-" + metricFilterObject.get("AND").asText().replaceAll(ALPHANUMERIC_REGEX, ""); //innerPostAggToOuterAggMap stores the mapping of old postAgg to new postAgg name. In filtering of metrics, //the name of postAggs(all postAggs other than CONSTANT type) in the nested query is appended with a filter @@ -239,7 +240,7 @@ public Collection updateNestedQueryPostAggs( @Override public TemplateDruidQuery updateTemplateDruidQuery( TemplateDruidQuery query, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -414,14 +415,14 @@ public PostAggregation replacePostAggWithPostAggFromMap( @Override public Set getFilteredAggregation( - JSONObject filter, + JsonNode filter, Aggregation aggregation, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest ) throws DimensionRowNotFoundException { //Converting json filter string to a plain filter string to prepare the Filter out of it - String filterString = filter.get("AND").toString().replace("],", "]],"); + String filterString = filter.get("AND").asText().replace("],", "]],"); String[] filterList = filterString.split("],"); Set filteredAggregationSet = new HashSet<>(); Map filterHashMap = new HashMap<>(); diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredThetaSketchMetricsHelper.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredThetaSketchMetricsHelper.java index 09c0d23591..0cbec81d5f 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredThetaSketchMetricsHelper.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/FilteredThetaSketchMetricsHelper.java @@ -25,8 +25,9 @@ import com.yahoo.bard.webservice.druid.model.postaggregation.WithFields; import com.yahoo.bard.webservice.table.LogicalTable; -import org.json.JSONArray; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,12 +48,12 @@ public class FilteredThetaSketchMetricsHelper implements MetricsFilterSetBuilder @Override - public void validateDuplicateMetrics(JSONArray metricsJsonArray) { + public void validateDuplicateMetrics(ArrayNode metricsJsonArray) { Set metricsList = new HashSet<>(); List duplicateMetrics = new ArrayList<>(); - for (int i = 0; i < metricsJsonArray.length(); i++) { - String metricName = metricsJsonArray.getJSONObject(i).getString("name"); + for (int i = 0; i < metricsJsonArray.size(); i++) { + String metricName = metricsJsonArray.get(i).get("name").asText(); boolean status = metricsList.add(metricName); if (!status) { duplicateMetrics.add(metricName); @@ -67,7 +68,7 @@ public void validateDuplicateMetrics(JSONArray metricsJsonArray) { @Override public LogicalMetric getFilteredLogicalMetric( LogicalMetric logicalMetric, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -85,7 +86,7 @@ public LogicalMetric getFilteredLogicalMetric( apiRequest ); - String filterSuffix = "-" + metricFilterObject.get("AND").toString().replaceAll(ALPHANUMERIC_REGEX, ""); + String filterSuffix = "-" + metricFilterObject.get("AND").asText().replaceAll(ALPHANUMERIC_REGEX, ""); //innerPostAggToOuterAggMap stores the mapping of old postAgg to new postAgg name. In filtering of metrics, //the name of postAggs(all postAggs other than CONSTANT type) in the nested query is appended with a filter @@ -207,7 +208,7 @@ public Collection updateNestedQueryPostAggs( @Override public TemplateDruidQuery updateTemplateDruidQuery( TemplateDruidQuery query, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -382,14 +383,14 @@ public PostAggregation replacePostAggWithPostAggFromMap( @Override public Set getFilteredAggregation( - JSONObject filter, + JsonNode filter, Aggregation aggregation, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest ) throws DimensionRowNotFoundException { //Converting json filter string to a plain filter string to prepare the Filter out of it - String filterString = filter.get("AND").toString().replace("],", "]],"); + String filterString = filter.get("AND").asText().replace("],", "]],"); String[] filterList = filterString.split("],"); Set filteredAggregationSet = new HashSet<>(); Map filterHashMap = new HashMap<>(); diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricParser.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricParser.java index 8af5d5139d..06039c9287 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricParser.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricParser.java @@ -2,14 +2,14 @@ // 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; -import org.json.JSONArray; -import org.json.JSONException; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Stack; @@ -21,7 +21,7 @@ public class MetricParser { private static final Logger LOG = LoggerFactory.getLogger(MetricParser.class); /** - * This function converts the string of metrics extracted from the url into JSONArray. + * This function converts the string of metrics extracted from the url into ArrayNode. * * @param metricString An Api metric string eg: *
{@code metricString = metric1(AND(dim1|id-in[a,b],dim2|id-in[c,d])),metric2 }
@@ -30,10 +30,9 @@ public class MetricParser { *
{@code {[{"filter":{"AND":{"dim2|id-in":["abc","xyz"],"dim3|id-in":["mobile","tablet"]}}, "name":"metric1"},
      * {"filter":{},"name":"metric2"}]}}
- * @throws JSONException if a JSON cannot be constructed successfully from the given metricString * @throws IllegalArgumentException if metricString is empty or the metricString has unbalanced brackets */ - public static JSONArray generateMetricFilterJsonArray(String metricString) throws JSONException { + public static ArrayNode generateMetricFilterJsonArray(String metricString) { if (metricString.length() == 0 || !(isBracketsBalanced(metricString))) { LOG.error("Metrics parameter values are invalid. The string is: " + metricString); throw new IllegalArgumentException("Metrics parameter values are invalid. The string is: " + metricString); @@ -45,7 +44,7 @@ public static JSONArray generateMetricFilterJsonArray(String metricString) throw String[] metrics = encodeMetricFilters(metricString, mapper).split(","); //looping each metric in a metrics array - List metricList = new ArrayList<>(); + ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode(); for (String metric : metrics) { //Separating metric and '-' separated filter encode metricFilterArray[0] will be metric name //and metricFilterArray[1] will be key of the mapper contains respective filter string of the metric @@ -53,34 +52,32 @@ public static JSONArray generateMetricFilterJsonArray(String metricString) throw //Retrieving the filter string from the mapper and creating a metric set with metric as key //and filter as value String metricFilter = metricFilterArray.length > 1 ? mapper.get("-" + metricFilterArray[1]) : ""; - metricList.add(getJsonString(metricFilterArray[0], metricFilter)); - } - StringBuilder finalJson = new StringBuilder(); - //preparing complete json string by appending brackets to metric name and metric filter - for (String jsonToken : metricList) { - finalJson.append("{" + jsonToken + "},"); + + ObjectNode objectNode = arrayNode.objectNode(); + addJsonFilter(objectNode, metricFilterArray[0], metricFilter); + arrayNode.add(objectNode); } - return new JSONArray("[" + finalJson.toString().substring(0, finalJson.toString().length() - 1) + "]"); + + return arrayNode; } /** - * Returns a String that is formatted to a JSON string. + * Add the name and filter of a metric to an ObjectNode. + * For eg: {"filter":{"AND":"property|id-in:[14,125],country|id-in:[US,IN]},"name":"foo"} * + * @param metricNode the object node to fill with the name and filter on a metric * @param metricName the name of the metric * @param metricFilter the filter associated with the metric. Could be empty or have a value - * - * @return A String in JSON format for a given metric and filter. - * For eg: "filter":{"AND":"property|id-in:[14,125],country|id-in:[US,IN]},"name":"foo" */ - private static String getJsonString(String metricName, String metricFilter) { - if (metricFilter.isEmpty()) { - metricFilter = "\"filter\": {}"; - } else { - metricFilter = "\"filter\":{\"AND\":\"" + - metricFilter.replace("AND", "").replace("(", "").replace(")", "") + "\" }"; - + private static void addJsonFilter(ObjectNode metricNode, String metricName, String metricFilter) { + metricNode.put("name", metricName); + ObjectNode filterNode = metricNode.putObject("filter"); + if (!metricFilter.isEmpty()) { + metricFilter = metricFilter.replace("AND", "") + .replace("(", "") + .replace(")", ""); + filterNode.put("AND", metricFilter); } - return "\"name\": \"" + metricName + "\"," + metricFilter; } /** diff --git a/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricsFilterSetBuilder.java b/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricsFilterSetBuilder.java index 6882f5ac78..03d038842b 100644 --- a/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricsFilterSetBuilder.java +++ b/fili-core/src/main/java/com/yahoo/bard/webservice/web/MetricsFilterSetBuilder.java @@ -14,8 +14,8 @@ import com.yahoo.bard.webservice.druid.model.postaggregation.SketchSetOperationPostAggFunction; import com.yahoo.bard.webservice.table.LogicalTable; -import org.json.JSONArray; -import org.json.JSONObject; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; import java.util.Collection; import java.util.List; @@ -38,7 +38,7 @@ public interface MetricsFilterSetBuilder { * @throws BadApiRequestException Invalid metric query if the metric query has * duplicate metrics */ - void validateDuplicateMetrics(JSONArray metricsJsonArray) throws BadApiRequestException; + void validateDuplicateMetrics(ArrayNode metricsJsonArray) throws BadApiRequestException; /** * Provides filter wrapped logical metric for the given logical metric. @@ -56,7 +56,7 @@ public interface MetricsFilterSetBuilder { */ LogicalMetric getFilteredLogicalMetric( LogicalMetric logicalMetric, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -125,7 +125,7 @@ Collection updateNestedQueryPostAggs( */ TemplateDruidQuery updateTemplateDruidQuery( TemplateDruidQuery query, - JSONObject metricFilterObject, + JsonNode metricFilterObject, DimensionDictionary dimensionDictionary, LogicalTable table, DataApiRequest apiRequest @@ -177,7 +177,7 @@ PostAggregation replacePostAggWithPostAggFromMap( * filter is not found. */ Set getFilteredAggregation( - JSONObject filter, + JsonNode filter, Aggregation aggregation, DimensionDictionary dimensionDictionary, LogicalTable table, diff --git a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/MetricParserSpec.groovy b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/MetricParserSpec.groovy index 100bebe388..2308b2945b 100644 --- a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/MetricParserSpec.groovy +++ b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/MetricParserSpec.groovy @@ -2,26 +2,29 @@ // 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 -import org.json.JSONArray +import com.yahoo.bard.webservice.application.ObjectMappersSuite + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ArrayNode import spock.lang.Specification import spock.lang.Unroll class MetricParserSpec extends Specification { - - JSONArray expectedJsonObj1 - JSONArray expectedJsonObj2 - JSONArray expectedJsonObj3 + ObjectMapper mapper = new ObjectMappersSuite().mapper + ArrayNode expectedJsonObj1 + ArrayNode expectedJsonObj2 + ArrayNode expectedJsonObj3 def setup() { - expectedJsonObj1 = new JSONArray("[{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]") - expectedJsonObj2 = new JSONArray("[{\"name\":\"pageviews\",\"filter\":{}},{\"name\":\"foo\",\"filter\":{}}]") - expectedJsonObj3 = new JSONArray("[{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"foo\"},{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"xcookie\"}]") + expectedJsonObj1 = mapper.readTree("[{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]"); + expectedJsonObj2 = mapper.readTree("[{\"name\":\"pageviews\",\"filter\":{}},{\"name\":\"foo\",\"filter\":{}}]") + expectedJsonObj3 = mapper.readTree("[{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"foo\"},{\"filter\":{\"AND\":\"app3|id-in[mobile,tablet],app2|id-in[abc,xyz]\"},\"name\":\"xcookie\"}]") } def "Test for wrong format of the metric filter with misaligned brackets"() { when: - MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet]app2|id-in[abc,xyz])").similar(expectedJsonObj1) + MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet]app2|id-in[abc,xyz])").equals(expectedJsonObj1) then: String expectedMessage = "Metrics parameter values are invalid. The string is: foo(AND(app3|id-in[mobile,tablet]app2|id-in[abc,xyz])" @@ -31,17 +34,17 @@ class MetricParserSpec extends Specification { def "Validate the json Array Object when metric string is a combination of filtered and non-filtered metrics"() { expect: - MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz])),pageviews").similar(expectedJsonObj1) + MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz])),pageviews").equals(expectedJsonObj1) } def "Validate the json Array Object when metric string contains only non-filtered metrics"() { expect: - MetricParser.generateMetricFilterJsonArray("pageviews,foo").similar(expectedJsonObj2) + MetricParser.generateMetricFilterJsonArray("pageviews,foo").equals(expectedJsonObj2) } def "Validate the json Array Object when metric string contains only filtered metrics"() { expect: - MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz])),xcookie(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz]))").similar(expectedJsonObj3) + MetricParser.generateMetricFilterJsonArray("foo(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz])),xcookie(AND(app3|id-in[mobile,tablet],app2|id-in[abc,xyz]))").equals(expectedJsonObj3) } def "Test for isBracketsBalanced validation"() { @@ -55,7 +58,7 @@ class MetricParserSpec extends Specification { @Unroll def "Create map using encodeMetricFilters, filter #filter returns values #filteredMetrics"() { setup: - Map metricMap = [:] + Map metricMap = [:] MetricParser.encodeMetricFilters(filter, metricMap) expect: diff --git a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/SketchIntersectionReportingResources.groovy b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/SketchIntersectionReportingResources.groovy index b6f2b74184..ba38fa110c 100644 --- a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/SketchIntersectionReportingResources.groovy +++ b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/SketchIntersectionReportingResources.groovy @@ -41,8 +41,9 @@ import com.yahoo.bard.webservice.table.LogicalTable import com.yahoo.bard.webservice.table.PhysicalTable import com.yahoo.bard.webservice.table.TableGroup -import org.json.JSONArray -import org.json.JSONObject +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ArrayNode import spock.lang.Specification /** @@ -56,7 +57,7 @@ class SketchIntersectionReportingResources extends Specification { public DimensionDictionary dimensionDict public MetricDictionary metricDict public LogicalTable table - public JSONObject filterObj + public JsonNode filterObj public PostAggregation fooPostAggregation; public Filter filter; public Set fooNoBarFilteredAggregationSet @@ -68,8 +69,11 @@ class SketchIntersectionReportingResources extends Specification { public TemplateDruidQuery dayAvgFoosTdq public Dimension propertyDim public Dimension countryDim + public ObjectMapper mapper SketchIntersectionReportingResources init() { + mapper = new ObjectMapper() + LinkedHashSet dimensionFields = new LinkedHashSet<>() dimensionFields.add(BardDimensionField.ID) dimensionFields.add(BardDimensionField.DESC) @@ -168,9 +172,9 @@ class SketchIntersectionReportingResources extends Specification { TableGroup tableGroup = new TableGroup([physicalTable] as LinkedHashSet, metrics, physicalTable.dimensions) table = new LogicalTable("NETWORK", DAY, tableGroup, metricDict) - JSONArray metricJsonObjArray = new JSONArray("[{\"filter\":{\"AND\":\"country|id-in[US,IN],property|id-in[114,125]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]") - JSONObject jsonobject = metricJsonObjArray.getJSONObject(0) - filterObj = jsonobject.getJSONObject("filter") + ArrayNode metricJsonObjArray = mapper.readTree("[{\"filter\":{\"AND\":\"country|id-in[US,IN],property|id-in[114,125]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]") + JsonNode jsonobject = metricJsonObjArray.get(0) + filterObj = jsonobject.get("filter") fooPostAggregation = foos.make().templateDruidQuery.getPostAggregations().first() diff --git a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/ThetaSketchIntersectionReportingResources.groovy b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/ThetaSketchIntersectionReportingResources.groovy index 687c8aee7a..1e8739b666 100644 --- a/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/ThetaSketchIntersectionReportingResources.groovy +++ b/fili-core/src/test/groovy/com/yahoo/bard/webservice/web/ThetaSketchIntersectionReportingResources.groovy @@ -42,8 +42,9 @@ import com.yahoo.bard.webservice.table.LogicalTable import com.yahoo.bard.webservice.table.PhysicalTable import com.yahoo.bard.webservice.table.TableGroup -import org.json.JSONArray -import org.json.JSONObject +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.node.ArrayNode import spock.lang.Specification @@ -54,9 +55,9 @@ class ThetaSketchIntersectionReportingResources extends Specification { public DimensionDictionary dimensionDict public MetricDictionary metricDict public LogicalTable table - public JSONObject filterObj public PostAggregation fooPostAggregation public Filter filter + public JsonNode filterObj public Set fooNoBarFilteredAggregationSet public Set fooRegFoosFilteredAggregationSet public ThetaSketchSetOperationPostAggregation fooNoBarPostAggregationInterim @@ -66,8 +67,11 @@ class ThetaSketchIntersectionReportingResources extends Specification { public TemplateDruidQuery dayAvgFoosTdq public Dimension propertyDim public Dimension countryDim + public ObjectMapper mapper ThetaSketchIntersectionReportingResources init() { + mapper = new ObjectMapper() + LinkedHashSet dimensionFields = new LinkedHashSet<>() dimensionFields.add(BardDimensionField.ID) dimensionFields.add(BardDimensionField.DESC) @@ -167,9 +171,9 @@ class ThetaSketchIntersectionReportingResources extends Specification { table = new LogicalTable("NETWORK", DAY, tableGroup, metricDict) - JSONArray metricJsonObjArray = new JSONArray("[{\"filter\":{\"AND\":\"country|id-in[US,IN],property|id-in[114,125]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]") - JSONObject jsonobject = metricJsonObjArray.getJSONObject(0) - filterObj = jsonobject.getJSONObject("filter") + ArrayNode metricJsonObjArray = mapper.readTree("[{\"filter\":{\"AND\":\"country|id-in[US,IN],property|id-in[114,125]\"},\"name\":\"foo\"},{\"filter\":{},\"name\":\"pageviews\"}]") + JsonNode jsonobject = metricJsonObjArray.get(0) + filterObj = jsonobject.get("filter") fooPostAggregation = foos.make().templateDruidQuery.getPostAggregations().first() diff --git a/pom.xml b/pom.xml index 00c5dc5a18..42b3520fb6 100644 --- a/pom.xml +++ b/pom.xml @@ -371,12 +371,6 @@ jackson-dataformat-csv ${version.jackson}
- - - org.json - json - 20160810 -