Skip to content

Commit

Permalink
GH-3585 code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Håvard Ottestad <[email protected]>
  • Loading branch information
hmottestad committed Jan 22, 2022
1 parent acfe08d commit 89aeef7
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.rdf4j.query.Binding;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.MutableBindingSet;
import org.eclipse.rdf4j.query.algebra.evaluation.util.OrderComparator;
import org.eclipse.rdf4j.query.impl.SimpleBinding;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ CloseableIteration<BindingSet, QueryEvaluationException> evaluate(TupleExpr expr
/**
* Prepare a QueryEvaluationStep that tries to do as much work once per query avoiding repeated calls to the same
* code as much as possible. This depends on java invoke dynamic for performance.
*
*
* @param expr that is to be evaluated later
* @return a QueryEvaluationStep that may avoid doing repeating the same work over and over.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public DelayedEvaluationIteration(QueryEvaluationStep arg, BindingSet bs) {

/**
* A fall back implementation that wraps a pre-existing evaluate method on a strategy
*
*
* @param strategy that can evaluate the tuple expr.
* @param expr that is going to be evaluated
* @return a thin wrapper arround the evaluation call.
Expand All @@ -64,7 +64,7 @@ public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Binding
/**
* Wrap an QueryEvalationStep: where we apply a function on every evaluation result of the wrapped EvaluationStep.
* Useful to add a timing function
*
*
* @param qes an QueryEvaluationStep that needs to return modified evaluation results
* @param wrap the function that will do the modification
* @return a new evaluation step that executes wrap on the inner qes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*******************************************************************************/
package org.eclipse.rdf4j.query.algebra.evaluation.function.numeric;

import java.util.Random;

import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.ValueFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ public void meet(ExtensionElem node) throws QueryEvaluationException {
String[] varNamesArr = varNames.toArray(new String[0]);
return varNamesArr;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Binding
}
return new ExtensionIterator(result, consumer, context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,39 @@

/**
* Optimizes a query model by pushing {@link Filter}s as far down in the model tree as possible.
*
*
* To make the first optimization succeed more often it splits filters which contains {@link And} conditions.
*
*
* <code>
* SELECT * WHERE {
* ?s ?p ?o .
* ?s ?p ?o2 .
* FILTER(?o > '2'^^xsd:int && ?o2 < '4'^^xsd:int)
* ?s ?p ?o .
* ?s ?p ?o2 .
* FILTER(?o > '2'^^xsd:int && ?o2 < '4'^^xsd:int)
* }
* </code> May be more efficient when decomposed into <code>
* SELECT * WHERE {
* ?s ?p ?o .
* FILTER(?o > '2'^^xsd:int)
* ?s ?p ?o2 .
* FILTER(?o2 < '4'^^xsd:int)
* FILTER(?o > '2'^^xsd:int)
* ?s ?p ?o2 .
* FILTER(?o2 < '4'^^xsd:int)
* }
* </code>
*
*
* Then it optimizes a query model by merging adjacent {@link Filter}s. e.g. <code>
* SELECT * WHERE {
* ?s ?p ?o .
* FILTER(?o > 2) .
* FILTER(?o < 4) .
* }
* </code> may be merged into <code>
* }
* </code> may be merged into <code>
* SELECT * WHERE {
* ?s ?p ?o .
* ?s ?p ?o .
* FILTER(?o > 2 && ?o < 4) . }
* </code>
*
*
* This optimization allows for sharing evaluation costs in the future and removes an iterator. This is done as a second
* step to not break the first optimization. In the case that the splitting was done but did not help it is now undone.
*
*
* @author Arjohn Kampman
* @author Jerven Bolleman
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.query.algebra.evaluation.impl;

Expand All @@ -21,7 +21,7 @@
/**
* Cleans up {@link QueryModelNode#getParentNode()} references that have become inconsistent with the actual algebra
* tree structure due to optimization operations. Typically used at the very end of the optimization pipeline.
*
*
* @author Jeen Broekstra
*/
public class ParentReferenceCleaner implements QueryOptimizer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
* SELECT ?s ?p ?o
* WHERE {?s ?p ?o }
* </code> Does not need a projection as the inner statement pattern returns the same result.
*
*
* While <code>
* * SELECT ?s ?p
* * SELECT ?s ?p
* WHERE {?s ?p ?o }
* </code> Does as the statement pattern has one more variable in use than the projection.
*
*
* Note: this optimiser should run after optimisations ran that depend on Projections. e.g.
*
*
* @see UnionScopeChangeOptimizer
*
*
* @author Jerven Bolleman
*/
public class ProjectionRemovalOptimizer implements QueryOptimizer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

/**
* A QueryEvaluationContext stores values and methods that are valid throughout the lifetime of a query execution.
*
*
* A classic case is the case of NOW() evaluation to the same instant for all invocations of that function in one query
* evaluation.
*
*
*/
public interface QueryEvaluationContext {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ protected BindingSet getNextElement() throws QueryEvaluationException {

return result;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public IntersectionQueryEvaluationStep(QueryEvaluationStep leftArg, QueryEvaluat
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bs) {
return new IntersectIteration<>(leftArgDelayed.evaluate(bs), rightArgDelayed.evaluate(bs), setMaker);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(Binding
return new BadlyDesignedLeftJoinIterator(left, right, condition, bindings, problemVars);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ public OrderQueryEvaluationStep(Comparator<BindingSet> cmp, long limit, boolean
public CloseableIteration<BindingSet, QueryEvaluationException> evaluate(BindingSet bs) {
return new OrderIterator(preparedArg.evaluate(bs), cmp, limit, reduced, iterationCacheSyncThreshold);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,4 @@ public void meet(Var var) {
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private static Predicate<Statement> subjectVariableHasEquals(boolean subEqPredVa
}

/**
*
*
* @param statementPattern
* @param contextValue
* @return the contexts that are valid for this statement pattern or null
Expand Down Expand Up @@ -348,7 +348,7 @@ private static Resource[] fillContextsFromDatasSetGraphs(Set<IRI> graphs) {
/**
* Converts statements into the required bindingsets. A lot of work is done in the constructor and then uses
* invokedynamic code with lambdas for the actual conversion.
*
*
* This allows avoiding of significant work during the iteration. Which pays of if the iteration is long, otherwise
* it of course is an unneeded expense.
*/
Expand Down Expand Up @@ -383,10 +383,10 @@ protected BindingSet convert(Statement st) {

/**
* We are going to chain biconsumer functions allowing us to avoid a lot of equals etc. code
*
*
* We need to test every binding with hasBinding etc. as these are not guaranteed to be equivalent between calls of
* evaluate(bs).
*
*
* @return a converter from statement into MutableBindingSet
*/
private static BiConsumer<MutableBindingSet, Statement> makeConverter(QueryEvaluationContext context,
Expand Down Expand Up @@ -449,7 +449,7 @@ private static Predicate<Statement> andThen(Predicate<Statement> pred, Predicate

/**
* A convience function to chain the consumers together if one exists otherwise returns the new one.
*
*
* @param co an earlier chain
* @param and the consumer to add to the chain
* @return a chain or the new (and) one
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.eclipse.rdf4j.model.base.CoreDatatype;
import org.eclipse.rdf4j.model.datatypes.XMLDatatypeUtil;
import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
import org.eclipse.rdf4j.model.vocabulary.XSD;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.MutableBindingSet;
import org.eclipse.rdf4j.query.QueryEvaluationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
import javax.xml.datatype.Duration;
import javax.xml.datatype.XMLGregorianCalendar;

import org.eclipse.rdf4j.common.annotation.InternalUseOnly;
import org.eclipse.rdf4j.model.Literal;
import org.eclipse.rdf4j.model.Value;
import org.eclipse.rdf4j.model.base.CoreDatatype;
import org.eclipse.rdf4j.model.datatypes.XMLDatatypeUtil;
import org.eclipse.rdf4j.model.util.Literals;
import org.eclipse.rdf4j.query.algebra.Compare;
import org.eclipse.rdf4j.query.algebra.Compare.CompareOp;
import org.eclipse.rdf4j.query.algebra.Or;

/**
* This class will take over for QueryEvaluationUtil. Currently marked as InternalUseOnly because there may still be
* changes to how this class works.
*
* @author Arjohn Kampman
* @author Håvard M. Ottestad
*/
@InternalUseOnly()
public class QueryEvaluationUtility {

/**
Expand Down Expand Up @@ -150,8 +153,8 @@ public static Order compareLiterals(Literal leftLit, Literal rightLit, boolean s
if (commonDatatype != null) {

try {
Order order = handleCommonDatatype(leftLit, rightLit, strict, leftXSDDatatype,
rightXSDDatatype, leftLangLit, rightLangLit, commonDatatype);
Order order = handleCommonDatatype(leftLit, rightLit, strict, leftXSDDatatype, rightXSDDatatype,
leftLangLit, rightLangLit, commonDatatype);

if (order == Order.illegalArgument) {
if (leftLit.equals(rightLit)) {
Expand Down Expand Up @@ -234,8 +237,7 @@ private static Order handleCommonDatatype(Literal leftLit, Literal rightLit, boo
if (compare != DatatypeConstants.INDETERMINATE) {
return Order.from(compare);
} else {
return otherCases(leftLit, rightLit, leftCoreDatatype, rightCoreDatatype, leftLangLit,
rightLangLit);
return otherCases(leftLit, rightLit, leftCoreDatatype, rightCoreDatatype, leftLangLit, rightLangLit);
}

} else if (commonDatatype == CoreDatatype.XSD.STRING) {
Expand All @@ -245,9 +247,8 @@ private static Order handleCommonDatatype(Literal leftLit, Literal rightLit, boo
return null;
}

private static Order otherCases(Literal leftLit, Literal rightLit,
CoreDatatype.XSD leftCoreDatatype, CoreDatatype.XSD rightCoreDatatype, boolean leftLangLit,
boolean rightLangLit) {
private static Order otherCases(Literal leftLit, Literal rightLit, CoreDatatype.XSD leftCoreDatatype,
CoreDatatype.XSD rightCoreDatatype, boolean leftLangLit, boolean rightLangLit) {
boolean literalsEqual = leftLit.equals(rightLit);

if (!literalsEqual) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.query.algebra.evaluation.impl;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
/*******************************************************************************
* Copyright (c) 2021 Eclipse RDF4J contributors.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*******************************************************************************/
package org.eclipse.rdf4j.query.algebra.evaluation.impl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand Down

0 comments on commit 89aeef7

Please sign in to comment.