Skip to content

Commit

Permalink
Revert opensearch-project#817 fix, extracted to a separate branch.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 26, 2022
1 parent f14b66f commit d734103
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package org.opensearch.sql.opensearch.response.agg;

import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanInfValue;
import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanValue;

import java.util.Collections;
import java.util.Map;
Expand All @@ -34,6 +34,6 @@ public class SingleValueParser implements MetricParser {
public Map<String, Object> parse(Aggregation agg) {
return Collections.singletonMap(
agg.getName(),
handleNanInfValue(((NumericMetricsAggregation.SingleValue) agg).value()));
handleNanValue(((NumericMetricsAggregation.SingleValue) agg).value()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package org.opensearch.sql.opensearch.response.agg;

import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanInfValue;
import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanValue;

import java.util.Collections;
import java.util.Map;
Expand All @@ -36,6 +36,6 @@ public class StatsParser implements MetricParser {
@Override
public Map<String, Object> parse(Aggregation agg) {
return Collections.singletonMap(
agg.getName(), handleNanInfValue(valueExtractor.apply((ExtendedStats) agg)));
agg.getName(), handleNanValue(valueExtractor.apply((ExtendedStats) agg)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
@UtilityClass
public class Utils {
/**
* Utils to handle Nan/Infinite Value.
* @return null if is Nan or is +-Infinity.
* Utils to handle Nan Value.
* @return null if is Nan.
*/
public static Object handleNanInfValue(double value) {
return Double.isNaN(value) || Double.isInfinite(value) ? null : value;
public static Object handleNanValue(double value) {
return Double.isNaN(value) ? null : value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.opensearch.sql.opensearch.response.AggregationResponseUtils.fromJson;
import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanInfValue;
import static org.opensearch.sql.opensearch.response.agg.Utils.handleNanValue;

import com.google.common.collect.ImmutableMap;
import java.util.List;
Expand Down Expand Up @@ -161,9 +161,7 @@ void unsupported_aggregation_should_fail() {

@Test
void nan_value_should_return_null() {
assertNull(handleNanInfValue(Double.NaN));
assertNull(handleNanInfValue(Double.NEGATIVE_INFINITY));
assertNull(handleNanInfValue(Double.POSITIVE_INFINITY));
assertNull(handleNanValue(Double.NaN));
}

@Test
Expand Down

0 comments on commit d734103

Please sign in to comment.