org.apache.jena.query.Query.getGroupBy()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(146)

本文整理了Java中org.apache.jena.query.Query.getGroupBy方法的一些代码示例,展示了Query.getGroupBy的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getGroupBy方法的具体详情如下:
包路径:org.apache.jena.query.Query
类名称:Query
方法名:getGroupBy

Query.getGroupBy介绍

暂无

代码示例

代码示例来源:origin: apache/tinkerpop

final VarExprList lstExpr = query.getGroupBy();
String grpVar = "";
for (Var expr : lstExpr.getVars()) {

代码示例来源:origin: apache/jena

@Override
public void visitGroupBy(Query query1)
{
  check("GROUP BY", query1.getGroupBy(), query2.getGroupBy()) ;
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static boolean isGroupedOnlyByVar(Query query, Var groupVar) {
  boolean result = false;
  boolean hasOneGroup = query.getGroupBy().size() == 1;
  if(hasOneGroup) {
    Expr expr = query.getGroupBy().getExprs().values().iterator().next();
    if(expr instanceof ExprVar) {
      Var v = expr.asVar();
      result = v.equals(groupVar);
    }
  }
  return result;
}

代码示例来源:origin: apache/jena

@Override
public void visitGroupBy(Query query)
{
  if ( query.hasGroupBy() )
    x ^= query.getGroupBy().hashCode() ;
}

代码示例来源:origin: apache/jena

@Override
public void visitGroupBy(Query query)
{
  if ( query.hasGroupBy() )
  {
    // Can have an empty GROUP BY list if the groupin gis implicit
    // by use of an aggregate in the SELECT clause.
    if ( ! query.getGroupBy().isEmpty() )
    {
      out.print("GROUP BY ") ;
      appendNamedExprList(query, out, query.getGroupBy()) ;
      out.println();
    }
  }
}

代码示例来源:origin: apache/jena

/**
 * Copy all the modifications from the Solution Modifier argument
 * @param solutionModifier The solution modifier to copy from.
 */
public void addAll(SolutionModifierHandler solutionModifier) {
  List<SortCondition> lst = solutionModifier.query.getOrderBy();
  if (lst != null) {
    for (SortCondition sc : lst) {
      query.addOrderBy(sc);
    }
  }
  query.getGroupBy().addAll(solutionModifier.query.getGroupBy());
  query.getHavingExprs().addAll(solutionModifier.query.getHavingExprs());
  query.setLimit(solutionModifier.query.getLimit());
  query.setOffset(solutionModifier.query.getOffset());
}

代码示例来源:origin: apache/jena

@Override
public void setVars(Map<Var, Node> values) {
  if (values.isEmpty()) {
    return;
  }
  ExprRewriter exprRewriter = new ExprRewriter(values);
  ExprList having = exprRewriter.rewrite(new ExprList(query
      .getHavingExprs()));
  List<SortCondition> orderBy = exprRewriter
      .rewriteSortConditionList(query.getOrderBy());
  VarExprList groupBy = exprRewriter.rewrite(query.getGroupBy());
  query.getHavingExprs().clear();
  query.getHavingExprs().addAll(having.getList());
  if (orderBy != null) {
    if (query.getOrderBy() == null) {
      for (SortCondition sc : orderBy) {
        query.addOrderBy(sc);
      }
    } else {
      query.getOrderBy().clear();
      query.getOrderBy().addAll(orderBy);
    }
  }
  query.getGroupBy().clear();
  query.getGroupBy().addAll(groupBy); 
}

代码示例来源:origin: org.apache.jena/jena-querybuilder

/**
 * Copy all the modifications from the Solution Modifier argument
 * @param solutionModifier The solution modifier to copy from.
 */
public void addAll(SolutionModifierHandler solutionModifier) {
  List<SortCondition> lst = solutionModifier.query.getOrderBy();
  if (lst != null) {
    for (SortCondition sc : lst) {
      query.addOrderBy(sc);
    }
  }
  query.getGroupBy().addAll(solutionModifier.query.getGroupBy());
  query.getHavingExprs().addAll(solutionModifier.query.getHavingExprs());
  query.setLimit(solutionModifier.query.getLimit());
  query.setOffset(solutionModifier.query.getOffset());
}

代码示例来源:origin: apache/jena

@Override
public void visitGroupBy(Query query) {
  if (query.hasGroupBy()) {
    VarExprList x = query.getGroupBy();
    for (Var v : x.getVars()) {
      Expr expr = x.getExpr(v);
      if (expr == null)
        newQuery.addGroupBy(v);
      else
        newQuery.addGroupBy(v, expr);
    }
  }
}

代码示例来源:origin: org.apache.jena/jena-querybuilder

@Override
public void setVars(Map<Var, Node> values) {
  if (values.isEmpty()) {
    return;
  }
  ExprRewriter exprRewriter = new ExprRewriter(values);
  ExprList having = exprRewriter.rewrite(new ExprList(query
      .getHavingExprs()));
  List<SortCondition> orderBy = exprRewriter
      .rewriteSortConditionList(query.getOrderBy());
  VarExprList groupBy = exprRewriter.rewrite(query.getGroupBy());
  query.getHavingExprs().clear();
  query.getHavingExprs().addAll(having.getList());
  if (orderBy != null) {
    if (query.getOrderBy() == null) {
      for (SortCondition sc : orderBy) {
        query.addOrderBy(sc);
      }
    } else {
      query.getOrderBy().clear();
      query.getOrderBy().addAll(orderBy);
    }
  }
  query.getGroupBy().clear();
  query.getGroupBy().addAll(groupBy); 
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

@Override
public void visitGroupBy(Query query) {
  if ( query.hasGroupBy() ) {
    VarExprList x = query.getGroupBy() ;
    for (Var v : x.getVars()) {
      Expr expr = x.getExpr(v) ;
      if ( expr == null )
        newQuery.addGroupBy(v) ;
      else
        newQuery.addGroupBy(v, expr) ;
    }
  }
}

代码示例来源:origin: apache/jena

VarExprList groupKey = query.getGroupBy() ;

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static Query transform(Query query, ElementTransform transform, ExprTransform exprTransform) {
  Query q2 = QueryTransformOps.shallowCopy(query) ;
  transformVarExprList(q2.getProject(), exprTransform) ;
  transformVarExprList(q2.getGroupBy(), exprTransform) ;
  // Nothing to do about ORDER BY - leave to sort by that variable.
  Element el = q2.getQueryPattern() ;
  Element el2 = ElementTransformer.transform(el, transform, exprTransform) ;
  // Top level is always a group.
  if ( ! ( el2 instanceof ElementGroup ) ) {
    ElementGroup eg = new ElementGroup() ;
    eg.addElement(el2);
    el2 = eg ;
  }
  q2.setQueryPattern(el2) ;
  return q2 ;
}

代码示例来源:origin: apache/jena

private static void check(Query query, Collection<Var> vars)
{
  // Check any expressions are assigned to fresh variables.
  checkExprListAssignment(vars, query.getProject()) ;
  
  // Check for SELECT * GROUP BY
  // Legal in ARQ, not in SPARQL 1.1
  if ( ! Syntax.syntaxARQ.equals(query.getSyntax()) )
  {
    if ( query.isQueryResultStar() && query.hasGroupBy() )
      throw new QueryParseException("SELECT * not legal with GROUP BY", -1 , -1) ;
  }
  
  // Check any variable in an expression is in scope (if GROUP BY) 
  checkExprVarUse(query) ;
  
  // Check GROUP BY AS 
  // ENABLE
  if ( false && query.hasGroupBy() )
  {
    VarExprList exprList2 = query.getGroupBy() ;
    checkExprListAssignment(vars, exprList2) ;
  // CHECK 
  }
  
}

代码示例来源:origin: apache/jena

query.getGroupBy().addAll(level.opGroup.getGroupVars()) ;
level.opGroup.getAggregators().forEach(eAgg -> {
  ExprVar v = eAgg.getAggVar() ;

代码示例来源:origin: apache/jena

/** Transform a query using {@link ElementTransform} and {@link ExprTransform}.
 *  It is the responsibility of these transforms to transform to a legal SPARQL query.
 */ 
public static Query transform(Query query, ElementTransform transform, ExprTransform exprTransform) {
  Query q2 = QueryTransformOps.shallowCopy(query);
  // "Shallow copy with transform."
  transformVarExprList(q2.getProject(), exprTransform);
  transformVarExprList(q2.getGroupBy(), exprTransform);
  transformExprList(q2.getHavingExprs(), exprTransform);
  if (q2.getOrderBy() != null) {
    transformSortConditions(q2.getOrderBy(), exprTransform);
  }
  // ?? DOES NOT WORK: transformExprListAgg(q2.getAggregators(), exprTransform) ; ??
  // if ( q2.hasHaving() ) {}
  // if ( q2.hasAggregators() ) {}
  Element el = q2.getQueryPattern();
  Element el2 = ElementTransformer.transform(el, transform, exprTransform);
  // Top level is always a group.
  if (!(el2 instanceof ElementGroup)) {
    ElementGroup eg = new ElementGroup();
    eg.addElement(el2);
    el2 = eg;
  }
  q2.setQueryPattern(el2);
  return q2;
}

代码示例来源:origin: SmartDataAnalytics/jena-sparql-api

public static long countQuery(Query query, QueryExecutionFactory qef) {
  boolean needsWrapping = !query.getGroupBy().isEmpty() || !query.getAggregators().isEmpty();

代码示例来源:origin: apache/jena

op = OpGroup.create(op, query.getGroupBy(), query.getAggregators()) ;

代码示例来源:origin: rdfhdt/hdt-java

if(ag==null || !query.getHavingExprs().isEmpty() || !query.getGroupBy().isEmpty() || query.hasLimit() || query.hasOffset() || !( (ag instanceof AggCount) || (ag instanceof AggCountVar) || (ag instanceof AggCountDistinct) || (ag instanceof AggCountVarDistinct)) ) {
  return null;

相关文章