Java Code Examples for org.eclipse.rdf4j.query.algebra.Group#addGroupElement()

The following examples show how to use org.eclipse.rdf4j.query.algebra.Group#addGroupElement() . 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: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAvgEmptySet() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("avg", new Avg(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.next().getBinding("avg").getValue())
			.describedAs("AVG on empty set should result in 0")
			.isEqualTo(vf.createLiteral("0", XMLSchema.INTEGER));
}
 
Example 2
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMaxEmptySet_DefaultGroup() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("max", new Max(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.hasNext()).isTrue();
	assertThat(gi.next().size()).isEqualTo(0);
}
 
Example 3
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMaxEmptySet_Grouped() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("max", new Max(new Var("a"))));
	group.addGroupBindingName("x"); // we are grouping by variable x

	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.hasNext()).isFalse();
}
 
Example 4
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testMinEmptySet() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("min", new Min(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.hasNext()).isTrue();
	assertThat(gi.next().size()).isEqualTo(0);
}
 
Example 5
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSampleEmptySet() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("sample", new Sample(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.hasNext()).isTrue();
	assertThat(gi.next().size()).isEqualTo(0);
}
 
Example 6
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGroupConcatEmptySet() throws QueryEvaluationException {
	Group group = new Group(EMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("groupconcat", new GroupConcat(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.next().getBinding("groupconcat").getValue())
			.describedAs("GROUP_CONCAT on empty set should result in empty string")
			.isEqualTo(vf.createLiteral(""));
}
 
Example 7
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testAvgNotZero() throws QueryEvaluationException {
	Group group = new Group(NONEMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("avg", new Avg(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.next().getBinding("avg").getValue()).isEqualTo(vf.createLiteral("5", XMLSchema.DECIMAL));
}
 
Example 8
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testCountNotZero() throws QueryEvaluationException {
	Group group = new Group(NONEMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("count", new Count(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.next().getBinding("count").getValue()).isEqualTo(vf.createLiteral("9", XMLSchema.INTEGER));
}
 
Example 9
Source File: GroupIteratorTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testSumNotZero() throws QueryEvaluationException {
	Group group = new Group(NONEMPTY_ASSIGNMENT);
	group.addGroupElement(new GroupElem("sum", new Sum(new Var("a"))));
	GroupIterator gi = new GroupIterator(evaluator, group, EmptyBindingSet.getInstance());

	assertThat(gi.next().getBinding("sum").getValue()).isEqualTo(vf.createLiteral("45", XMLSchema.INTEGER));
}
 
Example 10
Source File: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private TupleExpr processOrderClause(ASTOrderClause orderNode, TupleExpr tupleExpr, Group group)
		throws VisitorException {
	if (orderNode != null) {
		@SuppressWarnings("unchecked")
		List<OrderElem> orderElements = (List<OrderElem>) orderNode.jjtAccept(this, null);

		for (OrderElem orderElem : orderElements) {
			// retrieve any aggregate operators from the order element.
			AggregateCollector collector = new AggregateCollector();
			collector.meet(orderElem);

			Extension extension = new Extension();

			for (AggregateOperator operator : collector.getOperators()) {
				Var var = createAnonVar();

				// replace occurrence of the operator in the order condition
				// with the variable.
				AggregateOperatorReplacer replacer = new AggregateOperatorReplacer(operator, var);
				replacer.meet(orderElem);

				// create an extension linking the operator to the variable
				// name.
				String alias = var.getName();

				ExtensionElem pe = new ExtensionElem(operator, alias);
				extension.addElement(pe);

				// add the aggregate operator to the group.
				GroupElem ge = new GroupElem(alias, operator);
				group.addGroupElement(ge);
			}

			if (!extension.getElements().isEmpty()) {
				extension.setArg(tupleExpr);
				tupleExpr = extension;
			}
		}

		tupleExpr = new Order(tupleExpr, orderElements);

	}
	return tupleExpr;
}