|
@@ -15,6 +15,8 @@ import org.elasticsearch.xpack.eql.parser.EqlParser;
|
|
|
import org.elasticsearch.xpack.ql.expression.FieldAttribute;
|
|
|
import org.elasticsearch.xpack.ql.expression.predicate.logical.And;
|
|
|
import org.elasticsearch.xpack.ql.expression.predicate.logical.Not;
|
|
|
+import org.elasticsearch.xpack.ql.expression.predicate.nulls.IsNotNull;
|
|
|
+import org.elasticsearch.xpack.ql.expression.predicate.nulls.IsNull;
|
|
|
import org.elasticsearch.xpack.ql.expression.predicate.regex.Like;
|
|
|
import org.elasticsearch.xpack.ql.index.EsIndex;
|
|
|
import org.elasticsearch.xpack.ql.index.IndexResolution;
|
|
@@ -24,6 +26,8 @@ import org.elasticsearch.xpack.ql.plan.logical.OrderBy;
|
|
|
import org.elasticsearch.xpack.ql.type.EsField;
|
|
|
import org.elasticsearch.xpack.ql.type.TypesTests;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class OptimizerTests extends ESTestCase {
|
|
@@ -32,6 +36,7 @@ public class OptimizerTests extends ESTestCase {
|
|
|
private static final String INDEX_NAME = "test";
|
|
|
private EqlParser parser = new EqlParser();
|
|
|
private IndexResolution index = loadIndexResolution("mapping-default.json");
|
|
|
+
|
|
|
private static Map<String, EsField> loadEqlMapping(String name) {
|
|
|
return TypesTests.loadMapping(name);
|
|
|
}
|
|
@@ -51,9 +56,54 @@ public class OptimizerTests extends ESTestCase {
|
|
|
return accept(index, eql);
|
|
|
}
|
|
|
|
|
|
+ public void testIsNull() {
|
|
|
+ List<String> tests = Arrays.asList(
|
|
|
+ "foo where command_line == null",
|
|
|
+ "foo where null == command_line"
|
|
|
+ );
|
|
|
+
|
|
|
+ for (String q : tests) {
|
|
|
+ LogicalPlan plan = accept(q);
|
|
|
+ assertTrue(plan instanceof OrderBy);
|
|
|
+ plan = ((OrderBy) plan).child();
|
|
|
+ assertTrue(plan instanceof Filter);
|
|
|
+
|
|
|
+ Filter filter = (Filter) plan;
|
|
|
+ And condition = (And) filter.condition();
|
|
|
+ assertTrue(condition.right() instanceof IsNull);
|
|
|
+
|
|
|
+ IsNull check = (IsNull) condition.right();
|
|
|
+ assertEquals(((FieldAttribute) check.field()).name(), "command_line");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public void testIsNotNull() {
|
|
|
+ List<String> tests = Arrays.asList(
|
|
|
+ "foo where command_line != null",
|
|
|
+ "foo where null != command_line"
|
|
|
+ );
|
|
|
+
|
|
|
+ for (String q : tests) {
|
|
|
+ LogicalPlan plan = accept(q);
|
|
|
+ assertTrue(plan instanceof OrderBy);
|
|
|
+ plan = ((OrderBy) plan).child();
|
|
|
+ assertTrue(plan instanceof Filter);
|
|
|
+
|
|
|
+ Filter filter = (Filter) plan;
|
|
|
+ And condition = (And) filter.condition();
|
|
|
+ assertTrue(condition.right() instanceof IsNotNull);
|
|
|
+
|
|
|
+ IsNotNull check = (IsNotNull) condition.right();
|
|
|
+ assertEquals(((FieldAttribute) check.field()).name(), "command_line");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
public void testEqualsWildcard() {
|
|
|
- for (String q : new String[]{"foo where command_line == '* bar *'", "foo where '* bar *' == command_line"}) {
|
|
|
+ List<String> tests = Arrays.asList(
|
|
|
+ "foo where command_line == '* bar *'",
|
|
|
+ "foo where '* bar *' == command_line"
|
|
|
+ );
|
|
|
+
|
|
|
+ for (String q : tests) {
|
|
|
LogicalPlan plan = accept(q);
|
|
|
assertTrue(plan instanceof OrderBy);
|
|
|
plan = ((OrderBy) plan).child();
|
|
@@ -72,7 +122,12 @@ public class OptimizerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
public void testNotEqualsWildcard() {
|
|
|
- for (String q : new String[]{"foo where command_line != '* baz *'", "foo where '* baz *' != command_line"}) {
|
|
|
+ List<String> tests = Arrays.asList(
|
|
|
+ "foo where command_line != '* baz *'",
|
|
|
+ "foo where '* baz *' != command_line"
|
|
|
+ );
|
|
|
+
|
|
|
+ for (String q : tests) {
|
|
|
|
|
|
LogicalPlan plan = accept(q);
|
|
|
assertTrue(plan instanceof OrderBy);
|