protected AbstractIterHashJoin(
      JoinKey joinKey,
      QueryIterator probeIter,
      QueryIterator streamIter,
      ExecutionContext execCxt) {
    super(probeIter, streamIter, execCxt);

    if (joinKey == null) {
      QueryIterPeek pProbe = QueryIterPeek.create(probeIter, execCxt);
      QueryIterPeek pStream = QueryIterPeek.create(streamIter, execCxt);

      Binding bLeft = pProbe.peek();
      Binding bRight = pStream.peek();

      List<Var> varsLeft = Iter.toList(bLeft.vars());
      List<Var> varsRight = Iter.toList(bRight.vars());
      joinKey = JoinKey.createVarKey(varsLeft, varsRight);
      probeIter = pProbe;
      streamIter = pStream;
    }

    this.joinKey = joinKey;
    this.iterStream = streamIter;
    this.hashTable = new HashProbeTable(joinKey);
    this.iterCurrent = null;
    buildHashTable(probeIter);
  }
Exemple #2
0
  private Triple resolveTriple(final Triple t, final Binding values) {
    int idx = variables.indexOf(t.getSubject());

    final Node s = idx == -1 ? t.getSubject() : values.get(Var.alloc(variables.get(idx)));

    idx = variables.indexOf(t.getPredicate());
    final Node p = idx == -1 ? t.getPredicate() : values.get(Var.alloc(variables.get(idx)));
    idx = variables.indexOf(t.getObject());
    final Node o = idx == -1 ? t.getObject() : values.get(Var.alloc(variables.get(idx)));
    return new Triple(s, p, o);
  }
Exemple #3
0
  private List<Var> calcVars() {
    List<Var> vars = new ArrayList<>(4);
    // Only if not in parent.
    // A (var/value) binding may have been copied down to record it's NodeId.

    Binding b = idBinding.getParentBinding();

    Iterator<Var> iter = idBinding.iterator();
    for (Var v : idBinding) {
      if (b == null || !b.contains(v)) vars.add(v);
    }
    return vars;
  }
Exemple #4
0
  private static NodeValue evalOrElse(
      Expr expr, Binding binding, FunctionEnv functionEnv, NodeValue exceptionValue) {
    // Exceptions in java are expensive if the stack information is
    // collected which is the default behaviour.  The expensive step is
    // Throwable.fillInStackTrace.
    //
    // Otherwise, they are reasonable cheap. It needs special exceptions
    // which overrides fillInStackTrace to be cheap but they loose the
    // general information for development.
    //
    // Instead, pick out specal cases, the expression being a single variable
    // being the important one.
    //
    // BOUND(?x) is a important case where the expression is often an exception
    // in general evaluation.  See E_Bound - different exception handling
    // (it handles VariableNotBoundException not a general ExprEvalException).

    if (expr.isConstant())
      // Easy case.
      return expr.getConstant();
    if (expr.isVariable()) {
      // The case of the expr being a single variable.
      Var v = expr.asVar();
      Node n = binding.get(v);
      if (n == null) return exceptionValue;
      NodeValue nv = NodeValue.makeNode(n);
      return nv;
    }

    try {
      return expr.eval(binding, functionEnv);
    } catch (ExprEvalException ex) {
      return exceptionValue;
    }
  }
 private ResultSet ConvertResults(org.apache.jena.query.ResultSet results) {
   ResultSet rs = new ResultSet();
   while (results.hasNext()) {
     Binding b = results.nextBinding();
     Result result = new Result();
     Iterator<Var> v = b.vars();
     while (v.hasNext()) {
       Var currentV = v.next();
       Node val = b.get(currentV);
       if (currentV.toString().contains("_info_")) {
         String[] parts = val.getLiteral().getLexicalForm().toString().split("=");
         if (parts.length > 1) {
           for (int i = 0; i < parts.length; i++) {
             String[] subParts = parts[i].split("\\.");
             if (subParts.length > 1) {
               if (!Character.isDigit(subParts[1].charAt(0))) result.addTable(subParts[0]);
             }
           }
         }
         result.addWhere(val.getLiteral().getLexicalForm());
       } else {
         if (val.isLiteral()) {
           String value = val.getLiteral().getLexicalForm();
           String datatype = val.getLiteralDatatypeURI();
           if (datatype.equals(S2SML.LITERAL_MAP_IRI)) {
             String[] parts = value.split("\\.");
             if (parts.length > 1) {
               if (!Character.isDigit(parts[1].charAt(0))) result.addTable(parts[0]);
             }
           }
         }
         //					System.out.println(currentV.toString().replace("?", "") +" "+val);
         result.addVarMapping(
             currentV.toString().replace("?", ""), FormatUtil.processNode(val, dialect));
       }
     }
     rs.add(result);
   }
   return rs;
 }