Search in sources :

Example 16 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueUtilsTest method testToLowerCaseConverting.

@Test
public void testToLowerCaseConverting() {
    StringValue testString = new StringValue("TEST");
    StringValueUtils.toLowerCase(testString);
    assertEquals(new StringValue("test"), testString);
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 17 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueUtilsTest method testTokenizerOnStringOnlyWithDelimiter.

@Test
public void testTokenizerOnStringOnlyWithDelimiter() {
    StringValue testString = new StringValue("    ");
    StringValueUtils.WhitespaceTokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setStringToTokenize(testString);
    assertFalse(tokenizer.next(testString));
}
Also used : WhitespaceTokenizer(org.apache.flink.util.StringValueUtils.WhitespaceTokenizer) StringValue(org.apache.flink.types.StringValue) WhitespaceTokenizer(org.apache.flink.util.StringValueUtils.WhitespaceTokenizer) Test(org.junit.Test)

Example 18 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class VarLengthStringParserTest method testParseValidMixedStringsWithCharset.

@Test
public void testParseValidMixedStringsWithCharset() {
    Charset charset = StandardCharsets.US_ASCII;
    this.parser = new StringValueParser();
    this.parser.enableQuotedStringParsing((byte) '@');
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "@abcde|gh@|@i@|jklmnopq|@rs@|tuv".getBytes(ConfigConstants.DEFAULT_CHARSET);
    StringValue s = new StringValue();
    int startPos = 0;
    parser.setCharset(charset);
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertEquals(11, startPos);
    assertEquals("abcde|gh", s.getValue());
}
Also used : Charset(java.nio.charset.Charset) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 19 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class VarLengthStringParserTest method testParseValidUnquotedStrings.

@Test
public void testParseValidUnquotedStrings() {
    this.parser = new StringValueParser();
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "abcdefgh|i|jklmno|".getBytes(ConfigConstants.DEFAULT_CHARSET);
    StringValue s = new StringValue();
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 9);
    assertTrue(s.getValue().equals("abcdefgh"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("i"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 18);
    assertTrue(s.getValue().equals("jklmno"));
    // check single field not terminated
    recBytes = "abcde".getBytes(ConfigConstants.DEFAULT_CHARSET);
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 5);
    assertTrue(s.getValue().equals("abcde"));
    // check last field not terminated
    recBytes = "abcde|fg".getBytes(ConfigConstants.DEFAULT_CHARSET);
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 6);
    assertTrue(s.getValue().equals("abcde"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 8);
    assertTrue(s.getValue().equals("fg"));
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 20 with StringValue

use of org.apache.flink.types.StringValue in project flink by apache.

the class StringValueArraySerializerTest method getTestData.

@Override
protected StringValueArray[] getTestData() {
    int defaultElements = StringValueArray.DEFAULT_CAPACITY_IN_BYTES;
    Random rnd = new Random(874597969123412341L);
    long rndLong = rnd.nextLong();
    StringValueArray sva0 = new StringValueArray();
    StringValueArray sva1 = new StringValueArray();
    sva1.addAll(sva0);
    sva1.add(new StringValue(String.valueOf(0)));
    StringValueArray sva2 = new StringValueArray();
    sva2.addAll(sva1);
    sva2.add(new StringValue(String.valueOf(1)));
    StringValueArray sva3 = new StringValueArray();
    sva3.addAll(sva2);
    sva3.add(new StringValue(String.valueOf(-1)));
    StringValueArray sva4 = new StringValueArray();
    sva4.addAll(sva3);
    sva4.add(new StringValue(String.valueOf(Long.MAX_VALUE)));
    StringValueArray sva5 = new StringValueArray();
    sva5.addAll(sva4);
    sva5.add(new StringValue(String.valueOf(Long.MIN_VALUE)));
    StringValueArray sva6 = new StringValueArray();
    sva6.addAll(sva5);
    sva6.add(new StringValue(String.valueOf(rndLong)));
    StringValueArray sva7 = new StringValueArray();
    sva7.addAll(sva6);
    sva7.add(new StringValue(String.valueOf(-rndLong)));
    StringValueArray sva8 = new StringValueArray();
    sva8.addAll(sva7);
    for (int i = 0; i < 1.5 * defaultElements; i++) {
        sva8.add(new StringValue(String.valueOf(i)));
    }
    sva8.addAll(sva8);
    return new StringValueArray[] { sva0, sva1, sva2, sva3, sva4, sva5, sva6, sva7, sva8 };
}
Also used : Random(java.util.Random) StringValue(org.apache.flink.types.StringValue)

Aggregations

StringValue (org.apache.flink.types.StringValue)88 Test (org.junit.Test)61 IntValue (org.apache.flink.types.IntValue)35 LongValue (org.apache.flink.types.LongValue)21 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)15 Record (org.apache.flink.types.Record)13 TupleTypeInfo (org.apache.flink.api.java.typeutils.TupleTypeInfo)12 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)11 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)11 DoubleValue (org.apache.flink.types.DoubleValue)11 Value (org.apache.flink.types.Value)10 Tuple3 (org.apache.flink.api.java.tuple.Tuple3)9 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)7 Plan (org.apache.flink.api.common.Plan)7 Configuration (org.apache.flink.configuration.Configuration)7 FileInputSplit (org.apache.flink.core.fs.FileInputSplit)7 NoSuchElementException (java.util.NoSuchElementException)6 File (java.io.File)5 JobExecutionResult (org.apache.flink.api.common.JobExecutionResult)5