简体   繁体   English

Azure 数据工厂复制活动 JSON 数据类型转换问题

[英]Azure Data Factory copy activity JSON data type conversion issue

I have an azure data factory pipeline for fetch the data from a third party API and store the data to the data-lake as.json format.我有一个 azure 数据工厂管道,用于从第三方 API 获取数据并将数据存储到数据湖 as.json 格式。 When i click the import schema, it shows the correct datatype format.当我单击导入模式时,它会显示正确的数据类型格式。 在此处输入图像描述

When I set the above mentioned data-lake as a source of data flow activity, the Int64 data type convert to boolean. I have checked the Microsoft documents and knew if the value is 0 or 1, it automatically convert to boolean. How can I avoid this data type conversion?当我将上述数据湖设置为数据流活动的来源时,Int64 数据类型转换为 boolean。我查看了 Microsoft 文档并知道该值是 0 还是 1,它会自动转换为 boolean。我怎么能避免这种数据类型转换?

在此处输入图像描述

First, verify if you have checked 'Infer drifted column types' to true under Source Settings.首先,验证您是否已将源设置下的“推断漂移列类型”选中为真。

Data Factory detects the data type as boolean if the values in the source column are only 1 or 0. This could be a potential bug.如果源列中的值仅为 1 或 0,数据工厂会将数据类型检测为 boolean。这可能是一个潜在的错误。

One way around is, since you are using Data Flow, Add derivations for the columns using a Case statement and derive 1 & 0 in output based on boolean value.一种解决方法是,由于您使用的是数据流,因此使用 Case 语句为列添加派生,并根据 boolean 值在 output 中派生 1 和 0。

The easiest way is that just reset the all schema to String, that means don't convert the data type in Source dataset.最简单的方法是将所有模式重置为字符串,这意味着不要转换源数据集中的数据类型。

For example, this my source dataset schema and data, all the values in setNum are 1 or 0:例如,这是我的源数据集模式和数据, setNum中的所有值都是 1 或 0: 在此处输入图像描述

Data Flow Source Projection, the data type of setNum first considered as Boolean. Data Flow Source Projection,setNum的数据类型首先考虑为Boolean。

在此处输入图像描述

Reset schema: all the data type will be string.重置模式:所有数据类型都将是字符串。

在此处输入图像描述

Then data factory will convert the data type in Sink level.然后数据工厂会在Sink层进行数据类型的转换。 It is similar with copy data from csv file.与从 csv 文件复制数据类似。

Update:更新:

You can first reset the schema to String.您可以先将架构重置为字符串。

Then using Derived Column to change/convert the data type as you want.然后使用派生列根据需要更改/转换数据类型。

Using bellow expressions:使用波纹管表达式:

toShort()
toString()
toShort()

在此处输入图像描述

This will solve the problem.这将解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM