Search in sources :

Example 11 with RowDataSerializer

use of org.apache.flink.table.runtime.typeutils.RowDataSerializer 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)

Example 12 with RowDataSerializer

use of org.apache.flink.table.runtime.typeutils.RowDataSerializer in project flink by apache.

the class NestedRowDataTest method getBinaryRowData.

private BinaryRowData getBinaryRowData() {
    BinaryRowData row = new BinaryRowData(1);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    GenericTypeInfo<MyObj> info = new GenericTypeInfo<>(MyObj.class);
    TypeSerializer<MyObj> genericSerializer = info.createSerializer(new ExecutionConfig());
    GenericRowData gRow = new GenericRowData(5);
    gRow.setField(0, 1);
    gRow.setField(1, 5L);
    gRow.setField(2, StringData.fromString("12345678"));
    gRow.setField(3, null);
    gRow.setField(4, RawValueData.fromObject(new MyObj(15, 5)));
    RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.RAW(info.getTypeClass(), info.createSerializer(new ExecutionConfig())).getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringDataSerializer.INSTANCE, StringDataSerializer.INSTANCE, new RawValueDataSerializer<>(genericSerializer) });
    writer.writeRow(0, gRow, serializer);
    writer.complete();
    return row;
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) MyObj(org.apache.flink.table.data.util.DataFormatTestUtil.MyObj) GenericTypeInfo(org.apache.flink.api.java.typeutils.GenericTypeInfo) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 13 with RowDataSerializer

use of org.apache.flink.table.runtime.typeutils.RowDataSerializer in project flink by apache.

the class NestedRowDataTest method testNestInNestedRowData.

@Test
public void testNestInNestedRowData() {
    // layer1
    GenericRowData gRow = new GenericRowData(4);
    gRow.setField(0, 1);
    gRow.setField(1, 5L);
    gRow.setField(2, StringData.fromString("12345678"));
    gRow.setField(3, null);
    // layer2
    RowDataSerializer serializer = new RowDataSerializer(new LogicalType[] { DataTypes.INT().getLogicalType(), DataTypes.BIGINT().getLogicalType(), DataTypes.STRING().getLogicalType(), DataTypes.STRING().getLogicalType() }, new TypeSerializer[] { IntSerializer.INSTANCE, LongSerializer.INSTANCE, StringSerializer.INSTANCE, StringSerializer.INSTANCE });
    BinaryRowData row = new BinaryRowData(2);
    BinaryRowWriter writer = new BinaryRowWriter(row);
    writer.writeString(0, StringData.fromString("hahahahafff"));
    writer.writeRow(1, gRow, serializer);
    writer.complete();
    // layer3
    BinaryRowData row2 = new BinaryRowData(1);
    BinaryRowWriter writer2 = new BinaryRowWriter(row2);
    writer2.writeRow(0, row, null);
    writer2.complete();
    // verify
    {
        NestedRowData nestedRow = (NestedRowData) row2.getRow(0, 2);
        BinaryRowData binaryRow = new BinaryRowData(2);
        binaryRow.pointTo(nestedRow.getSegments(), nestedRow.getOffset(), nestedRow.getSizeInBytes());
        assertEquals(binaryRow, row);
    }
    assertEquals(row2.getRow(0, 2).getString(0), StringData.fromString("hahahahafff"));
    RowData nestedRow = row2.getRow(0, 2).getRow(1, 4);
    assertEquals(nestedRow.getInt(0), 1);
    assertEquals(nestedRow.getLong(1), 5L);
    assertEquals(nestedRow.getString(2), StringData.fromString("12345678"));
    assertTrue(nestedRow.isNullAt(3));
}
Also used : BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) NestedRowData(org.apache.flink.table.data.binary.NestedRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) BinaryRowWriter(org.apache.flink.table.data.writer.BinaryRowWriter) NestedRowData(org.apache.flink.table.data.binary.NestedRowData) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer) Test(org.junit.Test)

Example 14 with RowDataSerializer

use of org.apache.flink.table.runtime.typeutils.RowDataSerializer in project flink by apache.

the class BinaryArrayDataTest method testNested.

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

Example 15 with RowDataSerializer

use of org.apache.flink.table.runtime.typeutils.RowDataSerializer in project flink by apache.

the class StreamArrowPythonGroupWindowAggregateFunctionOperator method open.

@Override
public void open() throws Exception {
    super.open();
    windowSerializer = windowAssigner.getWindowSerializer(new ExecutionConfig());
    internalTimerService = getInternalTimerService("window-timers", windowSerializer, this);
    triggerContext = new TriggerContext();
    triggerContext.open();
    StateDescriptor<ListState<RowData>, List<RowData>> windowStateDescriptor = new ListStateDescriptor<>("window-input", new RowDataSerializer(inputType));
    StateDescriptor<ListState<RowData>, List<RowData>> dataRetractStateDescriptor = new ListStateDescriptor<>("data-retract", new RowDataSerializer(inputType));
    this.windowAccumulateData = (InternalListState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, windowStateDescriptor);
    this.windowRetractData = (InternalListState<K, W, RowData>) getOrCreateKeyedState(windowSerializer, dataRetractStateDescriptor);
    inputKeyAndWindow = new LinkedList<>();
    windowProperty = new GenericRowData(namedProperties.length);
    windowAggResult = new JoinedRowData();
    WindowContext windowContext = new WindowContext();
    windowAssigner.open(windowContext);
}
Also used : ListState(org.apache.flink.api.common.state.ListState) InternalListState(org.apache.flink.runtime.state.internal.InternalListState) ListStateDescriptor(org.apache.flink.api.common.state.ListStateDescriptor) ExecutionConfig(org.apache.flink.api.common.ExecutionConfig) GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Aggregations

RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)27 RowData (org.apache.flink.table.data.RowData)12 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)11 RowType (org.apache.flink.table.types.logical.RowType)11 BinaryRowWriter (org.apache.flink.table.data.writer.BinaryRowWriter)6 RowDataKeySelector (org.apache.flink.table.runtime.keyselector.RowDataKeySelector)6 ZoneId (java.time.ZoneId)5 Transformation (org.apache.flink.api.dag.Transformation)5 GenericRowData (org.apache.flink.table.data.GenericRowData)5 ExecEdge (org.apache.flink.table.planner.plan.nodes.exec.ExecEdge)5 OneInputTransformation (org.apache.flink.streaming.api.transformations.OneInputTransformation)4 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)3 AggregateInfoList (org.apache.flink.table.planner.plan.utils.AggregateInfoList)3 PerKeyStateDataViewStore (org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)3 IntType (org.apache.flink.table.types.logical.IntType)3 LogicalType (org.apache.flink.table.types.logical.LogicalType)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)2