Package com.manning.hip.ch3.avro.gen

Examples of com.manning.hip.ch3.avro.gen.StockAvg


  @Override
  protected void map(LongWritable key, Text value,
                     Context context)
      throws IOException, InterruptedException {

    StockPriceWritable stock =
        StockPriceWritable.fromLine(value.toString());

    byte[] rowkey = Bytes.add(
        Bytes.toBytes(stock.getSymbol()),
        Bytes.toBytes(stock.getDate()));

    Put put = new Put(rowkey);

    byte[] colValue = Bytes.toBytes(stock.getClose());
    put.add(STOCK_DETAILS_COLUMN_FAMILY_AS_BYTES,
        STOCK_COLUMN_QUALIFIER_AS_BYTES,
        colValue
    );
    context.write(stock, put);
View Full Code Here


      return null;
    }
    if (!(value instanceof StockPriceWritable)) {
      return null;
    }
    StockPriceWritable w = (StockPriceWritable) value;

    return TupleFactory.getInstance().newTuple(Arrays.asList(
        w.getSymbol(), w.getDate(), w.getOpen(),
        w.getHigh(), w.getLow(), w.getClose(),
        w.getVolume(), w.getAdjClose()
    ));
  }
View Full Code Here

            new DefaultCodec());
    try {
      Text key = new Text();

      for (String line : FileUtils.readLines(inputFile)) {   //<co id="ch03_comment_seqfile_write2"/>
        StockPriceWritable stock = StockPriceWritable.fromLine(line);
        key.set(stock.getSymbol());

        key.set(stock.getSymbol());
        writer.append(key,
            stock);        //<co id="ch03_comment_seqfile_write4"/>
      }
    } finally {
      writer.close();
View Full Code Here

    }
  }

  public Object deserialize(Writable field) throws SerDeException {
    if (field instanceof StockPriceWritable) {
      StockPriceWritable stock = (StockPriceWritable) field;
      row.set(0, stock.getSymbol());
      row.set(1, stock.getDate());
      row.set(2, stock.getOpen());
      row.set(3, stock.getHigh());
      row.set(4, stock.getLow());
      row.set(5, stock.getClose());
      row.set(6, stock.getVolume());
      row.set(7, stock.getAdjClose());
      return row;
    }
      throw new SerDeException(this.getClass().getName()
          + " unexpected Writable type " + field.getClass().getName());
  }
View Full Code Here

    try {
      System.out.println(
          "Is block compressed = " + reader.isBlockCompressed());

      Text key = new Text();
      StockPriceWritable value = new StockPriceWritable();

      while (reader.next(key, value)) {   //<co id="ch03_comment_seqfile_read2"/>
        System.out.println(key + "," + value);
      }
    } finally {
View Full Code Here

    }

    private void loadCSV() throws IOException {            //<co id="ch02_comment_csv_inputformat9"/>
      String line = reader.getCurrentValue().toString();
      String[] tokens = parser.parseLine(line);            //<co id="ch02_comment_csv_inputformat10"/>
      value = new TextArrayWritable(convert(tokens));
    }
View Full Code Here

    ByteArrayOutputStream bao = new ByteArrayOutputStream();
    BinaryEncoder encoder =
        EncoderFactory.get().directBinaryEncoder(bao, null);

    for (String line : FileUtils.readLines(inputFile)) {
      Stock stock = AvroStockFileWrite.createStock(line);
      writer.write(stock, encoder);
      encoder.flush();

      byte[] rowkey = Bytes.add(
          Bytes.toBytes(stock.symbol.toString()),
View Full Code Here

    public void configure(JobConf job) {
    }
  }

  public static Stock avroToWritable(StockPriceWritable writable) {
    Stock avro = new Stock();
    avro.symbol = writable.getSymbol();
    avro.date = writable.getDate();
    avro.open = writable.getOpen();
    avro.high = writable.getHigh();
    avro.low = writable.getLow();
View Full Code Here

      ImmutableBytesWritable key = new ImmutableBytesWritable();
      Result value = new Result();

      while (reader.next(key, value)) {
        Stock stock = stockReader.decode(value.getValue(
            STOCK_DETAILS_COLUMN_FAMILY_AS_BYTES,
            STOCK_COLUMN_QUALIFIER_AS_BYTES));
        System.out.println(new String(key.get()) + ": " +
        ToStringBuilder
              .reflectionToString(stock, ToStringStyle.SIMPLE_STYLE));
View Full Code Here

                  Context context)
      throws IOException, InterruptedException {
      for (KeyValue kv : columns.list()) {
        byte[] value = kv.getValue();

        Stock stock = stockReader.decode(value);

        outputKey.set(stock.symbol.toString());
        outputValue.set(stock.close);
        context.write(outputKey, outputValue);
      }
View Full Code Here

TOP

Related Classes of com.manning.hip.ch3.avro.gen.StockAvg

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.