/** * Returns the key row in this batch at `rowId`. Returned key row is reused across calls. */ @Override public UnsafeRow getKeyRow(int rowId) { assert(rowId >= 0); assert(rowId < numRows); if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached long offset = getKeyOffsetForFixedLengthRecords(rowId); keyRow.pointTo(base, offset, klen); // set keyRowId so we can check if desired row is cached keyRowId = rowId; } return keyRow; }
/** * Returns the value row by two steps: * 1) looking up the key row with the same id (skipped if the key row is cached) * 2) retrieve the value row by reusing the metadata from step 1) * In most times, 1) is skipped because `getKeyRow(id)` is often called before `getValueRow(id)`. */ @Override protected UnsafeRow getValueFromKey(int rowId) { if (keyRowId != rowId) { getKeyRow(rowId); } assert(rowId >= 0); valueRow.pointTo(base, keyRow.getBaseOffset() + klen, vlen); return valueRow; }
public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema, TaskMemoryManager manager, int maxRows) { boolean allFixedLength = true; // checking if there is any variable length fields // there is probably a more succinct impl of this for (String name : keySchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(keySchema.apply(name).dataType()); } for (String name : valueSchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(valueSchema.apply(name).dataType()); } if (allFixedLength) { return new FixedLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } else { return new VariableLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } }
public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema, TaskMemoryManager manager, int maxRows) { boolean allFixedLength = true; // checking if there is any variable length fields // there is probably a more succinct impl of this for (String name : keySchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(keySchema.apply(name).dataType()); } for (String name : valueSchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(valueSchema.apply(name).dataType()); } if (allFixedLength) { return new FixedLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } else { return new VariableLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } }
/** * Returns the value row by two steps: * 1) looking up the key row with the same id (skipped if the key row is cached) * 2) retrieve the value row by reusing the metadata from step 1) * In most times, 1) is skipped because `getKeyRow(id)` is often called before `getValueRow(id)`. */ @Override protected UnsafeRow getValueFromKey(int rowId) { if (keyRowId != rowId) { getKeyRow(rowId); } assert(rowId >= 0); valueRow.pointTo(base, keyRow.getBaseOffset() + klen, vlen); return valueRow; }
/** * Returns the key row in this batch at `rowId`. Returned key row is reused across calls. */ @Override public UnsafeRow getKeyRow(int rowId) { assert(rowId >= 0); assert(rowId < numRows); if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached long offset = getKeyOffsetForFixedLengthRecords(rowId); keyRow.pointTo(base, offset, klen); // set keyRowId so we can check if desired row is cached keyRowId = rowId; } return keyRow; }
public static RowBasedKeyValueBatch allocate(StructType keySchema, StructType valueSchema, TaskMemoryManager manager, int maxRows) { boolean allFixedLength = true; // checking if there is any variable length fields // there is probably a more succinct impl of this for (String name : keySchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(keySchema.apply(name).dataType()); } for (String name : valueSchema.fieldNames()) { allFixedLength = allFixedLength && UnsafeRow.isFixedLength(valueSchema.apply(name).dataType()); } if (allFixedLength) { return new FixedLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } else { return new VariableLengthRowBasedKeyValueBatch(keySchema, valueSchema, maxRows, manager); } }
/** * Returns the value row by two steps: * 1) looking up the key row with the same id (skipped if the key row is cached) * 2) retrieve the value row by reusing the metadata from step 1) * In most times, 1) is skipped because `getKeyRow(id)` is often called before `getValueRow(id)`. */ @Override protected UnsafeRow getValueFromKey(int rowId) { if (keyRowId != rowId) { getKeyRow(rowId); } assert(rowId >= 0); valueRow.pointTo(base, keyRow.getBaseOffset() + klen, vlen + 4); return valueRow; }
/** * Returns the key row in this batch at `rowId`. Returned key row is reused across calls. */ @Override public UnsafeRow getKeyRow(int rowId) { assert(rowId >= 0); assert(rowId < numRows); if (keyRowId != rowId) { // if keyRowId == rowId, desired keyRow is already cached long offset = getKeyOffsetForFixedLengthRecords(rowId); keyRow.pointTo(base, offset, klen); // set keyRowId so we can check if desired row is cached keyRowId = rowId; } return keyRow; }