SQL: Fix long lines in querydsl package (elastic/x-pack-elasticsearch#3454)

Break the lines longer than 140 characters in the querydsl package into
multiple lines to make them easier to read. And to make checkstyle
happy.

Original commit: elastic/x-pack-elasticsearch@cffef88490
This commit is contained in:
Nik Everett 2017-12-29 17:59:23 -05:00 committed by GitHub
parent c2527ed0f6
commit 16f996da92
7 changed files with 55 additions and 38 deletions

View File

@ -21,12 +21,6 @@
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]planner[/\\]PlanningException.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]planner[/\\]QueryFolder.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]planner[/\\]QueryTranslator.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]agg[/\\]AggPath.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]agg[/\\]GroupByColumnAgg.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]agg[/\\]GroupByDateAgg.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]agg[/\\]GroupByScriptAgg.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]agg[/\\]GroupingAgg.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]querydsl[/\\]query[/\\]RangeQuery.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]tree[/\\]NodeUtils.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" />

View File

@ -49,19 +49,34 @@ public abstract class AggPath {
return (Strings.hasLength(parent) ? parent + PATH_DELIMITER : StringUtils.EMPTY) + child;
}
//
// The depth indicates the level of an agg excluding the root agg (because all aggs in SQL require a group). However all other bucket aggs are counted.
// Since the path does not indicate the type of agg used, to differentiate between metric properties and bucket properties, the bucket value is considered.
// This is needed since one might refer to the keys or count of a bucket path.
// As the opposite side there are metric aggs which have the same level as their parent (their nesting is an ES implementation detail)
// Default examples:
//
// agg1 = 0 ; agg1 = default/root group
// agg1>agg2._count = 1 ; ._count indicates agg2 is a bucket agg and thus it counted - agg1 (default group), depth=0, agg2 (bucketed), depth=1
// agg1>agg2>agg3.value = 1 ; agg3.value indicates a metric bucket thus only agg1 and agg2 are counted -> depth=2. In other words, agg3.value has the same depth as agg2._count
// agg1>agg2>agg3._count = 2 ; ._count indicates agg3 is a bucket agg, so count it for depth -> depth = 2
// agg1>agg2>agg3.sum = 1 ; .sum indicates agg3 is a metric agg, only agg1 and agg2 are bucket and with agg1 being the default group -> depth = 1
/*
* The depth indicates the level of an agg excluding the root agg
* (because all aggs in SQL require a group). However all other
* bucket aggs are counted.
*
* Since the path does not indicate the type of agg used, to
* differentiate between metric properties and bucket properties,
* the bucket value is considered. This is needed since one might
* refer to the keys or count of a bucket path. As the opposite
* side there are metric aggs which have the same level as their
* parent (their nesting is an ES implementation detail).
*
* Examples:
*
* agg1 = 0; agg1 = default/root group
* agg1>agg2._count = 1; ._count indicates agg2 is a bucket
* agg and thus it counted - agg1 (default group),
* depth=0, agg2 (bucketed), depth=1
* agg1>agg2>agg3.value = 1; agg3.value indicates a metric bucket
* thus only agg1 and agg2 are counted -> depth=2. In
* other words, agg3.value has the same depth as
* agg2._count
* agg1>agg2>agg3._count = 2; ._count indicates agg3 is a
* bucket agg, so count it for depth -> depth = 2
* agg1>agg2>agg3.sum = 1; .sum indicates agg3 is a metric agg,
* only agg1 and agg2 are bucket and with agg1 being the
* default group -> depth = 1
*/
public static int depth(String path) {
int depth = countCharIn(path, PATH_DELIMITER_CHAR);
// a metric value always has .foo while a bucket prop with ._foo
@ -84,4 +99,4 @@ public abstract class AggPath {
}
return count;
}
}
}

View File

@ -29,7 +29,8 @@ public class GroupByColumnAgg extends GroupingAgg {
this(id, propertyPath, fieldName, emptyList(), emptyList(), emptyMap(), -1);
}
public GroupByColumnAgg(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order, int limit) {
public GroupByColumnAgg(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order, int limit) {
super(id, propertyPath, fieldName, subAggs, subPipelines, order);
this.limit = limit < 0 ? DEFAULT_LIMIT : Math.min(limit, DEFAULT_LIMIT);
}
@ -74,11 +75,12 @@ public class GroupByColumnAgg extends GroupingAgg {
}
@Override
protected GroupByColumnAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
protected GroupByColumnAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order) {
return new GroupByColumnAgg(id, propertyPath, fieldName, subAggs, subPipelines, order, limit);
}
public GroupByColumnAgg withLimit(int limit) {
return new GroupByColumnAgg(id(), propertyPath(), fieldName(), subAggs(), subPipelines(), order(), limit);
}
}
}

View File

@ -25,12 +25,12 @@ public class GroupByDateAgg extends GroupingAgg {
private final String interval;
private final DateTimeZone timeZone;
public GroupByDateAgg(String id, String propertyPath, String fieldName, String interval, DateTimeZone timeZone) {
this(id, propertyPath, fieldName, interval, timeZone, emptyList(), emptyList(), emptyMap());
}
public GroupByDateAgg(String id, String propertyPath, String fieldName, String interval, DateTimeZone timeZone,
public GroupByDateAgg(String id, String propertyPath, String fieldName, String interval, DateTimeZone timeZone,
List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
super(id, propertyPath, fieldName, subAggs, subPipelines, order);
this.interval = interval;
@ -70,7 +70,8 @@ public class GroupByDateAgg extends GroupingAgg {
}
@Override
protected GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
protected GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order) {
return new GroupByDateAgg(id, propertyPath, fieldName, interval, timeZone, subAggs, subPipelines, order);
}
}

View File

@ -45,7 +45,8 @@ public class GroupByScriptAgg extends GroupByColumnAgg {
}
@Override
protected GroupByScriptAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
protected GroupByScriptAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order) {
return new GroupByScriptAgg(id, propertyPath, fieldName, script, subAggs, subPipelines, order, limit());
}
@ -53,4 +54,4 @@ public class GroupByScriptAgg extends GroupByColumnAgg {
public GroupByScriptAgg withLimit(int limit) {
return new GroupByScriptAgg(id(), propertyPath(), fieldName(), script, subAggs(), subPipelines(), order(), limit);
}
}
}

View File

@ -30,7 +30,8 @@ public abstract class GroupingAgg extends Agg {
}
@Override
protected GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
protected GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order) {
throw new SqlIllegalArgumentException("Default group cannot be cloned");
}
};
@ -39,7 +40,8 @@ public abstract class GroupingAgg extends Agg {
private final List<PipelineAgg> subPipelines;
private final Map<String, Direction> order;
GroupingAgg(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order) {
GroupingAgg(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order) {
super(id, propertyPath, fieldName);
this.subAggs = subAggs;
this.subPipelines = subPipelines;
@ -53,7 +55,7 @@ public abstract class GroupingAgg extends Agg {
public List<PipelineAgg> subPipelines() {
return subPipelines;
}
public Map<String, Direction> order() {
return order;
}
@ -98,7 +100,8 @@ public abstract class GroupingAgg extends Agg {
return copy(id(), propertyPath(), fieldName(), subAggs, subPipelines, newOrder);
}
protected abstract GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs, List<PipelineAgg> subPipelines, Map<String, Direction> order);
protected abstract GroupingAgg copy(String id, String propertyPath, String fieldName, List<LeafAgg> subAggs,
List<PipelineAgg> subPipelines, Map<String, Direction> order);
@Override
public int hashCode() {
@ -110,21 +113,21 @@ public abstract class GroupingAgg extends Agg {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
GroupByColumnAgg other = (GroupByColumnAgg) obj;
return Objects.equals(id(), other.id())
return Objects.equals(id(), other.id())
&& Objects.equals(propertyPath(), other.propertyPath())
&& Objects.equals(fieldName(), other.fieldName())
&& Objects.equals(subAggs(), other.subAggs())
&& Objects.equals(subPipelines(), other.subPipelines());
}
@Override
public String toString() {
return super.toString() + "=" + subAggs() + "|" + subPipelines();
}
}
}

View File

@ -25,7 +25,8 @@ public class RangeQuery extends LeafQuery {
this(location, field, lower, includeLower, upper, includeUpper, null);
}
public RangeQuery(Location location, String field, Object lower, boolean includeLower, Object upper, boolean includeUpper, String format) {
public RangeQuery(Location location, String field, Object lower, boolean includeLower, Object upper,
boolean includeUpper, String format) {
super(location);
this.field = field;
this.lower = lower;