Skip to content

Commit

Permalink
add unsupported format test
Browse files Browse the repository at this point in the history
Signed-off-by: panguixin <panguixin@bytedance.com>
  • Loading branch information
bugmakerrrrrr committed Jul 8, 2024
1 parent dc263bc commit a984f54
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.function.BiFunction;
import lombok.Getter;
import lombok.Setter;
import org.opensearch.OpenSearchParseException;
import org.opensearch.common.time.DateFormatter;
import org.opensearch.common.time.DateFormatters;
import org.opensearch.common.time.FormatNames;
Expand Down Expand Up @@ -381,8 +382,11 @@ private ExprValue parseGeoPoint(Content content, boolean supportArrays) {
// an array in the [longitude, latitude] format.
if (first.isNumber()) {
double lon = first.doubleValue();
double lat = elements.next().doubleValue();
return new OpenSearchExprGeoPointValue(lat, lon);
var second = elements.next();
if (second.isNumber() == false) {
throw new OpenSearchParseException("lat must be a number, got " + second.objectValue());
}
return new OpenSearchExprGeoPointValue(second.doubleValue(), lon);
}

// there are multi points in doc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.junit.jupiter.api.Test;
import org.opensearch.OpenSearchParseException;
import org.opensearch.geometry.utils.Geohash;
import org.opensearch.sql.data.model.ExprCollectionValue;
import org.opensearch.sql.data.model.ExprDateValue;
Expand Down Expand Up @@ -721,6 +722,27 @@ public void constructGeoPoint() {
constructFromObject("geoV", "42.60355556,-97.25263889"));
}

@Test
public void constructGeoPointFromUnsupportedFormatShouldThrowException() {
OpenSearchParseException exception =
assertThrows(
OpenSearchParseException.class,
() -> tupleValue("{\"geoV\": [42.60355556, false]}").get("geoV"));
assertEquals("lat must be a number, got false", exception.getMessage());

exception =
assertThrows(
OpenSearchParseException.class,
() -> tupleValue("{\"geoV\":{\"lon\":-97.25263889}}").get("geoV"));
assertEquals("field [lat] missing", exception.getMessage());

exception =
assertThrows(
OpenSearchParseException.class,
() -> tupleValue("{\"geoV\":{\"lat\":true,\"lon\":-97.25263889}}").get("geoV"));
assertEquals("lat must be a number", exception.getMessage());
}

@Test
public void constructBinary() {
assertEquals(
Expand Down

0 comments on commit a984f54

Please sign in to comment.