Package eu.stratosphere.test.recordJobs.util

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


         count++;
      }
     
      if(rec != null)
      {
        Tuple tuple = new Tuple();
        tuple.addAttribute("" + count);
        rec.setField(1, tuple);
      }
     
      out.collect(rec);
    }
View Full Code Here


   
  }

  @Test
  public void testAddAttributeByteArray() {
    Tuple t = new Tuple();
   
    Assert.assertTrue(t.getNumberOfColumns() == 0);
   
    t.addAttribute("a".getBytes());
    Assert.assertTrue(t.getNumberOfColumns() == 1);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getBytes().length == 256);
   
    t.compact();
    t.addAttribute("123345".getBytes());
    Assert.assertTrue(t.getNumberOfColumns() == 2);
    Assert.assertTrue(t.getLongValueAt(1) == 123345);
    Assert.assertTrue(t.getBytes().length == 9);
   
    t.addAttribute("adfasdfg".getBytes());
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    byte[] ret = t.getByteArrayValueAt(2);
    Assert.assertTrue(ret.length == "adfasdfg".getBytes().length);
    for(int i=0;i<ret.length;i++) {
      Assert.assertTrue(ret[i] == "adfasdfg".getBytes()[i]);
    }
    Assert.assertTrue(t.getBytes().length == 18);
   
  }
View Full Code Here

  }

  @Test
  public void testAddAttributeFromKVRecord() {
   
    Tuple t1 = new Tuple();
    t1.addAttribute("a");
    t1.addAttribute("123345");
    t1.addAttribute("adfasdfg");
   
    Tuple t2 = new Tuple();
   
    Assert.assertTrue(t2.getNumberOfColumns() == 0);
   
    t2.addAttributeFromKVRecord(t1, 1);
    Assert.assertTrue(t2.getNumberOfColumns() == 1);
    Assert.assertTrue(t2.getLongValueAt(0) == 123345);
    Assert.assertTrue(t2.getBytes().length == 256);
   
    t2.compact();

    t2.addAttributeFromKVRecord(t1, 2);
    Assert.assertTrue(t2.getNumberOfColumns() == 2);
    byte[] ret = t2.getByteArrayValueAt(1);
    Assert.assertTrue(ret.length == "adfasdfg".getBytes().length);
    for(int i=0;i<ret.length;i++) {
      Assert.assertTrue(ret[i] == "adfasdfg".getBytes()[i]);
    }
    Assert.assertTrue(t2.getBytes().length == 16);
   
    t2.addAttributeFromKVRecord(t1, 0);
    Assert.assertTrue(t2.getNumberOfColumns() == 3);
    Assert.assertTrue(t2.getStringValueAt(2).equals("a"));
    Assert.assertTrue(t2.getBytes().length == 18);
   
  }
View Full Code Here

  }

  @Test
  public void testAddAttributeString() {
   
    Tuple t = new Tuple();
   
    Assert.assertTrue(t.getNumberOfColumns() == 0);
   
    t.addAttribute("a");
    Assert.assertTrue(t.getNumberOfColumns() == 1);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getBytes().length == 256);
   
    t.compact();
    t.addAttribute(123345+"");
    Assert.assertTrue(t.getNumberOfColumns() == 2);
    Assert.assertTrue(t.getLongValueAt(1) == 123345);
    Assert.assertTrue(t.getBytes().length == 9);
   
    t.addAttribute("adfasdfg");
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    byte[] ret = t.getByteArrayValueAt(2);
    Assert.assertTrue(ret.length == "adfasdfg".getBytes().length);
    for(int i=0;i<ret.length;i++) {
      Assert.assertTrue(ret[i] == "adfasdfg".getBytes()[i]);
    }
    Assert.assertTrue(t.getBytes().length == 18);
   
  }
View Full Code Here

  @Test
  public void testSerialization() {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(baos);
   
    Tuple t = new Tuple();
    t.addAttribute("Hello world!");
    try {
      t.write(dos);
    } catch (IOException e1) {
      e1.printStackTrace();
    }
   
    t.addAttribute("2ndAttribute");
    try {
      t.write(dos);
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    byte[] ba = "attr1|attr2|3|4|attr5|thisdoesnotbelongtothetuple".getBytes();
    int[] of2 = {0,6,12,14,16,22};
    t = new Tuple(ba, of2, 5);
   
    try {
      t.write(dos);
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    try {
      dos.flush();
      baos.flush();
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    byte[] data = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dis = new DataInputStream(bais);
   
    try {
      dos.close();
      baos.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    t = new Tuple();
    try {
      t.read(dis);
     
      Assert.assertTrue(t.getNumberOfColumns() == 1);
      Assert.assertTrue(t.getStringValueAt(0).equals("Hello world!"));
      Assert.assertTrue(t.toString().equals("Hello world!|"));
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    t = new Tuple();
    try {
      t.read(dis);
     
      Assert.assertTrue(t.getNumberOfColumns() == 2);
      Assert.assertTrue(t.getStringValueAt(0).equals("Hello world!"));
      Assert.assertTrue(t.getStringValueAt(1).equals("2ndAttribute"));
      Assert.assertTrue(t.toString().equals("Hello world!|2ndAttribute|"));
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    t = new Tuple();
    try {
      t.read(dis);
     
      Assert.assertTrue(t.getNumberOfColumns() == 5);
      Assert.assertTrue(t.getStringValueAt(0).equals("attr1"));
      Assert.assertTrue(t.getStringValueAt(1).equals("attr2"));
      Assert.assertTrue(t.getLongValueAt(2) == 3);
      Assert.assertTrue(t.getLongValueAt(3) == 4);
      Assert.assertTrue(t.getStringValueAt(4).equals("attr5"));
      Assert.assertTrue(t.toString().equals("attr1|attr2|3|4|attr5|"));
    } catch (IOException e) {
      e.printStackTrace();
    }
   
    try {
View Full Code Here

   
  }
 
  @Test
  public void testToString() {
    Tuple t = new Tuple();

    t.addAttribute("Hello world!");
    Assert.assertTrue(t.toString().equals("Hello world!|"));
    t.addAttribute("2ndValue");
    Assert.assertTrue(t.toString().equals("Hello world!|2ndValue|"));
   
    byte[] ba = "attr1|attr2|3|4|attr5|thisdoesnotbelongtothetuple".getBytes();
    int[] of2 = {0,6,12,14,16,22};
    t = new Tuple(ba, of2, 5);
   
    Assert.assertTrue(t.toString().equals("attr1|attr2|3|4|attr5|"));
   
  }
View Full Code Here

    private final IntValue custKey = new IntValue();
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception {
     
      Tuple t = record.getField(1, Tuple.class);
      if (Integer.parseInt(t.getStringValueAt(4).substring(0, 4)) > FilterO.YEAR_FILTER) {
        // project
        this.custKey.setValue((int) t.getLongValueAt(1));
        record.setField(1, this.custKey);
        out.collect(record);
      }
     
    }
View Full Code Here

    private final Tuple tuple = new Tuple();
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception
    {
      Tuple t = record.getField(1, this.tuple);
      if (t.getStringValueAt(8).equals("R")) {
        t.project(0x60); // l_extendedprice, l_discount
        record.setField(1, t);
        out.collect(record);
      }
    }
View Full Code Here

    private final StringValue comment = new StringValue();
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception
    {
      final Tuple t = record.getField(1, this.tuple);
     
      this.custName.setValue(t.getStringValueAt(1));
      this.address.setValue(t.getStringValueAt(2));
      this.nationKey.setValue((int) t.getLongValueAt(3));
      this.phone.setValue(t.getStringValueAt(4));
      this.balance.setValue(t.getStringValueAt(5));
      this.comment.setValue(t.getStringValueAt(7));
     
      record.setField(1, this.custName);
      record.setField(3, this.balance);
      record.setField(4, this.nationKey);
      record.setField(5, this.address);
View Full Code Here

    private final StringValue nationName = new StringValue();
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception
    {
      final Tuple t = record.getField(1, this.tuple);
     
      this.nationName.setValue(t.getStringValueAt(1));
      record.setField(1, this.nationName);
      out.collect(record);
    }
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.