我试图在Apache Pig Latin中读取一个包含每行的非分隔ascii的文本文件。也就是说,该行中的每一列都在该行的特定位置开始和结束。
样本定义:
+--------+----------------+--------------+
| Column | Start Position | End Position |
+--------+----------------+--------------+
| A | 1 | 6 |
+--------+----------------+--------------+
| B | 8 | 11 |
+--------+----------------+--------------+
| C | 13 | 15 |
+--------+----------------+--------------+
示例数据:
+---+---+---+---+---+---+---+----+---+----+----+----+----+----+----+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
+---+---+---+---+---+---+---+----+---+----+----+----+----+----+----+
| s | a | m | p | l | e | | d | a | t | a | | | h | i |
+---+---+---+---+---+---+---+----+---+----+----+----+----+----+----+
| d | u | d | e | | | | hi | | | | | b | r | o |
+---+---+---+---+---+---+---+----+---+----+----+----+----+----+----+
预期产出:
sample, data, hi
dude, hi, bro
我如何在Pig中阅读此内容? PigStorage似乎不够灵活,不允许位置分隔,只有字符串分隔(逗号,制表符等)。
答案 0 :(得分:0)
看起来Apache为这个特定的用例提供了一个加载器:
LOAD 'data.txt' USING org.apache.pig.piggybank.storage.FixedWidthLoader('1-6, 8-11, 13-15', 'SKIP_HEADER') AS (a, b, c);