2014-02-07 22 views

回答

2

Flex表格是Vertica 7.0中的一个新功能。这feauture创建不同类型的表格特别设计用于加载和查询非结构化数据,也称为HP Vertica的 语法半结构化数据来创建一个Flex表:

create flex table unstruc_data(); 

凡unstruc_data的内容有两列_ 身份 __ _; 其中,行col是半结构化数据的内容,其类型为LONG VARBINARY,标识将为行ID。
的Flex表附带了一组的帮助功能:

  • COMPUTE_FLEXTABLE_KEYS
  • BUILD_FLEXTABLE_VIEW
  • COMPUTE_FLEXTABLE_KEYS_AND_BUILD_VIEW
  • MATERIALIZE_FLEXTABLE_COLUMNS
  • RESTORE_FLEXTABLE_DEFAULT_KEYS_TABLE_AND_VIEW

我不打算解释所有这些,因为我认为你应该去研究它们。 有关新Vertica的更多细节特点去这个链接Vertica 7.0 New Stuff

1

所有非结构化数据保存到原始数据字段

这是一个BLOB

当您需要访问非结构化的领域,这是一个缓慢,因为需要BLOB提取

1

在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 .