use of org.apache.beam.sdk.coders.RowCoder in project beam by apache.
the class ExternalSchemaIOTransformRegistrar method translateRow.
private static Row translateRow(byte[] rowBytes, Schema configSchema) {
RowCoder rowCoder = RowCoder.of(configSchema);
InputStream stream = new ByteArrayInputStream(rowBytes);
try {
return rowCoder.decode(stream);
} catch (IOException e) {
throw new RuntimeException("Unable to infer configuration row from configuration proto and schema.", e);
}
}
use of org.apache.beam.sdk.coders.RowCoder in project beam by apache.
the class CoderTranslators method row.
static CoderTranslator<RowCoder> row() {
return new CoderTranslator<RowCoder>() {
@Override
public List<? extends Coder<?>> getComponents(RowCoder from) {
return ImmutableList.of();
}
@Override
public byte[] getPayload(RowCoder from) {
return SchemaTranslation.schemaToProto(from.getSchema(), true).toByteArray();
}
@Override
public RowCoder fromComponents(List<Coder<?>> components, byte[] payload, TranslationContext context) {
checkArgument(components.isEmpty(), "Expected empty component list, but received: " + components);
Schema schema;
try {
schema = SchemaTranslation.schemaFromProto(SchemaApi.Schema.parseFrom(payload));
} catch (InvalidProtocolBufferException e) {
throw new RuntimeException("Unable to parse schema for RowCoder: ", e);
}
return RowCoder.of(schema);
}
};
}
Aggregations