close
Skip to content

[fix][connector-mango] fix split with avgSize zero error#9255

Merged
hailin0 merged 1 commit into
apache:devfrom
CosmosNi:fix_mango_spilt_error
Apr 30, 2025
Merged

[fix][connector-mango] fix split with avgSize zero error#9255
hailin0 merged 1 commit into
apache:devfrom
CosmosNi:fix_mango_spilt_error

Conversation

@CosmosNi

Copy link
Copy Markdown
Collaborator

fix split with AvgSize zero
close #9245

Purpose of this pull request

Does this PR introduce any user-facing change?

How was this patch tested?

Check list

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes a division by zero issue in the MongoDB connector's split logic when the average document size (AvgSize) is zero.

  • Adds tests to cover scenarios where AvgSize is zero with and without documents.
  • Updates the SamplingSplitStrategy to handle avgSize of zero without throwing an exception.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
seatunnel-connectors-v2/connector-mongodb/src/test/java/org/apache/seatunnel/connectors/seatunnel/mongodb/source/split/SamplingSplitStrategyTest.java Adds tests for zero avgSize scenarios
seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/source/split/SamplingSplitStrategy.java Adds condition to handle avgSize <= 0 and prevent division by zero

long avgSize = numAndAvgSize.getRight();

// Handle the case when avgSize is 0 to prevent division by zero
if (avgSize <= 0) {

Copilot AI Apr 29, 2025

Copy link

Choose a reason for hiding this comment

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

Consider revising the condition to explicitly check for avgSize == 0 if negative values for avgSize are not expected. If negative avgSize could occur, it may be indicative of invalid data and should be handled appropriately.

Suggested change
if (avgSize <= 0) {
if (avgSize == 0) {

Copilot uses AI. Check for mistakes.
@Hisoka-X Hisoka-X changed the title [fix][connector-mango] fix split with AvgSize zero [fix][connector-mango] fix split with avgSize zero error Apr 30, 2025
@hailin0 hailin0 merged commit 564863b into apache:dev Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] [Module Name] 从MongoDB读数据报错:java.lang.ArithmeticException: / by zero

4 participants