Skip to content
gtessa edited this page Feb 13, 2016 · 4 revisions

The Simple Virtual Partitioning technique has mainly 3 steps:

Description

  1. Query analysis and subqueries creation: the input query is analyzed and rewritten in many subqueries with virtual partitioning predicate added;
  2. Subqueries execution: All the generated subqueries must be executed in database system instances available for it;
  3. Result composition: the results obtained from the subqueries need to be combined to produce the intended result to the input query

These steps were mapped into classes that makes the use of SVP much easier.

Query analysis and subqueries creation

The Partitioner class is the one used for this step. It can be used with a catalog file containing information from the queried database or it can use the database system directly to gather the necessary information to perform the analysis and create the fragments.

To use the Partitioner with a catalog file, you must open the catalog file as a stream and provide it to the object created (exception handling is omitted).

FileInputStream fis = new FileInputStream("/path/to/catalog/file.xml");
Partitioner partitioner = new Partitioner(fis);
fis.close();

List<String> fragments = partitioner.executePartitioning(query, N_FRAGMENTS);

To use Partitioner with the database system directly, you must indicate all the necessary information to establish the connection:

String host = "localhost"; // where the instance of XDBMS server running 
String port = 1984;        // the server port 
String username = "user";   
String password = "pass";
String dbname = "dbname";    // the database name you will be querying
String dbtype = "BASEX";     // which database system is this. Currently, BASEX and SEDNA are supported

FileInputStream fis = new FileInputStream(host, port, username, password, dbname, dbtype);
Partitioner partitioner = new Partitioner(fis);
fis.close();

List<String> fragments = partitioner.executePartitioning(query, N_FRAGMENTS);

Subqueries execution

In this step, one or more SubQueryExecutor instances must be created to execute each of the fragments obtained in the previous step. Those objects may be executed independently, and in parallel. Each result in written in a output stream, which can be a file, or a String. In the example below, it is written to a file (exception handling is omitted).

String host = "localhost"; // where the instance of XDBMS server running 
String port = 1984;        // the server port 
String username = "user";   
String password = "pass";
String dbname = "dbname";    // the database name you will be querying
String dbtype = "BASEX";     // which database system is this. Currently, BASEX and SEDNA are supported

SubQueryExecutor sqe = new SubQueryExecutor(fragment);
sqe.setDatabaseInfo(host, port, username, password, dbname, dbtype);

FileOutputStream fos = new FileOutputStream("/path/to/result.xml");
boolean hasResults = sqe.executeQuery(fos);
fos.flush();
fos.close();

Results composition

The results composition is executed using the FinalResultComposer object.

String host = "localhost"; // where the instance of XDBMS server running 
String port = 1984;        // the server port 
String username = "user";   
String password = "pass";
String dbname = "dbname";    // the database name you will be querying
String dbtype = "BASEX";     // which database system is this. Currently, BASEX and SEDNA are supported

FileOutputStream out = new FileOutputStream("/path/to/the/finalresult.xml");
FinalResultComposer frc = new FinalResultComposer(out);
frc.setDatabaseInfo(host, port, username, password, dbname, dbtype);
                
// Using a fragment as a way to restore execution context
ByteArrayInputStream contextStream = new ByteArrayInputStream(fragments.get(0).getBytes()); 
frc.setExecutionContext(ExecutionContext.restoreFromStream(contextStream));
contextStream.close();
                
List<String> partialFilenames = new ArrayList<String>();
partialFilenames.add("/path/to/partialresult.xml")
//...

for(String partial : partialFilenames) {
    FileInputStream fis = new FileInputStream(partial);
    frc.loadPartial(fis);
    fis.close();
}

frc.combinePartialResults();
out.flush();
out.close();