Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[SPARK-52373] Add CRC32 struct #191

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

Closed
wants to merge 1 commit into from

Conversation

dongjoon-hyun
Copy link
Member

@dongjoon-hyun dongjoon-hyun commented Jun 1, 2025

What changes were proposed in this pull request?

This PR aims to add CRC32 struct.

Why are the changes needed?

Apache Spark Connect requires CRC32 checksum to implement APIs like addArtifacts.

Does this PR introduce any user-facing change?

No behavior change.

How was this patch tested?

Pass the CIs.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Gemini 2.5 Flash. Ask to write ASF-licensed CRC32 Swift code.

  • CRC32.swift

I verified it manually and wrote test suite, CRC32Tests.swift.

@Test
func testLongChecksum() async throws {
let str = String(repeating: "Apache Spark Connect Client for Swift", count: 1000)
#expect(CRC32.checksum(string: str, encoding: .ascii) == 1_985_943_888)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is consistent with JDK CRC32.

jshell> var c = new java.util.zip.CRC32();
jshell> c.update("Apache Spark Connect Client for Swift".repeat(1000).getBytes())
jshell> c.getValue()
$9 ==> 1985943888

@Test
func testChecksum() async throws {
let str = "Apache Spark Connect Client for Swift"
#expect(CRC32.checksum(string: str, encoding: .ascii) == 2_736_908_745)
Copy link
Member Author

Choose a reason for hiding this comment

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

This is consistent with JDK CRC32.

jshell> var c = new java.util.zip.CRC32();
jshell> c.update("Apache Spark Connect Client for Swift".getBytes())
jshell> c.getValue()
$3 ==> 2736908745

@dongjoon-hyun
Copy link
Member Author

cc @viirya and @peter-toth

@dongjoon-hyun
Copy link
Member Author

I'll merge this to move forward~

@dongjoon-hyun dongjoon-hyun deleted the SPARK-52373 branch June 1, 2025 01:30
Copy link
Member

@viirya viirya left a comment

Choose a reason for hiding this comment

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

I don't look into the crc32 code in details. But if it is verified manually, it should be okay

@dongjoon-hyun
Copy link
Member Author

Thank you.

Copy link

@peter-toth peter-toth left a comment

Choose a reason for hiding this comment

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

Looks good, but it's a bit unusual that we need to reimplement the common CRC32 algorithm.

@dongjoon-hyun
Copy link
Member Author

Thank you, @peter-toth . Yes, indeed. I expected Swift Foundation framework has it, but it didn't.

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.

3 participants