Hive 表包含位于 Hive 表创建命令中给出的 HDFS 文件夹中的文件中的结构化数据。
使用 Cygnus 0.1,此类结构化数据是通过使用类似 CSV 的文件来实现的,因此向 HDFS 文件夹中添加新文件或将新数据附加到该文件夹中已存在的文件中同样简单作为组成新的类似 CSV 的数据行。分隔符必须与创建表格时指定的相同,例如:
create external table <table_name> (recvTimeTs bigint, recvTime string, entityId string, entityType string, attrName string, attrType string, attrValue string) row format delimited fields terminated by '|' location '/user/<myusername>/<mydataset>/';
因此,作为示例分隔符|,新的数据行必须是:
<ts>|<ts_ms>|<entity_name>|<entity_type>|<attribute_name>|<attribute_type>|<value>
从Cugnus 0.2(含)开始,使用类Json文件实现结构化数据。在这种情况下,您不必处理分隔符,也不必处理表创建(请参阅this question),因为 Json 不使用分隔符并且表创建是自动的。在这种情况下,您必须按照以下任何一种格式编写一个新文件或新数据以附加到已存在的文件中(取决于您分别以row 或column 模式存储数据):
{"recvTimeTs":"13453464536", "recvTime":"2014-02-27T14:46:21", "entityId":"Room1", "entityType":"Room", "attrName":"temperature", "attrType":"centigrade", "attrValue":"26.5", "attrMd":[{name:ID, type:string, value:ground}]}
{"recvTime":"2014-02-27T14:46:21", "temperature":"26.5", "temperature_md":[{"name":"ID", "type":"string", "value":"ground"}]}
值得一提的是,存在负责将 0.1-like 格式转换为 0.2-like (或更高) 格式的脚本。