Polishing.
Simplify field creation considering simplified projection expressions. See #3917 Original pull request: #4328
This commit is contained in:
@@ -96,23 +96,13 @@ class ExposedFieldsAggregationOperationContext implements AggregationOperationCo
|
|||||||
return exposedField;
|
return exposedField;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rootContext instanceof RelaxedTypeBasedAggregationOperationContext) {
|
if (rootContext instanceof RelaxedTypeBasedAggregationOperationContext) {
|
||||||
return new DirectFieldReference(new ExposedField(new Field() {
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (field != null) {
|
||||||
public String getTarget() {
|
return new DirectFieldReference(new ExposedField(field, true));
|
||||||
return field != null ? field.getTarget() : name;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return new DirectFieldReference(new ExposedField(name, true));
|
||||||
public boolean isAliased() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}, true));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException(String.format("Invalid reference '%s'", name));
|
throw new IllegalArgumentException(String.format("Invalid reference '%s'", name));
|
||||||
|
|||||||
@@ -601,7 +601,7 @@ public class AggregationUnitTests {
|
|||||||
new RelaxedTypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext,
|
new RelaxedTypeBasedAggregationOperationContext(BookWithFieldAnnotation.class, mappingContext,
|
||||||
new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
|
new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext))));
|
||||||
|
|
||||||
assertThat(extractPipelineElement(target, 1, "$project")).isEqualTo(Document.parse(" { \"_id\" : \"$_id\" }"));
|
assertThat(extractPipelineElement(target, 1, "$project")).isEqualTo(Document.parse(" { \"_id\" : 1 }"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // GH-3898
|
@Test // GH-3898
|
||||||
@@ -630,7 +630,7 @@ public class AggregationUnitTests {
|
|||||||
Document target = newAggregation(stage).toDocument("col-1", DEFAULT_CONTEXT);
|
Document target = newAggregation(stage).toDocument("col-1", DEFAULT_CONTEXT);
|
||||||
assertThat(extractPipelineElement(target, 0, "$project")).containsKey("name");
|
assertThat(extractPipelineElement(target, 0, "$project")).containsKey("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // GH-3917
|
@Test // GH-3917
|
||||||
void inheritedFieldsExposingContextShouldNotFailOnUnknownFieldReferenceForRelaxedRootContext() {
|
void inheritedFieldsExposingContextShouldNotFailOnUnknownFieldReferenceForRelaxedRootContext() {
|
||||||
|
|
||||||
@@ -648,7 +648,7 @@ public class AggregationUnitTests {
|
|||||||
|
|
||||||
MongoMappingContext mappingContext = new MongoMappingContext();
|
MongoMappingContext mappingContext = new MongoMappingContext();
|
||||||
QueryMapper queryMapper = new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext));
|
QueryMapper queryMapper = new QueryMapper(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext));
|
||||||
|
|
||||||
List<Document> documents = newAggregation(City.class, aggregationOperations).toPipeline(new RelaxedTypeBasedAggregationOperationContext(City.class, mappingContext, queryMapper));
|
List<Document> documents = newAggregation(City.class, aggregationOperations).toPipeline(new RelaxedTypeBasedAggregationOperationContext(City.class, mappingContext, queryMapper));
|
||||||
assertThat(documents.get(2)).isEqualTo("{ $sort : { 'serial_number' : -1, 'label_name' : -1 } }");
|
assertThat(documents.get(2)).isEqualTo("{ $sort : { 'serial_number' : -1, 'label_name' : -1 } }");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user