2017-11-20 1 views
1

Ich habe diese JSON-Datei.verschachtelte JSON-Daten aus Flex-Tabelle in Vertica lesen

 [ 
{ 
"Modified": "2016-09-0", 
"Id": 16, 
"Name": "ABC", 
    "Filters": [], 
"ScoreComponents":[ 
    { 
    "Id": 86, 
    "Name": "Politeness", 
    "Bins": [], 
    "Ranges": [ 
     { 
     "ComponentId": 86,      
     "LastUser": "CDE\\John.Doe" 
     }, 
     { 
     "ComponentId": 86, 
     "LastUser": "CDE\\John.Doe" 
     } 
     ], 
    "Filters": [] 
    }, 
    { 
    "Id": 87, 
    "Name": "Empathy", 
    "Bins": [], 
    "Ranges": [ 
     { 
     "ComponentId": 87, 
     "LastUser": "CDE\\John.Doe" 
     } 
    ], 
    "Filters": [ 
     { 
     "ComponentID": -30356, 
     "BucketID": 81 
     } 
    ] 
    }, 
    { 
    "Id": 88, 
    "Name": "Ownership", 
    "Bins": [], 
    "Ranges": [ 
     { 
     "ComponentId": 88, 
     "User": "CDE\\John.Doe" 

     } 
    ], 
    "Filters": [] 
    }] 
} 
] 

Ich habe diese Datei In Vertica flex Tabelle

 CREATE FLEX TABLE flex_test(); 
    copy events_stg.flex_test from LOCAL 'C:/test2.json' PARSER fjsonparser (flatten_maps= true, flatten_arrays = false) 

ich alle Daten von ScoreComponents einschließlich verschachtelte Arrays lesen möge geladen. Ich versuchte Abfrage Diese Abfrage

select "Id" as scoreid,mapitems("ScoreComponents") OVER(PARTITION BY 
     "Id") from flex_test 

immer eine Ausgabe wie: Outout of query

ich nicht nur die kleinen Quadrate in Ausgabe verstehen. Ich bin Student und diese vertica DB und Flex Tische sind neu für mich.

Ich habe versucht mit flatten_arrays = true, aber es gibt mir leere Ergebnismenge.

+0

Hilfe bitte Leute .. – Riya

Antwort

0

Sie erhalten Quadrate, weil das Wertefeld eine binäre VMap enthält.

Dies sollte es tun:

create flex table so_flex(); 
create table so_score_components(
    id int, 
    name varchar(100) 
); 
create table so_ranges(
    parent_id int, 
    component_id int, 
    last_user varchar(100) 
); 
create table so_filters(
    parent_id int, 
    component_id int, 
    bucket_id int 
); 

copy so_flex from local 'E:\Demos\so.json' 
parser fjsonparser(start_point='ScoreComponents', 
flatten_maps = false, flatten_arrays = false); 

insert into so_score_components(id, name) 
select id::int, name::varchar from so_flex; 

insert into so_ranges(parent_id, component_id, last_user) 
select id::int, values['ComponentId']::int, values['LastUser']::varchar 
from (
    select id, mapitems(ranges) over (partition by id) 
    from so_flex 
) t; 

insert into so_filters(parent_id, component_id, bucket_id) 
select id::int, values['ComponentID']::int, values['BucketID']::int 
from (
    select id, mapitems(filters) over (partition by id) 
    from so_flex 
) t;