You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline映射:CSV导入时为UserName字段设置静态值

Got it, let's figure out how to assign a fixed static value to the UserName field in your target JSON when importing from CSV via Azure Pipeline. Based on your input dataset details, here are two reliable approaches you can implement right away:

1. Use Copy Activity (Simplest for Basic Mapping)

Since your source is an Azure Blob CSV dataset (Input_dat) and target is JSON, the Copy Activity is the quickest way to handle this static value assignment without extra data flow overhead.

Step-by-Step Setup:

  • Add a Copy Activity to your pipeline, set the source to your Input_dat dataset, and configure your target JSON dataset.
  • Navigate to the Mapping tab of the Copy Activity:
    • For fields like ServerName, DTVer, and Ver, keep the default 1:1 mapping between source CSV columns and target JSON fields.
    • For the UserName field:
      1. Click Add > Derived Column (or directly edit the existing UserName mapping if it's already listed).
      2. In the derived column configuration:
        • Set the Column name to UserName (matching your target JSON field name).
        • For the Expression, enter your fixed static value wrapped in single quotes, e.g., 'your-static-username-here' (this tells Azure Data Factory to treat it as a literal string, not a column reference).
      3. Ensure this derived column is mapped to the target JSON's UserName field.

Example Mapping JSON Snippet:

If you prefer editing the pipeline JSON directly, here's what the translator section would look like:

"translator": {
    "type": "TabularTranslator",
    "mappings": [
        {
            "source": { "name": "ServerName" },
            "sink": { "name": "ServerName" }
        },
        {
            "source": { "name": "DTVer" },
            "sink": { "name": "DTVer" }
        },
        {
            "source": { "name": "Ver" },
            "sink": { "name": "Ver" }
        },
        {
            "source": {
                "type": "Expression",
                "value": "'static-user-001'"
            },
            "sink": { "name": "UserName" }
        }
    ]
}

2. Use Mapping Data Flow (For Flexible, Scalable Transformations)

If you anticipate needing additional data transformations later, Mapping Data Flow is a better fit. It gives you more control over data manipulation:

Step-by-Step Setup:

  1. Add a Mapping Data Flow activity to your pipeline.
  2. Inside the data flow:
    • Add a Source transformation, connect it to your Input_dat dataset.
    • Add a Derived Column transformation:
      • Create a new column (or overwrite the existing UserName column from the source) and set the expression to your static value, e.g., 'fixed-username'.
    • Add a Sink transformation, connect it to your target JSON dataset, and verify all fields (including the static UserName) are correctly mapped.

Key Notes:

  • Make sure your target JSON dataset's structure includes the UserName field with a String type (matching your source dataset's UserName type).
  • If your source CSV already has a UserName column, be sure to overwrite it with the static value in your mapping/derived column step—otherwise, the source value will take precedence.
  • Always test the pipeline with a small sample CSV to confirm the static value is correctly populated in the target JSON.

内容的提问来源于stack exchange,提问作者user2347519

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:59:31