[
https://issues.apache.org/jira/browse/BEAM-5504?focusedWorklogId=506112&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-506112
]
ASF GitHub Bot logged work on BEAM-5504:
----------------------------------------
Author: ASF GitHub Bot
Created on: 29/Oct/20 08:10
Start Date: 29/Oct/20 08:10
Worklog Time Spent: 10m
Work Description: piotr-szuberski commented on a change in pull request
#12780:
URL: https://github.com/apache/beam/pull/12780#discussion_r514070547
##########
File path:
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/pubsub/RowToPubsubMessage.java
##########
@@ -57,14 +73,43 @@ public static RowToPubsubMessage
withTimestampAttribute(boolean useTimestampAttr
? input.apply(WithTimestamps.of((row) ->
row.getDateTime(TIMESTAMP_FIELD).toInstant()))
: input;
- return withTimestamp
- .apply(DropFields.fields(TIMESTAMP_FIELD))
- .apply(ToJson.of())
- .apply(
- MapElements.into(TypeDescriptor.of(PubsubMessage.class))
- .via(
- (String json) ->
- new PubsubMessage(
- json.getBytes(StandardCharsets.ISO_8859_1),
ImmutableMap.of())));
+ withTimestamp = withTimestamp.apply(DropFields.fields(TIMESTAMP_FIELD));
+ switch (payloadFormat) {
+ case JSON:
+ return withTimestamp
+ .apply("MapRowToJsonString", ToJson.of())
+ .apply("MapToJsonBytes", MapElements.via(new StringToBytes()))
+ .apply("MapToPubsubMessage", MapElements.via(new
ToPubsubMessage()));
+ case AVRO:
+ return withTimestamp
+ .apply(
+ "MapRowToAvroBytes",
+
MapElements.via(AvroUtils.getRowToAvroBytesFunction(payloadSchema)))
+ .apply("MapToPubsubMessage", MapElements.via(new
ToPubsubMessage()));
+ default:
+ throw new IllegalArgumentException("Unsupported payload format: " +
payloadFormat);
+ }
+ }
+
+ private static class StringToBytes extends SimpleFunction<String, byte[]> {
+ @Override
+ public byte[] apply(String s) {
+ return s.getBytes(ISO_8859_1);
Review comment:
Sure! Done.
----------------------------------------------------------------
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:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 506112)
Time Spent: 11h 50m (was: 11h 40m)
> PubsubAvroTable
> ---------------
>
> Key: BEAM-5504
> URL: https://issues.apache.org/jira/browse/BEAM-5504
> Project: Beam
> Issue Type: New Feature
> Components: dsl-sql
> Reporter: Rui Wang
> Assignee: Piotr Szuberski
> Priority: P2
> Time Spent: 11h 50m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)