Пример #1
0
  private void writeInlineEdge(
      DataOutput out, InternalRelation edge, TitanType type, boolean writeEdgeType) {
    assert type.isSimple();
    assert writeEdgeType
        || type.isEdgeLabel()
        || (type.isPropertyKey() && !hasGenericDataType((TitanKey) type));

    if (edge == null) {
      assert !writeEdgeType;
      if (type.isPropertyKey()) {
        out.writeObject(null);
      } else {
        assert type.isEdgeLabel();
        VariableLong.writePositive(out, 0);
      }
    } else {
      if (writeEdgeType) {
        IDHandler.writeInlineEdgeType(out, type.getID(), idManager);
      }
      if (edge.isProperty()) {
        Object attribute = ((TitanProperty) edge).getAttribute();
        if (hasGenericDataType((TitanKey) type)) out.writeClassAndObject(attribute);
        else out.writeObject(attribute);
      } else {
        assert edge.isUnidirected() && edge.isEdge();
        VariableLong.writePositive(out, edge.getVertex(1).getID());
      }
    }
  }
Пример #2
0
  @Override
  public AbstractLongList getRawNeighborhood(AtomicQuery query, InternalTitanTransaction tx) {
    Preconditions.checkArgument(
        QueryUtil.queryCoveredByDiskIndexes(query),
        "Raw retrieval is currently does not support in-memory filtering");
    List<Entry> entries = queryForEntries(query, tx.getTxHandle());

    InternalTitanVertex node = query.getNode();
    TitanType titanType = null;
    if (query.hasEdgeTypeCondition()) titanType = query.getTypeCondition();

    AbstractLongList result = new LongArrayList();

    for (Entry entry : entries) {
      if (!query.hasEdgeTypeCondition()) {
        long etid = IDHandler.readEdgeType(entry.getColumn(), idManager);
        if (titanType == null || titanType.getID() != etid) {
          titanType = getTypeFromID(etid, tx);
        }
      }
      if (titanType.isPropertyKey() || (!titanType.isModifiable() && !query.queryUnmodifiable())) {
        continue; // Skip since it does not match query
      }
      // Get neighboring node id
      long iddiff = VariableLong.read(entry.getValue());
      long nghid = iddiff + node.getID();
      result.add(nghid);

      if (result.size() >= query.getLimit()) break;
    }
    return result;
  }
Пример #3
0
 private void createInlineEdge(VertexRelationLoader loader, TitanType type, Object entity) {
   if (entity != null) {
     if (type.isEdgeLabel()) {
       assert entity instanceof Long;
       loader.addRelationEdge((TitanLabel) type, (Long) entity);
     } else {
       assert type.isPropertyKey();
       loader.addRelationProperty((TitanKey) type, entity);
     }
   }
 }
Пример #4
0
 private Object readInline(ByteBuffer read, TitanType type) {
   if (type.isPropertyKey()) {
     TitanKey proptype = ((TitanKey) type);
     if (hasGenericDataType(proptype)) return serializer.readClassAndObject(read);
     else return serializer.readObject(read, proptype.getDataType());
   } else {
     assert type.isEdgeLabel();
     Long id = Long.valueOf(VariableLong.readPositive(read));
     if (id.longValue() == 0) return null;
     else return id;
   }
 }
Пример #5
0
  protected void loadRelations(
      Iterable<Entry> entries, VertexRelationLoader loader, InternalTitanTransaction tx) {
    Map<String, TitanType> etCache = new HashMap<String, TitanType>();
    TitanType titanType = null;

    for (Entry entry : entries) {
      ByteBuffer column = entry.getColumn();
      int dirID = IDHandler.getDirectionID(column.get(column.position()));
      long etid = IDHandler.readEdgeType(column, idManager);

      if (titanType == null || titanType.getID() != etid) {
        titanType = getTypeFromID(etid, tx);
      }

      Object[] keys = null;
      if (!titanType.isSimple()) {
        TypeDefinition def = ((InternalTitanType) titanType).getDefinition();
        String[] keysig = def.getKeySignature();
        keys = new Object[keysig.length];
        for (int i = 0; i < keysig.length; i++)
          keys[i] = readInline(column, getEdgeType(keysig[i], etCache, tx));
      }

      long edgeid = 0;
      if (!titanType.isFunctional()) {
        edgeid = VariableLong.readPositive(column);
      }

      ByteBuffer value = entry.getValue();
      if (titanType.isEdgeLabel()) {
        long nodeIDDiff = VariableLong.read(value);
        if (titanType.isFunctional()) edgeid = VariableLong.readPositive(value);
        assert edgeid > 0;
        long otherid = loader.getVertexId() + nodeIDDiff;
        assert dirID == 3 || dirID == 2;
        Direction dir = dirID == 3 ? Direction.IN : Direction.OUT;
        if (!tx.isDeletedRelation(edgeid))
          loader.loadEdge(edgeid, (TitanLabel) titanType, dir, otherid);
      } else {
        assert titanType.isPropertyKey();
        assert dirID == 0;
        TitanKey propType = ((TitanKey) titanType);
        Object attribute = null;

        if (hasGenericDataType(propType)) {
          attribute = serializer.readClassAndObject(value);
        } else {
          attribute = serializer.readObjectNotNull(value, propType.getDataType());
        }
        assert attribute != null;

        if (titanType.isFunctional()) edgeid = VariableLong.readPositive(value);
        assert edgeid > 0;
        if (!tx.isDeletedRelation(edgeid)) loader.loadProperty(edgeid, propType, attribute);
      }

      // Read value inline edges if any
      if (!titanType.isSimple()) {
        TypeDefinition def = ((InternalTitanType) titanType).getDefinition();
        // First create all keys buffered above
        String[] keysig = def.getKeySignature();
        for (int i = 0; i < keysig.length; i++) {
          createInlineEdge(loader, getEdgeType(keysig[i], etCache, tx), keys[i]);
        }

        // value signature
        for (String str : def.getCompactSignature())
          readLabel(loader, value, getEdgeType(str, etCache, tx));

        // Third: read rest
        while (value.hasRemaining()) {
          TitanType type =
              (TitanType) tx.getExistingVertex(IDHandler.readInlineEdgeType(value, idManager));
          readLabel(loader, value, type);
        }
      }
    }
  }