Search in sources :

Example 61 with StringValue

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

the class StringValueUtilsTest method testTokenizerOnStringWithoutNexToken.

@Test
public void testTokenizerOnStringWithoutNexToken() {
    StringValue testString = new StringValue("test");
    StringValueUtils.WhitespaceTokenizer tokenizer = new WhitespaceTokenizer();
    tokenizer.setStringToTokenize(testString);
    // first token
    tokenizer.next(testString);
    // next token is not exist
    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 62 with StringValue

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

the class VarLengthStringParserTest method testParseValidQuotedStrings.

@Test
public void testParseValidQuotedStrings() {
    this.parser = new StringValueParser();
    this.parser.enableQuotedStringParsing((byte) '"');
    // 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 == 11);
    assertTrue(s.getValue().equals("abcdefgh"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 15);
    assertTrue(s.getValue().equals("i"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 24);
    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 == 7);
    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 == 8);
    assertTrue(s.getValue().equals("abcde"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 12);
    assertTrue(s.getValue().equals("fg"));
    // check delimiter in quotes
    recBytes = "\"abcde|fg\"|\"hij|kl|mn|op\"|".getBytes(ConfigConstants.DEFAULT_CHARSET);
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcde|fg"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, 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(ConfigConstants.DEFAULT_CHARSET);
    startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcde|fg"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 25);
    assertTrue(s.getValue().equals("hij|kl|mn|op"));
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 63 with StringValue

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

the class VarLengthStringParserTest method testParseInvalidQuotedStrings.

@Test
public void testParseInvalidQuotedStrings() {
    this.parser = new StringValueParser();
    this.parser.enableQuotedStringParsing((byte) '"');
    // check valid strings with out whitespaces and trailing delimiter
    byte[] recBytes = "\"abcdefgh\"-|\"jklmno  ".getBytes(ConfigConstants.DEFAULT_CHARSET);
    StringValue s = new StringValue();
    int startPos = 0;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos < 0);
    startPos = 12;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos < 0);
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 64 with StringValue

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

the class VarLengthStringParserTest method testParseValidMixedStrings.

@Test
public void testParseValidMixedStrings() {
    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;
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 11);
    assertTrue(s.getValue().equals("abcde|gh"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 15);
    assertTrue(s.getValue().equals("i"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 24);
    assertTrue(s.getValue().equals("jklmnopq"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 29);
    assertTrue(s.getValue().equals("rs"));
    startPos = parser.parseField(recBytes, startPos, recBytes.length, new byte[] { '|' }, s);
    assertTrue(startPos == 32);
    assertTrue(s.getValue().equals("tuv"));
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 65 with StringValue

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

the class VarLengthStringParserTest method testGetValue.

@Test
public void testGetValue() {
    Value v = parser.createValue();
    assertTrue(v instanceof StringValue);
}
Also used : Value(org.apache.flink.types.Value) StringValue(org.apache.flink.types.StringValue) StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

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