You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@beam.apache.org by "ASF GitHub Bot (Jira)" <ji...@apache.org> on 2020/11/03 13:31:00 UTC
[jira] [Work logged] (BEAM-10892) Add Proto support to Kafka Table
Provider
[ https://issues.apache.org/jira/browse/BEAM-10892?focusedWorklogId=506655&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-506655 ]
ASF GitHub Bot logged work on BEAM-10892:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 03/Nov/20 13:30
Start Date: 03/Nov/20 13:30
Worklog Time Spent: 10m
Work Description: TheNeuralBit commented on a change in pull request #12838:
URL: https://github.com/apache/beam/pull/12838#discussion_r516389575
##########
File path: sdks/java/extensions/protobuf/src/main/java/org/apache/beam/sdk/extensions/protobuf/ProtoMessageSchema.java
##########
@@ -115,6 +122,76 @@ public SchemaUserTypeCreator schemaTypeCreator(Class<?> targetClass, Schema sche
return creator;
}
+ public static <T extends Message> SimpleFunction<byte[], Row> getProtoBytesToRowFn(
+ Class<T> clazz) {
+ return new ProtoBytesToRowFn<>(clazz);
+ }
+
+ public static class ProtoBytesToRowFn<T extends Message> extends SimpleFunction<byte[], Row> {
+ private final ProtoCoder<T> protoCoder;
+ private final SerializableFunction<T, Row> toRowFunction;
+
+ public ProtoBytesToRowFn(Class<T> clazz) {
+ this.protoCoder = ProtoCoder.of(clazz);
+ this.toRowFunction = new ProtoMessageSchema().toRowFunction(TypeDescriptor.of(clazz));
+ }
+
+ @Override
+ public Row apply(byte[] bytes) {
+ try {
+ InputStream inputStream = new ByteArrayInputStream(bytes);
+ T message = protoCoder.decode(inputStream);
+ return toRowFunction.apply(message);
+ } catch (IOException e) {
+ throw new IllegalArgumentException("Could not decode row from proto payload.", e);
+ }
+ }
+ }
+
+ public static <T extends Message> SimpleFunction<Row, byte[]> getRowToProtoBytesFn(
+ Class<T> clazz) {
+ return new RowToProtoBytesFn<>(clazz);
+ }
+
+ public static class RowToProtoBytesFn<T extends Message> extends SimpleFunction<Row, byte[]> {
Review comment:
Thanks! I think this approach is best for now. In the future I think we should try to isolate all the format specific logic in a module for just that format, and just have general purpose logic in SQL. This is closer to that vision imo.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Issue Time Tracking
-------------------
Worklog Id: (was: 506655)
Time Spent: 5h 10m (was: 5h)
> Add Proto support to Kafka Table Provider
> -----------------------------------------
>
> Key: BEAM-10892
> URL: https://issues.apache.org/jira/browse/BEAM-10892
> Project: Beam
> Issue Type: New Feature
> Components: dsl-sql
> Reporter: Piotr Szuberski
> Assignee: Piotr Szuberski
> Priority: P2
> Fix For: 2.26.0
>
> Time Spent: 5h 10m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)