PigStorage() 函数将数据加载并存储为结构化文本文件。它采用分隔符,使用它来将元组的每个实体分隔为一个参数。默认情况下,以't'作为参数。
下面给出了 PigStorage() 函数的语法。
grunt> PigStorage(field_delimiter)
假设在名为 /data/ 的HDFS目录中有一个名为 student_data.txt 的文件,其中包含以下内容。
001,Rajiv,Reddy,9848022337,Hyderabad 002,siddarth,Battacharya,9848022338,Kolkata 003,Rajesh,Khanna,9848022339,Delhi 004,Preethi,Agarwal,9848022330,Pune 005,Trupthi,Mohanthy,9848022336,Bhuwaneshwar 006,Archana,Mishra,9848022335,Chennai.
我们可以使用PigStorage函数加载数据,如下所示。
grunt> student = LOAD 'hdfs://localhost:9000/pig_data/student_data.txt' USING PigStorage(',') as ( id:int, firstname:chararray, lastname:chararray, phone:chararray, city:chararray );
在上面的例子中,我们已经看到过使用逗号(',')分隔符。因此,我们使用(,)分隔了记录的值。
同样,我们可以使用 PigStorage() 函数将数据存储到HDFS目录中,如下所示。
grunt> STORE student INTO ' hdfs://localhost:9000/pig_Output/ ' USING PigStorage (',');
这将把数据存储到给定的目录中。可以按如下所示验证数据。
你可以如下所示验证存储的数据。首先,使用 ls 命令列出名为 pig_output 的目录中的文件,如下所示。
$ hdfs dfs -ls 'hdfs://localhost:9000/pig_Output/' Found 2 items rw-r--r- 1 Hadoop supergroup 0 2015-10-05 13:03 hdfs://localhost:9000/pig_Output/_SUCCESS rw-r--r- 1 Hadoop supergroup 224 2015-10-05 13:03 hdfs://localhost:9000/pig_Output/part-m-00000
可以观察到在执行 Store 语句后创建了两个文件。
然后,使用 cat 命令,列出名为 part-m-00000 的文件的内容,如下所示。
$ hdfs dfs -cat 'hdfs://localhost:9000/pig_Output/part-m-00000' 1,Rajiv,Reddy,9848022337,Hyderabad 2,siddarth,Battacharya,9848022338,Kolkata 3,Rajesh,Khanna,9848022339,Delhi 4,Preethi,Agarwal,9848022330,Pune 5,Trupthi,Mohanthy,9848022336,Bhuwaneshwar 6,Archana,Mishra,9848022335,Chennai
函数 LTRIM()与函数 TRIM()相同。它从给定字符串(标题空格)的左侧删除不需要的空格。语法这里是LTRIM()函数的语法...
Pig Latin的 ABS()函数用于计算给定表达式的绝对值。语法这是 ABS()函数的语法。grunt ABS(expression)例假设在 HDFS 目录 /pig_...
wx.navigateTo(Object object)保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用wx.navigateBack可以返回...
logistics.updateBusiness本接口应在服务器端调用,详细说明参见服务端API。本接口支持云调用。需开发者工具版本 =1.02.1904090...
插件功能页插件功能页从小程序基础库版本2.1.0开始支持。某些接口不能在插件中直接调用(如wx.login),但插件开发者可以使用插...
判断结构要求程序员指定要由程序评估或测试的一个或多个条件,以及条件为真时要执行的语句(必需的)和条件为假时要执行的语句(...
具有两个维度(即,下标)的数组通常表示由排列在行和列中的信息组成的值的表格。以下是多维数组的关键特性:为了识别特定的表格...