use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class CLI method actionCreateTable.
/**
* Create a new table
* @param line
*/
protected void actionCreateTable(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Create table should be performed, but no table was specified");
printHelpAndExit();
}
final TupleStoreConfigurationBuilder ssTableConfigurationBuilder = TupleStoreConfigurationBuilder.create();
// Duplicates
if (line.hasOption(CLIParameter.DUPLICATES)) {
final String allowDuplicates = line.getOptionValue(CLIParameter.DUPLICATES);
final boolean duplicatesAllowed = MathUtil.tryParseBooleanOrExit(allowDuplicates, () -> "Unable to parse the bolean value for duplicates: " + allowDuplicates);
ssTableConfigurationBuilder.allowDuplicates(duplicatesAllowed);
}
// TTL
if (line.hasOption(CLIParameter.TTL)) {
final String ttlString = line.getOptionValue(CLIParameter.TTL);
final int ttl = MathUtil.tryParseIntOrExit(ttlString, () -> "Unable to parse the region size: " + ttlString);
ssTableConfigurationBuilder.withTTL(ttl, TimeUnit.MILLISECONDS);
}
// Versions
if (line.hasOption(CLIParameter.VERSIONS)) {
final String versionString = line.getOptionValue(CLIParameter.VERSIONS);
final int versions = MathUtil.tryParseIntOrExit(versionString, () -> "Unable to parse the region size: " + versionString);
ssTableConfigurationBuilder.withVersions(versions);
}
// Spatial index reader
if (line.hasOption(CLIParameter.SPATIAL_INDEX_READER)) {
final String spatialIndexReader = line.getOptionValue(CLIParameter.SPATIAL_INDEX_READER);
ssTableConfigurationBuilder.withSpatialIndexReader(spatialIndexReader);
}
// Spatial index writer
if (line.hasOption(CLIParameter.SPATIAL_INDEX_WRITER)) {
final String spatialIndexWriter = line.getOptionValue(CLIParameter.SPATIAL_INDEX_WRITER);
ssTableConfigurationBuilder.withSpatialIndexWriter(spatialIndexWriter);
}
final TupleStoreConfiguration configuration = ssTableConfigurationBuilder.build();
try {
final String table = line.getOptionValue(CLIParameter.TABLE);
final EmptyResultFuture resultFuture = bboxDbConnection.createTable(table, configuration);
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to create table: " + resultFuture.getAllMessages());
System.exit(-1);
}
} catch (BBoxDBException e) {
System.err.println("Got an exception while creating table: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class CLI method actionExecuteJoin.
/**
* Execute the given query
* @param line
*/
protected void actionExecuteJoin(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Query should be performed, but no table was specified");
printHelpAndExit();
}
if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
System.err.println("Bounding box is not given");
System.exit(-1);
}
try {
final String tables = line.getOptionValue(CLIParameter.TABLE);
final List<String> tableList = Arrays.asList(tables.split(":"));
System.out.println("Executing join query...");
final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
final JoinedTupleListFuture resultFuture = bboxDbConnection.queryJoin(tableList, boundingBox);
if (resultFuture == null) {
System.err.println("Unable to get query");
System.exit(-1);
}
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
System.exit(-1);
}
for (final JoinedTuple tuple : resultFuture) {
printJoinedTuple(tuple);
}
System.out.println("Join done");
} catch (BBoxDBException e) {
System.err.println("Got an exception while performing query: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class CLI method actionImportData.
/**
* Import data
* @param line
*/
protected void actionImportData(final CommandLine line) {
final List<String> requiredArgs = Arrays.asList(CLIParameter.FILE, CLIParameter.FORMAT, CLIParameter.TABLE);
checkRequiredArgs(requiredArgs);
final String filename = line.getOptionValue(CLIParameter.FILE);
final String format = line.getOptionValue(CLIParameter.FORMAT);
final String table = line.getOptionValue(CLIParameter.TABLE);
System.out.println("Importing file: " + filename);
final TupleFileReader tupleFile = new TupleFileReader(filename, format);
tupleFile.addTupleListener(t -> {
if (t == null) {
logger.error("Unable to parse line: " + tupleFile.getLastReadLine());
return;
}
if (tupleFile.getProcessedLines() % 1000 == 0) {
System.out.format("Read %d lines%n", tupleFile.getProcessedLines());
}
try {
final EmptyResultFuture result = bboxDbConnection.insertTuple(table, t);
pendingFutures.put(result);
} catch (BBoxDBException e) {
logger.error("Got exception while inserting tuple", e);
}
});
try {
tupleFile.processFile();
pendingFutures.waitForCompletion();
System.out.format("Successfully imported %d lines%n", tupleFile.getProcessedLines());
} catch (IOException e) {
logger.error("Got IO Exception while reading data", e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class CLI method actionExecuteQuery.
/**
* Execute the given query
* @param line
*/
protected void actionExecuteQuery(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Query should be performed, but no table was specified");
printHelpAndExit();
}
try {
final TupleListFuture resultFuture = buildQueryFuture(line);
if (resultFuture == null) {
System.err.println("Unable to get query");
System.exit(-1);
}
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
System.exit(-1);
}
for (final Tuple tuple : resultFuture) {
printTuple(tuple);
}
System.out.println("Query done");
} catch (BBoxDBException e) {
System.err.println("Got an exception while performing query: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
use of org.bboxdb.misc.BBoxDBException in project bboxdb by jnidzwetzki.
the class CLI method actionExecuteContinuousQuery.
/**
* Execute a continuous bounding box query
* @param line
*/
protected void actionExecuteContinuousQuery(final CommandLine line) {
if (!line.hasOption(CLIParameter.TABLE)) {
System.err.println("Query should be performed, but no table was specified");
printHelpAndExit();
}
try {
System.out.println("Executing continuous bounding box query...");
final String table = line.getOptionValue(CLIParameter.TABLE);
if (!line.hasOption(CLIParameter.BOUNDING_BOX)) {
System.err.println("Bounding box is not given");
System.exit(-1);
}
final BoundingBox boundingBox = getBoundingBoxFromArgs(line);
final TupleListFuture resultFuture = bboxDbConnection.queryBoundingBoxContinuous(table, boundingBox);
if (resultFuture == null) {
System.err.println("Unable to get query");
System.exit(-1);
}
resultFuture.waitForAll();
if (resultFuture.isFailed()) {
System.err.println("Unable to execute query: " + resultFuture.getAllMessages());
System.exit(-1);
}
for (final Tuple tuple : resultFuture) {
printTuple(tuple);
}
System.out.println("Query done");
} catch (BBoxDBException e) {
System.err.println("Got an exception while performing query: " + e);
System.exit(-1);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
}
Aggregations