Skip to content

Commit

Permalink
Minor refactor for ES|QL qstr integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty committed Nov 8, 2024
1 parent 7765193 commit 3d12ce4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
import org.elasticsearch.xpack.esql.plugin.TransportEsqlQueryAction;
import org.junit.After;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.equalTo;

@TestLogging(value = "org.elasticsearch.xpack.esql.session:DEBUG", reason = "to better understand planning")
Expand Down Expand Up @@ -219,4 +221,16 @@ protected static void assertColumnTypes(List<? extends ColumnInfo> actualColumns
protected static void assertValues(Iterator<Iterator<Object>> actualValues, Iterable<Iterable<Object>> expectedValues) {
assertThat(getValuesList(actualValues), equalTo(getValuesList(expectedValues)));
}

protected static void assertValuesInAnyOrder(Iterator<Iterator<Object>> actualValues, Iterable<Iterable<Object>> expectedValues) {
List<List<Object>> items = new ArrayList<>();
for (Iterable<Object> outter : expectedValues) {
var item = new ArrayList<>();
for (var inner : outter) {
item.add(inner);
}
items.add(item);
}
assertThat(getValuesList(actualValues), containsInAnyOrder(items.toArray()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@
import org.elasticsearch.index.query.QueryShardException;
import org.elasticsearch.xpack.esql.VerificationException;
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
import org.elasticsearch.xpack.esql.action.ColumnInfoImpl;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.junit.Before;

import java.util.List;

import static org.elasticsearch.test.ListMatcher.matchesList;
import static org.elasticsearch.test.MapMatcher.assertMap;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.xpack.esql.EsqlTestUtils.getValuesList;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.Matchers.equalTo;

public class QueryStringIT extends AbstractEsqlIntegTestCase {

Expand All @@ -42,11 +36,9 @@ public void testSimpleQueryString() {
""";

try (var resp = run(query)) {
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of("id")));
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of("INTEGER")));
// values
List<List<Object>> values = getValuesList(resp);
assertMap(values, matchesList().item(List.of(1)).item(List.of(3)).item(List.of(4)).item(List.of(5)));
assertColumnNames(resp.columns(), List.of("id"));
assertColumnTypes(resp.columns(), List.of("integer"));
assertValues(resp.values(), List.of(List.of(1), List.of(3), List.of(4), List.of(5)));
}
}

Expand All @@ -58,11 +50,9 @@ public void testMultiFieldQueryString() {
""";

try (var resp = run(query)) {
assertThat(resp.columns().stream().map(ColumnInfoImpl::name).toList(), equalTo(List.of("id")));
assertThat(resp.columns().stream().map(ColumnInfoImpl::type).map(DataType::toString).toList(), equalTo(List.of("INTEGER")));
// values
List<List<Object>> values = getValuesList(resp);
assertThat(values.size(), equalTo(5));
assertColumnNames(resp.columns(), List.of("id"));
assertColumnTypes(resp.columns(), List.of("integer"));
assertValuesInAnyOrder(resp.values(), List.of(List.of(1), List.of(2), List.of(3), List.of(4), List.of(5)));
}
}

Expand Down

0 comments on commit 3d12ce4

Please sign in to comment.