Package org.apache.tajo.storage

Examples of org.apache.tajo.storage.Tuple


    this.fetchCount = 0;
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple = child.next();
    fetchCount++;

    if (fetchCount > fetchFirstNum || tuple == null) {
      return null;
    }
View Full Code Here


    this.outputTuple = new VTuple(outSchema.getColumnNum());
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple;
    while ((tuple = child.next()) != null) {
      qual.eval(qualCtx, inSchema, tuple);
      if (qual.terminate(qualCtx).asBool()) {
        if (targetIds != null) {
          RowStoreUtil.project(tuple, outputTuple, targetIds);
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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(qualCtx, inSchema, frameTuple);
          projector.eval(evalContexts, frameTuple);
          projector.terminate(evalContexts, 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

    tupleSlots = new HashMap<Tuple, EvalContext[]>(10000);
    this.tuple = new VTuple(evalSchema.getColumnNum());
  }
 
  private void compute() throws IOException {
    Tuple tuple;
    Tuple keyTuple;
    int targetLength = plan.getTargets().length;
    while((tuple = child.next()) != null && !context.isStopped()) {
      keyTuple = new VTuple(keylist.length);
      // build one key tuple
      for(int i = 0; i < keylist.length; i++) {
        keyTuple.put(i, tuple.get(keylist[i]));
      }
     
      if(tupleSlots.containsKey(keyTuple)) {
        EvalContext [] tmpTuple = tupleSlots.get(keyTuple);
        for(int i = 0; i < measureList.length; i++) {
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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(evalContexts, frameTuple);
            projector.terminate(evalContexts, 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(qualCtx, inSchema, frameTuple);
          projector.eval(evalContexts, frameTuple);
          projector.terminate(evalContexts, 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

    File data = new File(URI.create(outDir.toUri() + "/output"));
    byte [] startBytes = Base64.decodeBase64(startKey);
    byte [] endBytes = Base64.decodeBase64(endKey);

    Tuple start;
    Tuple end;
    try {
      start = RowStoreUtil.RowStoreDecoder.toTuple(keySchema, startBytes);
    } catch (Throwable t) {
      throw new IllegalArgumentException("StartKey: " + startKey
          + ", decoded byte size: " + startBytes.length, t);
    }

    try {
      end = RowStoreUtil.RowStoreDecoder.toTuple(keySchema, endBytes);
    } catch (Throwable t) {
      throw new IllegalArgumentException("EndKey: " + endKey
          + ", decoded byte size: " + endBytes.length, t);
    }


    if(!comparator.isAscendingFirstKey()) {
      Tuple tmpKey = start;
      start = end;
      end = tmpKey;
    }

    LOG.info("GET Request for " + data.getAbsolutePath() + " (start="+start+", end="+ end +
View Full Code Here

      column.clear();
      in.getCurrentRow(column);
    }

    if(more) {
      Tuple tuple = makeTuple();
      return tuple;
    } else {
      close();
      return null;
    }
View Full Code Here

    }
  }

  private Tuple makeTuple() throws IOException {
    column.resetValid(schema.getColumnNum());
    Tuple tuple = new VTuple(schema.getColumnNum());
    int tid; // target column id
    for (int i = 0; i < projectionMap.length; i++) {
      tid = projectionMap[i];
      // if the column is byte[0], it presents a NULL value.
      if (column.get(tid).getLength() == 0) {
        tuple.put(tid, DatumFactory.createNullDatum());
      } else {
        switch (targets[i].getDataType().getType()) {
          case BOOLEAN:
            tuple.put(tid,
                DatumFactory.createBool(column.get(tid).getBytesCopy()[0]));
            break;
          case BIT:
            tuple.put(tid,
                DatumFactory.createBit(column.get(tid).getBytesCopy()[0]));
            break;
          case CHAR:
            byte[] buf = column.get(tid).getBytesCopy();
            tuple.put(tid,
                DatumFactory.createChar(buf));
            break;

          case INT2:
            tuple.put(tid,
                DatumFactory.createInt2(Bytes.toShort(
                    column.get(tid).getBytesCopy())));
            break;
          case INT4:
            tuple.put(tid,
                DatumFactory.createInt4(Bytes.toInt(
                    column.get(tid).getBytesCopy())));
            break;

          case INT8:
            tuple.put(tid,
                DatumFactory.createInt8(Bytes.toLong(
                    column.get(tid).getBytesCopy())));
            break;

          case FLOAT4:
            tuple.put(tid,
                DatumFactory.createFloat4(Bytes.toFloat(
                    column.get(tid).getBytesCopy())));
            break;

          case FLOAT8:
            tuple.put(tid,
                DatumFactory.createFloat8(Bytes.toDouble(
                    column.get(tid).getBytesCopy())));
            break;

          case INET4:
            tuple.put(tid,
                DatumFactory.createInet4(column.get(tid).getBytesCopy()));
            break;

          case TEXT:
            tuple.put(tid,
                DatumFactory.createText(
                    column.get(tid).getBytesCopy()));
            break;

          case BLOB:
            tuple.put(tid,
                DatumFactory.createBlob(column.get(tid).getBytesCopy()));
            break;

          default:
            throw new IOException("Unsupport data type");
View Full Code Here

    File data = new File(URI.create(outDir.toUri() + "/output"));
    byte [] startBytes = Base64.decodeBase64(startKey);
    byte [] endBytes = Base64.decodeBase64(endKey);

    Tuple start;
    Tuple end;
    try {
      start = RowStoreUtil.RowStoreDecoder.toTuple(keySchema, startBytes);
    } catch (Throwable t) {
      throw new IllegalArgumentException("StartKey: " + startKey
          + ", decoded byte size: " + startBytes.length, t);
    }

    try {
      end = RowStoreUtil.RowStoreDecoder.toTuple(keySchema, endBytes);
    } catch (Throwable t) {
      throw new IllegalArgumentException("EndKey: " + endKey
          + ", decoded byte size: " + endBytes.length, t);
    }


    if(!comparator.isAscendingFirstKey()) {
      Tuple tmpKey = start;
      start = end;
      end = tmpKey;
    }

    LOG.info("GET Request for " + data.getAbsolutePath() + " (start="+start+", end="+ end +
View Full Code Here

  /**
   * It computes the value cardinality of a tuple range.
   * @return
   */
  public static BigDecimal computeCardinalityForAllColumns(Schema schema, TupleRange range, boolean inclusive) {
    Tuple start = range.getStart();
    Tuple end = range.getEnd();
    Column col;

    BigDecimal cardinality = new BigDecimal(1);
    BigDecimal columnCard;
    for (int i = 0; i < schema.getColumnNum(); i++) {
      col = schema.getColumn(i);
      columnCard = computeCardinality(col.getDataType(), start.get(i), end.get(i), inclusive);

      if (new BigDecimal(0).compareTo(columnCard) < 0) {
        cardinality = cardinality.multiply(columnCard);
      }
    }
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.