In the given example https://www.dataiku.com/learn/guide/code/python/use-python-sql.html it is assumed that the user knows the dataset (sfo_prepared) he is operating on.
How can we make the plugin more generic and obtain the name of the dataset from the flow? The recipe should automatically pick up the dataset name when it is connected to a dataset.
# -*- coding: utf-8 -*-
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
# Import the class that allows us to execute SQL on the Studio connections
from dataiku.core.sql import SQLExecutor2
# Get a handle on the input dataset
sfo_prepared = dataiku.Dataset("sfo_prepared")
# We create an executor. We pass to it the dataset instance. This way, the
# executor knows which SQL database should be targeted
executor = SQLExecutor2(dataset=sfo_prepared)
# Get the 5 most frequent manufacturers by total landing count
# (over the whole period)
mf_manufacturers = executor.query_to_df(
select "Aircraft Manufacturer" as manufacturer,
sum("Landing Count") as count
group by "Aircraft Manufacturer"
order by count desc limit 5