Create a `SQL script` using the public API

Highlighted
joshlk
Level 1
Create a `SQL script` using the public API
Jump to solution

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?

0 Kudos
1 Solution

Accepted Solutions
apichery Dataiker
Dataiker
Re: Create a `SQL script` using the public API
Jump to solution

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)

View solution in original post

0 Kudos
4 Replies
apichery Dataiker
Dataiker
Re: Create a `SQL script` using the public API
Jump to solution

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)

View solution in original post

0 Kudos
joshlk
Level 1
Re: Create a `SQL script` using the public API
Jump to solution
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
0 Kudos
apichery Dataiker
Dataiker
Re: Create a `SQL script` using the public API
Jump to solution
Have you tried to refresh your browser? Your browser might not be notified that the Flow has been updated.
0 Kudos
joshlk
Level 1
Re: Create a `SQL script` using the public API
Jump to solution
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.
0 Kudos
Labels (2)