StaticOptimizer(final QueryRoot queryRoot, final AST2BOpContext context, final IBindingProducerNode[] ancestry, final List<IReorderableNode> nodes, final double optimistic) { this(new StaticAnalysis(queryRoot, context), ancestry, nodes, optimistic); }
StaticOptimizer(final QueryRoot queryRoot, final AST2BOpContext context, final IBindingProducerNode[] ancestry, final List<IReorderableNode> nodes, final double optimistic) { this(new StaticAnalysis(queryRoot, context), ancestry, nodes, optimistic); }
/** <code>[5, 3, 1, 0, 2, 4, 6]</code>. */ public void test_attachConstraints_BSBM_Q5_path02() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p5, s.p3, s.p1, s.p0, s.p2, s.p4, s.p6 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p5 s.NA, // p3 s.NA, // p1 s.C0, // p0 s.NA, // p2 s.C1, // p4 s.C2, // p6 }; assertSameConstraints(expected, actual); }
/** <code>path = [1, 2, 4, 6, 0, 3, 5]</code> */ public void test_attachConstraints_BSBM_Q5_path01() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p1, s.p2, s.p4, s.p6, s.p0, s.p3, s.p5 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p1 s.C0, // p2 s.NA, // p4 s.NA, // p6 s.NA, // p0 s.C1, // p3 s.C2, // p5 }; assertSameConstraints(expected, actual); }
/** <code>path = [1, 2, 4, 6, 0, 3, 5]</code> */ public void test_attachConstraints_BSBM_Q5_path01() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p1, s.p2, s.p4, s.p6, s.p0, s.p3, s.p5 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p1 s.C0, // p2 s.NA, // p4 s.NA, // p6 s.NA, // p0 s.C1, // p3 s.C2, // p5 }; assertSameConstraints(expected, actual); }
/** <code>[5, 3, 1, 0, 2, 4, 6]</code>. */ public void test_attachConstraints_BSBM_Q5_path02() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p5, s.p3, s.p1, s.p0, s.p2, s.p4, s.p6 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p5 s.NA, // p3 s.NA, // p1 s.C0, // p0 s.NA, // p2 s.C1, // p4 s.C2, // p6 }; assertSameConstraints(expected, actual); }
/** <code>[3, 4, 5, 6, 1, 2, 0]</code> (key-range constraint variant). */ public void test_attachConstraints_BSBM_Q5_path03() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p3, s.p4, s.p5, s.p6, s.p1, s.p2, s.p0 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p3 asSet(new FilterNode[]{s.c0,s.c1}), // p4 s.NA, // p5 s.C2, // p6 s.NA, // p1 s.NA, // p2 s.NA, // p0 }; assertSameConstraints(expected, actual); }
/** <code>[3, 4, 5, 6, 1, 2, 0]</code> (key-range constraint variant). */ public void test_attachConstraints_BSBM_Q5_path03() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p3, s.p4, s.p5, s.p6, s.p1, s.p2, s.p0 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p3 asSet(new FilterNode[]{s.c0,s.c1}), // p4 s.NA, // p5 s.C2, // p6 s.NA, // p1 s.NA, // p2 s.NA, // p0 }; assertSameConstraints(expected, actual); }
/** * Creates a {@link StaticAnalysis} object for the nodes by setting up a * SELECT query with a single {@link JoinGroupNode} comprising the nodes * in its body to retrieve the {@link StaticAnalysis} object. */ StaticAnalysis statisAnalysisForNodes(List<IGroupMemberNode> nodes) { final IGroupMemberNode[] nodesArr = nodes.toArray(new IGroupMemberNode[nodes.size()]); final JoinGroupNode jgn = (JoinGroupNode) new Helper(){{ tmp = joinGroupNode((Object[])nodesArr); }}.getTmp(); final QueryRoot queryRoot = new QueryRoot(QueryType.SELECT); queryRoot.setWhereClause(jgn); return new StaticAnalysis( queryRoot, new AST2BOpContext(new ASTContainer(queryRoot), store)); }
/** * Creates a {@link StaticAnalysis} object for the nodes by setting up a * SELECT query with a single {@link JoinGroupNode} comprising the nodes * in its body to retrieve the {@link StaticAnalysis} object. */ StaticAnalysis statisAnalysisForNodes(List<IGroupMemberNode> nodes) { final IGroupMemberNode[] nodesArr = nodes.toArray(new IGroupMemberNode[nodes.size()]); final JoinGroupNode jgn = (JoinGroupNode) new Helper(){{ tmp = joinGroupNode((Object[])nodesArr); }}.getTmp(); final QueryRoot queryRoot = new QueryRoot(QueryType.SELECT); queryRoot.setWhereClause(jgn); return new StaticAnalysis( queryRoot, new AST2BOpContext(new ASTContainer(queryRoot), store)); }
/** <code>[5, 3, 1, 0, 2, 4, 6]</code>. */ public void test_attachConstraints_BSBM_Q5_path02() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p5, s.p3, s.p1, s.p0, s.p2, s.p4, s.p6 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p5 s.NA, // p3 s.NA, // p1 s.C0, // p0 s.NA, // p2 s.C1, // p4 s.C2, // p6 }; assertSameConstraints(expected, actual); }
/** <code>path = [1, 2, 4, 6, 0, 3, 5]</code> */ public void test_attachConstraints_BSBM_Q5_path01() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p1, s.p2, s.p4, s.p6, s.p0, s.p3, s.p5 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p1 s.C0, // p2 s.NA, // p4 s.NA, // p6 s.NA, // p0 s.C1, // p3 s.C2, // p5 }; assertSameConstraints(expected, actual); }
@Override public QueryNodeWithBindingSet optimize( final AST2BOpContext context, final QueryNodeWithBindingSet input) { final IQueryNode queryNode = input.getQueryNode(); final IBindingSet[] bindingSets = input.getBindingSets(); final QueryRoot queryRoot = (QueryRoot) queryNode; final StaticAnalysis sa = new StaticAnalysis(queryRoot, context); // First, process any pre-existing named subqueries. { final NamedSubqueriesNode namedSubqueries = queryRoot .getNamedSubqueries(); if (namedSubqueries != null) { for (NamedSubqueryRoot namedSubquery : namedSubqueries) { optimizeJoinGroups(context, sa, namedSubquery.getWhereClause()); } } } // Now process the main where clause. optimizeJoinGroups(context, sa, queryRoot.getWhereClause()); return new QueryNodeWithBindingSet(queryRoot, bindingSets); }
@SuppressWarnings("unchecked") @Override public QueryNodeWithBindingSet optimize( final AST2BOpContext context, final QueryNodeWithBindingSet input) { final IQueryNode queryNode = input.getQueryNode(); final IBindingSet[] bindingSets = input.getBindingSets(); final QueryRoot queryRoot = (QueryRoot) queryNode; final StaticAnalysis sa = new StaticAnalysis(queryRoot, context); // First, process any pre-existing named subqueries. { final NamedSubqueriesNode namedSubqueries = queryRoot .getNamedSubqueries(); if (namedSubqueries != null) { for (NamedSubqueryRoot namedSubquery : namedSubqueries) { attachJoinFilters(context, sa, namedSubquery.getWhereClause()); } } } // Now process the main where clause. attachJoinFilters(context, sa, queryRoot.getWhereClause()); return new QueryNodeWithBindingSet(queryRoot, bindingSets); }
@Override public QueryNodeWithBindingSet optimize( final AST2BOpContext context, final QueryNodeWithBindingSet input) { final IQueryNode queryNode = input.getQueryNode(); final IBindingSet[] bindingSets = input.getBindingSets(); final QueryRoot queryRoot = (QueryRoot) queryNode; final StaticAnalysis sa = new StaticAnalysis(queryRoot, context); // First, process any pre-existing named subqueries. { final NamedSubqueriesNode namedSubqueries = queryRoot .getNamedSubqueries(); if (namedSubqueries != null) { for (NamedSubqueryRoot namedSubquery : namedSubqueries) { optimizeJoinGroups(context, sa, namedSubquery.getWhereClause()); } } } // Now process the main where clause. optimizeJoinGroups(context, sa, queryRoot.getWhereClause()); return new QueryNodeWithBindingSet(queryRoot, bindingSets); }
@SuppressWarnings("unchecked") @Override public QueryNodeWithBindingSet optimize( final AST2BOpContext context, final QueryNodeWithBindingSet input) { final IQueryNode queryNode = input.getQueryNode(); final IBindingSet[] bindingSets = input.getBindingSets(); final QueryRoot queryRoot = (QueryRoot) queryNode; final StaticAnalysis sa = new StaticAnalysis(queryRoot, context); // First, process any pre-existing named subqueries. { final NamedSubqueriesNode namedSubqueries = queryRoot .getNamedSubqueries(); if (namedSubqueries != null) { for (NamedSubqueryRoot namedSubquery : namedSubqueries) { assignJoinVars(sa, namedSubquery.getWhereClause()); } } } // Now process the main where clause. assignJoinVars(sa, queryRoot.getWhereClause()); return new QueryNodeWithBindingSet(queryRoot, bindingSets); }
/** <code>[3, 4, 5, 6, 1, 2, 0]</code> (key-range constraint variant). */ public void test_attachConstraints_BSBM_Q5_path03() { final BSBMQ5Setup s = new BSBMQ5Setup(store); final StaticAnalysis sa = new StaticAnalysis(s.queryRoot); final IJoinNode[] path = { s.p3, s.p4, s.p5, s.p6, s.p1, s.p2, s.p0 }; final FilterNode[][] actual = sa .getJoinGraphConstraints(path, s.constraints, null/* knownBoundVars */, true/* pathIsComplete */); @SuppressWarnings("unchecked") final Set<FilterNode>[] expected = new Set[] { // s.NA, // p3 asSet(new FilterNode[]{s.c0,s.c1}), // p4 s.NA, // p5 s.C2, // p6 s.NA, // p1 s.NA, // p2 s.NA, // p0 }; assertSameConstraints(expected, actual); }
/** * Creates a {@link StaticAnalysis} object for the nodes by setting up a * SELECT query with a single {@link JoinGroupNode} comprising the nodes * in its body to retrieve the {@link StaticAnalysis} object. */ StaticAnalysis statisAnalysisForNodes(List<IGroupMemberNode> nodes) { final IGroupMemberNode[] nodesArr = nodes.toArray(new IGroupMemberNode[nodes.size()]); final JoinGroupNode jgn = (JoinGroupNode) new Helper(){{ tmp = joinGroupNode((Object[])nodesArr); }}.getTmp(); final QueryRoot queryRoot = new QueryRoot(QueryType.SELECT); queryRoot.setWhereClause(jgn); return new StaticAnalysis( queryRoot, new AST2BOpContext(new ASTContainer(queryRoot), store)); }
@SuppressWarnings("serial") public void testComplexALPNode() { final ArbitraryLengthPathNode alpNode = (ArbitraryLengthPathNode) new Helper() {{ tmp = arbitartyLengthPropertyPath( varNode(x), constantNode(b), HelperFlag.ZERO_OR_MORE, joinGroupNode( statementPatternNode(leftVar(), constantNode(c), varNode(y)), statementPatternNode(varNode(y), constantNode(d), rightVar()) )); }}.getTmp(); final Set<IVariable<?>> requiredBoundAlpNode = new HashSet<IVariable<?>>(); final Set<IVariable<?>> desiredBoundAlpNode = new HashSet<IVariable<?>>() {{ add(Var.var("x")); add(Var.var("y")); }}; // dummy sa object final StaticAnalysis sa = new StaticAnalysis(new QueryRoot(QueryType.SELECT), null); assertEquals(requiredBoundAlpNode, alpNode.getRequiredBound(sa)); assertEquals(desiredBoundAlpNode, alpNode.getDesiredBound(sa)); }
@SuppressWarnings("serial") public void testNamedSubquery() { final NamedSubqueryInclude nsi = (NamedSubqueryInclude) new Helper() {{ tmp = namedSubQueryInclude("_set1"); }}.getTmp(); final QueryRoot query = (QueryRoot) new Helper(){{ tmp = select( varNodes(x,y,y), namedSubQuery("_set1",varNode(x),where(statementPatternNode(varNode(x), constantNode(a), constantNode(b),1))), where(nsi,statementPatternNode(varNode(x), constantNode(c), varNode(y),1,OPTIONAL) ) ); }}.getTmp(); final AST2BOpContext context = new AST2BOpContext(new ASTContainer(query), store); final StaticAnalysis sa = new StaticAnalysis(query, context); final Set<IVariable<?>> requiredBound = new HashSet<IVariable<?>>(); final Set<IVariable<?>> desiredBound = new HashSet<IVariable<?>>() {{ add(Var.var("x")); }}; assertEquals(requiredBound, nsi.getRequiredBound(sa)); assertEquals(desiredBound, nsi.getDesiredBound(sa)); }