Skip to content

Commit

Permalink
extracted the conversion of queries to select query into a new class. s…
Browse files Browse the repository at this point in the history
  • Loading branch information
bibhas committed Jul 20, 2012
1 parent a41adf9 commit 81e86bf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*******************************************************************************
* Copyright (c) 2012 National University of Ireland, Galway. All Rights Reserved.
*
*
* This project is a free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This project is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
package org.sindice.analytics.queryProcessor;

import org.openrdf.sindice.query.parser.sparql.ast.ASTAskQuery;
import org.openrdf.sindice.query.parser.sparql.ast.ASTDatasetClause;
import org.openrdf.sindice.query.parser.sparql.ast.ASTQueryContainer;
import org.openrdf.sindice.query.parser.sparql.ast.ASTSelect;
import org.openrdf.sindice.query.parser.sparql.ast.ASTSelectQuery;
import org.openrdf.sindice.query.parser.sparql.ast.SyntaxTreeBuilderTreeConstants;

/**
* Converts an AST to a Select Query AST if it is anything other than Select Query
* @author bibhas [Jul 20, 2012]
* @email bibhas.das@deri.org
*
*/
public class Change2Select {
private Change2Select(){

}

public static void process(ASTQueryContainer ast) {
if (!(ast.getQuery() instanceof ASTSelectQuery)) { // Change to a SelectQuery
final ASTSelectQuery selectQuery = new ASTSelectQuery(SyntaxTreeBuilderTreeConstants.JJTSELECTQUERY);
final ASTSelect select = new ASTSelect(SyntaxTreeBuilderTreeConstants.JJTSELECT);

selectQuery.jjtAppendChild(select);
for (ASTDatasetClause d : ast.getQuery().getDatasetClauseList()) {
selectQuery.jjtAppendChild(d);
}
selectQuery.jjtAppendChild(ast.getQuery().getWhereClause());
if (!(ast.getQuery() instanceof ASTAskQuery)) {
if (ast.getQuery().getGroupClause() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getGroupClause());
}
if (ast.getQuery().getHavingClause() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getHavingClause());
}
if (ast.getQuery().getOrderClause() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getOrderClause());
}
if (ast.getQuery().getLimit() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getLimit());
}
if (ast.getQuery().getOffset() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getOffset());
}
}
if (ast.getQuery().getBindingsClause() != null) {
selectQuery.jjtAppendChild(ast.getQuery().getBindingsClause());
}
ast.getQuery().jjtReplaceWith(selectQuery);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,37 +58,7 @@ public PipelineObject process(PipelineObject obj) throws VisitorException {
if (obj.getVarsToProject() != null) {
v.addAll(obj.getVarsToProject());
}
if (!(obj.getAst().getQuery() instanceof ASTSelectQuery)) { // Change to a SelectQuery
final ASTSelectQuery selectQuery = new ASTSelectQuery(SyntaxTreeBuilderTreeConstants.JJTSELECTQUERY);
final ASTSelect select = new ASTSelect(SyntaxTreeBuilderTreeConstants.JJTSELECT);

selectQuery.jjtAppendChild(select);
for (ASTDatasetClause d : obj.getAst().getQuery().getDatasetClauseList()) {
selectQuery.jjtAppendChild(d);
}
selectQuery.jjtAppendChild(obj.getAst().getQuery().getWhereClause());
if (!(obj.getAst().getQuery() instanceof ASTAskQuery)) {
if (obj.getAst().getQuery().getGroupClause() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getGroupClause());
}
if (obj.getAst().getQuery().getHavingClause() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getHavingClause());
}
if (obj.getAst().getQuery().getOrderClause() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getOrderClause());
}
if (obj.getAst().getQuery().getLimit() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getLimit());
}
if (obj.getAst().getQuery().getOffset() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getOffset());
}
}
if (obj.getAst().getQuery().getBindingsClause() != null) {
selectQuery.jjtAppendChild(obj.getAst().getQuery().getBindingsClause());
}
obj.getAst().getQuery().jjtReplaceWith(selectQuery);
}
Change2Select.process(obj.getAst());
final ASTMaterializePointOfFocus matPOF = new ASTMaterializePointOfFocus();
matPOF.visit(obj.getAst(), v);
final POFRecType type = new POFRecType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public void setUp() throws Exception {
@After
public void tearDown() throws Exception {
}

@Test
public void testPOFTargetIsLeaf() throws Exception {
final String query = "SELECT * WHERE { ?s ?p ?o. ?s2 < ?o }";
Expand Down

0 comments on commit 81e86bf

Please sign in to comment.