Talk about vertica's flex table

The Json format is familiar to all software developers today, and many data formats are stored in it. Let's take a look at how vertica handles json data. This is the flex table of vertica!

First create a json file:

{"name": "Everest", "type":"mountain", "height":29029, "hike_safety": 34.1}
{"name": "Mt St Helens", "type":"volcano", "height":29029, "hike_safety": 15.4}
{"name": "Denali", "type":"mountain", "height":17000, "hike_safety": 12.2}
{"name": "Kilimanjaro", "type":"mountain", "height":14000 }
{"name": "Mt Washington", "type":"mountain", "hike_safety": 50.6}

Then we create a flex table:

dbadmin=> CREATE FLEX TABLE start_json();
CREATE TABLE

Then copy the data into it:

dbadmin=> COPY start_json FROM '/home/dbadmin/qcfData/*json*' PARSER fjsonparser();
 Rows Loaded 
-------------
           5
(1 row)

search result:

dbadmin=> select * from start_json();
ERROR 4256:  Only relations and subqueries are allowed in the FROM clause
dbadmin=>  SELECT maptostring(__raw__) FROM start_json;
                                               maptostring                                                
----------------------------------------------------------------------------------------------------------
 {
   "height" : "29029",
   "hike_safety" : "34.1",
   "name" : "Everest",
   "type" : "mountain"
}

 {
   "height" : "29029",
   "hike_safety" : "15.4",
   "name" : "Mt St Helens",
   "type" : "volcano"
}

 {
   "height" : "17000",
   "hike_safety" : "12.2",
   "name" : "Denali",
   "type" : "mountain"
}

 {
   "height" : "14000",
   "name" : "Kilimanjaro",
   "type" : "mountain"
}

 {
   "hike_safety" : "50.6",
   "name" : "Mt Washington",
   "type" : "mountain"
}

(5 rows)

It is found that the json file is parsed well, and the file is formatted.

Query json data:

dbadmin=>  SELECT start_json.type,start_json.name FROM start_json;
   type   |     name      
----------+---------------
 mountain | Everest
 volcano  | Mt St Helens
 mountain | Denali
 mountain | Kilimanjaro
 mountain | Mt Washington
(5 rows)

In summary, flex table provides a good storage and display for data in json format.

<script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split('\n').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326913963&siteId=291194637