Package org.openrdf.sail.rdbms.algebra

Examples of org.openrdf.sail.rdbms.algebra.SelectQuery$OrderElem


  public void meet(Distinct node)
    throws RdbmsException
  {
    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      query.setDistinct(true);
      node.replaceWith(query);
    }
  }
View Full Code Here


    super.meet(node);
    for (TupleExpr arg : node.getArgs()) {
      if (!(arg instanceof SelectQuery)) {
        return;
      }
      SelectQuery sq = (SelectQuery)arg;
      if (sq.isComplex()) {
        return;
      }
    }
    assert node.getNumberOfArguments() > 0;
    UnionItem union = new UnionItem("u" + aliasCount++);
    SelectQuery query = new SelectQuery();
    query.setFrom(union);
    for (TupleExpr arg : node.getArgs()) {
      SelectQuery sub = (SelectQuery)arg.clone();
      union.addUnion(sub.getFrom().clone());
      mergeSelectClause(query, sub);
    }
    addProjectionsFromUnion(query, union);
    node.replaceWith(query);
  }
View Full Code Here

    super.meet(node);
    for (TupleExpr arg : node.getArgs()) {
      if (!(arg instanceof SelectQuery)) {
        return;
      }
      SelectQuery sq = (SelectQuery)arg;
      if (sq.isComplex()) {
        return;
      }
    }
    assert node.getNumberOfArguments() > 0;
    SelectQuery left = null;
    for (TupleExpr arg : node.getArgs()) {
      if (left == null) {
        left = (SelectQuery)arg.clone();
      }
      else {
        SelectQuery right = (SelectQuery)arg.clone();
        filterOn(left, right);
        mergeSelectClause(left, right);
        left.addJoin(right);
      }
    }
View Full Code Here

    TupleExpr l = node.getLeftArg();
    TupleExpr r = node.getRightArg();
    if (!(l instanceof SelectQuery && r instanceof SelectQuery)) {
      return;
    }
    SelectQuery left = (SelectQuery)l;
    SelectQuery right = (SelectQuery)r;
    if (left.isComplex() || right.isComplex()) {
      return;
    }
    Set<String> names = new HashSet<String>(left.getBindingNames());
    names.retainAll(right.getBindingNames());
    if (names.isEmpty()) {
      return;
    }
    left = left.clone();
    right = right.clone();
    filterOn(left, right);
    mergeSelectClause(left, right);
    left.addLeftJoin(right);
    List<SqlExpr> filters = new ArrayList<SqlExpr>();
    if (node.getCondition() != null) {
      for (ValueExpr expr : flatten(node.getCondition())) {
        try {
          filters.add(sql.createBooleanExpr(expr));
        }
        catch (UnsupportedRdbmsOperatorException e) {
          return;
        }
      }
    }
    for (SqlExpr filter : filters) {
      right.addFilter(filter);
    }
    node.replaceWith(left);
  }
View Full Code Here

    ColumnVar c = createCtx(alias, ctxVar, (Resource)ctxValue);

    s.setTypes(tables.getSubjTypes(predId));
    o.setTypes(tables.getObjTypes(predId));

    SelectQuery query = new SelectQuery();
    query.setFrom(from);
    Map<String, ColumnVar> vars = new HashMap<String, ColumnVar>(4);
    for (ColumnVar var : new ColumnVar[] { s, p, o, c }) {
      from.addVar(var);
      Value value = var.getValue();
      if (vars.containsKey(var.getName())) {
        IdColumn existing = new IdColumn(vars.get(var.getName()));
        from.addFilter(new SqlEq(new IdColumn(var), existing));
      }
      else if (value != null && !var.isImplied()) {
        try {
          NumberValue vc = new NumberValue(vf.getInternalId(value));
          from.addFilter(new SqlEq(new RefIdColumn(var), vc));
        }
        catch (RdbmsException e) {
          throw new RdbmsException(e);
        }
      }
      else {
        vars.put(var.getName(), var);
      }
      if (!var.isHiddenOrConstant() && value == null) {
        SelectProjection proj = new SelectProjection();
        proj.setVar(var);
        proj.setId(new RefIdColumn(var));
        proj.setStringValue(coalesce(new URIColumn(var), new BNodeColumn(var), new LabelColumn(var),
            new LongLabelColumn(var), new LongURIColumn(var)));
        proj.setDatatype(new DatatypeColumn(var));
        proj.setLanguage(new LanguageColumn(var));
        query.addSqlSelectVar(proj);
      }
    }
    if (contexts.length > 0) {
      RdbmsResource[] ids = vf.asRdbmsResource(contexts);
      RefIdColumn var = new RefIdColumn(c);
View Full Code Here

  public void meet(Filter node)
    throws RdbmsException
  {
    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      ValueExpr condition = null;
      for (ValueExpr expr : flatten(node.getCondition())) {
        try {
          query.addFilter(sql.createBooleanExpr(expr));
        }
        catch (UnsupportedRdbmsOperatorException e) {
          if (condition == null) {
            condition = expr;
          }
View Full Code Here

  public void meet(Projection node)
    throws RdbmsException
  {
    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      Map<String, String> bindingVars = new HashMap<String, String>();
      List<SelectProjection> selection = new ArrayList<SelectProjection>();
      ProjectionElemList list = node.getProjectionElemList();
      for (ProjectionElem e : list.getElements()) {
        String source = e.getSourceName();
        String target = e.getTargetName();
        bindingVars.put(target, source);
        SelectProjection s = query.getSelectProjection(source);
        if (s != null) {
          selection.add(s);
        }
      }
      query.setBindingVars(bindingVars);
      query.setSqlSelectVar(selection);
      node.replaceWith(query);
    }
  }
View Full Code Here

  public void meet(Slice node)
    throws RdbmsException
  {
    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      if (node.getOffset() > 0) {
        query.setOffset(node.getOffset());
      }
      if (node.getLimit() >= 0) {
        query.setLimit(node.getLimit());
      }
      node.replaceWith(query);
    }
  }
View Full Code Here

  {
    super.meet(node);
    if (!(node.getArg() instanceof SelectQuery)) {
      return;
    }
    SelectQuery query = (SelectQuery)node.getArg();
    try {
      for (OrderElem e : node.getElements()) {
        ValueExpr expr = e.getExpr();
        boolean asc = e.isAscending();
        query.addOrder(sql.createBNodeExpr(expr), asc);
        query.addOrder(sql.createUriExpr(expr), asc);
        query.addOrder(sql.createNumericExpr(expr), asc);
        query.addOrder(sql.createDatatypeExpr(expr), asc);
        query.addOrder(sql.createTimeExpr(expr), asc);
        query.addOrder(sql.createLanguageExpr(expr), asc);
        query.addOrder(sql.createLabelExpr(expr), asc);
      }
      node.replaceWith(query);
    }
    catch (UnsupportedRdbmsOperatorException e) {
      // unsupported
View Full Code Here

    super.meet(node);
    TupleExpr l = node.getLeftArg();
    TupleExpr r = node.getRightArg();
    if (!(l instanceof SelectQuery && r instanceof SelectQuery))
      return;
    SelectQuery left = (SelectQuery)l;
    SelectQuery right = (SelectQuery)r;
    if (left.isComplex() || right.isComplex())
      return;
    UnionItem union = new UnionItem("u" + aliasCount++);
    union.addUnion(left.getFrom().clone());
    union.addUnion(right.getFrom().clone());
    SelectQuery query = new SelectQuery();
    query.setFrom(union);
    mergeSelectClause(query, left);
    mergeSelectClause(query, right);
    node.replaceWith(query);
  }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.rdbms.algebra.SelectQuery$OrderElem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.