Skip to content

Commit ec1ac0d

Browse files
authored
Introduce reusable QL plugin for SQL and EQL (#50815)
Extract reusable functionality from SQL into its own dedicated project QL. Implemented as a plugin, it provides common components across SQL and the upcoming EQL. While this commit is fairly large, for the most part it's just a big file move from sql package to the newly introduced ql.
1 parent 2d59c84 commit ec1ac0d

File tree

671 files changed

+6144
-4739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

671 files changed

+6144
-4739
lines changed

x-pack/plugin/ql/build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
evaluationDependsOn(xpackModule('core'))
2+
3+
apply plugin: 'elasticsearch.esplugin'
4+
esplugin {
5+
name 'x-pack-ql'
6+
description 'Elasticsearch infrastructure plugin for EQL and SQL for Elasticsearch'
7+
classname 'org.elasticsearch.xpack.ql.plugin.QlPlugin'
8+
extendedPlugins = ['x-pack-core']
9+
}
10+
11+
archivesBaseName = 'x-pack-ql'
12+
13+
dependencies {
14+
compileOnly project(path: xpackModule('core'), configuration: 'default')
15+
testCompile project(':test:framework')
16+
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
17+
}
18+
19+
configurations {
20+
testArtifacts.extendsFrom testRuntime
21+
}
22+
23+
task testJar(type: Jar) {
24+
appendix 'test'
25+
from sourceSets.test.output
26+
}
27+
28+
artifacts {
29+
// normal es plugins do not publish the jar but we need to since users need it for extensions
30+
archives jar
31+
testArtifacts testJar
32+
}
33+
34+
35+
// disable integration tests for now
36+
integTest.enabled = false
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
package org.elasticsearch.xpack.ql;
8+
9+
import org.elasticsearch.rest.RestStatus;
10+
import org.elasticsearch.xpack.ql.tree.Source;
11+
12+
import static org.elasticsearch.common.logging.LoggerMessageFormat.format;
13+
14+
public class ParsingException extends QlClientException {
15+
private final int line;
16+
private final int charPositionInLine;
17+
18+
public ParsingException(String message, Exception cause, int line, int charPositionInLine) {
19+
super(message, cause);
20+
this.line = line;
21+
this.charPositionInLine = charPositionInLine;
22+
}
23+
24+
public ParsingException(String message, Object... args) {
25+
this(Source.EMPTY, message, args);
26+
}
27+
28+
public ParsingException(Source source, String message, Object... args) {
29+
super(message, args);
30+
this.line = source.source().getLineNumber();
31+
this.charPositionInLine = source.source().getColumnNumber();
32+
}
33+
34+
public ParsingException(Exception cause, Source source, String message, Object... args) {
35+
super(cause, message, args);
36+
this.line = source.source().getLineNumber();
37+
this.charPositionInLine = source.source().getColumnNumber();
38+
}
39+
40+
public int getLineNumber() {
41+
return line;
42+
}
43+
44+
public int getColumnNumber() {
45+
return charPositionInLine + 1;
46+
}
47+
48+
public String getErrorMessage() {
49+
return super.getMessage();
50+
}
51+
52+
@Override
53+
public RestStatus status() {
54+
return RestStatus.BAD_REQUEST;
55+
}
56+
57+
@Override
58+
public String getMessage() {
59+
return format("line {}:{}: {}", getLineNumber(), getColumnNumber(), getErrorMessage());
60+
}
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.ql;
7+
8+
public abstract class QlClientException extends QlException {
9+
10+
protected QlClientException(String message, Object... args) {
11+
super(message, args);
12+
}
13+
14+
protected QlClientException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
15+
super(message, cause, enableSuppression, writableStackTrace);
16+
}
17+
18+
protected QlClientException(String message, Throwable cause) {
19+
super(message, cause);
20+
}
21+
22+
protected QlClientException(Throwable cause, String message, Object... args) {
23+
super(cause, message, args);
24+
}
25+
26+
protected QlClientException(Throwable cause) {
27+
super(cause);
28+
}
29+
}

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/SqlException.java renamed to x-pack/plugin/ql/src/main/java/org/elasticsearch/xpack/ql/QlException.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql;
6+
package org.elasticsearch.xpack.ql;
77

88
import org.elasticsearch.ElasticsearchException;
99

10-
public abstract class SqlException extends ElasticsearchException {
11-
public SqlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
10+
public abstract class QlException extends ElasticsearchException {
11+
public QlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
1212
super(message, cause, enableSuppression, writableStackTrace);
1313
}
1414

15-
public SqlException(String message, Throwable cause) {
15+
public QlException(String message, Throwable cause) {
1616
super(message, cause);
1717
}
1818

19-
public SqlException(String message, Object... args) {
19+
public QlException(String message, Object... args) {
2020
super(message, args);
2121
}
2222

23-
public SqlException(Throwable cause, String message, Object... args) {
23+
public QlException(Throwable cause, String message, Object... args) {
2424
super(message, cause, args);
2525
}
2626

27-
public SqlException(Throwable cause) {
27+
public QlException(Throwable cause) {
2828
super(cause);
2929
}
3030
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.ql;
7+
8+
public class QlIllegalArgumentException extends QlServerException {
9+
public QlIllegalArgumentException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
10+
super(message, cause, enableSuppression, writableStackTrace);
11+
}
12+
13+
public QlIllegalArgumentException(String message, Throwable cause) {
14+
super(message, cause);
15+
}
16+
17+
public QlIllegalArgumentException(String message, Object... args) {
18+
super(message, args);
19+
}
20+
21+
public QlIllegalArgumentException(Throwable cause, String message, Object... args) {
22+
super(cause, message, args);
23+
}
24+
25+
public QlIllegalArgumentException(String message) {
26+
super(message);
27+
}
28+
29+
public QlIllegalArgumentException(Throwable cause) {
30+
super(cause);
31+
}
32+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
package org.elasticsearch.xpack.ql;
7+
8+
public abstract class QlServerException extends QlException {
9+
10+
protected QlServerException(String message, Object... args) {
11+
super(message, args);
12+
}
13+
14+
protected QlServerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
15+
super(message, cause, enableSuppression, writableStackTrace);
16+
}
17+
18+
protected QlServerException(String message, Throwable cause) {
19+
super(message, cause);
20+
}
21+
22+
protected QlServerException(Throwable cause, String message, Object... args) {
23+
super(cause, message, args);
24+
}
25+
26+
protected QlServerException(Throwable cause) {
27+
super(cause);
28+
}
29+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.capabilities;
6+
package org.elasticsearch.xpack.ql.capabilities;
77

88
public interface Resolvable {
99

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.capabilities;
6+
package org.elasticsearch.xpack.ql.capabilities;
77

88
public abstract class Resolvables {
99

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.capabilities;
6+
package org.elasticsearch.xpack.ql.capabilities;
77

88

99
public interface Unresolvable extends Resolvable {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
package org.elasticsearch.xpack.sql.capabilities;
6+
package org.elasticsearch.xpack.ql.capabilities;
77

8-
import org.elasticsearch.xpack.sql.ServerSqlException;
8+
import org.elasticsearch.xpack.ql.QlServerException;
99

1010
/**
1111
* Thrown when we accidentally attempt to resolve something on on an unresolved entity. Throwing this
1212
* is always a bug.
1313
*/
14-
public class UnresolvedException extends ServerSqlException {
14+
public class UnresolvedException extends QlServerException {
1515
public UnresolvedException(String action, Object target) {
1616
super("Invalid call to {} on an unresolved object {}", action, target);
1717
}

0 commit comments

Comments
 (0)