Search in sources :

Example 6 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class RowDataTest method before.

@Before
public void before() {
    str = StringData.fromString("haha");
    generic = RawValueData.fromObject("haha");
    genericSerializer = new RawValueDataSerializer<>(StringSerializer.INSTANCE);
    decimal1 = DecimalData.fromUnscaledLong(10, 5, 0);
    decimal2 = DecimalData.fromBigDecimal(new BigDecimal(11), 20, 0);
    array = new BinaryArrayData();
    {
        BinaryArrayWriter arrayWriter = new BinaryArrayWriter(array, 2, 4);
        arrayWriter.writeInt(0, 15);
        arrayWriter.writeInt(1, 16);
        arrayWriter.complete();
    }
    map = BinaryMapData.valueOf(array, array);
    underRow = new BinaryRowData(2);
    {
        BinaryRowWriter writer = new BinaryRowWriter(underRow);
        writer.writeInt(0, 15);
        writer.writeInt(1, 16);
        writer.complete();
    }
    bytes = new byte[] { 1, 5, 6 };
    timestamp1 = TimestampData.fromEpochMillis(123L);
    timestamp2 = TimestampData.fromLocalDateTime(LocalDateTime.of(1969, 1, 1, 0, 0, 0, 123456789));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) BinaryArrayWriter(org.apache.flink.table.data.writer.BinaryArrayWriter) BinaryArrayData(org.apache.flink.table.data.binary.BinaryArrayData) BigDecimal(java.math.BigDecimal) Before(org.junit.Before)

Example 7 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class BinaryHashTableTest method testRepeatBuildJoinWithSpill.

@Test
public void testRepeatBuildJoinWithSpill() throws Exception {
    final int numKeys = 30000;
    final int numRows = 300000;
    final int probeValsPerKey = 1;
    MutableObjectIterator<BinaryRowData> buildInput = new MutableObjectIterator<BinaryRowData>() {

        int cnt = 0;

        @Override
        public BinaryRowData next(BinaryRowData reuse) throws IOException {
            return next();
        }

        @Override
        public BinaryRowData next() throws IOException {
            cnt++;
            if (cnt > numRows) {
                return null;
            }
            int value = cnt % numKeys;
            BinaryRowData row = new BinaryRowData(2);
            BinaryRowWriter writer = new BinaryRowWriter(row);
            writer.writeInt(0, value);
            writer.writeInt(1, value);
            writer.complete();
            return row;
        }
    };
    MemoryManager memManager = MemoryManagerBuilder.newBuilder().setMemorySize(35 * PAGE_SIZE).build();
    MutableObjectIterator<BinaryRowData> probeInput = new UniformBinaryRowGenerator(numKeys, probeValsPerKey, true);
    final BinaryHashTable table = new BinaryHashTable(conf, new Object(), buildSideSerializer, probeSideSerializer, new MyProjection(), new MyProjection(), memManager, 35 * PAGE_SIZE, ioManager, 24, 200000, true, HashJoinType.INNER, null, false, new boolean[] { true }, true);
    int numRecordsInJoinResult = join(table, buildInput, probeInput, true);
    Assert.assertTrue("Wrong number of records in join result.", numRecordsInJoinResult < numRows);
    table.close();
    table.free();
}
Also used : MutableObjectIterator(org.apache.flink.util.MutableObjectIterator) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) MemoryManager(org.apache.flink.runtime.memory.MemoryManager) UniformBinaryRowGenerator(org.apache.flink.table.runtime.util.UniformBinaryRowGenerator) Test(org.junit.Test)

Example 8 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class BinaryRowDataTest method testHashAndCopy.

@Test
public void testHashAndCopy() throws IOException {
    MemorySegment[] segments = new MemorySegment[3];
    for (int i = 0; i < 3; i++) {
        segments[i] = MemorySegmentFactory.wrap(new byte[64]);
    }
    RandomAccessOutputView out = new RandomAccessOutputView(segments, 64);
    BinaryRowDataSerializer serializer = new BinaryRowDataSerializer(2);
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, fromString("hahahahahahahahahahahahahahahahahahahhahahahahahahahahah"));
    writer.writeString(1, fromString("hahahahahahahahahahahahahahahahahahahhahahahahahahahahaa"));
    writer.complete();
    serializer.serializeToPages(row, out);
    ArrayList<MemorySegment> segmentList = new ArrayList<>(Arrays.asList(segments));
    RandomAccessInputView input = new RandomAccessInputView(segmentList, 64, 64);
    BinaryRowData mapRow = serializer.createInstance();
    mapRow = serializer.mapFromPages(mapRow, input);
    assertEquals(row, mapRow);
    assertEquals(row.getString(0), mapRow.getString(0));
    assertEquals(row.getString(1), mapRow.getString(1));
    assertNotEquals(row.getString(0), mapRow.getString(1));
    // test if the hash code before and after serialization are the same
    assertEquals(row.hashCode(), mapRow.hashCode());
    assertEquals(row.getString(0).hashCode(), mapRow.getString(0).hashCode());
    assertEquals(row.getString(1).hashCode(), mapRow.getString(1).hashCode());
    // test if the copy method produce a row with the same contents
    assertEquals(row.copy(), mapRow.copy());
    assertEquals(((BinaryStringData) row.getString(0)).copy(), ((BinaryStringData) mapRow.getString(0)).copy());
    assertEquals(((BinaryStringData) row.getString(1)).copy(), ((BinaryStringData) mapRow.getString(1)).copy());
}
Also used : RandomAccessInputView(org.apache.flink.runtime.io.disk.RandomAccessInputView) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) ArrayList(java.util.ArrayList) RandomAccessOutputView(org.apache.flink.runtime.io.disk.RandomAccessOutputView) MemorySegment(org.apache.flink.core.memory.MemorySegment) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer) Test(org.junit.Test)

Example 9 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class BinaryRowDataTest method testReuseWriter.

@Test
public void testReuseWriter() {
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, fromString("01234567"));
    writer.writeString(1, fromString("012345678"));
    writer.complete();
    assertEquals("01234567", row.getString(0).toString());
    assertEquals("012345678", row.getString(1).toString());
    writer.reset();
    writer.writeString(0, fromString("1"));
    writer.writeString(1, fromString("0123456789"));
    writer.complete();
    assertEquals("1", row.getString(0).toString());
    assertEquals("0123456789", row.getString(1).toString());
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) Test(org.junit.Test)

Example 10 with BinaryRowWriter

use of org.apache.flink.table.data.writer.BinaryRowWriter in project flink by apache.

the class BinaryRowDataTest method testNested.

@Test
public void testNested() {
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeRow(0, GenericRowData.of(fromString("1"), 1), new RowDataSerializer(RowType.of(VarCharType.STRING_TYPE, new IntType())));
    writer.setNullAt(1);
    writer.complete();
    RowData nestedRow = row.getRow(0, 2);
    assertEquals("1", nestedRow.getString(0).toString());
    assertEquals(1, nestedRow.getInt(1));
    assertTrue(row.isNullAt(1));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer) IntType(org.apache.flink.table.types.logical.IntType) Test(org.junit.Test)

Aggregations

BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)54 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)53 Test (org.junit.Test)32 Random (java.util.Random)6 BinaryArrayData (org.apache.flink.table.data.binary.BinaryArrayData)6 BinaryRowDataSerializer (org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)6 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)6 MemorySegment (org.apache.flink.core.memory.MemorySegment)5 BinaryArrayWriter (org.apache.flink.table.data.writer.BinaryArrayWriter)5 ArrayDataSerializer (org.apache.flink.table.runtime.typeutils.ArrayDataSerializer)5 ArrayList (java.util.ArrayList)4 GenericRowData (org.apache.flink.table.data.GenericRowData)4 MapDataSerializer (org.apache.flink.table.runtime.typeutils.MapDataSerializer)4 LogicalType (org.apache.flink.table.types.logical.LogicalType)4 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)3 StringData.fromString (org.apache.flink.table.data.StringData.fromString)3 TimestampData (org.apache.flink.table.data.TimestampData)3 RawValueDataSerializer (org.apache.flink.table.runtime.typeutils.RawValueDataSerializer)3 BigDecimal (java.math.BigDecimal)2 HashMap (java.util.HashMap)2