Database schema name setting in dataset

Solved!
Meirkhan
Level 3
Database schema name setting in dataset

Hello!

I want to set database schema name programmatically for specific dataset.


P.S. I am aware that I can set default schema in global connection settings, but I need to do it for some specific datasets only

0 Kudos
1 Solution
VitaliyD
Dataiker

Hi @Meirkhan ,

To update the schema of the dataset programmatically you can use Dataiku API. Please refer to the code snippet below (you can run it Python notebook): 

import dataiku, json
from dataiku import pandasutils as pdu
import pandas as pd

client = dataiku.api_client()
proj_key = dataiku.default_project_key()
project = client.get_project(proj_key)
dataset = project.get_dataset('dataset_name')
dataset_settings = dataset.get_settings()
dataset_settings.settings["params"]["schema"] = 'new_schema'
dataset_settings.save()

 

Hope this helps. 

Best, 

Vitaliy

View solution in original post

0 Kudos
5 Replies
VitaliyD
Dataiker

Hi @Meirkhan ,

To update the schema of the dataset programmatically you can use Dataiku API. Please refer to the code snippet below (you can run it Python notebook): 

import dataiku, json
from dataiku import pandasutils as pdu
import pandas as pd

client = dataiku.api_client()
proj_key = dataiku.default_project_key()
project = client.get_project(proj_key)
dataset = project.get_dataset('dataset_name')
dataset_settings = dataset.get_settings()
dataset_settings.settings["params"]["schema"] = 'new_schema'
dataset_settings.save()

 

Hope this helps. 

Best, 

Vitaliy

0 Kudos
Meirkhan
Level 3
Author

Thanks!

I was trying to do get_settings() before, but it was not working.

Now I get why - I am using dss version 7. And one has to use get_definition() instead.

 

 

0 Kudos
jvijayakumar2
Level 3

Do we have an R equivalent of this snippet?

0 Kudos
VitaliyD
Dataiker

Hi, there is no R equivalent available. However, if you want to stay within the R, you can use "reticulate" to execute python. Here is the full documentation of how you can use "reticulate": https://rstudio.github.io/reticulate/articles/calling_python.html

Best,

Vitaliy

jvijayakumar2
Level 3

Thanks @VitaliyD !

0 Kudos