2017-02-02 2 views
0

My Json внизу. Я должен загрузить этот JSON в улей и запросить несколько деталей.Загрузка данных JSON в таблицу HIVE, дающая NoViableAltException/PraseException

{ 
    "id": "1234", 
    "pdid": "abcd", 
    "summary": { 
    "tripStartTimestamp": 1485263310528, 
    "tripEndTimestamp": 0, 
    "status": 10, 
    "totalGPSDistanceMetres": 0, 
    "avgGPSSpeed": 0, 
    "maxGPSSpeed": 0, 
    "avgInstMileage": 0, 
    "totalHaltTimeSeconds": 0, 
    "totalIdlingTimeSeconds": 0, 
    "totalRunningTimeMins": 0, 
    "startLocation": { 
     "latitude": 13.022425, 
     "longitude": 77.760587, 
     "speed": 70, 
     "ts": 1485263310528, 
     "direction": 0 
    }, 
    "endLocation": null, 
    "driverBehaviorSummary": [ 
     { 
     "driver": null, 
     "noOfRapidAcceleration": 0, 
     "noOfRapidDeceleration": 0, 
     "noOfOverSpeed": 0, 
     "noOfHarshBreak": 0 
     } 
    ] 
    }, 
    "latLongs": [ 
    { 
     "latitude": 13.022425, 
     "longitude": 77.760587, 
     "speed": 70, 
     "ts": 1485263310528, 
     "direction": 0 
    } 
    ], 
    "halts": [], 
    "idlings": [] 
} 

Я написал ниже для создания таблицы для HIVE. Я вычислил схему JSON и использовал ее для создания структуры ниже.

CREATE TABLE TABLE_ABC_Test1(
    id string , 
    pdid string , 
    summary object<struct< 
    tripStartTimestamp:int, 
    tripEndTimestamp:int, 
    status:int, 
    totalGPSDistanceMetres:int, 
    avgGPSSpeed:int, 
    maxGPSSpeed:int, 
    avgInstMileage:int, 
    totalHaltTimeSeconds:int, 
    totalIdlingTimeSeconds:int, 
    totalRunningTimeMins:int, 
    startLocation object<struct< 
    latitude:int, 
    longitude:int, 
    speed:int, 
    ts:int, 
    direction:int>> 
    endLocation:string, 
    driverBehaviorSummary array<struct<object<struct< 
    driver:string, 
    noOfRapidAcceleration:int, 
    noOfRapidDeceleration:int, 
    noOfOverSpeed:int, 
    noOfHarshBreak:int 
    >>>> 
    >> 
    latLongs<array<struct<object< 
    latitude:int, 
    longitude:int, 
    speed:int, 
    ts:int, 
    direction:int 
    >>>> 
    halts<array<struct<>>> 
    idlings<array<struct<>>> 
    ) 
ROW FORMAT SERDE 
'org.apache.hive.hcatalog.data.JsonSerDe' 
STORED AS TEXTFILE; 

Но ошибка пришла как:

NoViableAltException([email protected][]) 
     .......some hive stack trace 
FAILED: ParseException line 4:10 cannot recognize input near 'object' '<' 'struct' in column type 

ответ

1

улья не имеет object типа данных, а также вам не хватает прийти : для некоторых полевых заданий.

Синтаксис create table будет,

CREATE TABLE TABLE_ABC_Test1(
    id string , 
    pdid string , 
    summary struct< 
    tripStartTimestamp:int, 
    tripEndTimestamp:int, 
    status:int, 
    totalGPSDistanceMetres:int, 
    avgGPSSpeed:int, 
    maxGPSSpeed:int, 
    avgInstMileage:int, 
    totalHaltTimeSeconds:int, 
    totalIdlingTimeSeconds:int, 
    totalRunningTimeMins:int, 
    startLocation:struct< 
    latitude:int, 
    longitude:int, 
    speed:int, 
    ts:int, 
    direction:int>, 
    endLocation:string, 
    driverBehaviorSummary:array<struct< 
    driver:string, 
    noOfRapidAcceleration:int, 
    noOfRapidDeceleration:int, 
    noOfOverSpeed:int, 
    noOfHarshBreak:int 
    >> 
    >, 
    latLongs array<struct< 
    latitude:int, 
    longitude:int, 
    speed:int, 
    ts:int, 
    direction:int 
    >>, 
    halts array<string>, 
    idlings array<string> 
    ) 
ROW FORMAT SERDE 
'org.apache.hive.hcatalog.data.JsonSerDe' 
STORED AS TEXTFILE; 
Смежные вопросы