Polishing.

Simplify field creation considering simplified projection expressions.

See #3917
Original pull request: #4328
This commit is contained in:
Mark Paluch
2023-03-16 09:52:08 +01:00
parent e5bba39c62
commit aeea743921
2 changed files with 8 additions and 18 deletions

View File

@@ -97,22 +97,12 @@ class ExposedFieldsAggregationOperationContext implements AggregationOperationCo
} }
if (rootContext instanceof RelaxedTypeBasedAggregationOperationContext) { if (rootContext instanceof RelaxedTypeBasedAggregationOperationContext) {
return new DirectFieldReference(new ExposedField(new Field() {
@Override if (field != null) {
public String getName() { return new DirectFieldReference(new ExposedField(field, true));
return name;
} }
@Override return new DirectFieldReference(new ExposedField(name, true));
public String getTarget() {
return field != null ? field.getTarget() : name;
}
@Override
public boolean isAliased() {
return true;
}
}, true));
} }
throw new IllegalArgumentException(String.format("Invalid reference '%s'", name)); throw new IllegalArgumentException(String.format("Invalid reference '%s'", name));

View File

@@ -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