Skip to content

Commit

Permalink
Fix/delta merge builder instance check for connect + util fix (#130)
Browse files Browse the repository at this point in the history
<!--- Provide a general summary of your changes in the Title above -->

## Description
<!--- Describe your changes in detail -->
Additonal fixes for #101 and #102

## Related Issue
<!--- This project only accepts pull requests related to open issues -->
<!--- If suggesting a new feature or change, please discuss it in an
issue first -->
<!--- If fixing a bug, there should be an issue describing it with steps
to reproduce -->
<!--- Please link to the issue here: -->
#101, #102

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Screenshots (if appropriate):

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all
the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)

## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have read the **CONTRIBUTING** document.
- [ ] I have added tests to cover my changes.
- [x] All new and existing tests passed.

---------

Co-authored-by: Danny Meijer <10511979+dannymeijer@users.noreply.github.com>
  • Loading branch information
dannymeijer and dannymeijer authored Nov 26, 2024
1 parent ea2d15e commit c72f381
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/koheesio/spark/utils/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def is_remote_session(spark: Optional[SparkSession] = None) -> bool:
result = False

if (_spark := spark or get_active_session()) and check_if_pyspark_connect_is_supported():
result = True if _spark.conf.get("spark.remote", None) else False # type: ignore
# result = True if _spark.conf.get("spark.remote", None) else False # type: ignore
from pyspark.sql.connect.session import SparkSession as ConnectSparkSession

result = isinstance(_spark, ConnectSparkSession)

return result
7 changes: 5 additions & 2 deletions src/koheesio/spark/writers/delta/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ def _validate_params(cls, params: dict) -> dict:
clause = merge_conf.get("clause")
if clause not in valid_clauses:
raise ValueError(f"Invalid merge clause '{clause}' provided")
elif not isinstance(merge_builder, DeltaMergeBuilder):
elif (
not isinstance(merge_builder, DeltaMergeBuilder)
or not type(merge_builder).__name__ == "DeltaMergeBuilder"
):
raise ValueError("merge_builder must be a list or merge clauses or a DeltaMergeBuilder instance")

return params
Expand Down Expand Up @@ -378,7 +381,7 @@ def execute(self) -> Writer.Output:
if self.table.create_if_not_exists and not self.table.exists:
_writer = _writer.options(**self.table.default_create_properties)

if isinstance(_writer, DeltaMergeBuilder):
if isinstance(_writer, DeltaMergeBuilder) or type(_writer).__name__ == "DeltaMergeBuilder":
_writer.execute()
else:
if options := self.params:
Expand Down

0 comments on commit c72f381

Please sign in to comment.