Search in sources :

Example 1 with WrappingRuntimeException

use of org.apache.flink.util.WrappingRuntimeException in project flink by apache.

the class RegistryAvroSerializationSchema method serialize.

@Override
public byte[] serialize(T object) {
    checkAvroInitialized();
    if (object == null) {
        return null;
    } else {
        try {
            ByteArrayOutputStream outputStream = getOutputStream();
            outputStream.reset();
            Encoder encoder = getEncoder();
            schemaCoder.writeSchema(getSchema(), outputStream);
            getDatumWriter().write(object, encoder);
            encoder.flush();
            return outputStream.toByteArray();
        } catch (IOException e) {
            throw new WrappingRuntimeException("Failed to serialize schema registry.", e);
        }
    }
}
Also used : WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) Encoder(org.apache.avro.io.Encoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 2 with WrappingRuntimeException

use of org.apache.flink.util.WrappingRuntimeException in project flink by apache.

the class AbstractPythonFunctionOperator method processElementsOfCurrentKeyIfNeeded.

private void processElementsOfCurrentKeyIfNeeded(Object newKey) {
    // for batch operator
    if (inBatchExecutionMode(getKeyedStateBackend()) && !Objects.equals(newKey, getCurrentKey())) {
        while (!isBundleFinished()) {
            try {
                invokeFinishBundle();
                fireAllRegisteredTimers(newKey);
            } catch (Exception e) {
                throw new WrappingRuntimeException(e);
            }
        }
    }
}
Also used : WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException)

Example 3 with WrappingRuntimeException

use of org.apache.flink.util.WrappingRuntimeException in project flink by apache.

the class SharedBufferAccessor method materializeMatch.

/**
 * Extracts the real event from the sharedBuffer with pre-extracted eventId.
 *
 * @param match the matched event's eventId.
 * @return the event associated with the eventId.
 */
public Map<String, List<V>> materializeMatch(Map<String, List<EventId>> match) {
    Map<String, List<V>> materializedMatch = new LinkedHashMap<>(match.size());
    for (Map.Entry<String, List<EventId>> pattern : match.entrySet()) {
        List<V> events = new ArrayList<>(pattern.getValue().size());
        for (EventId eventId : pattern.getValue()) {
            try {
                V event = sharedBuffer.getEvent(eventId).getElement();
                events.add(event);
            } catch (Exception ex) {
                throw new WrappingRuntimeException(ex);
            }
        }
        materializedMatch.put(pattern.getKey(), events);
    }
    return materializedMatch;
}
Also used : WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with WrappingRuntimeException

use of org.apache.flink.util.WrappingRuntimeException in project flink by apache.

the class CopyOnWriteSkipListStateMapSnapshot method transformEntry.

private StateEntry<K, N, S> transformEntry(TypeSerializer<K> keySerializer, TypeSerializer<N> namespaceSerializer, StateSnapshotTransformer<S> stateSnapshotTransformer, SkipListValueSerializer<S> skipListValueSerializer, DataInputDeserializer inputDeserializer, Tuple2<Long, Long> pointers) {
    try {
        final S oldState = owningStateMap.helpGetState(pointers.f1, skipListValueSerializer);
        final S newState;
        if (stateSnapshotTransformer != null) {
            newState = stateSnapshotTransformer.filterOrTransform(oldState);
        } else {
            newState = oldState;
        }
        Tuple2<byte[], byte[]> keyAndNamespace = owningStateMap.helpGetBytesForKeyAndNamespace(pointers.f0);
        if (newState == null) {
            return null;
        } else {
            inputDeserializer.setBuffer(keyAndNamespace.f0);
            K key = keySerializer.deserialize(inputDeserializer);
            inputDeserializer.setBuffer(keyAndNamespace.f1);
            N namespace = namespaceSerializer.deserialize(inputDeserializer);
            return new StateEntry.SimpleStateEntry<>(key, namespace, newState);
        }
    } catch (IOException e) {
        throw new WrappingRuntimeException(e);
    }
}
Also used : WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) IOException(java.io.IOException)

Example 5 with WrappingRuntimeException

use of org.apache.flink.util.WrappingRuntimeException in project flink by apache.

the class SimpleCatalogFactory method createCatalog.

@Override
public Catalog createCatalog(Context context) {
    final Configuration configuration = Configuration.fromMap(context.getOptions());
    final String database = configuration.getString(DEFAULT_DATABASE);
    final String tableName = configuration.getString(TABLE_NAME);
    final GenericInMemoryCatalog genericInMemoryCatalog = new GenericInMemoryCatalog(context.getName(), database);
    StreamTableSource<Row> tableSource = new StreamTableSource<Row>() {

        @Override
        public DataStream<Row> getDataStream(StreamExecutionEnvironment execEnv) {
            return execEnv.fromCollection(TABLE_CONTENTS).returns(new RowTypeInfo(new TypeInformation[] { Types.INT(), Types.STRING() }, new String[] { "id", "string" }));
        }

        @Override
        public TableSchema getTableSchema() {
            return TableSchema.builder().field("id", DataTypes.INT()).field("string", DataTypes.STRING()).build();
        }

        @Override
        public DataType getProducedDataType() {
            return DataTypes.ROW(DataTypes.FIELD("id", DataTypes.INT()), DataTypes.FIELD("string", DataTypes.STRING())).notNull();
        }
    };
    try {
        genericInMemoryCatalog.createTable(new ObjectPath(database, tableName), ConnectorCatalogTable.source(tableSource, false), false);
    } catch (Exception e) {
        throw new WrappingRuntimeException(e);
    }
    return genericInMemoryCatalog;
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) Configuration(org.apache.flink.configuration.Configuration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Row(org.apache.flink.types.Row) RowTypeInfo(org.apache.flink.api.java.typeutils.RowTypeInfo) StreamTableSource(org.apache.flink.table.sources.StreamTableSource) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException)

Aggregations

WrappingRuntimeException (org.apache.flink.util.WrappingRuntimeException)9 IOException (java.io.IOException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Encoder (org.apache.avro.io.Encoder)2 JobListener (org.apache.flink.core.execution.JobListener)2 FlinkException (org.apache.flink.util.FlinkException)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 TypeInformation (org.apache.flink.api.common.typeinfo.TypeInformation)1 RowTypeInfo (org.apache.flink.api.java.typeutils.RowTypeInfo)1 Configuration (org.apache.flink.configuration.Configuration)1 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)1 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)1 ObjectPath (org.apache.flink.table.catalog.ObjectPath)1 StreamTableSource (org.apache.flink.table.sources.StreamTableSource)1 Row (org.apache.flink.types.Row)1