Skip to content

Conversation

@shujingyang-db
Copy link
Contributor

@shujingyang-db shujingyang-db commented Aug 1, 2025

Update Salesforce Data Source Name to accurately reflect its scope.

Summary by CodeRabbit

Summary by CodeRabbit

  • Documentation

    • Clarified streaming write recovery behavior and potential duplicate records in Salesforce integration docs.
    • Updated all references to the Salesforce data source name to "pyspark.datasource.salesforce" in documentation and examples.
  • Refactor

    • Changed the Salesforce data source identifier to "pyspark.datasource.salesforce" across the application and tests.

@coderabbitai
Copy link

coderabbitai bot commented Aug 1, 2025

Walkthrough

The changes update the Salesforce data source integration by renaming its registration identifier from "salesforce" to "pyspark.datasource.salesforce" in the implementation, tests, and examples. The class docstring is expanded to clarify streaming write recovery semantics. No logic, error handling, or control flow is modified.

Changes

Cohort / File(s) Change Summary
Salesforce Data Source Implementation
pyspark_datasources/salesforce.py
Updated the class docstring of SalesforceDataSource to clarify streaming write recovery behavior. Changed the name() class method to return "pyspark.datasource.salesforce" instead of "salesforce".
Salesforce Data Source Tests
tests/test_data_sources.py
Updated test to use the new data source name "pyspark.datasource.salesforce" in registration and format strings. No changes to test logic or error handling.
Salesforce Example Usage
examples/salesforce_example.py
Changed all .format() calls for streaming writes from "salesforce" to "pyspark.datasource.salesforce". No other changes to example logic or flow.
Documentation Updates
README.md, docs/index.md
Updated references to the Salesforce data source name from "salesforce" to "pyspark.datasource.salesforce" in examples and data source tables. Adjusted description from "sink" to "datasource" in README.

Sequence Diagram(s)

Not applicable: changes are limited to identifier renaming and docstring clarification, with no new or modified control flow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Possibly related PRs

  • Add support for Salesforce sink  #18: Introduces the initial SalesforceDataSource implementation and example under the original name "salesforce", which is directly refined by the current changes.

Suggested reviewers

  • allisonwang-db

Poem

A hop and a skip, a new name in the air,
Salesforce’s format string gets a formal flair!
From “salesforce” to “pyspark.datasource.salesforce” we leap,
With docstrings more clear and examples to keep.
The code stays the same, but the label’s now neat—
A bunny’s delight in a naming retreat! 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac0e63f and 82554f4.

📒 Files selected for processing (4)
  • README.md (1 hunks)
  • examples/salesforce_example.py (10 hunks)
  • pyspark_datasources/salesforce.py (10 hunks)
  • tests/test_data_sources.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pyspark_datasources/salesforce.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • examples/salesforce_example.py
🧰 Additional context used
🪛 Ruff (0.12.2)
tests/test_data_sources.py

81-81: SalesforceDataSource may be undefined, or defined from star imports

(F405)

🔇 Additional comments (2)
tests/test_data_sources.py (2)

81-81: LGTM!

The assertion correctly validates the updated data source name from "salesforce" to the fully qualified "pyspark.datasource.salesforce".


94-94: LGTM!

The format string correctly uses the updated data source name "pyspark.datasource.salesforce" for testing batch write failure.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
pyspark_datasources/salesforce.py (1)

80-106: Code examples use the obsolete identifier – they no longer run

All illustrative snippets (Lines 80-106, 116-122, 129-138, 149-157, etc.) call .format("salesforce"). Update them to "salesforce-sink" (or document both if an alias is provided) so that copy-paste examples work.

Example fix:

-    .format("salesforce") \
+    .format("salesforce-sink") \

Neglecting this will create immediate runtime errors for users following the docs.

🧹 Nitpick comments (1)
pyspark_datasources/salesforce.py (1)

26-33: Docstring still states Name: salesforce – update to avoid confusion

The high-level documentation advertises the old identifier, which contradicts the new return value and will mislead readers.

-    Name: `salesforce`
+    Name: `salesforce-sink`

[Suggest keeping a note about the legacy identifier if you adopt the alias approach.]

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b424900 and 4cb8ac5.

📒 Files selected for processing (1)
  • pyspark_datasources/salesforce.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pyspark_datasources/salesforce.py (6)
pyspark_datasources/lance.py (2)
  • name (48-49)
  • LanceSink (10-56)
pyspark_datasources/huggingface.py (1)
  • name (58-59)
pyspark_datasources/fake.py (1)
  • name (113-114)
pyspark_datasources/kaggle.py (1)
  • name (63-64)
pyspark_datasources/opensky.py (1)
  • name (441-442)
pyspark_datasources/simplejson.py (1)
  • name (48-49)

Comment on lines 168 to 172
@classmethod
def name(cls) -> str:
"""Return the short name for this Salesforce sink."""
return "salesforce"
return "salesforce-sink"

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Changed short-name silently breaks existing jobs – add an alias or clear migration path
Every user script that previously did

df.writeStream.format("salesforce")…

will now fail to resolve the sink after this one-line change. Either provide an explicit backward-compatibility alias or publish a migration note in the module so that production pipelines do not break without warning.

Minimal code-side mitigation:

     @classmethod
     def name(cls) -> str:
         """Return the short name for this Salesforce sink."""
         return "salesforce-sink"

+    # -- Backward-compatibility -------------------------------------------
+    @classmethod
+    def aliases(cls) -> List[str]:
+        """
+        Alternative identifiers accepted by Spark.  
+        Retain the legacy name while users migrate.
+        """
+        return ["salesforce"]        # legacy identifier

If DataSource doesn’t support an aliases() hook, expose a second thin subclass that only overrides name() back to "salesforce" and register both classes.
Failing that, at the very least document the breaking change in the project’s CHANGELOG/README.

🤖 Prompt for AI Agents
In pyspark_datasources/salesforce.py around lines 168 to 172, the change of the
sink's short name from "salesforce" to "salesforce-sink" breaks backward
compatibility for existing jobs using "salesforce". To fix this, either add an
alias for "salesforce" that points to the new sink or create a second subclass
with the old name method returning "salesforce" and register both classes. If
neither is possible, document this breaking change clearly in the project's
CHANGELOG or README to inform users of the migration path.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
tests/test_data_sources.py (1)

4-4: Replace star-import with explicit symbols to remove Ruff F405 and improve clarity

from pyspark_datasources import * obfuscates where SalesforceDataSource, FakeDataSource, etc. come from and triggers Ruff’s F405 (“may be undefined from star import”).
Import the required classes explicitly instead.

-from pyspark_datasources import *
+from pyspark_datasources import (
+    GithubDataSource,
+    FakeDataSource,
+    KaggleDataSource,
+    OpenSkyDataSource,
+    SalesforceDataSource,
+)
🧹 Nitpick comments (1)
tests/test_data_sources.py (1)

79-93: Use pytest.raises for cleaner failure-expectation

The manual try/except … assert False block is verbose and can hide assertion mistakes.
pytest.raises conveys intent and short-circuits correctly.

-try:
-    # Try to use batch write - should fail since we only support streaming
-    df = spark.range(1).select(
-        lit("Test Company").alias("Name"),
-        lit("Technology").alias("Industry"),
-        lit(50000.0).alias("AnnualRevenue")
-    )
-
-    df.write.format("salesforce-sink").mode("append").save()
-    assert False, "Should have raised error - Salesforce DataSource only supports streaming"
-except Exception as e:
-    # This is expected - Salesforce DataSource only supports streaming writes
-    error_msg = str(e).lower()
-    # The error can be about unsupported mode or missing writer
-    assert "unsupported" in error_msg or "writer" in error_msg or "not implemented" in error_msg
+df = spark.range(1).select(
+    lit("Test Company").alias("Name"),
+    lit("Technology").alias("Industry"),
+    lit(50000.0).alias("AnnualRevenue")
+)
+
+with pytest.raises(Exception) as excinfo:
+    df.write.format("salesforce-sink").mode("append").save()
+
+msg = str(excinfo.value).lower()
+assert any(keyword in msg for keyword in ("unsupported", "writer", "not implemented"))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe64c98 and 9a4d099.

📒 Files selected for processing (2)
  • examples/salesforce_sink_example.py (5 hunks)
  • tests/test_data_sources.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • examples/salesforce_sink_example.py
🧰 Additional context used
🪛 Ruff (0.12.2)
tests/test_data_sources.py

74-74: SalesforceDataSource may be undefined, or defined from star imports

(F405)

🔇 Additional comments (1)
tests/test_data_sources.py (1)

74-74: Assertion updated correctly to the new sink identifier

The expectation now matches the renamed SalesforceDataSource.name() value ("salesforce-sink").
Looks good and keeps the test aligned with the production change.

# Write to Salesforce
query = account_data.writeStream \
.format("salesforce") \
.format("salesforce-sink") \
Copy link
Owner

Choose a reason for hiding this comment

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

To follow the naming convention for Scala data source (e.g org.spark.sql.<datasource>) can we use something like: pyspark.datasource.salesforce? Or we can just use sfdc (abbreviation for salesforce).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure I updated it to pyspark.datasource.salesforce

- Uses Salesforce username/password/security token authentication
- Supports batch writing with Salesforce Composite Tree API for efficient processing
- Implements exactly-once semantics through Spark's checkpoint mechanism
- If a streaming write job fails and is resumed from the checkpoint,
Copy link
Owner

Choose a reason for hiding this comment

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

Let's also update the Name above?

Copy link
Owner

Choose a reason for hiding this comment

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

Also the name in the example below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry for missing it! I updated all data source references

@shujingyang-db shujingyang-db changed the title Update Salesforce Sink Data Source Name Update Salesforce Data Source Name Aug 4, 2025
@allisonwang-db allisonwang-db merged commit 72885d1 into allisonwang-db:master Aug 7, 2025
5 checks passed
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.

2 participants