use of org.apache.drill.exec.vector.ValueVector in project drill by apache.
the class BatchPrinter method printBatch.
public static void printBatch(VectorAccessible batch, SelectionVector2 sv2) {
List<String> columns = Lists.newArrayList();
List<ValueVector> vectors = Lists.newArrayList();
for (VectorWrapper vw : batch) {
columns.add(vw.getValueVector().getField().getPath());
vectors.add(vw.getValueVector());
}
int width = columns.size();
int rows = vectors.get(0).getMetadata().getValueCount();
for (int i = 0; i < rows; i++) {
if (i % 50 == 0) {
System.out.println(StringUtils.repeat("-", width * 17 + 1));
for (String column : columns) {
System.out.printf("| %-15s", width <= 15 ? column : column.substring(0, 14));
}
System.out.printf("|\n");
System.out.println(StringUtils.repeat("-", width * 17 + 1));
}
int row = sv2.getIndex(i);
for (ValueVector vv : vectors) {
Object o = vv.getAccessor().getObject(row);
String value;
if (o == null) {
value = "null";
} else if (o instanceof byte[]) {
value = new String((byte[]) o);
} else {
value = o.toString();
}
System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
}
System.out.printf("|\n");
}
}
use of org.apache.drill.exec.vector.ValueVector in project drill by apache.
the class BatchPrinter method printBatch.
public static void printBatch(VectorAccessible batch) {
List<String> columns = Lists.newArrayList();
List<ValueVector> vectors = Lists.newArrayList();
for (VectorWrapper vw : batch) {
columns.add(vw.getValueVector().getField().getPath());
vectors.add(vw.getValueVector());
}
int width = columns.size();
int rows = vectors.get(0).getMetadata().getValueCount();
for (int row = 0; row < rows; row++) {
if (row % 50 == 0) {
System.out.println(StringUtils.repeat("-", width * 17 + 1));
for (String column : columns) {
System.out.printf("| %-15s", width <= 15 ? column : column.substring(0, 14));
}
System.out.printf("|\n");
System.out.println(StringUtils.repeat("-", width * 17 + 1));
}
for (ValueVector vv : vectors) {
Object o = vv.getAccessor().getObject(row);
String value;
if (o == null) {
value = "null";
} else if (o instanceof byte[]) {
value = new String((byte[]) o);
} else {
value = o.toString();
}
System.out.printf("| %-15s", value.length() <= 15 ? value : value.substring(0, 14));
}
System.out.printf("|\n");
}
}
use of org.apache.drill.exec.vector.ValueVector in project drill by apache.
the class DrillParquetReader method next.
@Override
public int next() {
int count = 0;
// No columns found in the file were selected, simply return a full batch of null records for each column requested
if (noColumnsFound) {
if (mockRecordsRead == footer.getBlocks().get(entry.getRowGroupIndex()).getRowCount()) {
return 0;
}
long recordsToRead = 0;
recordsToRead = Math.min(DEFAULT_RECORDS_TO_READ, footer.getBlocks().get(entry.getRowGroupIndex()).getRowCount() - mockRecordsRead);
for (ValueVector vv : nullFilledVectors) {
vv.getMutator().setValueCount((int) recordsToRead);
}
mockRecordsRead += recordsToRead;
return (int) recordsToRead;
}
while (count < 4000 && totalRead < recordCount) {
recordMaterializer.setPosition(count);
recordReader.read();
count++;
totalRead++;
}
writer.setValueCount(count);
// (by simply setting the value counts inside of them, as they start null filled)
if (nullFilledVectors != null) {
for (final ValueVector vv : nullFilledVectors) {
vv.getMutator().setValueCount(count);
}
}
return count;
}
use of org.apache.drill.exec.vector.ValueVector in project drill by apache.
the class HBaseRecordReader method next.
@Override
public int next() {
Stopwatch watch = Stopwatch.createStarted();
if (rowKeyVector != null) {
rowKeyVector.clear();
rowKeyVector.allocateNew();
}
for (ValueVector v : familyVectorMap.values()) {
v.clear();
v.allocateNew();
}
int rowCount = 0;
// if allocated memory for the first row is larger than allowed max in batch, it will be added anyway
do {
Result result = null;
final OperatorStats operatorStats = operatorContext == null ? null : operatorContext.getStats();
try {
if (operatorStats != null) {
operatorStats.startWait();
}
try {
result = resultScanner.next();
} finally {
if (operatorStats != null) {
operatorStats.stopWait();
}
}
} catch (IOException e) {
throw new DrillRuntimeException(e);
}
if (result == null) {
break;
}
// parse the result and populate the value vectors
Cell[] cells = result.rawCells();
if (rowKeyVector != null) {
rowKeyVector.getMutator().setSafe(rowCount, cells[0].getRowArray(), cells[0].getRowOffset(), cells[0].getRowLength());
}
if (!rowKeyOnly) {
for (final Cell cell : cells) {
final int familyOffset = cell.getFamilyOffset();
final int familyLength = cell.getFamilyLength();
final byte[] familyArray = cell.getFamilyArray();
final MapVector mv = getOrCreateFamilyVector(new String(familyArray, familyOffset, familyLength), true);
final int qualifierOffset = cell.getQualifierOffset();
final int qualifierLength = cell.getQualifierLength();
final byte[] qualifierArray = cell.getQualifierArray();
final NullableVarBinaryVector v = getOrCreateColumnVector(mv, new String(qualifierArray, qualifierOffset, qualifierLength));
final int valueOffset = cell.getValueOffset();
final int valueLength = cell.getValueLength();
final byte[] valueArray = cell.getValueArray();
v.getMutator().setSafe(rowCount, valueArray, valueOffset, valueLength);
}
}
rowCount++;
} while (canAddNewRow(rowCount));
setOutputRowCount(rowCount);
logger.debug("Took {} ms to get {} records", watch.elapsed(TimeUnit.MILLISECONDS), rowCount);
return rowCount;
}
use of org.apache.drill.exec.vector.ValueVector in project drill by apache.
the class TestOrderedBytesConvertFunctions method getRunResult.
protected Object[] getRunResult(QueryType queryType, String planString) throws Exception {
List<QueryDataBatch> resultList = testRunAndReturn(queryType, planString);
List<Object> res = new ArrayList<Object>();
RecordBatchLoader loader = new RecordBatchLoader(getAllocator());
for (QueryDataBatch result : resultList) {
if (result.getData() != null) {
loader.load(result.getHeader().getDef(), result.getData());
ValueVector v = loader.iterator().next().getValueVector();
for (int j = 0; j < v.getAccessor().getValueCount(); j++) {
if (v instanceof VarCharVector) {
res.add(new String(((VarCharVector) v).getAccessor().get(j)));
} else {
res.add(v.getAccessor().getObject(j));
}
}
loader.clear();
result.release();
}
}
return res.toArray();
}
Aggregations