Package lupos.sparql1_1

Examples of lupos.sparql1_1.ASTSelectQuery


    // return "PREFIX\t"+pref+":\t"+visitChild( node, 0 )+"\n";
    // }

    if (this.rules[BASE] && this.base != null) {
      final URI uri = URI.create(pref);
      final ASTQuotedURIRef content = (ASTQuotedURIRef) node
          .jjtGetChild(0);
      String qRef = content.getQRef();
      if (!uri.isAbsolute()) {
        // pref = "<"
        // + base.toString().substring(1,
        // base.toString().length() - 1) + pref + ">";
        try {
View Full Code Here


      // walk through first level children of AST...
      for (int i = 0; i < ast.jjtGetNumChildren(); ++i) {
        final Node child = ast.jjtGetChild(i); // get current child

        if (child instanceof ASTSelectQuery) {
          final ASTSelectQuery selectChild = (ASTSelectQuery) child;

          // SELECT is not the wildcard *...
          if (!selectChild.isSelectAll()) {
            // walk through select children...
            for (int j = 0; j < selectChild.jjtGetNumChildren(); ++j) {
              final Node selectChildChild = selectChild
              .jjtGetChild(j);

              // child of select is variable...
              if (selectChildChild instanceof ASTVar) {
                final ASTVar var = (ASTVar) selectChildChild;
View Full Code Here

      }
    } else if(node instanceof ASTTripleSet){
      FederatedQuery.checkVariables(node, result);
    } else if(node instanceof ASTSelectQuery){
      // check embedded select queries recursively
      final ASTSelectQuery select = (ASTSelectQuery) node;
      final Set<Variable> innerQueryVariables = new HashSet<Variable>();
      final Set<Variable> innerQueryProjectedVariables = new HashSet<Variable>();
      for(final Node innerQueryChild: select.getChildren()){
        if(innerQueryChild instanceof ASTVar){
          final Variable v = new Variable(((ASTVar) innerQueryChild).getName());
          innerQueryProjectedVariables.add(v);
        } else if(innerQueryChild instanceof ASTGroupConstraint){
          innerQueryVariables.addAll(FederatedQuery.getSurelyBoundVariables(innerQueryChild));
        }
      }

      if(!select.isSelectAll()){
        innerQueryVariables.retainAll(innerQueryProjectedVariables);
      }
      result.addAll(innerQueryVariables);
    } else if(node instanceof ASTUnionConstraint){
      // Check union...
View Full Code Here

  }

  protected boolean handleHigherConstructToJoin(final Node n, final OperatorConnection connection, final Item graphConstraint){
    if (this.isHigherConstructToJoin(n)) {
      if(n instanceof ASTService){
        final ASTService service = (ASTService) n;
        if(this.serviceGenerator.countsAsJoinPartner(service)){
          this.serviceGenerator.insertIndependantFederatedQueryOperator(service, connection, this.indexScanCreator);
          return true;
        } else {
          return false;
View Full Code Here

  private void handleProjections(final SimpleNode node,
      final RetrieveDataWithProjectionAndSolutionModifier operator) {
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
      if (node.jjtGetChild(i) instanceof ASTVar) {
        final ASTVar var = (ASTVar) node.jjtGetChild(i);

        try {
          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      } else if (node.jjtGetChild(i) instanceof ASTQuotedURIRef) {
        final ASTQuotedURIRef var = (ASTQuotedURIRef) node
        .jjtGetChild(i);

        try {
          operator.addProjectionElement(var.toQueryString());
        } catch (final ModificationException e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here

              final Node selectChildChild = selectChild
              .jjtGetChild(j);

              // child of select is variable...
              if (selectChildChild instanceof ASTVar) {
                final ASTVar var = (ASTVar) selectChildChild;

                // add name of variable to order...
                if (!resultOrder.contains(var.getName())) {
                  resultOrder.add(var.getName());
                }
              } else if (selectChildChild instanceof ASTAs) {
                for (int j1 = 0; j1 < selectChildChild
                .jjtGetNumChildren(); ++j1) {
                  final Node selectChildChildChild = selectChildChild
                  .jjtGetChild(j1);
                  if (selectChildChildChild instanceof ASTVar) {
                    final ASTVar var = (ASTVar) selectChildChildChild;

                    // add name of variable to order...
                    if (!resultOrder.contains(var
                        .getName())) {
                      resultOrder.add(var
                          .getName());
                    }
                  }
                }
              }
View Full Code Here

  public static Item getItem(final Node n) {
    if(n instanceof ASTObjectList) {
      return getItem(n.jjtGetChild(0));
    }
    if (n instanceof ASTVar) {
      final ASTVar var = (ASTVar) n;
      final String name = var.getName();
      return new Variable(name);
    } else {
      return LazyLiteral.getLiteral(n, true);
    }
  }
View Full Code Here

      projection.addProjectionElement(subject);
      projection.addProjectionElement(object);
      if(graphConstraint!=null && graphConstraint.isVariable() && !graphConstraint.equals(getItem(subjectNode)) && !graphConstraint.equals(getItem(objectNode))) {
        projection.addProjectionElement((Variable)graphConstraint);
      }
      final ASTVar n = new ASTVar(100);
      n.setName(subject.toString().substring(1));
      final Bind bind = new Bind(subject);
      bind.addProjectionElement(object,n);
      union.addSucceedingOperator(new OperatorIDTuple(bind,0));
      bind.addSucceedingOperator(new OperatorIDTuple(projection,0));
      final InMemoryDistinct memoryDistinct = new InMemoryDistinct();
View Full Code Here

      boolean graphVariableIsSelected = false;
      for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        final Node n = node.jjtGetChild(i);
        if (n instanceof ASTVar) {
          final ASTVar variable = (ASTVar) n;
          if (variable.getName().equals(graphConstraint.getName())) {
            graphVariableIsSelected = true;
          }
        }
      }
      // as a workaround we rename the graphvariable in the subquery
      if (!graphVariableIsSelected) {
        int index=0;
        do {
          graphConstraint = new Variable(graphConstraint.getName() + index);
          index++;
        } while (this.hasThisVariable(node, graphConstraint));
      }
    }
    final int numberChildren = node.jjtGetNumChildren();

    boolean onlyAggregations = true;

    // insert limit operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTLimit) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }
    // insert offset operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTOffset) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }

    if (node instanceof ASTSelectQuery && ((ASTSelectQuery)node).isDistinct()) {

      // or insert a DISTINCT operator into the operator graph:
      connection.connectAndSetAsNewOperatorConnection(new Distinct());
    }

    LinkedList<AddComputedBinding> listOACB = new LinkedList<AddComputedBinding>();
    boolean group = false;

    for (int i = 0; i < numberChildren; i++) {
      final Node childi = node.jjtGetChild(i);
      if (childi instanceof ASTGroup) {
        group = true;
      }
    }

    // insert projection operator

    if (!(node instanceof ASTSelectQuery && ((ASTSelectQuery)node).isSelectAll())) {
      final Projection p = new Projection();
      final LinkedList<AddComputedBinding> listOfAddComputedBindings = new LinkedList<AddComputedBinding>();
      for (int i = 0; i < numberChildren; i++) {
        if (node.jjtGetChild(i) instanceof ASTVar) {
          final ASTVar variable = (ASTVar) node.jjtGetChild(i);
          p.addProjectionElement(new Variable(variable.getName()));
          onlyAggregations = false;
        } else if (node.jjtGetChild(i) instanceof ASTAs) {
          final ASTVar variable = (ASTVar) node.jjtGetChild(i)
              .jjtGetChild(1);
          final lupos.sparql1_1.Node constraint = node.jjtGetChild(i)
              .jjtGetChild(0);
          /*
           * Detecting Errors in SelectQuery if aggregations are used
           * and additional variables are not bound by a GROUP BY
           * statement
           */
          // this.prooveBoundedGroup(node.jjtGetChild(i));

          if (!(constraint instanceof ASTAggregation)) {
            onlyAggregations = false;
          }
          final Variable var2 = new Variable(variable.getName());
          p.addProjectionElement(var2);
          final AddComputedBinding acb = group ? new GroupByAddComputedBinding()
              : new AddComputedBinding();
          acb.addProjectionElement(var2, constraint);
          listOfAddComputedBindings.add(acb);
        }
      }
      // deleting of values if there is only an aggregation statement
      if (onlyAggregations || group) {
        connection.connectAndSetAsNewOperatorConnection(new Distinct());
      }
      listOACB = this.topologicalSorting(listOfAddComputedBindings);
      connection.connectAndSetAsNewOperatorConnection(p);
    }

    // insert sort operator
    for (int i = 0; i < numberChildren; i++) {
      if (node.jjtGetChild(i) instanceof ASTOrderConditions) {
        node.jjtGetChild(i).accept(this, connection);
      }
    }

    for (final AddComputedBinding acb : listOACB) {
      connection.connectAndSetAsNewOperatorConnection(acb);
    }

    // Dealing with the HAVING clause
    for (int i = 0; i < numberChildren; i++) {
      final Node childi = node.jjtGetChild(i);
      if (childi instanceof ASTHaving) {
        for (int k = 0; k < childi.jjtGetNumChildren(); k++) {
          if (childi.jjtGetChild(k) instanceof ASTFilterConstraint) {
            final Having filter = new Having((ASTFilterConstraint) childi
                .jjtGetChild(k));
            this.processExistChildren(node, graphConstraint, filter);
            filter.setEvaluator(this.evaluator);
            connection.connectAndSetAsNewOperatorConnection(filter);
          }
        }

      }
    }

    // Dealing with the GROUP clause
    for (int j = 0; j < numberChildren; j++) {
      final Projection p = new Projection();
      final LinkedList<AddComputedBinding> listOfAddComputedBindings = new LinkedList<AddComputedBinding>();
      ASTVar variable = null;
      final Node childi = node.jjtGetChild(j);
      onlyAggregations = true;
      if (childi instanceof ASTGroup) {
        for (int i = 0; i < childi.jjtGetNumChildren(); i++) {
          if (childi.jjtGetChild(i) instanceof ASTAdditionNode
              || childi.jjtGetChild(i) instanceof ASTSubtractionNode
              || childi.jjtGetChild(i) instanceof ASTMultiplicationNode
              || childi.jjtGetChild(i) instanceof ASTDivisionNode) {
            throw new Error(
                "Error in GROUP BY statement: AS not found");

          } else if (childi.jjtGetChild(i) instanceof ASTAs) {

            variable = (ASTVar) childi.jjtGetChild(i).jjtGetChild(1);
            final lupos.sparql1_1.Node constraint = childi.jjtGetChild(i).jjtGetChild(0);

            /*
             * Detecting Errors in SelectQuery if aggregations are
             * used and additional variables are not bound by a
             * GROUP BY statement
             */
            this.prooveBoundedGroup(constraint);

            if (!(constraint instanceof ASTAggregation)) {
              onlyAggregations = false;
            }
            final Variable var2 = new Variable(variable.getName());
            p.addProjectionElement(var2);

            final AddComputedBinding acb = new GroupByAddComputedBinding();
            acb.addProjectionElement(var2, constraint);
            listOfAddComputedBindings.add(acb);
View Full Code Here

   */
  private void groupNegativeSyntaxTest(final lupos.sparql1_1.Node childi, final lupos.sparql1_1.Node node) {
    final LinkedList<Variable> groupVariables = new LinkedList<Variable>();
    for (int k = 0; k < childi.jjtGetNumChildren(); k++) {
      if (childi.jjtGetChild(k) instanceof ASTVar) {
        final ASTVar variable = (ASTVar) childi.jjtGetChild(k);
        groupVariables.add(new Variable(variable.getName()));
      } else if (childi.jjtGetChild(k) instanceof ASTAs) {
        final ASTVar variable = (ASTVar) childi.jjtGetChild(k).jjtGetChild(1);
        groupVariables.add(new Variable(variable.getName()));
      }
    }
    final LinkedList<Variable> selectVariables = new LinkedList<Variable>();
    for (int k = 0; k < node.jjtGetNumChildren(); k++) {
      if (node.jjtGetChild(k) instanceof ASTVar) {
        final ASTVar variable = (ASTVar) node.jjtGetChild(k);
        selectVariables.add(new Variable(variable.getName()));
      }
    }
    for (int k = 0; k < groupVariables.size(); k++) {
      boolean allVariablesFound = false;
      for (int l = 0; l < selectVariables.size(); l++) {
View Full Code Here

TOP

Related Classes of lupos.sparql1_1.ASTSelectQuery

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.