You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by ja...@apache.org on 2014/06/26 22:45:15 UTC
[15/16] git commit: Add vector validator to IteratorValidator
Add vector validator to IteratorValidator
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/2aef4897
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/2aef4897
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/2aef4897
Branch: refs/heads/master
Commit: 2aef4897855ce89e70a2862f7ae8bf2628eb497a
Parents: d5967c5
Author: Steven Phillips <sp...@maprtech.com>
Authored: Wed Jun 25 17:58:24 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Thu Jun 26 09:02:35 2014 -0700
----------------------------------------------------------------------
.../IteratorValidatorBatchIterator.java | 7 ++
.../drill/exec/vector/VectorValidator.java | 73 ++++++++++++++++++++
2 files changed, 80 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2aef4897/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/IteratorValidatorBatchIterator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/IteratorValidatorBatchIterator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/IteratorValidatorBatchIterator.java
index c8e9c60..20e4de4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/IteratorValidatorBatchIterator.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/physical/impl/validate/IteratorValidatorBatchIterator.java
@@ -30,10 +30,13 @@ import org.apache.drill.exec.record.VectorWrapper;
import org.apache.drill.exec.record.WritableBatch;
import org.apache.drill.exec.record.selection.SelectionVector2;
import org.apache.drill.exec.record.selection.SelectionVector4;
+import org.apache.drill.exec.vector.VectorValidator;
public class IteratorValidatorBatchIterator implements RecordBatch {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(IteratorValidatorBatchIterator.class);
+ static final boolean VALIDATE_VECTORS = false;
+
private IterOutcome state = IterOutcome.NOT_YET;
private final RecordBatch incoming;
private boolean first = true;
@@ -127,6 +130,10 @@ public class IteratorValidatorBatchIterator implements RecordBatch {
if(incoming.getRecordCount() > MAX_BATCH_SIZE){
throw new IllegalStateException (String.format("Incoming batch of %s has size %d, which is beyond the limit of %d", incoming.getClass().getName(), incoming.getRecordCount(), MAX_BATCH_SIZE));
}
+
+ if (VALIDATE_VECTORS) {
+ VectorValidator.validate(incoming);
+ }
// int valueCount = incoming.getRecordCount();
// for (VectorWrapper vw : incoming) {
// assert valueCount == vw.getValueVector().getAccessor().getValueCount() : "Count of values in each vector within this batch does not match.";
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/2aef4897/exec/java-exec/src/main/java/org/apache/drill/exec/vector/VectorValidator.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/vector/VectorValidator.java b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/VectorValidator.java
new file mode 100644
index 0000000..6283f35
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/vector/VectorValidator.java
@@ -0,0 +1,73 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.vector;
+
+import org.apache.drill.exec.record.BatchSchema.SelectionVectorMode;
+import org.apache.drill.exec.record.RecordBatch;
+import org.apache.drill.exec.record.VectorWrapper;
+
+public class VectorValidator {
+ public static void validate(RecordBatch batch) {
+ int count = batch.getRecordCount();
+ long hash = 12345;
+ SelectionVectorMode mode = batch.getSchema().getSelectionVectorMode();
+ switch(mode) {
+ case NONE: {
+ for (VectorWrapper w : batch) {
+ ValueVector v = w.getValueVector();
+ for (int i = 0; i < count; i++) {
+ Object obj = v.getAccessor().getObject(i);
+ if (obj != null) {
+ hash = obj.hashCode() ^ hash;
+ }
+ }
+ }
+ break;
+ }
+ case TWO_BYTE: {
+ for (VectorWrapper w : batch) {
+ ValueVector v = w.getValueVector();
+ for (int i = 0; i < count; i++) {
+ int index = batch.getSelectionVector2().getIndex(i);
+ Object obj = v.getAccessor().getObject(index);
+ if (obj != null) {
+ hash = obj.hashCode() ^ hash;
+ }
+ }
+ }
+ break;
+ }
+ case FOUR_BYTE: {
+ for (VectorWrapper w : batch) {
+ ValueVector[] vv = w.getValueVectors();
+ for (int i = 0; i < count; i++) {
+ int index = batch.getSelectionVector4().get(i);
+ ValueVector v = vv[index >> 16];
+ Object obj = v.getAccessor().getObject(index & 65535);
+ if (obj != null) {
+ hash = obj.hashCode() ^ hash;
+ }
+ }
+ }
+ }
+ }
+ if (hash == 0) {
+ System.out.println(hash);
+ }
+ }
+}