List of usage examples for org.apache.hadoop.io Text getLength
@Override public int getLength()
From source file:org.apache.accumulo.core.iterators.user.IndexedDocIteratorTest.java
License:Apache License
private TreeMap<Key, Value> createSortedMap(float hitRatio, int numRows, int numDocsPerRow, Text[] columnFamilies, Text[] otherColumnFamilies, HashSet<Text> docs, Text[] negatedColumns) { StringBuilder sb = new StringBuilder(); Random r = new Random(); Value v = new Value(new byte[0]); TreeMap<Key, Value> map = new TreeMap<>(); boolean[] negateMask = new boolean[columnFamilies.length]; for (int i = 0; i < columnFamilies.length; i++) { negateMask[i] = false;/*from www . jav a 2s. c o m*/ if (negatedColumns.length > 0) for (Text ng : negatedColumns) if (columnFamilies[i].equals(ng)) negateMask[i] = true; } for (int i = 0; i < numRows; i++) { Text row = new Text(String.format("%06d", i)); for (int startDocID = docid; docid - startDocID < numDocsPerRow; docid++) { sb.setLength(0); sb.append("fake doc contents"); boolean docHits = true; Text doc = new Text("type"); doc.append(nullByte, 0, 1); doc.append(String.format("%010d", docid).getBytes(), 0, 10); for (int j = 0; j < columnFamilies.length; j++) { if (r.nextFloat() < hitRatio) { Text colq = new Text(columnFamilies[j]); colq.append(nullByte, 0, 1); colq.append(doc.getBytes(), 0, doc.getLength()); colq.append(nullByte, 0, 1); colq.append("stuff".getBytes(), 0, "stuff".length()); Key k = new Key(row, indexColf, colq); map.put(k, v); sb.append(" "); sb.append(columnFamilies[j]); if (negateMask[j]) docHits = false; } else { if (!negateMask[j]) docHits = false; } } if (docHits) { docs.add(doc); } for (Text cf : otherColumnFamilies) { if (r.nextFloat() < hitRatio) { Text colq = new Text(cf); colq.append(nullByte, 0, 1); colq.append(doc.getBytes(), 0, doc.getLength()); colq.append(nullByte, 0, 1); colq.append("stuff".getBytes(), 0, "stuff".length()); Key k = new Key(row, indexColf, colq); map.put(k, v); sb.append(" "); sb.append(cf); } } sb.append(" docID=").append(doc); Key k = new Key(row, docColf, new Text(String.format("%010d", docid).getBytes())); map.put(k, new Value(sb.toString().getBytes())); } } return map; }
From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java
License:Apache License
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use {@code newColFam} as the column family. *//* w ww .j ava 2s . c om*/ protected Key replaceColumnFamily(Key originalKey, Text newColFam) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = newColFam.getBytes(); byte[] cq = originalKey.getColumnQualifierData().toArray(); byte[] cv = originalKey.getColumnVisibilityData().toArray(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq, 0, cq.length, cv, 0, cv.length, timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java
License:Apache License
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use {@code newColQual} as the column qualifier. *///from w w w. j a v a 2 s . c om protected Key replaceColumnQualifier(Key originalKey, Text newColQual) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = newColQual.getBytes(); byte[] cv = originalKey.getColumnVisibilityData().toArray(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, newColQual.getLength(), cv, 0, cv.length, timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java
License:Apache License
/** * Make a new key with all parts (including delete flag) coming from {@code originalKey} but use {@code newColVis} as the column visibility. *//* w w w .ja v a2 s . c o m*/ protected Key replaceColumnVisibility(Key originalKey, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = originalKey.getColumnQualifierData().toArray(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, cq.length, cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java
License:Apache License
/** * Make a new key with a column family, column qualifier, and column visibility. Copy the rest of the parts of the key (including delete flag) from * {@code originalKey}.//from ww w .j a v a 2s . com */ protected Key replaceKeyParts(Key originalKey, Text newColFam, Text newColQual, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = newColFam.getBytes(); byte[] cq = newColQual.getBytes(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, newColFam.getLength(), cq, 0, newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
From source file:org.apache.accumulo.core.iterators.user.TransformingIterator.java
License:Apache License
/** * Make a new key with a column qualifier, and column visibility. Copy the rest of the parts of the key (including delete flag) from {@code originalKey}. *//*from ww w . j a v a 2s. c om*/ protected Key replaceKeyParts(Key originalKey, Text newColQual, Text newColVis) { byte[] row = originalKey.getRowData().toArray(); byte[] cf = originalKey.getColumnFamilyData().toArray(); byte[] cq = newColQual.getBytes(); byte[] cv = newColVis.getBytes(); long timestamp = originalKey.getTimestamp(); Key newKey = new Key(row, 0, row.length, cf, 0, cf.length, cq, 0, newColQual.getLength(), cv, 0, newColVis.getLength(), timestamp); newKey.setDeleted(originalKey.isDeleted()); return newKey; }
From source file:org.apache.accumulo.core.replication.ReplicationTarget.java
License:Apache License
/** * Deserialize a ReplicationTarget//from ww w .j a va 2 s .c o m * * @param t * Serialized copy * @return the deserialized version */ public static ReplicationTarget from(Text t) { ReplicationTarget target = new ReplicationTarget(); DataInputBuffer buffer = new DataInputBuffer(); buffer.reset(t.getBytes(), t.getLength()); try { target.readFields(buffer); } catch (IOException e) { throw new RuntimeException(e); } return target; }
From source file:org.apache.accumulo.core.replication.StatusFormatter.java
License:Apache License
protected StringBuilder appendText(StringBuilder sb, Text t) { return appendBytes(sb, t.getBytes(), 0, t.getLength()); }
From source file:org.apache.accumulo.core.util.format.BinaryFormatter.java
License:Apache License
public static StringBuilder appendText(StringBuilder sb, Text t) { return appendBytes(sb, t.getBytes(), 0, t.getLength()); }
From source file:org.apache.accumulo.core.util.format.DefaultFormatter.java
License:Apache License
static StringBuilder appendText(StringBuilder sb, Text t) { return appendBytes(sb, t.getBytes(), 0, t.getLength()); }