Package org.apache.tajo.storage

Examples of org.apache.tajo.storage.Tuple


    return this.curRow == this.totalRow;
  }

  @Override
  public boolean last() throws SQLException {
    Tuple last = null;
    while (this.next()) {
      last = cur;
    }
    cur = last;
    return true;
View Full Code Here


    if (maxRowNum != null && curRow >= maxRowNum) {
      return null;
    }

    Tuple tuple = scanner.next();
    if (tuple == null) {
      //query is closed automatically by querymaster but scanner is not
      scanner.close();
      scanner = null;
    }
View Full Code Here

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

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

      return null;
    }
  }

  private Tuple makeTuple() throws IOException {
    Tuple tuple = new VTuple(schema.size());
    synchronized (lock) {
      column.resetValid(schema.size());
      int tid; // target column id
      for (int i = 0; i < projectionMap.length; i++) {
        tid = projectionMap[i];

        byte[] bytes = column.get(tid).getBytesCopy();
        Datum datum = serde.deserialize(targets[i], bytes, 0, bytes.length, nullChars);
        tuple.put(tid, datum);
      }
    }
    return tuple;
  }
View Full Code Here

    private void fillRootIndex(int entryNum, FSDataInputStream in)
        throws IOException {
      this.dataIndex = new Tuple[entryNum];
      this.offsetIndex = new long[entryNum];
      Tuple keyTuple;
      byte[] buf;
      for (int i = 0; i < entryNum; i++) {
        buf = new byte[in.readInt()];
        Bytes.readFully(in, buf, 0, buf.length);
        keyTuple = rowStoreDecoder.toTuple(buf);
View Full Code Here

    return cardinality;
  }

  public static TupleRange [] getPartitions(Schema schema, int partNum, TupleRange range) {
    Tuple start = range.getStart();
    Tuple end = range.getEnd();
    Column col;
    TupleRange [] partitioned = new TupleRange[partNum];

    Datum[] term = new Datum[schema.getColumnNum()];
    Datum[] prevValues = new Datum[schema.getColumnNum()];

    // initialize term and previous values
    for (int i = 0; i < schema.getColumnNum(); i++) {
      col = schema.getColumn(i);
      prevValues[i] = start.get(i);
      switch (col.getDataType().getType()) {
        case CHAR:
          int sChar = start.get(i).asChar();
          int eChar = end.get(i).asChar();
          int rangeChar;
          if ((eChar - sChar) > partNum) {
            rangeChar = (eChar - sChar) / partNum;
          } else {
            rangeChar = 1;
          }
          term[i] = DatumFactory.createInt4(rangeChar);
        case BIT:
          byte sByte = start.get(i).asByte();
          byte eByte = end.get(i).asByte();
          int rangeByte;
          if ((eByte - sByte) > partNum) {
            rangeByte = (eByte - sByte) / partNum;
          } else {
            rangeByte = 1;
          }
          term[i] = DatumFactory.createBit((byte) rangeByte);
          break;

        case INT2:
          short sShort = start.get(i).asInt2();
          short eShort = end.get(i).asInt2();
          int rangeShort;
          if ((eShort - sShort) > partNum) {
            rangeShort = (eShort - sShort) / partNum;
          } else {
            rangeShort = 1;
          }
          term[i] = DatumFactory.createInt2((short) rangeShort);
          break;

        case INT4:
          int sInt = start.get(i).asInt4();
          int eInt = end.get(i).asInt4();
          int rangeInt;
          if ((eInt - sInt) > partNum) {
            rangeInt = (eInt - sInt) / partNum;
          } else {
            rangeInt = 1;
          }
          term[i] = DatumFactory.createInt4(rangeInt);
          break;

        case INT8:
          long sLong = start.get(i).asInt8();
          long eLong = end.get(i).asInt8();
          long rangeLong;
          if ((eLong - sLong) > partNum) {
            rangeLong = ((eLong - sLong) / partNum);
          } else {
            rangeLong = 1;
          }
          term[i] = DatumFactory.createInt8(rangeLong);
          break;

        case FLOAT4:
          float sFloat = start.get(i).asFloat4();
          float eFloat = end.get(i).asFloat4();
          float rangeFloat;
          if ((eFloat - sFloat) > partNum) {
            rangeFloat = ((eFloat - sFloat) / partNum);
          } else {
            rangeFloat = 1;
          }
          term[i] = DatumFactory.createFloat4(rangeFloat);
          break;
        case FLOAT8:
          double sDouble = start.get(i).asFloat8();
          double eDouble = end.get(i).asFloat8();
          double rangeDouble;
          if ((eDouble - sDouble) > partNum) {
            rangeDouble = ((eDouble - sDouble) / partNum);
          } else {
            rangeDouble = 1;
          }
          term[i] = DatumFactory.createFloat8(rangeDouble);
          break;
        case TEXT:
          char sChars = start.get(i).asChars().charAt(0);
          char eChars = end.get(i).asChars().charAt(0);
          int rangeString;
          if ((eChars - sChars) > partNum) {
            rangeString = ((eChars - sChars) / partNum);
          } else {
            rangeString = 1;
          }
          term[i] = DatumFactory.createText(((char) rangeString) + "");
          break;
        case INET4:
          throw new UnsupportedOperationException();
        case BLOB:
          throw new UnsupportedOperationException();
        default:
          throw new UnsupportedOperationException();
      }
    }

    for (int p = 0; p < partNum; p++) {
      Tuple sTuple = new VTuple(schema.getColumnNum());
      Tuple eTuple = new VTuple(schema.getColumnNum());
      for (int i = 0; i < schema.getColumnNum(); i++) {
        col = schema.getColumn(i);
        sTuple.put(i, prevValues[i]);
        switch (col.getDataType().getType()) {
          case CHAR:
            char endChar = (char) (prevValues[i].asChar() + term[i].asChar());
            if (endChar > end.get(i).asByte()) {
              eTuple.put(i, end.get(i));
            } else {
              eTuple.put(i, DatumFactory.createChar(endChar));
            }
            prevValues[i] = DatumFactory.createChar(endChar);
            break;
          case BIT:
            byte endByte = (byte) (prevValues[i].asByte() + term[i].asByte());
            if (endByte > end.get(i).asByte()) {
              eTuple.put(i, end.get(i));
            } else {
              eTuple.put(i, DatumFactory.createBit(endByte));
            }
            prevValues[i] = DatumFactory.createBit(endByte);
            break;
          case INT2:
            int endShort = (short) (prevValues[i].asInt2() + term[i].asInt2());
            if (endShort > end.get(i).asInt2()) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createInt2((short) endShort));
            }
            prevValues[i] = DatumFactory.createInt2((short) endShort);
            break;
          case INT4:
            int endInt = (prevValues[i].asInt4() + term[i].asInt4());
            if (endInt > end.get(i).asInt4()) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createInt4(endInt));
            }
            prevValues[i] = DatumFactory.createInt4(endInt);
            break;

          case INT8:
            long endLong = (prevValues[i].asInt8() + term[i].asInt8());
            if (endLong > end.get(i).asInt8()) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createInt8(endLong));
            }
            prevValues[i] = DatumFactory.createInt8(endLong);
            break;

          case FLOAT4:
            float endFloat = (prevValues[i].asFloat4() + term[i].asFloat4());
            if (endFloat > end.get(i).asFloat4()) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createFloat4(endFloat));
            }
            prevValues[i] = DatumFactory.createFloat4(endFloat);
            break;
          case FLOAT8:
            double endDouble = (prevValues[i].asFloat8() + term[i].asFloat8());
            if (endDouble > end.get(i).asFloat8()) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createFloat8(endDouble));
            }
            prevValues[i] = DatumFactory.createFloat8(endDouble);
            break;
          case TEXT:
            String endString = ((char)(prevValues[i].asChars().charAt(0) + term[i].asChars().charAt(0))) + "";
            if (endString.charAt(0) > end.get(i).asChars().charAt(0)) {
              eTuple.put(i, end.get(i));
            } else {
              // TODO - to consider overflow
              eTuple.put(i, DatumFactory.createText(endString));
            }
            prevValues[i] = DatumFactory.createText(endString);
            break;
          case INET4:
            throw new UnsupportedOperationException();
View Full Code Here

    for (Column col : target.getColumns()) {
      Preconditions.checkState(statSet.containsKey(col),
          "ERROR: Invalid Column Stats (column stats: " + colStats + ", there exists not target " + col);
    }

    Tuple startTuple = new VTuple(target.getColumnNum());
    Tuple endTuple = new VTuple(target.getColumnNum());
    int i = 0;
    for (Column col : target.getColumns()) {
      startTuple.put(i, statSet.get(col).getMinValue());
      endTuple.put(i, statSet.get(col).getMaxValue());
      i++;
    }
    return new TupleRange(target, startTuple, endTuple);
  }
View Full Code Here

   *
   * @see java.sql.ResultSet#last()
   */
  @Override
  public boolean last() throws SQLException {
    Tuple last = null;
    while (this.next()) {
      last = cur;
    }
    cur = last;
    return true;
View Full Code Here

    }
  }

  @Override
  public Tuple next() throws IOException {
    Tuple tuple = new VTuple(schema.getColumnNum());

    if (!columns[0].hasNext()) {
      return null;
    }

    int tid; // column id of the original input schema
    for (int i = 0; i < projectionMap.length; i++) {
      tid = projectionMap[i];
      columns[i].startRow();
      DataType dataType = schema.getColumn(tid).getDataType();
      switch (dataType.getType()) {
        case BOOLEAN:
          tuple.put(tid,
              DatumFactory.createBool(((Integer)columns[i].nextValue()).byteValue()));
          break;
        case BIT:
          tuple.put(tid,
              DatumFactory.createBit(((Integer) columns[i].nextValue()).byteValue()));
          break;
        case CHAR:
          String str = (String) columns[i].nextValue();
          tuple.put(tid,
              DatumFactory.createChar(str));
          break;

        case INT2:
          tuple.put(tid,
              DatumFactory.createInt2(((Integer) columns[i].nextValue()).shortValue()));
          break;
        case INT4:
          tuple.put(tid,
              DatumFactory.createInt4((Integer) columns[i].nextValue()));
          break;

        case INT8:
          tuple.put(tid,
              DatumFactory.createInt8((Long) columns[i].nextValue()));
          break;

        case FLOAT4:
          tuple.put(tid,
              DatumFactory.createFloat4((Float) columns[i].nextValue()));
          break;

        case FLOAT8:
          tuple.put(tid,
              DatumFactory.createFloat8((Double) columns[i].nextValue()));
          break;

        case INET4:
          tuple.put(tid,
              DatumFactory.createInet4(((ByteBuffer) columns[i].nextValue()).array()));
          break;

        case TEXT:
          tuple.put(tid,
              DatumFactory.createText((String) columns[i].nextValue()));
          break;

        case PROTOBUF: {
          ProtobufDatumFactory factory = ProtobufDatumFactory.get(dataType.getCode());
          Message.Builder builder = factory.newBuilder();
          builder.mergeFrom(((ByteBuffer)columns[i].nextValue()).array());
          tuple.put(tid, factory.createDatum(builder));
          break;
        }

        case BLOB:
          tuple.put(tid,
              new BlobDatum(((ByteBuffer) columns[i].nextValue())));
          break;

        case NULL:
          tuple.put(tid, NullDatum.get());
          break;

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

  public FileChunk get(Map<String, List<String>> kvs) throws IOException {
    // nothing to verify the file because AdvancedDataRetriever checks
    // its validity of the file.
    File data = new File(this.file, "data/data");
    byte [] startBytes = Base64.decodeBase64(kvs.get("start").get(0));
    Tuple start = RowStoreUtil.RowStoreDecoder.toTuple(schema, startBytes);
    byte [] endBytes;
    Tuple end;
    endBytes = Base64.decodeBase64(kvs.get("end").get(0));
    end = RowStoreUtil.RowStoreDecoder.toTuple(schema, endBytes);
    boolean last = kvs.containsKey("final");

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

    LOG.info("GET Request for " + data.getAbsolutePath() + " (start="+start+", end="+ end +
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.