Search in sources :

Example 6 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class RocksDBStore method mutate.

@Override
public void mutate(BackendMutation mutation) {
    Lock readLock = this.storeLock.readLock();
    readLock.lock();
    try {
        this.checkOpened();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Store {} mutation: {}", this.store, mutation);
        }
        for (HugeType type : mutation.types()) {
            Session session = this.session(type);
            for (Iterator<BackendAction> it = mutation.mutation(type); it.hasNext(); ) {
                this.mutate(session, it.next());
            }
        }
    } finally {
        readLock.unlock();
    }
}
Also used : BackendAction(com.baidu.hugegraph.backend.store.BackendAction) HugeType(com.baidu.hugegraph.type.HugeType) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) Session(com.baidu.hugegraph.backend.store.rocksdb.RocksDBSessions.Session)

Example 7 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class CassandraStore method query.

@Override
public Iterator<BackendEntry> query(Query query) {
    this.checkOpened();
    HugeType type = CassandraTable.tableType(query);
    String tableName = query.olap() ? this.olapTableName(type) : type.string();
    CassandraTable table = this.table(tableName);
    Iterator<BackendEntry> entries = table.query(this.session(), query);
    // Merge olap results as needed
    Set<Id> olapPks = query.olapPks();
    if (this.isGraphStore && !olapPks.isEmpty()) {
        List<Iterator<BackendEntry>> iterators = new ArrayList<>();
        for (Id pk : olapPks) {
            Query q = query.copy();
            table = this.table(this.olapTableName(pk));
            iterators.add(table.query(this.session(), q));
        }
        entries = new MergeIterator<>(entries, iterators, BackendEntry::mergeable);
    }
    return entries;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) Iterator(java.util.Iterator) MergeIterator(com.baidu.hugegraph.backend.serializer.MergeIterator) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType)

Example 8 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class BinarySerializer method writeIndex.

@Override
public BackendEntry writeIndex(HugeIndex index) {
    BinaryBackendEntry entry;
    if (index.fieldValues() == null && index.elementIds().size() == 0) {
        /*
             * When field-values is null and elementIds size is 0, it is
             * meaningful for deletion of index data by index label.
             * TODO: improve
             */
        entry = this.formatILDeletion(index);
    } else {
        Id id = index.id();
        HugeType type = index.type();
        byte[] value = null;
        if (!type.isNumericIndex() && indexIdLengthExceedLimit(id)) {
            id = index.hashId();
            // Save field-values as column value if the key is a hash string
            value = StringEncoding.encode(index.fieldValues().toString());
        }
        entry = newBackendEntry(type, id);
        if (index.indexLabel().olap()) {
            entry.olap(true);
        }
        entry.column(this.formatIndexName(index), value);
        entry.subId(index.elementId());
        if (index.hasTtl()) {
            entry.ttl(index.ttl());
        }
    }
    return entry;
}
Also used : BinaryId(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) HugeType(com.baidu.hugegraph.type.HugeType)

Example 9 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class TraversalUtil method fillConditionQuery.

public static ConditionQuery fillConditionQuery(ConditionQuery query, List<HasContainer> hasContainers, HugeGraph graph) {
    HugeType resultType = query.resultType();
    for (HasContainer has : hasContainers) {
        Condition condition = convHas2Condition(has, resultType, graph);
        query.query(condition);
    }
    return query;
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) HugeType(com.baidu.hugegraph.type.HugeType)

Example 10 with HugeType

use of com.baidu.hugegraph.type.HugeType in project incubator-hugegraph by apache.

the class HbaseTable method newEntryIterator.

protected BackendEntryIterator newEntryIterator(Query query, RowIterator rows) {
    return new BinaryEntryIterator<>(rows, query, (entry, row) -> {
        E.checkState(!row.isEmpty(), "Can't parse empty HBase result");
        byte[] id = row.getRow();
        if (entry == null || !Bytes.prefixWith(id, entry.id().asBytes())) {
            HugeType type = query.resultType();
            // NOTE: only support BinaryBackendEntry currently
            entry = new BinaryBackendEntry(type, id, this.enablePartition);
        }
        try {
            this.parseRowColumns(row, entry, query, this.enablePartition);
        } catch (IOException e) {
            throw new BackendException("Failed to read HBase columns", e);
        }
        return entry;
    });
}
Also used : BinaryEntryIterator(com.baidu.hugegraph.backend.serializer.BinaryEntryIterator) BinaryBackendEntry(com.baidu.hugegraph.backend.serializer.BinaryBackendEntry) IOException(java.io.IOException) HugeType(com.baidu.hugegraph.type.HugeType) BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

HugeType (com.baidu.hugegraph.type.HugeType)34 Id (com.baidu.hugegraph.backend.id.Id)16 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)5 Query (com.baidu.hugegraph.backend.query.Query)4 ExistedException (com.baidu.hugegraph.exception.ExistedException)4 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)4 ArrayList (java.util.ArrayList)4 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)3 Condition (com.baidu.hugegraph.backend.query.Condition)3 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)3 BinaryBackendEntry (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry)3 BinaryId (com.baidu.hugegraph.backend.serializer.BinaryBackendEntry.BinaryId)3 BackendAction (com.baidu.hugegraph.backend.store.BackendAction)3 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)3 Lock (java.util.concurrent.locks.Lock)3 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)3 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)3 HugeException (com.baidu.hugegraph.HugeException)2 BackendException (com.baidu.hugegraph.backend.BackendException)2 BinaryEntryIterator (com.baidu.hugegraph.backend.serializer.BinaryEntryIterator)2