Skip to content
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

add getPartitionIndex() to the Record<> #9947

Merged
merged 4 commits into from
Mar 26, 2021

Conversation

dlg99
Copy link
Contributor

@dlg99 dlg99 commented Mar 17, 2021

Motivation

Looking at #9927 (comment) there is no way to reliably get partition number.
There is Optional getPartitionId() which returns:

  • "{topic}-{partition}" in some Record implementation
  • String(partition) in other implementation (parsing back integer is a waste)
  • empty Optional (ok) in others

Modifications

Added default Optional<Integer> getPartitionIndex() to the Record interface.
Return partition number where appropriate.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is a trivial rework / code cleanup without any test coverage.

Does this pull request potentially affect one of the following parts:

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: yes - adds new method to interface Record<T>
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no
  • The rest endpoints: no
  • The admin cli options: no
  • Anything that affects deployment: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? JavaDocs

*
* @return The partition number
*/
default Optional<Integer> getPartitionNumber() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default Optional<Integer> getPartitionNumber() {
default Optional<Integer> getPartitionId() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think parittion id it better than partition number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sijie I agree but default Optional<String> getPartitionId() { already defined on line 76.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about getPartitionIndex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sijie renamed

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good to me
but I left some comments


KafkaSchemaWrappedSchema keySchema;

KafkaSchemaWrappedSchema valueSchema;

AbstractKafkaSourceRecord(SourceRecord srcRecord) {
this.destinationTopic = Optional.of("persistent://"+topicNamespace + "/" + srcRecord.topic());
this.partitionNumber = Optional.of(srcRecord.kafkaPartition());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional.ofNullable ?

@@ -178,6 +178,11 @@ public KafkaRecord(ConsumerRecord<String,?> record, V value, Schema<V> schema) {
return Optional.of(Integer.toString(record.partition()));
}

@Override
public Optional<Integer> getPartitionNumber() {
return Optional.of(record.partition());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional.ofNullable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

record.partition() returns int, cannot be null

@@ -61,6 +61,11 @@
return Optional.of(topicName);
}

@Override
public Optional<Integer> getPartitionNumber() {
return Optional.of(partition);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional.ofNullable ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int partition, cannot be null

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@sijie you left comments PTAL again

@dlg99 dlg99 changed the title add partitionNumber() to the Record<> add getPartitionIndex() to the Record<> Mar 22, 2021
Copy link
Contributor

@codelipenghui codelipenghui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add some tests for the new method introduced in the PR?

@codelipenghui codelipenghui added this to the 2.8.0 milestone Mar 24, 2021
@sijie sijie merged commit 0992634 into apache:master Mar 26, 2021
@dlg99 dlg99 deleted the record-partition-number branch October 14, 2021 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants