Package org.apache.flink.types

Examples of org.apache.flink.types.StringValue


  }
 
  public static List<Tuple2<StringValue, IntValue>> createReduceMutableDataGroupedResult() {
    List<Tuple2<StringValue, IntValue>> data = new ArrayList<Tuple2<StringValue, IntValue>>();
   
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("a"), new IntValue(1)));
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("b"), new IntValue(2)));
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("c"), new IntValue(3)));
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("dd"), new IntValue(9)));
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("eee"), new IntValue(21)));
    data.add(new Tuple2<StringValue, IntValue>(new StringValue("ffff"), new IntValue(42)));
   
    return data;
  }
View Full Code Here


 
  public static final class ConcatSumMutableReducer extends RichGroupReduceFunction<Tuple2<StringValue, IntValue>, Tuple2<StringValue, IntValue>> {

    @Override
    public void reduce(Iterable<Tuple2<StringValue, IntValue>> values, Collector<Tuple2<StringValue, IntValue>> out) {
      Tuple2<StringValue, IntValue> current = new Tuple2<StringValue, IntValue>(new StringValue(""), new IntValue(0));
     
      for (Tuple2<StringValue, IntValue> next : values) {
        next.f0.append(current.f0);
        next.f1.setValue(current.f1.getValue() + next.f1.getValue());
        current = next;
View Full Code Here

  }

  // --------------------------------------------------------------------------------------------

  public Record readRecord(Record reuse, byte[] bytes, int offset, int numBytes) {
    StringValue str = this.theString;
   
    //Check if \n is used as delimiter and the end of this line is a \r, then remove \r from the line
    if (this.getDelimiter() != null && this.getDelimiter().length == 1
        && this.getDelimiter()[0] == NEW_LINE && offset+numBytes >= 1
        && bytes[offset+numBytes-1] == CARRIAGE_RETURN){
      numBytes -= 1;
    }

   
    if (this.ascii) {
      str.setValueAscii(bytes, offset, numBytes);
    }
    else {
      ByteBuffer byteWrapper = this.byteWrapper;
      if (bytes != byteWrapper.array()) {
        byteWrapper = ByteBuffer.wrap(bytes, 0, bytes.length);
        this.byteWrapper = byteWrapper;
      }
      byteWrapper.limit(offset + numBytes);
      byteWrapper.position(offset);
       
      try {
        CharBuffer result = this.decoder.decode(byteWrapper);
        str.setValue(result);
      }
      catch (CharacterCodingException e) {
        byte[] copy = new byte[numBytes];
        System.arraycopy(bytes, offset, copy, 0, numBytes);
        LOG.warn("Line could not be encoded: " + Arrays.toString(copy), e);
View Full Code Here

      }
     
      Record r = new Record(2);
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        format.writeRecord(r);
       
        r.setField(0, new StringValue("AbCdE"));
        r.setField(1, new IntValue(13));
        format.writeRecord(r);
       
        format.close();
       
View Full Code Here

      Record r = new Record(2);
     
      boolean success = true;
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        format.writeRecord(r);
       
        r.setNull(0);
        r.setField(1, new IntValue(13));
View Full Code Here

      }
     
      Record r = new Record(2);
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        format.writeRecord(r);
       
        r.setNull(0);
        r.setField(1, new IntValue(13));
View Full Code Here

      }
     
      Record r = new Record(2);
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        r.setField(2, new StringValue("Hello User"));
        format.writeRecord(r);
       
        r.setField(0, new StringValue("AbCdE"));
        r.setField(1, new IntValue(13));
        r.setField(2, new StringValue("ZyXvW"));
        format.writeRecord(r);
       
        format.close();
       
        BufferedReader dis = new BufferedReader(new FileReader(tempFile));
View Full Code Here

      Record r = new Record(2);
     
      boolean success = true;
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        r.setField(2, new StringValue("Hello User"));
        format.writeRecord(r);
 
        r = new Record();
       
        r.setField(0, new StringValue("AbCdE"));
        r.setField(1, new IntValue(13));
        format.writeRecord(r);
       
        format.close();
       
View Full Code Here

      }
     
      Record r = new Record(2);
     
      try {
        r.setField(0, new StringValue("Hello World"));
        r.setField(1, new IntValue(42));
        r.setField(2, new StringValue("Hello User"));
        format.writeRecord(r);
 
        r = new Record();
       
        r.setField(0, new StringValue("AbCdE"));
        r.setField(1, new IntValue(13));
        format.writeRecord(r);
       
        format.close();
       
View Full Code Here

  @Test
  public void testPair() {
    NfIntStringPair pair1 = new NfIntStringPair();

    pair1.setFirst(new IntValue(10));
    pair1.setSecond(new StringValue("This is a string"));

    // test data retrieval
    Assert.assertEquals(pair1.getFirst(), new IntValue(10));
    Assert.assertEquals(pair1.getSecond(), new StringValue("This is a string"));

    // test serialization
    try {
      NfIntStringPair mPairActual = new NfIntStringPair();

      pair1.write(new OutputViewDataOutputStreamWrapper(out));
      mPairActual.read(new InputViewDataInputStreamWrapper(in));

      Assert.assertEquals(pair1, mPairActual);
    } catch (IOException e) {
      Assert.fail("Unexpected IOException");
    }

    // test comparison
    NfIntStringPair pair2 = new NfIntStringPair();
    NfIntStringPair pair3 = new NfIntStringPair();
    NfIntStringPair pair4 = new NfIntStringPair();
    NfIntStringPair pair5 = new NfIntStringPair();
    NfIntStringPair pair6 = new NfIntStringPair();

    pair2.setFirst(new IntValue(10));
    pair2.setSecond(new StringValue("This is a string"));

    pair3.setFirst(new IntValue(5));
    pair3.setSecond(new StringValue("This is a string"));

    pair4.setFirst(new IntValue(15));
    pair4.setSecond(new StringValue("This is a string"));

    pair5.setFirst(new IntValue(10));
    pair5.setSecond(new StringValue("This is a strina"));

    pair6.setFirst(new IntValue(10));
    pair6.setSecond(new StringValue("This is a strinz"));

    Assert.assertTrue(pair1.compareTo(pair2) == 0);
    Assert.assertTrue(pair1.compareTo(pair3) > 0);
    Assert.assertTrue(pair1.compareTo(pair4) < 0);
    Assert.assertTrue(pair1.compareTo(pair5) > 0);
View Full Code Here

TOP

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

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.