Skip to content

Commit

Permalink
Merge branch 'main' into testing_aug17_s
Browse files Browse the repository at this point in the history
Signed-off-by: Mitchell Gale <[email protected]>
  • Loading branch information
MitchellGale authored Aug 18, 2023
2 parents f3ddcd3 + b977f1e commit 7b86ad7
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ protected OpenSearchDataType cloneEmpty() {
}

/**
* Text field doesn't have doc value (exception thrown even when you call "get") Limitation:
* assume inner field name is always "keyword".
* Text field doesn't have doc value (exception thrown even when you call "get")<br>
* Limitation: assume inner field name is always "keyword".
*/
public static String convertTextToKeyword(String fieldName, ExprType fieldType) {
if (fieldType instanceof OpenSearchTextType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public Pair<Double, Double> geoValue() {
return Pair.of(lat, lon);
} else {
throw new IllegalStateException(
"geo point must in format of {\"lat\": number, \"lon\": " + "number}");
"geo point must in format of {\"lat\": number, \"lon\": number}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.opensearch.sql.opensearch.data.type.OpenSearchIpType;

/**
* OpenSearch IP ExprValue. Todo, add this to avoid the unknown value type exception, the
* implementation will be changed.
* OpenSearch IP ExprValue<br>
* Todo, add this to avoid the unknown value type exception, the implementation will be changed.
*/
@RequiredArgsConstructor
public class OpenSearchExprIpValue extends AbstractExprValue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ public OpenSearchExprValueFactory(Map<String, OpenSearchDataType> typeMapping) {
}

/**
* The struct construction has the following assumption: 1. The field has OpenSearch Object data
* type. See <a
* href="https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html">docs</a> 2.
* The deeper field is flattened in the typeMapping. e.g. { "employ", "STRUCT" } { "employ.id",
* "INTEGER" } { "employ.state", "STRING" }
*
*
* <pre>
* The struct construction has the following assumption:
* 1. The field has OpenSearch Object data type.
* See <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html">
* docs</a>
* 2. The deeper field is flattened in the typeMapping. e.g.
* { "employ", "STRUCT" }
* { "employ.id", "INTEGER" }
* { "employ.state", "STRING" }
* </pre>
*/
public ExprValue construct(String jsonString, boolean supportArrays) {
try {
Expand All @@ -172,8 +179,8 @@ public ExprValue construct(String jsonString, boolean supportArrays) {

/**
* Construct ExprValue from field and its value object. Throw exception if trying to construct
* from field of unsupported type. Todo, add IP, GeoPoint support after we have function
* implementation around it.
* from field of unsupported type.<br>
* Todo, add IP, GeoPoint support after we have function implementation around it.
*
* @param field field name
* @param value value object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@

/**
* {@link ResourceMonitor} implementation on Elasticsearch. When the heap memory usage exceeds
* certain threshold, the monitor is not healthy. Todo, add metrics.
* certain threshold, the monitor is not healthy.<br>
* Todo, add metrics.
*/
@Log4j2
public class OpenSearchResourceMonitor extends ResourceMonitor {
private final Settings settings;
private final Retry retry;
private final OpenSearchMemoryHealthy memoryMonitor;

/** Constructor of ElasticsearchCircuitBreaker. */
/** Constructor. */
public OpenSearchResourceMonitor(Settings settings, OpenSearchMemoryHealthy memoryMonitor) {
this.settings = settings;
RetryConfig config =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public boolean hasAnotherBatch() {
@Override
public void writeTo(StreamOutput out) throws IOException {
throw new UnsupportedOperationException(
"OpenSearchQueryRequest serialization " + "is not implemented.");
"OpenSearchQueryRequest serialization is not implemented.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void constructDatetime_fromCustomFormat() {
IllegalArgumentException.class,
() -> constructFromObject("customFormatV", "2015-01-01 12-10-30"));
assertEquals(
"Construct TIMESTAMP from \"2015-01-01 12-10-30\" failed, " + "unsupported format.",
"Construct TIMESTAMP from \"2015-01-01 12-10-30\" failed, unsupported format.",
exception.getMessage());

assertEquals(
Expand All @@ -393,7 +393,7 @@ public void constructDatetimeFromUnsupportedFormat_ThrowIllegalArgumentException
IllegalArgumentException.class,
() -> constructFromObject("timestampV", "2015-01-01 12:10"));
assertEquals(
"Construct TIMESTAMP from \"2015-01-01 12:10\" failed, " + "unsupported format.",
"Construct TIMESTAMP from \"2015-01-01 12:10\" failed, unsupported format.",
exception.getMessage());

// fail with missing seconds
Expand All @@ -402,7 +402,7 @@ public void constructDatetimeFromUnsupportedFormat_ThrowIllegalArgumentException
IllegalArgumentException.class,
() -> constructFromObject("dateOrEpochMillisV", "2015-01-01 12:10"));
assertEquals(
"Construct TIMESTAMP from \"2015-01-01 12:10\" failed, " + "unsupported format.",
"Construct TIMESTAMP from \"2015-01-01 12:10\" failed, unsupported format.",
exception.getMessage());
}

Expand All @@ -412,14 +412,13 @@ public void constructTimeFromUnsupportedFormat_ThrowIllegalArgumentException() {
assertThrows(
IllegalArgumentException.class, () -> constructFromObject("timeV", "2015-01-01"));
assertEquals(
"Construct TIME from \"2015-01-01\" failed, " + "unsupported format.",
exception.getMessage());
"Construct TIME from \"2015-01-01\" failed, unsupported format.", exception.getMessage());

exception =
assertThrows(
IllegalArgumentException.class, () -> constructFromObject("timeStringV", "10:10"));
assertEquals(
"Construct TIME from \"10:10\" failed, " + "unsupported format.", exception.getMessage());
"Construct TIME from \"10:10\" failed, unsupported format.", exception.getMessage());
}

@Test
Expand All @@ -428,14 +427,12 @@ public void constructDateFromUnsupportedFormat_ThrowIllegalArgumentException() {
assertThrows(
IllegalArgumentException.class, () -> constructFromObject("dateV", "12:10:10"));
assertEquals(
"Construct DATE from \"12:10:10\" failed, " + "unsupported format.",
exception.getMessage());
"Construct DATE from \"12:10:10\" failed, unsupported format.", exception.getMessage());

exception =
assertThrows(
IllegalArgumentException.class, () -> constructFromObject("dateStringV", "abc"));
assertEquals(
"Construct DATE from \"abc\" failed, " + "unsupported format.", exception.getMessage());
assertEquals("Construct DATE from \"abc\" failed, unsupported format.", exception.getMessage());
}

@Test
Expand Down Expand Up @@ -481,23 +478,20 @@ public void constructNestedArraysOfStrings() {
assertEquals(
new ExprCollectionValue(
List.of(collectionValue(List.of("zz", "au")), collectionValue(List.of("ss")))),
tupleValueWithArraySupport("{\"stringV\":[" + "[\"zz\", \"au\"]," + "[\"ss\"]" + "]}")
.get("stringV"));
tupleValueWithArraySupport("{\"stringV\":[ [\"zz\", \"au\"], [\"ss\"] ]}").get("stringV"));
}

@Test
public void constructNestedArraysOfStringsReturnsFirstIndex() {
assertEquals(
stringValue("zz"),
tupleValue("{\"stringV\":[" + "[\"zz\", \"au\"]," + "[\"ss\"]" + "]}").get("stringV"));
stringValue("zz"), tupleValue("{\"stringV\":[[\"zz\", \"au\"],[\"ss\"]]}").get("stringV"));
}

@Test
public void constructMultiNestedArraysOfStringsReturnsFirstIndex() {
assertEquals(
stringValue("z"),
tupleValue("{\"stringV\":" + "[\"z\"," + "[\"s\"]," + "[\"zz\", \"au\"]" + "]}")
.get("stringV"));
tupleValue("{\"stringV\":[\"z\",[\"s\"],[\"zz\", \"au\"]]}").get("stringV"));
}

@Test
Expand Down Expand Up @@ -567,20 +561,20 @@ public void constructNestedObjectArrayOfObjectArraysNode() {
Map.of("timeV", new ExprTimeValue("09:07:42")))))),
tupleValueWithArraySupport(
"{\"deepNestedV\":"
+ "["
+ "{\"year\":"
+ "["
+ "{\"timeV\":\"09:07:42\"},"
+ "{\"timeV\":\"09:07:42\"}"
+ "]"
+ "},"
+ "{\"year\":"
+ "["
+ "{\"timeV\":\"09:07:42\"},"
+ "{\"timeV\":\"09:07:42\"}"
+ "]"
+ "}"
+ "]"
+ " ["
+ " {\"year\":"
+ " ["
+ " {\"timeV\":\"09:07:42\"},"
+ " {\"timeV\":\"09:07:42\"}"
+ " ]"
+ " },"
+ " {\"year\":"
+ " ["
+ " {\"timeV\":\"09:07:42\"},"
+ " {\"timeV\":\"09:07:42\"}"
+ " ]"
+ " }"
+ " ]"
+ "}")
.get("deepNestedV"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OpenSearchAggregationResponseParserTest {
/** SELECT MAX(age) as max FROM accounts. */
@Test
void no_bucket_one_metric_should_pass() {
String response = "{\n" + " \"max#max\": {\n" + " \"value\": 40\n" + " }\n" + "}";
String response = "{\n \"max#max\": {\n \"value\": 40\n }\n}";
NoBucketAggregationParser parser = new NoBucketAggregationParser(new SingleValueParser("max"));
assertThat(parse(parser, response), contains(entry("max", 40d)));
}
Expand Down Expand Up @@ -140,8 +140,7 @@ void two_bucket_one_metric_should_pass() {

@Test
void unsupported_aggregation_should_fail() {
String response =
"{\n" + " \"date_histogram#date_histogram\": {\n" + " \"value\": 40\n" + " }\n" + "}";
String response = "{\n \"date_histogram#date_histogram\": {\n \"value\": 40\n }\n}";
NoBucketAggregationParser parser = new NoBucketAggregationParser(new SingleValueParser("max"));
RuntimeException exception =
assertThrows(RuntimeException.class, () -> parse(parser, response));
Expand Down

0 comments on commit 7b86ad7

Please sign in to comment.