Search in sources :

Example 41 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class SortMergeJoinOperator method open.

@Override
public void open() throws Exception {
    super.open();
    Configuration conf = getContainingTask().getJobConfiguration();
    isFinished = new boolean[] { false, false };
    collector = new StreamRecordCollector<>(output);
    ClassLoader cl = getUserCodeClassloader();
    AbstractRowDataSerializer inputSerializer1 = (AbstractRowDataSerializer) getOperatorConfig().getTypeSerializerIn1(cl);
    this.serializer1 = new BinaryRowDataSerializer(inputSerializer1.getArity());
    AbstractRowDataSerializer inputSerializer2 = (AbstractRowDataSerializer) getOperatorConfig().getTypeSerializerIn2(cl);
    this.serializer2 = new BinaryRowDataSerializer(inputSerializer2.getArity());
    this.memManager = this.getContainingTask().getEnvironment().getMemoryManager();
    this.ioManager = this.getContainingTask().getEnvironment().getIOManager();
    long totalMemory = computeMemorySize();
    externalBufferMemory = (long) (totalMemory * externalBufferMemRatio);
    externalBufferMemory = Math.max(externalBufferMemory, ResettableExternalBuffer.MIN_NUM_MEMORY);
    long totalSortMem = totalMemory - (type.equals(FlinkJoinType.FULL) ? externalBufferMemory * 2 : externalBufferMemory);
    if (totalSortMem < 0) {
        throw new TableException("Memory size is too small: " + totalMemory + ", please increase manage memory of task manager.");
    }
    // sorter1
    this.sorter1 = new BinaryExternalSorter(this.getContainingTask(), memManager, totalSortMem / 2, ioManager, inputSerializer1, serializer1, computer1.newInstance(cl), comparator1.newInstance(cl), conf);
    this.sorter1.startThreads();
    // sorter2
    this.sorter2 = new BinaryExternalSorter(this.getContainingTask(), memManager, totalSortMem / 2, ioManager, inputSerializer2, serializer2, computer2.newInstance(cl), comparator2.newInstance(cl), conf);
    this.sorter2.startThreads();
    keyComparator = genKeyComparator.newInstance(cl);
    this.condFunc = condFuncCode.newInstance(cl);
    condFunc.setRuntimeContext(getRuntimeContext());
    condFunc.open(new Configuration());
    projection1 = projectionCode1.newInstance(cl);
    projection2 = projectionCode2.newInstance(cl);
    this.leftNullRow = new GenericRowData(serializer1.getArity());
    this.rightNullRow = new GenericRowData(serializer2.getArity());
    this.joinedRow = new JoinedRowData();
    condFuncCode = null;
    computer1 = null;
    comparator1 = null;
    computer2 = null;
    comparator2 = null;
    projectionCode1 = null;
    projectionCode2 = null;
    genKeyComparator = null;
    getMetricGroup().gauge("memoryUsedSizeInBytes", (Gauge<Long>) () -> sorter1.getUsedMemoryInBytes() + sorter2.getUsedMemoryInBytes());
    getMetricGroup().gauge("numSpillFiles", (Gauge<Long>) () -> sorter1.getNumSpillFiles() + sorter2.getNumSpillFiles());
    getMetricGroup().gauge("spillInBytes", (Gauge<Long>) () -> sorter1.getSpillInBytes() + sorter2.getSpillInBytes());
}
Also used : AbstractRowDataSerializer(org.apache.flink.table.runtime.typeutils.AbstractRowDataSerializer) TableException(org.apache.flink.table.api.TableException) Configuration(org.apache.flink.configuration.Configuration) JoinedRowData(org.apache.flink.table.data.utils.JoinedRowData) BinaryExternalSorter(org.apache.flink.table.runtime.operators.sort.BinaryExternalSorter) GenericRowData(org.apache.flink.table.data.GenericRowData) BinaryRowDataSerializer(org.apache.flink.table.runtime.typeutils.BinaryRowDataSerializer)

Example 42 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class AvroToRowDataConverters method createRowConverter.

// -------------------------------------------------------------------------------------
// Runtime Converters
// -------------------------------------------------------------------------------------
public static AvroToRowDataConverter createRowConverter(RowType rowType) {
    final AvroToRowDataConverter[] fieldConverters = rowType.getFields().stream().map(RowType.RowField::getType).map(AvroToRowDataConverters::createNullableConverter).toArray(AvroToRowDataConverter[]::new);
    final int arity = rowType.getFieldCount();
    return avroObject -> {
        IndexedRecord record = (IndexedRecord) avroObject;
        GenericRowData row = new GenericRowData(arity);
        for (int i = 0; i < arity; ++i) {
            // avro always deserialize successfully even though the type isn't matched
            // so no need to throw exception about which field can't be deserialized
            row.setField(i, fieldConverters[i].convert(record.get(i)));
        }
        return row;
    };
}
Also used : ChronoField(java.time.temporal.ChronoField) Array(java.lang.reflect.Array) GenericArrayData(org.apache.flink.table.data.GenericArrayData) HashMap(java.util.HashMap) RowType(org.apache.flink.table.types.logical.RowType) ByteBuffer(java.nio.ByteBuffer) GenericRowData(org.apache.flink.table.data.GenericRowData) DecimalType(org.apache.flink.table.types.logical.DecimalType) GenericMapData(org.apache.flink.table.data.GenericMapData) Map(java.util.Map) LocalTime(java.time.LocalTime) LogicalTypeUtils(org.apache.flink.table.types.logical.utils.LogicalTypeUtils) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) RowData(org.apache.flink.table.data.RowData) GenericFixed(org.apache.avro.generic.GenericFixed) TimestampData(org.apache.flink.table.data.TimestampData) DataTypes(org.apache.flink.table.api.DataTypes) DecimalData(org.apache.flink.table.data.DecimalData) ArrayType(org.apache.flink.table.types.logical.ArrayType) Instant(java.time.Instant) AvroSchemaConverter.extractValueTypeToAvroMap(org.apache.flink.formats.avro.typeutils.AvroSchemaConverter.extractValueTypeToAvroMap) Serializable(java.io.Serializable) StringData(org.apache.flink.table.data.StringData) List(java.util.List) LogicalType(org.apache.flink.table.types.logical.LogicalType) LocalDate(java.time.LocalDate) Internal(org.apache.flink.annotation.Internal) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRowData(org.apache.flink.table.data.GenericRowData)

Example 43 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class RegistryAvroRowDataSeDeSchemaTest method address2RowData.

private static RowData address2RowData(Address address) {
    GenericRowData rowData = new GenericRowData(5);
    rowData.setField(0, address.getNum());
    rowData.setField(1, new BinaryStringData(address.getStreet().toString()));
    rowData.setField(2, new BinaryStringData(address.getCity().toString()));
    rowData.setField(3, new BinaryStringData(address.getState().toString()));
    rowData.setField(4, new BinaryStringData(address.getZip().toString()));
    return rowData;
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) BinaryStringData(org.apache.flink.table.data.binary.BinaryStringData)

Example 44 with GenericRowData

use of org.apache.flink.table.data.GenericRowData 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)

Example 45 with GenericRowData

use of org.apache.flink.table.data.GenericRowData in project flink by apache.

the class PythonStreamGroupWindowAggregateOperator method emitResult.

@Override
public void emitResult(Tuple2<byte[], Integer> resultTuple) throws Exception {
    byte[] rawUdfResult = resultTuple.f0;
    int length = resultTuple.f1;
    bais.setBuffer(rawUdfResult, 0, length);
    RowData udfResult = udfOutputTypeSerializer.deserialize(baisWrapper);
    byte recordType = udfResult.getByte(0);
    if (recordType == NORMAL_RECORD) {
        GenericRowData aggResult = (GenericRowData) udfResult.getRow(1, outputType.getFieldCount());
        int fieldCount = outputType.getFieldCount();
        for (int i = fieldCount - namedProperties.length; i < fieldCount; i++) {
            FlinkFnApi.GroupWindow.WindowProperty namedProperty = namedProperties[i - (fieldCount - namedProperties.length)];
            if (namedProperty == WINDOW_START || namedProperty == WINDOW_END) {
                aggResult.setField(i, TimestampData.fromEpochMillis(aggResult.getLong(i)));
            } else {
                aggResult.setField(i, TimestampData.fromEpochMillis(getShiftEpochMills(aggResult.getLong(i))));
            }
        }
        rowDataWrapper.collect(aggResult);
    } else {
        RowData timerData = udfResult.getRow(2, timerDataLength);
        byte timerOperandType = timerData.getByte(0);
        RowData key = timerData.getRow(1, keyLength);
        long timestamp = timerData.getLong(2);
        W window;
        byte[] encodedNamespace = timerData.getBinary(3);
        bais.setBuffer(encodedNamespace, 0, encodedNamespace.length);
        window = windowSerializer.deserialize(baisWrapper);
        BinaryRowData rowKey = keySerializer.toBinaryRow(key).copy();
        synchronized (getKeyedStateBackend()) {
            setCurrentKey(rowKey);
            if (timerOperandType == REGISTER_EVENT_TIMER) {
                internalTimerService.registerEventTimeTimer(window, toEpochMillsForTimer(timestamp, shiftTimeZone));
            } else if (timerOperandType == REGISTER_PROCESSING_TIMER) {
                internalTimerService.registerProcessingTimeTimer(window, toEpochMillsForTimer(timestamp, shiftTimeZone));
            } else if (timerOperandType == DELETE_EVENT_TIMER) {
                internalTimerService.deleteEventTimeTimer(window, toEpochMillsForTimer(timestamp, shiftTimeZone));
            } else if (timerOperandType == DELETE_PROCESSING_TIMER) {
                internalTimerService.deleteProcessingTimeTimer(window, toEpochMillsForTimer(timestamp, shiftTimeZone));
            } else {
                throw new RuntimeException(String.format("Unsupported timerOperandType %s.", timerOperandType));
            }
        }
    }
}
Also used : GenericRowData(org.apache.flink.table.data.GenericRowData) RowData(org.apache.flink.table.data.RowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) UpdatableRowData(org.apache.flink.table.data.UpdatableRowData) BinaryRowData(org.apache.flink.table.data.binary.BinaryRowData) GenericRowData(org.apache.flink.table.data.GenericRowData)

Aggregations

GenericRowData (org.apache.flink.table.data.GenericRowData)94 RowData (org.apache.flink.table.data.RowData)32 JoinedRowData (org.apache.flink.table.data.utils.JoinedRowData)16 Test (org.junit.Test)14 BinaryRowData (org.apache.flink.table.data.binary.BinaryRowData)13 RowType (org.apache.flink.table.types.logical.RowType)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 IntType (org.apache.flink.table.types.logical.IntType)11 List (java.util.List)9 LogicalType (org.apache.flink.table.types.logical.LogicalType)9 GenericArrayData (org.apache.flink.table.data.GenericArrayData)6 StringData (org.apache.flink.table.data.StringData)6 Arrays (java.util.Arrays)5 HashMap (java.util.HashMap)5 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4 Collections (java.util.Collections)4 Random (java.util.Random)4 Consumer (java.util.function.Consumer)4