Package org.apache.flink.types

Examples of org.apache.flink.types.StringValue


  @Test
  public void testParseValidUnquotedStrings() {
   
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "abcdefgh|i|jklmno|".getBytes();
    StringValue s = new StringValue();
   
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 9);
    assertTrue(s.getValue().equals("abcdefgh"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("i"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 18);
    assertTrue(s.getValue().equals("jklmno"));
   
   
    // check single field not terminated
    recBytes = "abcde".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 5);
    assertTrue(s.getValue().equals("abcde"));
   
    // check last field not terminated
    recBytes = "abcde|fg".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 6);
    assertTrue(s.getValue().equals("abcde"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 8);
    assertTrue(s.getValue().equals("fg"));
  }
View Full Code Here


  @Test
  public void testParseValidQuotedStringsWithoutWhitespaces() {
   
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "\"abcdefgh\"|\"i\"|\"jklmno\"|".getBytes();
    StringValue s = new StringValue();
   
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcdefgh"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 15);
    assertTrue(s.getValue().equals("i"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 24);
    assertTrue(s.getValue().equals("jklmno"));
   
   
    // check single field not terminated
    recBytes = "\"abcde\"".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 7);
    assertTrue(s.getValue().equals("abcde"));
   
    // check last field not terminated
    recBytes = "\"abcde\"|\"fg\"".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 8);
    assertTrue(s.getValue().equals("abcde"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 12);
    assertTrue(s.getValue().equals("fg"));
   
    // check delimiter in quotes
    recBytes = "\"abcde|fg\"|\"hij|kl|mn|op\"|".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcde|fg"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 26);
    assertTrue(s.getValue().equals("hij|kl|mn|op"));
   
    // check delimiter in quotes last field not terminated
    recBytes = "\"abcde|fg\"|\"hij|kl|mn|op\"".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcde|fg"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 25);
    assertTrue(s.getValue().equals("hij|kl|mn|op"));
  }
View Full Code Here

  @Test
  public void testParseValidQuotedStringsWithWhitespaces() {
   
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "  \"abcdefgh\"|     \"i\"\t\t\t|\t \t\"jklmno\"  |".getBytes();
    StringValue s = new StringValue();
   
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 13);
    assertTrue(s.getValue().equals("abcdefgh"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 25);
    assertTrue(s.getValue().equals("i"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 39);
    assertTrue(s.getValue().equals("jklmno"));
   
    // check valid strings with out whitespaces without trailing delimiter
    recBytes = "  \"abcdefgh\"|     \"i\"\t\t\t|\t \t\"jklmno\"  ".getBytes();
    s = new StringValue();
   
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 13);
    assertTrue(s.getValue().equals("abcdefgh"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 25);
    assertTrue(s.getValue().equals("i"));
   
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 38);
    assertTrue(s.getValue().equals("jklmno"));
   
    // check single field not terminated
    recBytes = "  \t\"abcde\"\t\t  \t ".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 16);
    assertTrue(s.getValue().equals("abcde"));
   
    // check single field terminated
    recBytes = "  \t\"abcde\"\t\t  \t |".getBytes();
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos == 17);
    assertTrue(s.getValue().equals("abcde"));
  }
View Full Code Here

  @Test
  public void testParseInvalidQuotedStrings() {
   
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "  \"abcdefgh\" gh |     \"i\"\t\t\t|\t \t\"jklmno\"  |".getBytes();
    StringValue s = new StringValue();
   
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, '|', s);
    assertTrue(startPos < 0);
  }
View Full Code Here

  }
 
  @Override
  public StringValue[] getValidTestResults() {
    return new StringValue[] {
      new StringValue("abcdefgh"), new StringValue("i"), new StringValue("jklmno"),
      new StringValue("abcdefgh"), new StringValue("i"), new StringValue("jklmno"),
      new StringValue("ab,cde|fg"), new StringValue("hij|m|n|op"),
      new StringValue("abcdefgh"), new StringValue("i"), new StringValue("jklmno"),
      new StringValue("     abcd    ")
    };
  }
View Full Code Here

    Record record = null;
    float amount = 0;

    while (records.hasNext()) {
      record = records.next();
      StringValue value = record.getField(1, StringValue.class);
      amount += Float.parseFloat(value.toString());
    }

    value.setValue(String.valueOf(amount));
    record.setField(1, value);
    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());
    value1.setField(1, new StringIntPair(new StringValue("" + amount), year));
    out.collect(value1);
  }
View Full Code Here

   
    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

  public void join(Record value1, Record value2, Collector<Record> out)
      throws Exception {
    suppKey = value1.getField(1, suppKey);
    nationVal = value2.getField(1, nationVal);
   
    StringValue nationName = new StringValue(nationVal.getStringValueAt(1));
   
    value1.setField(0, suppKey);
    value1.setField(1, nationName);
   
    out.collect(value1);
View Full Code Here

  public StringIntPair(StringValue first, IntValue second) {
    super(first, second);
  }

  public StringIntPair(String first, int second) {
    super(new StringValue(first), new IntValue(second));
  }
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.