-
Notifications
You must be signed in to change notification settings - Fork 90
Add Python decorator example #84
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
base: main
Are you sure you want to change the base?
Conversation
| # Python decorator | ||
|
|
||
| This example shows how to package a **Python decorator–based job** so you can | ||
| call regular Python functions from a Databricks job with minimal boilerplate. |
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.
Can you make it more clear this is about Python support for DABs?
E.g. include a doc link in this paragraph.
| raise ValueError("Only keyword arguments are supported") | ||
|
|
||
| func_full_name = f"{self.func.__module__}:{self.func.__name__}" | ||
| parameters: list = [func_full_name] + [f"--{k}={v}" for k, v in kwargs.items()] |
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.
With string conversion + argparse turning it from a string back into the type that the function accepts, does this limit the function argument types in a particular way?
| from my_project.python_wheel_task import python_wheel_task | ||
|
|
||
|
|
||
| @python_wheel_task |
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.
For this mini-framework, should this not just be called @task? In a more extensive version, we could always decide to use subtypes like @task.sql or move to top-level task types like @sql_file_task.
|
|
||
| # Makes the value available to downstream tasks as | ||
| # '{{ tasks.<task_key>.values.message }}' | ||
| dbutils.jobs.taskValues.set("message", "Hello World") |
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.
Could you make this example do something Sparky, like spark.read.table("samples.nyctaxi.trips")?
Add an example of using Python decorators in Databricks jobs, see README.md for more information.