我目前收到的csv文件格式如下:
Col1, Col2, Col3, Col4
Header1, , ,
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
Header2, , ,
Val1, Val2, Val3, Val4
Header3, , ,
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
每个标题的行数可以不同,标题可以包含任何单词。
预期结果应为以下之一:选项1:将标题保存到1个文件中的附加列文件:abc/abc/完成_输出
Col1, Col2, Col3, Col4, Col5
Val1, Val2, Val3, Val4, Header1
Val1, Val2, Val3, Val4, Header1
Val1, Val2, Val3, Val4, Header1
Val1, Val2, Val3, Val4, Header2
Val1, Val2, Val3, Val4, Header3
Val1, Val2, Val3, Val4, Header3
选项2:每个标题创建不同的文件:文件1:abc/abc/标题1
Col1, Col2, Col3, Col4
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
文件2:abc/abc/标题2
Col1, Col2, Col3, Col4
Val1, Val2, Val3, Val4
文件3:abc/abc/标题3
Col1, Col2, Col3, Col4
Val1, Val2, Val3, Val4
Val1, Val2, Val3, Val4
应将文件从接收到的格式拆分到不同的文件,或者应将标题行Map到其他列。是否可以在Azure数据工厂中完成此操作(包括数据流选项)?无法访问Databricks群集。
P.S.我知道使用Python脚本很容易做到这一点,但我希望能够在ADF中构建完整的流程。
我尝试基于条件拆分来拆分文件。但是,这不起作用,因为这只允许选择行。只有当行值(之一)给出有关标题的指示时,才可以使用这一方法。
其他的东西我都用不上。
编辑:按要求添加所需的输出选项
2条答案
按热度按时间9rygscc11#
First row as header
选项(这样您将获得如下图所示的输出)。我使用;
作为列分隔符,使用|
作为行分隔符,并且。header
活动是从查找输出中提取标题(col1,col2,col3,col4)。each file
设置变量activity来存储每个文件的所有数据。我用header
变量value初始化了它。get first filename
用于使用集合和字符串函数提取第一个文件的名称(本例中为header1)。if condition
活动来检查该行是否为标题(被视为文件名)。因此,我相应地连接了每一行,并根据要求使用复制数据活动。beq87vna2#
如果输入数据集是静态的,则将第二个选项视为要求,然后可以使用以下方法:
1.在源后面添加筛选器转换,表达式为:
!startsWith(Col1, 'Header')
1.添加代理键转换以创建增量标识列
1.添加条件拆分转换,将数据拆分为具有以下表达式的三个部分:
x一个月一个月一次x:x一个月二个月一次x一个月三个月一次x:x一个四个一个x一个五个一个x一个六个一个
1.使用选择转换取消选择“Id”列
1.添加sink转换以将数据加载到csv文件