Change SQL recipe code with dataikuapi

Options
Ioannis
Ioannis Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 28 ✭✭✭✭✭
edited July 16 in Using Dataiku

I want to perform changes in the code of my SQL recipes in a project. How can I access the code?

import dataiku
import dataikuapi

client = dataiku.api_client()
project = client.get_project("project")

recipes = project.list_recipes()

for recipe in recipes:
    recipe_code = recipe.get_code()   # can't figure out this step
    alter_code(recipe_code)​

Best Answer

  • Alexandru
    Alexandru Dataiker, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 1,209 Dataiker
    edited July 17 Answer ✓
    Options

    Hi @imanousar
    ,

    For SQL recipe you need to use get_payload() and set_payload() instead of get_code(), which only works for R/Python/Bash recipes and not SQL.

    client = dataiku.api_client()
    current_project = client.get_project(dataiku.default_project_key())
    current_recipe = current_project.get_recipe("compute_outnow")
    recipe_settings = current_recipe.get_settings()
    code = recipe_settings.get_payload()
    final_code = 'SELECT abc,edf FROM "TESTING_2_postgres_out"'
    recipe_settings.set_payload(final_code)
    recipe_settings.save()
Setup Info
    Tags
      Help me…