Skip to content

Commit

Permalink
Merge pull request #327 from gisaia/fix/#325-checkExistsForFieldRange
Browse files Browse the repository at this point in the history
Check if field exists in document before range calculation
  • Loading branch information
MohamedHamouGisaia authored Jul 11, 2018
2 parents 606d7a3 + 3f48274 commit 9ec522b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ public FluidSearch aggregate(List<Aggregation> aggregations, Boolean isGeoAggreg
}

public FluidSearch getFieldRange(String field) {
boolQueryBuilder = boolQueryBuilder.filter(QueryBuilders.existsQuery(field));
MinAggregationBuilder minAggregationBuilder = AggregationBuilders.min(FIELD_MIN_VALUE).field(field);
MaxAggregationBuilder maxAggregationBuilder = AggregationBuilders.max(FIELD_MAX_VALUE).field(field);
searchRequestBuilder = searchRequestBuilder.setSize(0).addAggregation(minAggregationBuilder).addAggregation(maxAggregationBuilder);
Expand Down
1 change: 1 addition & 0 deletions arlas-tests/src/test/java/io/arlas/server/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Data {
public class DataParams {
public String job;
public int age;
public Integer weight;
public String city;
public String country;
public Long startdate;
Expand Down
3 changes: 3 additions & 0 deletions arlas-tests/src/test/java/io/arlas/server/DataSetTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ private static void fillIndex(String indexName, int lonMin, int lonMax, int latM
data.fullname = "My name is " + data.id;
data.params.age = Math.abs(i * j);
data.params.startdate = 1l * (i + 1000) * (j + 1000);
if (data.params.startdate >= 1013600) {
data.params.weight = (i + 10) * (j + 10);
}
data.params.stopdate = 1l * (i + 1000) * (j + 1000) + 100;
data.geo_params.centroid = j + "," + i;
data.params.job = jobs[((Math.abs(i) + Math.abs(j)) / 10) % (jobs.length - 1)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ public void handleNoHeaderFilter(ValidatableResponse then) throws Exception {
public void handleDescribeFeature(ValidatableResponse then) throws Exception {
if(!DataSetTool.ALIASED_COLLECTION) {
then.statusCode(200)
.body("xs:schema.complexType.complexContent.extension.sequence.element.size()", equalTo(7));
.body("xs:schema.complexType.complexContent.extension.sequence.element.size()", equalTo(8));
} else {
then.statusCode(200)
.body("xs:schema.complexType.complexContent.extension.sequence.element.size()", equalTo(9));
.body("xs:schema.complexType.complexContent.extension.sequence.element.size()", equalTo(10));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,20 @@ public void testNumericFieldRangeRequest() throws Exception {
rangeRequest.filter.f = Arrays.asList(new MultiValueFilter<>(new Expression("params.startdate", OperatorEnum.lt, "0")));
handleFieldRangeEmptyResponse(post(rangeRequest));
handleFieldRangeEmptyResponse(get(rangeRequest.field,"f", rangeRequest.filter.f.get(0).get(0).toString()));
rangeRequest.filter = new Filter();

rangeRequest.field = "params.weight";
rangeRequest.filter.f = Arrays.asList(new MultiValueFilter<>(new Expression("params.startdate", OperatorEnum.range, "[763600<1013700]")));
handleFieldRangeRequest(post(rangeRequest), 1, -6000, -6000);
handleFieldRangeRequest(get(rangeRequest.field,"f", rangeRequest.filter.f.get(0).get(0).toString()), 1, -6000, -6000);

rangeRequest.filter.f = Arrays.asList(new MultiValueFilter<>(new Expression("params.startdate", OperatorEnum.range, "[763600<1013599]")));
handleFieldRangeEmptyResponse(post(rangeRequest));
handleFieldRangeEmptyResponse(get(rangeRequest.field,"f", rangeRequest.filter.f.get(0).get(0).toString()));
rangeRequest.filter = new Filter();

rangeRequest.field = "params.foo";
handleFieldRangeEmptyResponse(post(rangeRequest));
handleFieldRangeEmptyResponse(get(rangeRequest.field));
}

//----------------------------------------------------------------
Expand All @@ -71,10 +84,6 @@ public void testInvalidFieldRangeRequest() throws Exception {
rangeRequest.field = "geo_params.centroid";
handleInvalidFieldRangeRequest(post(rangeRequest));
handleInvalidFieldRangeRequest(get(rangeRequest.field));

rangeRequest.field = "params.foo";
handleInvalidFieldRangeRequest(post(rangeRequest));
handleInvalidFieldRangeRequest(get(rangeRequest.field));
}

protected abstract void handleFieldRangeRequest(ValidatableResponse then, int count, float minValue, float maxValue) throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public void testQueryFilter() throws Exception {
handleNotMatchingRequest(header(request.filter));

request.filter.q = Arrays.asList(new MultiValueFilter<>(Arrays.asList("400", "600", "800", "1000")));
handleMatchingQueryFilter(post(request), 56);
handleMatchingQueryFilter(get("q", request.filter.q.get(0).get(0) + ";" + request.filter.q.get(0).get(1) + ";" + request.filter.q.get(0).get(2) + ";" + request.filter.q.get(0).get(3)), (56));
handleMatchingQueryFilter(header(request.filter), 56);
handleMatchingQueryFilter(post(request), 68);
handleMatchingQueryFilter(get("q", request.filter.q.get(0).get(0) + ";" + request.filter.q.get(0).get(1) + ";" + request.filter.q.get(0).get(2) + ";" + request.filter.q.get(0).get(3)), (68));
handleMatchingQueryFilter(header(request.filter), 68);

request.filter.q = null;
}
Expand Down
3 changes: 3 additions & 0 deletions arlas-tests/src/test/resources/dataset.alternate.mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"age": {
"type": "integer"
},
"weight": {
"type": "integer"
},
"keywords": {
"type": "keyword"
},
Expand Down
3 changes: 3 additions & 0 deletions arlas-tests/src/test/resources/dataset.mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"age": {
"type": "integer"
},
"weight": {
"type": "integer"
},
"tags": {
"type": "keyword"
},
Expand Down

0 comments on commit 9ec522b

Please sign in to comment.