@Override public int eval(int index, int numPartitions) { String key = partitionKeyVector.getAccessor().getObject(index).toString(); byte[] encodedKey = IdCodec.encodeAsBytes(key);
@Override public Object getObject(int index) { Map<String, Object> vv = new JsonStringHashMap<>(); for (String child:getChildFieldNames()) { ValueVector v = getChild(child); // TODO(DRILL-4001): Resolve this hack: // The index/value count check in the following if statement is a hack // to work around the current fact that RecordBatchLoader.load and // MapVector.load leave child vectors with a length of zero (as opposed // to matching the lengths of siblings and the parent map vector) // because they don't remove (or set the lengths of) vectors from // previous batches that aren't in the current batch. if (v != null && index < v.getAccessor().getValueCount()) { Object value = v.getAccessor().getObject(index); if (value != null) { vv.put(child, value); } } } return vv; }
public ColumnSize(ValueVector v, String prefix) { this.prefix = prefix; valueCount = v.getAccessor().getValueCount(); metadata = v.getField(); isVariableWidth = (v instanceof VariableWidthVector || v instanceof RepeatedVariableWidthVectorLike);
final TypeProtos.MinorType fieldMinorType = vw.getValueVector().getMetadata().getMajorType().getMinorType(); final Accessor accessor = vw.getValueVector().getAccessor(); final Object value = i < accessor.getValueCount() ? accessor.getObject(i) : null; final String display = value == null ? null : formatter.format(value, fieldMinorType); record.put(field, display);
for (VectorWrapper<?> vw : va) { int columnWidth = getColumnWidth(columnWidths, columnIndex); Object o = vw.getValueVector().getAccessor().getObject(row); String cellString; if (o instanceof byte[]) {
ValueVector v = w.getValueVector(); for (int i = 0; i < count; i++) { Object obj = v.getAccessor().getObject(i); if (obj != null) { hash = obj.hashCode() ^ hash; 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; 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;
@Override public int eval(int index, int numPartitions) { String key = partitionKeyVector.getAccessor().getObject(index).toString(); byte[] encodedKey = IdCodec.encodeAsBytes(key);
Object o; try{ o = vw.getValueVector().getAccessor().getObject(row); } catch (Exception e) { throw new RuntimeException("failure while trying to read column " + vw.getField().getName());
List<String> rowValues = Lists.newArrayList(); for (VectorWrapper<?> vw : va) { Object o = vw.getValueVector().getAccessor().getObject(row); if (o == null) { rowValues.add("null");
Object o = vv.getAccessor().getObject(row); String value; if (o == null) {
Object o = vv.getAccessor().getObject(row); String value; if (o == null) {
Object o = vw.getValueVectors()[sv4.get(j) >>> 16].getAccessor().getObject(sv4.get(j) & 65535); String value; if (o == null) {
@SuppressWarnings("resource") private static ValueVector coerceVector(ValueVector v, VectorContainer c, MaterializedField field, int recordCount, BufferAllocator allocator) { if (v != null) { int valueCount = v.getAccessor().getValueCount(); TransferPair tp = v.getTransferPair(allocator); tp.transfer(); if (v.getField().getType().getMinorType().equals(field.getType().getMinorType())) { if (field.getType().getMinorType() == MinorType.UNION) { UnionVector u = (UnionVector) tp.getTo(); for (MinorType t : field.getType().getSubTypeList()) { u.addSubType(t); } } return tp.getTo(); } else { ValueVector newVector = TypeHelper.getNewVector(field, allocator); Preconditions.checkState(field.getType().getMinorType() == MinorType.UNION, "Can only convert vector to Union vector"); UnionVector u = (UnionVector) newVector; u.setFirstType(tp.getTo(), valueCount); return u; } } else { v = TypeHelper.getNewVector(field, allocator); v.allocateNew(); v.getMutator().setValueCount(recordCount); return v; } }
/** Compose the array of partition values for the directories that are referenced by filter: * e.g suppose the dir hierarchy is year/quarter/month and the query is: * SELECT * FROM T WHERE dir0=2015 AND dir1 = 'Q1', * then for 2015/Q1/Feb, this will have ['2015', 'Q1', null] * If the query filter condition is WHERE dir1 = 'Q2' (i.e no dir0 condition) then the array will * have [null, 'Q2', null] */ private Pair<String[], Integer> composePartition(BitSet referencedDirsBitSet, Map<Integer, Integer> partitionMap, ValueVector[] vectors, int recordCount) { String[] partition = new String[vectors.length]; int maxIndex = -1; for (int referencedDirsIndex : BitSets.toIter(referencedDirsBitSet)) { int partitionColumnIndex = partitionMap.get(referencedDirsIndex); ValueVector vv = vectors[partitionColumnIndex]; if (vv.getAccessor().getValueCount() > 0 && vv.getAccessor().getObject(recordCount) != null) { String value = vv.getAccessor().getObject(recordCount).toString(); partition[partitionColumnIndex] = value; maxIndex = Math.max(maxIndex, partitionColumnIndex); } } return Pair.of(partition, maxIndex); }
@Override public Object getObject(int index) { final List<Object> list = new JsonStringArrayList<>(); final int end = offsets.getAccessor().get(index+1); String fieldName; for (int i = offsets.getAccessor().get(index); i < end; i++) { final Map<String, Object> vv = Maps.newLinkedHashMap(); for (final MaterializedField field : getField().getChildren()) { if (!field.equals(BaseRepeatedValueVector.OFFSETS_FIELD)) { fieldName = field.getName(); final Object value = getChild(fieldName).getAccessor().getObject(i); if (value != null) { vv.put(fieldName, value); } } } list.add(vv); } return list; }
@Override public Object getObject(int index) { Map<String, Object> vv = new JsonStringHashMap<>(); for (String child:getChildFieldNames()) { ValueVector v = getChild(child); // TODO(DRILL-4001): Resolve this hack: // The index/value count check in the following if statement is a hack // to work around the current fact that RecordBatchLoader.load and // MapVector.load leave child vectors with a length of zero (as opposed // to matching the lengths of siblings and the parent map vector) // because they don't remove (or set the lengths of) vectors from // previous batches that aren't in the current batch. if (v != null && index < v.getAccessor().getValueCount()) { Object value = v.getAccessor().getObject(index); if (value != null) { vv.put(child, value); } } } return vv; }
/** * This method create a pretty string for a record in the {@link VectorContainer}. * @param index The index of the record of interest. * @return The string representation of a record. */ public String prettyPrintRecord(int index) { final StringBuilder sb = new StringBuilder(); String separator = ""; sb.append("["); for (VectorWrapper vectorWrapper: wrappers) { sb.append(separator); separator = ", "; final String columnName = vectorWrapper.getField().getName(); final Object value = vectorWrapper.getValueVector().getAccessor().getObject(index); // "columnName" = 11 sb.append("\"").append(columnName).append("\" = ").append(value); } sb.append("]"); return sb.toString(); } }
/** * Returns ids of rowKeys to be read. * Number of rowKey ids returned will be numRowKeysToRead at the most i.e. it * will be less than numRowKeysToRead if only that many exist in the currentBatch. */ @JsonIgnore public ByteBuffer[] getRowKeyIdsToRead(int numRowKeysToRead) { int numKeys = hasRowKeys(numRowKeysToRead); if (numKeys == 0) { return null; } int index = 0; final ByteBuffer[] rowKeyIds = new ByteBuffer[numKeys]; while (index < numKeys) { Object o = rowKeyVector.getAccessor().getObject(currentIndex + index); rowKeyIds[index++] = IdCodec.encode(o.toString()); } updateRowKeysRead(numKeys); return rowKeyIds; }
public ValueVector setFirstType(ValueVector v, int newValueCount) { // We can't check that this really is the first subtype since // the subtypes can be declared before vectors are added. Preconditions.checkState(accessor.getValueCount() == 0); final ValueVector vv = addVector(v); MinorType type = v.getField().getType().getMinorType(); ValueVector.Accessor vAccessor = vv.getAccessor(); for (int i = 0; i < newValueCount; i++) { if (! vAccessor.isNull(i)) { mutator.setType(i, type); } else { mutator.setNull(i); } } mutator.setValueCount(newValueCount); return vv; }
/** * Returns an instance sitting at the given index if exists, null otherwise. * * @see org.apache.drill.exec.vector.accessor.SqlAccessor#getObject(int) */ @Override public Object getObject(int rowOffset) throws InvalidAccessException { // In case some vectors have fewer values than others, and callee invokes // this method with index >= getValueCount(), this should still yield null. final ValueVector.Accessor accessor = vector.getAccessor(); if (rowOffset < accessor.getValueCount()) { return delegate.getObject(rowOffset); } return null; } }