Checkstyle and license headers in plugin

Original commit: elastic/x-pack-elasticsearch@e7855b949f
This commit is contained in:
Nik Everett 2017-06-22 12:22:57 -04:00
parent b504b0d2d9
commit 933a51edef
25 changed files with 1346 additions and 1495 deletions

View File

@ -40,7 +40,7 @@ subprojects {
}
tasks.withType(LicenseHeadersTask.class) {
approvedLicenses = ['Elasticsearch Confidential']
approvedLicenses = ['Elasticsearch Confidential', 'Generated']
additionalLicense 'ESCON', 'Elasticsearch Confidential', 'ELASTICSEARCH CONFIDENTIAL'
}
ext.projectSubstitutions += [ "org.elasticsearch.plugin:x-pack-api:${version}": ':x-pack-elasticsearch:plugin']

View File

@ -10,6 +10,7 @@
<!-- NOCOMMIT Temporary-->
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\].*.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]expression[/\\].*.java" checks="EqualsHashCode" />
<suppress files="sql-clients[/\\].*.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" />

View File

@ -969,7 +969,7 @@ public class Analyzer extends RuleExecutor<LogicalPlan> {
}
}
static abstract class AnalyzeRule<SubPlan extends LogicalPlan> extends Rule<SubPlan, LogicalPlan> {
abstract static class AnalyzeRule<SubPlan extends LogicalPlan> extends Rule<SubPlan, LogicalPlan> {
// transformUp (post-order) - that is first children and then the node
// but with a twist; only if the tree is not resolved or analyzed

View File

@ -5,8 +5,6 @@
*/
package org.elasticsearch.xpack.sql.analysis.analyzer;
import java.util.*;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.AttributeSet;
import org.elasticsearch.xpack.sql.expression.Expressions;
@ -20,6 +18,14 @@ import org.elasticsearch.xpack.sql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.sql.plan.logical.Project;
import org.elasticsearch.xpack.sql.tree.Node;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
@ -29,7 +35,7 @@ abstract class Verifier {
private final Node<?> source;
private final String message;
public Failure(Node<?> source, String message) {
Failure(Node<?> source, String message) {
this.source = source;
this.message = message;
}

View File

@ -11,7 +11,7 @@ import org.elasticsearch.search.SearchHitField;
class DocValueExtractor implements HitExtractor {
private final String fieldName;
public DocValueExtractor(String name) {
DocValueExtractor(String name) {
this.fieldName = name;
}

View File

@ -17,7 +17,7 @@ class InnerHitExtractor implements HitExtractor {
private final boolean useDocValue;
private final String[] tree;
public InnerHitExtractor(String hitName, String name, boolean useDocValue) {
InnerHitExtractor(String hitName, String name, boolean useDocValue) {
this.hitName = hitName;
this.fieldName = name;
this.useDocValue = useDocValue;

View File

@ -87,11 +87,11 @@ public class Scroller {
ScrollerActionListener l = new SessionScrollActionListener(listener, previous.client, previous.keepAlive, previous.schema, ext, previous.limit, previous.docsRead);
previous.client.searchScroll(new SearchScrollRequest(scrollId).scroll(previous.keepAlive), l);
}
}
// dedicated scroll used for aggs-only/group-by results
class AggsScrollActionListener extends ScrollerActionListener {
/**
* Dedicated scroll used for aggs-only/group-by results.
*/
static class AggsScrollActionListener extends ScrollerActionListener {
private final QueryContainer query;
AggsScrollActionListener(ActionListener<RowSetCursor> listener, Client client, TimeValue keepAlive, Schema schema, QueryContainer query) {
@ -174,11 +174,12 @@ class AggsScrollActionListener extends ScrollerActionListener {
private Object processIfNeeded(ColumnsProcessor processor, Object value) {
return processor != null ? processor.apply(value) : value;
}
}
// initial scroll used for parsing search hits (handles possible aggs)
class HandshakeScrollActionListener extends SearchHitsActionListener {
}
/**
* Initial scroll used for parsing search hits (handles possible aggs).
*/
static class HandshakeScrollActionListener extends SearchHitsActionListener {
private final QueryContainer query;
HandshakeScrollActionListener(ActionListener<RowSetCursor> listener, Client client, TimeValue keepAlive, Schema schema, QueryContainer query) {
@ -227,10 +228,12 @@ class HandshakeScrollActionListener extends SearchHitsActionListener {
throw new SqlIllegalArgumentException("Unexpected ValueReference %s", ref.getClass());
}
}
}
// listener used for streaming the rest of the results after the handshake has been used
class SessionScrollActionListener extends SearchHitsActionListener {
/**
* Listener used for streaming the rest of the results after the handshake has been used.
*/
static class SessionScrollActionListener extends SearchHitsActionListener {
private List<HitExtractor> exts;
@ -243,14 +246,14 @@ class SessionScrollActionListener extends SearchHitsActionListener {
protected List<HitExtractor> getExtractors() {
return exts;
}
}
abstract class SearchHitsActionListener extends ScrollerActionListener {
}
abstract static class SearchHitsActionListener extends ScrollerActionListener {
final int limit;
int docsRead;
SearchHitsActionListener(ActionListener<RowSetCursor> listener, Client client, TimeValue keepAlive, Schema schema, int limit, int docsRead) {
SearchHitsActionListener(ActionListener<RowSetCursor> listener, Client client, TimeValue keepAlive, Schema schema, int limit,
int docsRead) {
super(listener, client, keepAlive, schema);
this.limit = limit;
this.docsRead = docsRead;
@ -277,8 +280,7 @@ abstract class SearchHitsActionListener extends ScrollerActionListener {
clearScroll(scrollId);
// and remove it to indicate no more data is expected
scrollId = null;
}
else {
} else {
next = l -> Scroller.from(l, this, response.getScrollId(), exts);
}
}
@ -303,9 +305,9 @@ abstract class SearchHitsActionListener extends ScrollerActionListener {
}
protected abstract List<HitExtractor> getExtractors();
}
}
abstract class ScrollerActionListener implements ActionListener<SearchResponse> {
abstract static class ScrollerActionListener implements ActionListener<SearchResponse> {
final ActionListener<RowSetCursor> listener;
@ -348,4 +350,5 @@ abstract class ScrollerActionListener implements ActionListener<SearchResponse>
public final void onFailure(Exception ex) {
listener.onFailure(ex);
}
}
}

View File

@ -12,7 +12,7 @@ import org.elasticsearch.search.SearchHit;
class SourceExtractor implements HitExtractor {
private final String fieldName;
public SourceExtractor(String name) {
SourceExtractor(String name) {
this.fieldName = name;
}

View File

@ -43,6 +43,7 @@ public abstract class NamedExpression extends Expression {
@Override
public final int hashCode() {
// NOCOMMIT making this final upsets checkstyle.
return id.hashCode();
}

View File

@ -14,7 +14,7 @@ import org.elasticsearch.xpack.sql.type.DataType;
abstract class UnresolvedNamedExpression extends NamedExpression implements Unresolvable {
public UnresolvedNamedExpression(Location location, List<Expression> children) {
UnresolvedNamedExpression(Location location, List<Expression> children) {
super(location, "<unresolved>", children, ExpressionIdGenerator.EMPTY);
}

View File

@ -5,16 +5,53 @@
*/
package org.elasticsearch.xpack.sql.expression.function;
import org.elasticsearch.xpack.sql.SqlException;
import org.elasticsearch.xpack.sql.expression.function.aggregate.Avg;
import org.elasticsearch.xpack.sql.expression.function.aggregate.Count;
import org.elasticsearch.xpack.sql.expression.function.aggregate.Max;
import org.elasticsearch.xpack.sql.expression.function.aggregate.Min;
import org.elasticsearch.xpack.sql.expression.function.aggregate.Sum;
import org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayOfMonth;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayOfWeek;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DayOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.HourOfDay;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.MinuteOfDay;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.MinuteOfHour;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.MonthOfYear;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.SecondOfMinute;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.Year;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.ACos;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.ASin;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.ATan;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Abs;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cbrt;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Ceil;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cos;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Cosh;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Degrees;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.E;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Exp;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Expm1;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Floor;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Log;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Log10;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Pi;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Radians;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Round;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sin;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sinh;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Sqrt;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.Tan;
import java.io.IOException;
import java.lang.reflect.Modifier;
import java.net.URL;
import java.util.*;
import org.elasticsearch.xpack.sql.SqlException;
import org.elasticsearch.xpack.sql.expression.function.aggregate.*;
import org.elasticsearch.xpack.sql.expression.function.scalar.ScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.*;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Map;
import static org.elasticsearch.xpack.sql.util.CollectionUtils.combine;
import static org.elasticsearch.xpack.sql.util.CollectionUtils.of;

View File

@ -16,7 +16,7 @@ public enum FunctionType {
private final Class<? extends Function> baseClass;
private FunctionType(Class<? extends Function> base) {
FunctionType(Class<? extends Function> base) {
this.baseClass = base;
}

View File

@ -16,7 +16,7 @@ import org.elasticsearch.xpack.sql.type.DataTypes;
public class FullTextPredicate extends Expression {
public static enum Operator {
public enum Operator {
AND,
OR;

View File

@ -5,20 +5,13 @@
*/
package org.elasticsearch.xpack.sql.optimizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
import org.elasticsearch.xpack.sql.analysis.catalog.Catalog;
import org.elasticsearch.xpack.sql.expression.Alias;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.AttributeSet;
import org.elasticsearch.xpack.sql.expression.BinaryExpression;
import org.elasticsearch.xpack.sql.expression.BinaryExpression.Negateable;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.ExpressionSet;
import org.elasticsearch.xpack.sql.expression.Expressions;
@ -26,7 +19,6 @@ import org.elasticsearch.xpack.sql.expression.Literal;
import org.elasticsearch.xpack.sql.expression.NamedExpression;
import org.elasticsearch.xpack.sql.expression.NestedFieldAttribute;
import org.elasticsearch.xpack.sql.expression.Order;
import org.elasticsearch.xpack.sql.expression.BinaryExpression.Negateable;
import org.elasticsearch.xpack.sql.expression.function.Function;
import org.elasticsearch.xpack.sql.expression.function.aggregate.AggregateFunctionAttribute;
import org.elasticsearch.xpack.sql.expression.function.scalar.Cast;
@ -53,11 +45,23 @@ import org.elasticsearch.xpack.sql.rule.RuleExecutor;
import org.elasticsearch.xpack.sql.session.EmptyExecutable;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import static java.util.stream.Collectors.toList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import static java.util.stream.Collectors.toList;
import static org.elasticsearch.xpack.sql.expression.Literal.FALSE;
import static org.elasticsearch.xpack.sql.expression.Literal.TRUE;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.*;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.combineAnd;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.combineOr;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.inCommon;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.splitAnd;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.splitOr;
import static org.elasticsearch.xpack.sql.expression.predicate.Predicates.subtract;
public class Optimizer extends RuleExecutor<LogicalPlan> {
@ -108,10 +112,7 @@ public class Optimizer extends RuleExecutor<LogicalPlan> {
return Arrays.asList(resolution, aggregate, cleanup, label);
}
}
class PruneSubqueryAliases extends OptimizerRule<SubQueryAlias> {
static class PruneSubqueryAliases extends OptimizerRule<SubQueryAlias> {
PruneSubqueryAliases() {
super(false);
@ -121,9 +122,9 @@ class PruneSubqueryAliases extends OptimizerRule<SubQueryAlias> {
protected LogicalPlan rule(SubQueryAlias alias) {
return alias.child();
}
}
}
class CleanAliases extends OptimizerRule<LogicalPlan> {
static class CleanAliases extends OptimizerRule<LogicalPlan> {
CleanAliases() {
super(false);
@ -171,9 +172,9 @@ class CleanAliases extends OptimizerRule<LogicalPlan> {
private Expression trimAliases(Expression e) {
return e.transformDown(Alias::child, Alias.class);
}
}
}
class PruneDuplicatesInGroupBy extends OptimizerRule<Aggregate> {
static class PruneDuplicatesInGroupBy extends OptimizerRule<Aggregate> {
@Override
protected LogicalPlan rule(Aggregate agg) {
@ -187,9 +188,9 @@ class PruneDuplicatesInGroupBy extends OptimizerRule<Aggregate> {
}
return agg;
}
}
}
class ReplaceDuplicateAggsWithReferences extends OptimizerRule<Aggregate> {
static class ReplaceDuplicateAggsWithReferences extends OptimizerRule<Aggregate> {
@Override
protected LogicalPlan rule(Aggregate agg) {
@ -221,9 +222,9 @@ class ReplaceDuplicateAggsWithReferences extends OptimizerRule<Aggregate> {
return agg;
}
}
}
class PruneFilters extends OptimizerRule<Filter> {
static class PruneFilters extends OptimizerRule<Filter> {
@Override
protected LogicalPlan rule(Filter filter) {
@ -239,9 +240,9 @@ class PruneFilters extends OptimizerRule<Filter> {
return filter;
}
}
}
class ReplaceAliasesInHaving extends OptimizerRule<Filter> {
static class ReplaceAliasesInHaving extends OptimizerRule<Filter> {
@Override
protected LogicalPlan rule(Filter filter) {
@ -259,9 +260,9 @@ class ReplaceAliasesInHaving extends OptimizerRule<Filter> {
}
return filter;
}
}
}
class ProjectPruning extends OptimizerRule<Project> {
static class ProjectPruning extends OptimizerRule<Project> {
@Override
protected LogicalPlan rule(Project project) {
@ -278,9 +279,9 @@ class ProjectPruning extends OptimizerRule<Project> {
}
return project;
}
}
}
class PruneOrderByNestedFields extends OptimizerRule<Project> {
static class PruneOrderByNestedFields extends OptimizerRule<Project> {
@Override
protected LogicalPlan rule(Project project) {
@ -346,9 +347,9 @@ class PruneOrderByNestedFields extends OptimizerRule<Project> {
}
return project;
}
}
}
class PruneOrderBy extends OptimizerRule<OrderBy> {
static class PruneOrderBy extends OptimizerRule<OrderBy> {
@Override
protected LogicalPlan rule(OrderBy ob) {
@ -384,9 +385,9 @@ class PruneOrderBy extends OptimizerRule<OrderBy> {
}
return ob;
}
}
}
class CombineLimits extends OptimizerRule<Limit> {
static class CombineLimits extends OptimizerRule<Limit> {
@Override
protected LogicalPlan rule(Limit limit) {
@ -395,10 +396,10 @@ class CombineLimits extends OptimizerRule<Limit> {
}
throw new UnsupportedOperationException("not implemented yet");
}
}
}
// NB: it is important to start replacing casts from the bottom to properly replace aliases
class PruneCast extends Rule<LogicalPlan, LogicalPlan> {
// NB: it is important to start replacing casts from the bottom to properly replace aliases
static class PruneCast extends Rule<LogicalPlan, LogicalPlan> {
@Override
public LogicalPlan apply(LogicalPlan plan) {
@ -469,10 +470,9 @@ class PruneCast extends Rule<LogicalPlan, LogicalPlan> {
}
return transformed;
}
}
}
class PruneDuplicateFunctions extends Rule<LogicalPlan, LogicalPlan> {
static class PruneDuplicateFunctions extends Rule<LogicalPlan, LogicalPlan> {
@Override
public LogicalPlan apply(LogicalPlan p) {
@ -504,9 +504,9 @@ class PruneDuplicateFunctions extends Rule<LogicalPlan, LogicalPlan> {
private boolean functionsEquals(Function f, Function seenFunction) {
return f.name().equals(seenFunction.name()) && f.arguments().equals(seenFunction.arguments());
}
}
}
class SkipQueryOnLimitZero extends OptimizerRule<Limit> {
static class SkipQueryOnLimitZero extends OptimizerRule<Limit> {
@Override
protected LogicalPlan rule(Limit limit) {
@ -517,9 +517,9 @@ class SkipQueryOnLimitZero extends OptimizerRule<Limit> {
}
return limit;
}
}
}
class CombineFilters extends OptimizerRule<Filter> {
static class CombineFilters extends OptimizerRule<Filter> {
@Override
protected LogicalPlan rule(Filter filter) {
@ -529,9 +529,9 @@ class CombineFilters extends OptimizerRule<Filter> {
}
throw new UnsupportedOperationException("not implemented yet");
}
}
}
class BooleanSimplification extends OptimizerExpressionUpRule {
static class BooleanSimplification extends OptimizerExpressionUpRule {
@Override
protected Expression rule(Expression e) {
@ -628,9 +628,9 @@ class BooleanSimplification extends OptimizerExpressionUpRule {
return n;
}
}
}
class BinaryComparisonSimplification extends OptimizerExpressionUpRule {
static class BinaryComparisonSimplification extends OptimizerExpressionUpRule {
@Override
protected Expression rule(Expression e) {
@ -657,9 +657,9 @@ class BinaryComparisonSimplification extends OptimizerExpressionUpRule {
return bc;
}
}
}
class BooleanLiteralsOnTheRight extends OptimizerExpressionUpRule {
static class BooleanLiteralsOnTheRight extends OptimizerExpressionUpRule {
@Override
protected Expression rule(Expression e) {
@ -669,9 +669,9 @@ class BooleanLiteralsOnTheRight extends OptimizerExpressionUpRule {
private Expression literalToTheRight(BinaryExpression be) {
return be.left() instanceof Literal && !(be.right() instanceof Literal) ? be.swapLeftAndRight() : be;
}
}
}
class CombineComparisonsIntoRange extends OptimizerExpressionUpRule {
static class CombineComparisonsIntoRange extends OptimizerExpressionUpRule {
@Override
protected Expression rule(Expression e) {
@ -702,10 +702,10 @@ class CombineComparisonsIntoRange extends OptimizerExpressionUpRule {
return and;
}
}
}
class SetAsOptimized extends Rule<LogicalPlan, LogicalPlan> {
static class SetAsOptimized extends Rule<LogicalPlan, LogicalPlan> {
@Override
public LogicalPlan apply(LogicalPlan plan) {
@ -720,10 +720,10 @@ class SetAsOptimized extends Rule<LogicalPlan, LogicalPlan> {
}
return plan;
}
}
}
abstract class OptimizerRule<SubPlan extends LogicalPlan> extends Rule<SubPlan, LogicalPlan> {
abstract static class OptimizerRule<SubPlan extends LogicalPlan> extends Rule<SubPlan, LogicalPlan> {
private final boolean transformDown;
@ -743,9 +743,9 @@ abstract class OptimizerRule<SubPlan extends LogicalPlan> extends Rule<SubPlan,
@Override
protected abstract LogicalPlan rule(SubPlan plan);
}
}
abstract class OptimizerExpressionUpRule extends Rule<LogicalPlan, LogicalPlan> {
abstract static class OptimizerExpressionUpRule extends Rule<LogicalPlan, LogicalPlan> {
private final boolean transformDown;
@ -770,4 +770,5 @@ abstract class OptimizerExpressionUpRule extends Rule<LogicalPlan, LogicalPlan>
}
protected abstract Expression rule(Expression e);
}
}

View File

@ -13,9 +13,10 @@ import org.antlr.v4.runtime.IntStream;
// extension of ANTLR that does the uppercasing once for the whole stream
// the ugly part is that it has to duplicate LA method
class CaseInsensitiveStream extends ANTLRInputStream {
// NOCOMMIT maybe we can fix this in the lexer or on the way in so we don't need the LA override
protected char[] uppedChars;
public CaseInsensitiveStream(String input) {
CaseInsensitiveStream(String input) {
super(input);
this.uppedChars = input.toUpperCase(Locale.ROOT).toCharArray();
}

View File

@ -1,204 +0,0 @@
T__0=1
T__1=2
T__2=3
T__3=4
T__4=5
SELECT=6
FROM=7
AS=8
ALL=9
WHEN=10
THEN=11
ANY=12
DISTINCT=13
WHERE=14
GROUP=15
BY=16
GROUPING=17
SETS=18
ORDER=19
HAVING=20
LIMIT=21
OR=22
AND=23
IN=24
NOT=25
NO=26
EXISTS=27
BETWEEN=28
LIKE=29
RLIKE=30
IS=31
NULL=32
TRUE=33
FALSE=34
LAST=35
ASC=36
DESC=37
FOR=38
INTEGER=39
JOIN=40
CROSS=41
OUTER=42
INNER=43
LEFT=44
RIGHT=45
FULL=46
NATURAL=47
USING=48
ON=49
WITH=50
TABLE=51
INTO=52
DESCRIBE=53
OPTION=54
EXPLAIN=55
ANALYZE=56
FORMAT=57
TYPE=58
TEXT=59
VERIFY=60
GRAPHVIZ=61
LOGICAL=62
PHYSICAL=63
SHOW=64
TABLES=65
COLUMNS=66
COLUMN=67
FUNCTIONS=68
TO=69
DEBUG=70
PLAN=71
PARSED=72
ANALYZED=73
OPTIMIZED=74
MAPPED=75
EXECUTABLE=76
USE=77
SET=78
RESET=79
SESSION=80
SCHEMAS=81
EXTRACT=82
QUERY=83
MATCH=84
CAST=85
EQ=86
NEQ=87
LT=88
LTE=89
GT=90
GTE=91
PLUS=92
MINUS=93
ASTERISK=94
SLASH=95
PERCENT=96
CONCAT=97
STRING=98
INTEGER_VALUE=99
DECIMAL_VALUE=100
IDENTIFIER=101
DIGIT_IDENTIFIER=102
QUOTED_IDENTIFIER=103
BACKQUOTED_IDENTIFIER=104
SIMPLE_COMMENT=105
BRACKETED_COMMENT=106
WS=107
UNRECOGNIZED=108
'('=1
')'=2
','=3
'.'=4
'"'=5
'SELECT'=6
'FROM'=7
'AS'=8
'ALL'=9
'WHEN'=10
'THEN'=11
'ANY'=12
'DISTINCT'=13
'WHERE'=14
'GROUP'=15
'BY'=16
'GROUPING'=17
'SETS'=18
'ORDER'=19
'HAVING'=20
'LIMIT'=21
'OR'=22
'AND'=23
'IN'=24
'NOT'=25
'NO'=26
'EXISTS'=27
'BETWEEN'=28
'LIKE'=29
'RLIKE'=30
'IS'=31
'NULL'=32
'TRUE'=33
'FALSE'=34
'LAST'=35
'ASC'=36
'DESC'=37
'FOR'=38
'INTEGER'=39
'JOIN'=40
'CROSS'=41
'OUTER'=42
'INNER'=43
'LEFT'=44
'RIGHT'=45
'FULL'=46
'NATURAL'=47
'USING'=48
'ON'=49
'WITH'=50
'TABLE'=51
'INTO'=52
'DESCRIBE'=53
'OPTION'=54
'EXPLAIN'=55
'ANALYZE'=56
'FORMAT'=57
'TYPE'=58
'TEXT'=59
'VERIFY'=60
'GRAPHVIZ'=61
'LOGICAL'=62
'PHYSICAL'=63
'SHOW'=64
'TABLES'=65
'COLUMNS'=66
'COLUMN'=67
'FUNCTIONS'=68
'TO'=69
'DEBUG'=70
'PLAN'=71
'PARSED'=72
'ANALYZED'=73
'OPTIMIZED'=74
'MAPPED'=75
'EXECUTABLE'=76
'USE'=77
'SET'=78
'RESET'=79
'SESSION'=80
'SCHEMAS'=81
'EXTRACT'=82
'QUERY'=83
'MATCH'=84
'CAST'=85
'='=86
'<'=88
'<='=89
'>'=90
'>='=91
'+'=92
'-'=93
'*'=94
'/'=95
'%'=96
'||'=97

View File

@ -42,4 +42,10 @@ abstract class BinaryPlan extends LogicalPlan {
return Objects.equals(left(), other.left())
&& Objects.equals(right(), other.right());
}
@Override
public int hashCode() {
return Objects.hash(left, right);
}
}

View File

@ -22,11 +22,12 @@ public class Join extends BinaryPlan {
private final JoinType type;
private final Expression condition;
public static enum JoinType {
INNER, LEFT // OUTER
, RIGHT // OUTER
, FULL // OUTER
, IMPLICIT
public enum JoinType {
INNER,
LEFT, // OUTER
RIGHT, // OUTER
FULL, // OUTER
IMPLICIT,
}
public Join(Location location, LogicalPlan left, LogicalPlan right, JoinType type, Expression condition) {

View File

@ -10,8 +10,7 @@ import java.util.Collections;
import org.elasticsearch.xpack.sql.tree.Location;
abstract class LeafExec extends PhysicalPlan {
public LeafExec(Location location) {
LeafExec(Location location) {
super(location, Collections.emptyList());
}
}

View File

@ -124,9 +124,8 @@ class Mapper extends RuleExecutor<PhysicalPlan> {
throw new UnsupportedOperationException("Don't know how to handle join " + join.nodeString());
}
}
}
abstract class MapExecRule<SubPlan extends LogicalPlan> extends Rule<UnplannedExec, PhysicalPlan> {
abstract static class MapExecRule<SubPlan extends LogicalPlan> extends Rule<UnplannedExec, PhysicalPlan> {
private final Class<SubPlan> subPlanToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass());
@ -146,4 +145,5 @@ abstract class MapExecRule<SubPlan extends LogicalPlan> extends Rule<UnplannedEx
}
protected abstract PhysicalPlan map(SubPlan plan);
}
}

View File

@ -470,10 +470,11 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
return exec.with(qContainer);
}
}
}
// rule for folding physical plans together
abstract class FoldingRule<SubPlan extends PhysicalPlan> extends Rule<SubPlan, PhysicalPlan> {
/**
* Rule for folding physical plans together.
*/
abstract static class FoldingRule<SubPlan extends PhysicalPlan> extends Rule<SubPlan, PhysicalPlan> {
@Override
public final PhysicalPlan apply(PhysicalPlan plan) {
@ -482,4 +483,6 @@ abstract class FoldingRule<SubPlan extends PhysicalPlan> extends Rule<SubPlan, P
@Override
protected abstract PhysicalPlan rule(SubPlan plan);
}
}

View File

@ -5,14 +5,6 @@
*/
package org.elasticsearch.xpack.sql.planner;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.BinaryExpression;
@ -51,7 +43,6 @@ import org.elasticsearch.xpack.sql.expression.predicate.fulltext.MultiMatchQuery
import org.elasticsearch.xpack.sql.expression.predicate.fulltext.StringQueryPredicate;
import org.elasticsearch.xpack.sql.expression.regex.Like;
import org.elasticsearch.xpack.sql.expression.regex.RLike;
import org.elasticsearch.xpack.sql.planner.QueryTranslator.QueryTranslation;
import org.elasticsearch.xpack.sql.querydsl.agg.Agg;
import org.elasticsearch.xpack.sql.querydsl.agg.AggFilter;
import org.elasticsearch.xpack.sql.querydsl.agg.AndAggFilter;
@ -83,12 +74,18 @@ import org.elasticsearch.xpack.sql.type.DataTypes;
import org.elasticsearch.xpack.sql.util.Assert;
import org.elasticsearch.xpack.sql.util.ReflectionUtils;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import static java.lang.String.format;
import static java.util.stream.Collectors.toList;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder.paramsBuilder;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate;
import static org.elasticsearch.xpack.sql.planner.QueryTranslator.*;
abstract class QueryTranslator {
@ -399,12 +396,10 @@ abstract class QueryTranslator {
}
throw new SqlIllegalArgumentException("Does not know how to convert argument %s for functon %s", arg.nodeString(), af.nodeString());
}
}
// TODO: need to optimize on ngram
// TODO: see whether escaping is needed
class Likes extends ExppressionTranslator<BinaryExpression> {
// TODO: need to optimize on ngram
// TODO: see whether escaping is needed
static class Likes extends ExppressionTranslator<BinaryExpression> {
@Override
protected QueryTranslation asQuery(BinaryExpression e, boolean onAggs) {
@ -447,33 +442,33 @@ class Likes extends ExppressionTranslator<BinaryExpression> {
private static boolean hasMatchingPattern(String pattern) {
return pattern.contains("*") || pattern.contains("?");
}
}
}
class StringQueries extends ExppressionTranslator<StringQueryPredicate> {
static class StringQueries extends ExppressionTranslator<StringQueryPredicate> {
@Override
protected QueryTranslation asQuery(StringQueryPredicate q, boolean onAggs) {
return new QueryTranslation(new QueryStringQuery(q.location(), q.query(), q.fields(), q));
}
}
}
class Matches extends ExppressionTranslator<MatchQueryPredicate> {
static class Matches extends ExppressionTranslator<MatchQueryPredicate> {
@Override
protected QueryTranslation asQuery(MatchQueryPredicate q, boolean onAggs) {
return new QueryTranslation(wrapIfNested(new MatchQuery(q.location(), nameOf(q.field()), q.query(), q), q.field()));
}
}
}
class MultiMatches extends ExppressionTranslator<MultiMatchQueryPredicate> {
static class MultiMatches extends ExppressionTranslator<MultiMatchQueryPredicate> {
@Override
protected QueryTranslation asQuery(MultiMatchQueryPredicate q, boolean onAggs) {
return new QueryTranslation(new MultiMatchQuery(q.location(), q.query(), q.fields(), q));
}
}
}
class BinaryLogic extends ExppressionTranslator<BinaryExpression> {
static class BinaryLogic extends ExppressionTranslator<BinaryExpression> {
@Override
protected QueryTranslation asQuery(BinaryExpression e, boolean onAggs) {
@ -486,19 +481,19 @@ class BinaryLogic extends ExppressionTranslator<BinaryExpression> {
return null;
}
}
}
class Nots extends ExppressionTranslator<Not> {
static class Nots extends ExppressionTranslator<Not> {
@Override
protected QueryTranslation asQuery(Not not, boolean onAggs) {
QueryTranslation translation = toQuery(not.child(), onAggs);
return new QueryTranslation(not(translation.query), translation.aggFilter);
}
}
}
// assume the Optimizer properly orders the predicates to ease the translation
class BinaryComparisons extends ExppressionTranslator<BinaryComparison> {
// assume the Optimizer properly orders the predicates to ease the translation
static class BinaryComparisons extends ExppressionTranslator<BinaryComparison> {
@Override
protected QueryTranslation asQuery(BinaryComparison bc, boolean onAggs) {
@ -600,9 +595,9 @@ class BinaryComparisons extends ExppressionTranslator<BinaryComparison> {
Assert.isTrue(false, "don't know how to translate binary comparison %s in %s", bc.right().nodeString(), bc);
return null;
}
}
}
class Ranges extends ExppressionTranslator<Range> {
static class Ranges extends ExppressionTranslator<Range> {
@Override
protected QueryTranslation asQuery(Range r, boolean onAggs) {
@ -693,14 +688,14 @@ class Ranges extends ExppressionTranslator<Range> {
}
}
}
}
//
// Agg translators
//
//
// Agg translators
//
class DistinctCounts extends SingleValueAggTranslator<Count> {
static class DistinctCounts extends SingleValueAggTranslator<Count> {
@Override
protected LeafAgg toAgg(String id, String path, Count c) {
@ -709,49 +704,49 @@ class DistinctCounts extends SingleValueAggTranslator<Count> {
}
return new CardinalityAgg(id, path, field(c));
}
}
}
class Sums extends SingleValueAggTranslator<Sum> {
static class Sums extends SingleValueAggTranslator<Sum> {
@Override
protected LeafAgg toAgg(String id, String path, Sum s) {
return new SumAgg(id, path, field(s));
}
}
}
class Avgs extends SingleValueAggTranslator<Avg> {
static class Avgs extends SingleValueAggTranslator<Avg> {
@Override
protected LeafAgg toAgg(String id, String path, Avg a) {
return new AvgAgg(id, path, field(a));
}
}
}
class Maxes extends SingleValueAggTranslator<Max> {
static class Maxes extends SingleValueAggTranslator<Max> {
@Override
protected LeafAgg toAgg(String id, String path, Max m) {
return new MaxAgg(id, path, field(m));
}
}
}
class Mins extends SingleValueAggTranslator<Min> {
static class Mins extends SingleValueAggTranslator<Min> {
@Override
protected LeafAgg toAgg(String id, String path, Min m) {
return new MinAgg(id, path, field(m));
}
}
}
class DateTimes extends SingleValueAggTranslator<Min> {
static class DateTimes extends SingleValueAggTranslator<Min> {
@Override
protected LeafAgg toAgg(String id, String path, Min m) {
return new MinAgg(id, path, field(m));
}
}
}
abstract class SingleValueAggTranslator<F extends Function> extends AggTranslator<F> {
abstract static class SingleValueAggTranslator<F extends Function> extends AggTranslator<F> {
@Override
protected final LeafAgg asAgg(String id, String parent, F f) {
@ -760,9 +755,9 @@ abstract class SingleValueAggTranslator<F extends Function> extends AggTranslato
}
protected abstract LeafAgg toAgg(String id, String path, F f);
}
}
abstract class AggTranslator<F extends Function> {
abstract static class AggTranslator<F extends Function> {
private final Class<F> typeToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass());
@ -772,9 +767,9 @@ abstract class AggTranslator<F extends Function> {
}
protected abstract LeafAgg asAgg(String id, String parent, F f);
}
}
abstract class ExppressionTranslator<E extends Expression> {
abstract static class ExppressionTranslator<E extends Expression> {
private final Class<E> typeToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass());
@ -792,4 +787,5 @@ abstract class ExppressionTranslator<E extends Expression> {
}
return query;
}
}
}

View File

@ -20,7 +20,7 @@ abstract class Verifier {
private final Node<?> source;
private final String message;
public Failure(Node<?> source, String message) {
Failure(Node<?> source, String message) {
this.source = source;
this.message = message + " " + source.nodeString();
}

View File

@ -9,7 +9,7 @@ import org.elasticsearch.xpack.sql.type.Schema;
class EmptyRowSetCursor extends AbstractRowSetCursor {
public EmptyRowSetCursor(Schema schema) {
EmptyRowSetCursor(Schema schema) {
super(schema, null);
}

View File

@ -20,7 +20,7 @@ import static java.util.Collections.emptyList;
public class Schema implements Iterable<Entry> {
public static interface Entry {
public interface Entry {
String name();
DataType type();
}