问题
I am copying data from a source, an API, and copying it into Azure SQL DB. But in one of the column I am getting Json objects.
Any way i can use dynamic parameters (either through Pre-copy script or something else) in the pipeline to only take value of a particular tag from those json objects so that i can have only that value in the column. Only constraint is that I can't change the sink. It has to be Azure SQL DB.
Json object I am getting: [{"self":"https://xxxxxxxx.jira.com/rest/api/2/customFieldOption/11903","value":"Yes","id":"11903"}]
And I want only 'value' tag response not the complete json.
回答1:
The pre-copy script is a script that you run against the database before copying new data in, not to modify the data you are ingesting.
What you can do if you cannot change the sink, is store the data in a different table, using a varchar field for the json. Then add another activity in your pipeline, where you take this data and store it in the actual table. In this second activity, you can use t-sql statements to modify the sqlQuery of the copy activity to extract the value you want from it.
This will be useful when designing the query: https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-2017
Hope this helped! :)
PS: in the second activity, use this to get the "value"
select JSON_VALUE(fieldWhereYouStoredTheJson, '$[0].value') as jsonValue from temporaryTable
来源:https://stackoverflow.com/questions/50402950/pre-copy-script-in-data-factory-or-on-the-fly-data-processing