溫馨提示×

Apache Pig中怎么加載本地文件

Pig
小億
84
2024-03-28 14:05:21

在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:///前綴來指定文件路徑是本地文件。

0