Package org.openrdf.sail.rdbms.algebra

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


    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;
    left = left.clone();
    right = right.clone();
    filterOn(left, right);
    mergeSelectClause(left, right);
    left.addJoin(right);
    node.replaceWith(left);
  }
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;
    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 RdbmsRuntimeException(e);
        }
      }
      else {
        vars.put(var.getName(), var);
      }
      if (!var.isHidden() && 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 RuntimeException
  {
    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 RuntimeException
  {
    super.meet(node);
    if (node.getArg() instanceof SelectQuery) {
      SelectQuery query = (SelectQuery)node.getArg();
      Map<String, String> bindingNames = 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();
        bindingNames.put(source, target);
        SelectProjection s = query.getSelectProjection(source);
        if (s != null) {
          selection.add(s);
        }
      }
      query.setBindingNames(bindingNames);
      query.setSqlSelectVar(selection);
      node.replaceWith(query);
    }
  }
View Full Code Here

  public void meet(Slice node)
    throws RuntimeException
  {
    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);
    }
    if (node.getArg() instanceof UnaryTupleOperator &&
      ((UnaryTupleOperator)node.getArg()).getArg() instanceof Extension &&
      ((Extension)((UnaryTupleOperator)node.getArg()).getArg()).getArg() instanceof SelectQuery) {
        SelectQuery query = (SelectQuery) ((Extension)((UnaryTupleOperator)node.getArg()).getArg()).getArg();
        if (node.getOffset() > 0) {
          query.setOffset(node.getOffset());
        }
        if (node.getLimit() >= 0) {
          query.setLimit(node.getLimit());
        }
        node.replaceWith(node.getArg());       
      }
  }
View Full Code Here

    throws RuntimeException
  {
    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

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

TOP

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

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.