Package org.apache.tajo.storage

Examples of org.apache.tajo.storage.Tuple


    return sb.toString();
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple;
    while((tuple = child.next()) != null) {

      fillKeyTuple(tuple, currentKey);

      if (prevKey == null) {
View Full Code Here


    this.qual = plan.getQual();
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple;
    while ((tuple = child.next()) != null) {
      if (qual.eval(inSchema, tuple).isTrue()) {
        return tuple;
      }
    }
View Full Code Here

  public JoinNode getPlan(){
    return this.joinNode;
  }

  public Tuple next() throws IOException {
    Tuple previous;

    for (;;) {
      boolean newRound = false;
      if((posRightTupleSlots == -1) && (posLeftTupleSlots == -1)) {
        newRound = true;
      }
      if ((posRightTupleSlots == rightTupleSlots.size()) && (posLeftTupleSlots == leftTupleSlots.size())) {
        newRound = true;
      }

      if(newRound == true){

        if (end) {

          ////////////////////////////////////////////////////////////////////////
          // FINALIZING STAGE
          ////////////////////////////////////////////////////////////////////////
          // the finalizing stage, where remaining tuples on the right are
          // transformed into left-padded results while tuples on the left
          // are transformed into right-padded results

          // before exit, a left-padded tuple should be built for all remaining
          // right side and a right-padded tuple should be built for all remaining
          // left side

          if (initRightDone == false) {
            // maybe the left operand was empty => the right one didn't have the chance to initialize
            rightTuple = rightChild.next();
            initRightDone = true;
          }

          if((leftTuple == null) && (rightTuple == null)) {
            return null;
          }

          if((leftTuple == null) && (rightTuple != null)){
            // output a tuple with the nulls padded leftTuple
            Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(leftNumCols);
            frameTuple.set(nullPaddedTuple, rightTuple);
            projector.eval(frameTuple, outTuple);
            // we simulate we found a match, which is exactly the null padded one
            rightTuple = rightChild.next();
            return outTuple;
          }

          if((leftTuple != null) && (rightTuple == null)){
            // output a tuple with the nulls padded leftTuple
            Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(rightNumCols);
            frameTuple.set(leftTuple, nullPaddedTuple);
            projector.eval(frameTuple, outTuple);
            // we simulate we found a match, which is exactly the null padded one
            leftTuple = leftChild.next();
            return outTuple;
          }
        } // if end

        ////////////////////////////////////////////////////////////////////////
        // INITIALIZING STAGE
        ////////////////////////////////////////////////////////////////////////
        // initializing stage, reading the first tuple on each side
        if (leftTuple == null) {
          leftTuple = leftChild.next();
          if( leftTuple == null){
            end = true;
            continue;
          }
        }
        if (rightTuple == null) {
          rightTuple = rightChild.next();
          initRightDone = true;
          if (rightTuple == null) {
            end = true;
            continue;
          }
        }

        // reset tuple slots for a new round
        leftTupleSlots.clear();
        rightTupleSlots.clear();
        posRightTupleSlots = -1;
        posLeftTupleSlots = -1;

        ////////////////////////////////////////////////////////////////////////
        // Comparison and Move Forward Stage
        ////////////////////////////////////////////////////////////////////////
        // advance alternatively on each side until a match is found
        int cmp;
        while (!end && ((cmp = joincomparator.compare(leftTuple, rightTuple)) != 0)) {

          if (cmp > 0) {

            //before getting a new tuple from the right,  a leftnullpadded tuple should be built
            //output a tuple with the nulls padded leftTuple
            Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(leftNumCols);
            frameTuple.set(nullPaddedTuple, rightTuple);
            projector.eval(frameTuple, outTuple);
            // BEFORE RETURN, MOVE FORWARD
            rightTuple = rightChild.next();
            if(rightTuple == null) {
              end = true;
            }

            return outTuple;

          } else if (cmp < 0) {
            // before getting a new tuple from the left,  a rightnullpadded tuple should be built
            // output a tuple with the nulls padded rightTuple
            Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(rightNumCols);
            frameTuple.set(leftTuple, nullPaddedTuple);
            projector.eval(frameTuple, outTuple);
            // we simulate we found a match, which is exactly the null padded one
            // BEFORE RETURN, MOVE FORWARD
            leftTuple = leftChild.next();
            if(leftTuple == null) {
              end = true;
            }

            return outTuple;

          } // if (cmp < 0)
        } //while


        ////////////////////////////////////////////////////////////////////////
        // SLOTS POPULATION STAGE
        ////////////////////////////////////////////////////////////////////////
        // once a match is found, retain all tuples with this key in tuple slots
        // on each side
        if(!end) {
          endInPopulationStage = false;

          boolean endLeft = false;
          boolean endRight = false;

          previous = new VTuple(leftTuple);
          do {
            leftTupleSlots.add(new VTuple(leftTuple));
            leftTuple = leftChild.next();
            if(leftTuple == null) {
              endLeft = true;
            }


          } while ((endLeft != true) && (tupleComparator[0].compare(previous, leftTuple) == 0));
          posLeftTupleSlots = 0;


          previous = new VTuple(rightTuple);
          do {
            rightTupleSlots.add(new VTuple(rightTuple));
            rightTuple = rightChild.next();
            if(rightTuple == null) {
              endRight = true;
            }

          } while ((endRight != true) && (tupleComparator[1].compare(previous, rightTuple) == 0) );
          posRightTupleSlots = 0;

          if ((endLeft == true) || (endRight == true)) {
            end = true;
            endInPopulationStage = true;
          }

        } // if end false
      } // if newRound


      ////////////////////////////////////////////////////////////////////////
      // RESULTS STAGE
      ////////////////////////////////////////////////////////////////////////
      // now output result matching tuples from the slots
      // if either we haven't reached end on neither side, or we did reach end
      // on one(or both) sides but that happened in the slots population step
      // (i.e. refers to next round)
      if(!end || (end && endInPopulationStage)){
        if(posLeftTupleSlots == 0){
          leftNext = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
          posLeftTupleSlots = posLeftTupleSlots + 1;
        }

        if(posRightTupleSlots <= (rightTupleSlots.size() -1)) {
          Tuple aTuple = new VTuple(rightTupleSlots.get(posRightTupleSlots));
          posRightTupleSlots = posRightTupleSlots + 1;
          frameTuple.set(leftNext, aTuple);
          joinQual.eval(inSchema, frameTuple);
          projector.eval(frameTuple, outTuple);
          return outTuple;
        } else {
          // right (inner) slots reached end and should be rewind if there are still tuples in the outer slots
          if(posLeftTupleSlots <= (leftTupleSlots.size()-1)) {
            //rewind the right slots position
            posRightTupleSlots = 0;
            Tuple aTuple = new VTuple(rightTupleSlots.get(posRightTupleSlots));
            posRightTupleSlots = posRightTupleSlots + 1;
            leftNext = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
            posLeftTupleSlots = posLeftTupleSlots + 1;

            frameTuple.set(leftNext, aTuple);
View Full Code Here

    hashTable = new HashMap<Tuple, FunctionContext []>(100000);
    this.tuple = new VTuple(plan.getOutSchema().size());
  }

  private void compute() throws IOException {
    Tuple tuple;
    Tuple keyTuple;
    while((tuple = child.next()) != null && !context.isStopped()) {
      keyTuple = new VTuple(groupingKeyIds.length);
      // build one key tuple
      for(int i = 0; i < groupingKeyIds.length; i++) {
        keyTuple.put(i, tuple.get(groupingKeyIds[i]));
      }
     
      if(hashTable.containsKey(keyTuple)) {
        FunctionContext [] contexts = hashTable.get(keyTuple);
        for(int i = 0; i < aggFunctions.length; i++) {
View Full Code Here

    FunctionContext [] contexts;

    if (iterator.hasNext()) {
      Entry<Tuple, FunctionContext []> entry = iterator.next();
      Tuple keyTuple = entry.getKey();
      contexts =  entry.getValue();

      int tupleIdx = 0;
      for (; tupleIdx < groupingKeyNum; tupleIdx++) {
        tuple.put(tupleIdx, keyTuple.get(tupleIdx));
      }
      for (int funcIdx = 0; funcIdx < aggFunctionsNum; funcIdx++, tupleIdx++) {
        tuple.put(tupleIdx, aggFunctions[funcIdx].terminate(contexts[funcIdx]));
      }
View Full Code Here

   *
   * @return
   * @throws IOException
   */
  public Tuple next() throws IOException {
    Tuple previous;

    for (;;) {
      boolean newRound = false;
      if((posRightTupleSlots == -1) && (posLeftTupleSlots == -1)) {
        newRound = true;
      }
      if ((posRightTupleSlots == innerTupleSlots.size()) && (posLeftTupleSlots == leftTupleSlots.size())) {
        newRound = true;
      }

      if (newRound) {

        //////////////////////////////////////////////////////////////////////
        // BEGIN FINALIZING STAGE
        //////////////////////////////////////////////////////////////////////

        // The finalizing stage, where remaining tuples on the only right are transformed into left-padded results
        if (end) {
          if (initRightDone == false) {
            // maybe the left operand was empty => the right one didn't have the chance to initialize
            rightTuple = rightChild.next();
            initRightDone = true;
          }

          if(rightTuple == null) {
            return null;
          } else {
            // output a tuple with the nulls padded leftTuple
            Tuple nullPaddedTuple = createNullPaddedTuple(leftNumCols);
            frameTuple.set(nullPaddedTuple, rightTuple);
            projector.eval(frameTuple, outTuple);

            // we simulate we found a match, which is exactly the null padded one
            rightTuple = rightChild.next();

            return outTuple;
          }
        }
        //////////////////////////////////////////////////////////////////////
        // END FINALIZING STAGE
        //////////////////////////////////////////////////////////////////////


        //////////////////////////////////////////////////////////////////////
        // BEGIN INITIALIZATION STAGE
        //////////////////////////////////////////////////////////////////////

        // This stage reads the first tuple on each side
        if (leftTuple == null) {
          leftTuple = leftChild.next();

          if (leftTuple == null) {
            end = true;
            continue;
          }
        }

        if(rightTuple == null){
          rightTuple = rightChild.next();

          if(rightTuple != null){
            initRightDone = true;
          }
          else {
            initRightDone = true;
            end = true;
            continue;
          }
        }
        //////////////////////////////////////////////////////////////////////
        // END INITIALIZATION STAGE
        //////////////////////////////////////////////////////////////////////

        // reset tuple slots for a new round
        leftTupleSlots.clear();
        innerTupleSlots.clear();
        posRightTupleSlots = -1;
        posLeftTupleSlots = -1;


        //////////////////////////////////////////////////////////////////////
        // BEGIN MOVE FORWARDING STAGE
        //////////////////////////////////////////////////////////////////////

        // This stage moves forward a tuple cursor on each side relation until a match
        // is found
        int cmp;
        while ((end != true) && ((cmp = joinComparator.compare(leftTuple, rightTuple)) != 0)) {

          // if right is lower than the left tuple, it means that all right tuples s.t. cmp <= 0 are
          // matched tuples.
          if (cmp > 0) {
            // before getting a new tuple from the right,  a left null padded tuple should be built
            // output a tuple with the nulls padded left tuple
            Tuple nullPaddedTuple = createNullPaddedTuple(leftNumCols);
            frameTuple.set(nullPaddedTuple, rightTuple);
            projector.eval(frameTuple, outTuple);

            // we simulate we found a match, which is exactly the null padded one
            // BEFORE RETURN, MOVE FORWARD
            rightTuple = rightChild.next();
            if(rightTuple == null) {
              end = true;
            }
            return outTuple;

          } else if (cmp < 0) {
            // If the left tuple is lower than the right tuple, just move forward the left tuple cursor.
            leftTuple = leftChild.next();
            if(leftTuple == null) {
              end = true;
              // in original algorithm we had return null ,
              // but now we need to continue the end processing phase for remaining unprocessed right tuples
            }
          } // if (cmp<0)
        } // while
        //////////////////////////////////////////////////////////////////////
        // END MOVE FORWARDING STAGE
        //////////////////////////////////////////////////////////////////////

        // once a match is found, retain all tuples with this key in tuple slots on each side
        if(!end) {
          endInPopulationStage = false;

          boolean endOuter = false;
          boolean endInner = false;

          previous = new VTuple(leftTuple);
          do {
            leftTupleSlots.add(new VTuple(leftTuple));
            leftTuple = leftChild.next();
            if( leftTuple == null) {
              endOuter = true;
            }
          } while ((endOuter != true) && (tupleComparator[0].compare(previous, leftTuple) == 0));
          posLeftTupleSlots = 0;

          previous = new VTuple(rightTuple);

          do {
            innerTupleSlots.add(new VTuple(rightTuple));
            rightTuple = rightChild.next();
            if(rightTuple == null) {
              endInner = true;
            }

          } while ((endInner != true) && (tupleComparator[1].compare(previous, rightTuple) == 0) );
          posRightTupleSlots = 0;

          if ((endOuter == true) || (endInner == true)) {
            end = true;
            endInPopulationStage = true;
          }
        } // if end false
      } // if newRound


      // Now output result matching tuples from the slots
      // if either we haven't reached end on neither side, or we did reach end on one(or both) sides
      // but that happened in the slots population step (i.e. refers to next round)

      if ((end == false) || ((end == true) && (endInPopulationStage == true))){

        if(posLeftTupleSlots == 0){
          nextLeft = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
          posLeftTupleSlots = posLeftTupleSlots + 1;
        }


        if(posRightTupleSlots <= (innerTupleSlots.size() -1)) {

          Tuple aTuple = new VTuple(innerTupleSlots.get(posRightTupleSlots));
          posRightTupleSlots = posRightTupleSlots + 1;

          frameTuple.set(nextLeft, aTuple);
          joinQual.eval(inSchema, frameTuple);
          projector.eval(frameTuple, outTuple);
          return outTuple;

        } else {
          // right (inner) slots reached end and should be rewind if there are still tuples in the outer slots
          if(posLeftTupleSlots <= (leftTupleSlots.size() - 1)) {
            //rewind the right slots position
            posRightTupleSlots = 0;
            Tuple aTuple = new VTuple(innerTupleSlots.get(posRightTupleSlots));
            posRightTupleSlots = posRightTupleSlots + 1;
            nextLeft = new VTuple (leftTupleSlots.get(posLeftTupleSlots));
            posLeftTupleSlots = posLeftTupleSlots + 1;

            frameTuple.set(nextLeft, aTuple);
View Full Code Here

    this.qual = plan.getQual();
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple;
    while ((tuple = child.next()) != null) {
      if (qual.eval(inSchema, tuple).isTrue()) {
        return tuple;
      }
    }
View Full Code Here

  }

  public Tuple getNextUnmatchedRight() {

    List<Tuple> newValue;
    Tuple returnedTuple;
    // get a keyTUple from the matched hashmap with a boolean false value
    for(Tuple aKeyTuple : matched.keySet()) {
      if(matched.get(aKeyTuple) == false) {
        newValue = tupleSlots.get(aKeyTuple);
        returnedTuple = newValue.remove(0);
View Full Code Here

  public Tuple next() throws IOException {
    if (first) {
      loadRightToHashTable();
    }

    Tuple rightTuple;
    boolean found = false;

    while(!finished) {
      if (shouldGetLeftTuple) { // initially, it is true.
        // getting new outer
        leftTuple = leftChild.next(); // it comes from a disk
        if (leftTuple == null) { // if no more tuples in left tuples on disk, a join is completed.
          // in this stage we can begin outputing tuples from the right operand (which were before in tupleSlots) null padded on the left side
          Tuple unmatchedRightTuple = getNextUnmatchedRight();
          if( unmatchedRightTuple == null) {
            finished = true;
            outTuple = null;
            return null;
          } else {
            Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(leftNumCols);
            frameTuple.set(nullPaddedTuple, unmatchedRightTuple);
            projector.eval(frameTuple, outTuple);

            return outTuple;
          }
        }

        // getting corresponding right
        getKeyLeftTuple(leftTuple, leftKeyTuple); // get a left key tuple
        List<Tuple> rightTuples = tupleSlots.get(leftKeyTuple);
        if (rightTuples != null) { // found right tuples on in-memory hash table.
          iterator = rightTuples.iterator();
          shouldGetLeftTuple = false;
        } else {
          //this left tuple doesn't have a match on the right.But full outer join => we should keep it anyway
          //output a tuple with the nulls padded rightTuple
          Tuple nullPaddedTuple = TupleUtil.createNullPaddedTuple(rightNumCols);
          frameTuple.set(leftTuple, nullPaddedTuple);
          projector.eval(frameTuple, outTuple);
          // we simulate we found a match, which is exactly the null padded one
          shouldGetLeftTuple = true;
          return outTuple;
View Full Code Here

    }
    return outTuple;
  }

  protected void loadRightToHashTable() throws IOException {
    Tuple tuple;
    Tuple keyTuple;

    while ((tuple = rightChild.next()) != null) {
      keyTuple = new VTuple(joinKeyPairs.size());
      for (int i = 0; i < rightKeyList.length; i++) {
        keyTuple.put(i, tuple.get(rightKeyList[i]));
      }

      List<Tuple> newValue = tupleSlots.get(keyTuple);
      if (newValue != null) {
        newValue.add(tuple);
View Full Code Here

TOP

Related Classes of org.apache.tajo.storage.Tuple

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.