Skip to content

Commit

Permalink
Ensure tests will not break on snapshot builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
afoucret committed Nov 20, 2024
1 parent 5c0083c commit d1b975c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
import org.elasticsearch.xpack.esql.VerificationException;
import org.elasticsearch.xpack.esql.action.AbstractEsqlIntegTestCase;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.action.EsqlQueryRequest;
import org.elasticsearch.xpack.esql.action.EsqlQueryResponse;
import org.junit.Before;
import org.junit.BeforeClass;

import java.util.List;

Expand All @@ -25,17 +24,16 @@

public class KqlFunctionIT extends AbstractEsqlIntegTestCase {

@BeforeClass
protected static void ensureKqlFunctionEnabled() {
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());
}

@Before
public void setupIndex() {
createAndPopulateIndex();
}

@Override
protected EsqlQueryResponse run(EsqlQueryRequest request) {
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());
return super.run(request);
}

public void testSimpleKqlQuery() {
var query = """
FROM test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,9 @@ public void testQueryStringFunctionsNotAllowedAfterCommands() throws Exception {
}

public void testKqlFunctionsNotAllowedAfterCommands() throws Exception {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

// Source commands
assertEquals("1:13: [KQL] function cannot be used after SHOW", error("show info | where kql(\"8.16.0\")"));
assertEquals("1:17: [KQL] function cannot be used after ROW", error("row a= \"Anna\" | where kql(\"Anna\")"));
Expand Down Expand Up @@ -1319,6 +1322,9 @@ public void testQueryStringFunctionOnlyAllowedInWhere() throws Exception {
}

public void testKqlFunctionOnlyAllowedInWhere() throws Exception {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

assertEquals("1:9: [KQL] function is only supported in WHERE commands", error("row a = kql(\"Anna\")"));
checkFullTextFunctionsOnlyAllowedInWhere("KQL", "kql(\"Anna\")", "function");
}
Expand Down Expand Up @@ -1366,6 +1372,9 @@ public void testQueryStringFunctionArgNotNullOrConstant() throws Exception {
}

public void testKqlFunctionArgNotNullOrConstant() throws Exception {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

assertEquals(
"1:19: argument of [kql(first_name)] must be a constant, received [first_name]",
error("from test | where kql(first_name)")
Expand All @@ -1379,6 +1388,9 @@ public void testQueryStringWithDisjunctions() {
}

public void testKqlFunctionWithDisjunctions() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

checkWithDisjunctions("KQL", "kql(\"first_name: Anna\")", "function");
}

Expand Down Expand Up @@ -1440,6 +1452,9 @@ public void testQueryStringFunctionWithNonBooleanFunctions() {
}

public void testKqlFunctionWithNonBooleanFunctions() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

checkFullTextFunctionsWithNonBooleanFunctions("KQL", "kql(\"first_name: Anna\")", "function");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.apache.lucene.util.BytesRef;
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
import org.elasticsearch.xpack.esql.core.expression.Expression;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.expression.function.AbstractFunctionTestCase;
import org.elasticsearch.xpack.esql.expression.function.FunctionName;
import org.elasticsearch.xpack.esql.expression.function.TestCaseSupplier;
import org.hamcrest.Matcher;
import org.junit.BeforeClass;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -27,6 +29,10 @@

@FunctionName("kql")
public class KqlTests extends AbstractFunctionTestCase {
@BeforeClass
protected static void ensureKqlFunctionEnabled() {
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());
}

public KqlTests(@Name("TestCase") Supplier<TestCaseSupplier.TestCase> testCaseSupplier) {
this.testCase = testCaseSupplier.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,9 @@ public void testMatchFunctionMultipleMatchClauses() {
* \_EsQueryExec[test], indexMode[standard], query[{"kql":{"query":"last_name: Smith"}}]
*/
public void testKqlFunction() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

var plan = plannerOptimizer.plan("""
from test
| where kql("last_name: Smith")
Expand Down Expand Up @@ -739,6 +742,9 @@ public void testKqlFunction() {
* "boost":1.0}}][_doc{f}#1423], limit[1000], sort[] estimatedRowSize[324]
*/
public void testKqlFunctionConjunctionWhereOperands() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

String queryText = """
from test
| where kql("last_name: Smith") and emp_no > 10010
Expand Down Expand Up @@ -773,6 +779,9 @@ public void testKqlFunctionConjunctionWhereOperands() {
* "source":"cidr_match(ip, \"127.0.0.1/32\")@2:38"}}],"boost":1.0}}][_doc{f}#21], limit[1000], sort[] estimatedRowSize[354]
*/
public void testKqlFunctionWithFunctionsPushedToLucene() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

String queryText = """
from test
| where kql("last_name: Smith") and cidr_match(ip, "127.0.0.1/32")
Expand Down Expand Up @@ -808,6 +817,9 @@ public void testKqlFunctionWithFunctionsPushedToLucene() {
* "boost":1.0}}][_doc{f}#1167], limit[1000], sort[] estimatedRowSize[324]
*/
public void testKqlFunctionMultipleWhereClauses() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

String queryText = """
from test
| where kql("last_name: Smith")
Expand Down Expand Up @@ -842,6 +854,9 @@ public void testKqlFunctionMultipleWhereClauses() {
* {"kql":{"query":"emp_no > 10010"}}],"boost":1.0}}]
*/
public void testKqlFunctionMultipleKqlClauses() {
// Skip test if the kql function is not enabled.
assumeTrue("kql function capability not available", EsqlCapabilities.Cap.KQL_FUNCTION.isEnabled());

String queryText = """
from test
| where kql("last_name: Smith") and kql("emp_no > 10010")
Expand Down

0 comments on commit d1b975c

Please sign in to comment.