Java Code Examples for org.apache.jena.sparql.syntax.ElementGroup#addElement()

The following examples show how to use org.apache.jena.sparql.syntax.ElementGroup#addElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ARQTest.java    From tarql with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testQueryAddValuesInQueryPattern() {
	List<Var> header = vars("a", "b");
	Binding b1 = binding(header, "1", "2");
	Binding b2 = binding(header, "3", "4");

	Query q = QueryFactory.create("SELECT * {}");
	ElementGroup group = new ElementGroup();
	ElementData table = new ElementData();
	table.add(Var.alloc("a"));
	table.add(Var.alloc("b"));
	table.add(b1);
	table.add(b2);
	group.addElement(q.getQueryPattern());
	group.addElement(table);
	q.setQueryPattern(group);
	ResultSet rs = QueryExecutionFactory.create(q, 
			ModelFactory.createDefaultModel()).execSelect();

	assertEquals(Arrays.asList(new String[]{"a","b"}), rs.getResultVars());
	assertTrue(rs.hasNext());
	assertEquals(b1, rs.nextBinding());
	assertTrue(rs.hasNext());
	assertEquals(b2, rs.nextBinding());
	assertFalse(rs.hasNext());
}
 
Example 2
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 6 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * SELECT ?subject ?predicate ?object
 * WHERE { GRAPH fromGraphName { ?subject ?predicate ?object } }
 * </code></pre>
 */
private Stream<Quad> fetchAllFromGraph(final String fromGraphName, final IRI toGraphName) {
    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(SUBJECT);
    q.addResultVar(PREDICATE);
    q.addResultVar(OBJECT);

    final ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(create(SUBJECT, PREDICATE, OBJECT));

    final ElementGroup elg = new ElementGroup();
    elg.addElement(new ElementNamedGraph(createURI(fromGraphName), epb));

    q.setQueryPattern(elg);

    final Stream.Builder<Quad> builder = builder();
    rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(toGraphName,
                    getSubject(qs), getPredicate(qs), getObject(qs))));
    return builder.build();
}
 
Example 3
Source File: labelSearch.java    From xcurator with Apache License 2.0 6 votes vote down vote up
private QueryIterator buildSyntax(QueryIterator input, Node nodeVar, String pattern, ExecutionContext execCxt)
{
    Var var2 = createNewVar() ; 
    // Triple patterns for   ?x rdfs:label ?hiddenVar
    ElementTriplesBlock elementBGP = new ElementTriplesBlock();
    Triple t = new Triple(nodeVar, RDFS.label.asNode(), var2) ;
    elementBGP.addTriple(t) ;
    
    // Regular expression for  regex(?hiddenVar, "pattern", "i") 
    Expr regex = new E_Regex(new ExprVar(var2.getName()), pattern, "i") ;
    
    ElementGroup elementGroup = new ElementGroup() ;
    elementGroup.addElement(elementBGP) ;
    elementGroup.addElement(new ElementFilter(regex)) ;
    // Compile it.
    // The better design is to build the Op structure programmatically,
    Op op = Algebra.compile(elementGroup) ;
    op = Algebra.optimize(op, execCxt.getContext()) ;
    return QC.execute(op, input, execCxt) ;
}
 
Example 4
Source File: SelectExtractionVisitor.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public void visitQueryPattern(final Query query) {
    if (query.getQueryPattern() == null || ((ElementGroup) query.getQueryPattern()).isEmpty()) {
        output.setQueryPattern(new ElementGroup());
        return;
    }
	isDummyQuery = false;
    if (output.getQueryPattern() != null) {
        ElementGroup group = new ElementGroup();
        group.addElement(query.getQueryPattern());
        group.addElement(output.getQueryPattern());
        output.setQueryPattern(group);
    } else {
        Element el = query.getQueryPattern();
        output.setQueryPattern(el);
    }
}
 
Example 5
Source File: TriplestoreResourceService.java    From trellis with Apache License 2.0 6 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * WITH trellis:PreferServerManaged
 *   DELETE { IDENTIFIER dc:modified ?time }
 *   INSERT { IDENTIFIER dc:modified TIME }
 *   WHERE { IDENTIFIER dc:modified ?time } .
 * </code></pre></p>
 */
private UpdateRequest buildUpdateModificationRequest(final IRI identifier, final Literal time) {
    final UpdateRequest req = new UpdateRequest();
    final Var modified = Var.alloc(MODIFIED);
    final UpdateDeleteInsert modify = new UpdateDeleteInsert();
    modify.setWithIRI(toJena(PreferServerManaged));
    modify.getDeleteAcc().addTriple(triple(toJena(identifier), toJena(DC.modified), modified));
    modify.getInsertAcc().addTriple(triple(toJena(identifier), toJena(DC.modified), toJena(time)));
    final ElementGroup eg = new ElementGroup();
    final ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(triple(toJena(identifier), toJena(DC.modified), modified));
    eg.addElement(epb);
    modify.setElement(eg);
    req.add(modify);
    return req;
}
 
Example 6
Source File: QueryPatternNormalizer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup el) {
    final ElementGroup res = new ElementGroup();
    for (final Element element : el.getElements()) {
        element.visit(this);
        res.addElement(result);
    }
    result = res;
}
 
Example 7
Source File: RuleSystemToUnionQuery.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup group) {
	ElementGroup ret = new ElementGroup();
	for (Element elt: group.getElements() ) {
		elt.visit(this);
		ret.addElement(result);
	}
	result = ret;
}
 
Example 8
Source File: QueryPatternSimplification.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void visit(ElementGroup group) {
	//remove nested groups
	ElementGroup ret = new ElementGroup();
	ElementPathBlock pathBlock = new ElementPathBlock();
	for (Element elt: group.getElements()) {
		elt.visit(this);
		if (result instanceof ElementGroup) {
			ElementGroup subgroup = (ElementGroup) result;
			// add the subgroup content directly
			add(ret, pathBlock, subgroup);
		} else if (result instanceof ElementPathBlock) {
			if (pathBlock.isEmpty()) {
				ret.addElement(pathBlock);
			}
			add(pathBlock, (ElementPathBlock) result);
		} else if (result instanceof ElementTriplesBlock) {
			if (pathBlock.isEmpty()) {
				ret.addElement(pathBlock);
			}
			add(pathBlock, (ElementTriplesBlock) result);
			
		} else {
			ret.addElement(result);
		}
		
	}
	if (ret.getElements().size() == 1) {
		result = ret.getElements().get(0);
	} else {
		result = ret;
	}
}
 
Example 9
Source File: SelectPlan.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private void augmentQuery(final Query q, final List<Var> variables, final List<Binding> values) {
	if (variables.isEmpty()) {
		return;
	}
	ElementGroup old = (ElementGroup) q.getQueryPattern();
	ElementGroup newQueryPattern = new ElementGroup();
	q.setQueryPattern(newQueryPattern);
	if (old.size() >= 1 && old.get(0) instanceof ElementData) {
		ElementData qData = (ElementData) old.get(0);
		int oldSize = qData.getRows().size();
		qData = mergeValues(qData, variables, values);
		newQueryPattern.addElement(qData);
		for (int i = 1; i < old.size(); i++) {
			newQueryPattern.addElement(old.get(i));
		}
		LOG.debug("New query has " + qData.getRows().size() + " initial values. It had " + oldSize
				+ " values before");
	} else {
		ElementData data = new ElementData();
		variables.forEach(data::add);
		values.forEach(data::add);
		newQueryPattern.addElement(data);
		old.getElements().forEach(newQueryPattern::addElement);
		// unexplainable, but did happen
		check(data, values);
	}
}
 
Example 10
Source File: QueryPatternNormalizer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private void endVisit(Element nzed, NodeExprNormalizer nenzer) {
    if (!nenzer.hasBindings()) {
        result = nzed;
    } else {
        ElementGroup group = nenzer.getBindingsAsGroup();
        group.addElement(nzed);
        result = group;
    }
}
 
Example 11
Source File: ElementTransformSPARQLStarTest.java    From RDFstarTools with Apache License 2.0 5 votes vote down vote up
protected ElementGroup mergeElementPathBlocks( ElementGroup eg )
{
	if ( eg.size() == 1 )
		return eg;

	final ElementGroup result = new ElementGroup();

	final Iterator<Element> it = eg.getElements().iterator();
	Element prevEl = it.next();

	while ( it.hasNext() )
	{
		final Element currEl = it.next();
		if (    (currEl instanceof ElementPathBlock)
		     && (prevEl instanceof ElementPathBlock) )
		{
			final ElementPathBlock currPB = (ElementPathBlock) currEl;
			final ElementPathBlock prevPB = (ElementPathBlock) prevEl;
			prevPB.getPattern().addAll( currPB.getPattern() );
		}
		else {
			result.addElement(prevEl);
			prevEl = currEl;
		}
	}

	result.addElement(prevEl);

	return result;
}
 
Example 12
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * SELECT ?object ?type
 * WHERE {
 *   GRAPH trellis:PreferServerManaged {
 *      ?object dc:isPartOf IDENTIFIER .
 *      ?object rdf:type ?type .
 *   }
 * }
 * </code></pre>
 */
private Stream<Quad> fetchContainmentQuads() {
    if (getInteractionModel().getIRIString().endsWith("Container")) {
        final Query q = new Query();
        q.setQuerySelectType();
        q.addResultVar(OBJECT);
        q.addResultVar(TYPE);

        final ElementPathBlock epb = new ElementPathBlock();
        epb.addTriple(create(OBJECT, toJena(DC.isPartOf), toJena(identifier)));
        epb.addTriple(create(OBJECT, type.asNode(), TYPE));

        final ElementNamedGraph ng = new ElementNamedGraph(toJena(Trellis.PreferServerManaged), epb);

        final ElementGroup elg = new ElementGroup();
        elg.addElement(ng);
        q.setQueryPattern(elg);

        final Stream.Builder<Quad> builder = builder();
        final IRI ixnModel = getInteractionModel();
        final IRI subject = adjustIdentifier(identifier, ixnModel);
        rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferContainment,
                        subject, LDP.contains, adjustIdentifier((IRI) getObject(qs), getType(qs)))));
        return builder.build();
    }
    return Stream.empty();
}
 
Example 13
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * SELECT ?predicate ?object ?type
 * WHERE {
 *   GRAPH trellis:PreferServerManaged {
 *      IDENTIFIER dc:isPartOf ?subject .
 *      ?subject ldp:isMemberOfRelation ?predicate .
 *      ?subject ldp:membershipResource ?object .
 *      ?subject ldp:insertedContentRelation ldp:MemberSubject .
 *      ?object rdf:type ?type .
 *   }
 * }
 * </code></pre>
 */
private Stream<Quad> fetchDirectMemberQuadsInverse() {
    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(PREDICATE);
    q.addResultVar(OBJECT);
    q.addResultVar(TYPE);

    final ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(create(toJena(identifier), toJena(DC.isPartOf), SUBJECT));
    epb.addTriple(create(SUBJECT, toJena(LDP.isMemberOfRelation), PREDICATE));
    epb.addTriple(create(SUBJECT, toJena(LDP.membershipResource), OBJECT));
    epb.addTriple(create(SUBJECT, toJena(LDP.insertedContentRelation), toJena(LDP.MemberSubject)));
    epb.addTriple(create(OBJECT, type.asNode(), TYPE));

    final ElementNamedGraph ng = new ElementNamedGraph(toJena(Trellis.PreferServerManaged), epb);

    final ElementGroup elg = new ElementGroup();
    elg.addElement(ng);

    q.setQueryPattern(elg);

    final Stream.Builder<Quad> builder = builder();
    final IRI ixnModel = getInteractionModel();
    final IRI subject = adjustIdentifier(identifier, ixnModel);
    rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferMembership, subject,
                    getPredicate(qs), getObject(qs))));
    return builder.build();
}
 
Example 14
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * SELECT ?subject ?predicate ?object ?type
 * WHERE {
 *   GRAPH trellis:PreferServerManaged {
 *      ?s ldp:member IDENTIFIER
 *      ?s ldp:membershipResource ?subject
 *      ?s ldp:hasMemberRelation ?predicate
 *      ?s ldp:insertedContentRelation ldp:MemberSubject
 *      ?object dc:isPartOf ?s
 *      ?object rdf:type ?type .
 *   }
 * }
 * </code></pre>
 */
private Stream<Quad> fetchDirectMemberQuads() {
    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(SUBJECT);
    q.addResultVar(PREDICATE);
    q.addResultVar(OBJECT);
    q.addResultVar(TYPE);
    final Var s = Var.alloc("s");

    final ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(create(s, toJena(LDP.member), toJena(identifier)));
    epb.addTriple(create(s, toJena(LDP.membershipResource), SUBJECT));
    epb.addTriple(create(s, toJena(LDP.hasMemberRelation), PREDICATE));
    epb.addTriple(create(s, toJena(LDP.insertedContentRelation), toJena(LDP.MemberSubject)));
    epb.addTriple(create(OBJECT, toJena(DC.isPartOf), s));
    epb.addTriple(create(OBJECT, type.asNode(), TYPE));

    final ElementNamedGraph ng = new ElementNamedGraph(toJena(Trellis.PreferServerManaged), epb);

    final ElementGroup elg = new ElementGroup();
    elg.addElement(ng);

    q.setQueryPattern(elg);

    final Stream.Builder<Quad> builder = builder();
    rdfConnection.querySelect(q, qs -> builder.accept(rdf.createQuad(LDP.PreferMembership,
                    getSubject(qs), getPredicate(qs), adjustIdentifier((IRI) getObject(qs), getType(qs)))));
    return builder.build();
}
 
Example 15
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * This code is equivalent to the SPARQL query below.
 *
 * <p><pre><code>
 * SELECT ?subject ?predicate ?object
 * WHERE {
 *   GRAPH trellis:PreferServerManaged {
 *      ?s ldp:member IDENTIFIER .
 *      ?s ldp:membershipResource ?subject .
 *      ?s rdf:type ldp:IndirectContainer .
 *      ?s ldp:membershipRelation ?predicate .
 *      ?s ldp:insertedContentRelation ?o .
 *      ?res dc:isPartOf ?s .
 *   }
 *   GRAPH ?res { ?res ?o ?object }
 * }
 * </code></pre>
 */
private Stream<Quad> fetchIndirectMemberQuads() {
    final Var s = Var.alloc("s");
    final Var o = Var.alloc("o");
    final Var res = Var.alloc("res");

    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(SUBJECT);
    q.addResultVar(PREDICATE);
    q.addResultVar(OBJECT);

    final ElementPathBlock epb1 = new ElementPathBlock();
    epb1.addTriple(create(s, toJena(LDP.member), toJena(identifier)));
    epb1.addTriple(create(s, toJena(LDP.membershipResource), SUBJECT));
    epb1.addTriple(create(s, type.asNode(), toJena(LDP.IndirectContainer)));
    epb1.addTriple(create(s, toJena(LDP.hasMemberRelation), PREDICATE));
    epb1.addTriple(create(s, toJena(LDP.insertedContentRelation), o));
    epb1.addTriple(create(res, toJena(DC.isPartOf), s));

    final ElementPathBlock epb2 = new ElementPathBlock();
    epb2.addTriple(create(res, o, OBJECT));

    final ElementGroup elg = new ElementGroup();
    elg.addElement(new ElementNamedGraph(toJena(Trellis.PreferServerManaged), epb1));
    elg.addElement(new ElementNamedGraph(res, epb2));

    q.setQueryPattern(elg);

    final Stream.Builder<Quad> builder = builder();
    rdfConnection.querySelect(q, qs ->
        builder.accept(rdf.createQuad(LDP.PreferMembership, getSubject(qs), getPredicate(qs), getObject(qs))));
    return builder.build();
}
 
Example 16
Source File: TriplestoreResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Fetch data for this resource.
 *
 * <p>This is equivalent to the following SPARQL query:
 * <pre><code>
 * SELECT ?predicate ?object ?binarySubject ?binaryPredicate ?binaryObject
 * WHERE {
 *   GRAPH trellis:PreferServerManaged {
 *     IDENTIFIER ?predicate ?object
 *     OPTIONAL {
 *       IDENTIFIER dc:hasPart ?binarySubject .
 *       ?binarySubject ?binaryPredicate ?binaryObject
 *     }
 *   }
 * }
 * </code></pre>
 */
protected void fetchData() {
    LOGGER.debug("Fetching data from RDF datastore for: {}", identifier);
    final Var binarySubject = Var.alloc("binarySubject");
    final Var binaryPredicate = Var.alloc("binaryPredicate");
    final Var binaryObject = Var.alloc("binaryObject");
    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(PREDICATE);
    q.addResultVar(OBJECT);
    q.addResultVar(binarySubject);
    q.addResultVar(binaryPredicate);
    q.addResultVar(binaryObject);

    final ElementPathBlock epb1 = new ElementPathBlock();
    epb1.addTriple(create(toJena(identifier), PREDICATE, OBJECT));

    final ElementPathBlock epb2 = new ElementPathBlock();
    epb2.addTriple(create(toJena(identifier), toJena(DC.hasPart), binarySubject));
    epb2.addTriple(create(toJena(identifier), type.asNode(), toJena(LDP.NonRDFSource)));
    epb2.addTriple(create(binarySubject, binaryPredicate, binaryObject));

    final ElementGroup elg = new ElementGroup();
    elg.addElement(epb1);
    elg.addElement(new ElementOptional(epb2));

    q.setQueryPattern(new ElementNamedGraph(toJena(Trellis.PreferServerManaged), elg));

    rdfConnection.querySelect(q, qs -> {
        final RDFNode s = qs.get("binarySubject");
        final RDFNode p = qs.get("binaryPredicate");
        final RDFNode o = qs.get("binaryObject");
        nodesToTriple(s, p, o).ifPresent(t -> data.put(t.getPredicate(), t.getObject()));
        data.put(getPredicate(qs), getObject(qs));
    });
}
 
Example 17
Source File: TriplestoreResourceService.java    From trellis with Apache License 2.0 4 votes vote down vote up
/**
 * This code is equivalent to the SPARQL queries below.
 *
 * <pre><code>
 * SELECT ?object WHERE {
 *   GRAPH trellis:PreferServerManaged { IDENTIFIER rdf:type ?object }
 * }
 * </code></pre>
 *
 * <pre><code>
 * INSERT DATA {
 *   GRAPH trellis:PreferServerManaged {
 *     IDENTIFIER rdf:type ldp:Container ;
 *                dc:modified "NOW"^^xsd:dateTime }
 *   GRAPH IDENTIFIER?ext=audit {
 *     IDENTIFIER prov:wasGeneratedBy [
 *       rdf:type prov:Activity , as:Create ;
 *       prov:wasAssociatedWith trellis:AdministorAgent ;
 *       prov:atTime "TIME"^^xsd:dateTime ] }
 *   GRAPH IDENTIFIER?ext=acl {
 *     IDENTIFIER acl:mode acl.Read , acl:Write , acl:Control ;
 *       acl:agentClass foaf:Agent ;
 *       acl:accessTo IDENTIFIER }
 * }
 *
 * </code></pre>
 */
@PostConstruct
public void initialize() {
    final IRI root = rdf.createIRI(TRELLIS_DATA_PREFIX);
    final Query q = new Query();
    q.setQuerySelectType();
    q.addResultVar(OBJECT);

    final ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(triple(toJena(root), toJena(type), OBJECT));

    final ElementNamedGraph ng = new ElementNamedGraph(toJena(PreferServerManaged), epb);

    final ElementGroup elg = new ElementGroup();
    elg.addElement(ng);

    q.setQueryPattern(elg);

    final Stream.Builder<RDFTerm> builder = builder();
    rdfConnection.querySelect(q, qs -> builder.accept(getObject(qs)));
    if (!builder.build().findFirst().isPresent()) {
        final Literal time = rdf.createLiteral(now().toString(), XSD.dateTime);
        final IRI auth = rdf.createIRI(TRELLIS_DATA_PREFIX + "#auth");
        final UpdateRequest update = new UpdateRequest();

        final QuadDataAcc sink = new QuadDataAcc();
        sink.addQuad(new Quad(toJena(PreferServerManaged), triple(toJena(root), toJena(type),
                        toJena(LDP.BasicContainer))));
        sink.addQuad(new Quad(toJena(PreferServerManaged), triple(toJena(root), toJena(DC.modified),
                        toJena(time))));

        sink.addQuad(new Quad(getExtIRI(root, ACL_EXT), triple(toJena(auth), toJena(ACL.mode), toJena(ACL.Read))));
        sink.addQuad(new Quad(getExtIRI(root, ACL_EXT), triple(toJena(auth), toJena(ACL.mode), toJena(ACL.Write))));
        sink.addQuad(new Quad(getExtIRI(root, ACL_EXT), triple(toJena(auth), toJena(ACL.mode),
                        toJena(ACL.Control))));
        sink.addQuad(new Quad(getExtIRI(root, ACL_EXT), triple(toJena(auth), toJena(ACL.agentClass),
                        toJena(FOAF.Agent))));
        sink.addQuad(new Quad(getExtIRI(root, ACL_EXT), triple(toJena(auth), toJena(ACL.accessTo), toJena(root))));

        update.add(new UpdateDataInsert(sink));
        rdfConnection.update(update);
    }
    LOGGER.info("Initialized Trellis Triplestore Resource Service");
}
 
Example 18
Source File: TarqlQueryExecution.java    From tarql with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Modifies a query so that it operates onto a table. This is achieved
 * by appending the table as a VALUES block to the end of the main
 * query pattern.
 * 
 * @param query Original query; will be modified in place
 * @param table Data table to be added into the query
 */
private void modifyQuery(Query query, final Table table) {
	ElementData tableElement = new ElementData() {
		@Override
		public Table getTable() {
			return table;
		}
	};
	for (Var var: table.getVars()) {
		// Skip ?ROWNUM for "SELECT *" queries -- see further below
		if (query.isSelectType() && query.isQueryResultStar() 
				&& var.equals(TarqlQuery.ROWNUM)) continue;
		tableElement.add(var);
	}
	ElementGroup groupElement = new ElementGroup();
	groupElement.addElement(tableElement);
	if (query.getQueryPattern() instanceof ElementGroup) {
		for (Element element: ((ElementGroup) query.getQueryPattern()).getElements()) {
			groupElement.addElement(element);
		}
	} else {
		groupElement.addElement(query.getQueryPattern());
	}
	query.setQueryPattern(groupElement);
	
	// For SELECT * queries, we don't want to include pseudo
	// columns such as ?ROWNUM that may exist in the table.
	// That's why we skipped ?ROWNUM further up.
	if (query.isSelectType() && query.isQueryResultStar()) {
		// Force expansion of "SELECT *" to actual projection list
		query.setResultVars();
		// Tell ARQ that it actually needs to pay attention to
		// the projection list
		query.setQueryResultStar(false);
		// And now we can add ?ROWNUM to the table, as the "*"
		// has already been expanded.
		tableElement.add(TarqlQuery.ROWNUM);
	}
	// Data can only be added to table after we've finished the
	// ?ROWNUM shenangians
	/*for (Binding binding: table.getRows()) {
		tableElement.add(binding);
	}*/
}