Copying 7 column table to 6 column table

Viewed 2888

I'm porting SQL Server Integration Services packages to Azure Data Factory.

I have two tables (Table 1 and Table 2) which live on different servers. One has seven columns, the other six. I followed the example at https://docs.microsoft.com/en-us/azure/data-factory/data-factory-map-columns

Table 1 DDL:

CREATE TABLE dbo.Table1
(
    zonename nvarchar(max), 
    propertyname nvarchar(max), 
    basePropertyid int, 
    dfp_ad_unit_id bigint, 
    MomentType nvarchar(200), 
    OperatingSystemName nvarchar(50)
)

Table 2 DDL

CREATE TABLE dbo.Table2
(
    ZoneID int IDENTITY, 
    ZoneName nvarchar(max), 
    propertyName nvarchar(max), 
    BasePropertyID int, 
    dfp_ad_unit_id bigint, 
    MomentType nvarchar(200), 
    OperatingSystemName nvarchar(50)
)

In ADF, I define Table 1 as:

{
  "$schema": "http://datafactories.schema.management.azure.com/schemas/2015-09-01/Microsoft.DataFactory.Table.json",
  "name": "Table1",
  "properties": {
    "type": "AzureSqlTable",
    "linkedServiceName": "PlatformX",
    "structure": [
      { "name": "zonename" },
      { "name": "propertyname" },
      { "name": "basePropertyid" },
      { "name": "dfp_ad_unit_id" },
      { "name": "MomentType" },
      { "name": "OperatingSystemName" }
    ],
    "external": true,
    "typeProperties": {
      "tableName": "Platform.Zone"
    },
    "availability": {
      "frequency": "Day",
      "interval": 1
    }
  }
}

In ADF I define Table 2 as:

{
  "$schema": "http://datafactories.schema.management.azure.com/schemas/2015-09-01/Microsoft.DataFactory.Table.json",
  "name": "Table2",
  "properties": {
    "type": "SqlServerTable",
    "linkedServiceName": "BrixDW",
    "structure": [
      { "name": "ZoneID" },
      { "name": "ZoneName" },
      { "name": "propertyName" },
      { "name": "BasePropertyID" },
      { "name": "dfp_ad_unit_id" },
      { "name": "MomentType" },
      { "name": "OperatingSystemName" }
    ],
    "external": true,
    "typeProperties": {
      "tableName": "staging.DimZone"
    },
    "availability": {
      "frequency": "Day",
      "interval": 1
    }
  }
}

As you can see, Table2 has an identity column, which will automatically populated.

This should be a simple Copy activity:

{
  "$schema": "http://datafactories.schema.management.azure.com/schemas/2015-09-01/Microsoft.DataFactory.Pipeline.json",
  "name": "Copy_Table1_to_Table2",
  "properties": {
    "description": "Copy_Table1_to_Table2",
    "activities": [
      {
        "name": "Copy_Table1_to_Table2",
        "type": "Copy",
        "inputs": [
          { "name": "Table1" }
        ],
        "outputs": [
          {
            "name": "Table2"
          }
        ],
        "typeProperties": {
          "source": {
            "type": "SqlSource",
            "sqlReaderQuery": "select * from dbo.Table1"
          },
          "sink": {
            "type": "SqlSink"
          },
          "translator": {
            "type": "TabularTranslator",
            "columnMappings": "zonename: ZoneName, propertyname: propertyName, basePropertyid: BasePropertyID, dfp_ad_unit_id: dfp_ad_unit_id, MomentType: MomentType, OperatingSystemName: OperatingSystemName"
          }
        },
        "policy": {
          "concurrency": 1,
          "executionPriorityOrder": "OldestFirst",
          "retry": 3,
          "timeout": "01:00:00"
        },
        "scheduler": {
          "frequency": "Day",
          "interval": 1
        }
      }
    ],
    "start": "2017-07-23T00:00:00Z",
    "end": "2020-07-19T00:00:00Z"
  }
}

I figured by not mapping ZoneID, it would just be ignored. But ADF is giving me the following error.

Copy activity encountered a user error: GatewayNodeName=APP1250S,ErrorCode=UserErrorInvalidColumnMappingColumnCountMismatch,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Invalid column mapping provided to copy activity: 'zonename: ZoneName, propertyname: propertyName, basePropertyid: BasePropertyID, dfp_ad_unit_id: dfp_ad_unit_id, MomentType: MomentType, OperatingSystemName: OperatingSystemName', Detailed message: Different column count between target structure and column mapping. Target column count:7, Column mapping count:6. Check column mapping in table definition.,Source=Microsoft.DataTransfer.Common,'

In a nutshell I'm trying to copy a 7 column table to a 6 column table and Data Factory doesn't like it. How can I accomplish this task?

4 Answers

I realize this is an old question, but I ran into this issue just now. My problem was that I initially generated the destination/sink table, created a pipeline, and then added a column.

Despite clearing and reimporting the schemas, whenever triggering the pipeline, it would throw the above error. I made sure the new column (which has a default on it) was deselected in the mappings, so it would only use the default value. The error was still thrown.

The only way I managed to get things to work was by completely recreating the pipelines from scratch. It's almost as if somewhere in the meta data, the old mappings are retained.

I had the exact same issue and I solved it by going into the azure dataset and removing the identity column. Then making sure I had the same number of columns in my source and target(sink). After doing this the copy will add the records and the identity in the table will just work as expected. I did not have to modify the physical table in SQL only the dataset for the table in azure.

Related