cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Define SQL table name using Python

alm
New Contributor III

I want to control which schema a notebook writes. I want it to depend on the user that runs the notebook.

For now, the scope is to suport languages Python and SQL. I have written a Python function, `get_path`, that returns the full path of the destination. 

My idea was to create a SQL function that wraps the Python function.

```

create or replace function GETPATH(catalog_name string, schema_name string, table_name string)
returns string
language python
as $$
from path import get_path
return get_path(catalog_name, schema_name, table_name)
$$
```
Surprisingly, or not so much so, this doesn't work.
 
Any idea how to implement something like this? It might be, that it should handled completely different.
 
If I can set the catalog and schema of notebooks in a folder somewhere else so that the notebook only defines the table name, it would also solve the problem.   

  

1 REPLY 1

alm
New Contributor III

What is unclear to you? I need to create a table that depend on the username of the current user

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group