Joe Root
Joe Root

Reputation: 51

Load the Json file in hive with dynamic JSON Schema

I'm trying to load yelp_business JSON into hive table but not able to create schema for this json file in hive. Please let me know how to create schema for the below in hive. Depending on the business the attribute change in hive and I'm using json serde while creating a table.

{
    "business_id": "8-NRKkPY1UiFXW20WXKiXg",
    "name": "Filiberto's Mexican Food",
    "neighborhood": "",
    "address": "1440 N. Dysart Ave",
    "city": "Avondale",
    "state": "AZ",
    "postal_code": "85323",
    "latitude": 33.4481059352,
    "longitude": -112.341302074,
    "stars": 2.5,
    "review_count": 40,
    "is_open": 1,
    "attributes": {
        "Alcohol": "none",
        "Ambi
        ence": "{'romantic': False, 'intimate': False, 'classy': False, 'hipster': False, 'divey': False, 'touristy': False, 'trendy': False, 'upscale': False, 'c
        asual': True}",
        "BikeParking": "True",
        "BusinessAcceptsCreditCards": "True",
        "BusinessParking": "{'garage': False, 'street': False, 'validated': False, 'lot':
        True, 'valet': False}",
        "Caters": "False",
        "GoodForKids": "True",
        "GoodForMeal": "{'dessert': False, 'latenight': True, 'lunch': False, 'dinner': False, 'break
        fast': False, 'brunch': False}",
        "HasTV": "False",
        "NoiseLevel": "average",
        "OutdoorSeating": "False",
        "RestaurantsAttire": "casual",
        "RestaurantsDelivery": "False
        ",
        "RestaurantsGoodForGroups": "True",
        "RestaurantsPriceRange2": "1",
        "RestaurantsReservations": "False",
        "RestaurantsTableService": "False",
        "RestaurantsTakeOut"
        : "True",
        "WheelchairAccessible": "True",
        "WiFi": "no"
    },
    "categories": "Mexican, Restaurants",
    "hours": {
        "Monday": "0:0-0:0",
        "Tuesday": "0:0-0:0",
        "Wednesday": "0:0-0
        :0",
        "Thursday": "0:0-0:0",
        "Friday": "0:0-0:0",
        "Saturday": "0:0-0:0",
        "Sunday": "0:0-0:0"
    }
}
{
    "business_id": "UTm5QZThPQlT35mkAcGOjg",
    "name": "Maggie & Stella's Gifts",
    "neighborhood": "Oakland",
    "address": "209 Oakland Ave",
    "city": "Pittsburgh",
    "state"
    : "PA",
    "postal_code": "15213",
    "latitude": 40.4414214,
    "longitude": -79.9564571,
    "stars": 3.5,
    "review_count": 3,
    "is_open": 1,
    "attributes": {
        "BikeParking": "True",
        "Bu
        sinessAcceptsCreditCards": "True",
        "BusinessParking": "{'garage': False, 'street': False, 'validated': False, 'lot': False, 'valet': False}",
        "RestaurantsPri
        ceRange2": "2"
    },
    "categories": "Flowers & Gifts, Gift Shops, Shopping",
    "hours": {
        "Monday": "9:0-18:0",
        "Tuesday": "9:0-18:0",
        "Wednesday": "9:0-18:0",
        "Thursday": "
        9:0-18:0",
        "Friday": "9:0-17:0",
        "Saturday": "10:0-17:0"
    }
}

Upvotes: 0

Views: 339

Answers (1)

Gaurang Shah
Gaurang Shah

Reputation: 12930

Hive does not handle the dynamic schema.

What you can do is provide all the attributes weather applicable or not.

Upvotes: 0

Related Questions