From 16ea84defe50d95877e9493daa8c69da007f1d20 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Fri, 30 Jun 2017 20:55:28 +0300 Subject: [PATCH] Fix some checkstyles Original commit: elastic/x-pack-elasticsearch@ff1c6a6e70650ddbd962b59e1353422ff950ac49 --- .../xpack/sql/execution/search/Scroller.java | 105 +++++++++--------- .../expression/UnresolvedNamedExpression.java | 4 +- .../predicate/fulltext/FullTextPredicate.java | 8 +- .../xpack/sql/planner/QueryFolder.java | 25 ++--- .../xpack/sql/planner/QueryTranslator.java | 29 ++--- 5 files changed, 85 insertions(+), 86 deletions(-) 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 137e73c3870..06a4c433faf 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 @@ -88,37 +88,36 @@ public class Scroller { previous.client.searchScroll(new SearchScrollRequest(scrollId).scroll(previous.keepAlive), l); } - // dedicated scroll used for aggs-only/group-by results static class AggsScrollActionListener extends ScrollerActionListener { - + private final QueryContainer query; - + AggsScrollActionListener(ActionListener listener, Client client, TimeValue keepAlive, Schema schema, QueryContainer query) { super(listener, client, keepAlive, schema); this.query = query; } - + @Override protected RowSetCursor handleResponse(SearchResponse response) { Aggregations aggs = response.getAggregations(); - + List columns = new ArrayList<>(); - + // this method assumes the nested aggregation are all part of the same tree (the SQL group-by) int maxDepth = -1; - + for (Reference ref : query.refs()) { Object[] arr = null; - + ColumnProcessor processor = null; - + if (ref instanceof ProcessingRef) { ProcessingRef pRef = (ProcessingRef) ref; processor = pRef.processor(); ref = pRef.ref(); } - + if (ref == TotalCountRef.INSTANCE) { arr = new Object[] { processIfNeeded(processor, Long.valueOf(response.getHits().getTotalHits())) }; columns.add(arr); @@ -131,13 +130,13 @@ public class Scroller { path = AggPath.bucketValueWithoutFormat(path); } Object value = getAggProperty(aggs, path); - + // // FIXME: this can be tabular in nature // if (ref instanceof MappedAggRef) { // Map map = (Map) value; // Object extractedValue = map.get(((MappedAggRef) ref).fieldName()); // } - + if (formattedKey) { List buckets = ((MultiBucketsAggregation) value).getBuckets(); arr = new Object[buckets.size()]; @@ -148,7 +147,7 @@ public class Scroller { else { arr = value instanceof Object[] ? (Object[]) value : new Object[] { value }; } - + // process if needed for (int i = 0; i < arr.length; i++) { arr[i] = processIfNeeded(processor, arr[i]); @@ -159,16 +158,16 @@ public class Scroller { else { throw new SqlIllegalArgumentException("Unexpected non-agg/grouped column specified; %s", ref.getClass()); } - + if (ref.depth() > maxDepth) { maxDepth = ref.depth(); } } - + clearScroll(response.getScrollId()); return new AggsRowSetCursor(schema, columns, maxDepth, query.limit()); } - + private static Object getAggProperty(Aggregations aggs, String path) { List list = AggregationPath.parse(path).getPathElementsAsStringList(); String aggName = list.get(0); @@ -178,103 +177,103 @@ public class Scroller { } return agg.getProperty(list.subList(1, list.size())); } - + private Object processIfNeeded(ColumnProcessor processor, Object value) { return processor != null ? processor.apply(value) : value; } } - + // initial scroll used for parsing search hits (handles possible aggs) - class HandshakeScrollActionListener extends SearchHitsActionListener { - + static class HandshakeScrollActionListener extends SearchHitsActionListener { + private final QueryContainer query; - + HandshakeScrollActionListener(ActionListener listener, Client client, TimeValue keepAlive, Schema schema, QueryContainer query) { super(listener, client, keepAlive, schema, query.limit(), 0); this.query = query; } - + @Override public void onResponse(SearchResponse response) { super.onResponse(response); } - + @Override protected List getExtractors() { // create response extractors for the first time List refs = query.refs(); - + List exts = new ArrayList<>(refs.size()); - + for (Reference ref : refs) { exts.add(createExtractor(ref)); } return exts; } - + private HitExtractor createExtractor(Reference ref) { if (ref instanceof SearchHitFieldRef) { SearchHitFieldRef f = (SearchHitFieldRef) ref; return f.useDocValue() ? new DocValueExtractor(f.name()) : new SourceExtractor(f.name()); } - + if (ref instanceof NestedFieldRef) { NestedFieldRef f = (NestedFieldRef) ref; return new InnerHitExtractor(f.parent(), f.name(), f.useDocValue()); } - + if (ref instanceof ScriptFieldRef) { ScriptFieldRef f = (ScriptFieldRef) ref; return new DocValueExtractor(f.name()); } - + if (ref instanceof ProcessingRef) { ProcessingRef pRef = (ProcessingRef) ref; return new ProcessingHitExtractor(createExtractor(pRef.ref()), pRef.processor()); } - + throw new SqlIllegalArgumentException("Unexpected ValueReference %s", ref.getClass()); } } - + // listener used for streaming the rest of the results after the handshake has been used static class SessionScrollActionListener extends SearchHitsActionListener { - + private List exts; - + SessionScrollActionListener(ActionListener listener, Client client, TimeValue keepAlive, Schema schema, List ext, int limit, int docCount) { super(listener, client, keepAlive, schema, limit, docCount); this.exts = ext; } - + @Override protected List getExtractors() { return exts; } } - + abstract static class SearchHitsActionListener extends ScrollerActionListener { - + final int limit; int docsRead; - + SearchHitsActionListener(ActionListener listener, Client client, TimeValue keepAlive, Schema schema, int limit, int docsRead) { super(listener, client, keepAlive, schema); this.limit = limit; this.docsRead = docsRead; } - + protected RowSetCursor handleResponse(SearchResponse response) { SearchHit[] hits = response.getHits().getHits(); List exts = getExtractors(); - + // there are some results if (hits.length > 0) { String scrollId = response.getScrollId(); Consumer> next = null; - + docsRead += hits.length; - + // if there's an id, try to setup next scroll if (scrollId != null) { // is all the content already retrieved? @@ -300,7 +299,7 @@ public class Scroller { return needsHit(exts) ? Rows.empty(schema) : new SearchHitRowSetCursor(schema, exts); } } - + private static boolean needsHit(List exts) { for (HitExtractor ext : exts) { if (ext instanceof DocValueExtractor || ext instanceof ProcessingHitExtractor) { @@ -309,26 +308,26 @@ public class Scroller { } return false; } - + protected abstract List getExtractors(); } - + abstract static class ScrollerActionListener implements ActionListener { - + final ActionListener listener; - + final Client client; final TimeValue keepAlive; final Schema schema; - + ScrollerActionListener(ActionListener listener, Client client, TimeValue keepAlive, Schema schema) { this.listener = listener; - + this.client = client; this.keepAlive = keepAlive; this.schema = schema; } - + // TODO: need to handle rejections plus check failures (shard size, etc...) @Override public void onResponse(final SearchResponse response) { @@ -342,19 +341,19 @@ public class Scroller { onFailure(ex); } } - + protected abstract RowSetCursor handleResponse(SearchResponse response); - + protected final void clearScroll(String scrollId) { if (scrollId != null) { // fire and forget client.prepareClearScroll().addScrollId(scrollId).execute(); } } - + @Override public final void onFailure(Exception ex) { listener.onFailure(ex); } } -} +} \ No newline at end of file diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/UnresolvedNamedExpression.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/UnresolvedNamedExpression.java index 35ab2c0b389..1c56f87bb3e 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/UnresolvedNamedExpression.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/UnresolvedNamedExpression.java @@ -5,13 +5,13 @@ */ package org.elasticsearch.xpack.sql.expression; -import java.util.List; - import org.elasticsearch.xpack.sql.capabilities.Unresolvable; import org.elasticsearch.xpack.sql.capabilities.UnresolvedException; import org.elasticsearch.xpack.sql.tree.Location; import org.elasticsearch.xpack.sql.type.DataType; +import java.util.List; + abstract class UnresolvedNamedExpression extends NamedExpression implements Unresolvable { UnresolvedNamedExpression(Location location, List children) { diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/fulltext/FullTextPredicate.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/fulltext/FullTextPredicate.java index 7a9f63bdbbf..05cfbce4c2f 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/fulltext/FullTextPredicate.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/predicate/fulltext/FullTextPredicate.java @@ -5,15 +5,15 @@ */ package org.elasticsearch.xpack.sql.expression.predicate.fulltext; -import java.util.List; -import java.util.Map; -import java.util.Objects; - import org.elasticsearch.xpack.sql.expression.Expression; import org.elasticsearch.xpack.sql.tree.Location; import org.elasticsearch.xpack.sql.type.DataType; import org.elasticsearch.xpack.sql.type.DataTypes; +import java.util.List; +import java.util.Map; +import java.util.Objects; + public class FullTextPredicate extends Expression { public enum Operator { diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java index c31f9d475d7..186d2b924d9 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryFolder.java @@ -5,11 +5,6 @@ */ package org.elasticsearch.xpack.sql.planner; -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; import org.elasticsearch.xpack.sql.expression.Alias; import org.elasticsearch.xpack.sql.expression.Attribute; @@ -53,8 +48,12 @@ import org.elasticsearch.xpack.sql.rule.RuleExecutor; import org.elasticsearch.xpack.sql.session.EmptyExecutable; import org.elasticsearch.xpack.sql.util.StringUtils; -import static java.util.Collections.emptyMap; +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import static java.util.Collections.emptyMap; import static org.elasticsearch.xpack.sql.planner.QueryTranslator.and; import static org.elasticsearch.xpack.sql.planner.QueryTranslator.toAgg; import static org.elasticsearch.xpack.sql.planner.QueryTranslator.toQuery; @@ -83,7 +82,7 @@ class QueryFolder extends RuleExecutor { return Arrays.asList(rollup, finish); } - private class FoldProject extends FoldingRule { + private static class FoldProject extends FoldingRule { @Override protected PhysicalPlan rule(ProjectExec project) { @@ -141,7 +140,7 @@ class QueryFolder extends RuleExecutor { } } - private class FoldFilter extends FoldingRule { + private static class FoldFilter extends FoldingRule { @Override protected PhysicalPlan rule(FilterExec plan) { @@ -214,7 +213,7 @@ class QueryFolder extends RuleExecutor { } } - private class FoldAggregate extends FoldingRule { + private static class FoldAggregate extends FoldingRule { @Override protected PhysicalPlan rule(AggregateExec a) { @@ -380,7 +379,7 @@ class QueryFolder extends RuleExecutor { } } - private class FoldOrderBy extends FoldingRule { + private static class FoldOrderBy extends FoldingRule { @Override protected PhysicalPlan rule(OrderExec plan) { @@ -444,7 +443,7 @@ class QueryFolder extends RuleExecutor { } - private class FoldLimit extends FoldingRule { + private static class FoldLimit extends FoldingRule { @Override protected PhysicalPlan rule(LimitExec plan) { @@ -459,7 +458,7 @@ class QueryFolder extends RuleExecutor { } } - private class FoldQueryless extends FoldingRule { + private static class FoldQueryless extends FoldingRule { @Override protected PhysicalPlan rule(PhysicalPlan plan) { @@ -470,7 +469,7 @@ class QueryFolder extends RuleExecutor { } } - private class PlanOutputToQueryRef extends FoldingRule { + private static class PlanOutputToQueryRef extends FoldingRule { @Override protected PhysicalPlan rule(EsQueryExec exec) { QueryContainer qContainer = exec.queryContainer(); diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java index 7b246915090..ee2f96395a1 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/planner/QueryTranslator.java @@ -257,7 +257,7 @@ abstract class QueryTranslator { // dates are handled differently because of date histograms if (exp instanceof DateTimeFunction) { DateTimeFunction dtf = (DateTimeFunction) exp; - agg = new GroupByDateAgg(aggId, AggPath.bucketValue(propertyPath), nameOf(exp), dtf.interval(), dtf.timeZone()); + agg = new GroupByDateAgg(aggId, AggPath.bucketValue(propertyPath), nameOf(exp), dtf.interval()); } else { agg = new GroupByColumnAgg(aggId, AggPath.bucketValue(propertyPath), ne.name()); @@ -697,7 +697,7 @@ abstract class QueryTranslator { // // Agg translators // - + static class DistinctCounts extends SingleValueAggTranslator { @Override @@ -708,7 +708,7 @@ abstract class QueryTranslator { return new CardinalityAgg(id, path, field(c)); } } - + static class Sums extends SingleValueAggTranslator { @Override @@ -716,7 +716,7 @@ abstract class QueryTranslator { return new SumAgg(id, path, field(s)); } } - + static class Avgs extends SingleValueAggTranslator { @Override @@ -724,7 +724,7 @@ abstract class QueryTranslator { return new AvgAgg(id, path, field(a)); } } - + static class Maxes extends SingleValueAggTranslator { @Override @@ -732,7 +732,7 @@ abstract class QueryTranslator { return new MaxAgg(id, path, field(m)); } } - + static class Mins extends SingleValueAggTranslator { @Override @@ -740,7 +740,7 @@ abstract class QueryTranslator { return new MinAgg(id, path, field(m)); } } - + static class StatsAggs extends CompoundAggTranslator { @Override @@ -748,7 +748,7 @@ abstract class QueryTranslator { return new StatsAgg(id, path, field(s)); } } - + static class ExtendedStatsAggs extends CompoundAggTranslator { @Override @@ -756,7 +756,7 @@ abstract class QueryTranslator { return new ExtendedStatsAgg(id, path, field(e)); } } - + static class MatrixStatsAggs extends CompoundAggTranslator { @Override @@ -764,7 +764,7 @@ abstract class QueryTranslator { return new MatrixStatsAgg(id, path, singletonList(field(m))); } } - + static class DateTimes extends SingleValueAggTranslator { @Override @@ -772,7 +772,7 @@ abstract class QueryTranslator { return new MinAgg(id, path, field(m)); } } - + abstract static class AggTranslator { private final Class typeToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass()); @@ -784,7 +784,7 @@ abstract class QueryTranslator { protected abstract LeafAgg asAgg(String id, String parent, F f); } - + abstract static class SingleValueAggTranslator extends AggTranslator { @Override @@ -795,7 +795,7 @@ abstract class QueryTranslator { protected abstract LeafAgg toAgg(String id, String path, F f); } - + abstract static class CompoundAggTranslator extends AggTranslator { @Override @@ -806,7 +806,8 @@ abstract class QueryTranslator { protected abstract LeafAgg toAgg(String id, String path, C f); } - + + abstract static class ExppressionTranslator { private final Class typeToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass());