New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BEAM-13592 Add getOrderingKey in o.a.b.sdk.io.gcp.pubsub.PubsubMessage #22216
Merged
egalpin
merged 15 commits into
apache:master
from
gemelen:beam-13592-pubsub-java-orderingkey
Oct 11, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
03de550
BEAM-13592 Add getOrderingKey in org.apache.beam.sdk.io.gcp.pubsub.Pu…
gemelen d6f5ae4
Add CHANGES entry
gemelen 267cd10
Rename transform name according to review comment
gemelen bc97c6b
Update to pass ordering key
gemelen 7be63b9
Add CHANGES entry
gemelen bd1050a
Adds ordering key to OutgoingMessage builder, adds new coders to pubs…
egalpin e2a7c44
Fixes pubsub bounded writer allowing for orderingKey
egalpin bc60b74
Alters order of pubsub message support in registrar
egalpin 46497d1
Removed publishTime and messageId in grpc pubsub client publish
egalpin c3ea563
Attempts to allow different pubsub root url for PubsubIO.Write
egalpin 92e4d39
Fixes pubsub tests root url
egalpin 0d622d9
Puts PubsubMessageCoder last in registrar
egalpin 8d50229
Uses MoreObjects over Objects
egalpin fd7dedd
Renames PubsubMessageCoder to PubsubMessageWithAttributesAndMessageId…
egalpin 9ec1429
Merge remote-tracking branch 'upstream/master' into egalpin/gemelen-b…
egalpin File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...he/beam/sdk/io/gcp/pubsub/PubsubMessageWithAttributesAndMessageIdAndOrderingKeyCoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.beam.sdk.io.gcp.pubsub; | ||
|
||
import com.google.protobuf.Timestamp; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Map; | ||
import org.apache.beam.sdk.coders.ByteArrayCoder; | ||
import org.apache.beam.sdk.coders.Coder; | ||
import org.apache.beam.sdk.coders.CustomCoder; | ||
import org.apache.beam.sdk.coders.MapCoder; | ||
import org.apache.beam.sdk.coders.NullableCoder; | ||
import org.apache.beam.sdk.coders.StringUtf8Coder; | ||
import org.apache.beam.sdk.extensions.protobuf.ProtoCoder; | ||
import org.apache.beam.sdk.values.TypeDescriptor; | ||
|
||
/** A coder for PubsubMessage including all fields of a PubSub message from server. */ | ||
@SuppressWarnings({ | ||
"nullness" // TODO(https://github.com/apache/beam/issues/20497) | ||
}) | ||
public class PubsubMessageWithAttributesAndMessageIdAndOrderingKeyCoder | ||
extends CustomCoder<PubsubMessage> { | ||
// A message's payload cannot be null | ||
private static final Coder<byte[]> PAYLOAD_CODER = ByteArrayCoder.of(); | ||
// A message's attributes can be null. | ||
private static final Coder<Map<String, String>> ATTRIBUTES_CODER = | ||
NullableCoder.of(MapCoder.of(StringUtf8Coder.of(), StringUtf8Coder.of())); | ||
// A message's messageId cannot be null | ||
private static final Coder<String> MESSAGE_ID_CODER = StringUtf8Coder.of(); | ||
// A message's publish time, populated by server | ||
private static final Coder<Timestamp> PUBLISH_TIME_CODER = ProtoCoder.of(Timestamp.class); | ||
// A message's ordering key can be null | ||
private static final Coder<String> ORDERING_KEY_CODER = NullableCoder.of(StringUtf8Coder.of()); | ||
|
||
public static Coder<PubsubMessage> of(TypeDescriptor<PubsubMessage> ignored) { | ||
return of(); | ||
} | ||
|
||
public static PubsubMessageWithAttributesAndMessageIdAndOrderingKeyCoder of() { | ||
return new PubsubMessageWithAttributesAndMessageIdAndOrderingKeyCoder(); | ||
} | ||
|
||
@Override | ||
public void encode(PubsubMessage value, OutputStream outStream) throws IOException { | ||
PAYLOAD_CODER.encode(value.getPayload(), outStream); | ||
ATTRIBUTES_CODER.encode(value.getAttributeMap(), outStream); | ||
MESSAGE_ID_CODER.encode(value.getMessageId(), outStream); | ||
// TODO(discuss what to do with publish_time field) | ||
PUBLISH_TIME_CODER.encode(Timestamp.getDefaultInstance(), outStream); | ||
ORDERING_KEY_CODER.encode(value.getOrderingKey(), outStream); | ||
} | ||
|
||
@Override | ||
public PubsubMessage decode(InputStream inStream) throws IOException { | ||
byte[] payload = PAYLOAD_CODER.decode(inStream); | ||
Map<String, String> attributes = ATTRIBUTES_CODER.decode(inStream); | ||
String messageId = MESSAGE_ID_CODER.decode(inStream); | ||
PUBLISH_TIME_CODER.decode(inStream); | ||
String orderingKey = ORDERING_KEY_CODER.decode(inStream); | ||
return new PubsubMessage(payload, attributes, messageId, orderingKey); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe to support bounded writes, on line 1329 of this file you'll need to add explicit copying of the orderingKey as well (in the
output.add(OutgoingMessage.of(...
section ofprocessElement