Java Code Examples for org.apache.jena.sparql.core.VarExprList#getVars()

The following examples show how to use org.apache.jena.sparql.core.VarExprList#getVars() . 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: QueryXExprNormalizer.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public void visitGroupBy(Query query) {
    if (query.hasGroupBy() && !query.getGroupBy().isEmpty()) {
        // Can have an empty GROUP BY list if the grouping is implicit
        // by use of an aggregate in the SELECT clause.
        final VarExprList namedExprs = query.getGroupBy();
        final VarExprList newNamedExprs = new VarExprList();
        for (Var var : namedExprs.getVars()) {
            if (namedExprs.hasExpr(var)) {
                final Expr nzed = enzer.normalize(namedExprs.getExpr(var));
                newNamedExprs.add(var, nzed);
            } else {
                newNamedExprs.add(var);
            }
        }
        namedExprs.clear();
        namedExprs.addAll(newNamedExprs);
    }
}
 
Example 2
Source File: SelectQueryPartialCopyVisitor.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public void visitGroupBy(final Query query) {
    if (query.hasGroupBy()) {
        if (!query.getGroupBy().isEmpty()) {
            VarExprList namedExprs = query.getGroupBy();
            for (Var var : namedExprs.getVars()) {
                Expr expr = namedExprs.getExpr(var);
                if (expr != null) {
                    output.addGroupBy(var, expr);
                } else {
                    output.addGroupBy(var.getVarName());
                }
            }
        }
    }
}
 
Example 3
Source File: SelectExtractionVisitor.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
public void visitGroupBy(final Query query) {
    if (query.hasGroupBy()) {
    	isDummyQuery = false;
        if (!query.getGroupBy().isEmpty()) {
            VarExprList namedExprs = query.getGroupBy();
            for (Var var : namedExprs.getVars()) {
                Expr expr = namedExprs.getExpr(var);
                if (expr != null) {
                    output.addGroupBy(var, expr);
                    if (!query.isSelectType()) {
                        output.addResultVar(var);
                    }
                } else {
                    output.addGroupBy(var.getVarName());
                    if (!query.isSelectType()) {
                        output.addResultVar(var);
                    }
                }
            }
        }
    }
}
 
Example 4
Source File: DB2ResultSetImpl.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
public DB2ResultSetImpl(LiteralInfoResultSet rs, Store store, Connection c, List<String> list, VarExprList varExprList)
{
liRs = rs;
set = rs.getResultSet();
try {
 ResultSetMetaData rsMetaData = set.getMetaData();
 int numberOfColumns = rsMetaData.getColumnCount();
	
 // get the column names; column indexes start from 1
 for (int i = 1; i <= numberOfColumns; i++) {
     columnNames.add(rsMetaData.getColumnName(i));
    
 }
} catch (SQLException e) {
 e.printStackTrace();
 throw new RuntimeException("Error getting result metadata");
}
this.store = store;
connection = c;

if (varExprList.isEmpty())
   {
   varList = list;
   }
else
   {
   List<Var> vars = varExprList.getVars();
   varList = new ArrayList<String>();
   for (int i = 0; i < vars.size(); i++)
      {
      varList.add(vars.get(i).getName());
      }
   }
}
 
Example 5
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
void appendNamedExprList(Query query, IndentedWriter sb, VarExprList namedExprs) {
    boolean first = true;
    for (Var var : namedExprs.getVars()) {
        Expr expr = namedExprs.getExpr(var);
        if (!first) {
            sb.print(" ");
        }

        if (expr != null) {
            // The following are safe to write without () 
            // Compare/merge with fmtExpr.format
            boolean needParens = true;

            if (expr.isFunction()) {
                needParens = false;
            } //                else if ( expr instanceof E_Aggregator )
            //                    // Aggregators are variables (the function maps to an internal variable 
            //                    // that is accesses by the E_Aggregator
            //                    needParens = false ;
            else if (expr.isVariable()) {
                needParens = false;
            }

            if (!Var.isAllocVar(var)) // AS ==> need parens
            {
                needParens = true;
            }

            if (needParens) {
                out.print("(");
            }
            fmtExpr.format(expr);
            if (!Var.isAllocVar(var)) {
                sb.print(" AS ");
                sb.print(var.toString());
            }
            if (needParens) {
                out.print(")");
            }
        } else {
            sb.print(var.toString());
        }
        first = false;
    }
}