Search in sources :

Example 41 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class CassandraTable method setPageState.

protected void setPageState(Query query, List<Select> selects) {
    if (query.noLimit() && !query.paging()) {
        return;
    }
    for (Select select : selects) {
        int total = (int) query.total();
        if (!query.noLimit()) {
            E.checkArgument(total == query.total(), "Invalid query limit %s", query.limit());
        } else {
            assert total == -1 : total;
        }
        String page = query.page();
        if (page == null) {
            // Set limit
            assert total > 0 : total;
            select.limit(total);
        } else {
            /*
                 * NOTE: the `total` may be -1 when query.noLimit(),
                 * setFetchSize(-1) means the default fetch size will be used.
                 */
            assert total > 0 || total == -1 : total;
            select.setFetchSize(total);
            // It's the first time if page is empty, skip setPagingState
            if (!page.isEmpty()) {
                byte[] position = PageState.fromString(page).position();
                try {
                    select.setPagingState(PagingState.fromBytes(position));
                } catch (PagingStateException e) {
                    throw new BackendException(e);
                }
            }
        }
    }
}
Also used : PagingStateException(com.datastax.driver.core.exceptions.PagingStateException) Select(com.datastax.driver.core.querybuilder.Select) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 42 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class CassandraTable method condition2Cql.

protected Clause condition2Cql(Condition condition) {
    switch(condition.type()) {
        case AND:
            Condition.And and = (Condition.And) condition;
            Clause left = condition2Cql(and.left());
            Clause right = condition2Cql(and.right());
            return Clauses.and(left, right);
        case OR:
            throw new BackendException("Not support OR currently");
        case RELATION:
            Condition.Relation r = (Condition.Relation) condition;
            return relation2Cql(r);
        default:
            final String msg = "Unsupported condition: " + condition;
            throw new AssertionError(msg);
    }
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) Relation(com.baidu.hugegraph.backend.query.Condition.Relation) Clause(com.datastax.driver.core.querybuilder.Clause) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 43 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class TableSerializer method parseProperty.

protected void parseProperty(Id key, Object colValue, HugeElement owner) {
    // Get PropertyKey by PropertyKey id
    PropertyKey pkey = owner.graph().propertyKey(key);
    // Parse value
    Object value = this.readProperty(pkey, colValue);
    // Set properties of vertex/edge
    if (pkey.cardinality() == Cardinality.SINGLE) {
        owner.addProperty(pkey, value);
    } else {
        if (!(value instanceof Collection)) {
            throw new BackendException("Invalid value of non-single property: %s", value);
        }
        owner.addProperty(pkey, value);
    }
}
Also used : Collection(java.util.Collection) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 44 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class TextSerializer method parseProperty.

private void parseProperty(String colName, String colValue, HugeElement owner) {
    String[] colParts = SplicingIdGenerator.split(colName);
    assert colParts.length == 2 : colName;
    // Get PropertyKey by PropertyKey id
    PropertyKey pkey = owner.graph().propertyKey(readId(colParts[1]));
    // Parse value
    Object value = JsonUtil.fromJson(colValue, pkey.implementClazz());
    // Set properties of vertex/edge
    if (pkey.cardinality() == Cardinality.SINGLE) {
        owner.addProperty(pkey, value);
    } else {
        if (!(value instanceof Collection)) {
            throw new BackendException("Invalid value of non-single property: %s", colValue);
        }
        for (Object v : (Collection<?>) value) {
            v = JsonUtil.castNumber(v, pkey.dataType().clazz());
            owner.addProperty(pkey, v);
        }
    }
}
Also used : Collection(java.util.Collection) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 45 with BackendException

use of com.baidu.hugegraph.backend.BackendException in project incubator-hugegraph by apache.

the class RaftClosure method run.

@Override
public void run(Status status) {
    if (status.isOk()) {
        this.complete(status);
    } else {
        LOG.error("Failed to apply command: {}", status);
        String msg = "Failed to apply command in raft node with error: " + status.getErrorMsg();
        this.failure(status, new BackendException(msg));
    }
}
Also used : BackendException(com.baidu.hugegraph.backend.BackendException)

Aggregations

BackendException (com.baidu.hugegraph.backend.BackendException)79 SQLException (java.sql.SQLException)15 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)6 Status (com.alipay.sofa.jraft.Status)5 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 BytesBuffer (com.baidu.hugegraph.backend.serializer.BytesBuffer)4 Path (java.nio.file.Path)4 Random (java.util.Random)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 RocksDBException (org.rocksdb.RocksDBException)4 HugeGraph (com.baidu.hugegraph.HugeGraph)3 Id (com.baidu.hugegraph.backend.id.Id)3 Query (com.baidu.hugegraph.backend.query.Query)3 HugeConfig (com.baidu.hugegraph.config.HugeConfig)3 Map (java.util.Map)3 ReadIndexClosure (com.alipay.sofa.jraft.closure.ReadIndexClosure)2 Condition (com.baidu.hugegraph.backend.query.Condition)2 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)2