0
votes

I'm using Azure Data Factory to copy data from a source folder (Azure Blob) that has multiple folders inside it (and each one of those folders has a year as it's name, and inside the folders are the Excel spreadsheets with the data) to a SQL Server table. I want to iterate through the folders, select the folder name, and insert the name into a column in a table, so for each data read inside the files in the folder, the folder name where this data is will be in the table, like this:

Data 1   |Data 2   |Year
------------------------
A        |abc      |2020
B        |def      |2020
C        |ghi      |2021
D        |jkl      |2022
E        |lmn      |2023

My pipeline is like this: 1

I have a Get Metadata activity called Get Metadata1 2 pointing to the folders, and after that a ForEach to iterate through the folders 3 with two activities: one "Set variable" activity setting a variable named FolderYear 4 with @item().name as value (to select the folder name) and a Copy activity which creates a additional column 5 into the dataset named Year using the variable.

I'm trying to map the additional Year column to a column in the table, but when I debug the pipeline, the following error appears:

{ "errorCode": "2200", "message": "Mixed properties are used to reference 'source' columns/fields in copy activity mapping. Please only choose one of the three properties 'name', 'path' and 'ordinal'. The problematic mapping setting is 'name': 'Year', 'path': '','ordinal': ''. ", "failureType": "UserError", "target": "Copy data1", "details": [] }

It's possible to insert the folder name which I'm currently iterating into a database column?

1
There is no need to use "Set variable" activity. - Joseph Xu

1 Answers

0
votes

I've made a same test and copied the data(include the folder name) into a SQL table successfully.
I have two folders in the container and each folder contains one cvs file for test. enter image description here

The previous settings are the same as you.
Inside the ForEach activity, I use the Additional columns to add the folder name to the datasource.

enter image description here

After copied into a SQL table, the results show as follow: enter image description here


Update:
My file structure is as follows: enter image description here You can use expression @concat('FolderA/FolderB/',item().name): enter image description here