Hiveでは、map、array、structが同時に存在しますが、テーブル作成ステートメントでセパレーターをどのように指定する必要がありますか?

      Hiveには、マップ、配列、および構造体の形式があります。これらの3つの形式が同時に存在する場合、テーブル作成ステートメントのセパレーターはどのように指定する必要がありますか?
      

1.答えを最初に言う

      最初に答えを言ってください:

create table test(
	name string,
	friends array<string>,
	children map<string, int>,
	address struct<street:string, city:string>
)
row format delimited
fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';

      フィールドの説明:

row format delimited fields terminated by ','   /* 列分隔符 */
collection items terminated by '_'         /*  MAP STRUCT 和 ARRAY 的分隔符(数据分割
符号)  */
map keys terminated by ':'    /* MAP 中的 key 与 value 的分隔符    */
lines terminated by '\n';       /* 行分隔符  */

      説明が必要な場所は実際には2つだけです:
      ①。ハイブ、マップ、配列、および構造体の「_」で終了するコレクションアイテムはすべて、終了するコレクションアイテムを使用して指定されるため、共有できる区切り文字は1つだけです。
      ②。「\ n」で終了する行、書く必要はありません、行区切り文字はデフォルトで\ nです

2.例を挙げてください

      次のデータを想定して、ハイブ関連テーブルに挿入する必要があります

{
	"name": "张三",
	"friends": ["李四" , "王五"] , //列表 Array,
	"children": { //键值 Map,
		"小李四": 18 ,
		"小王五": 19
	}
	"address": { //结构 Struct,
		"street": "大兴" ,
		"city": "北京"
	}
}
  1. まず、それを1つのデータに整理します。
张三,李四_王五,小李四:18_小王五:19,大兴_北京

      セパレータに注意してください

  1. テーブルの作成
create table test(
	name string,
	friends array<string>,
	children map<string, int>,
	address struct<street:string, city:string>
)
row format delimited
fields terminated by ','
collection items terminated by '_'
map keys terminated by ':'
lines terminated by '\n';
  1. 最初にデータをドキュメントにVimし、次にそれをハイブに読み込みます
load data local inpath
"/home/software/data/test.txt" into table test;
  1. アクセス方法
    アクセスマップ:
select 	friends[1], /* 这是访问array */
	children['xiaosong'], /* 这是访问map */
	address.city
	from test;

      
      

48件の元の記事を公開 36のような 訪問130,000+

おすすめ

転載: blog.csdn.net/weixin_42845682/article/details/104919328