Fix some checkstyles
Original commit: elastic/x-pack-elasticsearch@ff1c6a6e70
This commit is contained in:
parent
4bb605d819
commit
16ea84defe
|
@ -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<RowSetCursor> 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<Object[]> 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<String, Object> map = (Map<String, Object>) value;
|
||||
// Object extractedValue = map.get(((MappedAggRef) ref).fieldName());
|
||||
// }
|
||||
|
||||
|
||||
if (formattedKey) {
|
||||
List<? extends Bucket> 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<String> 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<RowSetCursor> 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<HitExtractor> getExtractors() {
|
||||
// create response extractors for the first time
|
||||
List<Reference> refs = query.refs();
|
||||
|
||||
|
||||
List<HitExtractor> 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<HitExtractor> exts;
|
||||
|
||||
|
||||
SessionScrollActionListener(ActionListener<RowSetCursor> listener, Client client, TimeValue keepAlive, Schema schema, List<HitExtractor> ext, int limit, int docCount) {
|
||||
super(listener, client, keepAlive, schema, limit, docCount);
|
||||
this.exts = ext;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<HitExtractor> getExtractors() {
|
||||
return exts;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
super(listener, client, keepAlive, schema);
|
||||
this.limit = limit;
|
||||
this.docsRead = docsRead;
|
||||
}
|
||||
|
||||
|
||||
protected RowSetCursor handleResponse(SearchResponse response) {
|
||||
SearchHit[] hits = response.getHits().getHits();
|
||||
List<HitExtractor> exts = getExtractors();
|
||||
|
||||
|
||||
// there are some results
|
||||
if (hits.length > 0) {
|
||||
String scrollId = response.getScrollId();
|
||||
Consumer<ActionListener<RowSetCursor>> 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<HitExtractor> exts) {
|
||||
for (HitExtractor ext : exts) {
|
||||
if (ext instanceof DocValueExtractor || ext instanceof ProcessingHitExtractor) {
|
||||
|
@ -309,26 +308,26 @@ public class Scroller {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected abstract List<HitExtractor> getExtractors();
|
||||
}
|
||||
|
||||
|
||||
abstract static class ScrollerActionListener implements ActionListener<SearchResponse> {
|
||||
|
||||
|
||||
final ActionListener<RowSetCursor> listener;
|
||||
|
||||
|
||||
final Client client;
|
||||
final TimeValue keepAlive;
|
||||
final Schema schema;
|
||||
|
||||
|
||||
ScrollerActionListener(ActionListener<RowSetCursor> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Expression> children) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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<PhysicalPlan> {
|
|||
return Arrays.asList(rollup, finish);
|
||||
}
|
||||
|
||||
private class FoldProject extends FoldingRule<ProjectExec> {
|
||||
private static class FoldProject extends FoldingRule<ProjectExec> {
|
||||
|
||||
@Override
|
||||
protected PhysicalPlan rule(ProjectExec project) {
|
||||
|
@ -141,7 +140,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
}
|
||||
|
||||
private class FoldFilter extends FoldingRule<FilterExec> {
|
||||
private static class FoldFilter extends FoldingRule<FilterExec> {
|
||||
@Override
|
||||
protected PhysicalPlan rule(FilterExec plan) {
|
||||
|
||||
|
@ -214,7 +213,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
}
|
||||
|
||||
private class FoldAggregate extends FoldingRule<AggregateExec> {
|
||||
private static class FoldAggregate extends FoldingRule<AggregateExec> {
|
||||
@Override
|
||||
protected PhysicalPlan rule(AggregateExec a) {
|
||||
|
||||
|
@ -380,7 +379,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
}
|
||||
|
||||
private class FoldOrderBy extends FoldingRule<OrderExec> {
|
||||
private static class FoldOrderBy extends FoldingRule<OrderExec> {
|
||||
@Override
|
||||
protected PhysicalPlan rule(OrderExec plan) {
|
||||
|
||||
|
@ -444,7 +443,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
|
||||
|
||||
private class FoldLimit extends FoldingRule<LimitExec> {
|
||||
private static class FoldLimit extends FoldingRule<LimitExec> {
|
||||
|
||||
@Override
|
||||
protected PhysicalPlan rule(LimitExec plan) {
|
||||
|
@ -459,7 +458,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
}
|
||||
|
||||
private class FoldQueryless extends FoldingRule<PhysicalPlan> {
|
||||
private static class FoldQueryless extends FoldingRule<PhysicalPlan> {
|
||||
|
||||
@Override
|
||||
protected PhysicalPlan rule(PhysicalPlan plan) {
|
||||
|
@ -470,7 +469,7 @@ class QueryFolder extends RuleExecutor<PhysicalPlan> {
|
|||
}
|
||||
}
|
||||
|
||||
private class PlanOutputToQueryRef extends FoldingRule<EsQueryExec> {
|
||||
private static class PlanOutputToQueryRef extends FoldingRule<EsQueryExec> {
|
||||
@Override
|
||||
protected PhysicalPlan rule(EsQueryExec exec) {
|
||||
QueryContainer qContainer = exec.queryContainer();
|
||||
|
|
|
@ -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<Count> {
|
||||
|
||||
@Override
|
||||
|
@ -708,7 +708,7 @@ abstract class QueryTranslator {
|
|||
return new CardinalityAgg(id, path, field(c));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Sums extends SingleValueAggTranslator<Sum> {
|
||||
|
||||
@Override
|
||||
|
@ -716,7 +716,7 @@ abstract class QueryTranslator {
|
|||
return new SumAgg(id, path, field(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Avgs extends SingleValueAggTranslator<Avg> {
|
||||
|
||||
@Override
|
||||
|
@ -724,7 +724,7 @@ abstract class QueryTranslator {
|
|||
return new AvgAgg(id, path, field(a));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Maxes extends SingleValueAggTranslator<Max> {
|
||||
|
||||
@Override
|
||||
|
@ -732,7 +732,7 @@ abstract class QueryTranslator {
|
|||
return new MaxAgg(id, path, field(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class Mins extends SingleValueAggTranslator<Min> {
|
||||
|
||||
@Override
|
||||
|
@ -740,7 +740,7 @@ abstract class QueryTranslator {
|
|||
return new MinAgg(id, path, field(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class StatsAggs extends CompoundAggTranslator<Stats> {
|
||||
|
||||
@Override
|
||||
|
@ -748,7 +748,7 @@ abstract class QueryTranslator {
|
|||
return new StatsAgg(id, path, field(s));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class ExtendedStatsAggs extends CompoundAggTranslator<ExtendedStats> {
|
||||
|
||||
@Override
|
||||
|
@ -756,7 +756,7 @@ abstract class QueryTranslator {
|
|||
return new ExtendedStatsAgg(id, path, field(e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class MatrixStatsAggs extends CompoundAggTranslator<MatrixStats> {
|
||||
|
||||
@Override
|
||||
|
@ -764,7 +764,7 @@ abstract class QueryTranslator {
|
|||
return new MatrixStatsAgg(id, path, singletonList(field(m)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class DateTimes extends SingleValueAggTranslator<Min> {
|
||||
|
||||
@Override
|
||||
|
@ -772,7 +772,7 @@ abstract class QueryTranslator {
|
|||
return new MinAgg(id, path, field(m));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
abstract static class AggTranslator<F extends Function> {
|
||||
|
||||
private final Class<F> 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<F extends Function> extends AggTranslator<F> {
|
||||
|
||||
@Override
|
||||
|
@ -795,7 +795,7 @@ abstract class QueryTranslator {
|
|||
|
||||
protected abstract LeafAgg toAgg(String id, String path, F f);
|
||||
}
|
||||
|
||||
|
||||
abstract static class CompoundAggTranslator<C extends CompoundAggregate> extends AggTranslator<C> {
|
||||
|
||||
@Override
|
||||
|
@ -806,7 +806,8 @@ abstract class QueryTranslator {
|
|||
|
||||
protected abstract LeafAgg toAgg(String id, String path, C f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
abstract static class ExppressionTranslator<E extends Expression> {
|
||||
|
||||
private final Class<E> typeToken = ReflectionUtils.detectSuperTypeForRuleLike(getClass());
|
||||
|
|
Loading…
Reference in New Issue