Package eu.stratosphere.test.recordJobs.util

Examples of eu.stratosphere.test.recordJobs.util.Tuple


   *
   */
  @Override
  public void map(Record record, Collector<Record> out) throws Exception
  {
    Tuple inputTuple = record.getField(1, Tuple.class);
   
    /* Extract the year from the date element of the order relation: */
   
    /* pice = extendedprice * (1 - discount): */
    float price = Float.parseFloat(inputTuple.getStringValueAt(5)) * (1 - Float.parseFloat(inputTuple.getStringValueAt(6)));
    /* Project (orderkey | partkey, suppkey, linenumber, quantity, extendedprice, discount, tax, ...) to (partkey, suppkey, quantity): */
    inputTuple.project((0 << 0) | (1 << 1) | (1 << 2) | (0 << 3) | (1 << 4));
    inputTuple.addAttribute("" + price);
    record.setField(1, inputTuple);
    out.collect(record);
  }
View Full Code Here


   *  Value: year (from date)
   *
   */
  @Override
  public void map(Record record, Collector<Record> out) throws Exception {
    Tuple inputTuple = record.getField(1, this.inputTuple);
   
    int year = Integer.parseInt(inputTuple.getStringValueAt(4).substring(0, 4));
    record.setField(1, new IntValue(year));
    out.collect(record);
  }
View Full Code Here

  @Override
  public void join(Record value1, Record value2, Collector<Record> out)
      throws Exception {
    IntPair partAndSupplierKey = value1.getField(0, this.partAndSupplierKey);
    StringValue supplyCostStr = value1.getField(1, this.supplyCostStr);
    Tuple ordersValue = value2.getField(1, this.ordersValue);
   
    IntValue year = new IntValue(Integer.parseInt(ordersValue.getStringValueAt(0)));
    float quantity = Float.parseFloat(ordersValue.getStringValueAt(1));
    float price = Float.parseFloat(ordersValue.getStringValueAt(2));
    float supplyCost = Float.parseFloat(supplyCostStr.toString());
    float amount = price - supplyCost * quantity;
   
    /* Push (supplierKey, (amount, year)): */
    value1.setField(0, partAndSupplierKey.getSecond());
View Full Code Here

  @Override
  public void join(Record value1, Record value2, Collector<Record> out)
      throws Exception {

    IntValue year = value1.getField(1, IntValue.class);
    Tuple lineItem = value2.getField(1, Tuple.class);
   
    /* (partkey, suppkey) from lineItem: */
    IntPair newKey = new IntPair(new IntValue(Integer.parseInt(lineItem.getStringValueAt(0))), new IntValue(Integer.parseInt(lineItem.getStringValueAt(1))));
    Tuple newValue = new Tuple();
    newValue.addAttribute(year.toString()); // year
    newValue.addAttribute(lineItem.getStringValueAt(2)); // quantity
    newValue.addAttribute(lineItem.getStringValueAt(3)); // price
   
    value1.setField(0, newKey);
    value1.setField(1, newValue);
    out.collect(value1);
   
View Full Code Here

  @Override
  public void join(Record value1, Record value2, Collector<Record> out)
      throws Exception {

    IntValue partKey = value1.getField(0, this.partKey);
    Tuple partSuppValue = value2.getField(1, this.partSuppValue);
   
    IntPair newKey = new IntPair(partKey, new IntValue(Integer.parseInt(partSuppValue.getStringValueAt(0))));
    String supplyCost = partSuppValue.getStringValueAt(1);
   
    value1.setField(0, newKey);
    value1.setField(1, new StringValue(supplyCost));
    out.collect(value1);
   
View Full Code Here

   *
   */
  @Override
  public void map(Record record, Collector<Record> out) throws Exception
  {
    Tuple inputTuple = record.getField(1, this.inputTuple);
    if (inputTuple.getStringValueAt(1).indexOf(COLOR) != -1) {
      record.setField(1, NullValue.getInstance());
      out.collect(record);
    }
  }
View Full Code Here

  @Test
  public void testTupleByteArrayShortArrayInt() {
   
    String tupleStr = "attr1|attr2|3|4|attr5|";
    int[] offsets = {0,6,12,14,16,22};
    Tuple t1 = new Tuple(tupleStr.getBytes(),offsets,5);
   
    Assert.assertTrue(t1.getBytes().length == tupleStr.getBytes().length);
    for(int i=0;i<t1.getBytes().length;i++) {
      Assert.assertTrue(t1.getBytes()[i] == tupleStr.getBytes()[i]);
    }
    Assert.assertTrue(t1.getNumberOfColumns() == 5);
    Assert.assertTrue(t1.getStringValueAt(0).equals("attr1"));
    Assert.assertTrue(t1.getStringValueAt(1).equals("attr2"));
    Assert.assertTrue(t1.getLongValueAt(2) == 3);
    Assert.assertTrue(t1.getLongValueAt(3) == 4);
    Assert.assertTrue(t1.getStringValueAt(4).equals("attr5"));
   
  }
View Full Code Here

  }

  @Test
  public void testGetNumberOfColumns() {
   
    Tuple t = new Tuple();
   
    Assert.assertTrue(t.getNumberOfColumns() == 0);
   
    t.addAttribute("a");
    Assert.assertTrue(t.getNumberOfColumns() == 1);
   
    t.addAttribute("b");
    Assert.assertTrue(t.getNumberOfColumns() == 2);
   
    t.addAttribute("aasdfasd|fasdf");
    Assert.assertTrue(t.getNumberOfColumns() == 3);
   
    String tupleStr = "attr1|attr2|3|4|attr5|";
    int[] offsets = {0,6,12,14,16,22};
    t = new Tuple(tupleStr.getBytes(),offsets,5);
   
    Assert.assertTrue(t.getNumberOfColumns() == 5);
  }
View Full Code Here

  }

  @Test
  public void testGetBytes() {
   
    Tuple t1 = new Tuple();
   
    String[] values = {"a","b","cdefgh","2342432","Adasdfee324324D"};
   
    for(String val : values) {
      t1.addAttribute(val);
    }
   
    String exp1 = "";
    for(int i=0;i<values.length;i++) {
      exp1 += values[i]+"|";
    }
   
    byte[] ret1 = t1.getBytes();
   
    for(int i=0;i<exp1.getBytes().length;i++) {
      Assert.assertTrue(ret1[i] == exp1.getBytes()[i]);
    }
    Assert.assertTrue(ret1[exp1.getBytes().length+1] == 0);
   
    String tupleStr = "attr1|attr2|3|4|attr5|";
    int[] offsets = {0,6,12,14,16,22};
    Tuple t2 = new Tuple(tupleStr.getBytes(),offsets,5);
   
    byte[] ret2 = t2.getBytes();
   
    Assert.assertTrue(ret2.length == tupleStr.getBytes().length);
    for(int i=0;i<tupleStr.getBytes().length;i++) {
      Assert.assertTrue(ret2[i] == tupleStr.getBytes()[i]);
    }
View Full Code Here

    }
  }

  @Test
  public void testGetColumnLength() {
    Tuple t = new Tuple();
   
    Assert.assertTrue(t.getColumnLength(1) == -1);
    Assert.assertTrue(t.getColumnLength(0) == -1);
    Assert.assertTrue(t.getColumnLength(-1) == -1);
   
    t.addAttribute("a");
    Assert.assertTrue(t.getColumnLength(0) == 1);
   
    t.addAttribute("b");
    Assert.assertTrue(t.getColumnLength(1) == 1);
   
    t.addAttribute("aasdfasd|fasdf");
    Assert.assertTrue(t.getColumnLength(2) == 14);
   
    String tupleStr = "attr1|attr2|3|4|attr5|";
    int[] offsets = {0,6,12,14,16,22};
    t = new Tuple(tupleStr.getBytes(),offsets,5);
   
    Assert.assertTrue(t.getColumnLength(0) == 5);
    Assert.assertTrue(t.getColumnLength(1) == 5);
    Assert.assertTrue(t.getColumnLength(2) == 1);
    Assert.assertTrue(t.getColumnLength(3) == 1);
    Assert.assertTrue(t.getColumnLength(4) == 5);
   
  }
View Full Code Here

TOP

Related Classes of eu.stratosphere.test.recordJobs.util.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.