From c4474f8574c224a29e5736e531b733c75c02619c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Sun, 14 Jan 2018 10:32:31 -0500 Subject: [PATCH] SQL: Remove empty interface (elastic/x-pack-elasticsearch#3564) After some recent changes this interface is now empty. Original commit: elastic/x-pack-elasticsearch@4a44812f7899d52d7efd9ceeef6c3f5ce571d821 --- .../xpack/sql/execution/search/Scroller.java | 13 ++++---- .../definition/ProcessorDefinition.java | 5 ++- .../processor/definition/ReferenceInput.java | 6 ++-- .../xpack/sql/querydsl/container/AggRef.java | 3 +- .../querydsl/container/ColumnReference.java | 17 ---------- .../sql/querydsl/container/ComputedRef.java | 3 +- .../querydsl/container/FieldReference.java | 4 ++- .../querydsl/container/QueryContainer.java | 33 ++++++++++--------- .../definition/AttributeInputTests.java | 4 +-- 9 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ColumnReference.java diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java index f874e02d899..fceb322522a 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/execution/search/Scroller.java @@ -36,7 +36,6 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definiti import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor; import org.elasticsearch.xpack.sql.querydsl.agg.AggPath; import org.elasticsearch.xpack.sql.querydsl.container.AggRef; -import org.elasticsearch.xpack.sql.querydsl.container.ColumnReference; import org.elasticsearch.xpack.sql.querydsl.container.ComputedRef; import org.elasticsearch.xpack.sql.querydsl.container.QueryContainer; import org.elasticsearch.xpack.sql.querydsl.container.ScriptFieldRef; @@ -115,9 +114,9 @@ public class Scroller { // this method assumes the nested aggregation are all part of the same tree (the SQL group-by) int maxDepth = -1; - List cols = query.columns(); + List cols = query.columns(); for (int index = 0; index < cols.size(); index++) { - ColumnReference col = cols.get(index); + FieldExtraction col = cols.get(index); Supplier supplier = null; if (col instanceof ComputedRef) { @@ -157,7 +156,7 @@ public class Scroller { listener::onFailure)); } - private Object[] extractAggValue(ColumnReference col, SearchResponse response) { + private Object[] extractAggValue(FieldExtraction col, SearchResponse response) { if (col == TotalCountRef.INSTANCE) { return new Object[] { Long.valueOf(response.getHits().getTotalHits()) }; } @@ -254,17 +253,17 @@ public class Scroller { private List getExtractors() { // create response extractors for the first time - List refs = query.columns(); + List refs = query.columns(); List exts = new ArrayList<>(refs.size()); - for (ColumnReference ref : refs) { + for (FieldExtraction ref : refs) { exts.add(createExtractor(ref)); } return exts; } - private HitExtractor createExtractor(ColumnReference ref) { + private HitExtractor createExtractor(FieldExtraction ref) { if (ref instanceof SearchHitFieldRef) { SearchHitFieldRef f = (SearchHitFieldRef) ref; return new FieldHitExtractor(f.name(), f.useDocValue(), f.hitName()); diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ProcessorDefinition.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ProcessorDefinition.java index 36c04de23cf..5da2fa81b48 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ProcessorDefinition.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ProcessorDefinition.java @@ -9,7 +9,6 @@ import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.expression.Attribute; import org.elasticsearch.xpack.sql.expression.Expression; import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor; -import org.elasticsearch.xpack.sql.querydsl.container.ColumnReference; import org.elasticsearch.xpack.sql.tree.Node; import java.util.List; @@ -33,13 +32,13 @@ public abstract class ProcessorDefinition extends Node impl /** * Resolve {@link Attribute}s which are unprocessable into - * {@link ColumnReference}s which are processable. + * {@link FieldExtraction}s which are processable. * * @return {@code this} if the resolution doesn't change the * definition, a new {@link ProcessorDefinition} otherwise */ public abstract ProcessorDefinition resolveAttributes(AttributeResolver resolver); public interface AttributeResolver { - ColumnReference resolve(Attribute attribute); + FieldExtraction resolve(Attribute attribute); } } diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ReferenceInput.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ReferenceInput.java index b9dc98de335..4efc31f9310 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ReferenceInput.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/ReferenceInput.java @@ -5,12 +5,12 @@ */ package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition; +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder; import org.elasticsearch.xpack.sql.expression.Expression; -import org.elasticsearch.xpack.sql.querydsl.container.ColumnReference; -public class ReferenceInput extends NonExecutableInput { - public ReferenceInput(Expression expression, ColumnReference context) { +public class ReferenceInput extends NonExecutableInput { + public ReferenceInput(Expression expression, FieldExtraction context) { super(expression, context); } diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/AggRef.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/AggRef.java index 8107b2e4efe..973f45d859d 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/AggRef.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/AggRef.java @@ -5,10 +5,11 @@ */ package org.elasticsearch.xpack.sql.querydsl.container; +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder; import org.elasticsearch.xpack.sql.querydsl.agg.AggPath; -public class AggRef implements ColumnReference { +public class AggRef implements FieldExtraction { private final String path; private final int depth; diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ColumnReference.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ColumnReference.java deleted file mode 100644 index 4407679b7c5..00000000000 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ColumnReference.java +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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.sql.querydsl.container; - -import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; - -/** - * Entity representing a 'column' backed by one or multiple results from ES. A - * column reference can also extract a field (meta or otherwise) from a result - * set, so extends {@link FieldExtraction}. - */ -public interface ColumnReference extends FieldExtraction { - // TODO remove this interface intirely in a followup -} diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ComputedRef.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ComputedRef.java index 169f7a9db17..5da34115008 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ComputedRef.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/ComputedRef.java @@ -5,10 +5,11 @@ */ package org.elasticsearch.xpack.sql.querydsl.container; +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder; import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinition; -public class ComputedRef implements ColumnReference { +public class ComputedRef implements FieldExtraction { private final ProcessorDefinition processor; diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/FieldReference.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/FieldReference.java index 14a39b6ad1e..07e6038128c 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/FieldReference.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/FieldReference.java @@ -5,7 +5,9 @@ */ package org.elasticsearch.xpack.sql.querydsl.container; -public abstract class FieldReference implements ColumnReference { +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; + +public abstract class FieldReference implements FieldExtraction { /** * Field name. * diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java index 5dc0d6358bb..0ee0e2f5e3d 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/querydsl/container/QueryContainer.java @@ -11,6 +11,7 @@ import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.execution.search.SourceGenerator; import org.elasticsearch.xpack.sql.expression.Attribute; import org.elasticsearch.xpack.sql.expression.FieldAttribute; @@ -55,7 +56,7 @@ public class QueryContainer { // final output seen by the client (hence the list or ordering) // gets converted by the Scroller into Extractors for hits or actual results in case of aggregations - private final List columns; + private final List columns; // aliases (maps an alias to its actual resolved attribute) private final Map aliases; @@ -78,7 +79,7 @@ public class QueryContainer { this(null, null, null, null, null, null, null, -1); } - public QueryContainer(Query query, Aggs aggs, List refs, Map aliases, + public QueryContainer(Query query, Aggs aggs, List refs, Map aliases, Map pseudoFunctions, Map scalarFunctions, Set sort, int limit) { @@ -90,8 +91,8 @@ public class QueryContainer { this.columns = refs == null || refs.isEmpty() ? emptyList() : refs; this.sort = sort == null || sort.isEmpty() ? emptySet() : sort; this.limit = limit; - aggsOnly = columns.stream().allMatch(ColumnReference::supportedByAggsOnlyQuery); - aggDepth = columns.stream().mapToInt(ColumnReference::depth).max().orElse(0); + aggsOnly = columns.stream().allMatch(FieldExtraction::supportedByAggsOnlyQuery); + aggDepth = columns.stream().mapToInt(FieldExtraction::depth).max().orElse(0); } public Query query() { @@ -102,7 +103,7 @@ public class QueryContainer { return aggs; } - public List columns() { + public List columns() { return columns; } @@ -142,7 +143,7 @@ public class QueryContainer { return new QueryContainer(q, aggs, columns, aliases, pseudoFunctions, scalarFunctions, sort, limit); } - public QueryContainer with(List r) { + public QueryContainer with(List r) { return new QueryContainer(query, aggs, r, aliases, pseudoFunctions, scalarFunctions, sort, limit); } @@ -179,13 +180,13 @@ public class QueryContainer { // // reference methods // - private ColumnReference searchHitFieldRef(FieldAttribute fieldAttr) { + private FieldExtraction searchHitFieldRef(FieldAttribute fieldAttr) { return new SearchHitFieldRef(aliasName(fieldAttr), fieldAttr.dataType().hasDocValues()); } - private Tuple nestedFieldRef(FieldAttribute attr) { + private Tuple nestedFieldRef(FieldAttribute attr) { // Find the nested query for this field. If there isn't one then create it - List nestedRefs = new ArrayList<>(); + List nestedRefs = new ArrayList<>(); Query q = rewriteToContainNestedField(query, attr.location(), attr.nestedParent().path(), aliasName(attr), attr.dataType().hasDocValues()); @@ -221,7 +222,7 @@ public class QueryContainer { } // replace function's input with references - private Tuple computingRef(ScalarFunctionAttribute sfa) { + private Tuple computingRef(ScalarFunctionAttribute sfa) { Attribute name = aliases.getOrDefault(sfa, sfa); ProcessorDefinition proc = scalarFunctions.get(name); @@ -243,9 +244,9 @@ public class QueryContainer { } @Override - public ColumnReference resolve(Attribute attribute) { + public FieldExtraction resolve(Attribute attribute) { Attribute attr = aliases.getOrDefault(attribute, attribute); - Tuple ref = container.toReference(attr); + Tuple ref = container.toReference(attr); container = ref.v1(); return ref.v2(); } @@ -262,11 +263,11 @@ public class QueryContainer { } public QueryContainer addColumn(Attribute attr) { - Tuple tuple = toReference(attr); + Tuple tuple = toReference(attr); return tuple.v1().addColumn(tuple.v2()); } - private Tuple toReference(Attribute attr) { + private Tuple toReference(Attribute attr) { if (attr instanceof FieldAttribute) { FieldAttribute fa = (FieldAttribute) attr; if (fa.isNested()) { @@ -288,7 +289,7 @@ public class QueryContainer { throw new SqlIllegalArgumentException("Unknown output attribute %s", attr); } - public QueryContainer addColumn(ColumnReference ref) { + public QueryContainer addColumn(FieldExtraction ref) { return with(combine(columns, ref)); } @@ -304,7 +305,7 @@ public class QueryContainer { } public QueryContainer addAggCount(GroupingAgg parentGroup, String functionId) { - ColumnReference ref = parentGroup == null ? TotalCountRef.INSTANCE : new AggRef(AggPath.bucketCount(parentGroup.asParentPath())); + FieldExtraction ref = parentGroup == null ? TotalCountRef.INSTANCE : new AggRef(AggPath.bucketCount(parentGroup.asParentPath())); Map pseudoFunctions = new LinkedHashMap<>(this.pseudoFunctions); pseudoFunctions.put(functionId, parentGroup); return new QueryContainer(query, aggs, combine(columns, ref), aliases, pseudoFunctions, scalarFunctions, sort, limit); diff --git a/sql/server/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/AttributeInputTests.java b/sql/server/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/AttributeInputTests.java index 5c4a6dd967e..55c8a5625cd 100644 --- a/sql/server/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/AttributeInputTests.java +++ b/sql/server/src/test/java/org/elasticsearch/xpack/sql/expression/function/scalar/processor/definition/AttributeInputTests.java @@ -6,15 +6,15 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.sql.execution.search.FieldExtraction; import org.elasticsearch.xpack.sql.expression.Attribute; import org.elasticsearch.xpack.sql.expression.Expression; -import org.elasticsearch.xpack.sql.querydsl.container.ColumnReference; import static org.mockito.Mockito.mock; public class AttributeInputTests extends ESTestCase { public void testResolveAttributes() { - ColumnReference column = mock(ColumnReference.class); + FieldExtraction column = mock(FieldExtraction.class); Expression expression = mock(Expression.class); Attribute attribute = mock(Attribute.class);