基于hdfs文件创建hive表

create table customer
row format SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
stored as inputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
outputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
location '/datalake/raw/customer'
tblproperties (
    'avro.schema.literal'='{
    "namespace": "example.avro",
    "type": "record",
    "name": "Customer",
    "fields": [
        {"name":"id", "type":"int"},
        {"name":"first_name", "type":"string"},
        {"name":"last_name", "type":"string"},
        {"name":"dob", "type":"long"}
     ]
}');

create table address
row format SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
stored as inputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
outputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
location '/datalake/raw/address'
tblproperties (
    'avro.schema.literal'='{
    "namespace": "example.avro",
    "type": "record",
    "name": "Address",
    "fields": [
        {"name":"id", "type":"int"},
        {"name":"street1", "type":"string"},
        {"name":"street2", "type":"string"},
        {"name":"city", "type":"string"},
        {"name":"state", "type":"string"},
        {"name":"country", "type":"string"},
        {"name":"zip_code", "type":"string"}
     ]
}');


create table contact
row format SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
stored as inputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
outputformat
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
location '/datalake/raw/contacts/load1'
tblproperties (
    'avro.schema.literal'='{
    "namespace": "example.avro",
    "type": "record",
    "name": "Contact",
    "fields": [
        {"name":"id", "type":"string"},
        {"name":"cell", "type":"string"},
        {"name":"phone", "type":"string"},
        {"name":"email", "type":"string"}
     ]
}');

posted on 2021-03-03 00:19  rigidwang  阅读(536)  评论(0编辑  收藏  举报