在Apache Pig中加載本地文件可以使用load
命令,語法如下:
data = LOAD 'path/to/local/file' USING PigStorage(',') AS (column1:datatype1, column2:datatype2, ...);
其中,path/to/local/file
是本地文件的路徑,PigStorage(',')
指定了文件的分隔符,AS (column1:datatype1, column2:datatype2, ...)
用于指定每列的字段名和數(shù)據(jù)類型。
示例:
data = LOAD 'file:///path/to/local/file.txt' USING PigStorage(',') AS (name:chararray, age:int, city:chararray);
需要注意的是,加載本地文件時需要使用file:///
前綴來指定文件路徑是本地文件。