2

我有这个 json 文件。

        [
 {
"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": []
  }]
 }
 ]

我已经在 Vertica flex 表中加载了这个文件

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

我想从 ScoreComponents 中读取所有数据,包括嵌套数组。我试过查询这个查询

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

得到如下输出:超出查询范围

我只是不明白输出中的那些小方块。我是一名学生,这个 vertica DB 和 Flex 表对我来说是新的。

我试过 flatten_arrays = true 但它给了我空的结果集。

4

1 回答 1

1

您得到正方形是因为值字段包含二进制 VMap。

这应该这样做:

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;
于 2017-11-22T19:01:46.917 回答