问题
I copy the following csv file to a data flow in ADF.
The column Data has json format, but it is considered string. I want to flatten Data column into individual rows. I tried the flatten transformation, it did not work as Data column is not json. How do I deal with it? I also tried split expression, and it did not work either. Thank you
回答1:
Just from your screenshot, We can find that :
- The data in
Data
are not JSON format. - Data most look like an Array.
- The 'array' has 9 elements.
Me must consider it as the "Array" then we could using Data Flow Derived Column to flatten the Data. Please ref my steps bellow:
Source data:
Derived Column expressions and settings:
The expression to make data as string and using index to get the value:
Data 1: split(substring(Data, 2, length(Data)-2), ",")[1]
Data 2: split(substring(Data, 2, length(Data)-2), ",")[2]
Data 3: split(substring(Data, 2, length(Data)-2), ",")[3]
Data 4: split(substring(Data, 2, length(Data)-2), ",")[4]
Data 5: split(substring(Data, 2, length(Data)-2), ",")[5]
Data 6: split(substring(Data, 2, length(Data)-2), ",")[6]
Data 7: split(substring(Data, 2, length(Data)-2), ",")[7]
Data 8: split(substring(Data, 2, length(Data)-2), ",")[8]
Data 9: split(substring(Data, 2, length(Data)-2), ",")[9]
Derived Column output:
If the Data
are standard JSON format, we need convert the string to JSON first, and then use the key to get the value.
HTH.
来源:https://stackoverflow.com/questions/65741675/split-a-json-string-column-or-flatten-transformation-in-data-flow-adf