- ·上一篇文章:Pig Latin 基础
- ·下一篇文章:Apache Pig 存储数据
当前位置:K88软件开发 → 文章中心 → 大数据 → Apache Pig → 文章内容
Apache Pig 加载数据
op.executionengine.HExecutionEngine - Connecting to hadoop file system at: hdfs://localhost:9000 grunt>执行Load语句现在,通过在Grunt shell中执行以下Pig Latin语句,将文件 student_data.txt 中的数据加载到Pig中。grunt> student = LOAD 'hdfs://localhost:9000/pig_data/student_data.txt' USING PigStorage(',') as ( id:int, firstname:chararray, lastname:chararray, phone:chararray, city:chararray );以下是对上述说明的描述。Relation name我们已将数据存储在学生(student)模式中。Input file path我们从HDFS的/pig_data/目录中的 student_data.txt 文件读取数据。Storage function我们使用了 PigStorage() 函数,将数据加载并存储为结构化文本文件。它采用分隔符,使用元组的每个实体作为参数分隔。默认情况下,它以“\t"作为参数。schema我们已经使用以下模式存储了数据。columnid名字姓氏电话号码城市datatypeintchar arraychar arraychar arraychar array注意: Load语句会简单地将数据加载到Pig的指定的关系中。要验证Load语句的执行情况,必须使用Diagnostic运算符,这将在后续的章节中讨论。
Apache Pig 加载数据