SQL: Fix checkstyle in sql/rule package (elastic/x-pack-elasticsearch#3446)
* Replaces long line comment with rewritten javadoc with nice line feeds * Adds some line breaks in a few log lines Original commit: elastic/x-pack-elasticsearch@00dc7cc9c8
This commit is contained in:
parent
92a55df8e6
commit
5dcde97fdf
|
@ -12,17 +12,14 @@ import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.xpack.sql.tree.Node;
|
import org.elasticsearch.xpack.sql.tree.Node;
|
||||||
import org.elasticsearch.xpack.sql.util.ReflectionUtils;
|
import org.elasticsearch.xpack.sql.util.ReflectionUtils;
|
||||||
|
|
||||||
// Rule class that applies a transformation to a tree.
|
/**
|
||||||
// In addition, performs type filtering so that a rule that works only on a type node can be skipped if necessary just based on the class signature.
|
* Rules that apply transformation to a tree. In addition, performs
|
||||||
|
* type filtering so that a rule that the rule implementation doesn't
|
||||||
// Implementation detail:
|
* have to manually filter.
|
||||||
// While lambdas are nice, actual node rules tend to be fairly large and are much better suited as full blown classes.
|
* <p>
|
||||||
// In addition as they already embed their type information (all rule implementations end up with the generic information on them)
|
* Rules <strong>could</strong> could be built as lambdas but most
|
||||||
// this can be leveraged to perform the type filtering (as mentioned above).
|
* rules are much larger so we keep them as full blown subclasses.
|
||||||
// As a side note, getting the generic information from lambdas is very hacky and not portable (not without completely messing the JVM SM)
|
*/
|
||||||
|
|
||||||
// apply - indicates how to apply the rule (transformUp/Down, transformExpressions..) on the target
|
|
||||||
// rule - contains the actual rule logic.
|
|
||||||
public abstract class Rule<E extends T, T extends Node<T>> implements UnaryOperator<T> {
|
public abstract class Rule<E extends T, T extends Node<T>> implements UnaryOperator<T> {
|
||||||
|
|
||||||
protected Logger log = Loggers.getLogger(getClass());
|
protected Logger log = Loggers.getLogger(getClass());
|
||||||
|
@ -52,4 +49,4 @@ public abstract class Rule<E extends T, T extends Node<T>> implements UnaryOpera
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return name();
|
return name();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,7 +68,7 @@ public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Iterable<Batch> batches = batches();
|
private final Iterable<Batch> batches = batches();
|
||||||
|
|
||||||
protected abstract Iterable<RuleExecutor<TreeType>.Batch> batches();
|
protected abstract Iterable<RuleExecutor<TreeType>.Batch> batches();
|
||||||
|
|
||||||
public class Transformation {
|
public class Transformation {
|
||||||
|
@ -103,7 +103,7 @@ public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExecutionInfo {
|
public class ExecutionInfo {
|
||||||
|
|
||||||
private final TreeType before, after;
|
private final TreeType before, after;
|
||||||
private final Map<Batch, List<Transformation>> transformations;
|
private final Map<Batch, List<Transformation>> transformations;
|
||||||
|
|
||||||
|
@ -145,12 +145,12 @@ public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
|
||||||
boolean hasChanged = false;
|
boolean hasChanged = false;
|
||||||
long batchStart = System.currentTimeMillis();
|
long batchStart = System.currentTimeMillis();
|
||||||
long batchDuration = 0;
|
long batchDuration = 0;
|
||||||
|
|
||||||
// run each batch until no change occurs or the limit is reached
|
// run each batch until no change occurs or the limit is reached
|
||||||
do {
|
do {
|
||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
batchRuns++;
|
batchRuns++;
|
||||||
|
|
||||||
for (Rule<?, TreeType> rule : batch.rules) {
|
for (Rule<?, TreeType> rule : batch.rules) {
|
||||||
Transformation tf = new Transformation(currentPlan, rule);
|
Transformation tf = new Transformation(currentPlan, rule);
|
||||||
tfs.add(tf);
|
tfs.add(tf);
|
||||||
|
@ -168,11 +168,11 @@ public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batchDuration = System.currentTimeMillis() - batchStart;
|
batchDuration = System.currentTimeMillis() - batchStart;
|
||||||
} while (hasChanged && !batch.limit.reached(batchRuns));
|
} while (hasChanged && !batch.limit.reached(batchRuns));
|
||||||
|
|
||||||
totalDuration += batchDuration;
|
totalDuration += batchDuration;
|
||||||
|
|
||||||
if (log.isTraceEnabled()) {
|
if (log.isTraceEnabled()) {
|
||||||
TreeType before = plan;
|
TreeType before = plan;
|
||||||
TreeType after = plan;
|
TreeType after = plan;
|
||||||
|
@ -180,16 +180,16 @@ public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
|
||||||
before = tfs.get(0).before;
|
before = tfs.get(0).before;
|
||||||
after = tfs.get(tfs.size() - 1).after;
|
after = tfs.get(tfs.size() - 1).after;
|
||||||
}
|
}
|
||||||
log.trace("Batch {} applied took {}\n{}", batch.name, TimeValue.timeValueMillis(batchDuration), NodeUtils.diffString(before, after));
|
log.trace("Batch {} applied took {}\n{}",
|
||||||
|
batch.name, TimeValue.timeValueMillis(batchDuration), NodeUtils.diffString(before, after));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!currentPlan.equals(plan)) {
|
if (false == currentPlan.equals(plan) && log.isDebugEnabled()) {
|
||||||
if (log.isDebugEnabled()) {
|
log.debug("Tree transformation took {}\n{}",
|
||||||
log.debug("Tree transformation took {}\n{}", TimeValue.timeValueMillis(totalDuration), NodeUtils.diffString(plan, currentPlan));
|
TimeValue.timeValueMillis(totalDuration), NodeUtils.diffString(plan, currentPlan));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ExecutionInfo(plan, currentPlan, transformations);
|
return new ExecutionInfo(plan, currentPlan, transformations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue