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 @@ -119,7 +119,7 @@ public void setup() {
}

private LogicalPlan plan(EsqlParser parser, Analyzer analyzer, LogicalPlanOptimizer optimizer, String query) {
var parsed = parser.createStatement(query, new QueryParams(), telemetry, config);
var parsed = parser.createStatement(query, new QueryParams(), telemetry);
var analyzed = analyzer.analyze(parsed);
var optimized = optimizer.optimize(analyzed);
return optimized;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
*/
package org.elasticsearch.xpack.esql.core;

/**
* Like {@link IllegalArgumentException}, but treated as a server error.
* <p>
* Throw this in case of bugs, and the other in case of wrong user input.
* </p>
*/
public class QlIllegalArgumentException extends QlServerException {
public QlIllegalArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.RemoteException;
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
import org.elasticsearch.cluster.project.ProjectResolver;
Expand Down Expand Up @@ -103,6 +104,7 @@
import org.elasticsearch.xpack.esql.planner.PlannerSettings;
import org.elasticsearch.xpack.esql.planner.PlannerUtils;
import org.elasticsearch.xpack.esql.plugin.EsqlPlugin;
import org.elasticsearch.xpack.esql.plugin.EsqlQueryClusterSettings;
import org.elasticsearch.xpack.esql.plugin.QueryPragmas;
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
import org.elasticsearch.xpack.esql.session.Configuration;
Expand Down Expand Up @@ -445,7 +447,7 @@ public static LogicalOptimizerContext unboundLogicalOptimizerContext() {
createMockTransportService(),
mock(SearchService.class),
null,
mock(ClusterService.class),
createMockClusterService(),
mock(ProjectResolver.class),
mock(IndexNameExpressionResolver.class),
null,
Expand All @@ -454,6 +456,12 @@ public static LogicalOptimizerContext unboundLogicalOptimizerContext() {
TEST_PLANNER_SETTINGS
);

private static ClusterService createMockClusterService() {
var service = mock(ClusterService.class);
doReturn(new ClusterName("test-cluster")).when(service).getClusterName();
return service;
}

private static TransportService createMockTransportService() {
var service = mock(TransportService.class);
doReturn(createMockThreadPool()).when(service).getThreadPool();
Expand Down Expand Up @@ -495,6 +503,15 @@ public static Configuration configuration(String query) {
return configuration(new QueryPragmas(Settings.EMPTY), query);
}

public static EsqlQueryClusterSettings queryClusterSettings() {
return new EsqlQueryClusterSettings(
EsqlPlugin.QUERY_RESULT_TRUNCATION_MAX_SIZE.getDefault(Settings.EMPTY),
EsqlPlugin.QUERY_RESULT_TRUNCATION_DEFAULT_SIZE.getDefault(Settings.EMPTY),
EsqlPlugin.QUERY_TIMESERIES_RESULT_TRUNCATION_MAX_SIZE.getDefault(Settings.EMPTY),
EsqlPlugin.QUERY_TIMESERIES_RESULT_TRUNCATION_DEFAULT_SIZE.getDefault(Settings.EMPTY)
);
}

public static Literal L(Object value) {
return of(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,13 @@
import org.elasticsearch.xpack.esql.analysis.PreAnalyzer;
import org.elasticsearch.xpack.esql.analysis.Verifier;
import org.elasticsearch.xpack.esql.common.Failures;
import org.elasticsearch.xpack.esql.core.expression.FoldContext;
import org.elasticsearch.xpack.esql.enrich.EnrichPolicyResolver;
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext;
import org.elasticsearch.xpack.esql.optimizer.LogicalPlanOptimizer;
import org.elasticsearch.xpack.esql.optimizer.LogicalPlanPreOptimizer;
import org.elasticsearch.xpack.esql.optimizer.LogicalPreOptimizerContext;
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.esql.planner.mapper.Mapper;
import org.elasticsearch.xpack.esql.plugin.EsqlQueryClusterSettings;
import org.elasticsearch.xpack.esql.plugin.TransportActionServices;
import org.elasticsearch.xpack.esql.querylog.EsqlQueryLog;
import org.elasticsearch.xpack.esql.session.Configuration;
import org.elasticsearch.xpack.esql.session.EsqlSession;
import org.elasticsearch.xpack.esql.session.IndexResolver;
import org.elasticsearch.xpack.esql.session.Result;
Expand Down Expand Up @@ -72,8 +67,7 @@ public PlanExecutor(
public void esql(
EsqlQueryRequest request,
String sessionId,
Configuration cfg,
FoldContext foldContext,
EsqlQueryClusterSettings esqlQueryClusterSettings,
EnrichPolicyResolver enrichPolicyResolver,
EsqlExecutionInfo executionInfo,
IndicesExpressionGrouper indicesExpressionGrouper,
Expand All @@ -84,13 +78,11 @@ public void esql(
final PlanTelemetry planTelemetry = new PlanTelemetry(functionRegistry);
final var session = new EsqlSession(
sessionId,
cfg,
esqlQueryClusterSettings,
indexResolver,
enrichPolicyResolver,
preAnalyzer,
new LogicalPlanPreOptimizer(new LogicalPreOptimizerContext(foldContext, services.inferenceService())),
functionRegistry,
new LogicalPlanOptimizer(new LogicalOptimizerContext(cfg, foldContext)),
mapper,
verifier,
planTelemetry,
Expand Down
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Configuration" object wasn't being used here, at all. So I removed it. And this led to many changes along tests.
That's good btw, as otherwise creating the config after parsing would have been quite harder

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
import org.elasticsearch.xpack.esql.plan.EsqlStatement;
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.esql.session.Configuration;
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;

import java.util.BitSet;
Expand Down Expand Up @@ -100,41 +99,40 @@ public void setEsqlConfig(EsqlConfig config) {
}

// testing utility
public LogicalPlan createStatement(String query, Configuration configuration) {
return createStatement(query, new QueryParams(), configuration);
public LogicalPlan createStatement(String query) {
return createStatement(query, new QueryParams());
}

// testing utility
public LogicalPlan createStatement(String query, QueryParams params, Configuration configuration) {
return createStatement(query, params, new PlanTelemetry(new EsqlFunctionRegistry()), configuration);
public LogicalPlan createStatement(String query, QueryParams params) {
return createStatement(query, params, new PlanTelemetry(new EsqlFunctionRegistry()));
}

public LogicalPlan createStatement(String query, QueryParams params, PlanTelemetry metrics, Configuration configuration) {
public LogicalPlan createStatement(String query, QueryParams params, PlanTelemetry metrics) {
if (log.isDebugEnabled()) {
log.debug("Parsing as statement: {}", query);
}
return invokeParser(query, params, metrics, EsqlBaseParser::singleStatement, AstBuilder::plan, configuration);
return invokeParser(query, params, metrics, EsqlBaseParser::singleStatement, AstBuilder::plan);
}

// testing utility
public EsqlStatement createQuery(String query, QueryParams params, Configuration configuration) {
return createQuery(query, params, new PlanTelemetry(new EsqlFunctionRegistry()), configuration);
public EsqlStatement createQuery(String query, QueryParams params) {
return createQuery(query, params, new PlanTelemetry(new EsqlFunctionRegistry()));
}

public EsqlStatement createQuery(String query, QueryParams params, PlanTelemetry metrics, Configuration configuration) {
public EsqlStatement createQuery(String query, QueryParams params, PlanTelemetry metrics) {
if (log.isDebugEnabled()) {
log.debug("Parsing as statement: {}", query);
}
return invokeParser(query, params, metrics, EsqlBaseParser::statements, AstBuilder::statement, configuration);
return invokeParser(query, params, metrics, EsqlBaseParser::statements, AstBuilder::statement);
}

private <T> T invokeParser(
String query,
QueryParams params,
PlanTelemetry metrics,
Function<EsqlBaseParser, ParserRuleContext> parseFunction,
BiFunction<AstBuilder, ParserRuleContext, T> result,
Configuration configuration
BiFunction<AstBuilder, ParserRuleContext, T> result
) {
if (query.length() > MAX_LENGTH) {
throw new ParsingException("ESQL statement is too large [{} characters > {}]", query.length(), MAX_LENGTH);
Expand Down
Loading
Loading