Search in sources :

Example 1 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class RowDataKinesisDeserializationSchema method deserialize.

@Override
public RowData deserialize(byte[] recordValue, String partitionKey, String seqNum, long approxArrivalTimestamp, String stream, String shardId) throws IOException {
    RowData physicalRow = physicalDeserializer.deserialize(recordValue);
    GenericRowData metadataRow = new GenericRowData(requestedMetadataFields.size());
    for (int i = 0; i < metadataRow.getArity(); i++) {
        Metadata metadataField = requestedMetadataFields.get(i);
        if (metadataField == Metadata.Timestamp) {
            metadataRow.setField(i, TimestampData.fromEpochMillis(approxArrivalTimestamp));
        } else if (metadataField == Metadata.SequenceNumber) {
            metadataRow.setField(i, StringData.fromString(seqNum));
        } else if (metadataField == Metadata.ShardId) {
            metadataRow.setField(i, StringData.fromString(shardId));
        } else {
            String msg = String.format("Unsupported metadata key %s", metadataField);
            // should never happen
            throw new RuntimeException(msg);
        }
    }
    return new JoinedRowData(physicalRow.getRowKind(), physicalRow, metadataRow);
}
Also used : RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 2 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class PythonTableFunctionOperator method open.

@Override
@SuppressWarnings("unchecked")
public void open() throws Exception {
    super.open();
    rowDataWrapper = new StreamRecordRowDataWrappingCollector(output);
    reuseJoinedRow = new JoinedRowData();
    udtfInputProjection = udtfInputGeneratedProjection.newInstance(Thread.currentThread().getContextClassLoader());
    forwardedInputSerializer = new RowDataSerializer(inputType);
    udtfInputTypeSerializer = PythonTypeUtils.toInternalSerializer(udfInputType);
    udtfOutputTypeSerializer = PythonTypeUtils.toInternalSerializer(udfOutputType);
    input = null;
    hasJoined = false;
    isFinishResult = true;
}
Also used : StreamRecordRowDataWrappingCollector(org.apache.flink.table.runtime.operators.python.utils.StreamRecordRowDataWrappingCollector) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) RowDataSerializer(org.apache.flink.table.runtime.typeutils.RowDataSerializer)

Example 3 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class AbstractArrowPythonAggregateFunctionOperator method open.

@SuppressWarnings("unchecked")
@Override
public void open() throws Exception {
    super.open();
    rowDataWrapper = new StreamRecordRowDataWrappingCollector(output);
    reuseJoinedRow = new JoinedRowData();
    udafInputProjection = udafInputGeneratedProjection.newInstance(Thread.currentThread().getContextClassLoader());
    arrowSerializer = new ArrowSerializer(udfInputType, udfOutputType);
    arrowSerializer.open(bais, baos);
    currentBatchCount = 0;
}
Also used : StreamRecordRowDataWrappingCollector(org.apache.flink.table.runtime.operators.python.utils.StreamRecordRowDataWrappingCollector) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ArrowSerializer(org.apache.flink.table.runtime.arrow.serializers.ArrowSerializer)

Example 4 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class AbstractTopNFunction method open.

@Override
public void open(Configuration parameters) throws Exception {
    super.open(parameters);
    outputRow = new JoinedRowData();
    if (!isConstantRankEnd) {
        ValueStateDescriptor<Long> rankStateDesc = new ValueStateDescriptor<>("rankEnd", Types.LONG);
        if (ttlConfig.isEnabled()) {
            rankStateDesc.enableTimeToLive(ttlConfig);
        }
        rankEndState = getRuntimeContext().getState(rankStateDesc);
    }
    // compile comparator
    sortKeyComparator = generatedSortKeyComparator.newInstance(getRuntimeContext().getUserCodeClassLoader());
    generatedSortKeyComparator = null;
    invalidCounter = getRuntimeContext().getMetricGroup().counter("topn.invalidTopSize");
    // initialize rankEndFetcher
    if (!isConstantRankEnd) {
        LogicalType rankEndIdxType = inputRowType.toRowFieldTypes()[rankEndIndex];
        switch(rankEndIdxType.getTypeRoot()) {
            case BIGINT:
                rankEndFetcher = (RowData row) -> row.getLong(rankEndIndex);
                break;
            case INTEGER:
                rankEndFetcher = (RowData row) -> (long) row.getInt(rankEndIndex);
                break;
            case SMALLINT:
                rankEndFetcher = (RowData row) -> (long) row.getShort(rankEndIndex);
                break;
            default:
                LOG.error("variable rank index column must be long, short or int type, while input type is {}", rankEndIdxType.getClass().getName());
                throw new UnsupportedOperationException("variable rank index column must be long type, while input type is " + rankEndIdxType.getClass().getName());
        }
    }
}
Also used : ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) GenericRowData(org.apache.flink.table.data.GenericRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Example 5 with JoinedRowData

use of org.apache.flink.table.data.utils.JoinedRowData in project flink by apache.

the class AbstractRowTimeUnboundedPrecedingOver method open.

@Override
public void open(Configuration parameters) throws Exception {
    function = genAggsHandler.newInstance(getRuntimeContext().getUserCodeClassLoader());
    function.open(new PerKeyStateDataViewStore(getRuntimeContext()));
    output = new JoinedRowData();
    sortedTimestamps = new LinkedList<Long>();
    // initialize accumulator state
    InternalTypeInfo<RowData> accTypeInfo = InternalTypeInfo.ofFields(accTypes);
    ValueStateDescriptor<RowData> accStateDesc = new ValueStateDescriptor<RowData>("accState", accTypeInfo);
    accState = getRuntimeContext().getState(accStateDesc);
    // input element are all binary row as they are came from network
    InternalTypeInfo<RowData> inputType = InternalTypeInfo.ofFields(inputFieldTypes);
    ListTypeInfo<RowData> rowListTypeInfo = new ListTypeInfo<RowData>(inputType);
    MapStateDescriptor<Long, List<RowData>> inputStateDesc = new MapStateDescriptor<Long, List<RowData>>("inputState", Types.LONG, rowListTypeInfo);
    inputState = getRuntimeContext().getMapState(inputStateDesc);
    initCleanupTimeState("RowTimeUnboundedOverCleanupTime");
    // metrics
    this.numLateRecordsDropped = getRuntimeContext().getMetricGroup().counter(LATE_ELEMENTS_DROPPED_METRIC_NAME);
}
Also used : MapStateDescriptor(org.apache.flink.api.common.state.MapStateDescriptor) ValueStateDescriptor(org.apache.flink.api.common.state.ValueStateDescriptor) RowData(org.apache.flink.table.data.RowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) ListTypeInfo(org.apache.flink.api.java.typeutils.ListTypeInfo) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) PerKeyStateDataViewStore(org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)

Aggregations

JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)47 RowData (org.apache.flink.table.data.RowData)22 GenericRowData (org.apache.flink.table.data.GenericRowData)17 ValueStateDescriptor (org.apache.flink.api.common.state.ValueStateDescriptor)12 PerKeyStateDataViewStore (org.apache.flink.table.runtime.dataview.PerKeyStateDataViewStore)12 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)11 ArrayList (java.util.ArrayList)7 List (java.util.List)7 MapStateDescriptor (org.apache.flink.api.common.state.MapStateDescriptor)7 ListTypeInfo (org.apache.flink.api.java.typeutils.ListTypeInfo)5 StreamOperator (org.apache.flink.streaming.api.operators.StreamOperator)5 Test (org.junit.Test)5 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 StateTtlConfig (org.apache.flink.api.common.state.StateTtlConfig)4 Configuration (org.apache.flink.configuration.Configuration)4 OperatorID (org.apache.flink.runtime.jobgraph.OperatorID)3 TwoInputStreamTask (org.apache.flink.streaming.runtime.tasks.TwoInputStreamTask)3 TwoInputStreamTaskTestHarness (org.apache.flink.streaming.runtime.tasks.TwoInputStreamTaskTestHarness)3 StreamRecordRowDataWrappingCollector (org.apache.flink.table.runtime.operators.python.utils.StreamRecordRowDataWrappingCollector)3 RowDataSerializer (org.apache.flink.table.runtime.typeutils.RowDataSerializer)3