Here are the examples of the java api class org.apache.accumulo.core.data.ByteSequence taken from open source projects.
1. AccumuloMRUtils#getRangeLength()
Project: geowave
File: AccumuloMRUtils.java
File: AccumuloMRUtils.java
protected static double getRangeLength(final Range range) { final ByteSequence start = range.getStartKey().getRowData(); final ByteSequence end = range.getEndKey().getRowData(); final int maxDepth = Math.max(end.length(), start.length()); final BigInteger startBI = new BigInteger(extractBytes(start, maxDepth)); final BigInteger endBI = new BigInteger(extractBytes(end, maxDepth)); return endBI.subtract(startBI).doubleValue(); }
2. AccumuloResult#nextInner()
Project: gora
File: AccumuloResult.java
File: AccumuloResult.java
@Override protected boolean nextInner() throws IOException { if (!iterator.hasNext()) return false; key = null; Iterator<Entry<Key, Value>> nextRow = iterator.next(); ByteSequence row = getDataStore().populate(nextRow, persistent); key = ((AccumuloStore<K, T>) dataStore).fromBytes(getKeyClass(), row.toArray()); return true; }
3. ByteUtilTest#testByteSequence()
Project: incubator-fluo
File: ByteUtilTest.java
File: ByteUtilTest.java
@Test public void testByteSequence() { String s2 = "test2"; ByteSequence bs2 = new ArrayByteSequence(s2); Bytes b2 = ByteUtil.toBytes(bs2); Assert.assertEquals(Bytes.of(s2), b2); Assert.assertEquals(bs2, ByteUtil.toByteSequence(b2)); }
4. AccumuloStore#populate()
Project: gora
File: AccumuloStore.java
File: AccumuloStore.java
public ByteSequence populate(Iterator<Entry<Key, Value>> iter, T persistent) throws IOException { ByteSequence row = null; Map<Utf8, Object> currentMap = null; List currentArray = null; Text currentFam = null; int currentPos = 0; Schema currentSchema = null; Field currentField = null; BinaryDecoder decoder = DecoderFactory.get().binaryDecoder(new byte[0], null); while (iter.hasNext()) { Entry<Key, Value> entry = iter.next(); if (row == null) { row = entry.getKey().getRowData(); } byte[] val = entry.getValue().get(); Field field = fieldMap.get(getFieldName(entry)); if (currentMap != null) { if (currentFam.equals(entry.getKey().getColumnFamily())) { currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get())); continue; } else { persistent.put(currentPos, currentMap); currentMap = null; } } else if (currentArray != null) { if (currentFam.equals(entry.getKey().getColumnFamily())) { currentArray.add(fromBytes(currentSchema, entry.getValue().get())); continue; } else { persistent.put(currentPos, new GenericData.Array<T>(currentField.schema(), currentArray)); currentArray = null; } } switch(field.schema().getType()) { case // first entry only. Next are handled above on the next loop MAP: currentMap = new DirtyMapWrapper<>(new HashMap<Utf8, Object>()); currentPos = field.pos(); currentFam = entry.getKey().getColumnFamily(); currentSchema = field.schema().getValueType(); currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get())); break; case ARRAY: currentArray = new DirtyListWrapper<>(new ArrayList<>()); currentPos = field.pos(); currentFam = entry.getKey().getColumnFamily(); currentSchema = field.schema().getElementType(); currentField = field; currentArray.add(fromBytes(currentSchema, entry.getValue().get())); break; case // default value of null acts like union with null UNION: Schema effectiveSchema = field.schema().getTypes().get(firstNotNullSchemaTypeIndex(field.schema())); // map and array were coded without union index so need to be read the same way if (effectiveSchema.getType() == Type.ARRAY) { currentArray = new DirtyListWrapper<>(new ArrayList<>()); currentPos = field.pos(); currentFam = entry.getKey().getColumnFamily(); currentSchema = field.schema().getElementType(); currentField = field; currentArray.add(fromBytes(currentSchema, entry.getValue().get())); break; } else if (effectiveSchema.getType() == Type.MAP) { currentMap = new DirtyMapWrapper<>(new HashMap<Utf8, Object>()); currentPos = field.pos(); currentFam = entry.getKey().getColumnFamily(); currentSchema = effectiveSchema.getValueType(); currentMap.put(new Utf8(entry.getKey().getColumnQualifierData().toArray()), fromBytes(currentSchema, entry.getValue().get())); break; } // continue like a regular top-level union case RECORD: SpecificDatumReader<?> reader = new SpecificDatumReader<Schema>(field.schema()); persistent.put(field.pos(), reader.read(null, DecoderFactory.get().binaryDecoder(val, decoder))); break; default: persistent.put(field.pos(), fromBytes(field.schema(), entry.getValue().get())); } } if (currentMap != null) { persistent.put(currentPos, currentMap); } else if (currentArray != null) { persistent.put(currentPos, new GenericData.Array<T>(currentField.schema(), currentArray)); } persistent.clearDirty(); return row; }
5. OsmProvider#nodesFromAccumulo()
Project: geowave
File: OsmProvider.java
File: OsmProvider.java
private Map<Long, Coordinate> nodesFromAccumulo(List<Long> vals) { List<Range> ranges = new ArrayList<>(vals.size()); for (Long l : vals) { byte[] row = Schema.getIdHash(l); ranges.add(new Range(new Text(row))); // ranges.add(new Range(l.toString())); } ranges = Range.mergeOverlapping(ranges); bs.setRanges(ranges); bs.clearColumns(); // bs.fetchColumnFamily(new Text(Schema.CF.NODE)); bs.fetchColumn(new Text(Schema.CF.NODE), new Text(Schema.CQ.LONGITUDE)); bs.fetchColumn(new Text(Schema.CF.NODE), new Text(Schema.CQ.LATITUDE)); bs.fetchColumn(new Text(Schema.CF.NODE), new Text(Schema.CQ.ID)); Map<Long, Coordinate> coords = new HashMap<>(); long id = -1; Coordinate crd = new Coordinate(-1, -1); ByteSequence lastkey = null; for (Map.Entry<Key, Value> row : bs) { if (lastkey == null) { lastkey = row.getKey().getRowData(); } if (Schema.arraysEqual(row.getKey().getColumnQualifierData(), Schema.CQ.LONGITUDE)) { crd.x = doubleReader.readField(row.getValue().get()); } else if (Schema.arraysEqual(row.getKey().getColumnQualifierData(), Schema.CQ.LATITUDE)) { crd.y = doubleReader.readField(row.getValue().get()); } else if (Schema.arraysEqual(row.getKey().getColumnQualifierData(), Schema.CQ.ID)) { id = longReader.readField(row.getValue().get()); } if (id != -1 && crd.x != -1 && crd.y != -1) { coords.put(id, crd); id = -1; crd = new Coordinate(-1, -1); lastkey = null; } else if (!lastkey.equals(row.getKey().getRowData())) { id = -1; crd = new Coordinate(-1, -1); lastkey = null; } } return coords; }
6. OsmProvider#waysFromAccumulo()
Project: geowave
File: OsmProvider.java
File: OsmProvider.java
private Map<String, List<LinearRing>> waysFromAccumulo(Map<Integer, SimpleFeatureGenerator.RelationSet> relations, SimpleFeatureGenerator.OSMUnion osmunion) { Map<String, List<LinearRing>> rings = new HashMap<>(); rings.put("inner", new ArrayList<LinearRing>()); rings.put("outer", new ArrayList<LinearRing>()); List<Long> outerWays = new ArrayList<>(); List<Long> innerWays = new ArrayList<>(); for (Map.Entry<Integer, SimpleFeatureGenerator.RelationSet> kvp : relations.entrySet()) { switch(kvp.getValue().memType) { case RELATION: { LOGGER.warn("Super-relations not currently supported"); return null; } case WAY: { if ("outer".equals(kvp.getValue().roleId)) { outerWays.add(kvp.getValue().memId); } else if ("inner".equals(kvp.getValue().roleId)) { innerWays.add(kvp.getValue().memId); } break; } case NODE: { LOGGER.warn("Nodes as direct members of relationships not currently supported"); return null; } } } List<Range> ranges = new ArrayList<>(outerWays.size() + innerWays.size()); if (ranges.size() == 0) { LOGGER.warn("No multipolygon relations found for relation: " + osmunion.Id); return null; } for (Long l : outerWays) { byte[] row = Schema.getIdHash(l); ranges.add(new Range(new Text(row))); } for (Long l : innerWays) { byte[] row = Schema.getIdHash(l); ranges.add(new Range(new Text(row))); } bs.setRanges(ranges); bs.clearColumns(); bs.fetchColumn(new Text(Schema.CF.WAY), new Text(Schema.CQ.ID)); bs.fetchColumn(new Text(Schema.CF.WAY), new Text(Schema.CQ.REFERENCES)); Map<Long, List<Long>> vals = new HashMap<>(); long id = -1; List<Long> tvals = null; ByteSequence lastkey = null; for (Map.Entry<Key, Value> row : bs) { if (lastkey == null) { lastkey = row.getKey().getRowData(); } if (Schema.arraysEqual(row.getKey().getColumnQualifierData(), Schema.CQ.ID)) { id = longReader.readField(row.getValue().get()); } else if (Schema.arraysEqual(row.getKey().getColumnQualifierData(), Schema.CQ.REFERENCES)) { try { tvals = TypeUtils.deserializeLongArray(row.getValue().get(), null).getIds(); } catch (IOException e) { LOGGER.error("Error deserializing member array for way: "); } } if (id != -1 && tvals != null) { vals.put(id, tvals); tvals = null; id = -1; lastkey = null; } else if (!lastkey.equals(row.getKey().getRowData())) { tvals = null; id = -1; lastkey = null; } } for (Map.Entry<Long, List<Long>> kvp : vals.entrySet()) { Map<Long, Coordinate> ring = nodesFromAccumulo(kvp.getValue()); Coordinate[] sortedCoords = new Coordinate[ring.size()]; List<String> missingIds = new ArrayList<>(); int i = 0; for (long l : kvp.getValue()) { sortedCoords[i] = ring.get(l); if (sortedCoords[i] == null) { missingIds.add(String.valueOf(l)); } i++; } if (missingIds.size() != 0) { LOGGER.error("Error building ring relation for relation: " + osmunion.Id + " missing values were: (" + Joiner.on(",").join(missingIds) + ")"); return null; } if (sortedCoords[0] != sortedCoords[sortedCoords.length - 1]) { // ring not closed, should be by definition -f ix Coordinate[] closedCords = Arrays.copyOf(sortedCoords, sortedCoords.length + 1); closedCords[sortedCoords.length + 1] = closedCords[0]; sortedCoords = closedCords; } if (sortedCoords.length < 4) { LOGGER.error("Not enough coordinates for way: " + kvp.getKey() + " for relation: " + osmunion.Id); return null; } LinearRing lr = GeometryUtils.GEOMETRY_FACTORY.createLinearRing(sortedCoords); if (innerWays.contains(kvp.getKey())) { rings.get("inner").add(lr); } else if (outerWays.contains(kvp.getKey())) { rings.get("outer").add(lr); } else { LOGGER.error("Relation not found in inner or outer for way: " + kvp.getKey()); return null; } } return rings; }