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);
}
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;
}
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;
}
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);
}
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();
}
Aggregations