-
Notifications
You must be signed in to change notification settings - Fork 234
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
Convert df to pyspark DataFrame if it is pandas before writing #469
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6f28e2e
Convert df to pyspark DataFrame if it is pandas before writing
dbeatty10 1afde7a
Changelog entry
dbeatty10 68c6aac
Use `overwriteSchema` option like dbt-databricks
dbeatty10 82062d4
Upstream `py_write_table` macro from dbt-databricks
dbeatty10 1afc312
Convert df to a PySpark DataFrame if it's a Pandas-on-Spark DataFrame…
dbeatty10 09388ff
Separate conversion logic from import logic
dbeatty10 dca2b40
Raise exception if not able to convert to a Spark DataFrame
dbeatty10 cbf11e9
Prefer pandas → pandas-on-Spark → Spark over direct pandas → Spark
dbeatty10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: Under the Hood | ||
body: Enable Pandas and Pandas-on-Spark DataFrames for dbt python models | ||
time: 2022-09-16T12:57:06.846297-06:00 | ||
custom: | ||
Author: chamini2 dbeatty10 | ||
Issue: "468" | ||
PR: "469" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the risk of making this even more complex than it needs to be — I believe
pyspark.pandas
was introduced in Spark v3.2: https://www.databricks.com/blog/2021/10/04/pandas-api-on-upcoming-apache-spark-3-2.htmlIt won't be available in earlier versions. (The same functionality was available via the
koalas
package, which was the old codename for pandas-on-PySpark.)I don't want us to get too-too clever with this logic, though! Could just look like a
try/except
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what will happen currently if the input is a pandas-on-Spark DataFrame but
pyspark.pandas
is not available:msg = f"{type(df)} is not a supported type for dbt Python materialization"
What I believe will happen if the input is a pandas DataFrame but
pyspark.pandas
is not available:df = spark.createDataFrame(df)
We can add in an attempt to
import databricks.koalas
so we are covering as many bases as possible. If we go that route, is there an environment we could test it out on?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could spin up a Databricks cluster running an older Spark version (v3.1). This is also what will be running inside Dataproc — the latest Apache Spark release it supports is v3.1.