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

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


      }
    }
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception {
      Tuple tuple = record.getField(1, Tuple.class);
      Date orderDate;
     
      String orderStringDate = tuple.getStringValueAt(4);
     
      try {
        orderDate = sdf.parse(orderStringDate);
      } catch (ParseException e) {
        throw new RuntimeException(e);
View Full Code Here


    private final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   
    @Override
    public void map(Record record, Collector<Record> out) throws Exception {
      Tuple tuple = record.getField(1, Tuple.class);
      String commitString = tuple.getStringValueAt(11);
      String receiptString = tuple.getStringValueAt(12);

      Date commitDate;
      Date receiptDate;
     
      try {
View Full Code Here

  public static class JoinLiO extends JoinFunction {
   
    @Override
    public void join(Record order, Record line, Collector<Record> out)
        throws Exception {
      Tuple orderTuple = order.getField(1, Tuple.class);
     
      orderTuple.project(32);
      String newOrderKey = orderTuple.getStringValueAt(0);
     
      order.setField(0, new StringValue(newOrderKey));
      out.collect(order);
    }
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

         count++;
      }
     
      if(rec != null)
      {
        Tuple tuple = new Tuple();
        tuple.addAttribute("" + count);
        rec.setField(1, tuple);
      }
     
      out.collect(rec);
    }
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

    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

  public void shouldNotFilterTuple() throws Exception, InterruptedException
  {
    LineItemFilter out = new LineItemFilter();
   
    String shipDate = "1996-03-13";
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
View Full Code Here

  {
    LineItemFilter out = new LineItemFilter();
   
    String shipDate = "1999-03-13";
   
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
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.