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 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 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

  {
    LineItemFilter out = new LineItemFilter();
   
    String shipDate = "foobarDate";
   
    Tuple input = createInputTuple(shipDate);
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
    rec.setField(1, input);
   
View Full Code Here

  @Test
  public void shouldNoThrowExceptionOnTooShortTuple() throws Exception, InterruptedException
  {
    LineItemFilter out = new LineItemFilter();
   
    Tuple input = new Tuple();
    input.addAttribute("" +1);
    input.addAttribute("" + 155190);
    input.addAttribute("" + 7706);
    input.addAttribute("" + 1);
    input.addAttribute("" + 17);
    input.addAttribute("" + 21168.23);
    input.addAttribute("" + 0.04);
    input.addAttribute("" + 0.02);
    input.addAttribute(RETURN_FLAG);
    input.addAttribute("0");
    //the relevant column is missing now
   
    IntValue inputKey = new IntValue();
    Record rec = new Record();
    rec.setField(0, inputKey);
View Full Code Here

   *
   * 1155190|7706|1|17|21168.23|0.04|0.02|N|O|1996-03-13|1996-02-12|1996-03-22|DELIVER IN PERSON|TRUCK|egular courts above the|
   * @param shipDate the date the {@link LineItemFilter} filters for.
   */
  private Tuple createInputTuple(String shipDate) {
    Tuple input = new Tuple();
    input.addAttribute("" +1);
    input.addAttribute("" + 155190);
    input.addAttribute("" + 7706);
    input.addAttribute("" + 1);
    input.addAttribute("" + 17);
    input.addAttribute("" + 21168.23);
    input.addAttribute("" + 0.04);
    input.addAttribute("" + 0.02);
    input.addAttribute(RETURN_FLAG);
    input.addAttribute("0");
    input.addAttribute(shipDate);
    return 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.