Package org.apache.flink.types

Examples of org.apache.flink.types.Record


        driverPath,
        dbUrl,
        "select * from " + sourceTable);
    jdbcInputFormat.configure(null);

    Record record = new Record();
    while (!jdbcInputFormat.reachedEnd()) {
      jdbcInputFormat.nextRecord(record);
      jdbcOutputFormat.writeRecord(record);
    }

    jdbcOutputFormat.close();
    jdbcInputFormat.close();

    jdbcInputFormat = new JDBCInputFormat(
        driverPath,
        dbUrl,
        "select * from " + targetTable);
    jdbcInputFormat.configure(null);

    int recordCount = 0;
    while (!jdbcInputFormat.reachedEnd()) {
      jdbcInputFormat.nextRecord(record);
      Assert.assertEquals(5, record.getNumFields());
      Assert.assertEquals("Field 0 should be int", IntValue.class, record.getField(0, IntValue.class).getClass());
      Assert.assertEquals("Field 1 should be String", StringValue.class, record.getField(1, StringValue.class).getClass());
      Assert.assertEquals("Field 2 should be String", StringValue.class, record.getField(2, StringValue.class).getClass());
      Assert.assertEquals("Field 3 should be float", DoubleValue.class, record.getField(3, DoubleValue.class).getClass());
      Assert.assertEquals("Field 4 should be int", IntValue.class, record.getField(4, IntValue.class).getClass());

      int[] pos = {0, 1, 2, 3, 4};
      Value[] values = {new IntValue(), new StringValue(), new StringValue(), new DoubleValue(), new IntValue()};
      Assert.assertTrue(record.equalsFields(pos, dbData[recordCount], values));

      recordCount++;
    }
    Assert.assertEquals(5, recordCount);

View Full Code Here


  @Test(expected = IllegalArgumentException.class)
  public void testUnsupportedSQLType() {
    jdbcInputFormat = new JDBCInputFormat("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:ebookshop", "select * from bookscontent");
    jdbcInputFormat.configure(null);
    jdbcInputFormat.nextRecord(new Record());
  }
View Full Code Here

  }

  @Test(expected = IllegalArgumentException.class)
  public void testNotConfiguredFormatNext() {
    jdbcInputFormat = new JDBCInputFormat("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:ebookshop", "select * from books");
    jdbcInputFormat.nextRecord(new Record());
  }
View Full Code Here

  @Test
  public void testJDBCInputFormat() throws IOException {
    jdbcInputFormat = new JDBCInputFormat("org.apache.derby.jdbc.EmbeddedDriver", "jdbc:derby:memory:ebookshop", "select * from books");
    jdbcInputFormat.configure(null);
    Record record = new Record();
    int recordCount = 0;
    while (!jdbcInputFormat.reachedEnd()) {
      jdbcInputFormat.nextRecord(record);
      Assert.assertEquals(5, record.getNumFields());
      Assert.assertEquals("Field 0 should be int", IntValue.class, record.getField(0, IntValue.class).getClass());
      Assert.assertEquals("Field 1 should be String", StringValue.class, record.getField(1, StringValue.class).getClass());
      Assert.assertEquals("Field 2 should be String", StringValue.class, record.getField(2, StringValue.class).getClass());
      Assert.assertEquals("Field 3 should be float", DoubleValue.class, record.getField(3, DoubleValue.class).getClass());
      Assert.assertEquals("Field 4 should be int", IntValue.class, record.getField(4, IntValue.class).getClass());

      int[] pos = {0, 1, 2, 3, 4};
      Value[] values = {new IntValue(), new StringValue(), new StringValue(), new DoubleValue(), new IntValue()};
      Assert.assertTrue(record.equalsFields(pos, dbData[recordCount], values));

      recordCount++;
    }
    Assert.assertEquals(5, recordCount);
   
View Full Code Here

      StringTokenizer tokenizer = new StringTokenizer(line);
      while (tokenizer.hasMoreTokens()) {
        String word = tokenizer.nextToken();
       
        // we emit a (word, 1) pair
        collector.collect(new Record(new StringValue(word), new IntValue(1)));
      }
    }
View Full Code Here

   
    private static final long serialVersionUID = 1L;
   
    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception {
      Record element = null;
      int sum = 0;
     
      while (records.hasNext()) {
        element = records.next();
        int cnt = element.getField(1, IntValue.class).getValue();
        sum += cnt;
      }

      element.setField(1, new IntValue(sum));
      out.collect(element);
    }
View Full Code Here

    public MockOutputGate(int index, List<Record> outList) {
      super(new JobID(), new GateID(), index);
      this.out = outList;
      this.deserializer = new AdaptiveSpanningRecordDeserializer<Record>();
      this.record = new Record();
    }
View Full Code Here

     *   1:SHIPPRIORITY
     *   2:SUM(EXTENDEDPRICE)
     */
    @Override
    public void reduce(Iterator<Record> values, Collector<Record> out) {
      Record rec = null;
      double partExtendedPriceSum = 0;

      while (values.hasNext()) {
        rec = values.next();
        partExtendedPriceSum += rec.getField(2, DoubleValue.class).getValue();
      }

      this.extendedPrice.setValue(partExtendedPriceSum);
      rec.setField(2, this.extendedPrice);
      out.collect(rec);
    }
View Full Code Here

    private StringValue reduceValue = new StringValue();
    private StringValue combineValue = new StringValue();

    @Override
    public void combine(Iterator<Record> records, Collector<Record> out) {
      Record record = null;
      int sum = 0;
     
      while (records.hasNext()) {
        record = records.next();
        combineValue = record.getField(1, combineValue);
        sum += Integer.parseInt(combineValue.toString());
      }
      combineValue.setValue(sum + "");
      record.setField(1, combineValue);
      out.collect(record);
    }
View Full Code Here

      out.collect(record);
    }

    @Override
    public void reduce(Iterator<Record> records, Collector<Record> out) {
      Record record = null;
      int sum = 0;
     
      while (records.hasNext()) {
        record = records.next();
        reduceValue = record.getField(1, reduceValue);
        sum += Integer.parseInt(reduceValue.toString());
      }
      record.setField(1, new IntValue(sum));
      out.collect(record);
    }
View Full Code Here

TOP

Related Classes of org.apache.flink.types.Record

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.