Skip to content

Commit

Permalink
QL: Backport project to 7.x (#51497)
Browse files Browse the repository at this point in the history
* 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.

(cherry picked from commit ec1ac0d)

* SQL: Fix incomplete registration of geo NamedWritables

(cherry picked from commit e295763)

* QL: Extend NodeSubclass to read classes from jars (#50866)

As the test classes are spread across more than one project, the Gradle
classpath contains not just folders but also jars.
This commit allows the test class to explore the archive content and
load matching classes from said source.

(cherry picked from commit 25ad749)

* QL: Remove implicit conversion inside Literal (#50962)

Literal constructor makes an implicit conversion for each value given
which turns out has some subtle side-effects.
Improve MathProcessors to preserve numeric type where possible
Fix bug on issue compatibility between date and intervals
Preserve the source when folding inside the Optimizer

(cherry picked from commit 9b73e22)

* QL: Refactor DataType for pluggability (#51328)

Change DataType from enum to class
Break DataType enums into QL (default) and SQL types
Make data type conversion pluggable so that new types can be introduced

As part of the process:
- static type conversion in QL package (such as Literal) has been
removed
- several utility classes have been broken into base (QL) and extended
(SQL) parts based on type awareness
- operators (+,-,/,*) are
- due to extensibility, serialization of arithmetic operation has been
slightly changed and pushed down to the operator executor itself

(cherry picked from commit aebda81)

* Compilation fixes for 7.x
  • Loading branch information
costin committed Jan 27, 2020
1 parent 3eae601 commit e22f501
Show file tree
Hide file tree
Showing 701 changed files with 10,786 additions and 7,211 deletions.
36 changes: 36 additions & 0 deletions x-pack/plugin/ql/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
evaluationDependsOn(xpackModule('core'))

apply plugin: 'elasticsearch.esplugin'
esplugin {
name 'x-pack-ql'
description 'Elasticsearch infrastructure plugin for EQL and SQL for Elasticsearch'
classname 'org.elasticsearch.xpack.ql.plugin.QlPlugin'
extendedPlugins = ['x-pack-core']
}

archivesBaseName = 'x-pack-ql'

dependencies {
compileOnly project(path: xpackModule('core'), configuration: 'default')
testCompile project(':test:framework')
testCompile project(path: xpackModule('core'), configuration: 'testArtifacts')
}

configurations {
testArtifacts.extendsFrom testRuntime
}

task testJar(type: Jar) {
appendix 'test'
from sourceSets.test.output
}

artifacts {
// normal es plugins do not publish the jar but we need to since users need it for extensions
archives jar
testArtifacts testJar
}


// disable integration tests for now
integTest.enabled = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.ql;

import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.xpack.ql.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 RestStatus status() {
return RestStatus.BAD_REQUEST;
}

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

public abstract 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql;
package org.elasticsearch.xpack.ql;

import org.elasticsearch.ElasticsearchException;

public abstract class SqlException extends ElasticsearchException {
public SqlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
public abstract class QlException extends ElasticsearchException {
public QlException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}

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

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

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

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

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,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.ql;

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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.capabilities;
package org.elasticsearch.xpack.ql.capabilities;

public interface Resolvable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.capabilities;
package org.elasticsearch.xpack.ql.capabilities;

public abstract class Resolvables {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.capabilities;
package org.elasticsearch.xpack.ql.capabilities;


public interface Unresolvable extends Resolvable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.capabilities;
package org.elasticsearch.xpack.ql.capabilities;

import org.elasticsearch.xpack.sql.ServerSqlException;
import org.elasticsearch.xpack.ql.QlServerException;

/**
* Thrown when we accidentally attempt to resolve something on on an unresolved entity. Throwing this
* is always a bug.
*/
public class UnresolvedException extends ServerSqlException {
public class UnresolvedException extends QlServerException {
public UnresolvedException(String action, Object target) {
super("Invalid call to {} on an unresolved object {}", action, target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.execution.search;
package org.elasticsearch.xpack.ql.execution.search;

/**
* Reference to a ES aggregation (which can be either a GROUP BY or Metric agg).
*/
public abstract class AggRef implements FieldExtraction {

@Override
public void collectFields(SqlSourceBuilder sourceBuilder) {
public void collectFields(QlSourceBuilder sourceBuilder) {
// Aggregations do not need any special fields
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.execution.search;
package org.elasticsearch.xpack.ql.execution.search;

import org.elasticsearch.search.builder.SearchSourceBuilder;

Expand All @@ -17,7 +17,7 @@ public interface FieldExtraction {
* in order to fetch the field. This can include tracking the score,
* {@code _source} fields, doc values fields, and script fields.
*/
void collectFields(SqlSourceBuilder sourceBuilder);
void collectFields(QlSourceBuilder sourceBuilder);

/**
* Is this aggregation supported in an "aggregation only" query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.xpack.sql.execution.search;
package org.elasticsearch.xpack.ql.execution.search;

import org.elasticsearch.common.Strings;
import org.elasticsearch.script.Script;
Expand All @@ -20,15 +20,15 @@
* {@link FieldExtraction} that can "build" whatever needs to be extracted from
* the resulting ES document as a field.
*/
public class SqlSourceBuilder {
public class QlSourceBuilder {
// The LinkedHashMaps preserve the order of the fields in the response
final Set<String> sourceFields = new LinkedHashSet<>();
final Set<FieldAndFormat> docFields = new LinkedHashSet<>();
final Map<String, Script> scriptFields = new LinkedHashMap<>();
private final Set<String> sourceFields = new LinkedHashSet<>();
private final Set<FieldAndFormat> docFields = new LinkedHashSet<>();
private final Map<String, Script> scriptFields = new LinkedHashMap<>();

boolean trackScores = false;

public SqlSourceBuilder() {
public QlSourceBuilder() {
}

/**
Expand Down Expand Up @@ -71,4 +71,8 @@ public void build(SearchSourceBuilder sourceBuilder) {
docFields.forEach(field -> sourceBuilder.docValueField(field.field, field.format));
scriptFields.forEach(sourceBuilder::scriptField);
}

public boolean noSource() {
return sourceFields.isEmpty();
}
}
Loading

0 comments on commit e22f501

Please sign in to comment.