Skip to content
Open
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 @@ -72,7 +72,8 @@ public void cleanUp() throws Exception {
public void testSimplePPLQueryExecution() throws Exception {
String pplQuery =
String.format(
"source = opensearch.%s | fields firstname, age | where age > 30 | head 3",
"source = opensearch.%s | where age > 30 and account_number in (1, 6, 18) | fields"
+ " firstname, age",
TEST_INDEX_ACCOUNT);

RelNode logicalPlan = planner.plan(pplQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testParseCommandDispatchesToComplexPool() throws IOException {
executeQuery(
String.format(
"source=%s | parse address '(?<number>\\\\d+) (?<street>.*)'"
+ " | fields number, street | head 1",
+ " | sort account_number | fields number, street | head 1",
TEST_INDEX_BANK));

verifyDataRows(result, rows("880", "Holmes Lane"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,8 +955,8 @@ public void testMvmapWithOtherFieldReference() throws IOException {
JSONObject actual =
executeQuery(
String.format(
"source=%s | eval arr = array(1, 2, 3), result = mvmap(arr, arr * age) | head 1 |"
+ " fields age, result",
"source=%s | eval arr = array(1, 2, 3), result = mvmap(arr, arr * age) | sort"
Comment thread
dai-chen marked this conversation as resolved.
+ " account_number | head 1 | fields age, result",
TEST_INDEX_BANK));

verifySchema(actual, schema("age", "int"), schema("result", "array"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ public void testBinTimestampSpan7Days() throws IOException {
JSONObject result =
executeQuery(
String.format(
"source=%s | bin @timestamp span=7day | fields"
+ " @timestamp, value | sort @timestamp | head 3",
"source=%s | eval original_timestamp = @timestamp | bin @timestamp span=7day |"
+ " sort original_timestamp | head 3 | fields @timestamp, value",
TEST_INDEX_TIME_DATA));
verifySchema(result, schema("@timestamp", null, "timestamp"), schema("value", null, "int"));
verifyDataRows(
Expand All @@ -457,8 +457,8 @@ public void testBinTimestampSpan6Days() throws IOException {
JSONObject result =
executeQuery(
String.format(
"source=%s | bin @timestamp span=6day | fields"
+ " @timestamp, value | sort @timestamp | head 3",
"source=%s | eval original_timestamp = @timestamp | bin @timestamp span=6day |"
+ " sort original_timestamp | head 3 | fields @timestamp, value",
TEST_INDEX_TIME_DATA));
verifySchema(result, schema("@timestamp", null, "timestamp"), schema("value", null, "int"));
verifyDataRows(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,10 +573,14 @@ public void testTableWithDuplicateWildcardMatches() throws IOException {
public void testFieldsAndTableEquivalence() throws IOException {
JSONObject fieldsResult =
executeQuery(
String.format("source=%s | fields firstname, lastname | head 3", TEST_INDEX_ACCOUNT));
String.format(
"source=%s | where account_number in (1, 6, 13) | fields firstname, lastname",
TEST_INDEX_ACCOUNT));
JSONObject tableResult =
executeQuery(
String.format("source=%s | table firstname, lastname | head 3", TEST_INDEX_ACCOUNT));
String.format(
"source=%s | where account_number in (1, 6, 13) | table firstname, lastname",
TEST_INDEX_ACCOUNT));

verifySchema(fieldsResult, schema("firstname", "string"), schema("lastname", "string"));
verifySchema(tableResult, schema("firstname", "string"), schema("lastname", "string"));
Expand All @@ -592,11 +596,13 @@ public void testSpaceDelimitedEquivalentToCommaDelimited() throws IOException {
JSONObject commaResult =
executeQuery(
String.format(
"source=%s | fields firstname, lastname, age | head 3", TEST_INDEX_ACCOUNT));
"source=%s | where account_number in (1, 6, 13) | fields firstname, lastname, age",
TEST_INDEX_ACCOUNT));
JSONObject spaceResult =
executeQuery(
String.format(
"source=%s | fields firstname lastname age | head 3", TEST_INDEX_ACCOUNT));
"source=%s | where account_number in (1, 6, 13) | fields firstname lastname age",
TEST_INDEX_ACCOUNT));

verifySchema(
commaResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public void testMultisearchWithFieldsProjection() throws IOException {
JSONObject result =
executeQuery(
String.format(
"| multisearch [search source=%s | where gender = \\\"M\\\" | fields"
+ " firstname, lastname, balance] [search source=%s | where gender = \\\"F\\\""
+ " | fields firstname, lastname, balance] | head 5",
"| multisearch [search source=%s | where gender = \\\"M\\\" and account_number in"
+ " (1, 6, 18) | fields firstname, lastname, balance] [search source=%s | where"
+ " gender = \\\"F\\\" and account_number in (13, 25) | fields firstname,"
+ " lastname, balance]",
TEST_INDEX_ACCOUNT, TEST_INDEX_ACCOUNT));

verifySchema(
Expand All @@ -145,8 +146,8 @@ public void testMultisearchWithFieldsProjection() throws IOException {
rows("Amber", "Duke", 39225L),
rows("Hattie", "Bond", 5686L),
rows("Dale", "Adams", 4180L),
rows("Elinor", "Ratliff", 16418L),
rows("Mcgee", "Mooney", 18612L));
rows("Nanette", "Bates", 32838L),
rows("Virginia", "Ayala", 40540L));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ public void testMvCombine_basicGroupCollapsesToOneRow() throws IOException {
schema("tags", null, "string"),
schema("packets_str", null, "array"));

verifyDataRows(result, rows("10.0.0.1", 100, "t1", List.of("10", "20", "30")));
JSONArray row = result.getJSONArray("datarows").getJSONArray(0);
Assertions.assertEquals("10.0.0.1", row.getString(0));
Assertions.assertEquals(100, row.getLong(1));
Assertions.assertEquals("t1", row.getString(2));
List<String> packets = new ArrayList<>();
row.getJSONArray(3).forEach(value -> packets.add(value.toString()));
Collections.sort(packets);
Assertions.assertEquals(List.of("10", "20", "30"), packets);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import static org.opensearch.sql.legacy.TestsConstants.*;
import static org.opensearch.sql.util.Capability.COALESCE_ALL_NULL_OPERANDS;
import static org.opensearch.sql.util.Capability.HEAD_WITHOUT_STABLE_SORT;
import static org.opensearch.sql.util.MatcherUtils.*;

import java.io.IOException;
Expand Down Expand Up @@ -39,13 +38,12 @@ public void init() throws Exception {
}

@Test
@RequiresCapability(HEAD_WITHOUT_STABLE_SORT)
public void testCoalesceBasic() throws IOException {
JSONObject actual =
executeQuery(
String.format(
"source=%s | eval result = coalesce(name, age, 0) | fields name, age, result |"
+ " head 3",
"source=%s | eval result = coalesce(name, age, 0) | sort - age | fields name, age,"
Comment thread
mengweieric marked this conversation as resolved.
+ " result | head 3",
TEST_INDEX_STATE_COUNTRY_WITH_NULL));

verifySchema(
Expand All @@ -55,13 +53,12 @@ public void testCoalesceBasic() throws IOException {
}

@Test
@RequiresCapability(HEAD_WITHOUT_STABLE_SORT)
public void testCoalesceWithMixedTypes() throws IOException {
JSONObject actual =
executeQuery(
String.format(
"source=%s | eval result = coalesce(name, age, 'fallback') |"
+ " fields name, age, result | head 3",
+ " sort - age | fields name, age, result | head 3",
TEST_INDEX_STATE_COUNTRY_WITH_NULL));

verifySchema(
Expand Down Expand Up @@ -170,8 +167,8 @@ public void testCoalesceWithAllNonExistentFields() throws IOException {
JSONObject actual =
executeQuery(
String.format(
"source=%s | eval result = coalesce(field1, field2, field3) | fields name, result |"
+ " head 1",
"source=%s | eval result = coalesce(field1, field2, field3) | sort - age | fields"
+ " name, result | head 1",
TEST_INDEX_STATE_COUNTRY_WITH_NULL));

// When every COALESCE operand is missing/null, the result has no known type (see #5175).
Expand Down
Loading
Loading