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);
}
}
}
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);
}
}
}
}
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;
}
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);
}
}
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;
}
Aggregations