Skip to content

Commit

Permalink
ESQL: Clone ql for esql (#108773)
Browse files Browse the repository at this point in the history
Part of #106679

* Copy the `ql` project into a different project _just for esql_, call it `esql-core`.
* Make `esql` depend only on the latter.
* Fix `EsqlNodeSubclassTests`; I'm confused why this didn't bite us earlier.
* Update the warning regexes in some csv tests as the exceptions have other package names now.

**Note to reviewers:** Exclude the first commit when viewing the diff,
as that contains only the actual copying of `ql`. The remaining commits
are the actually meaningful ones. _The `build.gradle` files probably
require the most attention._
  • Loading branch information
alex-spies committed May 22, 2024
1 parent 06c27ec commit 16a5d24
Show file tree
Hide file tree
Showing 1,056 changed files with 39,571 additions and 3,058 deletions.
2 changes: 1 addition & 1 deletion benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies {
exclude group: 'net.sf.jopt-simple', module: 'jopt-simple'
}
api(project(':modules:aggregations'))
api(project(':x-pack:plugin:ql'))
api(project(':x-pack:plugin:esql-core'))
api(project(':x-pack:plugin:esql'))
api(project(':x-pack:plugin:esql:compute'))
implementation project(path: ':libs:elasticsearch-vec')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
import org.elasticsearch.compute.operator.EvalOperator;
import org.elasticsearch.compute.operator.Operator;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xpack.esql.core.expression.FieldAttribute;
import org.elasticsearch.xpack.esql.core.expression.Literal;
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.esql.core.tree.Source;
import org.elasticsearch.xpack.esql.core.type.DataTypes;
import org.elasticsearch.xpack.esql.core.type.EsField;
import org.elasticsearch.xpack.esql.evaluator.EvalMapper;
import org.elasticsearch.xpack.esql.expression.function.scalar.date.DateTrunc;
import org.elasticsearch.xpack.esql.expression.function.scalar.math.Abs;
Expand All @@ -31,12 +37,6 @@
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.Equals;
import org.elasticsearch.xpack.esql.planner.Layout;
import org.elasticsearch.xpack.esql.type.EsqlDataTypes;
import org.elasticsearch.xpack.ql.expression.FieldAttribute;
import org.elasticsearch.xpack.ql.expression.Literal;
import org.elasticsearch.xpack.ql.expression.predicate.regex.RLikePattern;
import org.elasticsearch.xpack.ql.tree.Source;
import org.elasticsearch.xpack.ql.type.DataTypes;
import org.elasticsearch.xpack.ql.type.EsField;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/esql/functions/examples/to_integer.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ The header will provide information on the source of the failure:

A following header will contain the failure reason and the offending value:

`"org.elasticsearch.xpack.ql.InvalidArgumentException: [501379200000] out of [integer] range"`
`"org.elasticsearch.xpack.esql.core.InvalidArgumentException: [501379200000] out of [integer] range"`


14 changes: 14 additions & 0 deletions x-pack/plugin/esql-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ES|QL core

This project originated as a copy of the `ql` x-pack plugin.
It contains some fundamental classes used in `esql`, like `Node`, its subclasses `Expression`, `QueryPlan`, and the plan optimizer code.
Originally, `ql` shared classes between ES|QL, SQL and EQL, but ES|QL diverged far enough to justify a split.

## Warning

- **Consider the contents of this project untested.**
There may be some tests in `sql` and `eql` that may have indirectly covered the initial version of this (when it was copied from `ql`);
but neither do these tests apply to `esql`, nor do they even run against this.
- **Consider this project technical debt.**
The contents of this project need to be consolidated with the `esql` plugin.
In particular, there is a significant amount of code (or code paths) that are not used/executed at all in `esql`.
24 changes: 24 additions & 0 deletions x-pack/plugin/esql-core/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'elasticsearch.internal-es-plugin'
apply plugin: 'elasticsearch.internal-test-artifact'

esplugin {
name 'x-pack-esql-core'
description 'Elasticsearch infrastructure plugin for ESQL'
classname 'org.elasticsearch.xpack.esql.core.plugin.EsqlCorePlugin'
extendedPlugins = ['x-pack-core']
}

base {
archivesName = 'x-pack-esql-core'
}

dependencies {
api "org.antlr:antlr4-runtime:${versions.antlr4}"
api project(path: xpackModule('mapper-version'))
compileOnly project(path: xpackModule('core'))
testApi(project(xpackModule('esql-core:test-fixtures'))) {
exclude group: 'org.elasticsearch.plugin', module: 'esql-core'
}
testImplementation project(':test:framework')
testImplementation(testArtifact(project(xpackModule('core'))))
}
26 changes: 26 additions & 0 deletions x-pack/plugin/esql-core/licenses/antlr4-runtime-LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[The "BSD license"]
Copyright (c) 2015 Terence Parr, Sam Harwell
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.core;

/**
* Exception thrown when unable to continue processing client request,
* in cases such as invalid query parameter or failure to apply requested processing to given data.
* It's meant as a generic equivalent to QlIllegalArgumentException (that's a server exception).
* TODO: reason for [E|S|ES]QL specializations of QlIllegalArgumentException?
* TODO: the intended use of ql.ParsingException, vs its [E|S|ES]QL equivalents, subclassed from the respective XxxClientException?
* Same for PlanningException.
*/
public class InvalidArgumentException extends QlClientException {

public InvalidArgumentException(String message, Object... args) {
super(message, args);
}

public InvalidArgumentException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.esql.core;

import org.elasticsearch.xpack.esql.core.tree.Source;

import static org.elasticsearch.common.logging.LoggerMessageFormat.format;

public class ParsingException extends QlClientException {
private final int line;
private final int charPositionInLine;

public ParsingException(String message, Exception cause, int line, int charPositionInLine) {
super(message, cause);
this.line = line;
this.charPositionInLine = charPositionInLine;
}

public ParsingException(String message, Object... args) {
this(Source.EMPTY, message, args);
}

public ParsingException(Source source, String message, Object... args) {
super(message, args);
this.line = source.source().getLineNumber();
this.charPositionInLine = source.source().getColumnNumber();
}

public ParsingException(Exception cause, Source source, String message, Object... args) {
super(cause, message, args);
this.line = source.source().getLineNumber();
this.charPositionInLine = source.source().getColumnNumber();
}

public int getLineNumber() {
return line;
}

public int getColumnNumber() {
return charPositionInLine + 1;
}

public String getErrorMessage() {
return super.getMessage();
}

@Override
public String getMessage() {
return format("line {}:{}: {}", getLineNumber(), getColumnNumber(), getErrorMessage());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.core;

import org.elasticsearch.rest.RestStatus;

/**
* Exception thrown by performing client (or user) code.
* Typically it means the given action or query is incorrect and needs fixing.
*/
public class QlClientException extends QlException {

protected QlClientException(String message, Object... args) {
super(message, args);
}

protected QlClientException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

protected QlClientException(String message, Throwable cause) {
super(message, cause);
}

protected QlClientException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}

protected QlClientException(Throwable cause) {
super(cause);
}

@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.core;

import org.elasticsearch.ElasticsearchException;

/**
* Base class for all QL exceptions. Useful as a catch-all.
*/
public abstract class QlException extends ElasticsearchException {
public QlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public QlException(String message, Throwable cause) {
super(message, cause);
}

public QlException(String message, Object... args) {
super(message, args);
}

public QlException(Throwable cause, String message, Object... args) {
super(message, cause, args);
}

public QlException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.core;

public class QlIllegalArgumentException extends QlServerException {
public QlIllegalArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

public QlIllegalArgumentException(String message, Throwable cause) {
super(message, cause);
}

public QlIllegalArgumentException(String message, Object... args) {
super(message, args);
}

public QlIllegalArgumentException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}

public QlIllegalArgumentException(String message) {
super(message);
}

public QlIllegalArgumentException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
package org.elasticsearch.xpack.esql.core;

/**
* Exception triggered inside server-side code.
* Typically a validation error or worse, a bug.
*/
public abstract class QlServerException extends QlException {

protected QlServerException(String message, Object... args) {
super(message, args);
}

protected QlServerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

protected QlServerException(String message, Throwable cause) {
super(message, cause);
}

protected QlServerException(Throwable cause, String message, Object... args) {
super(cause, message, args);
}

protected QlServerException(Throwable cause) {
super(cause);
}
}

0 comments on commit 16a5d24

Please sign in to comment.