Forum Discussion
Fabric Notebook ExitValue how to select specific values
- 6 months ago
Hi Ka13 ,
Yes we can read this query in a copy activity. First convert this select query to json
import jsonfrom notebookutils import notebooknb_result = {"select_query": select_query}notebook.exit(json.dumps(nb_result))Then in pipeline add notebook activity and connect to copy data. In the dynamic content of copy data, add this json expression.
@json(activity('Notebook1').output.exitValue).select_queryThis works.
If this post helps, please accept this as a solution. Appreciate your kudos.
Thanks,
Pallavi_r
Thanks Pallavi, in Details if we have one more field of columns like - id,name,city,country. And to extract columns.
can you please suggest.
Hi Ka13 ,
So here we need frame a dynamic sql. in the previous one we had parsed the string into json. Now we have to retrieve all the column names into string literal in a python list.
|
details = parsed["parent1"]["Details"]
schema = details["schema"]
table = details["table"]
columns = details["columns"]
|
|
getcol = [
f"CAST({col} AS STRING) AS {col}"
for col in columns
]
|
Then to create a dynamic sql expression, we need to merge all the elements from the above list into a single comma separated string using ",".join(column)
|
select_query = f"""
SELECT
{", ".join(getcol)}
FROM {schema}.{table}
"""
print(select_query)
|
working code below:
If this post helps, please accept this as a solution. Appreciate your kudos.
Thanks,
Pallavi
- Ka137 months agoHelper II
Thanks Pallavi, can we pass this select query formed to the next activity ( Copy Activity) ? , to execute the query. Will test the above and let you know if any questions.
- Ka137 months agoHelper II
Hi Pallavi, can we pass this formed select query in next Copy Activity?
- pallavi_r6 months agoSuper User
Hi Ka13 ,
Yes we can read this query in a copy activity. First convert this select query to json
import jsonfrom notebookutils import notebooknb_result = {"select_query": select_query}notebook.exit(json.dumps(nb_result))Then in pipeline add notebook activity and connect to copy data. In the dynamic content of copy data, add this json expression.
@json(activity('Notebook1').output.exitValue).select_queryThis works.
If this post helps, please accept this as a solution. Appreciate your kudos.
Thanks,
Pallavi_r
- Ka136 months agoHelper II
Hi Pallavi, can we pass this formed select query in next Copy Activity?