use of org.apache.hadoop.hive.ql.exec.vector.ListColumnVector in project hive by apache.
the class BatchToRowReader method nextList.
private ArrayList<Object> nextList(ColumnVector vector, int row, ListTypeInfo schema, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
ArrayList<Object> result;
if (previous == null || previous.getClass() != ArrayList.class) {
result = new ArrayList<>();
} else {
result = (ArrayList<Object>) previous;
}
ListColumnVector list = (ListColumnVector) vector;
int length = (int) list.lengths[row];
int offset = (int) list.offsets[row];
result.ensureCapacity(length);
int oldLength = result.size();
int idx = 0;
TypeInfo childType = schema.getListElementTypeInfo();
while (idx < length && idx < oldLength) {
result.set(idx, nextValue(list.child, offset + idx, childType, result.get(idx)));
idx += 1;
}
if (length < oldLength) {
for (int i = oldLength - 1; i >= length; --i) {
result.remove(i);
}
} else if (oldLength < length) {
while (idx < length) {
result.add(nextValue(list.child, offset + idx, childType, null));
idx += 1;
}
}
return result;
} else {
return null;
}
}
use of org.apache.hadoop.hive.ql.exec.vector.ListColumnVector in project hive by apache.
the class RecordReaderImpl method copyListColumn.
void copyListColumn(ColumnVector destination, ColumnVector source, int sourceOffset, int length) {
ListColumnVector castedSource = (ListColumnVector) source;
ListColumnVector castedDestination = (ListColumnVector) destination;
castedDestination.isRepeating = castedSource.noNulls;
castedDestination.noNulls = castedSource.noNulls;
if (source.isRepeating) {
castedDestination.isNull[0] = castedSource.isNull[0];
castedDestination.offsets[0] = 0;
castedDestination.lengths[0] = castedSource.lengths[0];
copyColumn(castedDestination.child, castedSource.child, (int) castedSource.offsets[0], (int) castedSource.lengths[0]);
} else {
if (!castedSource.noNulls) {
for (int r = 0; r < length; ++r) {
castedDestination.isNull[r] = castedSource.isNull[sourceOffset + r];
}
}
int minOffset = Integer.MAX_VALUE;
int maxOffset = Integer.MIN_VALUE;
for (int r = 0; r < length; ++r) {
int childOffset = (int) castedSource.offsets[r + sourceOffset];
int childLength = (int) castedSource.lengths[r + sourceOffset];
castedDestination.offsets[r] = childOffset;
castedDestination.lengths[r] = childLength;
minOffset = Math.min(minOffset, childOffset);
maxOffset = Math.max(maxOffset, childOffset + childLength);
}
if (minOffset <= maxOffset) {
castedDestination.childCount = maxOffset - minOffset + 1;
copyColumn(castedDestination.child, castedSource.child, minOffset, castedDestination.childCount);
} else {
castedDestination.childCount = 0;
}
}
}
use of org.apache.hadoop.hive.ql.exec.vector.ListColumnVector in project hive by apache.
the class RecordReaderImpl method nextList.
static ArrayList<Object> nextList(ColumnVector vector, int row, TypeDescription schema, Object previous) {
if (vector.isRepeating) {
row = 0;
}
if (vector.noNulls || !vector.isNull[row]) {
ArrayList<Object> result;
if (previous == null || previous.getClass() != ArrayList.class) {
result = new ArrayList<>();
} else {
result = (ArrayList<Object>) previous;
}
ListColumnVector list = (ListColumnVector) vector;
int length = (int) list.lengths[row];
int offset = (int) list.offsets[row];
result.ensureCapacity(length);
int oldLength = result.size();
int idx = 0;
TypeDescription childType = schema.getChildren().get(0);
while (idx < length && idx < oldLength) {
result.set(idx, nextValue(list.child, offset + idx, childType, result.get(idx)));
idx += 1;
}
if (length < oldLength) {
result.subList(length, result.size()).clear();
} else if (oldLength < length) {
while (idx < length) {
result.add(nextValue(list.child, offset + idx, childType, null));
idx += 1;
}
}
return result;
} else {
return null;
}
}
use of org.apache.hadoop.hive.ql.exec.vector.ListColumnVector in project druid by druid-io.
the class DruidOrcInputFormatTest method makeOrcFile.
private File makeOrcFile() throws IOException {
final File dir = temporaryFolder.newFolder();
final File testOrc = new File(dir, "test.orc");
TypeDescription schema = TypeDescription.createStruct().addField("timestamp", TypeDescription.createString()).addField("col1", TypeDescription.createString()).addField("col2", TypeDescription.createList(TypeDescription.createString())).addField("val1", TypeDescription.createFloat());
Configuration conf = new Configuration();
Writer writer = OrcFile.createWriter(new Path(testOrc.getPath()), OrcFile.writerOptions(conf).setSchema(schema).stripeSize(100000).bufferSize(10000).compress(CompressionKind.ZLIB).version(OrcFile.Version.CURRENT));
VectorizedRowBatch batch = schema.createRowBatch();
batch.size = 1;
((BytesColumnVector) batch.cols[0]).setRef(0, timestamp.getBytes(), 0, timestamp.length());
((BytesColumnVector) batch.cols[1]).setRef(0, col1.getBytes(), 0, col1.length());
ListColumnVector listColumnVector = (ListColumnVector) batch.cols[2];
listColumnVector.childCount = col2.length;
listColumnVector.lengths[0] = 3;
for (int idx = 0; idx < col2.length; idx++) {
((BytesColumnVector) listColumnVector.child).setRef(idx, col2[idx].getBytes(), 0, col2[idx].length());
}
((DoubleColumnVector) batch.cols[3]).vector[0] = val1;
writer.addRowBatch(batch);
writer.close();
return testOrc;
}
Aggregations