Search in sources :

Example 71 with BackendException

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

the class MysqlTable method queryNumber.

@Override
public Number queryNumber(Session session, Query query) {
    Aggregate aggregate = query.aggregateNotNull();
    Iterator<Number> results = this.query(session, query, (q, rs) -> {
        try {
            if (!rs.resultSet().next()) {
                return IteratorUtils.of(aggregate.defaultValue());
            }
            return IteratorUtils.of(rs.resultSet().getLong(1));
        } catch (SQLException e) {
            throw new BackendException(e);
        } finally {
            rs.close();
        }
    });
    return aggregate.reduce(results);
}
Also used : SQLException(java.sql.SQLException) Aggregate(com.baidu.hugegraph.backend.query.Aggregate) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 72 with BackendException

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

the class MysqlTable method query.

protected <R> Iterator<R> query(Session session, Query query, BiFunction<Query, ResultSetWrapper, Iterator<R>> parser) {
    ExtendableIterator<R> rs = new ExtendableIterator<>();
    if (query.limit() == 0L && !query.noLimit()) {
        LOG.debug("Return empty result(limit=0) for query {}", query);
        return rs;
    }
    List<StringBuilder> selections = this.query2Select(this.table(), query);
    try {
        for (StringBuilder selection : selections) {
            ResultSetWrapper results = session.select(selection.toString());
            rs.extend(parser.apply(query, results));
        }
    } catch (SQLException e) {
        throw new BackendException("Failed to query [%s]", e, query);
    }
    LOG.debug("Return {} for query {}", rs, query);
    return rs;
}
Also used : SQLException(java.sql.SQLException) ExtendableIterator(com.baidu.hugegraph.iterator.ExtendableIterator) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 73 with BackendException

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

the class RocksDBIngester method ingest.

public List<String> ingest(Path path, ColumnFamilyHandle cf) throws RocksDBException {
    SuffixFileVisitor visitor = new SuffixFileVisitor(SST);
    try {
        Files.walkFileTree(path, visitor);
    } catch (IOException e) {
        throw new BackendException("Failed to walk path '%s'", e, path);
    }
    List<Path> files = visitor.files();
    List<String> ssts = new ArrayList<>(files.size());
    for (Path file : files) {
        File sst = file.toFile();
        if (sst.exists() && sst.length() > 0L) {
            ssts.add(sst.getPath());
        }
    }
    this.ingest(cf, ssts);
    return ssts;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 74 with BackendException

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

the class RocksDBSstSessions method createTable.

private void createTable(String table) throws RocksDBException {
    String number = String.format("%04d", 1);
    Path sstFile = Paths.get(this.dataPath, table, number + RocksDBIngester.SST);
    try {
        FileUtils.forceMkdir(sstFile.getParent().toFile());
    } catch (IOException e) {
        throw new BackendException("Can't make directory for sst: '%s'", e, sstFile.toString());
    }
    EnvOptions env = new EnvOptions();
    Options options = new Options();
    RocksDBStdSessions.initOptions(this.config(), options, options, options, options);
    // NOTE: unset merge op due to SIGSEGV when cf.setMergeOperatorName()
    options.setMergeOperatorName("not-exist-merge-op");
    SstFileWriter sst = new SstFileWriter(env, options);
    sst.open(sstFile.toString());
    this.tables.put(table, sst);
}
Also used : Path(java.nio.file.Path) EnvOptions(org.rocksdb.EnvOptions) Options(org.rocksdb.Options) SstFileWriter(org.rocksdb.SstFileWriter) IOException(java.io.IOException) EnvOptions(org.rocksdb.EnvOptions) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 75 with BackendException

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

the class PostgresqlSessions method escapeAndWrapString.

public static String escapeAndWrapString(String value) {
    StringBuilder builder = new StringBuilder(8 + value.length());
    builder.append('\'');
    try {
        Utils.escapeLiteral(builder, value, false);
    } catch (SQLException e) {
        throw new BackendException("Failed to escape '%s'", e, value);
    }
    builder.append('\'');
    return builder.toString();
}
Also used : PSQLException(org.postgresql.util.PSQLException) SQLException(java.sql.SQLException) 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