Skip to content

Add support for $asin and $asinh aggregation operators #3796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,24 @@ public Sinh sinh(AngularUnit unit) {
return usesFieldRef() ? Sinh.sinhOf(fieldReference, unit) : Sinh.sinhOf(expression, unit);
}

/**
* Creates new {@link AggregationExpression} that calculates the inverse sine of a numeric value.
*
* @return new instance of {@link ASin}.
*/
public ASin asin() {
return usesFieldRef() ? ASin.asinOf(fieldReference) : ASin.asinOf(expression);
}

/**
* Creates new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a numeric value.
*
* @return new instance of {@link ASinh}.
*/
public ASinh asinh() {
return usesFieldRef() ? ASinh.asinhOf(fieldReference) : ASinh.asinhOf(expression);
}

/**
* Creates new {@link AggregationExpression} that calculates the cosine of a numeric value given in
* {@link AngularUnit#RADIANS radians}.
Expand Down Expand Up @@ -2272,6 +2290,104 @@ protected String getMongoMethod() {
return "$sinh";
}
}

/**
* An {@link AggregationExpression expression} that calculates the inverse sine of a value.
*
*/
public static class ASin extends AbstractAggregationExpression {

private ASin(Object value) {
super(value);
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse sine of a value.
*
* @param fieldReference the name of the {@link Field field} that resolves to a numeric value.
* @return new instance of {@link ASin}.
*/
public static ASin asinOf(String fieldReference) {

Assert.notNull(fieldReference, "FieldReference must not be null!");
return new ASin(Fields.field(fieldReference));
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse sine of a value.
* <p />
*
* @param expression the {@link AggregationExpression expression} that resolves to a numeric value.
* @return new instance of {@link ASin}.
*/
public static ASin asinOf(AggregationExpression expression) {
return new ASin(expression);
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse sine of a value.
*
* @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a
* numeric value.
* @return new instance of {@link ASin}.
*/
public static ASin asinOf(Number value) {
return new ASin(value);
}

@Override
protected String getMongoMethod() {
return "$asin";
}
}

/**
* An {@link AggregationExpression expression} that calculates the inverse hyperbolic sine of a value
*/
public static class ASinh extends AbstractAggregationExpression {

private ASinh(Object value) {
super(value);
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value.
*
* @param fieldReference the name of the {@link Field field} that resolves to a numeric value.
* @return new instance of {@link ASinh}.
*/
public static ASinh asinhOf(String fieldReference) {
return new ASinh(Fields.field(fieldReference));
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value.
* <p />
*
* @param expression the {@link AggregationExpression expression} that resolves to a numeric value.
* @return new instance of {@link ASinh}.
*/
public static ASinh asinhOf(AggregationExpression expression) {
return new ASinh(expression);
}

/**
* Creates a new {@link AggregationExpression} that calculates the inverse hyperbolic sine of a value.
*
* @param value anything ({@link Field field}, {@link AggregationExpression expression}, ...) that resolves to a
* numeric value.
* @return new instance of {@link ASinh}.
*/
public static ASinh asinhOf(Object value) {
return new ASinh(value);
}

@Override
protected String getMongoMethod() {
return "$asinh";
}
}


/**
* An {@link AggregationExpression expression} that calculates the cosine of a value that is measured in radians.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class MethodReferenceNode extends ExpressionNode {
map.put("integral", mapArgRef().forOperator("$integral").mappingParametersTo("input", "unit"));
map.put("sin", singleArgRef().forOperator("$sin"));
map.put("sinh", singleArgRef().forOperator("$sinh"));
map.put("asin", singleArgRef().forOperator("$asin"));
map.put("asinh", singleArgRef().forOperator("$asinh"));
map.put("cos", singleArgRef().forOperator("$cos"));
map.put("cosh", singleArgRef().forOperator("$cosh"));
map.put("tan", singleArgRef().forOperator("$tan"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ void rendersSinhWithValueInDegrees() {
assertThat(valueOf("angle").sinh(AngularUnit.DEGREES).toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo("{ $sinh : { $degreesToRadians : \"$angle\" } }");
}

@Test // DATAMONGO - 3708
void rendersASin() {

assertThat(valueOf("field").asin().toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo("{ $asin : \"$field\" }");
}

@Test // DATAMONGO - 3708
void rendersASinh() {

assertThat(valueOf("field").asinh().toDocument(Aggregation.DEFAULT_CONTEXT))
.isEqualTo("{ $asinh : \"$field\" }");
}

@Test // GH-3710
void rendersCos() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,16 @@ void shouldRenderSin() {
void shouldRenderSinh() {
assertThat(transform("sinh(angle)")).isEqualTo("{ \"$sinh\" : \"$angle\"}");
}

@Test // DATAMONGO-3708
void shouldRenderASin() {
assertThat(transform("asin(number)")).isEqualTo("{ \"$asin\" : \"$number\"}");
}

@Test // DATAMONGO-3708
void shouldRenderASinh() {
assertThat(transform("asinh(number)")).isEqualTo("{ \"$asinh\" : \"$number\"}");
}

@Test // GH-3710
void shouldRenderCos() {
Expand Down