Create a `SQL script` using the public API
![joshlk](https://us.v-cdn.net/6038231/uploads/Dataiku/nAvatar3.png)
joshlk
Registered Posts: 7 ✭✭✭✭
You can create a "SQL query" recipe with the public API using the `SQLQueryRecipeCreator` object. However, there isn't an equivalent object for a "SQL script" recipe. How can I create a SQL script recipe using the public API?
Best Answer
-
There is no specific API to create an SQL Script recipe, but you can use the generic SingleOutputRecipeCreator to do it.
Here is an example to create such a recipe:
from dataikuapi.dss.recipe import SingleOutputRecipeCreator
# Create an SQL script recipe
builder = SingleOutputRecipeCreator('sql_script', "my_sql_script_recipe_name", project)
builder = builder.with_input("my_input_ds")
builder = builder.with_output("my_output_ds")
recipe = builder.build()
# Update the SQL script recipe to set its script
recipe_def = recipe.get_definition_and_payload()
recipe_def.set_payload('CREATE TABLE ...')
recipe.set_definition_and_payload(recipe_def)
Answers
-
Hi apichery, thanks for the above. The above Python executes fine but the node and dataset doesn't appear in the Dataiku flow. Not sure why not. No error from Python or Dataiku. Im running Version 4.3.1
-
Have you tried to refresh your browser? Your browser might not be notified that the Flow has been updated.
-
Yep - it doesn't help. What's interesting is that if I then try to create a node with SQLQueryRecipeCreator with the same output, the first recipe created with SingleOutputRecipeCreator suddenly appears.