Package eu.stratosphere.test.recordJobs.util

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


   
  }

  @Test
  public void testConcatenate() {
    Tuple t0 = new Tuple();
    Tuple t1 = new Tuple();
    Tuple t2 = new Tuple();
   
    // check handling of empty tuples
    t0.concatenate(t1);
    Assert.assertTrue(t0.getNumberOfColumns() == 0);
   
    t1.addAttribute("a");
    t1.concatenate(t0);
    Assert.assertTrue(t1.getNumberOfColumns() == 1);
    Assert.assertTrue(t1.getStringValueAt(0).equals("a"));
   
    t0.concatenate(t1);
    Assert.assertTrue(t0.getNumberOfColumns() == 1);
    Assert.assertTrue(t0.getStringValueAt(0).equals("a"));
   
    t1.addAttribute("b");
    t1.addAttribute("c");
    t2.addAttribute("z");
    t2.addAttribute("y");
    t2.addAttribute("x");
    t2.concatenate(t1);
    // check tuple t2
    Assert.assertTrue(t2.getNumberOfColumns() == 6);
    Assert.assertTrue(t2.getStringValueAt(0).equals("z"));
    Assert.assertTrue(t2.getStringValueAt(1).equals("y"));
    Assert.assertTrue(t2.getStringValueAt(2).equals("x"));
    Assert.assertTrue(t2.getStringValueAt(3).equals("a"));
    Assert.assertTrue(t2.getStringValueAt(4).equals("b"));
    Assert.assertTrue(t2.getStringValueAt(5).equals("c"));
   
    t1.concatenate(t2);
    // check tuple t1
    Assert.assertTrue(t1.getNumberOfColumns() == 9);
    Assert.assertTrue(t1.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t1.getStringValueAt(1).equals("b"));
    Assert.assertTrue(t1.getStringValueAt(2).equals("c"));
    Assert.assertTrue(t1.getStringValueAt(3).equals("z"));
    Assert.assertTrue(t1.getStringValueAt(4).equals("y"));
    Assert.assertTrue(t1.getStringValueAt(5).equals("x"));
    Assert.assertTrue(t1.getStringValueAt(6).equals("a"));
    Assert.assertTrue(t1.getStringValueAt(7).equals("b"));
    Assert.assertTrue(t1.getStringValueAt(8).equals("c"));
    // check tuple t2
    Assert.assertTrue(t2.getNumberOfColumns() == 6);
    Assert.assertTrue(t2.getStringValueAt(0).equals("z"));
    Assert.assertTrue(t2.getStringValueAt(1).equals("y"));
    Assert.assertTrue(t2.getStringValueAt(2).equals("x"));
    Assert.assertTrue(t2.getStringValueAt(3).equals("a"));
    Assert.assertTrue(t2.getStringValueAt(4).equals("b"));
    Assert.assertTrue(t2.getStringValueAt(5).equals("c"));
   
  }
View Full Code Here


  }

  @Test
  public void testProject() {
   
    Tuple t = new Tuple();
   
    t.project(1);
    Assert.assertTrue(t.getNumberOfColumns() == 0);
   
    t.addAttribute("a");
    t.project(0);
    Assert.assertTrue(t.getNumberOfColumns() == 0);

    t.addAttribute("a");
    t.addAttribute("b");
    t.project(2);
    Assert.assertTrue(t.getNumberOfColumns() == 1);
    Assert.assertTrue(t.getStringValueAt(0).equals("b"));
   
    t.addAttribute("c");
    t.addAttribute("d");
    t.project(5);
    Assert.assertTrue(t.getNumberOfColumns() == 2);
    Assert.assertTrue(t.getStringValueAt(0).equals("b"));
    Assert.assertTrue(t.getStringValueAt(1).equals("d"));
   
    t.project(0);
    Assert.assertTrue(t.getNumberOfColumns() == 0);
   
    t.addAttribute("a");
    t.addAttribute("b");
    t.addAttribute("c");
    t.addAttribute("d");
    t.project(11);
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    Assert.assertTrue(t.getStringValueAt(2).equals("d"));
   
    t.project(23);
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getStringValueAt(1).equals("b"));
    Assert.assertTrue(t.getStringValueAt(2).equals("d"));
   
    t.project(-1);
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getStringValueAt(1).equals("b"));
    Assert.assertTrue(t.getStringValueAt(2).equals("d"));
  }
View Full Code Here

    Assert.assertTrue(t.getStringValueAt(2).equals("d"));
  }

  @Test
  public void testCompareStringAttribute() {
    Tuple t1 = new Tuple();
    Tuple t2 = new Tuple();
   
    t1.addAttribute("a");
    t1.addAttribute("b");
    t1.addAttribute("ccccc");
   
    t2.addAttribute("a");
    t2.addAttribute("bb");
    t2.addAttribute("ccccc");
    t2.addAttribute("z");
   
    Assert.assertTrue(t1.compareStringAttribute(t2, 0, 0) == 0);
    Assert.assertTrue(t1.compareStringAttribute(t2, 0, 1) < 0);
    Assert.assertTrue(t1.compareStringAttribute(t2, 1, 1) < 0);
    Assert.assertTrue(t1.compareStringAttribute(t2, 2, 2) == 0);
    Assert.assertTrue(t1.compareStringAttribute(t2, 2, 3) < 0);
   
    Assert.assertTrue(t2.compareStringAttribute(t1, 0, 0) == 0);
    Assert.assertTrue(t2.compareStringAttribute(t1, 1, 0) > 0);
    Assert.assertTrue(t2.compareStringAttribute(t1, 1, 1) > 0);
    Assert.assertTrue(t2.compareStringAttribute(t1, 2, 2) == 0);
    Assert.assertTrue(t2.compareStringAttribute(t1, 3, 2) > 0);
   
    Assert.assertTrue(t1.compareStringAttribute(t1, 0, 0) == 0);
    Assert.assertTrue(t1.compareStringAttribute(t1, 1, 1) == 0);
    Assert.assertTrue(t1.compareStringAttribute(t1, 2, 2) == 0);
    Assert.assertTrue(t1.compareStringAttribute(t1, 0, 1) < 0);
View Full Code Here

    Assert.assertTrue(exceptionThrown);
  }

  @Test
  public void testCompareIntAttribute() {
    Tuple t1 = new Tuple();
   
    t1.addAttribute("1");
    t1.addAttribute("2");
    t1.addAttribute("112315412");
    t1.addAttribute(Integer.MAX_VALUE+"");
    t1.addAttribute("-1");
    t1.addAttribute(Integer.MIN_VALUE+"");
   
    // check identical values
    Assert.assertTrue(t1.compareIntAttribute(t1, 0, 0) == 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 1, 1) == 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 2, 2) == 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 3, 3) == 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 4, 4) == 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 5, 5) == 0);
   
    // check unequal values
    Assert.assertTrue(t1.compareIntAttribute(t1, 0, 1) < 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 1, 0) > 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 1, 2) < 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 2, 1) > 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 2, 3) < 0);
   
    // check negative values
    Assert.assertTrue(t1.compareIntAttribute(t1, 0, 4) > 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 4, 0) < 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 4, 5) > 0);
    Assert.assertTrue(t1.compareIntAttribute(t1, 5, 4) < 0);
   
    // check for non-existing attributes
    boolean exceptionThrown = false;
    try {
      t1.compareIntAttribute(t1, 0, 6);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t1.compareIntAttribute(t1, 7, 0);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
  }
View Full Code Here

    }
  }

  @Override
  public void map(Record record, Collector<Record> out) throws Exception {
    Tuple value = record.getField(1, Tuple.class);
   
    if (value != null && value.getNumberOfColumns() >= 11) {
      String shipDateString = value.getStringValueAt(10);
     
      try {
        Date shipDate = format.parse(shipDateString);

        if (shipDate.before(constantDate)) { 
          String returnFlag = value.getStringValueAt(8);
         
          record.setField(0, new StringValue(returnFlag));
          out.collect(record);
        }
      }
View Full Code Here

  }

  @Test
  public void testGetStringValueAt() {
   
    Tuple t = new Tuple();
   
    String[] testStrings = {"a","b","123123","Hello world!","Test with p|pe","!§$%&/()=*'.:,;-_#+'`}][{"};
   
    for(String testString : testStrings) {
      t.addAttribute(testString);
    }
   
    // check for same value
    for(int i=0;i<testStrings.length;i++) {
      Assert.assertTrue(t.getStringValueAt(i).equals(testStrings[i]));
    }
   
    // check for out-of-bounds values
    boolean exceptionThrown = false;
    try {
      t.getStringValueAt(-1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getStringValueAt(testStrings.length);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getStringValueAt(testStrings.length+1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
View Full Code Here

  private static final long serialVersionUID = 1L;

  @Override
  public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception {
    Record outRecord = new Record();
    Tuple returnTuple = new Tuple();
   
    long quantity = 0;
    double extendedPriceSum = 0.0;
   
    boolean first = true;
    while(records.hasNext()) {
      Record rec = records.next();
      Tuple t = rec.getField(1, Tuple.class);
     
      if(first) {
        first = false;
        rec.copyTo(outRecord);
        returnTuple.addAttribute(rec.getField(0, StringValue.class).toString());
      }
     
      long tupleQuantity = Long.parseLong(t.getStringValueAt(4));
      quantity += tupleQuantity;
     
      double extendedPricePerTuple = Double.parseDouble(t.getStringValueAt(5));
      extendedPriceSum += extendedPricePerTuple;
    }
   
    LongValue pactQuantity = new LongValue(quantity);
    returnTuple.addAttribute("" + pactQuantity);
View Full Code Here

  }

  @Test
  public void testGetLongValueAt() {
 
    Tuple t = new Tuple();
   
    long[] testVals = {0,1,2,1234123,-1,-1212312, Long.MIN_VALUE, Long.MAX_VALUE};
   
    for(long testVal : testVals) {
      t.addAttribute(testVal+"");
    }
   
    // check for same value
    for(int i=0;i<testVals.length;i++) {
      Assert.assertTrue(t.getLongValueAt(i) == testVals[i]);
    }
   
    // check for out-of-bounds values
    boolean exceptionThrown = false;
    try {
      t.getLongValueAt(-1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getLongValueAt(testVals.length);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getLongValueAt(testVals.length+1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    // check for invalid format exception
    t.addAttribute("abc");
    exceptionThrown = false;
    try {
      t.getLongValueAt(testVals.length);
    } catch(NumberFormatException nfe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
View Full Code Here

  }

  @Test
  public void testGetByteArrayValueAt() {
   
    Tuple t = new Tuple();
   
    String[] testStrings = {"a","b","123123","Hello world!","Test with p|pe"};
   
    for(String testString : testStrings) {
      t.addAttribute(testString);
    }
   
    // check for same value
    for(int i=0;i<testStrings.length;i++) {
      byte[] att = t.getByteArrayValueAt(i);
      Assert.assertTrue(att.length == (testStrings[i]).getBytes().length);
      for(int j=0;j<att.length;j++) {
        Assert.assertTrue(att[j] == testStrings[i].getBytes()[j]);
      }
    }
   
    // check for out-of-bounds values
    boolean exceptionThrown = false;
    try {
      t.getByteArrayValueAt(-1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getByteArrayValueAt(testStrings.length);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
    exceptionThrown = false;
    try {
      t.getByteArrayValueAt(testStrings.length+1);
    } catch(IndexOutOfBoundsException ioobe) {
      exceptionThrown = true;
    }
    Assert.assertTrue(exceptionThrown);
   
View Full Code Here

   
  }

  @Test
  public void testReserveSpace() {
    Tuple t = new Tuple();
   
    t.addAttribute("a");
    t.addAttribute("b");
    t.addAttribute("cde");
   
    t.reserveSpace(512);
   
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getStringValueAt(1).equals("b"));
    Assert.assertTrue(t.getStringValueAt(2).equals("cde"));
    Assert.assertTrue(t.getBytes().length == 512);
   
    t.reserveSpace(20);
   
    Assert.assertTrue(t.getNumberOfColumns() == 3);
    Assert.assertTrue(t.getStringValueAt(0).equals("a"));
    Assert.assertTrue(t.getStringValueAt(1).equals("b"));
    Assert.assertTrue(t.getStringValueAt(2).equals("cde"));
    Assert.assertTrue(t.getBytes().length == 512);
   
  }
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.