2017-04-26 4 views
-2

je tentais de charger ces données JSON dans la rucheErreur dans Nested JSON Ruches

{ 
    "id": "0001", 
    "type": "donut", 
    "name": "Cake", 
    "ppu": 0.55, 
    "batters": 
     { 
      "batter": 
       [ 
        { "id": "1001", "type": "Regular" }, 
        { "id": "1002", "type": "Chocolate" }, 
        { "id": "1003", "type": "Blueberry" }, 
        { "id": "1004", "type": "Devil's Food" } 
       ] 
     }, 
    "topping": 
     [ 
      { "id": "5001", "type": "None" }, 
      { "id": "5002", "type": "Glazed" }, 
      { "id": "5005", "type": "Sugar" }, 
      { "id": "5007", "type": "Powdered Sugar" }, 
      { "id": "5006", "type": "Chocolate with Sprinkles" }, 
      { "id": "5003", "type": "Chocolate" }, 
      { "id": "5004", "type": "Maple" } 
     ] 
} 

utilisant DDL commandes

ADD JAR /home/cloudera/Downloads/json-serde-1.3.6-SNAPSHOT-jar-with-dependencies.jar; 

CREATE EXTERNAL TABLE format.json_serde (
    `id` string, 
    `type` string, 
    `name` string, 
`ppu` float,  
    batters` struct < `batter`:array < struct <`bid`:string, `btype`:string >>>, 
    `topping`:array < struct<`tid`:int, `ttype`:string>> 
) 
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe'; 

jette moi error

FAILED: ParseException line 7:11 cannot recognize input near ':' 'array' '<' in column type </b> 

Répondre

0
  1. Vous avez des fautes de frappe
    ttype`: string doit être ttype: string
    battersstruct devrait être frappeurs struct
    en tête: tableau devrait être tableau en tête

  2. cartographie JSON SerDe est fait par son nom.
    Les noms de vos champs de structure doivent correspondre aux noms réels, par ex. id et non bid ou tid, sinon vous obtiendrez des valeurs NULL pour ces champs.

  3. Il existe déjà un Serotype JSON qui fait partie de l'installation de Hive. https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL#LanguageManualDDL-RowFormats&SerDe


create external table json_serde 
( 
    id  string 
    ,type string 
    ,name string 
    ,ppu  float 
    ,batters struct<batter:array<struct<id:string,type:string>>> 
    ,topping array<struct<id:string,type:string>> 
) 
row format serde 
'org.apache.hive.hcatalog.data.JsonSerDe' 
stored as textfile 
; 

select * from json_serde 
; 

+------+-------+------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| id | type | name |  ppu  |                  batters                  |                             topping                             | 
+------+-------+------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
| 0001 | donut | Cake | 0.550000011920929 | {"batter":[{"id":"1001","type":"Regular"},{"id":"1002","type":"Chocolate"},{"id":"1003","type":"Blueberry"},{"id":"1004","type":"Devil'sFood"}]} | [{"id":"5001","type":"None"},{"id":"5002","type":"Glazed"},{"id":"5005","type":"Sugar"},{"id":"5007","type":"PowderedSugar"},{"id":"5006","type":"ChocolatewithSprinkles"},{"id":"5003","type":"Chocolate"},{"id":"5004","type":"Maple"}] | 
+------+-------+------+-------------------+--------------------------------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 
+0

Merci, quand j'ai essayé de l'interroger a renvoyé l'erreur folllowing ** Echec à l'exception java.io.IOException: org.apache.hadoop .hive.serde2.SerDeException: org.codehaus.jackson.JsonParseException: End-of-input inattendu: marqueur de fermeture attendu pour OBJECT (à partir de [Source: [email protected]; ligne: 1, colonne: 0]) à [Source: java.io.ByteArrayInputStream @ 73304204; ligne: 1, colonne: 3] ** S'il vous plaît laissez-moi savoir si vous avez effectué une mise en forme sur les données d'entrée –

+0

Tout document JSON doit être écrit dans une seule ligne. Je ne suis au courant d'aucun Serotype JSON qui sait comment traiter un document multi-lignes. –

0

Il a travaillé quand j'enlevé les points-virgules près de nappage. Merci


CREATE TABLE EXTERNE format.json_serde (
chaîne id,
type chaîne,
chaîne name,
ppu flotteur,

batters struct < batter: tableau < struct < bid: string, btype: string >>>,


topping tableau < struct < tid: string, ttype: string >> )