Github user ilooner commented on a diff in the pull request:
https://github.com/apache/drill/pull/984#discussion_r148157170
--- Diff:
exec/java-exec/src/test/java/org/apache/drill/test/BatchUtils.java ---
@@ -0,0 +1,280 @@
+/*
+ * 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.test;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.drill.exec.record.VectorContainer;
+import org.apache.drill.exec.record.VectorWrapper;
+import org.apache.drill.exec.record.selection.SelectionVector4;
+import org.apache.drill.exec.vector.ValueVector;
+import org.junit.Assert;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+public class BatchUtils {
+ static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(BatchUtils.class);
+
+ public static Map<String, List<Object>>
containerToObjects(VectorContainer vectorContainer) {
+ Map<String, List<Object>> rows = Maps.newHashMap();
+ int numCols = vectorContainer.getNumberOfColumns();
+ int recordCount = vectorContainer.getRecordCount();
+
+ for (int columnIndex = 0; columnIndex < numCols; columnIndex++) {
+ String columnName =
vectorContainer.getSchema().getColumn(columnIndex).getName();
+ List<Object> data = Lists.newArrayList();
+
+ ValueVector.Accessor valueVectorAccessor = vectorContainer
+ .getValueVector(columnIndex)
+ .getValueVector()
+ .getAccessor();
+
+ for (int recordIndex = 0; recordIndex < recordCount; recordIndex++) {
+ data.add(valueVectorAccessor.getObject(recordIndex));
+ }
+
+ rows.put(columnName, data);
+ }
+
+ return rows;
+ }
+
+ public static Map<String, List<Object>>
hyperBatchAndSelectorToObjects(VectorContainer vectorContainer,
SelectionVector4 selectionVector4) {
+ Map<String, List<Object>> rows = Maps.newHashMap();
+ int numCols = vectorContainer.getNumberOfColumns();
+ int numIndices = selectionVector4.getCount();
+
+ for (int columnIndex = 0; columnIndex < numCols; columnIndex++) {
+ String columnName =
vectorContainer.getSchema().getColumn(columnIndex).getName();
+ List<Object> data = Lists.newArrayList();
+
+ VectorWrapper vectorWrapper =
vectorContainer.getValueVector(columnIndex);
+
+ for (int indexIndex = 0; indexIndex < numIndices; indexIndex++) {
+ int sv4Index = selectionVector4.get(indexIndex);
+ int batchIndex = SelectionVector4.getBatchIndex(sv4Index);
+ int recordIndex = SelectionVector4.getRecordIndex(sv4Index);
+
+ ValueVector valueVector =
vectorWrapper.getValueVectors()[batchIndex];
+ Object columnValue =
valueVector.getAccessor().getObject(recordIndex);
+ data.add(columnValue);
+ }
+
+ rows.put(columnName, data);
+ }
+
+ return rows;
+ }
+
+ public static String toString(Map<String, List<Object>> table) {
+ if (table.isEmpty()) {
+ return "[ empty table ]";
+ }
+
+ List<String> columnNames = Lists.newArrayList(table.keySet());
+ Collections.sort(columnNames);
+ int numRecords = table.get(columnNames.get(0)).size();
+
+ StringBuilder sb = new StringBuilder();
+
+ {
+ sb.append("[ ");
+ String separator = "";
+
+ for (String columnName : columnNames) {
+ sb.append(separator);
+ separator = ", ";
+ sb.append(columnName);
+ }
+
+ sb.append(" ]\n");
+ }
+
+ for (int recordIndex = 0; recordIndex < numRecords; recordIndex++) {
+ sb.append("{");
+ String separator = "";
+
+ for (String columnName : columnNames) {
+ sb.append(separator);
+ separator = ", ";
+ sb.append(table.get(columnName).get(recordIndex));
+ }
+
+ sb.append("}\n");
+ }
+
+ return sb.toString();
+ }
+
+ public static void assertEqual(Map<String, List<Object>> expected,
Map<String, List<Object>> actual) {
--- End diff --
Done
---