arina-ielchiieva commented on a change in pull request #1871: DRILL-7403:
lidate batch checks, vector integretity in unit tests
URL: https://github.com/apache/drill/pull/1871#discussion_r334629593
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/BatchValidator.java
##########
@@ -48,50 +52,235 @@
private static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(BatchValidator.class);
+ public static final boolean LOG_TO_STDOUT = true;
public static final int MAX_ERRORS = 100;
- private final int rowCount;
- private final VectorAccessible batch;
- private final List<String> errorList;
- private int errorCount;
+ public interface ErrorReporter {
+ void error(String name, ValueVector vector, String msg);
+ void warn(String name, ValueVector vector, String msg);
+ void error(String msg);
+ int errorCount();
+ }
+
+ public abstract static class BaseErrorReporter implements ErrorReporter {
+
+ private final String opName;
+ private int errorCount;
+
+ public BaseErrorReporter(String opName) {
+ this.opName = opName;
+ }
+
+ protected boolean startError() {
+ if (errorCount == 0) {
+ logger.error("Found one or more vector errors from " + opName);
+ }
+ errorCount++;
+ if (errorCount >= MAX_ERRORS) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void error(String name, ValueVector vector, String msg) {
+ error(String.format("%s - %s: %s",
+ name, vector.getClass().getSimpleName(), msg));
+ }
+
+ @Override
+ public void warn(String name, ValueVector vector, String msg) {
+ warn(String.format("%s - %s: %s",
+ name, vector.getClass().getSimpleName(), msg));
+ }
+
+ public abstract void warn(String msg);
+
+ @Override
+ public int errorCount() { return errorCount; }
+ }
+
+ private static class StdOutReporter extends BaseErrorReporter {
+
+ public StdOutReporter(String opName) {
+ super(opName);
+ }
+
+ @Override
+ public void error(String msg) {
+ if (startError()) {
+ System.out.println(msg);
+ }
+ }
+
+ @Override
+ public void warn(String msg) {
+ System.out.println(msg);
+ }
+ }
+
+ private static class LogReporter extends BaseErrorReporter {
+
+ public LogReporter(String opName) {
+ super(opName);
+ }
+
+ @Override
+ public void error(String msg) {
+ if (startError()) {
+ logger.error(msg);
+ }
+ }
- public BatchValidator(VectorAccessible batch) {
- rowCount = batch.getRecordCount();
- this.batch = batch;
- errorList = null;
+ @Override
+ public void warn(String msg) {
+ logger.error(msg);
+ }
}
- public BatchValidator(VectorAccessible batch, boolean captureErrors) {
- rowCount = batch.getRecordCount();
- this.batch = batch;
- if (captureErrors) {
- errorList = new ArrayList<>();
+ private enum CheckMode { COUNTS, ALL };
+
+ private static Map<Class<? extends RecordBatch>, CheckMode> checkRules =
buildRules();
+
+ private final ErrorReporter errorReporter;
+
+ public BatchValidator(ErrorReporter errorReporter) {
+ this.errorReporter = errorReporter;
+ }
+
+ /**
+ * At present, most operators will not pass the checks here. The following
+ * table identifies those that should be checked, and the degree of check.
+ * Over time, this table should include all operators, and thus become
+ * unnecessary.
+ */
+ private static Map<Class<? extends RecordBatch>, CheckMode> buildRules() {
+ Map<Class<? extends RecordBatch>, CheckMode> rules = new
IdentityHashMap<>();
Review comment:
```suggestion
private final Map<Class<? extends RecordBatch>, CheckMode> rules = new
IdentityHashMap<>();
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services