use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class SparqlToPigTransformVisitorTest method testMutlipleJoins.
public void testMutlipleJoins() throws Exception {
String query = "select * where {\n" + "?subj <urn:lubm:rdfts#name> 'Department0'.\n" + "?subj <urn:lubm:rdfts#subOrganizationOf> <http://www.University0.edu>.\n" + "?subj <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:lubm:rdfts#Department>.\n" + "}";
// System.out.println(query);
QueryParser parser = new SPARQLParser();
ParsedQuery parsedQuery = parser.parseQuery(query, null);
// System.out.println(parsedQuery);
SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
visitor.setTablePrefix(tablePrefix);
visitor.setInstance(instance);
visitor.setZk(zk);
visitor.setUser(user);
visitor.setPassword(password);
visitor.meet(new QueryRoot(parsedQuery.getTupleExpr()));
// System.out.println(visitor.getPigScript());
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class SparqlToPigTransformVisitorTest method testLimit.
public void testLimit() throws Exception {
String query = "select * where {\n" + "?subj <urn:lubm:rdfts#name> 'Department0'.\n" + "?subj <urn:lubm:rdfts#subOrganizationOf> ?suborg.\n" + "} limit 100";
// System.out.println(query);
QueryParser parser = new SPARQLParser();
ParsedQuery parsedQuery = parser.parseQuery(query, null);
// System.out.println(parsedQuery);
SparqlToPigTransformVisitor visitor = new SparqlToPigTransformVisitor();
visitor.setTablePrefix(tablePrefix);
visitor.setInstance(instance);
visitor.setZk(zk);
visitor.setUser(user);
visitor.setPassword(password);
visitor.meet(new QueryRoot(parsedQuery.getTupleExpr()));
// System.out.println(visitor.getPigScript());
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class IndexWritingTool method setVarOrders.
public void setVarOrders(final String s, final Configuration conf) throws MalformedQueryException {
final SPARQLParser parser = new SPARQLParser();
final TupleExpr query = parser.parseQuery(s, null).getTupleExpr();
final List<String> projList = Lists.newArrayList(((Projection) query).getProjectionElemList().getTargetNames());
final String projElems = Joiner.on(";").join(projList);
conf.set("projElems", projElems);
final Pattern splitPattern1 = Pattern.compile("\n");
final Pattern splitPattern2 = Pattern.compile(",");
final String[] lines = splitPattern1.split(s);
final List<String> varOrders = Lists.newArrayList();
final List<String> varOrderPos = Lists.newArrayList();
int orderNum = 0;
final int projSizeSq = projList.size() * projList.size();
for (String t : lines) {
if (orderNum > projSizeSq) {
break;
}
String[] order = null;
if (t.startsWith("#prefix")) {
t = t.substring(7).trim();
order = splitPattern2.split(t, projList.size());
}
String tempVarOrder = "";
String tempVarOrderPos = "";
if (order != null) {
for (final String u : order) {
if (tempVarOrder.length() == 0) {
tempVarOrder = u.trim();
} else {
tempVarOrder = tempVarOrder + ";" + u.trim();
}
final int pos = projList.indexOf(u.trim());
if (pos < 0) {
throw new IllegalArgumentException("Invalid variable order!");
} else {
if (tempVarOrderPos.length() == 0) {
tempVarOrderPos = tempVarOrderPos + pos;
} else {
tempVarOrderPos = tempVarOrderPos + ";" + pos;
}
}
}
varOrders.add(tempVarOrder);
varOrderPos.add(tempVarOrderPos);
}
if (tempVarOrder.length() > 0) {
orderNum++;
}
}
if (orderNum == 0) {
varOrders.add(projElems);
String tempVarPos = "";
for (int i = 0; i < projList.size(); i++) {
if (i == 0) {
tempVarPos = Integer.toString(0);
} else {
tempVarPos = tempVarPos + ";" + i;
}
}
varOrderPos.add(tempVarPos);
}
final String[] vOrders = varOrders.toArray(new String[varOrders.size()]);
final String[] vOrderPos = varOrderPos.toArray(new String[varOrderPos.size()]);
conf.setStrings("varOrders", vOrders);
conf.setStrings("varOrderPos", vOrderPos);
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThreeSingleNodeIndex.
@Test
public void testThreeSingleNodeIndex() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q19, null);
ParsedQuery pq2 = parser.parseQuery(q20, null);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup1);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(3, indexSet.size());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
int size = 0;
while (processedTups.hasNext()) {
Assert.assertTrue(processedTups.hasNext());
processedTups.next();
size++;
}
Assert.assertTrue(!processedTups.hasNext());
Assert.assertEquals(3, size);
}
use of org.openrdf.query.parser.sparql.SPARQLParser in project incubator-rya by apache.
the class IndexedExecutionPlanGeneratorTest method testThreeIndexQuery.
@Test
public void testThreeIndexQuery() throws Exception {
SPARQLParser parser = new SPARQLParser();
ParsedQuery pq1 = parser.parseQuery(q16, null);
ParsedQuery pq2 = parser.parseQuery(q17, null);
ParsedQuery pq3 = parser.parseQuery(q18, null);
SimpleExternalTupleSet extTup1 = new SimpleExternalTupleSet((Projection) pq2.getTupleExpr());
SimpleExternalTupleSet extTup2 = new SimpleExternalTupleSet((Projection) pq3.getTupleExpr());
List<ExternalTupleSet> list = new ArrayList<ExternalTupleSet>();
list.add(extTup2);
list.add(extTup1);
IndexedExecutionPlanGenerator iep = new IndexedExecutionPlanGenerator(pq1.getTupleExpr(), list);
List<ExternalTupleSet> indexSet = iep.getNormalizedIndices();
Assert.assertEquals(6, indexSet.size());
Iterator<TupleExpr> processedTups = iep.getIndexedTuples();
int size = 0;
while (processedTups.hasNext()) {
Assert.assertTrue(processedTups.hasNext());
processedTups.next();
size++;
}
Assert.assertTrue(!processedTups.hasNext());
Assert.assertEquals(9, size);
}
Aggregations