DSSRecipeDefinitionAndPayload set recipe output

Tomas
Tomas Registered, Neuron 2022 Posts: 121 ✭✭✭✭✭

Hi,

I would like to add a new folder to the recipe's output, bases on the documentaion there is just a get method for recipe inputs/outputs.

Is there any way to set it?

Thanks

classdataikuapi.dss.recipe.DSSRecipeDefinitionAndPayload(data)

Definition for a recipe, that is, the recipe definition itself and its payload

get_recipe_raw_definition()

get_recipe_inputs()

get_recipe_outputs()

get_recipe_params()

get_payload()

get_json_payload()

set_payload(payload)

set_json_payload(payload)

Best Answer

Answers

  • Tomas
    Tomas Registered, Neuron 2022 Posts: 121 ✭✭✭✭✭
    Yes I know, but can you give me an example? I dont know how to change inside the definition object the inputs/outputs.

    folder = prj.get_managed_folder('qFs1aIyX')
    recipe=dataikuapi.dss.recipe.DSSRecipe(client, 'S3_IMPORT', 'compute_process_s3')
    df=recipe.get_definition_and_payload()
    ##########################################
    # Here I want to add the folder as a recipe output:
    df.add_recipe_input?( folder )
    ##########################################

    recipe.set_definition_and_payload(df)

    Thanks!
  • Alex_Combessie
    Alex_Combessie Alpha Tester, Dataiker Alumni Posts: 539 ✭✭✭✭✭✭✭✭✭
    Hi,
    You need to get the result of get_definition_and_payload() and modify it. It is a Python dictionary which contains all elements describing the recipe and its outputs. Then once modified, pass it back to set_definition_and_payload().
    Cheers,
    Alex
  • Tomas
    Tomas Registered, Neuron 2022 Posts: 121 ✭✭✭✭✭
    Hi Tomas,
    Sorry about this, I forgot one step: you need to modify the result of get_recipe_raw_definition() on the DSSRecipeDefinitionAndPayload instance in order to then use set_definition_and_payload(). So if I put it all back together, you will need:

    import dataiku
    import dataikuapi
    client = dataiku.api_client()
    project = client.get_project(dataiku.default_project_key())
    recipe = dataikuapi.dss.recipe.DSSRecipe(client, 'SANDBOX', 'compute_something')
    definition_and_payload = recipe.get_definition_and_payload()
    print(definition_and_payload.get_recipe_raw_definition())
    # Here you modify the raw definition in-place as a Python dictionary (example below)
    definition_and_payload.get_recipe_raw_definition()["outputs"] = {u'main': {u'items': [{u'appendMode': False,
    u'ref': u'JZLLhzOn'}]}}
    recipe.set_definition_and_payload(definition_and_payload)
    # Now you will get a message telling you that the recipe has been updated. You can verify with:
    print(recipe.get_definition_and_payload().get_recipe_raw_definition())
  • Tomas
    Tomas Registered, Neuron 2022 Posts: 121 ✭✭✭✭✭
    Thanks, that worked!
Setup Info
    Tags
      Help me…