Search in sources :

Example 21 with StringValue

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

the class CharValueArrayTest method testBoundedArrayWithVariableLengthCharacters.

@Test
public void testBoundedArrayWithVariableLengthCharacters() {
    // characters alternatingly take 1 and 2 bytes (plus one byte for length)
    int count = 1280;
    ValueArray<StringValue> sva = new StringValueArray(3200);
    // fill the array
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(Character.toString((char) (i & 0xFF)))));
        assertEquals(i + 1, sva.size());
    }
    // array is now full
    assertTrue(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals((idx++) & 0xFF, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertFalse(sva.add(new StringValue(String.valueOf((char) count))));
    assertFalse(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 22 with StringValue

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

the class CharValueArrayTest method testUnboundedArray.

@Test
public void testUnboundedArray() {
    int count = 4096;
    ValueArray<StringValue> sva = new StringValueArray();
    // add several elements
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(String.valueOf((char) i))));
        assertEquals(i + 1, sva.size());
    }
    // array never fills
    assertFalse(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals(idx++, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertTrue(sva.add(new StringValue(String.valueOf((char) count))));
    assertTrue(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test mark/reset
    int size = sva.size();
    sva.mark();
    assertTrue(sva.add(new StringValue()));
    assertEquals(size + 1, sva.size());
    sva.reset();
    assertEquals(size, sva.size());
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 23 with StringValue

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

the class CharValueArrayTest method testBoundedArray.

@Test
public void testBoundedArray() {
    // one byte for length and one byte for character
    int count = StringValueArray.DEFAULT_CAPACITY_IN_BYTES / 2;
    ValueArray<StringValue> sva = new StringValueArray(StringValueArray.DEFAULT_CAPACITY_IN_BYTES);
    // fill the array
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(Character.toString((char) (i & 0x7F)))));
        assertEquals(i + 1, sva.size());
    }
    // array is now full
    assertTrue(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals((idx++) & 0x7F, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertFalse(sva.add(new StringValue(String.valueOf((char) count))));
    assertFalse(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 24 with StringValue

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

the class StringValueArrayTest method testBoundedArrayWithVariableLengthCharacters.

@Test
public void testBoundedArrayWithVariableLengthCharacters() {
    // characters alternatingly take 1 and 2 bytes (plus one byte for length)
    int count = 1280;
    ValueArray<StringValue> sva = new StringValueArray(3200);
    // fill the array
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(Character.toString((char) (i & 0xFF)))));
        assertEquals(i + 1, sva.size());
    }
    // array is now full
    assertTrue(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals((idx++) & 0xFF, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertFalse(sva.add(new StringValue(String.valueOf((char) count))));
    assertFalse(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : StringValue(org.apache.flink.types.StringValue) Test(org.junit.Test)

Example 25 with StringValue

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

the class StringValueArrayTest method testUnboundedArray.

@Test
public void testUnboundedArray() {
    int count = 4096;
    ValueArray<StringValue> sva = new StringValueArray();
    // add several elements
    for (int i = 0; i < count; i++) {
        assertFalse(sva.isFull());
        assertEquals(i, sva.size());
        assertTrue(sva.add(new StringValue(String.valueOf((char) i))));
        assertEquals(i + 1, sva.size());
    }
    // array never fills
    assertFalse(sva.isFull());
    assertEquals(count, sva.size());
    // verify the array values
    int idx = 0;
    for (StringValue sv : sva) {
        assertEquals(idx++, sv.getValue().charAt(0));
    }
    // add element past end of array
    assertTrue(sva.add(new StringValue(String.valueOf((char) count))));
    assertTrue(sva.addAll(sva));
    // test copy
    assertEquals(sva, sva.copy());
    // test copyTo
    StringValueArray svaTo = new StringValueArray();
    sva.copyTo(svaTo);
    assertEquals(sva, svaTo);
    // test mark/reset
    int size = sva.size();
    sva.mark();
    assertTrue(sva.add(new StringValue()));
    assertEquals(size + 1, sva.size());
    sva.reset();
    assertEquals(size, sva.size());
    // test clear
    sva.clear();
    assertEquals(0, sva.size());
}
Also used : 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