3

I'm trying to drive the columnMapping property from a database configuration table. My first activity in the pipeline pulls in the rows from the config table. My copy activity source is a Json file in Azure blob storage and my sink is an Azure SQL database.

In copy activity I'm setting the mapping using the dynamic content window. The code looks like this:

"translator": {
    "value": "@json(activity('Lookup1').output.value[0].ColumnMapping)",
     "type": "Expression"
 }

My question is, what should the value of activity('Lookup1').output.value[0].ColumnMapping look like?

I've tried several different json formats but the copy activity always seems to ignore it.

For example, I've tried:

{
    "type": "TabularTranslator",
    "columnMappings": {
      "view.url": "url"
    }
}

and:

"columnMappings": {
    "view.url": "url"
}

and:

{
  "view.url": "url"
}

In this example, view.url is the name of the column in the JSON source, and url is the name of the column in my destination table in Azure SQL database.

3 Answers 3

2

The issue is due to the dot (.) sign in your column name.

  1. To use column mapping, you should also specify structure in your source and sink dataset.
  2. For your source dataset, you need specify your format correctly. And since your column name has dot, you need specify the json path as following. enter image description here
  3. You could use ADF UI to setup a copy for a single file first to get the related format, structure and column mapping format. Then change it to lookup.

And as my understanding, your first format should be the right format. If it is already in json format, then you may not need use "json" function in your expression.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! JSONPath expression was indeed where my issue was. Unfortunately I now realize that the JSONPath expressions do not support the "dynamic content" option, so I do not think I can drive that from my configuration database :(
For JSON path not support dynamic content, I think that could be an UI issue. You could have a try with json code directly.
@FangLiu It is not a UI issue. The product has a bug where the expression language is ignored for schema mapping column names.
2

There seems to be a disconnect between the question and the answer, so I'll hopefully provide a more straightforward answer.

When setting this up, you should have a source dataset with dynamic mapping. The sink doesn't require one, as we're going to specify it in the mapping.

Within the copy activity, format the dynamic json like the following:

    {
      "structure": [
        {
          "name": "Address Number"
        },
        {
          "name": "Payment ID"
        },
        {
          "name": "Document Number"
        },
          ...
          ...
      ]
    }

You would then specify your dynamic mapping like this:

    {
      "translator": {
        "type": "TabularTranslator",
        "mappings": [
          {
            "source": {
              "name": "Address Number",
              "type": "Int32"
            },
            "sink": {
              "name": "address_number"
            }
          },
          {
            "source": {
              "name": "Payment ID",
              "type": "Int64"
            },
            "sink": {
              "name": "payment_id"
            }
          },
          {
            "source": {
              "name": "Document Number",
              "type": "Int32"
            },
            "sink": {
              "name": "document_number"
            }
          },
          ...
          ...
        ]
      }
    }

Assuming these were set in separate variables, you would want to send the source as a string, and the mapping as json:

source: @string(json(variables('str_dyn_structure')).structure)

mapping: @json(variables('str_dyn_translator')).translator

2 Comments

@VladDrak Please could you provide an example of the complete JSON block for the copy activity? My understanding from this documentation is that the structure section should be part of the definition of the dataset, but I can't see any way to add it dynamically.
@Jon.Mozley you need to save translator block in variable and put in dynamic content as the last line shown in answer @json(variables('str_dyn_translator')).translator. Other things are not required. In my case, I am setting mapping variable from database.
0

VladDrak - You could skip the source dynamic definition by building dynamic mapping like this:

{
  "translator": {
    "type": "TabularTranslator",
    "mappings": [
      {
        "source": {
          "type": "String",
          "ordinal": "1"
        },
        "sink": {
          "name": "dateOfActivity",
          "type": "String"
        }
      },
      {
        "source": {
          "type": "String",
          "ordinal": "2"
        },
        "sink": {
          "name": "CampaignID",
          "type": "String"
        }
      }
    ]
  }
}

2 Comments

It's hard to tell if you're asking a question or proposing a different answer :-) If it's an answer, you might want to rephrase the above, so it doesn't get mistaken for a question and deleted. Otherwise, please open a new thread, see How to Ask.
It was a proposed solution that saves you the bother of the dynamic schema definition on the source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.