Flex表是Vertica 7.0中的新功能之一。
有人能告诉我Flex表如何将非结构化数据转换为结构化数据?
提前致谢!
答案 0 :(得分:2)
Flex表是Vertica 7.0中的新功能。这个特性创建了一种不同类型的表,专门用于加载和查询非结构化数据,在HP Vertica中也称为半结构化数据 创建弹性表格的语法:
create flex table unstruc_data();
unstruc_data的内容有两列 _ 标识 _ 和 _ 行 _ ;
行col是半结构化数据的内容,其类型为LONG VARBINARY,标识为行id。
Flex表附带一组帮助功能:
我不打算解释所有这些,因为我认为你应该去研究它们。 有关新Vertica功能的更多详细信息,请转到此链接Vertica 7.0 New Stuff
答案 1 :(得分:0)
所有非结构化数据保存到原始数据字段
它是一个BLOB
当你需要访问非结构化字段时,它是一个SLOW,因为需要BLOB提取
答案 2 :(得分:0)
在通过客户端向您传递JSON文档的场景中,您需要将其存储在Vertica DB中。
不使用flex表这里有几个问题: 1)你需要知道Json的结构。 2)在Vertica DB中创建一个表。 3)从JSON文档中提取每个列值 4)在表格中插入值。
除了这个过程之外,如果将新密钥添加到JSON,则在vertica DB上还有其他任务可以更改表,还有处理逻辑可以获取新的密钥对值
使用Flex表,下面详细说明了我们如何简化它:
1) Take the below Json,EE.txt
{"Name":"Rahul","Age":30}
2) Create a flex table EMP_test
dbadmin=> create flex table EMP_Test();
CREATE TABLE
3) Load the data into the flex table
dbadmin=> copy EMP_Test from '/home/dbadmin/EE.txt' parser fjsonparser();
Rows Loaded
-------------
1
(1 row)
4) To find out what keys are there in your Json , You have to refresh keys projection using below command
dbadmin=> select compute_flextable_keys('EMP_Test');
compute_flextable_keys
--------------------------------------------------
Please see public.EMP_Test_keys for updated keys
(1 row)
dbadmin=> select * FRom EMP_Test_keys;
key_name | frequency | data_type_guess
----------+-----------+-----------------
Age | 1 | varchar(20)
Name | 1 | varchar(20)
(2 rows)
5) Refresh the view for flex table using below command .You can query the view for data
dbadmin=>
dbadmin=> select build_flextable_view('EMP_Test');
build_flextable_view
-----------------------------------------------------
The view public.EMP_Test_view is ready for querying
(1 row)
dbadmin=> select * From EMP_Test_View
dbadmin-> ;
age | name
-----+-------
30 | Rahul
(1 row)
6) Now , If your Json structure changes and a Additional key 'Gender' is added .
{"Name":"Sid","Age":22,"Gender":"M"}
7) You can load the data directly into the table EMP_Test
dbadmin=> copy EMP_Test from '/home/dbadmin/EE1.txt' parser fjsonparser();
Rows Loaded
-------------
1
(1 row)
8) Re compute the keys and rebuild the view using below command
dbadmin=> select compute_flextable_keys('EMP_Test');
compute_flextable_keys
--------------------------------------------------
Please see public.EMP_Test_keys for updated keys
(1 row)
dbadmin=> select build_flextable_view('EMP_Test');
build_flextable_view
-----------------------------------------------------
The view public.EMP_Test_view is ready for querying
(1 row)
9) You can find the new data added and new keys using the below command .
dbadmin=>
dbadmin=> select * From EMP_Test_keys;
key_name | frequency | data_type_guess
----------+-----------+-----------------
Age | 2 | varchar(20)
Name | 2 | varchar(20)
Gender | 1 | varchar(20)
(3 rows)
dbadmin=> select * From EMP_test_view;
age | name | gender
-----+-------+--------
30 | Rahul |
22 | Sid | M
(2 rows)
This is how Flex table converts unstructured data(semi structured data) to structured data .
Flex table has made it very easy to integrate any data service with vertica DB .