Package org.apache.flink.test.recordJobs.util

Examples of org.apache.flink.test.recordJobs.util.Tuple


  }

  @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


  }

  @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

  }

  @Test
  public void testCompact() {
   
    Tuple t = new Tuple();
    t.addAttribute("Hello world!");
   
    Assert.assertTrue(t.getBytes().length == 256);
    t.compact();
    Assert.assertTrue(t.getBytes().length == 13);
   
    byte[] ba = new byte[1024];
    int[] of = {0};
    t = new Tuple(ba, of, 0);
   
    Assert.assertTrue(t.getBytes().length == 1024);
    t.compact();
    Assert.assertTrue(t.getBytes().length == 0);
   
    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.getBytes().length == ba.length);
    t.compact();
    Assert.assertTrue(t.getBytes().length == 22);
   
  }
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

    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

  }

  @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

    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

TOP

Related Classes of org.apache.flink.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.