Azure Data Factory: collectionReference not supported in dynamic TabularTranslator

TerrenceV 21 Reputation points
2020-11-05T14:28:34.143+00:00

Hi there,

The Copy Activity doesn't use the specified "collectionReference" value in the dynamic mapping.

Consider the payload:

{
  "skip": 0,
  "take": 2,
  "rows": [
    {
      "Column_one": 42,
      "Column_two": 42
    },
    {
      "Column_one": 33,
      "Column_two": 33
    }

  ]
}

When I use the interface the code generated is:

"translator": {
                        "type": "TabularTranslator",
                        "mappings": [
                            {
                                "source": {
                                    "path": "['Column_one']"
                                },
                                "sink": {
                                    "name": "Column_one",
                                    "type": "Int32"
                                }
                            },
                            {
                                "source": {
                                    "path": "['Column_two']"
                                },
                                "sink": {
                                    "name": "Column_two",
                                    "type": "Int32"
                                }
                            }
                        ],
                        "collectionReference": "$['rows']"
                    }

Then the resulting table in Azure SQL Server would be, more or les:
Column_one | Column_two
42 | 42
33 | 33

But when I provide the exact same code via "Add dynamic content" on the mapping page of the Copy Activity, it completely ignores the specified "collectionReference": "$['rows']", inserting exactly one row with only NULL values.

Can ADF please support the collectionReference parameter provided via the dynamic content on Mapping?

Thanks in advance.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,702 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saurabh Sharma 23,821 Reputation points Microsoft Employee
    2020-11-09T20:44:59.347+00:00

    @TerrenceV In order to make dynamic content work you need to cast the dynamic mapping content to JSON in the dynamic section. I have replicated your ADF pipeline and instead of adding the code directly to the dynamic editor I have created a variable and stored the translator code including collectionreference in the variable (@mapping). Later I have used the variable in dynamic mapping by casting to json using @json () function. Please refer to the below animation for the same.
    38416-adf-dyamicmapping.gif
    I have tested the ADF flow by moving the data from cosmos db to SQL table with dynamic mapping and it works as expected and I see two records in SQL table.
    38464-image.png

    Please try it out and let me know if you have any issues.

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. TerrenceV 21 Reputation points
    2020-11-10T10:01:45.62+00:00

    Oh wow, thanks for your elaborate answer Saurabh Sharma!

    I assumed that the response of my Lookup was a json, casting to json explicitly did the trick. I have a lookup which I used in this fashion:

    @activity('Get Mapping').output.firstRow.json_output

    Changing that to:

    @json (activity('Get Mapping').output.firstRow.json_output)

    Made it work like a charm. Thanks!


  2. Catameo, Fred (Taguig City 1634) 236 Reputation points
    2021-01-22T06:24:33.107+00:00

    The collectionReference seems to work but stops working when an unmapped json field is encountered from the source? The rest of the fields on the collectionReference become null valued.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.