Skip to content

Commit

Permalink
Address minor review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: currantw <[email protected]>
  • Loading branch information
currantw committed Dec 18, 2024
1 parent 7036e5f commit ac9c300
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class ExprIpValue extends AbstractExprValue {
private final IPAddress value;

public ExprIpValue(String s) {
value = IPUtils.toAddress(s);
public ExprIpValue(String addressString) {
value = IPUtils.toAddress(addressString);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ private ExprValue exprCidrMatch(ExprValue addressExprValue, ExprValue rangeExprV
IPAddress address = addressExprValue.ipValue();
IPAddress range = IPUtils.toRange(rangeExprValue.stringValue());

if (IPUtils.compare(address, range.getLower()) < 0) {
return ExprValueUtils.LITERAL_FALSE;
}

if (IPUtils.compare(address, range.getUpper()) > 0) {
return ExprValueUtils.LITERAL_FALSE;
}

return ExprValueUtils.LITERAL_TRUE;
return (IPUtils.compare(address, range.getLower()) < 0)
|| (IPUtils.compare(address, range.getUpper()) > 0)
? ExprValueUtils.LITERAL_FALSE
: ExprValueUtils.LITERAL_TRUE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ private static DefaultFunctionResolver castToBoolean() {
private static DefaultFunctionResolver castToIp() {
return FunctionDSL.define(
BuiltinFunctionName.CAST_TO_IP.getName(),
impl(nullMissingHandling((v) -> v), IP, IP),
impl(nullMissingHandling((v) -> new ExprIpValue(v.stringValue())), IP, STRING));
impl(nullMissingHandling((v) -> new ExprIpValue(v.stringValue())), IP, STRING),
impl(nullMissingHandling((v) -> v), IP, IP));
}

private static DefaultFunctionResolver castToDate() {
Expand Down
2 changes: 1 addition & 1 deletion docs/user/ppl/cmd/trendline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Syntax
* field: mandatory. The name of the field the moving average should be calculated for.
* alias: optional. The name of the resulting column containing the moving average (defaults to the field name with "_trendline").

And the moment only the Simple Moving Average (SMA) type is supported.
At the moment only the Simple Moving Average (SMA) type is supported.

It is calculated like

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ class OpenSearchExprValueFactoryTest {
.put("geoV", OpenSearchDataType.of(OpenSearchDataType.MappingType.GeoPoint))
.put("binaryV", OpenSearchDataType.of(OpenSearchDataType.MappingType.Binary))
.build();

private static final double TOLERANCE = 1E-5;
private final OpenSearchExprValueFactory exprValueFactory =
new OpenSearchExprValueFactory(MAPPING, true);

private final OpenSearchExprValueFactory exprValueFactoryNoArrays =
new OpenSearchExprValueFactory(MAPPING, false);

Expand Down Expand Up @@ -761,8 +760,6 @@ public void constructIP() {
tupleValue(String.format("{\"%s\":\"%s\"}", fieldIp, ipString)).get(fieldIp));
}

private static final double TOLERANCE = 1E-5;

@Test
public void constructGeoPoint() {
final double lat = 42.60355556;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void test_date_has_format() {
}

@Test
void test_string_field_type() {
String dateString = "STRING";
void test_non_date_field_type() {
String dateString = "2021-11-08";
OpenSearchDateType dateType = OpenSearchDateType.of(STRING);
ExprValue literal = ExprValueUtils.stringValue(dateString);
assertNotNull(new RangeQuery(Comparison.LT).doBuild("string_value", dateType, literal));
Expand Down

0 comments on commit ac9c300

Please sign in to comment.