2017-10-12 7 views
0

Mon JSON Objet:JSON Serde Parsing Tableau struct Problème

{ 
    "_total": 4, 
    "values": [ 
     { 
      "total-follower-count": 63911, 
      "organic-follower-count": 6000, 
      "paid-follower-count": 3911, 
      "time": 1399334400000 
     }, 
     { 
      "total-follower-count": 64023, 
      "organic-follower-count": 6000, 
      "paid-follower-count": 4023, 
      "time": 1399420800000 
     }, 
     { 
      "total-follower-count": 64023, 
      "organic-follower-count": 6000, 
      "paid-follower-count": 4023, 
      "time": 1399507200000 
     }, 
     { 
      "total-follower-count": 64048, 
      "organic-follower-count": 6000, 
      "paid-follower-count": 4048, 
      "time": 1399593600000 
     } 
    ] 
} 

Dans AWS Athena, je crée une table comme ci-dessous.

CREATE EXTERNAL TABLE IF NOT EXISTS Linkedindata 
(
    `_total` INT, 
    values array<struct<total_follower_count:INT, 
         organic_follower_count:INT, 
         paid_follower_count:INT>> 
) 
ROW FORMAT SERDE 'org.openx.data.jsonserde.JsonSerDe' 
WITH SERDEPROPERTIES (
    "mapping.total_follower_count"="total-follower-count", 
    "mapping.organic_follower_count"="organic-follower-count", 
    "mapping.paid_follower_count"="paid-follower-count" 
) 
LOCATION 's3://mybucket/' 
TBLPROPERTIES ('has_encrypted_data'='false') 

Je suis incapable d'accéder à des valeurs de tableau comme "Total_Follower_count". S'il te plait peux-tu aider. Merci

Répondre

0

Vous devez aplatir vos tableaux et effectuer votre sélection sur cela.

Documenté par exemple clair ici,

http://docs.aws.amazon.com/athena/latest/ug/flattening-arrays.html

Hope it helps.

+0

J'ai essayé d'utiliser le script ci-dessous mais il ne retourne rien. sélectionner \t _total, \t unnested_series.valuesentry.total_follower_count \t de \t linkedindata t \t jointure croisée unnest (t.values) unnested_series (valuesentry) –